#include "../rfxswf.h"
#include "../q.h"
#include "abc.h"
+#include "assets.h"
char stringbuffer[2048];
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;
}
int t;
int num_metadata = swf_GetU30(tag);
- DEBUG printf("%d metadata\n");
+ DEBUG printf("%d metadata\n", num_metadata);
for(t=0;t<num_metadata;t++) {
const char*entry_name = pool_lookup_string(pool, swf_GetU30(tag));
int num = swf_GetU30(tag);
abc_class_t* abc_class_new(abc_file_t*file, multiname_t*classname, multiname_t*superclass) {
NEW(abc_class_t,c);
- array_append(file->classes, NO_KEY, c);
+ if(file)
+ array_append(file->classes, NO_KEY, c);
c->file = file;
c->classname = multiname_clone(classname);
{
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)
{
/* 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);
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)
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);
} 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)));
int s;
array_t*items = (array_t*)array_getvalue(file->metadata, t);
for(s=0;s<items->num;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);
}
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");
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);
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();
// don't bother to set m->index
body->method = m; m->body = body;
if(c->superclass && c->superclass->name && strcmp(c->superclass->name,"Object")) {
- __ getlocal_0(body);
- __ constructsuper(body, 0);
+ body->code = abc_getlocal_0(body->code);
+ body->code = abc_constructsuper(body->code, 0);
}
- __ returnvoid(body);
+ body->code = abc_returnvoid(body->code);
c->constructor = m;
} else {
NEW(abc_method_t,m);array_append(file->methods, NO_KEY, m);
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;
}
}
swf_SetU30(tag, file->scripts->num);
for(t=0;t<file->scripts->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);
}