X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=lib%2Fas3%2Fabc.c;h=d03977d9798592ad7e48413d6e4010398a900f17;hb=cecf84b4cc9ba4d47beaac8adac6ba727c4a04dd;hp=97b5884ab37dd7c36da6733869c93b79189ba156;hpb=2839fd9b16fe61e2bc4b93b5a034ef26776cd4fc;p=swftools.git diff --git a/lib/as3/abc.c b/lib/as3/abc.c index 97b5884..d03977d 100644 --- a/lib/as3/abc.c +++ b/lib/as3/abc.c @@ -322,14 +322,14 @@ static void dump_method(FILE*fo, const char*prefix, const char*type, const char* return; } - fprintf(fo, "%s[%d %d %d %d %d]\n", prefix, c->max_stack, c->local_count, c->init_scope_depth, c->max_scope_depth, c->exception_count); + fprintf(fo, "%s[%d %d %d %d %d]\n", prefix, c->max_stack, c->local_count, c->init_scope_depth, c->max_scope_depth, list_length(c->exceptions)); char prefix2[80]; sprintf(prefix2, "%s ", prefix); if(c->traits) dump_traits(fo, prefix, c->traits, file); fprintf(fo, "%s{\n", prefix); - code_dump(c->code, file, prefix2, fo); + code_dump(c->code, c->exceptions, file, prefix2, fo); fprintf(fo, "%s}\n\n", prefix); } @@ -634,8 +634,9 @@ void* swf_ReadABC(TAG*tag) int s; for(s=0;sparameters, param); } @@ -735,18 +736,27 @@ void* swf_ReadABC(TAG*tag) m->body = c; int pos = tag->pos + code_length; - c->code = code_parse(tag, code_length, file, pool); + codelookup_t*codelookup = 0; + c->code = code_parse(tag, code_length, file, pool, &codelookup); tag->pos = pos; int exception_count = swf_GetU30(tag); int s; + c->exceptions = list_new(); for(s=0;sfrom = code_atposition(codelookup, swf_GetU30(tag)); + e->to = code_atposition(codelookup, swf_GetU30(tag)); + e->target = code_atposition(codelookup, swf_GetU30(tag)); + + e->exc_type = multiname_clone(pool_lookup_multiname(pool, swf_GetU30(tag))); + e->var_name = multiname_clone(pool_lookup_multiname(pool, swf_GetU30(tag))); + //e->var_name = pool_lookup_string(pool, swf_GetU30(tag)); + //if(e->var_name) e->var_name = strdup(e->var_name); + list_append(c->exceptions, e); } + codelookup_free(codelookup); c->traits = traits_parse(tag, pool, file); DEBUG printf("method_body %d) (method %d), %d bytes of code", t, methodnr, code_length); @@ -808,24 +818,6 @@ void* swf_ReadABC(TAG*tag) return file; } -static void code_write(TAG*tag, abc_code_t*code, pool_t*pool, abc_file_t*file) -{ - int len = 0; - abc_code_t*c = code; - while(c) { - len += opcode_write(0, c, pool, file); - c = c->next; - } - swf_SetU30(tag, len); - int pos = tag->len; - c = code; - while(c) { - opcode_write(tag, c, pool, file); - c = c->next; - } - assert(tag->len - pos == len); -} - void swf_WriteABC(TAG*abctag, void*code) { abc_file_t*file = (abc_file_t*)code; @@ -865,6 +857,16 @@ void swf_WriteABC(TAG*abctag, void*code) for(t=0;tmethod_bodies->num;t++) { abc_method_body_t*m = (abc_method_body_t*)array_getvalue(file->method_bodies, t); m->index = t; + exception_list_t*ee = m->exceptions; + while(ee) { + exception_t*e=ee->exception;ee->exception=0; + e->from = e->to = e->target = 0; + multiname_destroy(e->exc_type);e->exc_type=0; + multiname_destroy(e->var_name);e->var_name=0; + free(e); + ee=ee->next; + } + list_free(m->exceptions);m->exceptions=0; } for(t=0;tmethods->num;t++) { @@ -966,7 +968,18 @@ void swf_WriteABC(TAG*abctag, void*code) code_write(tag, c->code, pool, file); - swf_SetU30(tag, c->exception_count); + swf_SetU30(tag, list_length(c->exceptions)); + exception_list_t*l = c->exceptions; + while(l) { + // warning: assumes "pos" in each code_t is up-to-date + swf_SetU30(tag, l->exception->from->pos); + swf_SetU30(tag, l->exception->to->pos); + swf_SetU30(tag, l->exception->target->pos); + swf_SetU30(tag, pool_register_multiname(pool, l->exception->exc_type)); + swf_SetU30(tag, pool_register_multiname(pool, l->exception->var_name)); + l = l->next; + } + traits_write(pool, tag, c->traits); } @@ -990,9 +1003,8 @@ void swf_WriteABC(TAG*abctag, void*code) pool_destroy(pool); } -void swf_FreeABC(void*code) +void abc_file_free(abc_file_t*file) { - abc_file_t*file= (abc_file_t*)code; int t; for(t=0;tmetadata->num;t++) { @@ -1073,6 +1085,12 @@ void swf_FreeABC(void*code) free(file); } +void swf_FreeABC(void*code) +{ + abc_file_t*file= (abc_file_t*)code; + abc_file_free(file); +} + void swf_AddButtonLinks(SWF*swf, char stop_each_frame, char events) { int num_frames = 0;