Preparing to support disassembly again

This commit is contained in:
Pierre Pronchery 2011-04-23 03:51:39 +00:00
parent 53d6f4cbc3
commit b56d0f3f4e
14 changed files with 182 additions and 92 deletions

View File

@ -184,6 +184,9 @@ typedef struct _ArchPluginHelper
/* assembly */ /* assembly */
ssize_t (*write)(Arch * arch, void const * buf, size_t size); ssize_t (*write)(Arch * arch, void const * buf, size_t size);
/* disassembly */
ssize_t (*read)(Arch * arch, void * buf, size_t size);
} ArchPluginHelper; } ArchPluginHelper;
typedef struct _ArchPlugin ArchPlugin; typedef struct _ArchPlugin ArchPlugin;
@ -200,8 +203,7 @@ struct _ArchPlugin
int (*write)(ArchPlugin * arch, ArchInstruction * instruction, int (*write)(ArchPlugin * arch, ArchInstruction * instruction,
ArchInstructionCall * call); ArchInstructionCall * call);
/* FIXME complete and implement */ int (*decode)(ArchPlugin * arch, ArchInstructionCall * call);
int (*read)(ArchPlugin * arch);
}; };
#endif /* !DEVEL_ASM_ARCH_H */ #endif /* !DEVEL_ASM_ARCH_H */

View File

@ -40,7 +40,7 @@ char const * as_get_format_name(As * as);
/* useful */ /* 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_parse(As * as, char const * infile, char const * outfile);
int as_open(As * as, char const * outfile); int as_open(As * as, char const * outfile);

View File

@ -44,7 +44,7 @@ typedef struct _FormatPluginHelper
/* disassembly */ /* disassembly */
/* FIXME let a different architecture be specified in the callback */ /* 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); off_t offset, size_t size, off_t base);
} FormatPluginHelper; } FormatPluginHelper;
@ -63,7 +63,7 @@ struct _FormatPlugin
int (*section)(FormatPlugin * format, char const * section); int (*section)(FormatPlugin * format, char const * section);
char const * (*detect)(FormatPlugin * format); char const * (*detect)(FormatPlugin * format);
int (*disas)(FormatPlugin * format); int (*decode)(FormatPlugin * format);
void * priv; void * priv;
}; };

View File

@ -27,7 +27,10 @@
/* macros */ /* macros */
#ifndef abs #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 #endif
@ -45,6 +48,9 @@ struct _Arch
/* internal */ /* internal */
char const * filename; char const * filename;
FILE * fp; FILE * fp;
char const * buffer;
size_t buffer_cnt;
size_t buffer_pos;
}; };
@ -57,6 +63,7 @@ struct _Arch
/* prototypes */ /* prototypes */
/* callbacks */ /* callbacks */
static char const * _arch_get_filename(Arch * arch); 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); 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) if(a->plugin->registers != NULL)
for(; a->plugin->registers[a->registers_cnt].name != NULL; for(; a->plugin->registers[a->registers_cnt].name != NULL;
a->registers_cnt++); a->registers_cnt++);
a->filename = NULL;
a->fp = NULL;
a->buffer = NULL;
a->buffer_cnt = 0;
a->buffer_pos = 0;
return a; return a;
} }
@ -420,11 +432,36 @@ ArchRegister * arch_get_register_by_name_size(Arch * arch, char const * name,
/* useful */ /* 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 */ /* arch_exit */
int arch_exit(Arch * arch) int arch_exit(Arch * arch)
{ {
arch->filename = NULL; arch->filename = NULL;
arch->fp = NULL; arch->fp = NULL;
arch->buffer = NULL;
arch->buffer_cnt = 0;
arch->buffer_pos = 0;
memset(&arch->helper, 0, sizeof(arch->helper)); memset(&arch->helper, 0, sizeof(arch->helper));
return 0; return 0;
} }
@ -442,12 +479,33 @@ int arch_init(Arch * arch, char const * filename, FILE * fp)
arch->helper.arch = arch; arch->helper.arch = arch;
arch->helper.get_filename = _arch_get_filename; arch->helper.get_filename = _arch_get_filename;
arch->helper.get_register_by_name_size = arch_get_register_by_name_size; arch->helper.get_register_by_name_size = arch_get_register_by_name_size;
arch->helper.read = NULL;
arch->helper.write = _arch_write; arch->helper.write = _arch_write;
arch->plugin->helper = &arch->helper; arch->plugin->helper = &arch->helper;
return 0; 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 */ /* arch_write */
int arch_write(Arch * arch, ArchInstruction * instruction, int arch_write(Arch * arch, ArchInstruction * instruction,
ArchInstructionCall * call) 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 */ /* arch_write */
static ssize_t _arch_write(Arch * arch, void const * buf, size_t size) static ssize_t _arch_write(Arch * arch, void const * buf, size_t size)
{ {

View File

@ -50,9 +50,14 @@ ArchRegister * arch_get_register_by_name_size(Arch * arch, char const * name,
/* useful */ /* useful */
int arch_init(Arch * arch, char const * filename, FILE * fp); 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); int arch_exit(Arch * arch);
/* assembly */
int arch_write(Arch * arch, ArchInstruction * instruction, int arch_write(Arch * arch, ArchInstruction * instruction,
ArchInstructionCall * call); ArchInstructionCall * call);
/* disassembly */
int arch_decode(Arch * arch);
#endif /* !ASM_ARCH_H */ #endif /* !ASM_ARCH_H */

View File

@ -149,7 +149,7 @@ int as_close(As * as)
/* as_decode */ /* 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); return code_decode(as->code, buffer, size);
} }

View File

@ -128,6 +128,16 @@ int code_close(Code * code)
/* code_decode */ /* 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, static ArchInstruction * _decode_size(Code * code, size_t * size,
ArchInstruction * ai); ArchInstruction * ai);
@ -168,6 +178,7 @@ static ArchInstruction * _decode_size(Code * code, size_t * size,
*size = s; *size = s;
return ai; return ai;
} }
#endif
/* code_function */ /* code_function */

View File

@ -40,13 +40,15 @@ Format * code_get_format(Code * code);
char const * code_get_format_name(Code * code); char const * code_get_format_name(Code * code);
/* useful */ /* useful */
/* assembly */
int code_open(Code * code, char const * filename); int code_open(Code * code, char const * filename);
int code_close(Code * code); 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_function(Code * code, char const * function);
int code_instruction(Code * code, ArchInstructionCall * call); int code_instruction(Code * code, ArchInstructionCall * call);
int code_section(Code * code, char const * section); int code_section(Code * code, char const * section);
/* disassembly */
int code_decode(Code * code, char const * buffer, size_t size);
#endif /* !ASM_CODE_H */ #endif /* !ASM_CODE_H */

View File

@ -31,6 +31,7 @@ void format_delete(Format * format);
char const * format_get_name(Format * format); char const * format_get_name(Format * format);
/* useful */ /* useful */
/* assembly */
int format_init(Format * format, char const * filename, FILE * fp); int format_init(Format * format, char const * filename, FILE * fp);
int format_exit(Format * format); int format_exit(Format * format);

View File

@ -117,7 +117,7 @@ static char _dex_signature[4] = "dex\n";
static int _dex_init(FormatPlugin * format, char const * arch); static int _dex_init(FormatPlugin * format, char const * arch);
static int _dex_destroy(FormatPlugin * format); static int _dex_destroy(FormatPlugin * format);
static char const * _dex_detect(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); static int _dex_error(FormatPlugin * format);
@ -135,7 +135,7 @@ FormatPlugin format_plugin =
NULL, NULL,
NULL, NULL,
_dex_detect, _dex_detect,
_dex_disas, _dex_decode,
NULL NULL
}; };
@ -185,13 +185,13 @@ static char const * _dex_detect(FormatPlugin * format)
} }
/* dex_disas */ /* dex_decode */
static int _disas_map(FormatPlugin * format, DexHeader * dh); static int _decode_map(FormatPlugin * format, DexHeader * dh);
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);
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); size_t size);
static int _dex_disas(FormatPlugin * format) static int _dex_decode(FormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; FormatPluginHelper * helper = format->helper;
DexHeader dh; DexHeader dh;
@ -201,12 +201,12 @@ static int _dex_disas(FormatPlugin * format)
if(helper->read(helper->format, &dh, sizeof(dh)) != sizeof(dh)) if(helper->read(helper->format, &dh, sizeof(dh)) != sizeof(dh))
return -1; return -1;
dh.map_off = _htol32(dh.map_off); dh.map_off = _htol32(dh.map_off);
if(_disas_map(format, &dh) != 0) if(_decode_map(format, &dh) != 0)
return -1; return -1;
return 0; return 0;
} }
static int _disas_map(FormatPlugin * format, DexHeader * dh) static int _decode_map(FormatPlugin * format, DexHeader * dh)
{ {
int ret = 0; int ret = 0;
FormatPluginHelper * helper = format->helper; FormatPluginHelper * helper = format->helper;
@ -242,11 +242,11 @@ static int _disas_map(FormatPlugin * format, DexHeader * dh)
switch(dmi.type) switch(dmi.type)
{ {
case TYPE_CODE_ITEM: case TYPE_CODE_ITEM:
ret |= _disas_map_code(format, dmi.offset, ret |= _decode_map_code(format, dmi.offset,
dmi.size); dmi.size);
break; break;
case TYPE_STRING_ID_ITEM: case TYPE_STRING_ID_ITEM:
ret |= _disas_map_string_id(format, dmi.offset, ret |= _decode_map_string_id(format, dmi.offset,
dmi.size); dmi.size);
} }
if(helper->seek(helper->format, offset, SEEK_SET) != offset) if(helper->seek(helper->format, offset, SEEK_SET) != offset)
@ -257,7 +257,7 @@ static int _disas_map(FormatPlugin * format, DexHeader * dh)
return ret; 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; FormatPluginHelper * helper = format->helper;
DexMapCodeItem dmci; DexMapCodeItem dmci;
@ -267,7 +267,7 @@ static int _disas_map_code(FormatPlugin * format, off_t offset, size_t size)
DexMapTryItem dmti; DexMapTryItem dmti;
ssize_t s; 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; return -1;
for(i = 0; i < size; i++) 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.debug_info_off = _htol32(dmci.debug_info_off);
dmci.insns_size = _htol32(dmci.insns_size); dmci.insns_size = _htol32(dmci.insns_size);
seek = helper->seek(helper->format, 0, SEEK_CUR); 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); 0);
/* skip padding and try_items */ /* skip padding and try_items */
seek = (dmci.insns_size & 0x1) == 0x1 ? 2 : 0; 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); dmti.handler_off = _htol16(dmti.handler_off);
} }
seek = helper->seek(helper->format, 0, SEEK_CUR); 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; 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) size_t size)
{ {
FormatPluginHelper * helper = format->helper; FormatPluginHelper * helper = format->helper;

View File

@ -61,9 +61,9 @@ static int _elf_error(FormatPlugin * format);
/* plug-in */ /* plug-in */
static int _elf_init(FormatPlugin * format, char const * arch); static int _elf_init(FormatPlugin * format, char const * arch);
static char const * _elf_detect(FormatPlugin * format); static char const * _elf_detect(FormatPlugin * format);
static int _elf_disas(FormatPlugin * format); static int _elf_decode(FormatPlugin * format);
static int _elf_disas32(FormatPlugin * format); static int _elf_decode32(FormatPlugin * format);
static int _elf_disas64(FormatPlugin * format); static int _elf_decode64(FormatPlugin * format);
/* ELF32 */ /* ELF32 */
static int _init_32(FormatPlugin * format); static int _init_32(FormatPlugin * format);
@ -138,7 +138,7 @@ FormatPlugin format_plugin =
NULL, NULL,
NULL, NULL,
_elf_detect, _elf_detect,
_elf_disas, _elf_decode,
NULL NULL
}; };
@ -222,7 +222,7 @@ static char const * _elf_detect(FormatPlugin * format)
static char const * _detect_32(FormatPlugin * format, Elf32_Ehdr * ehdr) static char const * _detect_32(FormatPlugin * format, Elf32_Ehdr * ehdr)
{ {
format->disas = _elf_disas32; format->decode = _elf_decode32;
switch(ehdr->e_machine) switch(ehdr->e_machine)
{ {
case EM_386: case EM_386:
@ -237,7 +237,7 @@ static char const * _detect_32(FormatPlugin * format, Elf32_Ehdr * ehdr)
case EM_SPARC: case EM_SPARC:
return "sparc"; return "sparc";
} }
format->disas = _elf_disas; format->decode = _elf_decode;
error_set_code(1, "%s: %s 0x%x", "elf", "Unsupported ELF architecture", error_set_code(1, "%s: %s 0x%x", "elf", "Unsupported ELF architecture",
ehdr->e_machine); ehdr->e_machine);
return NULL; 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) static char const * _detect_64(FormatPlugin * format, Elf64_Ehdr * ehdr)
{ {
format->disas = _elf_disas64; format->decode = _elf_decode64;
switch(ehdr->e_machine) switch(ehdr->e_machine)
{ {
case EM_SPARC: case EM_SPARC:
@ -254,32 +254,32 @@ static char const * _detect_64(FormatPlugin * format, Elf64_Ehdr * ehdr)
case EM_X86_64: case EM_X86_64:
return "amd64"; return "amd64";
} }
format->disas = _elf_disas; format->decode = _elf_decode;
error_set_code(1, "%s: %s 0x%x", "elf", "Unsupported ELF architecture", error_set_code(1, "%s: %s 0x%x", "elf", "Unsupported ELF architecture",
ehdr->e_machine); ehdr->e_machine);
return NULL; return NULL;
} }
/* elf_disas */ /* elf_decode */
static int _elf_disas(FormatPlugin * format) static int _elf_decode(FormatPlugin * format)
{ {
if(_elf_detect(format) == NULL) if(_elf_detect(format) == NULL)
return -1; return -1;
return format->disas(format); return format->decode(format);
} }
/* elf_disas32 */ /* elf_decode32 */
static int _disas32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr, static int _decode32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr,
Elf32_Shdr ** shdr); Elf32_Shdr ** shdr);
static int _disas32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr, static int _decode32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr,
Elf32_Addr * addr); 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 shdr_cnt, uint16_t ndx, char ** strtab,
size_t * strtab_cnt); size_t * strtab_cnt);
static int _elf_disas32(FormatPlugin * format) static int _elf_decode32(FormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; FormatPluginHelper * helper = format->helper;
Elf32_Ehdr ehdr; Elf32_Ehdr ehdr;
@ -297,10 +297,10 @@ static int _elf_disas32(FormatPlugin * format)
|| helper->read(helper->format, &ehdr, sizeof(ehdr)) || helper->read(helper->format, &ehdr, sizeof(ehdr))
!= sizeof(ehdr)) != sizeof(ehdr))
return -1; return -1;
if(_disas32_shdr(format, &ehdr, &shdr) != 0) if(_decode32_shdr(format, &ehdr, &shdr) != 0)
return -1; return -1;
if(_disas32_addr(format, &ehdr, &base) != 0 if(_decode32_addr(format, &ehdr, &base) != 0
|| _disas32_strtab(format, shdr, ehdr.e_shnum, || _decode32_strtab(format, shdr, ehdr.e_shnum,
ehdr.e_shstrndx, &shstrtab, &shstrtab_cnt) ehdr.e_shstrndx, &shstrtab, &shstrtab_cnt)
!= 0) != 0)
{ {
@ -313,7 +313,7 @@ static int _elf_disas32(FormatPlugin * format)
continue; continue;
if(shdr[i].sh_type == SHT_PROGBITS if(shdr[i].sh_type == SHT_PROGBITS
&& shdr[i].sh_flags & SHF_EXECINSTR) && shdr[i].sh_flags & SHF_EXECINSTR)
helper->disas(helper->format, helper->decode(helper->format,
&shstrtab[shdr[i].sh_name], &shstrtab[shdr[i].sh_name],
shdr[i].sh_offset, shdr[i].sh_size, shdr[i].sh_offset, shdr[i].sh_size,
base); base);
@ -323,7 +323,7 @@ static int _elf_disas32(FormatPlugin * format)
return 0; return 0;
} }
static int _disas32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr, static int _decode32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr,
Elf32_Shdr ** shdr) Elf32_Shdr ** shdr)
{ {
FormatPluginHelper * helper = format->helper; FormatPluginHelper * helper = format->helper;
@ -351,7 +351,7 @@ static int _disas32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr,
return 0; return 0;
} }
static int _disas32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr, static int _decode32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr,
Elf32_Addr * addr) Elf32_Addr * addr)
{ {
FormatPluginHelper * helper = format->helper; FormatPluginHelper * helper = format->helper;
@ -373,7 +373,7 @@ static int _disas32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr,
return 0; 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 shdr_cnt, uint16_t ndx, char ** strtab,
size_t * strtab_cnt) size_t * strtab_cnt)
{ {
@ -399,16 +399,16 @@ static int _disas32_strtab(FormatPlugin * format, Elf32_Shdr * shdr,
} }
/* elf_disas64 */ /* elf_decode64 */
static int _disas64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr, static int _decode64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Shdr ** shdr); Elf64_Shdr ** shdr);
static int _disas64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr, static int _decode64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Addr * addr); 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 shdr_cnt, uint16_t ndx, char ** strtab,
size_t * strtab_cnt); size_t * strtab_cnt);
static int _elf_disas64(FormatPlugin * format) static int _elf_decode64(FormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; FormatPluginHelper * helper = format->helper;
Elf64_Ehdr ehdr; Elf64_Ehdr ehdr;
@ -426,10 +426,10 @@ static int _elf_disas64(FormatPlugin * format)
|| helper->read(helper->format, &ehdr, sizeof(ehdr)) || helper->read(helper->format, &ehdr, sizeof(ehdr))
!= sizeof(ehdr)) != sizeof(ehdr))
return -1; return -1;
if(_disas64_shdr(format, &ehdr, &shdr) != 0) if(_decode64_shdr(format, &ehdr, &shdr) != 0)
return -1; return -1;
if(_disas64_addr(format, &ehdr, &base) != 0 if(_decode64_addr(format, &ehdr, &base) != 0
|| _disas64_strtab(format, shdr, ehdr.e_shnum, || _decode64_strtab(format, shdr, ehdr.e_shnum,
ehdr.e_shstrndx, &shstrtab, &shstrtab_cnt) ehdr.e_shstrndx, &shstrtab, &shstrtab_cnt)
!= 0) != 0)
{ {
@ -442,7 +442,7 @@ static int _elf_disas64(FormatPlugin * format)
continue; continue;
if(shdr[i].sh_type == SHT_PROGBITS if(shdr[i].sh_type == SHT_PROGBITS
&& shdr[i].sh_flags & SHF_EXECINSTR) && shdr[i].sh_flags & SHF_EXECINSTR)
helper->disas(helper->format, helper->decode(helper->format,
&shstrtab[shdr[i].sh_name], &shstrtab[shdr[i].sh_name],
shdr[i].sh_offset, shdr[i].sh_size, shdr[i].sh_offset, shdr[i].sh_size,
base); base);
@ -452,7 +452,7 @@ static int _elf_disas64(FormatPlugin * format)
return 0; return 0;
} }
static int _disas64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr, static int _decode64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Shdr ** shdr) Elf64_Shdr ** shdr)
{ {
FormatPluginHelper * helper = format->helper; FormatPluginHelper * helper = format->helper;
@ -480,7 +480,7 @@ static int _disas64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr,
return 0; return 0;
} }
static int _disas64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr, static int _decode64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Addr * addr) Elf64_Addr * addr)
{ {
FormatPluginHelper * helper = format->helper; FormatPluginHelper * helper = format->helper;
@ -502,7 +502,7 @@ static int _disas64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr,
return 0; 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 shdr_cnt, uint16_t ndx, char ** strtab,
size_t * strtab_cnt) size_t * strtab_cnt)
{ {

View File

@ -24,7 +24,7 @@
/* private */ /* private */
/* prototypes */ /* prototypes */
/* plug-in */ /* plug-in */
static int _flat_disas(FormatPlugin * format); static int _flat_decode(FormatPlugin * format);
/* public */ /* public */
@ -40,7 +40,7 @@ FormatPlugin format_plugin =
NULL, NULL,
NULL, NULL,
NULL, NULL,
_flat_disas, _flat_decode,
NULL NULL
}; };
@ -48,13 +48,13 @@ FormatPlugin format_plugin =
/* private */ /* private */
/* functions */ /* functions */
/* plug-in */ /* plug-in */
/* flat_disas */ /* flat_decode */
static int _flat_disas(FormatPlugin * format) static int _flat_decode(FormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; FormatPluginHelper * helper = format->helper;
off_t offset; off_t offset;
if((offset = helper->seek(helper->format, 0, SEEK_END)) < 0) if((offset = helper->seek(helper->format, 0, SEEK_END)) < 0)
return -1; return -1;
return helper->disas(helper->format, ".data", 0, offset, 0); return helper->decode(helper->format, ".data", 0, offset, 0);
} }

View File

@ -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_init(FormatPlugin * format, char const * arch);
static int _java_exit(FormatPlugin * format); static int _java_exit(FormatPlugin * format);
static char const * _java_detect(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); static int _java_error(FormatPlugin * format);
@ -124,7 +124,7 @@ FormatPlugin format_plugin =
NULL, NULL,
NULL, NULL,
_java_detect, _java_detect,
_java_disas, _java_decode,
NULL NULL
}; };
@ -286,13 +286,13 @@ static char const * _java_detect(FormatPlugin * format)
} }
/* java_disas */ /* java_decode */
static int _disas_skip_attributes(FormatPlugin * format, uint16_t cnt); static int _decode_skip_attributes(FormatPlugin * format, uint16_t cnt);
static int _disas_skip_constants(FormatPlugin * format, uint16_t cnt); static int _decode_skip_constants(FormatPlugin * format, uint16_t cnt);
static int _disas_skip_fields(FormatPlugin * format, uint16_t cnt); static int _decode_skip_fields(FormatPlugin * format, uint16_t cnt);
static int _disas_skip_interfaces(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; FormatPluginHelper * helper = format->helper;
JavaHeader jh; JavaHeader jh;
@ -308,29 +308,29 @@ static int _java_disas(FormatPlugin * format)
return -1; return -1;
/* skip constants */ /* skip constants */
jh.cp_cnt = _htob16(jh.cp_cnt); 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; return -1;
/* skip interfaces */ /* skip interfaces */
if(helper->read(helper->format, &jh2, sizeof(jh2)) != sizeof(jh2)) if(helper->read(helper->format, &jh2, sizeof(jh2)) != sizeof(jh2))
return -1; return -1;
jh2.interfaces_cnt = _htob16(jh2.interfaces_cnt); 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; return -1;
/* skip fields */ /* skip fields */
if(helper->read(helper->format, &u16, sizeof(u16)) != sizeof(u16)) if(helper->read(helper->format, &u16, sizeof(u16)) != sizeof(u16))
return -1; return -1;
u16 = _htob16(u16); u16 = _htob16(u16);
if(_disas_skip_fields(format, u16) != 0) if(_decode_skip_fields(format, u16) != 0)
return -1; return -1;
/* disassemble the rest */ /* decodesemble the rest */
if((offset = helper->seek(helper->format, 0, SEEK_CUR)) < 0 if((offset = helper->seek(helper->format, 0, SEEK_CUR)) < 0
|| (end = helper->seek(helper->format, 0, SEEK_END)) || (end = helper->seek(helper->format, 0, SEEK_END))
< 0) < 0)
return -1; 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; FormatPluginHelper * helper = format->helper;
size_t i; size_t i;
@ -355,7 +355,7 @@ static int _disas_skip_attributes(FormatPlugin * format, uint16_t cnt)
return 0; 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; FormatPluginHelper * helper = format->helper;
size_t i; size_t i;
@ -415,7 +415,7 @@ static int _disas_skip_constants(FormatPlugin * format, uint16_t cnt)
return 0; 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; FormatPluginHelper * helper = format->helper;
size_t i; size_t i;
@ -430,12 +430,12 @@ static int _disas_skip_fields(FormatPlugin * format, uint16_t cnt)
!= sizeof(jfi)) != sizeof(jfi))
return -1; return -1;
jfi.attributes_cnt = _htob16(jfi.attributes_cnt); jfi.attributes_cnt = _htob16(jfi.attributes_cnt);
_disas_skip_attributes(format, jfi.attributes_cnt); _decode_skip_attributes(format, jfi.attributes_cnt);
} }
return 0; 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; FormatPluginHelper * helper = format->helper;
size_t i; size_t i;

View File

@ -89,7 +89,7 @@ static char const _pe_header_signature[4] = "PE\0\0";
/* plug-in */ /* plug-in */
static int _pe_init(FormatPlugin * format, char const * arch); static int _pe_init(FormatPlugin * format, char const * arch);
static char const * _pe_detect(FormatPlugin * format); static char const * _pe_detect(FormatPlugin * format);
static int _pe_disas(FormatPlugin * format); static int _pe_decode(FormatPlugin * format);
/* useful */ /* useful */
static char const * _pe_get_arch(uint16_t machine); static char const * _pe_get_arch(uint16_t machine);
@ -109,7 +109,7 @@ FormatPlugin format_plugin =
NULL, NULL,
NULL, NULL,
_pe_detect, _pe_detect,
_pe_disas, _pe_decode,
NULL NULL
}; };
@ -173,10 +173,10 @@ static char const * _detect_error(FormatPlugin * format)
} }
/* pe_disas */ /* pe_decode */
static int _disas_error(FormatPlugin * format); static int _decode_error(FormatPlugin * format);
static int _pe_disas(FormatPlugin * format) static int _pe_decode(FormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; FormatPluginHelper * helper = format->helper;
struct pe_msdos pm; struct pe_msdos pm;
@ -193,13 +193,13 @@ static int _pe_disas(FormatPlugin * format)
!= pm.offset) != pm.offset)
return -1; return -1;
if(helper->read(helper->format, &ph, sizeof(ph)) != sizeof(ph)) 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.section_cnt = _htol16(ph.section_cnt);
ph.opthdr_size = _htol16(ph.opthdr_size); ph.opthdr_size = _htol16(ph.opthdr_size);
if(ph.section_cnt > 0 && ph.opthdr_size != 0 if(ph.section_cnt > 0 && ph.opthdr_size != 0
&& helper->seek(helper->format, ph.opthdr_size, && helper->seek(helper->format, ph.opthdr_size,
SEEK_CUR) < 0) SEEK_CUR) < 0)
return _disas_error(format); return _decode_error(format);
for(i = 0; i < ph.section_cnt; i++) for(i = 0; i < ph.section_cnt; i++)
{ {
if(helper->read(helper->format, &psh, sizeof(psh)) if(helper->read(helper->format, &psh, sizeof(psh))
@ -209,13 +209,13 @@ static int _pe_disas(FormatPlugin * format)
psh.vaddr = _htol32(psh.vaddr); psh.vaddr = _htol32(psh.vaddr);
psh.raw_size = _htol32(psh.raw_size); psh.raw_size = _htol32(psh.raw_size);
psh.raw_offset = _htol32(psh.raw_offset); 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); psh.raw_size, psh.vaddr);
} }
return 0; 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( return -error_set_code(1, "%s: %s", format->helper->get_filename(
format->helper->format), strerror(errno)); format->helper->format), strerror(errno));