Skip to content

Commit

Permalink
* r_anal // r_asm
Browse files Browse the repository at this point in the history
  - Initial AOP parser (needs more love)
  - Adds buf and inst_len to r_asm_t
  - Refactoring
* More Makefile refactoring
  • Loading branch information
jroimartin committed Feb 8, 2009
1 parent 710adba commit 389cce0
Show file tree
Hide file tree
Showing 16 changed files with 528 additions and 35 deletions.
3 changes: 2 additions & 1 deletion libr/anal/anal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
struct r_anal_t *r_anal_new()
{
struct r_anal_t *a = MALLOC_STRUCT(struct r_anal_t);
r_asm_init(a);
r_anal_init(a);
return a;
}

Expand All @@ -16,3 +16,4 @@ int r_anal_init(struct r_anal_t *a)
{
return R_TRUE;
}

1 change: 1 addition & 0 deletions libr/asm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CFLAGS+=-DLIL_ENDIAN=1
# X86
OBJ+=arch/x86/asm.o
OBJ+=arch/x86/pseudo.o
OBJ+=arch/x86/aop.o
OBJ+=arch/x86/realloc.o
# udis86
OBJ+=arch/x86/udis86/syn.o
Expand Down
10 changes: 6 additions & 4 deletions libr/asm/arch/arm/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ static int buf_fprintf(void *stream, const char *format, ...)
int r_asm_arm_disasm(struct r_asm_t *a, u8 *buf, u64 len)
{
struct disassemble_info disasm_obj;
int ret;

buf_global = a->buf_asm;
Offset = a->pc;
Expand All @@ -79,10 +78,13 @@ int r_asm_arm_disasm(struct r_asm_t *a, u8 *buf, u64 len)
disasm_obj.stream = stdout;

a->buf_asm[0]='\0';
ret = print_insn_arm((bfd_vma)Offset, &disasm_obj);
a->inst_len = print_insn_arm((bfd_vma)Offset, &disasm_obj);

if (ret == -1)
if (a->inst_len == -1)
strcpy(a->buf_asm, " (data)");

return ret;
if (a->inst_len > 0)
memcpy(a->buf, buf, a->inst_len);

return a->inst_len;
}
12 changes: 7 additions & 5 deletions libr/asm/arch/mips/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ static int buf_fprintf(void *stream, const char *format, ...)
int r_asm_mips_disasm(struct r_asm_t *a, u8 *buf, u64 len)
{
struct disassemble_info disasm_obj;
int ret;

buf_global = a->buf_asm;
Offset = a->pc;
Expand All @@ -81,11 +80,14 @@ int r_asm_mips_disasm(struct r_asm_t *a, u8 *buf, u64 len)

a->buf_asm[0]='\0';
if (a->big_endian)
ret = print_insn_big_mips((bfd_vma)Offset, &disasm_obj);
else ret = print_insn_little_mips((bfd_vma)Offset, &disasm_obj);
a->inst_len = print_insn_big_mips((bfd_vma)Offset, &disasm_obj);
else a->inst_len = print_insn_little_mips((bfd_vma)Offset, &disasm_obj);

if (ret == -1)
if (a->inst_len == -1)
strcpy(a->buf_asm, " (data)");

return ret;
if (a->inst_len > 0)
memcpy(a->buf, buf, a->inst_len);

return a->inst_len;
}
1 change: 1 addition & 0 deletions libr/asm/arch/ppc/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int r_asm_ppc_disasm(struct r_asm_t *a, u8 *buf, u64 len)
PPC_Disassemble(&dp, a->big_endian);
r_hex_bin2str((u8*)bof, 4, a->buf_hex);
sprintf(a->buf_asm, "%s %s", opcode, operands);
memcpy(a->buf, buf, 4);

return 4;
}
10 changes: 6 additions & 4 deletions libr/asm/arch/sparc/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ static int buf_fprintf(void *stream, const char *format, ...)
int r_asm_sparc_disasm(struct r_asm_t *a, u8 *buf, u64 len)
{
struct disassemble_info disasm_obj;
int ret;

buf_global = a->buf_asm;
Offset = a->pc;
Expand All @@ -78,10 +77,13 @@ int r_asm_sparc_disasm(struct r_asm_t *a, u8 *buf, u64 len)
disasm_obj.stream = stdout;

a->buf_asm[0]='\0';
ret = print_insn_sparc((bfd_vma)Offset, &disasm_obj);
a->inst_len = print_insn_sparc((bfd_vma)Offset, &disasm_obj);

if (ret == -1)
if (a->inst_len == -1)
strcpy(a->buf_asm, " (data)");

return ret;
if (a->inst_len > 0)
memcpy(a->buf, buf, a->inst_len);

return a->inst_len;
}
Loading

0 comments on commit 389cce0

Please sign in to comment.