Added the option to deassemble only executable code
This commit is contained in:
parent
d839f7268a
commit
0f27fe745e
@ -109,7 +109,7 @@ int asm_instruction(Asm * a, char const * name, unsigned int operands_cnt, ...);
|
|||||||
|
|
||||||
/* deassemble */
|
/* deassemble */
|
||||||
int asm_deassemble(Asm * a, char const * buffer, size_t size);
|
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 */
|
/* plug-in helpers */
|
||||||
int asm_plugin_list(AsmPluginType type);
|
int asm_plugin_list(AsmPluginType type);
|
||||||
|
@ -69,7 +69,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 (*decode)(FormatPlugin * format);
|
int (*decode)(FormatPlugin * format, int raw);
|
||||||
|
|
||||||
void * priv;
|
void * priv;
|
||||||
};
|
};
|
||||||
|
@ -258,7 +258,7 @@ int asm_open_assemble(Asm * a, char const * outfile)
|
|||||||
|
|
||||||
|
|
||||||
/* asm_open_deassemble */
|
/* 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
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, filename);
|
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));
|
code_get_filename(a->code));
|
||||||
if((a->code = code_new_file(a->arch, a->format, filename)) == NULL)
|
if((a->code = code_new_file(a->arch, a->format, filename)) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
if(code_decode(a->code) != 0)
|
if(code_decode(a->code, raw) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -316,11 +316,11 @@ int code_close(Code * code)
|
|||||||
|
|
||||||
|
|
||||||
/* code_decode */
|
/* 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),
|
printf("%s: %s-%s\n", code->filename, format_get_name(code->format),
|
||||||
arch_get_name(code->arch));
|
arch_get_name(code->arch));
|
||||||
return format_decode(code->format, code);
|
return format_decode(code->format, code, raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ int code_instruction(Code * code, ArchInstructionCall * call);
|
|||||||
int code_section(Code * code, char const * section);
|
int code_section(Code * code, char const * section);
|
||||||
|
|
||||||
/* disassembly */
|
/* 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,
|
int code_decode_at(Code * code, char const * section, off_t offset,
|
||||||
size_t size, off_t base);
|
size_t size, off_t base);
|
||||||
int code_decode_buffer(Code * code, char const * buffer, size_t size);
|
int code_decode_buffer(Code * code, char const * buffer, size_t size);
|
||||||
|
17
src/deasm.c
17
src/deasm.c
@ -28,8 +28,8 @@
|
|||||||
/* deasm */
|
/* deasm */
|
||||||
/* private */
|
/* private */
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static int _deasm(char const * arch, char const * format,
|
static int _deasm(char const * arch, char const * format, char const * filename,
|
||||||
char const * filename);
|
int raw);
|
||||||
static int _deasm_buffer(char const * arch, char const * format,
|
static int _deasm_buffer(char const * arch, char const * format,
|
||||||
char const * buffer, size_t size);
|
char const * buffer, size_t size);
|
||||||
static int _deasm_string(char const * arch, char const * format,
|
static int _deasm_string(char const * arch, char const * format,
|
||||||
@ -41,14 +41,15 @@ static int _usage(void);
|
|||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
/* deasm */
|
/* 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;
|
int ret;
|
||||||
Asm * a;
|
Asm * a;
|
||||||
|
|
||||||
if((a = asm_new(arch, format)) == NULL)
|
if((a = asm_new(arch, format)) == NULL)
|
||||||
return -error_print("deasm");
|
return -error_print("deasm");
|
||||||
if((ret = asm_open_deassemble(a, filename)) != 0)
|
if((ret = asm_open_deassemble(a, filename, raw)) != 0)
|
||||||
error_print("deasm");
|
error_print("deasm");
|
||||||
else
|
else
|
||||||
asm_close(a);
|
asm_close(a);
|
||||||
@ -164,8 +165,9 @@ int main(int argc, char * argv[])
|
|||||||
char const * arch = NULL;
|
char const * arch = NULL;
|
||||||
char const * format = NULL;
|
char const * format = NULL;
|
||||||
char const * string = 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)
|
switch(o)
|
||||||
{
|
{
|
||||||
case 'a':
|
case 'a':
|
||||||
@ -179,12 +181,15 @@ int main(int argc, char * argv[])
|
|||||||
case 's':
|
case 's':
|
||||||
string = optarg;
|
string = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'D':
|
||||||
|
raw = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return _usage();
|
return _usage();
|
||||||
}
|
}
|
||||||
if(optind == argc && string != NULL)
|
if(optind == argc && string != NULL)
|
||||||
return _deasm_string(arch, format, string);
|
return _deasm_string(arch, format, string);
|
||||||
else if(optind + 1 == argc && string == NULL)
|
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();
|
return _usage();
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ char const * format_get_name(Format * format)
|
|||||||
|
|
||||||
/* useful */
|
/* useful */
|
||||||
/* format_decode */
|
/* format_decode */
|
||||||
int format_decode(Format * format, Code * code)
|
int format_decode(Format * format, Code * code, int raw)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ int format_decode(Format * format, Code * code)
|
|||||||
return error_set_code(1, "%s: %s", format_get_name(format),
|
return error_set_code(1, "%s: %s", format_get_name(format),
|
||||||
"Disassembly is not supported");
|
"Disassembly is not supported");
|
||||||
format->code = code;
|
format->code = code;
|
||||||
ret = format->plugin->decode(format->plugin);
|
ret = format->plugin->decode(format->plugin, raw);
|
||||||
format->code = NULL;
|
format->code = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ int format_function(Format * format, char const * function);
|
|||||||
int format_section(Format * format, char const * section);
|
int format_section(Format * format, char const * section);
|
||||||
|
|
||||||
/* disassembly */
|
/* disassembly */
|
||||||
int format_decode(Format * format, Code * code);
|
int format_decode(Format * format, Code * code, int raw);
|
||||||
char const * format_detect_arch(Format * format);
|
char const * format_detect_arch(Format * format);
|
||||||
int format_match(Format * format);
|
int format_match(Format * format);
|
||||||
|
|
||||||
|
@ -125,7 +125,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_exit(FormatPlugin * format);
|
static int _dex_exit(FormatPlugin * format);
|
||||||
static char const * _dex_detect(FormatPlugin * format);
|
static char const * _dex_detect(FormatPlugin * format);
|
||||||
static int _dex_decode(FormatPlugin * format);
|
static int _dex_decode(FormatPlugin * format, int raw);
|
||||||
|
|
||||||
|
|
||||||
/* public */
|
/* 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,
|
static int _decode_map_string_id(FormatPlugin * format, off_t offset,
|
||||||
size_t size);
|
size_t size);
|
||||||
|
|
||||||
static int _dex_decode(FormatPlugin * format)
|
static int _dex_decode(FormatPlugin * format, int raw)
|
||||||
{
|
{
|
||||||
FormatPluginHelper * helper = format->helper;
|
FormatPluginHelper * helper = format->helper;
|
||||||
DexHeader dh;
|
DexHeader dh;
|
||||||
|
@ -76,9 +76,9 @@ static int _elf_error(FormatPlugin * format);
|
|||||||
static int _elf_init(FormatPlugin * format, char const * arch);
|
static int _elf_init(FormatPlugin * format, char const * arch);
|
||||||
static int _elf_exit(FormatPlugin * format);
|
static int _elf_exit(FormatPlugin * format);
|
||||||
static char const * _elf_detect(FormatPlugin * format);
|
static char const * _elf_detect(FormatPlugin * format);
|
||||||
static int _elf_decode(FormatPlugin * format);
|
static int _elf_decode(FormatPlugin * format, int raw);
|
||||||
static int _elf_decode32(FormatPlugin * format);
|
static int _elf_decode32(FormatPlugin * format, int raw);
|
||||||
static int _elf_decode64(FormatPlugin * format);
|
static int _elf_decode64(FormatPlugin * format, int raw);
|
||||||
|
|
||||||
/* ELF32 */
|
/* ELF32 */
|
||||||
static int _init_32(FormatPlugin * format);
|
static int _init_32(FormatPlugin * format);
|
||||||
@ -332,11 +332,11 @@ static char const * _detect_64(FormatPlugin * format, Elf64_Ehdr * ehdr)
|
|||||||
|
|
||||||
|
|
||||||
/* elf_decode */
|
/* elf_decode */
|
||||||
static int _elf_decode(FormatPlugin * format)
|
static int _elf_decode(FormatPlugin * format, int raw)
|
||||||
{
|
{
|
||||||
if(_elf_detect(format) == NULL)
|
if(_elf_detect(format) == NULL)
|
||||||
return -1;
|
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 shdr_cnt, uint16_t ndx, char ** strtab,
|
||||||
size_t * strtab_cnt);
|
size_t * strtab_cnt);
|
||||||
|
|
||||||
static int _elf_decode32(FormatPlugin * format)
|
static int _elf_decode32(FormatPlugin * format, int raw)
|
||||||
{
|
{
|
||||||
FormatPluginHelper * helper = format->helper;
|
FormatPluginHelper * helper = format->helper;
|
||||||
Elf32_Ehdr ehdr;
|
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 shdr_cnt, uint16_t ndx, char ** strtab,
|
||||||
size_t * strtab_cnt);
|
size_t * strtab_cnt);
|
||||||
|
|
||||||
static int _elf_decode64(FormatPlugin * format)
|
static int _elf_decode64(FormatPlugin * format, int raw)
|
||||||
{
|
{
|
||||||
FormatPluginHelper * helper = format->helper;
|
FormatPluginHelper * helper = format->helper;
|
||||||
Elf64_Ehdr ehdr;
|
Elf64_Ehdr ehdr;
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
/* private */
|
/* private */
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
/* plug-in */
|
/* plug-in */
|
||||||
static int _flat_decode(FormatPlugin * format);
|
static int _flat_decode(FormatPlugin * format, int raw);
|
||||||
|
|
||||||
|
|
||||||
/* public */
|
/* public */
|
||||||
@ -49,7 +49,7 @@ FormatPlugin format_plugin =
|
|||||||
/* functions */
|
/* functions */
|
||||||
/* plug-in */
|
/* plug-in */
|
||||||
/* flat_decode */
|
/* flat_decode */
|
||||||
static int _flat_decode(FormatPlugin * format)
|
static int _flat_decode(FormatPlugin * format, int raw)
|
||||||
{
|
{
|
||||||
FormatPluginHelper * helper = format->helper;
|
FormatPluginHelper * helper = format->helper;
|
||||||
off_t offset;
|
off_t offset;
|
||||||
|
@ -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_decode(FormatPlugin * format);
|
static int _java_decode(FormatPlugin * format, int raw);
|
||||||
|
|
||||||
static int _java_error(FormatPlugin * format);
|
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_fields(FormatPlugin * format, uint16_t cnt);
|
||||||
static int _decode_skip_interfaces(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;
|
FormatPluginHelper * helper = format->helper;
|
||||||
JavaHeader jh;
|
JavaHeader jh;
|
||||||
|
@ -193,7 +193,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_decode(FormatPlugin * format);
|
static int _pe_decode(FormatPlugin * format, int raw);
|
||||||
|
|
||||||
/* useful */
|
/* useful */
|
||||||
static char const * _pe_get_arch(uint16_t machine);
|
static char const * _pe_get_arch(uint16_t machine);
|
||||||
@ -277,7 +277,7 @@ static char const * _pe_detect(FormatPlugin * format)
|
|||||||
/* pe_decode */
|
/* pe_decode */
|
||||||
static int _decode_error(FormatPlugin * format);
|
static int _decode_error(FormatPlugin * format);
|
||||||
|
|
||||||
static int _pe_decode(FormatPlugin * format)
|
static int _pe_decode(FormatPlugin * format, int raw)
|
||||||
{
|
{
|
||||||
FormatPluginHelper * helper = format->helper;
|
FormatPluginHelper * helper = format->helper;
|
||||||
struct pe_msdos pm;
|
struct pe_msdos pm;
|
||||||
|
Loading…
Reference in New Issue
Block a user