泛型(Vector)在 AVM 中如何工作?
支持泛型(目前仅 Vector.<*>,以及Flash Player 10 中添加了“后缀类型参数”(Adobe 称为“后缀类型参数”),但唯一的 AVM2 文档 没有描述如何访问这些对象。
具体来说,我注意到一个新的操作码(0x53)和一个新的多名称类型(0x1D)似乎相关,但它们的用法没有记录。
注意:这个问题是用已知的答案创建的,因为在这里比在我的博客或 Adobe Bug DB 上更容易找到它。
Support for generics (currently only Vector.<*>, and called 'postfix type parameters' by Adobe) was added in Flash Player 10, but the only AVM2 documentation does not describe how these objects are accessed.
Specifically, I noticed a new opcode (0x53) and a new multiname kind (0x1D) that seem relevant, but their usage is not documented.
NB: This question was created with the answer already known as it is more easily found here than on my blog or the Adobe Bug DB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此所做的逆向工程工作不包括声明您自己的泛型类型,尽管这很可能是可能的。
对声明(无参数)泛型类型(向量)的引用是通过常规限定名称进行的(尽管任何多重名称都应该这样做)。
对类型化泛型类型(Vector.与 Vector.<> 相对)的引用是由新的多名称类型 (0x1D) 进行的,我将其称为 GenericName。 GenericName 的格式如下:
其中:
显然,泛型尚未得到普遍支持,因此 ParamCount 将始终为 1(对于 Vector.<*>)。
另一个有趣的事情是如何创建类的实例。 Flash 10 (0x53) 中添加了一个新的操作码,我将其称为 MakeGenericType。 MakeGenericType 使用以下堆栈进行声明:
它还有一个参数,一个 U8(U30?),指定堆栈上有多少个参数。 您通常会看到像这样使用 MakeGenericType:
因此,如果您有以下内容...
您现在将拥有一个 Vector 实例。
The reverse engineering work I did on this did not include declaring your own generic types, though it's very likely possible.
References to the declaring (parameterless) generic type (Vector) are made through a regular qualified name (though any multiname should do).
References to a typed generic type (Vector.<int> as opposed to Vector.<>) are made by a new multiname kind (0x1D), which I call GenericName. GenericName has a format like so:
Where:
Obviously generics are not generally supported yet, so ParamCount will always be 1 (for Vector.<*>).
The other interesting thing is how instances of the class are created. A new opcode was added in Flash 10 (0x53), which I will call MakeGenericType. MakeGenericType is declared with the following stack:
It also has one parameter, a U8 (U30?) specifying how many parameters are on the stack. You will generally see MakeGenericType being used like this:
So if you had the following...
You would now have an instance of Vector.<int>