X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fpool.c;h=913a84e189ccdc8712d6a8f2c0f3f1a910bb39ed;hb=3dea7306ae2c9590673c10dec1fbabcd6d7e1806;hp=c158811526780a3bd0dd631502a2223b1e614a87;hpb=63632e88b59faf27683664213efe240d02fca66d;p=swftools.git diff --git a/lib/as3/pool.c b/lib/as3/pool.c index c158811..913a84e 100644 --- a/lib/as3/pool.c +++ b/lib/as3/pool.c @@ -189,8 +189,7 @@ char* namespace_tostring(namespace_t*ns) else if(!*s) sprintf(string, "[%s]\"\"", access, s); else - sprintf(string, "[%s]", access, s); - + sprintf(string, "[%s]%s", access, s); free(s); return string; } @@ -251,7 +250,7 @@ namespace_t* namespace_new(U8 access, const char*name) ns->name = name?strdup(name):0; return ns; } -namespace_t* namespace_new_undefined(const char*name) { +namespace_t* namespace_new_namespace(const char*name) { return namespace_new(0x08, name); // public? } namespace_t* namespace_new_package(const char*name) { @@ -276,7 +275,7 @@ namespace_t* namespace_new_private(const char*name) { void namespace_destroy(namespace_t*n) { if(n) { - free(n->name);n->name=0; + free((char*)n->name);n->name=0; n->access=0x00; free(n); } @@ -522,7 +521,7 @@ char* multiname_tostring(multiname_t*m) char*name = m->name?escape_string(m->name):strdup("*"); int namelen = strlen(name); - if(m->type==QNAME || m->type==QNAMEA) { + if(m->type==QNAME || m->type==QNAMEA || m->type==POSTFIXTYPE) { char*nsname = escape_string(m->ns->name); mname = malloc(strlen(nsname)+namelen+32); strcpy(mname, "type); + return strdup(""); } free(name); return mname; @@ -635,9 +634,6 @@ type_t multiname_type = { // ------------------------------- constants ------------------------------------- -#define NS_TYPE(x) ((x) == 0x08 || (x) == 0x16 || (x) == 0x17 || (x) == 0x18 || \ - (x) == 0x19 || (x) == 0x1a || (x) == 0x05) - #define UNIQUE_CONSTANT(x) ((x) == CONSTANT_TRUE || (x) == CONSTANT_FALSE || (x) == CONSTANT_NULL || (x) == CONSTANT_UNDEFINED) constant_t* constant_new_int(int i) @@ -707,6 +703,18 @@ constant_t* constant_new_undefined() c->type = CONSTANT_UNDEFINED; return c; } +constant_t* constant_clone(constant_t*other) +{ + if(!other) return 0; + constant_t*c = malloc(sizeof(constant_t)); + memcpy(c, other, sizeof(constant_t)); + if(NS_TYPE(c->type)) { + c->ns = namespace_clone(other->ns); + } else if(c->type == CONSTANT_STRING) { + c->s = string_dup3(other->s); + } + return c; +} constant_t* constant_fromindex(pool_t*pool, int index, int type) { if(!index) { @@ -792,6 +800,10 @@ int constant_get_index(pool_t*pool, constant_t*c) return pool_register_float(pool, c->f); } else if(c->type == CONSTANT_STRING) { return pool_register_string2(pool, c->s); + } else if(c->type == CONSTANT_UNDEFINED) { + /* write undefined with index 0 (and no type). Otherwise, the FlashPlayer + seems to throw an "attempt to read out of bounds" exception */ + return 0; } else if(!constant_has_index(c)) { return 1; } else { @@ -828,16 +840,24 @@ static int compare_arrayentry(const void*_c1, const void*_c2) const array_entry_t*c2 = _c2; return c2->data - c1->data; } + +static void* nodup(const void*o) {return (void*)o;} + static void reshuffle_array(array_t*array) { qsort(array->d+1, array->num-1, sizeof(array->d[0]), compare_arrayentry); - dict_t*d = dict_new2(array->entry2pos->key_type); + type_t* old_type = array->entry2pos->key_type; + type_t old_type_nodup = *old_type; + old_type_nodup.dup = nodup; + dict_t*d = dict_new2(&old_type_nodup); dict_destroy_shallow(array->entry2pos); array->entry2pos = d; int t; for(t=0;tnum;t++) { dict_put(array->entry2pos, array->d[t].name, (void*)(ptroff_t)(t+1)); } + d->key_type = old_type; + } // ------------------------------- pool ------------------------------------- @@ -1136,6 +1156,12 @@ void pool_read(pool_t*pool, TAG*tag) for(t=1;tdata[tag->pos+s]); + printf("\n");*/ + m.type = swf_GetU8(tag); if(m.type==0x07 || m.type==0x0d) { int namespace_index = swf_GetU30(tag); @@ -1157,6 +1183,12 @@ void pool_read(pool_t*pool, TAG*tag) } else if(m.type==0x1b || m.type==0x1c) { int namespace_set_index = swf_GetU30(tag); m.namespace_set = (namespace_set_t*)array_getkey(pool->x_namespace_sets, namespace_set_index); + } else if(m.type==0x1d) { + int v1 = swf_GetU30(tag); //multiname + int v2 = swf_GetU30(tag); //counter? + int v3 = swf_GetU30(tag); //multiname + // e.g. Vector ... we only store the parent object + m = *(multiname_t*)array_getkey(pool->x_multinames, v1); } else { printf("can't parse type %d multinames yet\n", m.type); }