泛型(向量)如何在 AVM 中工作? [英] How do generics (Vector) work inside the AVM?

查看:22
本文介绍了泛型(向量)如何在 AVM 中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

支持泛型(目前仅 Vector.<*>,并被 Adob​​e 称为后缀类型参数")已添加到 Flash Player 10 中,但唯一的 AVM2 文档 没有描述如何访问这些对象.

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.

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

Specifically, I noticed a new opcode (0x53) and a new multiname kind (0x1D) that seem relevant, but their usage is not documented.

注意:这个问题是用已知的答案创建的,因为在这里比我的博客或 Adob​​e Bug DB 更容易找到它.

推荐答案

我在这方面所做的逆向工程工作不包括声明您自己的泛型类型,尽管这很有可能.

The reverse engineering work I did on this did not include declaring your own generic types, though it's very likely possible.

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

References to the declaring (parameterless) generic type (Vector) are made through a regular qualified name (though any multiname should do).

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

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]

地点:

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

显然泛型尚不支持,因此 ParamCount 将始终为 1(对于 Vector.<*>).

Obviously generics are not generally supported yet, so ParamCount will always be 1 (for Vector.<*>).

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

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

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

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

您现在将拥有 Vector 的实例.

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

这篇关于泛型(向量)如何在 AVM 中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆