diff --git a/include/Asm/arch.h b/include/Asm/arch.h index 88402ce..1e52e2f 100644 --- a/include/Asm/arch.h +++ b/include/Asm/arch.h @@ -184,6 +184,9 @@ typedef struct _ArchPluginHelper /* assembly */ ssize_t (*write)(Arch * arch, void const * buf, size_t size); + + /* disassembly */ + ssize_t (*read)(Arch * arch, void * buf, size_t size); } ArchPluginHelper; typedef struct _ArchPlugin ArchPlugin; @@ -200,8 +203,7 @@ struct _ArchPlugin int (*write)(ArchPlugin * arch, ArchInstruction * instruction, ArchInstructionCall * call); - /* FIXME complete and implement */ - int (*read)(ArchPlugin * arch); + int (*decode)(ArchPlugin * arch, ArchInstructionCall * call); }; #endif /* !DEVEL_ASM_ARCH_H */ diff --git a/include/Asm/asm.h b/include/Asm/asm.h index 575e835..eab8e01 100644 --- a/include/Asm/asm.h +++ b/include/Asm/asm.h @@ -40,7 +40,7 @@ char const * as_get_format_name(As * as); /* useful */ -ArchInstruction * as_decode(As * as, char const * buffer, size_t * size); +int as_decode(As * as, char const * buffer, size_t size); int as_parse(As * as, char const * infile, char const * outfile); int as_open(As * as, char const * outfile); diff --git a/include/Asm/format.h b/include/Asm/format.h index 2683a60..ecf8e71 100644 --- a/include/Asm/format.h +++ b/include/Asm/format.h @@ -44,7 +44,7 @@ typedef struct _FormatPluginHelper /* disassembly */ /* FIXME let a different architecture be specified in the callback */ - int (*disas)(Format * format, char const * section, + int (*decode)(Format * format, char const * section, off_t offset, size_t size, off_t base); } FormatPluginHelper; @@ -63,7 +63,7 @@ struct _FormatPlugin int (*section)(FormatPlugin * format, char const * section); char const * (*detect)(FormatPlugin * format); - int (*disas)(FormatPlugin * format); + int (*decode)(FormatPlugin * format); void * priv; }; diff --git a/src/arch.c b/src/arch.c index fb43426..c357725 100644 --- a/src/arch.c +++ b/src/arch.c @@ -27,7 +27,10 @@ /* macros */ #ifndef abs -# define abs(a) ((a) >= 0 ? (a) : -(a)) +# define abs(a) ((a) >= 0 ? (a) : -(a)) +#endif +#ifndef min +# define min(a, b) ((a) < (b) ? (a) : (b)) #endif @@ -45,6 +48,9 @@ struct _Arch /* internal */ char const * filename; FILE * fp; + char const * buffer; + size_t buffer_cnt; + size_t buffer_pos; }; @@ -57,6 +63,7 @@ struct _Arch /* prototypes */ /* callbacks */ static char const * _arch_get_filename(Arch * arch); +static ssize_t _arch_read_buffer(Arch * arch, void * buf, size_t size); static ssize_t _arch_write(Arch * arch, void const * buf, size_t size); @@ -93,6 +100,11 @@ Arch * arch_new(char const * name) if(a->plugin->registers != NULL) for(; a->plugin->registers[a->registers_cnt].name != NULL; a->registers_cnt++); + a->filename = NULL; + a->fp = NULL; + a->buffer = NULL; + a->buffer_cnt = 0; + a->buffer_pos = 0; return a; } @@ -420,11 +432,36 @@ ArchRegister * arch_get_register_by_name_size(Arch * arch, char const * name, /* useful */ +/* arch_decode */ +static void _decode_print(ArchInstructionCall * call); + +int arch_decode(Arch * arch) +{ + ArchInstructionCall call; + + if(arch->plugin->decode == NULL) + return -error_set_code(1, "%s: %s", arch->plugin->name, + "Disassembly not supported"); + while(arch->plugin->decode(arch->plugin, &call) == 0) + _decode_print(&call); + return 0; +} + +static void _decode_print(ArchInstructionCall * call) +{ + /* FIXME really implement */ + printf("\t%s\n", call->name); +} + + /* arch_exit */ int arch_exit(Arch * arch) { arch->filename = NULL; arch->fp = NULL; + arch->buffer = NULL; + arch->buffer_cnt = 0; + arch->buffer_pos = 0; memset(&arch->helper, 0, sizeof(arch->helper)); return 0; } @@ -442,12 +479,33 @@ int arch_init(Arch * arch, char const * filename, FILE * fp) arch->helper.arch = arch; arch->helper.get_filename = _arch_get_filename; arch->helper.get_register_by_name_size = arch_get_register_by_name_size; + arch->helper.read = NULL; arch->helper.write = _arch_write; arch->plugin->helper = &arch->helper; return 0; } +/* arch_init */ +int arch_init_buffer(Arch * arch, char const * buffer, size_t size) +{ +#ifdef DEBUG + fprintf(stderr, "DEBUG: %s()\n", __func__); +#endif + arch->filename = "buffer"; + arch->buffer = buffer; + arch->buffer_cnt = size; + arch->buffer_pos = 0; + arch->helper.arch = arch; + arch->helper.get_filename = _arch_get_filename; + arch->helper.get_register_by_name_size = arch_get_register_by_name_size; + arch->helper.write = NULL; + arch->helper.read = _arch_read_buffer; + arch->plugin->helper = &arch->helper; + return 0; +} + + /* arch_write */ int arch_write(Arch * arch, ArchInstruction * instruction, ArchInstructionCall * call) @@ -468,6 +526,17 @@ static char const * _arch_get_filename(Arch * arch) } +/* arch_read_buffer */ +static ssize_t _arch_read_buffer(Arch * arch, void * buf, size_t size) +{ + ssize_t s = min(arch->buffer_cnt - arch->buffer_pos, size); + + memcpy(buf, &arch->buffer[arch->buffer_pos], s); + arch->buffer_pos += s; + return s; +} + + /* arch_write */ static ssize_t _arch_write(Arch * arch, void const * buf, size_t size) { diff --git a/src/arch.h b/src/arch.h index ceefe69..a174c08 100644 --- a/src/arch.h +++ b/src/arch.h @@ -50,9 +50,14 @@ ArchRegister * arch_get_register_by_name_size(Arch * arch, char const * name, /* useful */ int arch_init(Arch * arch, char const * filename, FILE * fp); +int arch_init_buffer(Arch * arch, char const * buffer, size_t size); int arch_exit(Arch * arch); +/* assembly */ int arch_write(Arch * arch, ArchInstruction * instruction, ArchInstructionCall * call); +/* disassembly */ +int arch_decode(Arch * arch); + #endif /* !ASM_ARCH_H */ diff --git a/src/asm.c b/src/asm.c index 5d4a941..8fcd393 100644 --- a/src/asm.c +++ b/src/asm.c @@ -149,7 +149,7 @@ int as_close(As * as) /* as_decode */ -ArchInstruction * as_decode(As * as, char const * buffer, size_t * size) +int as_decode(As * as, char const * buffer, size_t size) { return code_decode(as->code, buffer, size); } diff --git a/src/code.c b/src/code.c index 990797d..e0eb1ea 100644 --- a/src/code.c +++ b/src/code.c @@ -128,6 +128,16 @@ int code_close(Code * code) /* code_decode */ +int code_decode(Code * code, char const * buffer, size_t size) +{ + int ret; + + arch_init_buffer(code->arch, buffer, size); + ret = arch_decode(code->arch); + arch_exit(code->arch); + return ret; +} +#if 0 static ArchInstruction * _decode_size(Code * code, size_t * size, ArchInstruction * ai); @@ -168,6 +178,7 @@ static ArchInstruction * _decode_size(Code * code, size_t * size, *size = s; return ai; } +#endif /* code_function */ diff --git a/src/code.h b/src/code.h index e3cd689..ead452d 100644 --- a/src/code.h +++ b/src/code.h @@ -40,13 +40,15 @@ Format * code_get_format(Code * code); char const * code_get_format_name(Code * code); /* useful */ +/* assembly */ int code_open(Code * code, char const * filename); int code_close(Code * code); -ArchInstruction * code_decode(Code * code, char const * buffer, size_t * size); - int code_function(Code * code, char const * function); int code_instruction(Code * code, ArchInstructionCall * call); int code_section(Code * code, char const * section); +/* disassembly */ +int code_decode(Code * code, char const * buffer, size_t size); + #endif /* !ASM_CODE_H */ diff --git a/src/format.h b/src/format.h index 71fb350..307bc7d 100644 --- a/src/format.h +++ b/src/format.h @@ -31,6 +31,7 @@ void format_delete(Format * format); char const * format_get_name(Format * format); /* useful */ +/* assembly */ int format_init(Format * format, char const * filename, FILE * fp); int format_exit(Format * format); diff --git a/src/format/dex.c b/src/format/dex.c index d61972d..212acf8 100644 --- a/src/format/dex.c +++ b/src/format/dex.c @@ -117,7 +117,7 @@ static char _dex_signature[4] = "dex\n"; static int _dex_init(FormatPlugin * format, char const * arch); static int _dex_destroy(FormatPlugin * format); static char const * _dex_detect(FormatPlugin * format); -static int _dex_disas(FormatPlugin * format); +static int _dex_decode(FormatPlugin * format); static int _dex_error(FormatPlugin * format); @@ -135,7 +135,7 @@ FormatPlugin format_plugin = NULL, NULL, _dex_detect, - _dex_disas, + _dex_decode, NULL }; @@ -185,13 +185,13 @@ static char const * _dex_detect(FormatPlugin * format) } -/* dex_disas */ -static int _disas_map(FormatPlugin * format, DexHeader * dh); -static int _disas_map_code(FormatPlugin * format, off_t offset, size_t size); -static int _disas_map_string_id(FormatPlugin * format, off_t offset, +/* dex_decode */ +static int _decode_map(FormatPlugin * format, DexHeader * dh); +static int _decode_map_code(FormatPlugin * format, off_t offset, size_t size); +static int _decode_map_string_id(FormatPlugin * format, off_t offset, size_t size); -static int _dex_disas(FormatPlugin * format) +static int _dex_decode(FormatPlugin * format) { FormatPluginHelper * helper = format->helper; DexHeader dh; @@ -201,12 +201,12 @@ static int _dex_disas(FormatPlugin * format) if(helper->read(helper->format, &dh, sizeof(dh)) != sizeof(dh)) return -1; dh.map_off = _htol32(dh.map_off); - if(_disas_map(format, &dh) != 0) + if(_decode_map(format, &dh) != 0) return -1; return 0; } -static int _disas_map(FormatPlugin * format, DexHeader * dh) +static int _decode_map(FormatPlugin * format, DexHeader * dh) { int ret = 0; FormatPluginHelper * helper = format->helper; @@ -242,11 +242,11 @@ static int _disas_map(FormatPlugin * format, DexHeader * dh) switch(dmi.type) { case TYPE_CODE_ITEM: - ret |= _disas_map_code(format, dmi.offset, + ret |= _decode_map_code(format, dmi.offset, dmi.size); break; case TYPE_STRING_ID_ITEM: - ret |= _disas_map_string_id(format, dmi.offset, + ret |= _decode_map_string_id(format, dmi.offset, dmi.size); } if(helper->seek(helper->format, offset, SEEK_SET) != offset) @@ -257,7 +257,7 @@ static int _disas_map(FormatPlugin * format, DexHeader * dh) return ret; } -static int _disas_map_code(FormatPlugin * format, off_t offset, size_t size) +static int _decode_map_code(FormatPlugin * format, off_t offset, size_t size) { FormatPluginHelper * helper = format->helper; DexMapCodeItem dmci; @@ -267,7 +267,7 @@ static int _disas_map_code(FormatPlugin * format, off_t offset, size_t size) DexMapTryItem dmti; ssize_t s; - if(helper->disas(helper->format, ".text", offset, 0, 0) != 0) + if(helper->decode(helper->format, ".text", offset, 0, 0) != 0) return -1; for(i = 0; i < size; i++) { @@ -281,7 +281,7 @@ static int _disas_map_code(FormatPlugin * format, off_t offset, size_t size) dmci.debug_info_off = _htol32(dmci.debug_info_off); dmci.insns_size = _htol32(dmci.insns_size); seek = helper->seek(helper->format, 0, SEEK_CUR); - helper->disas(helper->format, NULL, seek, dmci.insns_size * 2, + helper->decode(helper->format, NULL, seek, dmci.insns_size * 2, 0); /* skip padding and try_items */ seek = (dmci.insns_size & 0x1) == 0x1 ? 2 : 0; @@ -307,13 +307,13 @@ static int _disas_map_code(FormatPlugin * format, off_t offset, size_t size) dmti.handler_off = _htol16(dmti.handler_off); } seek = helper->seek(helper->format, 0, SEEK_CUR); - helper->disas(helper->format, NULL, seek, 8, 0); + helper->decode(helper->format, NULL, seek, 8, 0); } } return 0; } -static int _disas_map_string_id(FormatPlugin * format, off_t offset, +static int _decode_map_string_id(FormatPlugin * format, off_t offset, size_t size) { FormatPluginHelper * helper = format->helper; diff --git a/src/format/elf.c b/src/format/elf.c index 133be52..eac61d7 100644 --- a/src/format/elf.c +++ b/src/format/elf.c @@ -61,9 +61,9 @@ static int _elf_error(FormatPlugin * format); /* plug-in */ static int _elf_init(FormatPlugin * format, char const * arch); static char const * _elf_detect(FormatPlugin * format); -static int _elf_disas(FormatPlugin * format); -static int _elf_disas32(FormatPlugin * format); -static int _elf_disas64(FormatPlugin * format); +static int _elf_decode(FormatPlugin * format); +static int _elf_decode32(FormatPlugin * format); +static int _elf_decode64(FormatPlugin * format); /* ELF32 */ static int _init_32(FormatPlugin * format); @@ -138,7 +138,7 @@ FormatPlugin format_plugin = NULL, NULL, _elf_detect, - _elf_disas, + _elf_decode, NULL }; @@ -222,7 +222,7 @@ static char const * _elf_detect(FormatPlugin * format) static char const * _detect_32(FormatPlugin * format, Elf32_Ehdr * ehdr) { - format->disas = _elf_disas32; + format->decode = _elf_decode32; switch(ehdr->e_machine) { case EM_386: @@ -237,7 +237,7 @@ static char const * _detect_32(FormatPlugin * format, Elf32_Ehdr * ehdr) case EM_SPARC: return "sparc"; } - format->disas = _elf_disas; + format->decode = _elf_decode; error_set_code(1, "%s: %s 0x%x", "elf", "Unsupported ELF architecture", ehdr->e_machine); return NULL; @@ -245,7 +245,7 @@ static char const * _detect_32(FormatPlugin * format, Elf32_Ehdr * ehdr) static char const * _detect_64(FormatPlugin * format, Elf64_Ehdr * ehdr) { - format->disas = _elf_disas64; + format->decode = _elf_decode64; switch(ehdr->e_machine) { case EM_SPARC: @@ -254,32 +254,32 @@ static char const * _detect_64(FormatPlugin * format, Elf64_Ehdr * ehdr) case EM_X86_64: return "amd64"; } - format->disas = _elf_disas; + format->decode = _elf_decode; error_set_code(1, "%s: %s 0x%x", "elf", "Unsupported ELF architecture", ehdr->e_machine); return NULL; } -/* elf_disas */ -static int _elf_disas(FormatPlugin * format) +/* elf_decode */ +static int _elf_decode(FormatPlugin * format) { if(_elf_detect(format) == NULL) return -1; - return format->disas(format); + return format->decode(format); } -/* elf_disas32 */ -static int _disas32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr, +/* elf_decode32 */ +static int _decode32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr, Elf32_Shdr ** shdr); -static int _disas32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr, +static int _decode32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr, Elf32_Addr * addr); -static int _disas32_strtab(FormatPlugin * format, Elf32_Shdr * shdr, +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_disas32(FormatPlugin * format) +static int _elf_decode32(FormatPlugin * format) { FormatPluginHelper * helper = format->helper; Elf32_Ehdr ehdr; @@ -297,10 +297,10 @@ static int _elf_disas32(FormatPlugin * format) || helper->read(helper->format, &ehdr, sizeof(ehdr)) != sizeof(ehdr)) return -1; - if(_disas32_shdr(format, &ehdr, &shdr) != 0) + if(_decode32_shdr(format, &ehdr, &shdr) != 0) return -1; - if(_disas32_addr(format, &ehdr, &base) != 0 - || _disas32_strtab(format, shdr, ehdr.e_shnum, + if(_decode32_addr(format, &ehdr, &base) != 0 + || _decode32_strtab(format, shdr, ehdr.e_shnum, ehdr.e_shstrndx, &shstrtab, &shstrtab_cnt) != 0) { @@ -313,7 +313,7 @@ static int _elf_disas32(FormatPlugin * format) continue; if(shdr[i].sh_type == SHT_PROGBITS && shdr[i].sh_flags & SHF_EXECINSTR) - helper->disas(helper->format, + helper->decode(helper->format, &shstrtab[shdr[i].sh_name], shdr[i].sh_offset, shdr[i].sh_size, base); @@ -323,7 +323,7 @@ static int _elf_disas32(FormatPlugin * format) return 0; } -static int _disas32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr, +static int _decode32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr, Elf32_Shdr ** shdr) { FormatPluginHelper * helper = format->helper; @@ -351,7 +351,7 @@ static int _disas32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr, return 0; } -static int _disas32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr, +static int _decode32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr, Elf32_Addr * addr) { FormatPluginHelper * helper = format->helper; @@ -373,7 +373,7 @@ static int _disas32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr, return 0; } -static int _disas32_strtab(FormatPlugin * format, Elf32_Shdr * shdr, +static int _decode32_strtab(FormatPlugin * format, Elf32_Shdr * shdr, size_t shdr_cnt, uint16_t ndx, char ** strtab, size_t * strtab_cnt) { @@ -399,16 +399,16 @@ static int _disas32_strtab(FormatPlugin * format, Elf32_Shdr * shdr, } -/* elf_disas64 */ -static int _disas64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr, +/* elf_decode64 */ +static int _decode64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr, Elf64_Shdr ** shdr); -static int _disas64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr, +static int _decode64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr, Elf64_Addr * addr); -static int _disas64_strtab(FormatPlugin * format, Elf64_Shdr * shdr, +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_disas64(FormatPlugin * format) +static int _elf_decode64(FormatPlugin * format) { FormatPluginHelper * helper = format->helper; Elf64_Ehdr ehdr; @@ -426,10 +426,10 @@ static int _elf_disas64(FormatPlugin * format) || helper->read(helper->format, &ehdr, sizeof(ehdr)) != sizeof(ehdr)) return -1; - if(_disas64_shdr(format, &ehdr, &shdr) != 0) + if(_decode64_shdr(format, &ehdr, &shdr) != 0) return -1; - if(_disas64_addr(format, &ehdr, &base) != 0 - || _disas64_strtab(format, shdr, ehdr.e_shnum, + if(_decode64_addr(format, &ehdr, &base) != 0 + || _decode64_strtab(format, shdr, ehdr.e_shnum, ehdr.e_shstrndx, &shstrtab, &shstrtab_cnt) != 0) { @@ -442,7 +442,7 @@ static int _elf_disas64(FormatPlugin * format) continue; if(shdr[i].sh_type == SHT_PROGBITS && shdr[i].sh_flags & SHF_EXECINSTR) - helper->disas(helper->format, + helper->decode(helper->format, &shstrtab[shdr[i].sh_name], shdr[i].sh_offset, shdr[i].sh_size, base); @@ -452,7 +452,7 @@ static int _elf_disas64(FormatPlugin * format) return 0; } -static int _disas64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr, +static int _decode64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr, Elf64_Shdr ** shdr) { FormatPluginHelper * helper = format->helper; @@ -480,7 +480,7 @@ static int _disas64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr, return 0; } -static int _disas64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr, +static int _decode64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr, Elf64_Addr * addr) { FormatPluginHelper * helper = format->helper; @@ -502,7 +502,7 @@ static int _disas64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr, return 0; } -static int _disas64_strtab(FormatPlugin * format, Elf64_Shdr * shdr, +static int _decode64_strtab(FormatPlugin * format, Elf64_Shdr * shdr, size_t shdr_cnt, uint16_t ndx, char ** strtab, size_t * strtab_cnt) { diff --git a/src/format/flat.c b/src/format/flat.c index 235846f..dd585fc 100644 --- a/src/format/flat.c +++ b/src/format/flat.c @@ -24,7 +24,7 @@ /* private */ /* prototypes */ /* plug-in */ -static int _flat_disas(FormatPlugin * format); +static int _flat_decode(FormatPlugin * format); /* public */ @@ -40,7 +40,7 @@ FormatPlugin format_plugin = NULL, NULL, NULL, - _flat_disas, + _flat_decode, NULL }; @@ -48,13 +48,13 @@ FormatPlugin format_plugin = /* private */ /* functions */ /* plug-in */ -/* flat_disas */ -static int _flat_disas(FormatPlugin * format) +/* flat_decode */ +static int _flat_decode(FormatPlugin * format) { FormatPluginHelper * helper = format->helper; off_t offset; if((offset = helper->seek(helper->format, 0, SEEK_END)) < 0) return -1; - return helper->disas(helper->format, ".data", 0, offset, 0); + return helper->decode(helper->format, ".data", 0, offset, 0); } diff --git a/src/format/java.c b/src/format/java.c index ea50dcc..fdb5295 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_disas(FormatPlugin * format); +static int _java_decode(FormatPlugin * format); static int _java_error(FormatPlugin * format); @@ -124,7 +124,7 @@ FormatPlugin format_plugin = NULL, NULL, _java_detect, - _java_disas, + _java_decode, NULL }; @@ -286,13 +286,13 @@ static char const * _java_detect(FormatPlugin * format) } -/* java_disas */ -static int _disas_skip_attributes(FormatPlugin * format, uint16_t cnt); -static int _disas_skip_constants(FormatPlugin * format, uint16_t cnt); -static int _disas_skip_fields(FormatPlugin * format, uint16_t cnt); -static int _disas_skip_interfaces(FormatPlugin * format, uint16_t cnt); +/* java_decode */ +static int _decode_skip_attributes(FormatPlugin * format, uint16_t cnt); +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_disas(FormatPlugin * format) +static int _java_decode(FormatPlugin * format) { FormatPluginHelper * helper = format->helper; JavaHeader jh; @@ -308,29 +308,29 @@ static int _java_disas(FormatPlugin * format) return -1; /* skip constants */ jh.cp_cnt = _htob16(jh.cp_cnt); - if(jh.cp_cnt > 1 && _disas_skip_constants(format, jh.cp_cnt) != 0) + if(jh.cp_cnt > 1 && _decode_skip_constants(format, jh.cp_cnt) != 0) return -1; /* skip interfaces */ if(helper->read(helper->format, &jh2, sizeof(jh2)) != sizeof(jh2)) return -1; jh2.interfaces_cnt = _htob16(jh2.interfaces_cnt); - if(_disas_skip_interfaces(format, jh2.interfaces_cnt) != 0) + if(_decode_skip_interfaces(format, jh2.interfaces_cnt) != 0) return -1; /* skip fields */ if(helper->read(helper->format, &u16, sizeof(u16)) != sizeof(u16)) return -1; u16 = _htob16(u16); - if(_disas_skip_fields(format, u16) != 0) + if(_decode_skip_fields(format, u16) != 0) return -1; - /* disassemble the rest */ + /* decodesemble the rest */ if((offset = helper->seek(helper->format, 0, SEEK_CUR)) < 0 || (end = helper->seek(helper->format, 0, SEEK_END)) < 0) return -1; - return helper->disas(helper->format, NULL, offset, end - offset, 0); + return helper->decode(helper->format, NULL, offset, end - offset, 0); } -static int _disas_skip_attributes(FormatPlugin * format, uint16_t cnt) +static int _decode_skip_attributes(FormatPlugin * format, uint16_t cnt) { FormatPluginHelper * helper = format->helper; size_t i; @@ -355,7 +355,7 @@ static int _disas_skip_attributes(FormatPlugin * format, uint16_t cnt) return 0; } -static int _disas_skip_constants(FormatPlugin * format, uint16_t cnt) +static int _decode_skip_constants(FormatPlugin * format, uint16_t cnt) { FormatPluginHelper * helper = format->helper; size_t i; @@ -415,7 +415,7 @@ static int _disas_skip_constants(FormatPlugin * format, uint16_t cnt) return 0; } -static int _disas_skip_fields(FormatPlugin * format, uint16_t cnt) +static int _decode_skip_fields(FormatPlugin * format, uint16_t cnt) { FormatPluginHelper * helper = format->helper; size_t i; @@ -430,12 +430,12 @@ static int _disas_skip_fields(FormatPlugin * format, uint16_t cnt) != sizeof(jfi)) return -1; jfi.attributes_cnt = _htob16(jfi.attributes_cnt); - _disas_skip_attributes(format, jfi.attributes_cnt); + _decode_skip_attributes(format, jfi.attributes_cnt); } return 0; } -static int _disas_skip_interfaces(FormatPlugin * format, uint16_t cnt) +static int _decode_skip_interfaces(FormatPlugin * format, uint16_t cnt) { FormatPluginHelper * helper = format->helper; size_t i; diff --git a/src/format/pe.c b/src/format/pe.c index 73eb320..a805fca 100644 --- a/src/format/pe.c +++ b/src/format/pe.c @@ -89,7 +89,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_disas(FormatPlugin * format); +static int _pe_decode(FormatPlugin * format); /* useful */ static char const * _pe_get_arch(uint16_t machine); @@ -109,7 +109,7 @@ FormatPlugin format_plugin = NULL, NULL, _pe_detect, - _pe_disas, + _pe_decode, NULL }; @@ -173,10 +173,10 @@ static char const * _detect_error(FormatPlugin * format) } -/* pe_disas */ -static int _disas_error(FormatPlugin * format); +/* pe_decode */ +static int _decode_error(FormatPlugin * format); -static int _pe_disas(FormatPlugin * format) +static int _pe_decode(FormatPlugin * format) { FormatPluginHelper * helper = format->helper; struct pe_msdos pm; @@ -193,13 +193,13 @@ static int _pe_disas(FormatPlugin * format) != pm.offset) return -1; if(helper->read(helper->format, &ph, sizeof(ph)) != sizeof(ph)) - return _disas_error(format); + return _decode_error(format); ph.section_cnt = _htol16(ph.section_cnt); ph.opthdr_size = _htol16(ph.opthdr_size); if(ph.section_cnt > 0 && ph.opthdr_size != 0 && helper->seek(helper->format, ph.opthdr_size, SEEK_CUR) < 0) - return _disas_error(format); + return _decode_error(format); for(i = 0; i < ph.section_cnt; i++) { if(helper->read(helper->format, &psh, sizeof(psh)) @@ -209,13 +209,13 @@ static int _pe_disas(FormatPlugin * format) psh.vaddr = _htol32(psh.vaddr); psh.raw_size = _htol32(psh.raw_size); psh.raw_offset = _htol32(psh.raw_offset); - helper->disas(helper->format, psh.name, psh.raw_offset, + helper->decode(helper->format, psh.name, psh.raw_offset, psh.raw_size, psh.vaddr); } return 0; } -static int _disas_error(FormatPlugin * format) +static int _decode_error(FormatPlugin * format) { return -error_set_code(1, "%s: %s", format->helper->get_filename( format->helper->format), strerror(errno));