3 Extension module for the rfxswf library.
4 Part of the swftools package.
6 Copyright (c) 2009 Matthias Kramm <kramm@quiss.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
27 void as3_import_abc(char*filename)
29 TAG*tag = swf_InsertTag(0, ST_RAWABC);
30 memfile_t*file = memfile_open(filename);
31 tag->data = file->data;
33 abc_file_t*abc = swf_ReadABC(tag);
40 void as3_import_swf(char*filename)
42 SWF* swf = swf_OpenSWF(filename);
45 TAG*tag = swf->firstTag;
47 if(tag->id == ST_DOABC || tag->id == ST_RAWABC) {
48 abc_file_t*abc = swf_ReadABC(tag);
58 static int compare_traits(const void*v1, const void*v2)
60 trait_t* x1 = *(trait_t**)v1;
61 trait_t* x2 = *(trait_t**)v2;
62 int i = strcmp(x1->name->ns->name, x2->name->ns->name);
65 return strcmp(x1->name->name, x2->name->name);
69 void as3_import_code(abc_file_t*abc)
72 for(t=0;t<abc->classes->num;t++) {
73 abc_class_t*cls = array_getvalue(abc->classes, t);
74 U8 access = cls->classname->ns->access;
75 if(access==ACCESS_PRIVATE ||
76 access==ACCESS_PACKAGEINTERNAL)
78 if(!strncmp(cls->classname->ns->name, "__AS3", 5))
81 const char*package = strdup(cls->classname->ns->name);
82 const char*name = strdup(cls->classname->name);
84 multiname_list_t*i=cls->interfaces;
85 classinfo_t*c = classinfo_register(access, package, name, list_length(i));
87 if(cls->flags & CLASS_FINAL)
88 c->flags |= FLAG_FINAL;
89 if(cls->flags & CLASS_INTERFACE)
90 c->flags |= FLAG_INTERFACE;
91 if(!(cls->flags & CLASS_SEALED))
92 c->flags |= FLAG_DYNAMIC;
97 c->interfaces[nr++] = i->multiname;
108 trait_t*trait = l->trait;
109 U8 access = trait->name->ns->access;
110 if(access==ACCESS_PRIVATE)
112 const char*name = trait->name->name;
113 if(registry_findmember(c, name, 0))
118 if(trait->kind == TRAIT_METHOD) {
119 s = (memberinfo_t*)methodinfo_register_onclass(c, access, name);
120 } else if(trait->kind == TRAIT_SLOT ||
121 trait->kind == TRAIT_GETTER) {
122 s = (memberinfo_t*)varinfo_register_onclass(c, access, name);
126 s->flags = is_static?FLAG_STATIC:0;
131 if(!l && !is_static) {
132 l = cls->static_traits;
138 # define IS_PUBLIC_MEMBER(trait) ((trait)->kind != TRAIT_CLASS)
140 /* count public functions */
142 for(t=0;t<abc->scripts->num;t++) {
143 trait_list_t*l = ((abc_script_t*)array_getvalue(abc->scripts, t))->traits;
145 num_methods += IS_PUBLIC_MEMBER(l->trait);
148 trait_t**traits = (trait_t**)malloc(num_methods*sizeof(trait_t*));
150 for(t=0;t<abc->scripts->num;t++) {
151 trait_list_t*l = ((abc_script_t*)array_getvalue(abc->scripts, t))->traits;
153 if(IS_PUBLIC_MEMBER(l->trait)) {
154 traits[num_methods++] = l->trait;
158 qsort(traits, num_methods, sizeof(trait_t*), compare_traits);
159 for(t=0;t<num_methods;t++) {
160 trait_t*trait = traits[t];
161 if(IS_PUBLIC_MEMBER(trait)) {
162 U8 access = trait->name->ns->access;
163 const char*package = strdup(trait->name->ns->name);
164 const char*name = strdup(trait->name->name);
167 if(trait->kind == TRAIT_METHOD) {
168 m = (memberinfo_t*)methodinfo_register_global(access, package, name);
170 m = (memberinfo_t*)varinfo_register_global(access, package, name);