X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fswfdump.c;h=c292c89472f9c60effaa8163cd48dd4ad33a5b98;hb=07b215b2a0b442a8f9b832b9ff94755bb6191d48;hp=1d2f7317bcfa330a4094936498610ec3646a7804;hpb=89a192e3511d3cd35bb574783a291090273a97ff;p=swftools.git diff --git a/src/swfdump.c b/src/swfdump.c index 1d2f731..c292c89 100644 --- a/src/swfdump.c +++ b/src/swfdump.c @@ -1,407 +1,202 @@ -/* swfdump.c - Shows the structure of a swf file - - Part of the swftools package. - - Copyright (c) 2001 Matthias Kramm - - This file is distributed under the GPL, see file COPYING for details */ - -#define HAVE_STAT - -#ifdef HAVE_SYS_STAT_H -#include -#else -#undef HAVE_STAT -#endif - -#ifdef HAVE_SYS_TYPES_H -#include -#else -#undef HAVE_STAT -#endif - -#include -#include -#include -#include "../lib/rfxswf.h" -#include "../lib/args.h" - -char * filename = 0; - -/* idtab stores the ids which are defined in the file. This allows us - to detect errors in the file. (i.e. ids which are defined more than - once */ -char idtab[65536]; -int action = 0; - -struct options_t options[] = -{ - {"a","action"}, - {"v","verbose"}, - {"V","version"}, - {0,0} -}; - - -int args_callback_option(char*name,char*val) -{ - if(!strcmp(name, "V")) { - printf("swfdump - part of %s %s\n", PACKAGE, VERSION); - exit(0); - } - else if(name[0]=='a') { - action = 1; - return 0; - } -} -int args_callback_longoption(char*name,char*val) -{ - return args_long2shortoption(options, name, val); -} -void args_callback_usage(char*name) -{ - printf("Usage: %s [-a] file.swf\n", name); - printf("-h , --help\t\t\t Print help and exit\n"); - printf("-a , --action\t\t\t Disassemble action tags\n"); - printf("-V , --version\t\t\t Print program version and exit\n"); -} -int args_callback_command(char*name,char*val) -{ - if(filename) { - fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n", - filename, name); - } - filename = name; - return 0; -} - -struct Action -{ - int flashversion; - char*name; - U8 op; - char*flags; -} actions[] = -{ -/* -f: frame (word) -u: url (string) -t: target (string) -l: label (string) -c: constant pool (string) -s: skip (byte) (number of actions) -m: method (byte) url:(0=none, 1=get, 2=post)/gf2:(1=play) -b: branch (word) (number of bytes) -p: type(byte), type=0:string, type=1:double -{: define function (name (string), num (word), params (num strings), codesize (word) -o: object (string) -r: register (byte) - */ -{3,"GotoFrame", 0x81, "f"}, -{4,"GotoFrame2", 0x9f, "m"}, // -1 (/Movieclip:3) -{3,"GetUrl", 0x83, "ul"}, -{4,"GetUrl2", 0x9a, "m"}, //-2 -{3,"NextFrame", 0x04, ""}, -{3,"PreviousFrame", 0x05, ""}, -{3,"Play", 0x06, ""}, -{3,"Stop", 0x07, ""}, -{3,"ToggleQuality", 0x08, ""}, -{3,"StopSounds", 0x09, ""}, -{3,"WaitForFrame", 0x8a, "fs"}, -{4,"WaitForFrame2", 0x8d, "s"}, // -1 -{3,"SetTarget", 0x8b, "t"}, -{4,"SetTarget2", 0x20, ""}, //-1 -{3,"GotoLabel", 0x8c, "l"}, -{4,"Add", 0x0a, ""}, // -2, +1 -{4,"Multiply", 0x0c, ""}, // -2, +1 -{4,"Divide", 0x0d, ""}, // -2, +1 -{4,"Subtract", 0x0b, ""}, // -2, +1 -{4,"Less", 0x0f, ""}, // -2, +1 -{4,"Equals", 0x0e, ""}, // -2, +1 -{4,"And", 0x10, ""}, // -2, +1 -{4,"Or", 0x11, ""}, // -2, +1 -{4,"Not", 0x12, ""}, // -1, +1 -{4,"StringAdd", 0x21, ""}, // -2,+1 -{4,"StringLength", 0x14, ""}, // -1, +1 -{4,"MBStringLength", 0x31}, // -1, +1 -{4,"StringEquals", 0x13, ""}, // -2, +1 -{4,"StringLess", 0x29, ""}, //-2, +1 -{4,"StringExtract", 0x15, ""}, // -3, +1 -{4,"MBStringExtract", 0x35, ""}, //-3 +1 -{4,"Push", 0x96, "p"}, // +1 -{4,"Pop", 0x17, ""}, // -1 -{4,"ToInteger", 0x18, ""}, // -1, +1 -{4,"CharToAscii", 0x32, ""}, // -1, +1 -{4,"AsciiToChar", 0x33, ""}, // -1, +1 -{4,"MBCharToAscii", 0x36, ""}, // -1, +1 -{4,"MBAsciiToChar", 0x37, ""}, // -1, +1 -{4,"Jump", 0x99, "b"}, -{4,"If", 0x9a, "b"}, // -1 -{4,"Call", 0x9e, ""}, //-1 (frame label/number) -{4,"GetVariable", 0x1c,""}, // -1, +1 -{4,"SetVariable", 0x1d,""}, // -2 -{4,"GetProperty", 0x22,""}, //-2, +1 -{4,"SetProperty", 0x23, ""}, // -3 -{4,"RemoveSprite", 0x25, ""}, //-1 -{4,"StartDrag", 0x27, ""}, // -2, -1, (-4) -{4,"EndDrag", 0x28, ""}, -{4,"CloneSprite", 0x24}, // -3 -{4,"Trace", 0x26, ""}, //-1 -{4,"GetTime", 0x34, ""}, //+1 -{4,"RandomNumber", 0x30, ""}, //-1,+1 - -{5,"Modulo", 0x3f,""}, -{5,"BitAnd", 0x60,""}, -{5,"BitLShift", 0x63,""}, -{5,"BitOr", 0x61,""}, -{5,"BitRShift", 0x64,""}, -{5,"BitURShift", 0x65,""}, -{5,"BitXor", 0x62,""},//66? -{5,"Decrement", 0x51,""}, -{5,"Increment", 0x50,""}, -{5,"PushDuplicate", 0x4c,""}, -{5,"StackSwap", 0x4d,""}, -{5,"StoreRegister", 0x87,"r"}, -{5,"CallFunction", 0x3d,""}, -{5,"DefineFunction", 0x9b, "{"}, -{5,"Return", 0x3e,""}, -{5,"GetMember", 0x4e,""}, -{5,"SetMember", 0x4f,""}, -{5,"CallMethod", 0x52,""}, -{5,"Constantpool", 0x88, "c"}, -{5,"DefineLocal", 0x3c,""}, -{5,"DefineLocal2", 0x41,""}, -{5,"Delete", 0x3a,""}, -{5,"Delete2", 0x3b,""}, -{5,"Enumerate", 0x46,""}, -{5,"Equals2", 0x49,""}, -{5,"InitArray", 0x42,""}, // InitObject? -{5,"NewMethod", 0x53,""}, -{5,"NewObject", 0x40,""}, -{5,"TargetPath", 0x45,""}, -{5,"With", 0x94, "o"}, -{5,"ToNumber", 0x4a,""}, -{5,"ToString", 0x4b,""}, -{5,"TypeOf", 0x44,""}, -{5,"Add2", 0x47,""}, -{5,"Less2", 0x48,""}, - -{5,"???", 0x9d, ""} -}; -int definedactions = sizeof(actions)/sizeof(struct Action); - -struct _ActionTAG { - U8 op; - U16 len; - U8 * data; - - struct _ActionTAG * next; - struct _ActionTAG * prev; - -} ; -typedef struct _ActionTAG ActionTAG; - -ActionTAG* showdoaction(TAG*tag, char*prefix) -{ - U8 op; - int length; - int t; - ActionTAG tmp; - ActionTAG*atag = &tmp; - U8*data; - char* cp; - while(1) - { - int pos; - atag->next = (ActionTAG*)malloc(sizeof(ActionTAG)); - atag->next->prev = atag; - atag->next->next = 0; - - op = GetU8(tag); - if(op<0x80) - length = 0; - else - length = GetU16(tag); - - if(length) { - data = malloc(length); - for(t=0;top = op; - atag->len = length; - atag->data = data; - - if(!op) - break; - - for(t=0;tid); - tag = tag->next; - continue; - } - printf("[%03x] %9d %s%s", tag->id, tag->len, prefix, getTagName(tag)); - - if(isDefiningTag(tag)) { - U16 id = GetDefineID(tag); - printf(" defines id %04x", id); - if(idtab[id]) - fprintf(stderr, "Error: Id %04x is defined more than once.\n", id); - idtab[id] = 1; - } - else if(tag->id == ST_PLACEOBJECT || - tag->id == ST_PLACEOBJECT2) { - printf(" places id %04x at depth %04x", GetPlaceID(tag), GetDepth(tag)); - if(GetName(tag)) - printf(" name \"%s\"",GetName(tag)); - } - else if(tag->id == ST_REMOVEOBJECT) { - printf(" removes id %04x from depth %04x", GetPlaceID(tag), GetDepth(tag)); - } - else if(tag->id == ST_REMOVEOBJECT2) { - printf(" removes object from depth %04x", GetDepth(tag)); - } - - printf("\n"); - - if(tag->id == ST_DEFINESPRITE) { - sprintf(prefix, " "); - } - else if(tag->id == ST_END) { - sprintf(prefix, ""); - } - else if(tag->id == ST_DOACTION && action) { - char myprefix[128]; - sprintf(myprefix, " %s", prefix); - showdoaction(tag, myprefix); - } - tag = tag->next; - } - - FreeTags(&swf); - return 0; -} - +/* swfdump.c + Shows the structure of a swf file + + Part of the swftools package. + + Copyright (c) 2001 Matthias Kramm + + This file is distributed under the GPL, see file COPYING for details */ + +#define HAVE_STAT + +#ifdef HAVE_SYS_STAT_H +#include +#else +#undef HAVE_STAT +#endif + +#ifdef HAVE_SYS_TYPES_H +#include +#else +#undef HAVE_STAT +#endif + +#include +#include +#include +#include "../lib/rfxswf.h" +#include "../lib/args.h" + +char * filename = 0; + +/* idtab stores the ids which are defined in the file. This allows us + to detect errors in the file. (i.e. ids which are defined more than + once */ +char idtab[65536]; +int action = 0; + +struct options_t options[] = +{ + {"a","action"}, + {"v","verbose"}, + {"V","version"}, + {0,0} +}; + + +int args_callback_option(char*name,char*val) +{ + if(!strcmp(name, "V")) { + printf("swfdump - part of %s %s\n", PACKAGE, VERSION); + exit(0); + } + else if(name[0]=='a') { + action = 1; + return 0; + } + else { + printf("Unknown option: -%s\n", name); + } + + return 0; +} +int args_callback_longoption(char*name,char*val) +{ + return args_long2shortoption(options, name, val); +} +void args_callback_usage(char*name) +{ + printf("Usage: %s [-a] file.swf\n", name); + printf("-h , --help\t\t\t Print help and exit\n"); + printf("-a , --action\t\t\t Disassemble action tags\n"); + printf("-V , --version\t\t\t Print program version and exit\n"); +} +int args_callback_command(char*name,char*val) +{ + if(filename) { + fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n", + filename, name); + } + filename = name; + return 0; +} + +char* what; +char* testfunc(char*str) +{ + printf("%s: %s\n", what, str); + return 0; +} + +int main (int argc,char ** argv) +{ + SWF swf; + TAG*tag; +#ifdef HAVE_STAT + struct stat statbuf; +#endif + int f; + char prefix[128]; + prefix[0] = 0; + memset(idtab,0,65536); + + processargs(argc, argv); + + if(!filename) + { + fprintf(stderr, "You must supply a filename.\n"); + return 1; + } + + f = open(filename,O_RDONLY); + + if (f<0) + { + perror("Couldn't open file: "); + exit(1); + } + if FAILED(swf_ReadSWF(f,&swf)) + { + fprintf(stderr, "%s is not a valid SWF file or contains errors.\n",filename); + close(f); + exit(1); + } + +#ifdef HAVE_STAT + fstat(f, &statbuf); + if(statbuf.st_size != swf.FileSize) + fprintf(stderr, "Error: Real Filesize (%d) doesn't match header Filesize (%d)", + statbuf.st_size, swf.FileSize); +#endif + + close(f); + + printf("[HEADER] File version: %d\n", swf.fileVersion); + printf("[HEADER] File size: %ld\n", swf.fileSize); + printf("[HEADER] Frame rate: %f\n",swf.frameRate/256.0); + printf("[HEADER] Frame count: %d\n",swf.frameCount); + printf("[HEADER] Movie width: %.3f\n",(swf.movieSize.xmax-swf.movieSize.xmin)/20.0); + printf("[HEADER] Movie height: %.3f\n",(swf.movieSize.ymax-swf.movieSize.ymin)/20.0); + + tag = swf.firstTag; + + while(tag) { + char*name = swf_TagGetName(tag); + if(!name) { + fprintf(stderr, "Error: Unknown tag:0x%03x\n", tag->id); + tag = tag->next; + continue; + } + printf("[%03x] %9ld %s%s", tag->id, tag->len, prefix, swf_TagGetName(tag)); + + if(swf_isDefiningTag(tag)) { + U16 id = swf_GetDefineID(tag); + printf(" defines id %04x", id); + if(idtab[id]) + fprintf(stderr, "Error: Id %04x is defined more than once.\n", id); + idtab[id] = 1; + } + else if(tag->id == ST_PLACEOBJECT || + tag->id == ST_PLACEOBJECT2) { + printf(" places id %04x at depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag)); + if(swf_GetName(tag)) + printf(" name \"%s\"",swf_GetName(tag)); + } + else if(tag->id == ST_REMOVEOBJECT) { + printf(" removes id %04x from depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag)); + } + else if(tag->id == ST_REMOVEOBJECT2) { + printf(" removes object from depth %04x", swf_GetDepth(tag)); + } + + printf("\n"); + + if(tag->id == ST_DEFINESPRITE) { + sprintf(prefix, " "); + } + else if(tag->id == ST_END) { + *prefix = 0; + } + else if(tag->id == ST_DOACTION && action) { + char myprefix[128]; + ActionTAG*actions; + sprintf(myprefix, " %s", prefix); + + actions = swf_GetActions(tag); + + swf_DumpActions(actions, myprefix); + +/* what = "URL"; + ActionEnumerateURLs(actions, testfunc); + what = "String"; + ActionEnumerateStrings(actions, testfunc); + what = "Target"; + ActionEnumerateTargets(actions, testfunc);*/ + } + tag = tag->next; + } + + swf_FreeTags(&swf); + return 0; +} +