- }
-}
-
-#define TRAIT_SLOT 0
-#define TRAIT_METHOD 1
-#define TRAIT_GETTER 2
-#define TRAIT_SETTER 3
-#define TRAIT_CLASS 4
-#define TRAIT_FUNCTION 5
-#define TRAIT_CONST 6
-
-static dict_t* traits_parse(TAG*tag, abc_file_t*pool)
-{
- int num_traits = swf_GetU30(tag);
- dict_t*traits = dict_new();
- int t;
- if(num_traits) {
- DEBUG printf("%d traits\n", num_traits);
- }
-
- for(t=0;t<num_traits;t++) {
- abc_trait_t*trait = malloc(sizeof(abc_trait_t));
- memset(trait, 0, sizeof(abc_trait_t));
- dict_append(traits, 0, trait);
- trait->name_index = swf_GetU30(tag);
- const char*name = dict_getstr(pool->multinames, trait->name_index);
- U8 kind = trait->type = swf_GetU8(tag);
- U8 attributes = kind&0xf0;
- kind&=0x0f;
- DEBUG printf(" trait %d) %s type=%02x\n", t, name, kind);
- if(kind == 1 || kind == 2 || kind == 3) { // method / getter / setter
- trait->disp_id = swf_GetU30(tag);
- trait->nr = swf_GetU30(tag);
- DEBUG printf(" method/getter/setter\n");
- } else if(kind == 5) { // function
- trait->slot_id = swf_GetU30(tag);
- trait->nr = swf_GetU30(tag);
- } else if(kind == 4) { // class
- trait->slot_id = swf_GetU30(tag);
- trait->cls = swf_GetU30(tag);
- DEBUG printf(" class %s %d %d\n", name, trait->slot_id, trait->cls);
- } else if(kind == 0 || kind == 6) { // slot, const
- /* a slot is a variable in a class that is shared amonst all instances
- of the same type, but which has a unique location in each object
- (in other words, slots are non-static, traits are static)
- */
- trait->slot_id = swf_GetU30(tag);
- const char*type_name = dict_getstr(pool->multinames, swf_GetU30(tag));
- trait->vindex = swf_GetU30(tag);
- if(trait->vindex) {
- trait->vkind = swf_GetU8(tag);
- }
- DEBUG printf(" slot %s %d %s (vindex=%d)\n", name, trait->slot_id, type_name, trait->vindex);
- } else {
- printf(" can't parse trait type %d\n", kind);
- return 0;
- }
- if(attributes&0x40) {
- int num = swf_GetU30(tag);
- int s;
- for(s=0;s<num;s++) {
- swf_GetU30(tag); //index into metadata array
- }
- }
- }
- return traits;
-}
-
-static void dump_traits(const char*prefix, dict_t*traits, abc_file_t*pool)
-{
- int num_traits = traits->num;
- int t;
- for(t=0;t<num_traits;t++) {
- abc_trait_t*trait = (abc_trait_t*)dict_getdata(traits, t);
- const char*name = dict_getstr(pool->multinames, trait->name_index);
- U8 kind = trait->type;
- U8 attributes = kind&0xf0;
- kind&=0x0f;
- if(kind == TRAIT_METHOD) {
- dump_method(prefix, "method", name, trait->nr, pool);
- } else if(kind == TRAIT_GETTER) {
- dump_method(prefix, "getter", name, trait->nr, pool);
- } else if(kind == TRAIT_SETTER) {
- dump_method(prefix, "setter", name, trait->nr, pool);
- } else if(kind == TRAIT_FUNCTION) { // function
- dump_method(prefix, "function", name, trait->nr, pool);
- } else if(kind == TRAIT_CLASS) { // class
- abc_class_t*cls = (abc_class_t*)dict_getdata(pool->classes, trait->cls);
- if(!cls) {
- printf("%sslot %d: class %s=class%d %d\n", prefix, trait->slot_id, name, trait->cls);
- } else {
- printf("%sslot %d: class %s=%s\n", prefix, trait->slot_id, name, cls->classname);
- }
- } else if(kind == TRAIT_SLOT || kind == TRAIT_CONST) { // slot, const
- int slot_id = trait->slot_id;
- const char*type_name = dict_getstr(pool->multinames, trait->type_index);
- printf("%sslot %s %d %s (vindex=%d)\n", prefix, name, trait->slot_id, type_name, trait->vindex);
- } else {
- printf(" can't dump trait type %d\n", kind);
- }