8 #define print(x) {fputs(x,stdout);}
11 #define INDENT_LEVEL 2
13 void println(const char *s
, ...)
16 int n
= gIndent
*INDENT_LEVEL
;
30 int readUInt8(Buffer f
)
32 return f
->buffer
[fileOffset
++];
35 int readSInt8(Buffer f
)
37 return (signed char)readUInt8(f
);
40 int readSInt16(Buffer f
)
42 return readUInt8(f
) + readSInt8(f
)*256;
45 int readUInt16(Buffer f
)
47 return readUInt8(f
) + (readUInt8(f
)<<8);
50 long readSInt32(Buffer f
)
52 return (long)readUInt8(f
) + (readUInt8(f
)<<8) + (readUInt8(f
)<<16) + (readUInt8(f
)<<24);
55 unsigned long readUInt32(Buffer f
)
57 return (unsigned long)(readUInt8(f
) + (readUInt8(f
)<<8) + (readUInt8(f
)<<16) + (readUInt8(f
)<<24));
60 double readDouble(Buffer f
)
63 unsigned char *p
= (unsigned char *)&d
;
77 char *readString(Buffer f
)
79 int len
= 0, buflen
= 256;
82 buf
= (char *)malloc(sizeof(char)*256);
85 while((c
=(char)readUInt8(f
)) != '\0')
89 buf
= (char *)realloc(buf
, sizeof(char)*(buflen
+256));
103 void dumpBytes(Buffer f
, int length
)
106 unsigned char buf
[16];
115 printf("%02x ", buf
[i
] = readUInt8(f
));
124 for(k
=i
+1; k
<16; ++k
)
133 if((buf
[k
] > 31) && (buf
[k
] < 128))
147 void printDoAction(Buffer f
, int length
);
149 char *dictionary
[256];
151 int printActionRecord(Buffer f
)
153 int length
= 0, type
;
155 printf("(%i)\t", fileOffset
);
159 if((type
&0x80) == 0x80)
160 length
= readUInt16(f
);
167 case SWFACTION_SUBTRACT
:
170 case SWFACTION_MULTIPLY
:
173 case SWFACTION_DIVIDE
:
176 case SWFACTION_EQUAL
:
179 case SWFACTION_LESSTHAN
:
180 println("Less Than");
182 case SWFACTION_LOGICALAND
:
185 case SWFACTION_LOGICALOR
:
188 case SWFACTION_LOGICALNOT
:
191 case SWFACTION_STRINGEQ
:
192 println("String eq");
194 case SWFACTION_STRINGLENGTH
:
195 println("String Length");
197 case SWFACTION_SUBSTRING
:
198 println("Substring");
206 case SWFACTION_GETVARIABLE
:
207 println("Get Variable");
209 case SWFACTION_SETVARIABLE
:
210 println("Set Variable");
212 case SWFACTION_SETTARGETEXPRESSION
:
213 println("Set Target Expression");
215 case SWFACTION_STRINGCONCAT
:
216 println("String Concat");
218 case SWFACTION_GETPROPERTY
:
219 println("Get Property");
221 case SWFACTION_SETPROPERTY
:
222 println("Set Property");
224 case SWFACTION_DUPLICATECLIP
:
225 println("Duplicate Clip");
227 case SWFACTION_REMOVECLIP
:
228 println("Remove Clip");
230 case SWFACTION_TRACE
:
233 case SWFACTION_STARTDRAGMOVIE
:
234 println("Start Drag Movie");
236 case SWFACTION_STOPDRAGMOVIE
:
237 println("Stop Drag Movie");
239 case SWFACTION_STRINGCOMPARE
:
240 println("String Compare");
242 case SWFACTION_RANDOM
:
245 case SWFACTION_MBLENGTH
:
246 println("String MB Length");
254 case SWFACTION_GETTIMER
:
255 println("Get Timer");
257 case SWFACTION_MBSUBSTRING
:
258 println("MB Substring");
260 case SWFACTION_MBORD
:
263 case SWFACTION_MBCHR
:
266 case SWFACTION_NEXTFRAME
:
267 println("Next Frame");
269 case SWFACTION_PREVFRAME
:
270 println("Previous Frame");
278 case SWFACTION_TOGGLEQUALITY
:
279 println("Toggle Quality");
281 case SWFACTION_STOPSOUNDS
:
282 println("Stop Sounds");
286 case SWFACTION_PUSHDATA
:
289 int start
= fileOffset
;
291 while(fileOffset
< start
+length
)
293 switch(type
= readUInt8(f
))
296 println("Push String: %s", readString(f
));
298 case 1: /* property */
299 readUInt16(f
); /* always 0? */
300 println("Push Property: %04x", readUInt16(f
));
303 println("Push NULL");
306 println("Push type 3- ??");
309 println("Push register %i", readUInt8(f
));
313 println("Push true");
315 println("Push false");
318 println("Push %f", readDouble(f
));
321 println("Push %i", readSInt32(f
));
323 case 8: /* dictionary */
324 println("Push \"%s\"", dictionary
[readUInt8(f
)]);
326 case 9: /* dictionary */
327 println("Push \"%s\"", dictionary
[readSInt16(f
)]);
329 println("unknown push type: %i", type
);
334 case SWFACTION_GOTOFRAME
:
335 println("Goto Frame %i", readUInt16(f
));
337 case SWFACTION_GETURL
:
339 char *url
= readString(f
);
340 println("Get URL \"%s\" target \"%s\"", url
, readString(f
));
343 case SWFACTION_WAITFORFRAMEEXPRESSION
:
344 println("Wait For Frame Expression, skip %i\n", readUInt8(f
));
346 case SWFACTION_BRANCHALWAYS
:
347 println("Branch Always %i", readSInt16(f
));
349 case SWFACTION_GETURL2
:
351 int flags
= readUInt8(f
);
353 const char *op
= (flags
& 0x80) ? "Get URL2 (loadvariables)" : "Get URL2";
354 const char *tgt
= (flags
& 0x40) ? " into target" : "";
358 case 0: println("%s%s (Don't send)", op
, tgt
); break;
359 case 1: println("%s%s (GET)", op
, tgt
); break;
360 case 2: println("%s%s (POST)", op
, tgt
); break;
364 case SWFACTION_BRANCHIFTRUE
:
365 println("Branch If True %i", readSInt16(f
));
367 case SWFACTION_CALLFRAME
:
368 println("Call Frame");
369 dumpBytes(f
, length
);
371 case SWFACTION_GOTOEXPRESSION
:
372 print("Goto Expression");
373 if(readUInt8(f
) == 1)
374 printf(" and Play\n");
376 printf(" and Stop\n");
378 case SWFACTION_WAITFORFRAME
:
380 int frame
= readUInt16(f
);
381 println("Wait for frame %i else skip %i", frame
, readUInt8(f
));
384 case SWFACTION_SETTARGET
:
385 println("Set Target %s", readString(f
));
387 case SWFACTION_GOTOLABEL
:
388 println("Goto Label %s", readString(f
));
395 case SWFACTION_DELETE
:
401 case SWFACTION_VAREQUALS
:
402 println("Var assign");
404 case SWFACTION_INITARRAY
:
405 println("Init array");
407 case SWFACTION_INITOBJECT
:
408 println("Init object");
410 case SWFACTION_CALLFUNCTION
:
411 println("call function");
413 case SWFACTION_RETURN
:
416 case SWFACTION_MODULO
:
422 case SWFACTION_TYPEOF
:
425 case SWFACTION_NEWADD
:
428 case SWFACTION_NEWLESSTHAN
:
429 println("new less than");
431 case SWFACTION_NEWEQUALS
:
432 println("new equals");
440 case SWFACTION_GETMEMBER
:
441 println("get member");
443 case SWFACTION_SETMEMBER
:
444 println("set member");
446 case SWFACTION_INCREMENT
:
447 println("increment");
449 case SWFACTION_CALLMETHOD
:
450 println("call method");
452 case SWFACTION_BITWISEAND
:
453 println("bitwise and");
455 case SWFACTION_BITWISEOR
:
456 println("bitwise or");
458 case SWFACTION_BITWISEXOR
:
459 println("bitwise xor");
461 case SWFACTION_SHIFTLEFT
:
462 println("shift left");
464 case SWFACTION_SHIFTRIGHT
:
465 println("shift right");
467 case SWFACTION_SHIFTRIGHT2
:
468 println("shift right 2");
471 case SWFACTION_CONSTANTPOOL
:
473 int i
, n
= readUInt16(f
);
474 print("declare dictionary:");
477 printf(" %s%c", dictionary
[i
]=readString(f
), (i
<n
-1)?',':'\n');
486 printDoAction(f
, readUInt16(f
));
491 case SWFACTION_DEFINEFUNCTION
:
493 char *name
= readString(f
);
494 int n
= readUInt16(f
);
502 printf("%s", readString(f
));
507 printf(", %s", readString(f
));
513 printDoAction(f
, readUInt16(f
));
519 case SWFACTION_ENUMERATE
:
520 println("enumerate");
523 case SWFACTION_SETREGISTER
:
524 println("set register %i", readUInt8(f
));
528 case SWFACTION_INSTANCEOF
:
529 println("instanceof");
531 case SWFACTION_STRICTEQ
:
532 println("strict_equals");
534 case SWFACTION_ENUM2
:
539 println("Unknown Action: %02X", type
);
540 dumpBytes(f
, length
);
546 void printDoAction(Buffer f
, int length
)
553 end
= fileOffset
+ length
;
555 while(fileOffset
< end
&& printActionRecord(f
))