mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-12 01:25:35 +00:00
* Add support for ARM to r_bin_mach0
* Update r_core using r_bin_meta_*
This commit is contained in:
parent
581ba0e201
commit
a536777d35
@ -172,7 +172,9 @@ static int MACH0_(r_bin_mach0_parse_thread)(struct MACH0_(r_bin_mach0_obj_t)* bi
|
||||
eprintf("Error: read (thread)\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
if (bin->hdr.cputype == CPU_TYPE_I386 || bin->hdr.cputype == CPU_TYPE_X86_64) {
|
||||
switch (bin->hdr.cputype) {
|
||||
case CPU_TYPE_I386:
|
||||
case CPU_TYPE_X86_64:
|
||||
if (bin->thread.flavor == X86_THREAD_STATE32) {
|
||||
if ((len = r_buf_fread_at(bin->b, off + sizeof(struct thread_command),
|
||||
(ut8*)&bin->thread_state.x86_32, bin->endian?"16I":"16i", 1)) == -1) {
|
||||
@ -184,29 +186,39 @@ static int MACH0_(r_bin_mach0_parse_thread)(struct MACH0_(r_bin_mach0_obj_t)* bi
|
||||
} else if (bin->thread.flavor == X86_THREAD_STATE64) {
|
||||
if ((len = r_buf_fread_at(bin->b, off + sizeof(struct thread_command),
|
||||
(ut8*)&bin->thread_state.x86_64, bin->endian?"21L":"21l", 1)) == -1) {
|
||||
eprintf("Error: read (thread state x86_32)\n");
|
||||
eprintf("Error: read (thread state x86_64)\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
bin->entry = bin->thread_state.x86_64.rip;
|
||||
}
|
||||
} else if (bin->hdr.cputype == CPU_TYPE_POWERPC || bin->hdr.cputype == CPU_TYPE_POWERPC64) {
|
||||
break;
|
||||
case CPU_TYPE_POWERPC:
|
||||
case CPU_TYPE_POWERPC64:
|
||||
if (bin->thread.flavor == X86_THREAD_STATE32) {
|
||||
if ((len = r_buf_fread_at(bin->b, off + sizeof(struct thread_command),
|
||||
(ut8*)&bin->thread_state.ppc_32, bin->endian?"40I":"40i", 1)) == -1) {
|
||||
eprintf("Error: read (thread state x86_32)\n");
|
||||
eprintf("Error: read (thread state ppc_32)\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
bin->entry = bin->thread_state.ppc_32.srr0;
|
||||
|
||||
} else if (bin->thread.flavor == X86_THREAD_STATE64) {
|
||||
if ((len = r_buf_fread_at(bin->b, off + sizeof(struct thread_command),
|
||||
(ut8*)&bin->thread_state.ppc_64, bin->endian?"34LI3LI":"34li3li", 1)) == -1) {
|
||||
eprintf("Error: read (thread state x86_32)\n");
|
||||
eprintf("Error: read (thread state ppc_64)\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
bin->entry = bin->thread_state.ppc_64.srr0;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
case CPU_TYPE_ARM:
|
||||
if ((len = r_buf_fread_at(bin->b, off + sizeof(struct thread_command),
|
||||
(ut8*)&bin->thread_state.arm, bin->endian?"17I":"17i", 1)) == -1) {
|
||||
eprintf("Error: read (thread state arm)\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
bin->entry = bin->thread_state.arm.r15;
|
||||
break;
|
||||
default:
|
||||
eprintf("Error: read (unknown thread state structure)\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ struct MACH0_(r_bin_mach0_obj_t) {
|
||||
struct x86_thread_state64 x86_64;
|
||||
struct ppc_thread_state32 ppc_32;
|
||||
struct ppc_thread_state64 ppc_64;
|
||||
struct arm_thread_state arm;
|
||||
} thread_state;
|
||||
int size;
|
||||
ut64 baddr;
|
||||
|
@ -187,6 +187,7 @@ struct mach_header_64 {
|
||||
#define CPU_TYPE_X86_64 (CPU_TYPE_X86 | CPU_ARCH_ABI64)
|
||||
#define CPU_TYPE_MC98000 ((cpu_type_t) 10)
|
||||
#define CPU_TYPE_HPPA ((cpu_type_t) 11)
|
||||
#define CPU_TYPE_ARM ((cpu_type_t) 12)
|
||||
#define CPU_TYPE_MC88000 ((cpu_type_t) 13)
|
||||
#define CPU_TYPE_SPARC ((cpu_type_t) 14)
|
||||
#define CPU_TYPE_I860 ((cpu_type_t) 15)
|
||||
@ -773,6 +774,9 @@ struct x86_thread_state64 {
|
||||
uint64_t gs;
|
||||
};
|
||||
|
||||
#define X86_THREAD_STATE32 1
|
||||
#define X86_THREAD_STATE64 4
|
||||
|
||||
struct ppc_thread_state32 {
|
||||
uint32_t srr0; /* Instruction address register (PC) */
|
||||
uint32_t srr1; /* Machine state register (supervisor) */
|
||||
@ -862,9 +866,25 @@ struct ppc_thread_state64 {
|
||||
uint32_t vrsave; /* Vector Save Register */
|
||||
};
|
||||
|
||||
|
||||
#define X86_THREAD_STATE32 1
|
||||
#define X86_THREAD_STATE64 4
|
||||
struct arm_thread_state {
|
||||
uint32_t r0;
|
||||
uint32_t r1;
|
||||
uint32_t r2;
|
||||
uint32_t r3;
|
||||
uint32_t r4;
|
||||
uint32_t r5;
|
||||
uint32_t r6;
|
||||
uint32_t r7;
|
||||
uint32_t r8;
|
||||
uint32_t r9;
|
||||
uint32_t r10;
|
||||
uint32_t r11;
|
||||
uint32_t r12;
|
||||
uint32_t r13;
|
||||
uint32_t r14;
|
||||
uint32_t r15;
|
||||
uint32_t r16; /* Apple's thread_state has this 17th reg, bug?? */
|
||||
};
|
||||
|
||||
/*
|
||||
* The routines command contains the address of the dynamic shared library
|
||||
|
@ -155,7 +155,7 @@ static int rabin_show_symbols(ut64 at) {
|
||||
else if (!strncmp (symbol->type,"OBJECT", 6))
|
||||
printf ("Cd %lli @ 0x%08llx\n",
|
||||
symbol->size, va?baddr+symbol->rva:symbol->offset);
|
||||
printf ("f sym.%s %lli @ 0x%08llx\n",
|
||||
printf ("f sym.%s %lli 0x%08llx\n",
|
||||
symbol->name, symbol->size,
|
||||
va?baddr+symbol->rva:symbol->offset);
|
||||
} else printf ("f sym.%s @ 0x%08llx\n",
|
||||
|
@ -1410,21 +1410,17 @@ static int cmd_open(void *data, const char *input)
|
||||
static int cmd_meta(void *data, const char *input)
|
||||
{
|
||||
struct r_core_t *core = (struct r_core_t *)data;
|
||||
//int ret, line = 0;
|
||||
//char file[1024];
|
||||
//struct r_core_t *core = (struct r_core_t *)data;
|
||||
int ret, line = 0;
|
||||
char file[1024];
|
||||
switch(input[0]) {
|
||||
case '*':
|
||||
r_meta_list(&core->meta, R_META_ANY);
|
||||
break;
|
||||
case 'L': // debug information of current offset
|
||||
#warning TODO: Implement new bininfo interface here
|
||||
#if 0
|
||||
ret = r_bininfo_get_line(
|
||||
&core->bininfo, core->offset, file, 1023, &line);
|
||||
ret = r_bin_meta_get_line(
|
||||
&core->bin, core->offset, file, 1023, &line);
|
||||
if (ret)
|
||||
r_cons_printf("file %s\nline %d\n", file, line);
|
||||
#endif
|
||||
break;
|
||||
case 'C': /* add comment */
|
||||
// TODO: do we need to get the size? or the offset?
|
||||
|
@ -128,7 +128,6 @@ R_API int r_core_init(struct r_core_t *core)
|
||||
r_parse_init (&core->parser);
|
||||
r_parse_set_user_ptr (&core->parser, core);
|
||||
r_bin_init (&core->bin);
|
||||
//r_bininfo_init (&core->bininfo);
|
||||
r_bin_set_user_ptr (&core->bin, core);
|
||||
r_meta_init (&core->meta);
|
||||
r_cons_init ();
|
||||
|
@ -31,8 +31,6 @@ R_API struct r_core_file_t *r_core_file_open(struct r_core_t *r, const char *fil
|
||||
list_add (&(fh->list), &r->files);
|
||||
|
||||
r_bin_load (&r->bin, fh->filename, NULL);
|
||||
// DEPRECATED XXX: detect plugin automagically or set it in config.c
|
||||
//r_bininfo_open (&r->bininfo, fh->filename, 0, "addr2line");
|
||||
|
||||
r_core_block_read (r, 0);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user