From 95706ae1c7ff59b6396c54da046b61eca7f3982f Mon Sep 17 00:00:00 2001 From: kramm Date: Mon, 24 Nov 2008 16:11:57 +0000 Subject: [PATCH] added exception struct --- lib/as3/abc.c | 50 ++++++++++++++++++++++++++++++++++++++------------ lib/as3/abc.h | 18 +++++++++++++----- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/lib/as3/abc.c b/lib/as3/abc.c index abdc258..d545a98 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); @@ -948,7 +958,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); } @@ -972,9 +993,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++) { @@ -1055,6 +1075,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; diff --git a/lib/as3/abc.h b/lib/as3/abc.h index a298973..cfa48b0 100644 --- a/lib/as3/abc.h +++ b/lib/as3/abc.h @@ -32,6 +32,8 @@ DECLARE(abc_method); DECLARE(abc_method_body); DECLARE(abc_interface); DECLARE(abc_class); +DECLARE(exception); +DECLARE_LIST(exception); #include "code.h" #include "opcodes.h" @@ -121,26 +123,32 @@ abc_method_body_t* abc_class_staticconstructor(abc_class_t*cls, char*returntype, abc_method_body_t* abc_class_constructor(abc_class_t*cls, char*returntype, int num_params, ...); abc_method_body_t* abc_class_method(abc_class_t*cls, char*returntype, char*name, int num_params, ...); +struct _exception { + code_t*from; + code_t*to; + code_t*target; + multiname_t*exc_type; + multiname_t*var_name; +}; + struct _abc_method_body { abc_file_t*pool; //abc_class_t*cls; abc_method_t*method; - abc_code_t*code; + code_t*code; int max_stack; int local_count; int init_scope_depth; int max_scope_depth; - int exception_count; + exception_list_t* exceptions; + trait_list_t*traits; int index; // filled in during writing }; -typedef struct _abc_label { -} abc_label_t; - typedef struct _abc_script { abc_method_t*method; abc_file_t*pool; -- 1.7.10.4