X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fpool.c;h=9568d5f527aa84f67aa10c627024a8b72bed79a5;hb=ea87e32fc17cce0b6633b88df1855f538efe9652;hp=67615378e7a2b371df32e3afd101c7db0245d730;hpb=bb864e1a88e670c99d559c7dee4f74e9bf7d978b;p=swftools.git diff --git a/lib/as3/pool.c b/lib/as3/pool.c index 6761537..9568d5f 100644 --- a/lib/as3/pool.c +++ b/lib/as3/pool.c @@ -136,7 +136,7 @@ char*escape_string(const char*str) if(!str) return strdup("NULL"); int len=0; - unsigned const char*s=str; + unsigned const char*s=(unsigned const char*)str; while(*s) { if(*s<10) { len+=2; // \d @@ -151,7 +151,7 @@ char*escape_string(const char*str) } char*newstr = malloc(len+1); char*dest = newstr; - s=str; + s=(unsigned const char*)str; while(*s) { if(*s<9) { dest+=sprintf(dest, "\\%d", *s); @@ -522,14 +522,17 @@ char* multiname_tostring(multiname_t*m) int namelen = strlen(name); if(m->type==QNAME || m->type==QNAMEA || m->type==POSTFIXTYPE) { - char*nsname = escape_string(m->ns->name); + char*nsname = m->ns?escape_string(m->ns->name):strdup("NULL"); mname = malloc(strlen(nsname)+namelen+32); strcpy(mname, "type == QNAMEA) strcat(mname, ",attr"); - strcat(mname, ">["); - strcat(mname,access2str(m->ns->access)); - strcat(mname, "]"); + strcat(mname, ">"); + if(m->ns) { + strcat(mname,"["); + strcat(mname,access2str(m->ns->access)); + strcat(mname, "]"); + } strcat(mname, nsname); free(nsname); strcat(mname, "::"); @@ -634,9 +637,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) @@ -660,7 +660,7 @@ constant_t* constant_new_float(double f) c->type = CONSTANT_FLOAT; return c; } -constant_t* constant_new_string(char*s) +constant_t* constant_new_string(const char*s) { NEW(constant_t,c); c->s = string_new4(s); @@ -706,6 +706,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) { @@ -791,6 +803,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 { @@ -1101,7 +1117,7 @@ void pool_read(pool_t*pool, TAG*tag) DEBUG printf("%d strings\n", num_strings); for(t=1;tdata[tag->pos], len); + string_t s = string_new((char*)&tag->data[tag->pos], len); swf_GetBlock(tag, 0, len); array_append(pool->x_strings, &s, 0); DEBUG printf("%d) \"%s\"\n", t, ((string_t*)array_getkey(pool->x_strings, t))->str); @@ -1153,6 +1169,9 @@ void pool_read(pool_t*pool, TAG*tag) if(m.type==0x07 || m.type==0x0d) { int namespace_index = swf_GetU30(tag); m.ns = (namespace_t*)array_getkey(pool->x_namespaces, namespace_index); + if(!m.ns) { + fprintf(stderr, "Error: Illegal reference to namespace #%d in constant pool.\n", namespace_index); + } int name_index = swf_GetU30(tag); if(name_index) // 0 = '*' (any) m.name = pool_lookup_string(pool, name_index);