bump version to 0.9.1
[rofl0r-agsutils.git] / agsdisas.c
blobbd09b0ff4f13f66b266e19519e12adb52f98c601
1 #define _GNU_SOURCE
2 #include "DataFile.h"
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include "version.h"
7 #define ADS ":::AGSdisas " VERSION " by rofl0r:::"
9 static int usage(char *argv0) {
10 dprintf(2, ADS "\nusage:\n%s [-obl] file.o [file.s]\n"
11 "pass input and optionally output filename.\n"
12 "options:\n"
13 "-o : dump offset comments in disassembly\n"
14 "-b : dump hexadecimal bytecode comments in disassembly\n"
15 "-l : remove linenumber debug assembly directives [produces smaller files]\n"
16 , argv0);
17 exit(1);
20 static void disas(char *o, char *s, int flags) {
21 //ARF_find_code_start
22 AF f_b, *f = &f_b;
23 ASI sc;
24 if(AF_open(f, o)) {
25 ASI *i = ASI_read_script(f, &sc) ? &sc : 0;
26 dprintf(1, "disassembling %s -> %s", o, s);
27 if(!i || !ASI_disassemble(f, i, s, flags)) dprintf(1, " FAIL");
28 dprintf(1, "\n");
29 AF_close(f);
33 int main(int argc, char**argv) {
34 int flags = 0, c;
35 while ((c = getopt(argc, argv, "obl")) != EOF) switch(c) {
36 case 'o': flags |= DISAS_DEBUG_OFFSETS; break;
37 case 'b': flags |= DISAS_DEBUG_BYTECODE; break;
38 case 'l': flags |= DISAS_SKIP_LINENO; break;
39 default: return usage(argv[0]);
41 if(!argv[optind]) return usage(argv[0]);
42 char *o = argv[optind], *s, out[256];
43 if(!argv[optind+1]) {
44 size_t l = strlen(o);
45 snprintf(out, 256, "%s", o);
46 out[l-1] = 's'; // overflow me!
47 s = out;
48 } else s = argv[optind+1];
49 disas(o, s, flags);
50 return 0;