diff --git a/include/Asm/asm.h b/include/Asm/asm.h index ec6ab9f..ca76cf4 100644 --- a/include/Asm/asm.h +++ b/include/Asm/asm.h @@ -109,7 +109,7 @@ int asm_instruction(Asm * a, char const * name, unsigned int operands_cnt, ...); /* deassemble */ int asm_deassemble(Asm * a, char const * buffer, size_t size); -int asm_open_deassemble(Asm * a, char const * filename); +int asm_open_deassemble(Asm * a, char const * filename, int raw); /* plug-in helpers */ int asm_plugin_list(AsmPluginType type); diff --git a/include/Asm/format.h b/include/Asm/format.h index 54f5327..1f0aa1f 100644 --- a/include/Asm/format.h +++ b/include/Asm/format.h @@ -69,7 +69,7 @@ struct _FormatPlugin int (*section)(FormatPlugin * format, char const * section); char const * (*detect)(FormatPlugin * format); - int (*decode)(FormatPlugin * format); + int (*decode)(FormatPlugin * format, int raw); void * priv; }; diff --git a/src/asm.c b/src/asm.c index d353a9e..b33a3e2 100644 --- a/src/asm.c +++ b/src/asm.c @@ -258,7 +258,7 @@ int asm_open_assemble(Asm * a, char const * outfile) /* asm_open_deassemble */ -int asm_open_deassemble(Asm * a, char const * filename) +int asm_open_deassemble(Asm * a, char const * filename, int raw) { #ifdef DEBUG fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, filename); @@ -268,7 +268,7 @@ int asm_open_deassemble(Asm * a, char const * filename) code_get_filename(a->code)); if((a->code = code_new_file(a->arch, a->format, filename)) == NULL) return -1; - if(code_decode(a->code) != 0) + if(code_decode(a->code, raw) != 0) return -1; return 0; } diff --git a/src/code.c b/src/code.c index e7d5d3d..b09c030 100644 --- a/src/code.c +++ b/src/code.c @@ -316,11 +316,11 @@ int code_close(Code * code) /* code_decode */ -int code_decode(Code * code) +int code_decode(Code * code, int raw) { printf("%s: %s-%s\n", code->filename, format_get_name(code->format), arch_get_name(code->arch)); - return format_decode(code->format, code); + return format_decode(code->format, code, raw); } diff --git a/src/code.h b/src/code.h index 8013be6..9d929a1 100644 --- a/src/code.h +++ b/src/code.h @@ -56,7 +56,7 @@ int code_instruction(Code * code, ArchInstructionCall * call); int code_section(Code * code, char const * section); /* disassembly */ -int code_decode(Code * code); +int code_decode(Code * code, int raw); int code_decode_at(Code * code, char const * section, off_t offset, size_t size, off_t base); int code_decode_buffer(Code * code, char const * buffer, size_t size); diff --git a/src/deasm.c b/src/deasm.c index f3c23ae..18a29a6 100644 --- a/src/deasm.c +++ b/src/deasm.c @@ -28,8 +28,8 @@ /* deasm */ /* private */ /* prototypes */ -static int _deasm(char const * arch, char const * format, - char const * filename); +static int _deasm(char const * arch, char const * format, char const * filename, + int raw); static int _deasm_buffer(char const * arch, char const * format, char const * buffer, size_t size); static int _deasm_string(char const * arch, char const * format, @@ -41,14 +41,15 @@ static int _usage(void); /* functions */ /* deasm */ -static int _deasm(char const * arch, char const * format, char const * filename) +static int _deasm(char const * arch, char const * format, char const * filename, + int raw) { int ret; Asm * a; if((a = asm_new(arch, format)) == NULL) return -error_print("deasm"); - if((ret = asm_open_deassemble(a, filename)) != 0) + if((ret = asm_open_deassemble(a, filename, raw)) != 0) error_print("deasm"); else asm_close(a); @@ -164,8 +165,9 @@ int main(int argc, char * argv[]) char const * arch = NULL; char const * format = NULL; char const * string = NULL; + int raw = 0; - while((o = getopt(argc, argv, "a:f:ls:")) != -1) + while((o = getopt(argc, argv, "a:f:ls:D")) != -1) switch(o) { case 'a': @@ -179,12 +181,15 @@ int main(int argc, char * argv[]) case 's': string = optarg; break; + case 'D': + raw = 1; + break; default: return _usage(); } if(optind == argc && string != NULL) return _deasm_string(arch, format, string); else if(optind + 1 == argc && string == NULL) - return (_deasm(arch, format, argv[optind]) == 0) ? 0 : 2; + return (_deasm(arch, format, argv[optind], raw) == 0) ? 0 : 2; return _usage(); } diff --git a/src/format.c b/src/format.c index 19228a7..5e7b2b4 100644 --- a/src/format.c +++ b/src/format.c @@ -129,7 +129,7 @@ char const * format_get_name(Format * format) /* useful */ /* format_decode */ -int format_decode(Format * format, Code * code) +int format_decode(Format * format, Code * code, int raw) { int ret; @@ -137,7 +137,7 @@ int format_decode(Format * format, Code * code) return error_set_code(1, "%s: %s", format_get_name(format), "Disassembly is not supported"); format->code = code; - ret = format->plugin->decode(format->plugin); + ret = format->plugin->decode(format->plugin, raw); format->code = NULL; return ret; } diff --git a/src/format.h b/src/format.h index 8009876..c2ffa2e 100644 --- a/src/format.h +++ b/src/format.h @@ -50,7 +50,7 @@ int format_function(Format * format, char const * function); int format_section(Format * format, char const * section); /* disassembly */ -int format_decode(Format * format, Code * code); +int format_decode(Format * format, Code * code, int raw); char const * format_detect_arch(Format * format); int format_match(Format * format); diff --git a/src/format/dex.c b/src/format/dex.c index eaed088..b610315 100644 --- a/src/format/dex.c +++ b/src/format/dex.c @@ -125,7 +125,7 @@ static char _dex_signature[4] = "dex\n"; static int _dex_init(FormatPlugin * format, char const * arch); static int _dex_exit(FormatPlugin * format); static char const * _dex_detect(FormatPlugin * format); -static int _dex_decode(FormatPlugin * format); +static int _dex_decode(FormatPlugin * format, int raw); /* public */ @@ -196,7 +196,7 @@ static int _decode_map_method_id(FormatPlugin * format, off_t offset, static int _decode_map_string_id(FormatPlugin * format, off_t offset, size_t size); -static int _dex_decode(FormatPlugin * format) +static int _dex_decode(FormatPlugin * format, int raw) { FormatPluginHelper * helper = format->helper; DexHeader dh; diff --git a/src/format/elf.c b/src/format/elf.c index ac375be..e6166d4 100644 --- a/src/format/elf.c +++ b/src/format/elf.c @@ -76,9 +76,9 @@ static int _elf_error(FormatPlugin * format); static int _elf_init(FormatPlugin * format, char const * arch); static int _elf_exit(FormatPlugin * format); static char const * _elf_detect(FormatPlugin * format); -static int _elf_decode(FormatPlugin * format); -static int _elf_decode32(FormatPlugin * format); -static int _elf_decode64(FormatPlugin * format); +static int _elf_decode(FormatPlugin * format, int raw); +static int _elf_decode32(FormatPlugin * format, int raw); +static int _elf_decode64(FormatPlugin * format, int raw); /* ELF32 */ static int _init_32(FormatPlugin * format); @@ -332,11 +332,11 @@ static char const * _detect_64(FormatPlugin * format, Elf64_Ehdr * ehdr) /* elf_decode */ -static int _elf_decode(FormatPlugin * format) +static int _elf_decode(FormatPlugin * format, int raw) { if(_elf_detect(format) == NULL) return -1; - return format->decode(format); + return format->decode(format, raw); } @@ -349,7 +349,7 @@ static int _decode32_strtab(FormatPlugin * format, Elf32_Shdr * shdr, size_t shdr_cnt, uint16_t ndx, char ** strtab, size_t * strtab_cnt); -static int _elf_decode32(FormatPlugin * format) +static int _elf_decode32(FormatPlugin * format, int raw) { FormatPluginHelper * helper = format->helper; Elf32_Ehdr ehdr; @@ -488,7 +488,7 @@ static int _decode64_strtab(FormatPlugin * format, Elf64_Shdr * shdr, size_t shdr_cnt, uint16_t ndx, char ** strtab, size_t * strtab_cnt); -static int _elf_decode64(FormatPlugin * format) +static int _elf_decode64(FormatPlugin * format, int raw) { FormatPluginHelper * helper = format->helper; Elf64_Ehdr ehdr; diff --git a/src/format/flat.c b/src/format/flat.c index dd585fc..b98b465 100644 --- a/src/format/flat.c +++ b/src/format/flat.c @@ -24,7 +24,7 @@ /* private */ /* prototypes */ /* plug-in */ -static int _flat_decode(FormatPlugin * format); +static int _flat_decode(FormatPlugin * format, int raw); /* public */ @@ -49,7 +49,7 @@ FormatPlugin format_plugin = /* functions */ /* plug-in */ /* flat_decode */ -static int _flat_decode(FormatPlugin * format) +static int _flat_decode(FormatPlugin * format, int raw) { FormatPluginHelper * helper = format->helper; off_t offset; diff --git a/src/format/java.c b/src/format/java.c index a3c3a33..1713ab2 100644 --- a/src/format/java.c +++ b/src/format/java.c @@ -105,7 +105,7 @@ static char _java_signature[4] = "\xca\xfe\xba\xbe"; static int _java_init(FormatPlugin * format, char const * arch); static int _java_exit(FormatPlugin * format); static char const * _java_detect(FormatPlugin * format); -static int _java_decode(FormatPlugin * format); +static int _java_decode(FormatPlugin * format, int raw); static int _java_error(FormatPlugin * format); @@ -297,7 +297,7 @@ static int _decode_skip_constants(FormatPlugin * format, uint16_t cnt); static int _decode_skip_fields(FormatPlugin * format, uint16_t cnt); static int _decode_skip_interfaces(FormatPlugin * format, uint16_t cnt); -static int _java_decode(FormatPlugin * format) +static int _java_decode(FormatPlugin * format, int raw) { FormatPluginHelper * helper = format->helper; JavaHeader jh; diff --git a/src/format/pe.c b/src/format/pe.c index 9926bcf..5f1c9eb 100644 --- a/src/format/pe.c +++ b/src/format/pe.c @@ -193,7 +193,7 @@ static char const _pe_header_signature[4] = "PE\0\0"; /* plug-in */ static int _pe_init(FormatPlugin * format, char const * arch); static char const * _pe_detect(FormatPlugin * format); -static int _pe_decode(FormatPlugin * format); +static int _pe_decode(FormatPlugin * format, int raw); /* useful */ static char const * _pe_get_arch(uint16_t machine); @@ -277,7 +277,7 @@ static char const * _pe_detect(FormatPlugin * format) /* pe_decode */ static int _decode_error(FormatPlugin * format); -static int _pe_decode(FormatPlugin * format) +static int _pe_decode(FormatPlugin * format, int raw) { FormatPluginHelper * helper = format->helper; struct pe_msdos pm;