泛型(Vector)在 AVM 中如何工作?

发布于 2024-07-13 21:36:54 字数 430 浏览 7 评论 0原文

支持泛型(目前仅 Vector.<*>,以及Flash Player 10 中添加了“后缀类型参数”(Adobe 称为“后缀类型参数”),但唯一的 AVM2 文档 没有描述如何访问这些对象。

具体来说,我注意到一个新的操作码(0x53)和一个新的多名称类型(0x1D)似乎相关,但它们的用法没有记录。

注意:这个问题是用已知的答案创建的,因为在这里比在我的博客或 Adob​​e 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

电影里的梦 2024-07-20 21:36:54

我对此所做的逆向工程工作不包括声明您自己的泛型类型,尽管这很可能是可能的。

对声明(无参数)泛型类型(向量)的引用是通过常规限定名称进行的(尽管任何多重名称都应该这样做)。

对类型化泛型类型(Vector.与 Vector.<> 相对)的引用是由新的多名称类型 (0x1D) 进行的,我将其称为 GenericName。 GenericName 的格式如下:

[Kind] [TypeDefinition] [ParamCount] [Param1] [Param2] [ParamN]

其中:

  • [TypeDefinition] 是多名称表中的 U30
  • [ParamCount] 是有多少个类型参数的 U8(U30?)
  • [ParamX] 是多名称表中的 U30。

显然,泛型尚未得到普遍支持,因此 ParamCount 将始终为 1(对于 Vector.<*>)。

另一个有趣的事情是如何创建类的实例。 Flash 10 (0x53) 中添加了一个新的操作码,我将其称为 MakeGenericType。 MakeGenericType 使用以下堆栈进行声明:

TypeDefinition, ParameterType1, ParameterTypeN -> GenericType

它还有一个参数,一个 U8(U30?),指定堆栈上有多少个参数。 您通常会看到像这样使用 MakeGenericType:

GetLex [TypeDefinitionMultiname]
GetLex [ParameterTypeMultiname]
MakeGeneric [ParamCount]
Coerce [GenericNameMultiname]
Construct [ConstructorParamCount]

因此,如果您有以下内容...

GetLex __AS3__.vec::Vector
GetLex int
MakeGeneric 1
Coerce __AS3__.vec::Vector.<int>
Construct 0

您现在将拥有一个 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:

[Kind] [TypeDefinition] [ParamCount] [Param1] [Param2] [ParamN]

Where:

  • [TypeDefinition] is a U30 into the multiname table
  • [ParamCount] is a U8 (U30?) of how many type parameters there are
  • [ParamX] is a U30 into the multiname table.

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:

TypeDefinition, ParameterType1, ParameterTypeN -> GenericType

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:

GetLex [TypeDefinitionMultiname]
GetLex [ParameterTypeMultiname]
MakeGeneric [ParamCount]
Coerce [GenericNameMultiname]
Construct [ConstructorParamCount]

So if you had the following...

GetLex __AS3__.vec::Vector
GetLex int
MakeGeneric 1
Coerce __AS3__.vec::Vector.<int>
Construct 0

You would now have an instance of Vector.<int>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文