From 84c032a40eb2aa436e140b5ac821657f2a957ba3 Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 29 Aug 2012 00:45:44 +0200 Subject: [PATCH] Fix strange ELF loading and mips code analysis --- libr/anal/p/anal_mips.c | 14 ++++++-------- libr/bin/p/bin_elf.c | 6 +++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libr/anal/p/anal_mips.c b/libr/anal/p/anal_mips.c index 5ea9b9bbca3b4..6278d5b20080c 100644 --- a/libr/anal/p/anal_mips.c +++ b/libr/anal/p/anal_mips.c @@ -7,7 +7,7 @@ #include static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len) { - unsigned long opcode; + unsigned int opcode; char buf[10]; int reg; int oplen = (anal->bits==16)?2:4; @@ -20,7 +20,6 @@ static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int le op->length = oplen; r_mem_copyendian ((ut8*)&opcode, bytes, 4, anal->big_endian); - op->type = R_ANAL_OP_TYPE_UNK; switch (opcode & 0x3f) { // J-Type @@ -30,8 +29,7 @@ static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int le //XXX TODO //eprintf("UJUMP\n"); //op->type = R_ANAL_OP_TYPE_UJMP; - break; - op->type = R_ANAL_OP_TYPE_CJMP; + op->type = R_ANAL_OP_TYPE_UJMP; break; // R-Type case 1: // bltz @@ -68,7 +66,10 @@ static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int le op->type = R_ANAL_OP_TYPE_TRAP; break; default: - switch(opcode) { + switch (opcode) { + case 0: + op->type = R_ANAL_OP_TYPE_NOP; + break; case 32: // add case 33: // addu op->type = R_ANAL_OP_TYPE_ADD; @@ -85,9 +86,6 @@ static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int le case 0x0d000000: // break op->type = R_ANAL_OP_TYPE_TRAP; break; - case 0: - op->type = R_ANAL_OP_TYPE_NOP; - break; default: //switch((opcode<<24)&0xff) { //bytes[3]) { // TODO handle endian ? switch((bytes[3])) { diff --git a/libr/bin/p/bin_elf.c b/libr/bin/p/bin_elf.c index 233620e9e1c71..2a9f2d3275991 100644 --- a/libr/bin/p/bin_elf.c +++ b/libr/bin/p/bin_elf.c @@ -91,8 +91,12 @@ static RList* sections(RBinArch *arch) { free (section); // TODO: use r_list_free here // program headers is another section - if (r_list_empty (ret)) { + if (!arch->size) { + struct Elf_(r_bin_elf_obj_t) *bin = arch->bin_obj; + if (bin) arch->size = bin->size; + else arch->size = 0x9999; // XXX hack + } if (!(ptr = R_NEW (RBinSection))) return ret; strncpy (ptr->name, "undefined", R_BIN_SIZEOF_STRINGS);