2 Shows the structure of a swf file
4 Part of the swftools package.
6 Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
8 This file is distributed under the GPL, see file COPYING for details */
12 #ifdef HAVE_SYS_STAT_H
18 #ifdef HAVE_SYS_TYPES_H
19 #include <sys/types.h>
27 #include "../lib/rfxswf.h"
28 #include "../lib/args.h"
32 /* idtab stores the ids which are defined in the file. This allows us
33 to detect errors in the file. (i.e. ids which are defined more than
38 struct options_t options[] =
47 int args_callback_option(char*name,char*val)
49 if(!strcmp(name, "V")) {
50 printf("swfdump - part of %s %s\n", PACKAGE, VERSION);
53 else if(name[0]=='a') {
58 printf("Unknown option: -%s\n", name);
63 int args_callback_longoption(char*name,char*val)
65 return args_long2shortoption(options, name, val);
67 void args_callback_usage(char*name)
69 printf("Usage: %s [-a] file.swf\n", name);
70 printf("-h , --help\t\t\t Print help and exit\n");
71 printf("-a , --action\t\t\t Disassemble action tags\n");
72 printf("-V , --version\t\t\t Print program version and exit\n");
74 int args_callback_command(char*name,char*val)
77 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
84 int main (int argc,char ** argv)
94 memset(idtab,0,65536);
96 processargs(argc, argv);
100 fprintf(stderr, "You must supply a filename.\n");
104 f = open(filename,O_RDONLY);
108 perror("Couldn't open file: ");
111 if FAILED(swf_ReadSWF(f,&swf))
113 fprintf(stderr, "%s is not a valid SWF file or contains errors.\n",filename);
120 if(statbuf.st_size != swf.fileSize)
121 fprintf(stderr, "Error: Real Filesize (%d) doesn't match header Filesize (%d)",
122 statbuf.st_size, swf.fileSize);
127 printf("[HEADER] File version: %d\n", swf.fileVersion);
128 printf("[HEADER] File size: %ld\n", swf.fileSize);
129 printf("[HEADER] Frame rate: %f\n",swf.frameRate/256.0);
130 printf("[HEADER] Frame count: %d\n",swf.frameCount);
131 printf("[HEADER] Movie width: %.3f\n",(swf.movieSize.xmax-swf.movieSize.xmin)/20.0);
132 printf("[HEADER] Movie height: %.3f\n",(swf.movieSize.ymax-swf.movieSize.ymin)/20.0);
137 char*name = swf_TagGetName(tag);
139 fprintf(stderr, "Error: Unknown tag:0x%03x\n", tag->id);
143 printf("[%03x] %9ld %s%s", tag->id, tag->len, prefix, swf_TagGetName(tag));
145 if(swf_isDefiningTag(tag)) {
146 U16 id = swf_GetDefineID(tag);
147 printf(" defines id %04x", id);
149 fprintf(stderr, "Error: Id %04x is defined more than once.\n", id);
152 else if(tag->id == ST_PLACEOBJECT ||
153 tag->id == ST_PLACEOBJECT2) {
154 printf(" places id %04x at depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag));
155 if(swf_TagGetName(tag))
156 printf(" name \"%s\"",swf_TagGetName(tag));
158 else if(tag->id == ST_REMOVEOBJECT) {
159 printf(" removes id %04x from depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag));
161 else if(tag->id == ST_REMOVEOBJECT2) {
162 printf(" removes object from depth %04x", swf_GetDepth(tag));
167 if(tag->id == ST_DEFINESPRITE) {
168 sprintf(prefix, " ");
170 else if(tag->id == ST_END) {
173 else if(tag->id == ST_DOACTION && action) {
176 sprintf(myprefix, " %s", prefix);
178 actions = swf_GetActions(tag);
180 swf_DumpActions(actions, myprefix);