7 #define ADS ":::AGSdisas " VERSION " by rofl0r:::"
9 static int usage(char *argv0
) {
10 dprintf(2, ADS
"\nusage:\n%s [-oblf] file.o [file.s]\n"
11 "pass input and optionally output filename.\n"
13 "-v : verbose (show filenames)\n"
14 "-o : dump offset comments in disassembly\n"
15 "-b : dump hexadecimal bytecode comments in disassembly\n"
16 "-f : dump informative original fixups section\n"
17 "-l : remove linenumber debug assembly directives [produces smaller files]\n"
22 static int disas(char *o
, char *s
, int flags
, int verbose
) {
28 ASI
*i
= ASI_read_script(f
, &sc
) ? &sc
: 0;
29 if(verbose
) printf("disassembling %s -> %s", o
, s
);
30 if(!i
|| !ASI_disassemble(f
, i
, s
, flags
)) err
= 1;
32 if(err
) printf(" FAIL\n");
40 int main(int argc
, char**argv
) {
41 int flags
= 0, c
, verbose
= 0;
42 while ((c
= getopt(argc
, argv
, "voblf")) != EOF
) switch(c
) {
43 case 'v': verbose
= 1; break;
44 case 'o': flags
|= DISAS_DEBUG_OFFSETS
; break;
45 case 'b': flags
|= DISAS_DEBUG_BYTECODE
; break;
46 case 'l': flags
|= DISAS_SKIP_LINENO
; break;
47 case 'f': flags
|= DISAS_DEBUG_FIXUPS
; break;
48 default: return usage(argv
[0]);
50 if(!argv
[optind
]) return usage(argv
[0]);
51 char *o
= argv
[optind
], *s
, out
[256];
54 snprintf(out
, 256, "%s", o
);
55 out
[l
-1] = 's'; // overflow me!
57 } else s
= argv
[optind
+1];
59 dprintf(2, "error: input and output file (%s) identical!\n", o
);
63 return disas(o
, s
, flags
, verbose
);