Minor improvements to Dalvik disassembly

This commit is contained in:
Pierre Pronchery 2011-04-24 02:46:12 +00:00
parent 4fd35ba7cc
commit 85fcaa2e01
5 changed files with 30 additions and 24 deletions

View File

@ -449,7 +449,7 @@ int arch_decode(Arch * arch)
if(arch->plugin->decode == NULL)
return -error_set_code(1, "%s: %s", arch->plugin->name,
"Disassembly not supported");
printf("%08lx:\n", offset);
printf("\n%08lx:\n", offset);
for(; arch->plugin->decode(arch->plugin, &call) == 0;
offset = arch->buffer_pos)
_decode_print(offset, &call);
@ -506,6 +506,8 @@ int arch_decode_at(Arch * arch, off_t offset, size_t size, off_t base)
return -error_set_code(1, "%s", strerror(ENOSYS));
if(fseek(arch->fp, offset, SEEK_SET) != 0)
return -error_set_code(1, "%s", strerror(errno));
if(size == 0)
return 0;
arch->buffer_pos = offset + base;
arch->buffer_cnt = offset + base + size;
if((ret = arch_decode(arch)) == 0

View File

@ -133,26 +133,26 @@
{ "invoke-interface", 0x72, OP1F, OP_U8, OP_U16, OP_U16 },
{ "invoke-interface-range",
0x78, OP1F, OP_U8, OP_U16, OP_U16 },
{ "invoke-static", 0x71, OP1F, OP_U8, OP_U16, OP_U16 },
{ "invoke-static/range",0x77, OP1F, OP_U8, OP_U16, OP_U16 },
{ "invoke-super", 0x6f, OP1F, OP_U8, OP_U16, OP_U16 },
{ "invoke-super/range", 0x75, OP1F, OP_U8, OP_U16, OP_U16 },
{ "invoke-virtual", 0x6e, OP1F, OP_U8, OP_U16, OP_U16 },
{ "invoke-static", 0x71, OP1F, OP_U8, OP_U16, OP_U16 },
{ "invoke-static/range",0x77, OP1F, OP_U8, OP_U16, OP_U16 },
{ "invoke-super", 0x6f, OP1F, OP_U8, OP_U16, OP_U16 },
{ "invoke-super/range", 0x75, OP1F, OP_U8, OP_U16, OP_U16 },
{ "invoke-virtual", 0x6e, OP1F, OP_U8, OP_U16, OP_U16 },
{ "invoke-virtual/range",
0x74, OP1F, OP_U8, OP_U16, OP_U16 },
{ "iput", 0x59, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "iput-boolean", 0x5c, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "iput-byte", 0x5d, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "iput-char", 0x5e, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "iput-object", 0x5b, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "iput-short", 0x5f, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "iput-wide", 0x5a, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "long-to-double", 0x86, OP1F, OP_REG4, OP_REG4, AOT_NONE },
{ "long-to-float", 0x85, OP1F, OP_REG4, OP_REG4, AOT_NONE },
{ "long-to-int", 0x84, OP1F, OP_REG4, OP_REG4, AOT_NONE },
0x74, OP1F, OP_U8, OP_U16, OP_U16 },
{ "iput", 0x59, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "iput-boolean", 0x5c, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "iput-byte", 0x5d, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "iput-char", 0x5e, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "iput-object", 0x5b, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "iput-short", 0x5f, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "iput-wide", 0x5a, OP1F, OP_REG4, OP_REG4, OP_U16 },
{ "long-to-double", 0x86, OP1F, OP_REG4, OP_REG4, AOT_NONE },
{ "long-to-float", 0x85, OP1F, OP_REG4, OP_REG4, AOT_NONE },
{ "long-to-int", 0x84, OP1F, OP_REG4, OP_REG4, AOT_NONE },
{ "monitor-enter", 0x1d, OP1F, OP_REG8, AOT_NONE, AOT_NONE },
{ "monitor-exit", 0x1e, OP1F, OP_REG8, AOT_NONE, AOT_NONE },
{ "move", 0x01, OP1F, OP_REG4, OP_REG4, AOT_NONE },
{ "move", 0x01, OP1F, OP_REG4, OP_REG4, AOT_NONE },
{ "move/16", 0x03, OP1F, OP_REG16, OP_REG8, AOT_NONE },
{ "move/from16", 0x02, OP1F, OP_REG8, OP_REG16, AOT_NONE },
{ "move-exception", 0x0d, OP1F, OP_REG8, AOT_NONE, AOT_NONE },
@ -183,7 +183,6 @@
{ "new-instance", 0x22, OP1F, OP_REG8, OP_U16, AOT_NONE },
{ "nop", 0x0000, OP2F, AOT_NONE, AOT_NONE, AOT_NONE },
#if 1 /* XXX really implement */
{ "nop", 0x00, OP1F, OP_U8, AOT_NONE, AOT_NONE },
{ "not-int", 0x7c, OP1F, OP_REG4, OP_REG4, AOT_NONE },
{ "not-long", 0x7e, OP1F, OP_REG4, OP_REG4, AOT_NONE },
#endif
@ -206,7 +205,6 @@
{ "return", 0x0f, OP1F, OP_REG8, AOT_NONE, AOT_NONE },
{ "return-object", 0x11, OP1F, OP_REG8, AOT_NONE, AOT_NONE },
{ "return-void", 0x0e00, OP2F, AOT_NONE, AOT_NONE, AOT_NONE },
{ "return-void", 0x0e, OP1F, OP_U8, AOT_NONE, AOT_NONE },
{ "return-wide", 0x10, OP1F, OP_REG8, AOT_NONE, AOT_NONE },
{ "sget", 0x60, OP1F, OP_REG8, OP_U16, AOT_NONE },
{ "sget-boolean", 0x63, OP1F, OP_REG8, OP_U16, AOT_NONE },

View File

@ -163,7 +163,6 @@ static int _decode_file_callback(void * priv, char const * section,
if(section != NULL)
printf("%s%s:\n", "\nDisassembly of section ", section);
putchar('\n');
return arch_decode_at(code->arch, offset, size, base);
}

View File

@ -136,6 +136,10 @@ int format_decode(Format * format, int (*callback)(void * priv,
static int _decode_callback(Format * format, char const * section,
off_t offset, size_t size, off_t base)
{
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\", 0x%lx, 0x%lx, 0x%lx)\n", __func__,
section, offset, size, base);
#endif
return format->decode_callback(format->decode_priv, section, offset,
size, base);
}

View File

@ -281,8 +281,9 @@ static int _decode_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->decode(helper->format, NULL, seek, dmci.insns_size * 2,
0);
if(helper->decode(helper->format, NULL, seek,
dmci.insns_size * 2, 0) != 0)
return -1;
/* skip padding and try_items */
seek = (dmci.insns_size & 0x1) == 0x1 ? 2 : 0;
#ifdef DEBUG
@ -307,7 +308,9 @@ static int _decode_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->decode(helper->format, NULL, seek, 8, 0);
if(helper->decode(helper->format, NULL, seek, 8, 0)
!= 0)
return -1;
}
}
return 0;