X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fas3%2Fabc.c;h=7e11e1c94f07fbfb830916f89c572f47676767bc;hp=2962331ae2b9db197cf645097cc91206176ef276;hb=2391d7ae5d8a145a250a8b80ab8c93ba74eba030;hpb=780e53f414a281c516c153a578638c4f7414434c diff --git a/lib/as3/abc.c b/lib/as3/abc.c index 2962331..7e11e1c 100644 --- a/lib/as3/abc.c +++ b/lib/as3/abc.c @@ -26,6 +26,7 @@ #include "../rfxswf.h" #include "../q.h" #include "abc.h" +#include "assets.h" char stringbuffer[2048]; @@ -49,12 +50,12 @@ static void params_dump(FILE*fo, multiname_list_t*l, constant_list_t*o) fprintf(fo, "("); while(l) { char*s = multiname_tostring(l->multiname); - fprintf(fo, s); + fprintf(fo, "%s", s); free(s); if(i>=n-no) { s = constant_tostring(o->constant); fprintf(fo, " = "); - fprintf(fo, s); + fprintf(fo, "%s", s); free(s); o = o->next; } @@ -74,7 +75,7 @@ static void parse_metadata(TAG*tag, abc_file_t*file, pool_t*pool) int t; int num_metadata = swf_GetU30(tag); - DEBUG printf("%d metadata\n"); + DEBUG printf("%d metadata\n", num_metadata); for(t=0;tclasses, NO_KEY, c); + if(file) + array_append(file->classes, NO_KEY, c); c->file = file; c->classname = multiname_clone(classname); @@ -156,6 +158,20 @@ void abc_class_add_interface(abc_class_t*c, multiname_t*interface) { list_append(c->interfaces, multiname_clone(interface)); } +char*abc_class_fullname(abc_class_t*cls) +{ + const char*package = cls->classname->ns->name; + const char*name = cls->classname->name; + int l1 = strlen(package); + int l2 = strlen(name); + char*fullname = malloc(l1+l2+2); + if(l1) { + memcpy(fullname, package, l1); + fullname[l1++]='.'; + } + memcpy(fullname+l1, name, l2+1); + return fullname; +} void abc_method_init(abc_method_t*m, abc_file_t*file, multiname_t*returntype, char body) { @@ -308,7 +324,7 @@ void abc_method_body_addClassTrait(abc_method_body_t*code, char*multiname, int s /* notice: traits of a method (body) belonging to an init script and traits of the init script are *not* the same thing */ -int abc_initscript_addClassTrait(abc_script_t*script, multiname_t*multiname, abc_class_t*cls) +trait_t* abc_initscript_addClassTrait(abc_script_t*script, multiname_t*multiname, abc_class_t*cls) { abc_file_t*file = script->file; multiname_t*m = multiname_clone(multiname); @@ -316,7 +332,7 @@ int abc_initscript_addClassTrait(abc_script_t*script, multiname_t*multiname, abc trait_t*trait = trait_new(TRAIT_CLASS, m, slotid, 0, 0); trait->cls = cls; list_append(script->traits, trait); - return slotid; + return trait; } abc_script_t* abc_initscript(abc_file_t*file) @@ -345,7 +361,7 @@ static void dump_method(FILE*fo, const char*prefix, if(m->return_type) return_type = multiname_tostring(m->return_type); else - return_type = strdup("void"); + return_type = strdup("*"); fprintf(fo, "%s", prefix); fprintf(fo, "%s %s ", attr, type); @@ -450,7 +466,7 @@ static trait_list_t* traits_parse(TAG*tag, pool_t*pool, abc_file_t*file) } else if(kind == TRAIT_CLASS) { // class trait->slot_id = swf_GetU30(tag); trait->cls = (abc_class_t*)array_getvalue(file->classes, swf_GetU30(tag)); - DEBUG printf(" class %s %d %d\n", name, trait->slot_id, trait->cls); + DEBUG printf(" class %s %d %08x\n", name, trait->slot_id, (int)trait->cls); } else if(kind == TRAIT_SLOT || kind == TRAIT_CONST) { // slot, const trait->slot_id = swf_GetU30(tag); trait->type_name = multiname_clone(pool_lookup_multiname(pool, swf_GetU30(tag))); @@ -591,7 +607,7 @@ static void traits_dump(FILE*fo, const char*prefix, trait_list_t*traits, abc_fil char*value = constant_tostring(trait->value); fprintf(fo, "%sslot %d: %s %s:%s %s %s\n", prefix, trait->slot_id, kind==TRAIT_CONST?"const":"var", name, type_name, - value?"=":"", value?value:""); + trait->value?"=":"", trait->value?value:""); if(value) free(value); free(type_name); } else { @@ -619,7 +635,7 @@ void* swf_DumpABC(FILE*fo, void*code, char*prefix) int s; array_t*items = (array_t*)array_getvalue(file->metadata, t); for(s=0;snum;s++) { - fprintf(fo, "%s# %s=%s\n", prefix, array_getkey(items, s), array_getvalue(items,s)); + fprintf(fo, "%s# %s=%s\n", prefix, (char*)array_getkey(items, s), (char*)array_getvalue(items,s)); } fprintf(fo, "%s#\n", prefix); } @@ -647,6 +663,8 @@ void* swf_DumpABC(FILE*fo, void*code, char*prefix) char*supername = multiname_tostring(cls->superclass); fprintf(fo, " extends %s", supername); free(supername); + } + if(cls->interfaces) { multiname_list_t*ilist = cls->interfaces; if(ilist) fprintf(fo, " implements"); @@ -675,6 +693,11 @@ void* swf_DumpABC(FILE*fo, void*code, char*prefix) dump_method(fo, prefix2, "", "constructor", n, cls->constructor, file, methods_seen); free(n); traits_dump(fo, prefix2,cls->traits, file, methods_seen); + + if(cls->asset) { + swf_DumpAsset(fo, cls->asset, prefix2); + } + fprintf(fo, "%s}\n", prefix); } fprintf(fo, "%s\n", prefix); @@ -752,9 +775,9 @@ void* swf_ReadABC(TAG*tag) m->flags = swf_GetU8(tag); - DEBUG printf("method %d) %s ", m->name); + DEBUG printf("method %d) %s ", t, m->name); DEBUG params_dump(stdout, m->parameters, m->optional_parameters); - DEBUG printf("flags=%02x\n", t, m->flags); + DEBUG printf("flags=%02x\n", m->flags); if(m->flags&0x08) { m->optional_parameters = list_new(); @@ -949,7 +972,11 @@ static pool_t*writeABC(TAG*abctag, void*code, pool_t*pool) NEW(abc_method_body_t,body);array_append(file->method_bodies, NO_KEY, body); // don't bother to set m->index body->method = m; m->body = body; - __ returnvoid(body); + if(c->superclass && c->superclass->name && strcmp(c->superclass->name,"Object")) { + body->code = abc_getlocal_0(body->code); + body->code = abc_constructsuper(body->code, 0); + } + body->code = abc_returnvoid(body->code); c->constructor = m; } else { NEW(abc_method_t,m);array_append(file->methods, NO_KEY, m); @@ -960,7 +987,7 @@ static pool_t*writeABC(TAG*abctag, void*code, pool_t*pool) NEW(abc_method_t,m);array_append(file->methods, NO_KEY, m); NEW(abc_method_body_t,body);array_append(file->method_bodies, NO_KEY, body); body->method = m; m->body = body; - __ returnvoid(body); + body->code = abc_returnvoid(0); c->static_constructor = m; } } @@ -1124,6 +1151,9 @@ static pool_t*writeABC(TAG*abctag, void*code, pool_t*pool) swf_SetU30(tag, file->scripts->num); for(t=0;tscripts->num;t++) { abc_script_t*s = (abc_script_t*)array_getvalue(file->scripts, t); + if(!s->method->body || !s->method->body->code) { + fprintf(stderr, "Internal Error: initscript has no body\n"); + } swf_SetU30(tag, s->method->index); //!=t! traits_write(pool, tag, s->traits); }