Skip to content

Commit

Permalink
Fix strange ELF loading and mips code analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Aug 28, 2012
1 parent d101eb5 commit 84c032a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 6 additions & 8 deletions libr/anal/p/anal_mips.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <r_anal.h>

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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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])) {
Expand Down
6 changes: 5 additions & 1 deletion libr/bin/p/bin_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 84c032a

Please sign in to comment.