WIP - Totally remove host endianness dependence
- Adds endian aware functions - Removes references to host endian - Uses binary detected endianness else tries LE and restricts by RAsmPlugin - Fixes gdb debugger endianness when debugging BE qemu gdbserver Signed-off-by: Damien Zammit <damien@zamaudio.com>
This commit is contained in:
parent
1b29487ba6
commit
af0a865d9f
127 changed files with 920 additions and 729 deletions
|
|
@ -74,6 +74,7 @@ This release comes with contributions from the following people:
|
|||
- ampotos
|
||||
- capi_x
|
||||
- cosarara
|
||||
- damo22
|
||||
- dso (Adam Pridgen)
|
||||
- dunhame
|
||||
- dx
|
||||
|
|
|
|||
|
|
@ -332,6 +332,7 @@ int main (int argc, char *argv[]) {
|
|||
const char *env_bits = r_sys_getenv ("RASM2_BITS");
|
||||
unsigned char buf[R_ASM_BUFSIZE];
|
||||
char *arch = NULL, *file = NULL, *filters = NULL, *kernel = NULL, *cpu = NULL, *tmp;
|
||||
bool isbig = false;
|
||||
ut64 offset = 0;
|
||||
int fd = -1, dis = 0, ascii = 0, bin = 0, ret = 0, bits = 32, c, whatsop = 0;
|
||||
ut64 len = 0, idx = 0, skip = 0;
|
||||
|
|
@ -377,8 +378,8 @@ int main (int argc, char *argv[]) {
|
|||
r_asm_set_bits (a, sysbits);
|
||||
r_anal_set_bits (anal, sysbits);
|
||||
}
|
||||
r_asm_set_big_endian (a, false);
|
||||
r_anal_set_big_endian (anal, false);
|
||||
isbig = r_asm_set_big_endian (a, false);
|
||||
r_anal_set_big_endian (anal, isbig);
|
||||
|
||||
while ((c = getopt (argc, argv, "Ai:k:DCc:eEva:b:s:do:Bl:hjLf:F:wO:")) != -1) {
|
||||
switch (c) {
|
||||
|
|
@ -407,7 +408,8 @@ int main (int argc, char *argv[]) {
|
|||
dis = 2;
|
||||
break;
|
||||
case 'e':
|
||||
r_asm_set_big_endian (a, !a->big_endian);
|
||||
isbig = r_asm_set_big_endian (a, true);
|
||||
r_anal_set_big_endian (anal, isbig);
|
||||
break;
|
||||
case 'E':
|
||||
dis = 3;
|
||||
|
|
|
|||
|
|
@ -15,16 +15,14 @@ static int rax (char *str, int len, int last);
|
|||
|
||||
static int format_output (char mode, const char *s) {
|
||||
ut64 n = r_num_math (num, s);
|
||||
const char *str = (char*)&n;
|
||||
char strbits[65];
|
||||
|
||||
if (force_mode)
|
||||
mode = force_mode;
|
||||
|
||||
if (flags & 2) {
|
||||
/* swap endian */
|
||||
ut32 n2 = (n >> 32) ? 8 : 4;
|
||||
r_mem_copyendian ((ut8*)str, (ut8*)str, n2, 0);
|
||||
ut64 n2 = n;
|
||||
r_mem_swapendian ((ut8*)&n, (ut8*)&n2, (n >> 32) ? 8 : 4);
|
||||
}
|
||||
switch (mode) {
|
||||
case 'I': printf ("%"PFMT64d"\n", n); break;
|
||||
|
|
@ -307,7 +305,6 @@ static int rax (char *str, int len, int last) {
|
|||
} else if (flags & 2048) { // -t
|
||||
ut32 n = r_num_math (num, str);
|
||||
RPrint *p = r_print_new ();
|
||||
r_mem_copyendian ((ut8*) &n, (ut8*) &n, 4, !(flags & 2));
|
||||
r_print_date_unix (p, (const ut8*)&n, sizeof (ut32));
|
||||
r_print_free (p);
|
||||
return true;
|
||||
|
|
|
|||
68
doc/endian
Normal file
68
doc/endian
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
Endian issues
|
||||
=============
|
||||
|
||||
As hackers, we need to be aware of endianness.
|
||||
|
||||
Endianness can become a problem when you try to process buffers or streams
|
||||
of bytes and store intermediate values as integers with width larger than
|
||||
a single byte.
|
||||
|
||||
It can seem very easy to write the following code:
|
||||
|
||||
ut8 opcode[4] = {0x10, 0x20, 0x30, 0x40};
|
||||
ut32 value = *(ut32*)opcode;
|
||||
|
||||
... and then continue to use "value" in the code to represent the opcode.
|
||||
|
||||
This needs to be avoided!
|
||||
|
||||
Why? What is actually happening?
|
||||
|
||||
When you cast the opcode stream to a unsigned int, the compiler uses the endianness
|
||||
of the host to interpret the bytes and stores it in host endianness. This leads to
|
||||
very unportable code, because if you compile on a different endian machine, the
|
||||
value stored in "value" might be 0x40302010 instead of 0x10203040.
|
||||
|
||||
In the past, radare devs were not as strict about this issue, and as a result,
|
||||
needed to swap the endian of values regularly in the code.
|
||||
|
||||
Solution
|
||||
========
|
||||
|
||||
Use bitshifts and OR instructions to interpret bytes in a known endian.
|
||||
Instead of casting streams of bytes to larger width integers, do the following:
|
||||
|
||||
ut8 opcode[4] = {0x10, 0x20, 0x30, 0x40};
|
||||
ut32 value = opcode[0] | opcode[1] << 8 | opcode[2] << 16 | opcode[3] << 24;
|
||||
|
||||
or if you prefer the other endian:
|
||||
|
||||
ut32 value = opcode[3] | opcode[2] << 8 | opcode[1] << 16 | opcode[0] << 24;
|
||||
|
||||
This is much better because you actually know which endian your bytes are stored in
|
||||
within the integer value, REGARDLESS of the host endian of the machine.
|
||||
|
||||
|
||||
Endian helper functions
|
||||
=======================
|
||||
|
||||
Radare2 now uses helper functions to interpret all byte streams in a known endian.
|
||||
|
||||
Please use these at all times, eg:
|
||||
|
||||
val32 = r_read_be32(buffer) // reads 4 bytes from a stream in BE
|
||||
val32 = r_read_le32(buffer) // reads 4 bytes from a stream in LE
|
||||
val32 = r_read_ble32(buffer, isbig) // reads 4 bytes from a stream:
|
||||
// if isbig is true, reads in BE
|
||||
// otherwise reads in LE
|
||||
|
||||
There are a number of helper functions for 64, 32, 16, and 8 bit reads and writes.
|
||||
|
||||
(Note that 8 bit reads are equivalent to casting a single byte of the buffer
|
||||
to a ut8 value, ie endian is irrelevant).
|
||||
|
||||
Happy hacking!
|
||||
|
||||
- damo22
|
||||
|
||||
|
||||
|
|
@ -187,3 +187,6 @@ Run a command with unspecified long sequence of 'a', pancake will be summoned an
|
|||
In r2land usability is treated as a bug
|
||||
radare2 is WYSIWYF - what you see is what you fix
|
||||
Your endian swaps
|
||||
*(ut64*)buffer ought to be illegal
|
||||
MY ENDIAN IS HUUUGE
|
||||
enlarge your endian
|
||||
|
|
@ -27,3 +27,4 @@ less stupid than putting CO2 in your ass.
|
|||
Puritans, ruining everything since the 16th century.
|
||||
Better fuck a watermelon.
|
||||
Can you deal with an ascii penis?
|
||||
two girls one endian
|
||||
|
|
@ -113,7 +113,6 @@ R_API RAnal *r_anal_new() {
|
|||
anal->refs = r_anal_ref_list_new ();
|
||||
anal->types = r_anal_type_list_new ();
|
||||
r_anal_set_bits (anal, 32);
|
||||
r_anal_set_big_endian (anal, false);
|
||||
anal->plugins = r_list_newf ((RListFree) r_anal_plugin_free);
|
||||
if (anal->plugins) {
|
||||
for (i=0; anal_static_plugins[i]; i++) {
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ static int is_string(const ut8 *buf, int size, int *len) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int is_number(const ut8 *buf, int endian, int size) {
|
||||
ut64 n = r_mem_get_num (buf, size, endian);
|
||||
static int is_number(const ut8 *buf, int size) {
|
||||
ut64 n = r_mem_get_num (buf, size);
|
||||
return (n < UT32_MAX)? (int)n: 0;
|
||||
}
|
||||
|
||||
|
|
@ -48,12 +48,13 @@ static int is_invalid(const ut8 *buf, int size) {
|
|||
}
|
||||
|
||||
#define USE_IS_VALID_OFFSET 1
|
||||
static ut64 is_pointer(RIOBind *iob, const ut8 *buf, int endian, int size) {
|
||||
static ut64 is_pointer(RAnal *anal, const ut8 *buf, int size) {
|
||||
ut64 n;
|
||||
ut8 buf2[32];
|
||||
RIOBind *iob = &anal->iob;
|
||||
if (size > sizeof (buf2))
|
||||
size = sizeof (buf2);
|
||||
n = r_mem_get_num (buf, size, endian);
|
||||
n = r_mem_get_num (buf, size);
|
||||
if (!n) return 1; // null pointer
|
||||
#if USE_IS_VALID_OFFSET
|
||||
int r = iob->is_valid_offset (iob->io, n, 0);
|
||||
|
|
@ -227,7 +228,6 @@ R_API RAnalData *r_anal_data(RAnal *anal, ut64 addr, const ut8 *buf, int size) {
|
|||
ut64 dst = 0;
|
||||
int n, nsize = 0;
|
||||
int bits = anal->bits;
|
||||
int endi = !anal->big_endian;
|
||||
int word = R_MIN (8, bits / 8);
|
||||
|
||||
if (size < 4)
|
||||
|
|
@ -266,7 +266,7 @@ R_API RAnalData *r_anal_data(RAnal *anal, ut64 addr, const ut8 *buf, int size) {
|
|||
return r_anal_data_new (addr, R_ANAL_DATA_TYPE_HEADER, -1,
|
||||
buf, word);
|
||||
if (size >= word) {
|
||||
dst = is_pointer (&anal->iob, buf, endi, word);
|
||||
dst = is_pointer (anal, buf, word);
|
||||
if (dst) return r_anal_data_new (addr,
|
||||
R_ANAL_DATA_TYPE_POINTER, dst, buf, word);
|
||||
}
|
||||
|
|
@ -277,7 +277,7 @@ R_API RAnalData *r_anal_data(RAnal *anal, ut64 addr, const ut8 *buf, int size) {
|
|||
nsize, R_ANAL_DATA_TYPE_WIDE_STRING);
|
||||
}
|
||||
if (size >= word) {
|
||||
n = is_number (buf, endi, word);
|
||||
n = is_number (buf, word);
|
||||
if (n) return r_anal_data_new (addr, R_ANAL_DATA_TYPE_NUMBER,
|
||||
n, buf, word);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1379,12 +1379,8 @@ static int esil_deceq(RAnalEsil *esil) {
|
|||
static int esil_poke_n(RAnalEsil *esil, int bits) {
|
||||
ut64 bitmask = genmask (bits - 1);
|
||||
ut64 num, addr;
|
||||
union {
|
||||
ut8 byte;
|
||||
ut16 word;
|
||||
ut32 dword;
|
||||
ut64 qword;
|
||||
} n, n2;
|
||||
ut8 b[sizeof(ut64)];
|
||||
ut64 n;
|
||||
char *dst = r_anal_esil_pop (esil);
|
||||
char *src = r_anal_esil_pop (esil);
|
||||
int bytes = bits / 8, ret = 0;
|
||||
|
|
@ -1398,16 +1394,15 @@ static int esil_poke_n(RAnalEsil *esil, int bits) {
|
|||
if (dst && r_anal_esil_get_parm (esil, dst, &addr)) {
|
||||
int type = r_anal_esil_get_parm_type (esil, src);
|
||||
if (type != R_ANAL_ESIL_PARM_INTERNAL) {
|
||||
n.qword = n2.qword = 0;
|
||||
r_anal_esil_mem_read (esil, addr, (ut8 *)&n, bytes);
|
||||
r_mem_copyendian ((ut8 *)&n2, (ut8 *)&n, bytes, !esil->anal->big_endian);
|
||||
esil->old = n2.qword;
|
||||
r_anal_esil_mem_read (esil, addr, b, bytes);
|
||||
n = r_read_ble64 (b, esil->anal->big_endian);
|
||||
esil->old = n;
|
||||
esil->cur = (num & bitmask);
|
||||
esil->lastsz = bits;
|
||||
num = num & bitmask;
|
||||
}
|
||||
r_mem_copyendian ((ut8 *)&n, (ut8 *)&num, bytes, !esil->anal->big_endian);
|
||||
ret = r_anal_esil_mem_write (esil, addr, (const ut8 *)&n, bytes);
|
||||
r_write_ble64 (b, num, esil->anal->big_endian);
|
||||
ret = r_anal_esil_mem_write (esil, addr, b, bytes);
|
||||
}
|
||||
}
|
||||
free (src);
|
||||
|
|
@ -1433,30 +1428,31 @@ static int esil_poke(RAnalEsil *esil) {
|
|||
|
||||
static int esil_poke_some(RAnalEsil *esil) {
|
||||
int i, ret = 0;
|
||||
int regsize;
|
||||
ut64 ptr, regs;
|
||||
char *count, *dst = r_anal_esil_pop (esil);
|
||||
if (dst) {
|
||||
if (dst && r_anal_esil_get_parm_size (esil, dst, NULL, ®size)) {
|
||||
ut8 bytes = regsize / 8;
|
||||
// reg
|
||||
isregornum (esil, dst, &ptr);
|
||||
count = r_anal_esil_pop (esil);
|
||||
if (count) {
|
||||
isregornum (esil, count, ®s);
|
||||
if (regs > 0) {
|
||||
ut8 b[bytes];
|
||||
ut64 num64;
|
||||
ut32 num32;
|
||||
for (i = 0; i < regs; i++) {
|
||||
char *foo = r_anal_esil_pop (esil);
|
||||
isregornum (esil, foo, &num64);
|
||||
/* TODO: implement peek here */
|
||||
// read from $dst
|
||||
num32 = num64;
|
||||
ret = r_anal_esil_mem_write (esil, ptr,
|
||||
(const ut8 *)&num32, sizeof (num32));
|
||||
if (ret != sizeof (num32)) {
|
||||
r_write_ble64 (b, num64, esil->anal->big_endian);
|
||||
ret = r_anal_esil_mem_write (esil, ptr, b, bytes);
|
||||
if (ret != bytes) {
|
||||
//eprintf ("Cannot write at 0x%08" PFMT64x "\n", ptr);
|
||||
esil->trap = 1;
|
||||
}
|
||||
ptr += 4;
|
||||
ptr += bytes;
|
||||
free (foo);
|
||||
}
|
||||
}
|
||||
|
|
@ -1481,9 +1477,11 @@ static int esil_peek_n(RAnalEsil *esil, int bits) {
|
|||
return 0;
|
||||
}
|
||||
if (dst && isregornum (esil, dst, &addr)) {
|
||||
ut64 a, b, bitmask = genmask (bits - 1);
|
||||
ret = r_anal_esil_mem_read (esil, addr, (ut8 *)&a, bytes);
|
||||
r_mem_copyendian ((ut8 *)&b, (const ut8 *)&a, bytes, !esil->anal->big_endian);
|
||||
ut64 bitmask = genmask (bits - 1);
|
||||
ut8 a[sizeof(ut64)];
|
||||
ut64 b;
|
||||
ret = r_anal_esil_mem_read (esil, addr, a, bytes);
|
||||
b = r_read_ble64 (a, esil->anal->big_endian);
|
||||
snprintf (res, sizeof (res), "0x%" PFMT64x, b & bitmask);
|
||||
r_anal_esil_push (esil, res);
|
||||
esil->lastsz = bits;
|
||||
|
|
@ -1521,20 +1519,21 @@ static int esil_peek_some(RAnalEsil *esil) {
|
|||
isregornum (esil, count, ®s);
|
||||
if (regs > 0) {
|
||||
ut32 num32;
|
||||
ut8 a[sizeof (ut32)];
|
||||
for (i = 0; i < regs; i++) {
|
||||
char *foo = r_anal_esil_pop (esil);
|
||||
if (!foo) {
|
||||
ERR ("Cannot pop in peek");
|
||||
return 0;
|
||||
}
|
||||
ret = r_anal_esil_mem_read (esil, ptr,
|
||||
(ut8 *)&num32, sizeof (num32));
|
||||
if (ret == sizeof (num32)) {
|
||||
ret = r_anal_esil_mem_read (esil, ptr, a, 4);
|
||||
if (ret == sizeof (ut32)) {
|
||||
num32 = r_read_ble32 (a, esil->anal->big_endian);
|
||||
r_anal_esil_reg_write (esil, foo, num32);
|
||||
} else {
|
||||
eprintf ("Cannot peek from 0x%08" PFMT64x "\n", ptr);
|
||||
}
|
||||
ptr += 4;
|
||||
ptr += sizeof (ut32);
|
||||
free (foo);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,9 +229,14 @@ static int try_walkthrough_jmptbl(RAnal *anal, RAnalFunction *fcn, int depth, ut
|
|||
ut64 offs, sz = anal->bits >> 3;
|
||||
if (!jmptbl) return 0;
|
||||
anal->iob.read_at (anal->iob.io, ptr, jmptbl, MAX_JMPTBL_SIZE);
|
||||
for (offs = 0; offs < MAX_JMPTBL_SIZE; offs += sz) {
|
||||
ut64 jmpptr = 0;
|
||||
r_mem_copyendian ((ut8*)&jmpptr, jmptbl + offs, sz, !anal->big_endian);
|
||||
for (offs = 0; offs + sz - 1 < MAX_JMPTBL_SIZE; offs += sz) {
|
||||
ut64 jmpptr;
|
||||
switch (sz) {
|
||||
case 1: jmpptr = r_read_le8 (jmptbl + offs); break;
|
||||
case 2: jmpptr = r_read_le16 (jmptbl + offs); break;
|
||||
case 4: jmpptr = r_read_le32 (jmptbl + offs); break;
|
||||
default: jmpptr = r_read_le64 (jmptbl + offs); break;
|
||||
}
|
||||
if (anal->limit) {
|
||||
if (jmpptr < anal->limit->from || jmpptr > anal->limit->to)
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ static void h8300_anal_jmp(RAnalOp *op, ut64 addr, const ut8 *buf) {
|
|||
break;
|
||||
case H8300_JMP_2:
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
r_mem_copyendian((ut8*)&ad, buf + 2, sizeof(ut16), !LIL_ENDIAN);
|
||||
r_mem_swapendian ((ut8*)&ad, buf + 2, sizeof (ut16));
|
||||
op->jump = ad;
|
||||
break;
|
||||
case H8300_JMP_3:
|
||||
|
|
@ -72,8 +72,7 @@ static void h8300_anal_jsr(RAnalOp *op, ut64 addr, const ut8 *buf) {
|
|||
break;
|
||||
case H8300_JSR_2:
|
||||
op->type = R_ANAL_OP_TYPE_CALL;
|
||||
r_mem_copyendian((ut8*)&ad, buf + 2,
|
||||
sizeof(ut16), !LIL_ENDIAN);
|
||||
r_mem_swapendian ((ut8*)&ad, buf + 2, sizeof (ut16));
|
||||
op->jump = ad;
|
||||
op->fail = addr + 4;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -19,9 +19,8 @@ static const char* mips_reg_decode(unsigned reg_num) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b_in, int len) {
|
||||
static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len) {
|
||||
unsigned int opcode;
|
||||
ut8 b[4];
|
||||
// WIP char buf[10]; int reg; int family;
|
||||
int optype, oplen = (anal->bits==16)?2:4;
|
||||
|
||||
|
|
@ -35,10 +34,8 @@ static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b_in, int len
|
|||
op->addr = addr;
|
||||
r_strbuf_init (&op->esil);
|
||||
|
||||
// Reminder: r_mem_copyendian swaps if arg `endian` ==0 ...
|
||||
// When anal->big_endian is "false", as for mipsel architecture, we NEED to swap here for the below analysis to work.
|
||||
r_mem_copyendian ((ut8*)&opcode, b_in, 4, anal->big_endian ? 1 : 0);
|
||||
r_mem_copyendian (b, b_in, 4, anal->big_endian ? 1 : 0);
|
||||
// Be endian aware
|
||||
opcode = r_read_ble32 (b, anal->big_endian);
|
||||
|
||||
// eprintf ("MIPS: %02x %02x %02x %02x (after endian: big=%d)\n", b[0], b[1], b[2], b[3], anal->big_endian);
|
||||
if (opcode == 0) {
|
||||
|
|
|
|||
|
|
@ -7,11 +7,8 @@
|
|||
|
||||
// NOTE: buf should be at least 16 bytes!
|
||||
// XXX addr should be off_t for 64 love
|
||||
static int ppc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *_bytes, int len) {
|
||||
static int ppc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len) {
|
||||
//int arch_ppc_op(ut64 addr, const u8 *bytes, struct op_t *op)
|
||||
// TODO swap endian here??
|
||||
char bytes[1024];
|
||||
r_mem_copyendian ((ut8*)bytes, _bytes, 4, 1);
|
||||
// XXX hack
|
||||
int opcode = (bytes[0] & 0xf8) >> 3; // bytes 0-5
|
||||
short baddr = ((bytes[2]<<8) | (bytes[3]&0xfc));// 16-29
|
||||
|
|
|
|||
|
|
@ -51,16 +51,15 @@ static struct riscv_opcode *get_opcode (insn_t word) {
|
|||
static int riscv_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) {
|
||||
const int no_alias = 1;
|
||||
struct riscv_opcode *o = NULL;
|
||||
insn_t word = 0;
|
||||
ut64 word = 0;
|
||||
int xlen = anal->bits;
|
||||
|
||||
op->size = 4;
|
||||
op->addr = addr;
|
||||
op->type = R_ANAL_OP_TYPE_UNK;
|
||||
|
||||
if (len>=sizeof (word))
|
||||
r_mem_copyendian ((void*)&word, (const void*)data, sizeof (word), true);
|
||||
else r_mem_copyendian ((void*)&word, (const void*)data, 2, true); //sizeof (word), true);
|
||||
word = (len >= sizeof (ut64))? r_read_ble64 (data, anal->big_endian): r_read_ble16 (data, anal->big_endian);
|
||||
|
||||
o = get_opcode (word);
|
||||
if (word == UT64_MAX) {
|
||||
op->type = R_ANAL_OP_TYPE_ILL;
|
||||
|
|
|
|||
|
|
@ -766,8 +766,8 @@ static int sh_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len)
|
|||
|
||||
op->size = 2;
|
||||
|
||||
op_MSB = (anal->big_endian)? data[0]:data[1];
|
||||
op_LSB = (anal->big_endian)? data[1]:data[0];
|
||||
op_MSB = anal->big_endian? data[0]: data[1];
|
||||
op_LSB = anal->big_endian? data[1]: data[0];
|
||||
ret = first_nibble_decode[(op_MSB>>4) & 0x0F](anal, op, (ut16)(op_MSB<<8 | op_LSB));
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -379,7 +379,7 @@ static int sparc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
|
|||
op->jump = op->fail = -1;
|
||||
op->ptr = op->val = -1;
|
||||
|
||||
if(LIL_ENDIAN) {
|
||||
if(!anal->big_endian) {
|
||||
((char*)&insn)[0] = data[3];
|
||||
((char*)&insn)[1] = data[2];
|
||||
((char*)&insn)[2] = data[1];
|
||||
|
|
|
|||
|
|
@ -45,9 +45,10 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len)
|
|||
ret = op->size = v810_decode_command (buf, len, &cmd);
|
||||
if (ret <= 0) return ret;
|
||||
|
||||
r_mem_copyendian ((ut8*)&word1, buf, 2, LIL_ENDIAN);
|
||||
word1 = r_read_ble16 (buf, anal->big_endian);
|
||||
|
||||
if (ret == 4)
|
||||
r_mem_copyendian ((ut8*)&word2, buf + 2, 2, LIL_ENDIAN);
|
||||
word2 = r_read_ble16 (buf+2, anal->big_endian);
|
||||
|
||||
op->addr = addr;
|
||||
op->jump = op->fail = -1;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr,
|
|||
op->jump = op->fail = -1;
|
||||
op->ptr = op->val = -1;
|
||||
|
||||
r_mem_copyendian ((ut8*)&word1, buf, 2, LIL_ENDIAN);
|
||||
word1 = r_read_ble16 (buf, anal->big_endian);
|
||||
|
||||
switch ((word1 >> 5) & 0x3F) {
|
||||
case V850_MOV_IMM5:
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ R_API int r_anal_value_set_ut64(RAnal *anal, RAnalValue *val, ut64 num) {
|
|||
if (anal->iob.io) {
|
||||
ut8 data[8];
|
||||
ut64 addr = r_anal_value_to_ut64 (anal, val);
|
||||
r_mem_set_num (data, val->memref, num, anal->big_endian);
|
||||
r_mem_set_num (data, val->memref, num);
|
||||
anal->iob.write_at (anal->iob.io, addr, data, val->memref);
|
||||
} else eprintf ("No IO binded to r_anal\n");
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -245,9 +245,7 @@ static ut32 getshift(const char *str) {
|
|||
}
|
||||
}
|
||||
|
||||
r_mem_copyendian ((ut8*)&shift, (const ut8*)&i, sizeof (ut32), 0);
|
||||
|
||||
return shift;
|
||||
return i;
|
||||
}
|
||||
|
||||
static void arm_opcode_parse(ArmOpcode *ao, const char *str) {
|
||||
|
|
@ -404,8 +402,8 @@ static int thumb_assemble(ArmOpcode *ao, const char *str) {
|
|||
return 0;
|
||||
}
|
||||
ut16 opcode = 0xe000 | ((delta / 2) & 0x7ff); //11bit offset>>1
|
||||
ao->o = opcode >>8;
|
||||
ao->o |= (opcode & 0xff)<<8; // (ut32) ao->o holds the opcode in little-endian format !?
|
||||
ao->o = opcode >> 8;
|
||||
ao->o |= (opcode & 0xff) << 8; // XXX (ut32) ao->o holds the opcode in little-endian format !?
|
||||
return 2;
|
||||
} else
|
||||
if (!strcmpnull (ao->op, "bx")) {
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ static inline int cr16_decode_i_r(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
int ret = 2;
|
||||
ut16 in, immed, dstreg;
|
||||
|
||||
r_mem_copyendian((ut8*)&in, instr, 2, LIL_ENDIAN);
|
||||
in = r_read_le16 (instr);
|
||||
|
||||
if (in == 0x0200)
|
||||
return -1;
|
||||
|
|
@ -440,8 +440,7 @@ static inline int cr16_decode_i_r(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
switch((in & 0x1F) ^ 0x11) {
|
||||
case 0:
|
||||
if ((in & 0x1) == 0x1) {
|
||||
r_mem_copyendian((ut8*)&immed, instr + 2,
|
||||
2, LIL_ENDIAN);
|
||||
immed = r_read_at_le16 (instr, 2);
|
||||
ret = 4;
|
||||
} else {
|
||||
immed = cr16_get_short_imm(in);
|
||||
|
|
@ -487,7 +486,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
ut32 disp32;
|
||||
ut16 c, disp16;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
if (cr16_print_ld_sw_opcode(cmd, c)) {
|
||||
return -1;
|
||||
|
|
@ -500,7 +499,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
ret = -1;
|
||||
break;
|
||||
}
|
||||
r_mem_copyendian((ut8*)&disp16, instr + 2, 2, LIL_ENDIAN);
|
||||
disp16 = r_read_at_le16 (instr, 2);
|
||||
|
||||
disp32 = disp16 | ((c & 0x0100) << 9) | ((c & 0x0020) << 11);
|
||||
|
||||
|
|
@ -508,7 +507,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
break;
|
||||
case 0x05:
|
||||
ret = 4;
|
||||
r_mem_copyendian((ut8*)&disp16, instr + 2, 2, LIL_ENDIAN);
|
||||
disp16 = r_read_at_le16 (instr, 2);
|
||||
|
||||
if (cr16_print_short_reg_rel(cmd, cr16_get_srcreg(c),
|
||||
disp16, cr16_get_dstreg(c) & 0x9)) {
|
||||
|
|
@ -541,7 +540,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
ret = -1;
|
||||
break;
|
||||
}
|
||||
r_mem_copyendian((ut8*)&disp16, instr + 2, 2, LIL_ENDIAN);
|
||||
disp16 = r_read_at_le16 (instr, 2);
|
||||
disp32 = disp16 | (((c >> 9) & 0x3) << 16);
|
||||
|
||||
cr16_print_reg_rel_reg(cmd, disp32, cr16_get_srcreg(c),
|
||||
|
|
@ -550,7 +549,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
|
||||
case 0x13:
|
||||
ret = 4;
|
||||
r_mem_copyendian((ut8*)&disp16, instr + 2, 2, LIL_ENDIAN);
|
||||
disp16 = r_read_at_le16 (instr, 2);
|
||||
disp32 = disp16 | (((c >> 9) & 0x3) << 16);
|
||||
|
||||
if (cr16_get_srcreg(c) == 0xF) {
|
||||
|
|
@ -562,7 +561,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
break;
|
||||
case 0x1B:
|
||||
ret = 4;
|
||||
r_mem_copyendian((ut8*)&disp16, instr + 2, 2, LIL_ENDIAN);
|
||||
disp16 = r_read_at_le16 (instr, 2);
|
||||
disp32 = disp16 | (((c >> 9) & 0x3) << 16);
|
||||
|
||||
if (cr16_get_srcreg(c) == 0xF) {
|
||||
|
|
@ -574,7 +573,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
break;
|
||||
case 0x1A:
|
||||
ret = 4;
|
||||
r_mem_copyendian((ut8*)&disp16, instr + 2, 2, LIL_ENDIAN);
|
||||
disp16 = r_read_at_le16 (instr, 2);
|
||||
disp32 = disp16 | (((c >> 9) & 0x3) << 16);
|
||||
|
||||
cr16_print_reg_rel_reg(cmd, disp32, cr16_get_srcreg(c),
|
||||
|
|
@ -613,7 +612,7 @@ static int cr16_decode_slpr(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
int ret = 2;
|
||||
ut16 c;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "%s",
|
||||
instrs_4bit[c >> 9]);
|
||||
|
|
@ -641,7 +640,7 @@ static int cr16_decode_r_r(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
int ret = 2;
|
||||
ut16 c;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
if (!(c & 0x1)) {
|
||||
return -1;
|
||||
|
|
@ -675,7 +674,7 @@ static int cr16_decode_push_pop(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
int ret = 2;
|
||||
ut16 c;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
if ((c & 1)) {
|
||||
return -1;
|
||||
|
|
@ -706,7 +705,7 @@ static int cr16_decode_jmp(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
ut16 c;
|
||||
int ret = 2;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
switch (c >> 9) {
|
||||
case CR16_JUMP:
|
||||
|
|
@ -764,7 +763,7 @@ static int cr16_decode_bcond_br(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
ut16 c, disp;
|
||||
ut32 disp32;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
if (c & 0x1)
|
||||
return -1;
|
||||
|
|
@ -775,7 +774,7 @@ static int cr16_decode_bcond_br(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
if (((c >> 5) & 0xF) == 0xE) {
|
||||
snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "br");
|
||||
if (((c >> 1) & 0x7) == 0x7) {
|
||||
r_mem_copyendian((ut8*)&disp, instr + 2, 2, LIL_ENDIAN);
|
||||
disp = r_read_at_le16 (instr, 2);
|
||||
|
||||
disp32 = disp | (((c >> 4) & 0x1) << 16);
|
||||
ret = 4;
|
||||
|
|
@ -791,7 +790,7 @@ static int cr16_decode_bcond_br(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
} else {
|
||||
if (cr16_get_opcode_i(c)) {
|
||||
ret = 4;
|
||||
r_mem_copyendian((ut8*)&disp, instr + 2, 2, LIL_ENDIAN);
|
||||
disp = r_read_at_le16 (instr, 2);
|
||||
disp32 = disp | (((c >> 1) & 0x7) << 17) | (((c >> 4) & 1) << 16);
|
||||
if (disp32 & 0x80000) {
|
||||
disp32 |= 0xFFF00000;
|
||||
|
|
@ -821,7 +820,7 @@ static int cr16_decode_bcond_br(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
return -1;
|
||||
|
||||
if ((c >> 8) == CR16_BCOND_2) {
|
||||
r_mem_copyendian((ut8*)&disp, instr + 2, 2, LIL_ENDIAN);
|
||||
disp = r_read_at_le16 (instr, 2);
|
||||
disp32 = disp | (GET_BIT(c, 4) << 16);
|
||||
if (disp32 & 0x80000) {
|
||||
disp32 |= 0xFFF00000;
|
||||
|
|
@ -855,7 +854,7 @@ static int cr16_decode_bcond01i(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
ut16 c;
|
||||
int ret = 2;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
if (!(c & 1))
|
||||
return -1;
|
||||
|
|
@ -897,7 +896,7 @@ static int cr16_decode_misc(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
ut16 c;
|
||||
int ret = 2;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
cmd->operands[0] = '\0';
|
||||
switch (c) {
|
||||
|
|
@ -947,8 +946,8 @@ static int cr16_decode_bal(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
ut16 c, disp16;
|
||||
ut32 disp32;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
r_mem_copyendian((ut8*)&disp16, instr + 2, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
disp16 = r_read_at_le16 (instr, 2);
|
||||
|
||||
snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "bal");
|
||||
|
||||
|
|
@ -975,7 +974,7 @@ int cr16_decode_loadm_storm(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
int ret = 2;
|
||||
ut16 c;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
if ((c & 0x1F) != 4)
|
||||
return -1;
|
||||
|
|
@ -994,7 +993,7 @@ int cr16_decode_movz(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
{
|
||||
int ret = 2;
|
||||
ut16 c;
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
if (c & 1)
|
||||
return -1;
|
||||
|
|
@ -1024,8 +1023,8 @@ int cr16_decode_movd(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
ut16 imm;
|
||||
ut32 imm32;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
r_mem_copyendian((ut8*)&imm, instr + 2, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
imm = r_read_at_le16 (instr, 2);
|
||||
|
||||
if (c & 1)
|
||||
return -1;
|
||||
|
|
@ -1044,7 +1043,7 @@ int cr16_decode_muls(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
{
|
||||
int ret = 2;
|
||||
ut16 c;
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
switch (c >> 9) {
|
||||
case CR16_MULSB:
|
||||
|
|
@ -1080,7 +1079,7 @@ int cr16_decode_scond(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
int ret = 2;
|
||||
ut16 c;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
if (c & 1)
|
||||
return -1;
|
||||
|
|
@ -1102,7 +1101,7 @@ int cr16_decode_biti(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
ut16 c, disp16;
|
||||
ut8 reg, position;
|
||||
|
||||
r_mem_copyendian((ut8*)&c, instr, 2, LIL_ENDIAN);
|
||||
c = r_read_le16 (instr);
|
||||
|
||||
if (((c >> 6) & 0x3) == 0x3) {
|
||||
return -1;
|
||||
|
|
@ -1122,7 +1121,7 @@ int cr16_decode_biti(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
switch (((c >> 13) & 0x2) | (c & 0x1)) {
|
||||
case 0x0:
|
||||
ret = 4;
|
||||
r_mem_copyendian((ut8*)&disp16, instr + 2, 2, LIL_ENDIAN);
|
||||
disp16 = r_read_at_le16 (instr, 2);
|
||||
|
||||
abs18 = disp16 | ((reg & 0x1) << 16) | ((reg >> 3) << 17);
|
||||
|
||||
|
|
@ -1133,7 +1132,7 @@ int cr16_decode_biti(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
case 0x1:
|
||||
ret = 4;
|
||||
|
||||
r_mem_copyendian((ut8*)&disp16, instr + 2, 2, LIL_ENDIAN);
|
||||
disp16 = r_read_at_le16 (instr, 2);
|
||||
|
||||
snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
|
||||
"$0x%02x,0x%04x(%s)", position,
|
||||
|
|
@ -1157,7 +1156,7 @@ int cr16_decode_command(const ut8 *instr, struct cr16_cmd *cmd)
|
|||
{
|
||||
int ret;
|
||||
ut16 in;
|
||||
r_mem_copyendian((ut8*)&in, instr, 2, LIL_ENDIAN);
|
||||
in = r_read_le16 (instr);
|
||||
|
||||
switch (cr16_get_opcode_low(in)) {
|
||||
case CR16_MOV:
|
||||
|
|
|
|||
|
|
@ -143,9 +143,7 @@ static int decode_opcode(const ut8 *bytes, struct h8300_cmd *cmd)
|
|||
{
|
||||
ut16 ext_opcode;
|
||||
|
||||
r_mem_copyendian((ut8*)&ext_opcode, bytes, sizeof(ut16), !LIL_ENDIAN);
|
||||
|
||||
ext_opcode = ext_opcode >> 7;
|
||||
ext_opcode = (r_read_be16 (bytes)) >> 7;
|
||||
|
||||
switch (ext_opcode) {
|
||||
case H8300_BOR:
|
||||
|
|
@ -333,7 +331,7 @@ static int decode_imm162r16(const ut8 *bytes, struct h8300_cmd *cmd)
|
|||
return -1;
|
||||
}
|
||||
|
||||
r_mem_copyendian((ut8*)&imm, bytes + 2, sizeof(ut16), !LIL_ENDIAN);
|
||||
imm = r_read_at_be16 (bytes, 2);
|
||||
snprintf(cmd->operands, H8300_INSTR_MAXLEN, "#0x%x:16,r%u",
|
||||
imm, bytes[1] & 0x7);
|
||||
|
||||
|
|
@ -350,8 +348,7 @@ static int decode_disp162r16(const ut8 *bytes, struct h8300_cmd *cmd)
|
|||
return -1;
|
||||
}
|
||||
|
||||
r_mem_copyendian((ut8*)&disp, bytes + 2,
|
||||
sizeof(ut16), !LIL_ENDIAN);
|
||||
disp = r_read_at_be16 (bytes, 2);
|
||||
|
||||
if (bytes[1] & 0x80) {
|
||||
snprintf(cmd->operands, H8300_INSTR_MAXLEN,
|
||||
|
|
@ -598,7 +595,7 @@ int decode_jmp_abs16(const ut8 *bytes, struct h8300_cmd *cmd)
|
|||
return -1;
|
||||
}
|
||||
|
||||
r_mem_copyendian((ut8*)&abs, bytes + 2, 2, !LIL_ENDIAN);
|
||||
abs = r_read_at_be16 (bytes, 2);
|
||||
snprintf(cmd->operands, H8300_INSTR_MAXLEN, "@0x%x:16", abs);
|
||||
|
||||
return ret;
|
||||
|
|
@ -644,7 +641,7 @@ static int decode_abs162r16(const ut8 *bytes, struct h8300_cmd *cmd)
|
|||
return -1;
|
||||
}
|
||||
|
||||
r_mem_copyendian((ut8*)&abs, bytes + 2, sizeof(ut16), !LIL_ENDIAN);
|
||||
abs = r_read_at_be16 (bytes, 2);
|
||||
if (bytes[1] & 0x80) {
|
||||
snprintf(cmd->operands, H8300_INSTR_MAXLEN,
|
||||
"r%u,@0x%x:16", bytes[1] & 0x7, abs);
|
||||
|
|
@ -688,7 +685,7 @@ static int decode_r82dispr16(const ut8 *bytes, struct h8300_cmd *cmd)
|
|||
return -1;
|
||||
}
|
||||
|
||||
r_mem_copyendian((ut8*)&disp, bytes + 2, sizeof(ut16), !LIL_ENDIAN);
|
||||
disp = r_read_at_be16 (bytes, 2);
|
||||
if (bytes[1] & 0x80) {
|
||||
snprintf(cmd->operands, H8300_INSTR_MAXLEN,
|
||||
"r%u%c,@(0x%x:16,r%u)",
|
||||
|
|
@ -741,7 +738,7 @@ static int decode_r82abs16(const ut8 *bytes, struct h8300_cmd *cmd)
|
|||
return -1;
|
||||
}
|
||||
|
||||
r_mem_copyendian((ut8*)&abs, bytes + 2, sizeof(ut16), !LIL_ENDIAN);
|
||||
abs = r_read_at_be16 (bytes, 2);
|
||||
|
||||
if (bytes[1] & 0x80) {
|
||||
snprintf(cmd->operands, H8300_INSTR_MAXLEN, "r%u%c,@0x%x:16",
|
||||
|
|
|
|||
|
|
@ -446,7 +446,7 @@ int msp430_decode_command(const ut8 *in, struct msp430_cmd *cmd)
|
|||
ut16 operand1, operand2;
|
||||
ut8 opcode;
|
||||
|
||||
r_mem_copyendian((ut8*)&instr, in, sizeof(ut16), LIL_ENDIAN);
|
||||
instr = r_read_le16 (in);
|
||||
|
||||
opcode = get_twoop_opcode(instr);
|
||||
|
||||
|
|
@ -464,8 +464,8 @@ int msp430_decode_command(const ut8 *in, struct msp430_cmd *cmd)
|
|||
case MSP430_XOR:
|
||||
case MSP430_AND:
|
||||
cmd->type = MSP430_TWOOP;
|
||||
r_mem_copyendian((ut8*)&operand1, in + 2, sizeof(ut16), LIL_ENDIAN);
|
||||
r_mem_copyendian((ut8*)&operand2, in + 4, sizeof(ut16), LIL_ENDIAN);
|
||||
operand1 = r_read_at_le16 (in, 2);
|
||||
operand2 = r_read_at_le16 (in, 4);
|
||||
ret = decode_twoop_opcode(instr, operand1, operand2, cmd);
|
||||
break;
|
||||
}
|
||||
|
|
@ -479,7 +479,7 @@ int msp430_decode_command(const ut8 *in, struct msp430_cmd *cmd)
|
|||
if (ret > 0)
|
||||
return ret;
|
||||
|
||||
r_mem_copyendian((ut8*)&operand1, in + 2, sizeof(ut16), LIL_ENDIAN);
|
||||
operand1 = r_read_at_le16 (in, 2);
|
||||
ret = decode_oneop_opcode(instr, operand1, cmd);
|
||||
|
||||
/* if ret < 0, it's an invalid opcode.Say so and return 2 since
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ int propeller_decode_command(const ut8 *instr, struct propeller_cmd *cmd)
|
|||
ut32 in;
|
||||
ut16 opcode;
|
||||
|
||||
r_mem_copyendian((ut8*)&in, instr, sizeof (ut32), LIL_ENDIAN);
|
||||
in = r_read_be32 (instr);
|
||||
|
||||
opcode = get_opcode (in);
|
||||
|
||||
|
|
|
|||
|
|
@ -309,9 +309,9 @@ int v810_decode_command(const ut8 *instr, int len, struct v810_cmd *cmd) {
|
|||
ut16 word1 = 0;
|
||||
ut16 word2 = 0;
|
||||
|
||||
r_mem_copyendian ((ut8*)&word1, instr, 2, LIL_ENDIAN);
|
||||
word1 = r_read_le16 (instr);
|
||||
if (len >= 4)
|
||||
r_mem_copyendian ((ut8*)&word2, instr + 2, 2, LIL_ENDIAN);
|
||||
word2 = r_read_le16 (instr + 2);
|
||||
|
||||
switch (OPCODE(word1)) {
|
||||
case V810_MOV:
|
||||
|
|
|
|||
|
|
@ -183,8 +183,8 @@ static int decode_jarl(const ut8 *instr, struct v850_cmd *cmd) {
|
|||
ut16 word1, word2;
|
||||
ut32 disp;
|
||||
|
||||
r_mem_copyendian ((ut8*)&word1, instr, 2, LIL_ENDIAN);
|
||||
r_mem_copyendian ((ut8*)&word2, instr + 2, 2, LIL_ENDIAN);
|
||||
word1 = r_read_le16 (instr);
|
||||
word2 = r_read_at_le16 (instr, 2);
|
||||
|
||||
reg = get_reg2 (word1);
|
||||
disp = (word2 << 6) | get_reg1 (word1);
|
||||
|
|
@ -199,8 +199,8 @@ static int decode_jarl(const ut8 *instr, struct v850_cmd *cmd) {
|
|||
static int decode_3operands(const ut8 *instr, struct v850_cmd *cmd) {
|
||||
ut16 word1, word2;
|
||||
|
||||
r_mem_copyendian ((ut8*)&word1, instr, 2, LIL_ENDIAN);
|
||||
r_mem_copyendian ((ut8*)&word2, instr + 2, 2, LIL_ENDIAN);
|
||||
word1 = r_read_le16 (instr);
|
||||
word2 = r_read_at_le16 (instr, 2);
|
||||
|
||||
snprintf (cmd->instr, V850_INSTR_MAXLEN - 1, "%s", instrs[get_opcode (word1)]);
|
||||
snprintf (cmd->operands, V850_INSTR_MAXLEN - 1, "0x%x, r%d, r%d",
|
||||
|
|
@ -212,8 +212,8 @@ static int decode_3operands(const ut8 *instr, struct v850_cmd *cmd) {
|
|||
static int decode_load_store(const ut8 *instr, struct v850_cmd *cmd) {
|
||||
ut16 word1, word2;
|
||||
|
||||
r_mem_copyendian ((ut8*)&word1, instr, 2, LIL_ENDIAN);
|
||||
r_mem_copyendian ((ut8*)&word2, instr + 2, 2, LIL_ENDIAN);
|
||||
word1 = r_read_le16 (instr);
|
||||
word2 = r_read_at_le16 (instr, 2);
|
||||
|
||||
switch (get_opcode (word1)) {
|
||||
case V850_STB:
|
||||
|
|
@ -247,8 +247,8 @@ static int decode_bit_op(const ut8 *instr, struct v850_cmd *cmd) {
|
|||
ut16 word1, word2;
|
||||
ut8 reg1;
|
||||
|
||||
r_mem_copyendian ((ut8*)&word1, instr, 2, LIL_ENDIAN);
|
||||
r_mem_copyendian ((ut8*)&word2, instr + 2, 2, LIL_ENDIAN);
|
||||
word1 = r_read_le16 (instr);
|
||||
word2 = r_read_at_le16 (instr, 2);
|
||||
|
||||
snprintf (cmd->instr, V850_INSTR_MAXLEN - 1, "%s", bit_instrs[word1 >> 14]);
|
||||
|
||||
|
|
@ -262,8 +262,8 @@ static int decode_bit_op(const ut8 *instr, struct v850_cmd *cmd) {
|
|||
static int decode_extended(const ut8 *instr, struct v850_cmd *cmd) {
|
||||
ut16 word1, word2;
|
||||
|
||||
r_mem_copyendian ((ut8*)&word1, instr, 2, LIL_ENDIAN);
|
||||
r_mem_copyendian ((ut8*)&word2, instr + 2, 2, LIL_ENDIAN);
|
||||
word1 = r_read_le16 (instr);
|
||||
word2 = r_read_at_le16 (instr, 2);
|
||||
|
||||
snprintf (cmd->instr, V850_INSTR_MAXLEN - 1, "%s",
|
||||
ext_instrs1[get_opcode (word1)]);
|
||||
|
|
@ -310,7 +310,7 @@ int v850_decode_command (const ut8 *instr, struct v850_cmd *cmd) {
|
|||
int ret;
|
||||
ut16 in;
|
||||
|
||||
r_mem_copyendian ((ut8*)&in, instr, 2, LIL_ENDIAN);
|
||||
in = r_read_le16 (instr);
|
||||
|
||||
switch (get_opcode (in)) {
|
||||
case V850_MOV:
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ static inline int r_asm_pseudo_intN(RAsm *a, RAsmOp *op, char *input, int n) {
|
|||
l = (long int)s64;
|
||||
p = (const ut8*)&l;
|
||||
} else return 0;
|
||||
r_mem_copyendian (op->buf, p, n, !a->big_endian);
|
||||
memcpy (op->buf, p, n);
|
||||
r_hex_bin2str (op->buf, n, op->buf_hex);
|
||||
return n;
|
||||
}
|
||||
|
|
@ -147,7 +147,6 @@ R_API int r_asm_setup(RAsm *a, const char *arch, int bits, int big_endian) {
|
|||
int ret = 0;
|
||||
ret |= !r_asm_use (a, arch);
|
||||
ret |= !r_asm_set_bits (a, bits);
|
||||
ret |= !r_asm_set_big_endian (a, big_endian);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -278,9 +277,25 @@ R_API int r_asm_set_bits(RAsm *a, int bits) {
|
|||
return false;
|
||||
}
|
||||
|
||||
R_API int r_asm_set_big_endian(RAsm *a, int b) {
|
||||
a->big_endian = b;
|
||||
return true;
|
||||
R_API bool r_asm_set_big_endian(RAsm *a, bool b) {
|
||||
if (!a || !a->cur) return false;
|
||||
switch (a->cur->endian) {
|
||||
case R_SYS_ENDIAN_NONE:
|
||||
case R_SYS_ENDIAN_BI:
|
||||
// let user select
|
||||
a->big_endian = b;
|
||||
return b;
|
||||
case R_SYS_ENDIAN_LITTLE:
|
||||
a->big_endian = false;
|
||||
return false;
|
||||
case R_SYS_ENDIAN_BIG:
|
||||
a->big_endian = true;
|
||||
return true;
|
||||
default:
|
||||
eprintf ("RAsmPlugin doesn't specify endianness\n");
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API int r_asm_set_syntax(RAsm *a, int syntax) {
|
||||
|
|
@ -331,12 +346,10 @@ R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
if (!op->buf_asm[0] || op->size <1 || !strcmp (op->buf_asm, "invalid")) {
|
||||
if (a->invhex) {
|
||||
if (a->bits == 16) {
|
||||
ut16 b;
|
||||
r_mem_copyendian ((ut8*)&b, buf, 2, !a->big_endian);
|
||||
ut16 b = r_read_le16 (buf);
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), ".word 0x%04x", b);
|
||||
} else {
|
||||
ut32 b;
|
||||
r_mem_copyendian ((ut8*)&b, buf, 4, !a->big_endian);
|
||||
ut32 b = r_read_le32 (buf);
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), ".dword 0x%08x", b);
|
||||
}
|
||||
// TODO: something for 64bits too?
|
||||
|
|
@ -346,7 +359,7 @@ R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
}
|
||||
if (a->ofilter)
|
||||
r_parse_parse (a->ofilter, op->buf_asm, op->buf_asm);
|
||||
r_mem_copyendian (op->buf, buf, oplen, !a->big_endian);
|
||||
memcpy (op->buf, buf, oplen);
|
||||
*op->buf_hex = 0;
|
||||
if ((oplen*4) >= sizeof (op->buf_hex))
|
||||
oplen = (sizeof (op->buf_hex)/4)-1;
|
||||
|
|
@ -482,7 +495,7 @@ R_API RAsmCode* r_asm_massemble(RAsm *a, const char *buf) {
|
|||
char *lbuf = NULL, *ptr2, *ptr = NULL, *ptr_start = NULL,
|
||||
*tokens[R_ASM_BUFSIZE], buf_token[R_ASM_BUFSIZE];
|
||||
RAsmCode *acode = NULL;
|
||||
RAsmOp op;
|
||||
RAsmOp op = {0};
|
||||
ut64 off, pc;
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ RAsmPlugin r_asm_plugin_6502 = {
|
|||
.desc = "6502/NES/C64/Tamagotchi/T-1000 CPU",
|
||||
.arch = "6502",
|
||||
.bits = 8|16,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.license = "LGPL3",
|
||||
.disassemble = &disassemble,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -39,9 +39,8 @@ RAsmPlugin r_asm_plugin_8051 = {
|
|||
.name = "8051",
|
||||
.arch = "8051",
|
||||
.bits = 8,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
.desc = "8051 Intel CPU",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL,
|
||||
.license = "PD"
|
||||
|
|
|
|||
|
|
@ -91,9 +91,8 @@ RAsmPlugin r_asm_plugin_arc = {
|
|||
.name = "arc",
|
||||
.arch = "arc",
|
||||
.bits = 16|32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.desc = "Argonaut RISC Core",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL,
|
||||
.license = "GPL3"
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ RAsmPlugin r_asm_plugin_arm_as = {
|
|||
.arch = "arm",
|
||||
.license = "LGPL3",
|
||||
.bits = 16|32|64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = NULL,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
cs_insn* insn = NULL;
|
||||
cs_mode mode = 0;
|
||||
int ret, n = 0;
|
||||
mode |= (a->bits == 16) ? CS_MODE_THUMB: CS_MODE_ARM;
|
||||
mode |= (a->bits == 16)? CS_MODE_THUMB: CS_MODE_ARM;
|
||||
mode |= (a->big_endian)? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN;
|
||||
if (mode != omode || a->bits != obits) {
|
||||
cs_close (&cd);
|
||||
|
|
@ -99,11 +99,14 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
|||
if (is_thumb) {
|
||||
const int o = opcode >> 16;
|
||||
opsize = o>0? 4: 2; //(o&0x80 && ((o&0xe0)==0xe0))? 4: 2;
|
||||
r_mem_copyendian (op->buf, (void *)&opcode,
|
||||
opsize, a->big_endian);
|
||||
if (opsize == 4) {
|
||||
r_write_be32(op->buf, opcode);
|
||||
} else if (opsize == 2) {
|
||||
r_write_be16(op->buf, opcode & UT16_MAX);
|
||||
}
|
||||
} else {
|
||||
opsize = 4;
|
||||
r_mem_copyendian (op->buf, (void *)&opcode, 4, a->big_endian);
|
||||
r_write_be32(op->buf, opcode);
|
||||
}
|
||||
// XXX. thumb endian assembler needs no swap
|
||||
return opsize;
|
||||
|
|
@ -116,8 +119,7 @@ RAsmPlugin r_asm_plugin_arm_cs = {
|
|||
.license = "BSD",
|
||||
.arch = "arm",
|
||||
.bits = 16 | 32 | 64,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = &assemble,
|
||||
.features = "no-mclass,v8"
|
||||
|
|
|
|||
|
|
@ -158,12 +158,11 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
op->buf_asm[0]='\0';
|
||||
if (a->bits==64) {
|
||||
obj.disassembler_options = NULL;
|
||||
/* is endianness ignored on 64bits? */
|
||||
//r_mem_copyendian (bytes, buf, 4, !a->big_endian);
|
||||
memcpy (bytes, buf, 4);
|
||||
op->size = print_insn_aarch64 ((bfd_vma)Offset, &obj);
|
||||
} else {
|
||||
obj.disassembler_options = options;
|
||||
op->size = obj.endian?
|
||||
op->size = (obj.endian == BFD_ENDIAN_LITTLE)?
|
||||
print_insn_little_arm ((bfd_vma)Offset, &obj):
|
||||
print_insn_big_arm ((bfd_vma)Offset, &obj);
|
||||
}
|
||||
|
|
@ -179,11 +178,9 @@ RAsmPlugin r_asm_plugin_arm_gnu = {
|
|||
.name = "arm.gnu",
|
||||
.arch = "arm",
|
||||
.bits = 16|32|64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.desc = "Acorn RISC Machine CPU",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL,
|
||||
.license = "GPL3"
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
arm_set_pc (arminsn, a->pc);
|
||||
arm_set_thumb (arminsn, a->bits == 16);
|
||||
if (a->big_endian && a->bits == 32) {
|
||||
r_mem_copyendian (buf2, buf, 4, 0);
|
||||
r_mem_swapendian (buf2, buf, 4);
|
||||
arm_set_input_buffer (arminsn, buf2);
|
||||
} else {
|
||||
arm_set_input_buffer (arminsn, buf);
|
||||
|
|
@ -31,11 +31,9 @@ RAsmPlugin r_asm_plugin_arm_winedbg = {
|
|||
.name = "arm.winedbg",
|
||||
.arch = "arm",
|
||||
.bits = 16|32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.desc = "WineDBG's ARM disassembler",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL,
|
||||
.license = "LGPL2"
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -406,6 +406,7 @@ RAsmPlugin r_asm_plugin_avr = {
|
|||
.arch = "avr",
|
||||
.license = "GPL",
|
||||
.bits = 8|16,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.desc = "AVR Atmel",
|
||||
.disassemble = &disassemble,
|
||||
.assemble = &assemble
|
||||
|
|
|
|||
|
|
@ -156,11 +156,10 @@ RAsmPlugin r_asm_plugin_bf = {
|
|||
.arch = "bf",
|
||||
.license = "LGPL3",
|
||||
.bits = 16|32|64,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
.desc = "Brainfuck",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = &assemble
|
||||
.assemble = &assemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len)
|
|||
int ret = 1;
|
||||
struct cr16_cmd cmd;
|
||||
|
||||
ret = cr16_decode_command(buf, &cmd);
|
||||
ret = cr16_decode_command (buf, &cmd);
|
||||
|
||||
snprintf(op->buf_asm, R_ASM_BUFSIZE, "%s %s", cmd.instr, cmd.operands);
|
||||
op->size = ret;
|
||||
|
|
@ -25,11 +25,8 @@ RAsmPlugin r_asm_plugin_cr16 = {
|
|||
.desc = "cr16 disassembly plugin",
|
||||
.arch = "cr16",
|
||||
.bits = 16,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.modify = NULL,
|
||||
.assemble = NULL
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -126,11 +126,9 @@ RAsmPlugin r_asm_plugin_cris_gnu = {
|
|||
.cpus = "v10,v32,v10+v32",
|
||||
.license = "GPL3",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.desc = "Axis Communications 32-bit embedded processor",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -38,11 +38,9 @@ RAsmPlugin r_asm_plugin_csr = {
|
|||
.arch = "csr",
|
||||
.license = "PD",
|
||||
.bits = 16,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.desc = "Cambridge Silicon Radio (CSR)",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -429,7 +429,7 @@ static int dalvik_assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
|||
// TODO: use a hashtable here
|
||||
for (i=0; i<256; i++)
|
||||
if (!strcmp (dalvik_opcodes[i].name, buf)) {
|
||||
r_mem_copyendian (op->buf, (void*)&i, 4, a->big_endian);
|
||||
r_write_ble32 (op->buf, i, a->big_endian);
|
||||
op->size = dalvik_opcodes[i].len;
|
||||
return op->size;
|
||||
}
|
||||
|
|
@ -442,9 +442,9 @@ RAsmPlugin r_asm_plugin_dalvik = {
|
|||
.license = "LGPL3",
|
||||
.desc = "AndroidVM Dalvik",
|
||||
.bits = 32 | 64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.disassemble = &dalvik_disassemble,
|
||||
.assemble = &dalvik_assemble,
|
||||
0
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ RAsmPlugin r_asm_plugin_dcpu16 = {
|
|||
.name = "dcpu16",
|
||||
.arch = "dpcu",
|
||||
.bits = 16,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.desc = "Mojang's DCPU-16",
|
||||
.license = "PD",
|
||||
.disassemble = &disassemble,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ RAsmPlugin r_asm_plugin_ebc = {
|
|||
.desc = "EFI Bytecode",
|
||||
.arch = "ebc",
|
||||
.bits = 32|64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.disassemble = &disassemble,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -31,10 +31,9 @@ RAsmPlugin r_asm_plugin_x86_gas = {
|
|||
.desc = "GNU Assembler (gas)",
|
||||
.arch = NULL, //"x86", // XXX
|
||||
.bits = 16|32|64,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.disassemble = NULL, /*&disassemble,*/
|
||||
.assemble = &assemble,
|
||||
.assemble = &assemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ RAsmPlugin r_asm_plugin_gb = {
|
|||
.arch = "z80",
|
||||
.license = "LGPL3",
|
||||
.bits = 16,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = &assemble,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -25,11 +25,8 @@ RAsmPlugin r_asm_plugin_h8300 = {
|
|||
.desc = "H8/300 disassembly plugin",
|
||||
.arch = "h8300",
|
||||
.bits = 16,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.modify = NULL,
|
||||
.assemble = NULL
|
||||
.endian = R_SYS_ENDIAN_BIG,
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ static char *buf_global = NULL;
|
|||
static unsigned char bytes[4];
|
||||
|
||||
static int hppa_buffer_read_memory (bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) {
|
||||
#if SWAP_ENDIAN
|
||||
#if 0 // XXX wtf ?!
|
||||
if (length == 4) {
|
||||
// swap
|
||||
myaddr[0] = bytes[3];
|
||||
|
|
@ -84,7 +84,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
disasm_obj.symbol_at_address_func = &symbol_at_address;
|
||||
disasm_obj.memory_error_func = &memory_error_func;
|
||||
disasm_obj.print_address_func = &print_address;
|
||||
disasm_obj.endian = !a->big_endian;
|
||||
disasm_obj.endian = BFD_ENDIAN_BIG;
|
||||
disasm_obj.fprintf_func = &buf_fprintf;
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
|
|
@ -100,11 +100,9 @@ RAsmPlugin r_asm_plugin_hppa_gnu = {
|
|||
.arch = "hppa",
|
||||
.license = "GPL3",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_BIG,
|
||||
.desc = "HP PA-RISC",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -16,11 +16,8 @@ RAsmPlugin r_asm_plugin_i4004 = {
|
|||
.arch = "i4004",
|
||||
.license = "LGPL3",
|
||||
.bits = 4,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.modify = NULL,
|
||||
.assemble = NULL,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -20,10 +20,8 @@ RAsmPlugin r_asm_plugin_i8080 = {
|
|||
.arch = "i8080",
|
||||
.license = "BSD",
|
||||
.bits = 8,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = do_disassemble,
|
||||
.assemble = NULL,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
.disassemble = &do_disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ RAsmPlugin r_asm_plugin_java = {
|
|||
.arch = "java",
|
||||
.license = "Apache",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_BIG,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = &assemble
|
||||
};
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
disasm_obj.symbol_at_address_func = &symbol_at_address;
|
||||
disasm_obj.memory_error_func = &memory_error_func;
|
||||
disasm_obj.print_address_func = &print_address;
|
||||
disasm_obj.endian = !a->big_endian;
|
||||
disasm_obj.endian = BFD_ENDIAN_BIG;
|
||||
disasm_obj.fprintf_func = &buf_fprintf;
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
|
|
@ -91,9 +91,9 @@ RAsmPlugin r_asm_plugin_lanai_gnu = {
|
|||
.arch = "lanai",
|
||||
.license = "GPL3",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_BIG,
|
||||
.desc = "LANAI",
|
||||
.disassemble = &disassemble,
|
||||
0
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -32,8 +32,9 @@ RAsmPlugin r_asm_plugin_lh5801 = {
|
|||
.arch = "LH5801",
|
||||
.license = "LGPL3",
|
||||
.bits = 8,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
.desc = "SHARP LH5801 disassembler",
|
||||
.disassemble = &disassemble,
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -388,8 +388,6 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
|
|||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
RAsmLm32Instruction instr;
|
||||
//lm32 is big endian
|
||||
a->big_endian = 1;
|
||||
instr.value = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
|
||||
instr.addr = a->pc;
|
||||
if (r_asm_lm32_decode (&instr)) {
|
||||
|
|
@ -412,8 +410,8 @@ RAsmPlugin r_asm_plugin_lm32 = {
|
|||
.desc = "disassembly plugin for Lattice Micro 32 ISA",
|
||||
.license = "BSD",
|
||||
.bits = 32,
|
||||
.disassemble = disassemble,
|
||||
//.assemble = &assemble, TODO
|
||||
.endian = R_SYS_ENDIAN_BIG,
|
||||
.disassemble = &disassemble,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ RAsmPlugin r_asm_plugin_m68k = {
|
|||
.arch = "m68k",
|
||||
.license = "BSD",
|
||||
.bits = 16|32,
|
||||
.endian = R_SYS_ENDIAN_BIG,
|
||||
.desc = "Motorola 68000",
|
||||
.disassemble = &disassemble,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,9 +20,8 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
static int omode = -1;
|
||||
static int obits = 32;
|
||||
cs_insn* insn = NULL;
|
||||
cs_mode mode = 0;
|
||||
int ret, n = 0;
|
||||
mode |= (a->big_endian)? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN;
|
||||
cs_mode mode = a->big_endian? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN;
|
||||
if (mode != omode || a->bits != obits) {
|
||||
cs_close (&cd);
|
||||
cd = 0; // unnecessary
|
||||
|
|
@ -106,8 +105,8 @@ RAsmPlugin r_asm_plugin_m68k_cs = {
|
|||
.license = "BSD",
|
||||
.arch = "m68k",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.disassemble = &disassemble,
|
||||
.features = NULL
|
||||
};
|
||||
|
||||
static bool check_features(RAsm *a, cs_insn *insn) {
|
||||
|
|
@ -130,6 +129,7 @@ RAsmPlugin r_asm_plugin_m68k_cs = {
|
|||
.license = "BSD",
|
||||
.arch = "m68k",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
};
|
||||
struct r_lib_struct_t radare_plugin = {
|
||||
.type = R_LIB_TYPE_ASM,
|
||||
|
|
|
|||
|
|
@ -45,10 +45,8 @@ RAsmPlugin r_asm_plugin_malbolge = {
|
|||
.arch = "malbolge",
|
||||
.license = "LGPL3",
|
||||
.bits = 32,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &__disassemble,
|
||||
.assemble = NULL,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
.disassemble = &__disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ RAsmPlugin r_asm_plugin_mcs96 = {
|
|||
.arch = "mcs96",
|
||||
.license = "LGPL3",
|
||||
.bits = 16,
|
||||
.disassemble = &disassemble,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
csh handle;
|
||||
cs_insn* insn;
|
||||
int mode, n, ret = -1;
|
||||
mode = a->big_endian? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN;
|
||||
mode = (a->big_endian)? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN;
|
||||
if (a->cpu && *a->cpu) {
|
||||
if (!strcmp (a->cpu, "micro")) {
|
||||
mode |= CS_MODE_MICRO;
|
||||
|
|
@ -52,7 +52,6 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *str) {
|
||||
int ret = mips_assemble (str, a->pc, op->buf);
|
||||
r_mem_copyendian (op->buf, op->buf, 4, !a->big_endian);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -63,10 +62,9 @@ RAsmPlugin r_asm_plugin_mips_cs = {
|
|||
.arch = "mips",
|
||||
.cpus = "gp64,micro,r6,v3",
|
||||
.bits = 16|32|64,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = assemble
|
||||
.assemble = &assemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -80,9 +80,10 @@ static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf,
|
|||
disasm_obj.stream = stdout;
|
||||
|
||||
op->buf_asm[0] = '\0';
|
||||
if (a->big_endian)
|
||||
if (disasm_obj.endian == BFD_ENDIAN_LITTLE)
|
||||
op->size = print_insn_little_mips ((bfd_vma)Offset, &disasm_obj);
|
||||
else
|
||||
op->size = print_insn_big_mips ((bfd_vma)Offset, &disasm_obj);
|
||||
else op->size = print_insn_little_mips ((bfd_vma)Offset, &disasm_obj);
|
||||
if (op->size == -1)
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
return op->size;
|
||||
|
|
@ -90,7 +91,8 @@ static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf,
|
|||
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *str) {
|
||||
int ret = mips_assemble (str, a->pc, op->buf);
|
||||
r_mem_copyendian (op->buf, op->buf, 4, !a->big_endian);
|
||||
if (!a->big_endian)
|
||||
r_mem_swapendian (op->buf, op->buf, op->size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -99,11 +101,10 @@ RAsmPlugin r_asm_plugin_mips_gnu = {
|
|||
.arch = "mips",
|
||||
.license = "GPL3",
|
||||
.bits = 32|64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.desc = "MIPS CPU",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = &assemble,
|
||||
.assemble = &assemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -32,11 +32,8 @@ RAsmPlugin r_asm_plugin_msp430 = {
|
|||
.desc = "msp430 disassembly plugin",
|
||||
.arch = "msp430",
|
||||
.bits = 16,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.disassemble = &disassemble,
|
||||
.modify = NULL,
|
||||
.assemble = NULL,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len)
|
|||
disasm_obj.stream = stdout;
|
||||
|
||||
op->buf_asm[0]='\0';
|
||||
if (a->big_endian)
|
||||
if (disasm_obj.endian == BFD_ENDIAN_BIG)
|
||||
op->size = print_insn_big_nios2 ((bfd_vma)Offset, &disasm_obj);
|
||||
else op->size = print_insn_little_nios2 ((bfd_vma)Offset, &disasm_obj);
|
||||
|
||||
|
|
@ -95,11 +95,9 @@ RAsmPlugin r_asm_plugin_nios2 = {
|
|||
.arch = "nios2",
|
||||
.license = "GPL3",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.desc = "NIOS II Embedded Processor",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -232,6 +232,7 @@ RAsmPlugin r_asm_plugin_pic18c = {
|
|||
.arch = "pic18c",
|
||||
.license = "LGPL3",
|
||||
.bits = 8,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
.desc = "pic18c disassembler"
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -16,13 +16,12 @@ static bool the_end(void *p) {
|
|||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
static int omode = 0;
|
||||
int mode = 0, n, ret;
|
||||
int n, ret;
|
||||
ut64 off = a->pc;
|
||||
cs_insn* insn;
|
||||
|
||||
int mode = (a->big_endian)? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN;
|
||||
|
||||
if (a->big_endian) {
|
||||
mode = CS_MODE_BIG_ENDIAN;
|
||||
}
|
||||
if (handle && mode != omode) {
|
||||
cs_close (&handle);
|
||||
handle = 0;
|
||||
|
|
@ -59,6 +58,7 @@ RAsmPlugin r_asm_plugin_ppc_cs = {
|
|||
.license = "BSD",
|
||||
.arch = "ppc",
|
||||
.bits = 32|64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.fini = the_end,
|
||||
.disassemble = &disassemble,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -79,8 +79,8 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
disasm_obj.stream = stdout;
|
||||
|
||||
if (a->big_endian)
|
||||
op->size = print_insn_big_powerpc((bfd_vma)Offset, &disasm_obj);
|
||||
else op->size = print_insn_little_powerpc((bfd_vma)Offset, &disasm_obj);
|
||||
op->size = print_insn_big_powerpc ((bfd_vma)Offset, &disasm_obj);
|
||||
else op->size = print_insn_little_powerpc ((bfd_vma)Offset, &disasm_obj);
|
||||
|
||||
if (op->size == -1)
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
|
|
@ -93,10 +93,9 @@ RAsmPlugin r_asm_plugin_ppc_gnu = {
|
|||
.arch = "ppc",
|
||||
.license = "GPL3",
|
||||
.bits = 32 | 64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.desc = "PowerPC",
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL,
|
||||
0
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -32,11 +32,8 @@ RAsmPlugin r_asm_plugin_propeller = {
|
|||
.desc = "propeller disassembly plugin",
|
||||
.arch = "propeller",
|
||||
.bits = 32,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.modify = NULL,
|
||||
.assemble = NULL,
|
||||
.endian = R_SYS_ENDIAN_BIG,
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -26,11 +26,10 @@ RAsmPlugin r_asm_plugin_rar = {
|
|||
.arch = "rar",
|
||||
.license = "LGPL3",
|
||||
.bits = 1,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
.desc = "RAR VM",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = &assemble
|
||||
.assemble = &assemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ RAsmPlugin r_asm_plugin_riscv = {
|
|||
.desc = "RISC-V",
|
||||
.arch = "riscv",
|
||||
.bits = 32|64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.license = "GPL",
|
||||
.disassemble = &disassemble,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
disasm_obj.stream = stdout;
|
||||
|
||||
op->buf_asm[0] = '\0';
|
||||
if (a->big_endian)
|
||||
if (disasm_obj.endian == BFD_ENDIAN_BIG)
|
||||
op->size = print_insn_shb ((bfd_vma)Offset, &disasm_obj);
|
||||
else
|
||||
op->size = print_insn_shl ((bfd_vma)Offset, &disasm_obj);
|
||||
|
|
@ -89,11 +89,9 @@ RAsmPlugin r_asm_plugin_sh = {
|
|||
.arch = "sh",
|
||||
.license = "GPL3",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.desc = "SuperH-4 CPU",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -18,12 +18,9 @@ RAsmPlugin r_asm_plugin_snes = {
|
|||
.desc = "SuperNES CPU",
|
||||
.arch = "snes",
|
||||
.bits = 8|16,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.license = "LGPL3",
|
||||
.disassemble = &disassemble,
|
||||
.modify = NULL,
|
||||
.assemble = NULL,
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
csh handle;
|
||||
cs_insn* insn;
|
||||
int mode, n, ret = -1;
|
||||
mode = a->big_endian? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN;
|
||||
int n, ret = -1;
|
||||
int mode = a->big_endian? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN;
|
||||
if (a->cpu && *a->cpu) {
|
||||
if (!strcmp (a->cpu, "v9")) {
|
||||
mode |= CS_MODE_V9;
|
||||
|
|
@ -19,7 +19,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
ret = cs_open (CS_ARCH_SPARC, mode, &handle);
|
||||
if (ret) goto fin;
|
||||
cs_option (handle, CS_OPT_DETAIL, CS_OPT_OFF);
|
||||
n = cs_disasm (handle, (ut8*)buf, len, a->pc, 1, &insn);
|
||||
n = cs_disasm (handle, buf, len, a->pc, 1, &insn);
|
||||
if (n < 1) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
op->size = 4;
|
||||
|
|
@ -47,8 +47,8 @@ RAsmPlugin r_asm_plugin_sparc_cs = {
|
|||
.arch = "sparc",
|
||||
.cpus = "v9",
|
||||
.bits = 32|64,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL
|
||||
.endian = R_SYS_ENDIAN_BIG | R_SYS_ENDIAN_LITTLE,
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
if (len<4) return -1;
|
||||
buf_global = op->buf_asm;
|
||||
Offset = a->pc;
|
||||
memcpy (bytes, buf, 4); // TODO handle thumb
|
||||
// disasm inverted
|
||||
r_mem_swapendian (bytes, buf, 4); // TODO handle thumb
|
||||
|
||||
/* prepare disassembler */
|
||||
memset (&disasm_obj,'\0', sizeof (struct disassemble_info));
|
||||
|
|
@ -80,6 +81,7 @@ RAsmPlugin r_asm_plugin_sparc_gnu = {
|
|||
.name = "sparc.gnu",
|
||||
.arch = "sparc",
|
||||
.bits = 32|64,
|
||||
.endian = R_SYS_ENDIAN_BIG | R_SYS_ENDIAN_LITTLE,
|
||||
.license = "GPL3",
|
||||
.desc = "Scalable Processor Architecture",
|
||||
.disassemble = &disassemble,
|
||||
|
|
|
|||
|
|
@ -22,11 +22,8 @@ RAsmPlugin r_asm_plugin_spc700 = {
|
|||
.arch = "spc700",
|
||||
.license = "LGPL3",
|
||||
.bits = 16,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.endian = R_SYS_ENDIAN_NONE, // is this LE?
|
||||
.disassemble = &disassemble,
|
||||
.modify = NULL,
|
||||
.assemble = NULL,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ RAsmPlugin r_asm_plugin_sysz = {
|
|||
.license = "BSD",
|
||||
.arch = "sysz",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_BIG,
|
||||
.fini = the_end,
|
||||
.disassemble = &disassemble,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -43,9 +43,10 @@ RAsmPlugin r_asm_plugin_tms320 = {
|
|||
.desc = "TMS320 DSP family",
|
||||
.license = "LGPLv3",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.init = tms320_init,
|
||||
.fini = tms320_fini,
|
||||
.disassemble = tms320_disassemble,
|
||||
.disassemble = &tms320_disassemble,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
disasm_obj.symbol_at_address_func = &symbol_at_address;
|
||||
disasm_obj.memory_error_func = &memory_error_func;
|
||||
disasm_obj.print_address_func = &print_address;
|
||||
disasm_obj.endian = !a->big_endian;
|
||||
disasm_obj.endian = BFD_ENDIAN_LITTLE;
|
||||
disasm_obj.fprintf_func = &buf_fprintf;
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
|
|
@ -116,9 +116,9 @@ RAsmPlugin r_asm_plugin_tricore = {
|
|||
.arch = "tricore",
|
||||
.license = "GPL3",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.desc = "Siemens TriCore CPU",
|
||||
.disassemble = &disassemble,
|
||||
0
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -28,11 +28,8 @@ RAsmPlugin r_asm_plugin_v810 = {
|
|||
.desc = "V810 disassembly plugin",
|
||||
.arch = "v810",
|
||||
.bits = 32,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.modify = NULL,
|
||||
.assemble = NULL
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -28,11 +28,8 @@ RAsmPlugin r_asm_plugin_v850 = {
|
|||
.desc = "v850 disassembly plugin",
|
||||
.arch = "v850",
|
||||
.bits = 32,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.modify = NULL,
|
||||
.assemble = NULL
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
disasm_obj.symbol_at_address_func = &symbol_at_address;
|
||||
disasm_obj.memory_error_func = &memory_error_func;
|
||||
disasm_obj.print_address_func = &print_address;
|
||||
disasm_obj.endian = !a->big_endian;
|
||||
disasm_obj.endian = BFD_ENDIAN_LITTLE;
|
||||
disasm_obj.fprintf_func = &buf_fprintf;
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
|
|
@ -97,6 +97,7 @@ RAsmPlugin r_asm_plugin_vax = {
|
|||
.arch = "vax",
|
||||
.license = "GPL",
|
||||
.bits = 8 | 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.desc = "VAX",
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,11 +17,8 @@ RAsmPlugin r_asm_plugin_ws = {
|
|||
.arch = "whitespace",
|
||||
.license = "LGPL3",
|
||||
.bits = 32,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = &disassemble,
|
||||
.modify = NULL,
|
||||
.assemble = NULL
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -85,9 +85,7 @@ RAsmPlugin r_asm_plugin_x86_as = {
|
|||
.license = "LGPL3",
|
||||
// NOTE: 64bits is not supported on OSX's nasm :(
|
||||
.bits = 16|32|64,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = NULL,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.assemble = &assemble,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -111,10 +111,9 @@ RAsmPlugin r_asm_plugin_x86_cs = {
|
|||
.license = "BSD",
|
||||
.arch = "x86",
|
||||
.bits = 16|32|64,
|
||||
.init = NULL,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.fini = the_end,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL,
|
||||
.features = "vm,3dnow,aes,adx,avx,avx2,avx512,bmi,bmi2,cmov,"
|
||||
"f16c,fma,fma4,fsgsbase,hle,mmx,rtm,sha,sse1,sse2,"
|
||||
"sse3,sse41,sse42,sse4a,ssse3,pclmul,xop"
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ RAsmPlugin r_asm_plugin_x86_nasm = {
|
|||
.arch = "x86",
|
||||
// NOTE: 64bits is not supported on OSX's nasm :(
|
||||
.bits = 16|32|64,
|
||||
.assemble = &assemble,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.assemble = &assemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -1410,11 +1410,8 @@ RAsmPlugin r_asm_plugin_x86_nz = {
|
|||
.license = "LGPL3",
|
||||
.arch = "x86",
|
||||
.bits = 16|32|64,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = NULL,
|
||||
.modify = NULL,
|
||||
.assemble = &assemble,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.assemble = &assemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -47,8 +47,7 @@ RAsmPlugin r_asm_plugin_x86_olly = {
|
|||
.desc = "OllyDBG X86 disassembler",
|
||||
.arch = "x86",
|
||||
.bits = 32,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = &assemble,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1366,10 +1366,7 @@ RAsmPlugin r_asm_plugin_x86_tab = {
|
|||
.license = "LGPL3",
|
||||
.arch = "x86",
|
||||
.bits = 32, // maybe later: 16, 64
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = NULL,
|
||||
.modify = NULL,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.assemble = &assemble,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -77,11 +77,9 @@ RAsmPlugin r_asm_plugin_x86_udis = {
|
|||
.arch = "x86",
|
||||
.license = "BSD",
|
||||
.bits = 16 | 32 | 64,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.disassemble = &disassemble,
|
||||
.modify = &modify,
|
||||
.assemble = NULL,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -40,12 +40,9 @@ RAsmPlugin r_asm_plugin_xcore_cs = {
|
|||
.desc = "Capstone XCore disassembler",
|
||||
.license = "BSD",
|
||||
.arch = "xcore",
|
||||
.cpus = NULL,
|
||||
.bits = 32,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.disassemble = &disassemble,
|
||||
.assemble = NULL
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -88,9 +88,9 @@ RAsmPlugin r_asm_plugin_xtensa = {
|
|||
.arch = "xtensa",
|
||||
.license = "GPL3",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.desc = "XTensa CPU",
|
||||
.disassemble = &disassemble,
|
||||
0
|
||||
.disassemble = &disassemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -24,10 +24,9 @@ RAsmPlugin r_asm_plugin_z80 = {
|
|||
.license = "NC-GPL2", //NON-COMMERCIAL",
|
||||
.arch = "z80",
|
||||
.bits = 8,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = do_disassemble,
|
||||
.assemble = &do_assemble,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
.disassemble = &do_disassemble,
|
||||
.assemble = &do_assemble,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -17,10 +17,8 @@ RAsmPlugin r_asm_plugin_z80_cr = {
|
|||
.license = "LGPL",
|
||||
.arch = "z80",
|
||||
.bits = 8,
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.disassemble = do_disassemble,
|
||||
.assemble = NULL,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
.disassemble = &do_disassemble,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
|
|
|||
|
|
@ -1401,7 +1401,7 @@ R_API RList *r_bin_get_mem(RBin *bin) {
|
|||
|
||||
R_API int r_bin_is_big_endian(RBin *bin) {
|
||||
RBinObject *o = r_bin_cur_object (bin);
|
||||
return o? o->info->big_endian: false;
|
||||
return o? o->info->big_endian: -1;
|
||||
}
|
||||
|
||||
R_API int r_bin_is_stripped(RBin *bin) {
|
||||
|
|
|
|||
|
|
@ -80,8 +80,7 @@ static int init_ehdr(struct Elf_(r_bin_elf_obj_t) *bin) {
|
|||
" ident (elf_type)type (elf_machine)machine version entry phoff shoff flags ehsize"
|
||||
" phentsize phnum shentsize shnum shstrndx", 0);
|
||||
#endif
|
||||
bin->endian = (e_ident[EI_DATA] == ELFDATA2MSB) ?
|
||||
LIL_ENDIAN: !LIL_ENDIAN;
|
||||
bin->endian = (e_ident[EI_DATA] == ELFDATA2MSB)? 1: 0;
|
||||
memset (&bin->ehdr, 0, sizeof (Elf_(Ehdr)));
|
||||
len = r_buf_fread_at (bin->b, 0, (ut8*)&bin->ehdr,
|
||||
#if R_BIN_ELF64
|
||||
|
|
|
|||
|
|
@ -64,8 +64,6 @@ ut64 Elf_(r_bin_elf_resize_section)(struct Elf_(r_bin_elf_obj_t) *bin, const cha
|
|||
perror("read (rel)");
|
||||
|
||||
for (j = 0, relp = rel; j < shdrp->sh_size; j += sizeof(Elf_(Rel)), relp++) {
|
||||
r_mem_copyendian((ut8*)&(relp->r_offset), (ut8*)&(relp->r_offset),
|
||||
sizeof(Elf_(Addr)), !bin->endian);
|
||||
/* rewrite relp->r_offset */
|
||||
if (relp->r_offset - got_addr + got_offset >= rsz_offset + rsz_osize) {
|
||||
relp->r_offset+=delta;
|
||||
|
|
@ -88,8 +86,6 @@ ut64 Elf_(r_bin_elf_resize_section)(struct Elf_(r_bin_elf_obj_t) *bin, const cha
|
|||
perror("read (rel)");
|
||||
|
||||
for (j = 0, relp = rel; j < shdrp->sh_size; j += sizeof(Elf_(Rela)), relp++) {
|
||||
r_mem_copyendian((ut8*)&(relp->r_offset), (ut8*)&(relp->r_offset),
|
||||
sizeof(Elf_(Addr)), !bin->endian);
|
||||
/* rewrite relp->r_offset */
|
||||
if (relp->r_offset - got_addr + got_offset >= rsz_offset + rsz_osize) {
|
||||
relp->r_offset+=delta;
|
||||
|
|
|
|||
|
|
@ -89,17 +89,17 @@ static int init_hdr(struct MACH0_(obj_t)* bin) {
|
|||
return false;
|
||||
}
|
||||
if (magic == MACH0_(MH_MAGIC))
|
||||
bin->endian = !LIL_ENDIAN;
|
||||
bin->big_endian = false;
|
||||
else if (magic == MACH0_(MH_CIGAM))
|
||||
bin->endian = LIL_ENDIAN;
|
||||
bin->big_endian = true;
|
||||
else if (magic == FAT_CIGAM)
|
||||
bin->endian = LIL_ENDIAN;
|
||||
bin->big_endian = true;
|
||||
else return false; // object files are magic == 0, but body is different :?
|
||||
len = r_buf_fread_at (bin->b, 0, (ut8*)&bin->hdr,
|
||||
#if R_BIN_MACH064
|
||||
bin->endian?"8I":"8i", 1
|
||||
bin->big_endian?"8I":"8i", 1
|
||||
#else
|
||||
bin->endian?"7I":"7i", 1
|
||||
bin->big_endian?"7I":"7i", 1
|
||||
#endif
|
||||
);
|
||||
|
||||
|
|
@ -147,9 +147,9 @@ static int parse_segments(struct MACH0_(obj_t)* bin, ut64 off) {
|
|||
return false;
|
||||
}
|
||||
#if R_BIN_MACH064
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&bin->segs[seg], bin->endian?"2I16c4L4I":"2i16c4l4i", 1);
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&bin->segs[seg], bin->big_endian?"2I16c4L4I":"2i16c4l4i", 1);
|
||||
#else
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&bin->segs[seg], bin->endian?"2I16c8I":"2i16c8i", 1);
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&bin->segs[seg], bin->big_endian?"2I16c8I":"2i16c8i", 1);
|
||||
#endif
|
||||
if (len < 1)
|
||||
return false;
|
||||
|
|
@ -203,9 +203,9 @@ static int parse_segments(struct MACH0_(obj_t)* bin, ut64 off) {
|
|||
len = r_buf_fread_at (bin->b, off + sizeof (struct MACH0_(segment_command)),
|
||||
(ut8*)&bin->sects[sect],
|
||||
#if R_BIN_MACH064
|
||||
bin->endian?"16c16c2L8I":"16c16c2l8i",
|
||||
bin->big_endian?"16c16c2L8I":"16c16c2l8i",
|
||||
#else
|
||||
bin->endian?"16c16c9I":"16c16c9i",
|
||||
bin->big_endian?"16c16c9I":"16c16c9i",
|
||||
#endif
|
||||
bin->nsects - sect);
|
||||
if (len == 0 || len == -1) {
|
||||
|
|
@ -229,7 +229,7 @@ static int parse_symtab(struct MACH0_(obj_t)* bin, ut64 off) {
|
|||
if (off > bin->size || off + sizeof (struct symtab_command) > bin->size)
|
||||
return false;
|
||||
int len = r_buf_fread_at (bin->b, off, (ut8*)&st,
|
||||
bin->endian?"6I":"6i", 1);
|
||||
bin->big_endian?"6I":"6i", 1);
|
||||
if (len == 0 || len == -1) {
|
||||
eprintf ("Error: read (symtab)\n");
|
||||
return false;
|
||||
|
|
@ -265,10 +265,10 @@ static int parse_symtab(struct MACH0_(obj_t)* bin, ut64 off) {
|
|||
}
|
||||
#if R_BIN_MACH064
|
||||
len = r_buf_fread_at (bin->b, st.symoff, (ut8*)bin->symtab,
|
||||
bin->endian?"I2cSL":"i2csl", bin->nsymtab);
|
||||
bin->big_endian?"I2cSL":"i2csl", bin->nsymtab);
|
||||
#else
|
||||
len = r_buf_fread_at (bin->b, st.symoff, (ut8*)bin->symtab,
|
||||
bin->endian?"I2cSI":"i2csi", bin->nsymtab);
|
||||
bin->big_endian?"I2cSI":"i2csi", bin->nsymtab);
|
||||
#endif
|
||||
if (len == 0 || len == -1) {
|
||||
eprintf ("Error: read (nlist)\n");
|
||||
|
|
@ -286,7 +286,7 @@ static int parse_dysymtab(struct MACH0_(obj_t)* bin, ut64 off) {
|
|||
if (off > bin->size || off + sizeof (struct dysymtab_command) > bin->size)
|
||||
return false;
|
||||
|
||||
len = r_buf_fread_at(bin->b, off, (ut8*)&bin->dysymtab, bin->endian?"20I":"20i", 1);
|
||||
len = r_buf_fread_at(bin->b, off, (ut8*)&bin->dysymtab, bin->big_endian?"20I":"20i", 1);
|
||||
if (len == 0 || len == -1) {
|
||||
eprintf ("Error: read (dysymtab)\n");
|
||||
return false;
|
||||
|
|
@ -310,7 +310,7 @@ static int parse_dysymtab(struct MACH0_(obj_t)* bin, ut64 off) {
|
|||
return false;
|
||||
}
|
||||
len = r_buf_fread_at(bin->b, bin->dysymtab.tocoff,
|
||||
(ut8*)bin->toc, bin->endian?"2I":"2i", bin->ntoc);
|
||||
(ut8*)bin->toc, bin->big_endian?"2I":"2i", bin->ntoc);
|
||||
if (len == 0 || len == -1) {
|
||||
eprintf ("Error: read (toc)\n");
|
||||
R_FREE (bin->toc);
|
||||
|
|
@ -338,10 +338,10 @@ static int parse_dysymtab(struct MACH0_(obj_t)* bin, ut64 off) {
|
|||
}
|
||||
#if R_BIN_MACH064
|
||||
len = r_buf_fread_at (bin->b, bin->dysymtab.modtaboff,
|
||||
(ut8*)bin->modtab, bin->endian?"12IL":"12il", bin->nmodtab);
|
||||
(ut8*)bin->modtab, bin->big_endian?"12IL":"12il", bin->nmodtab);
|
||||
#else
|
||||
len = r_buf_fread_at (bin->b, bin->dysymtab.modtaboff,
|
||||
(ut8*)bin->modtab, bin->endian?"13I":"13i", bin->nmodtab);
|
||||
(ut8*)bin->modtab, bin->big_endian?"13I":"13i", bin->nmodtab);
|
||||
#endif
|
||||
if (len == -1) {
|
||||
eprintf ("Error: read (modtab)\n");
|
||||
|
|
@ -370,7 +370,7 @@ static int parse_dysymtab(struct MACH0_(obj_t)* bin, ut64 off) {
|
|||
}
|
||||
|
||||
len = r_buf_fread_at (bin->b, bin->dysymtab.indirectsymoff,
|
||||
(ut8*)bin->indirectsyms, bin->endian?"I":"i", bin->nindirectsyms);
|
||||
(ut8*)bin->indirectsyms, bin->big_endian?"I":"i", bin->nindirectsyms);
|
||||
if (len == -1) {
|
||||
eprintf ("Error: read (indirect syms)\n");
|
||||
R_FREE (bin->indirectsyms);
|
||||
|
|
@ -391,12 +391,12 @@ static int parse_thread(struct MACH0_(obj_t)* bin, struct load_command *lc, ut64
|
|||
return false;
|
||||
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&bin->thread,
|
||||
bin->endian?"2I":"2i", 1);
|
||||
bin->big_endian?"2I":"2i", 1);
|
||||
if (len == 0 || len == -1)
|
||||
goto wrong_read;
|
||||
|
||||
len = r_buf_fread_at(bin->b, off + sizeof(struct thread_command),
|
||||
(ut8*)&flavor, bin->endian?"1I":"1i", 1);
|
||||
(ut8*)&flavor, bin->big_endian?"1I":"1i", 1);
|
||||
if (len == -1)
|
||||
goto wrong_read;
|
||||
|
||||
|
|
@ -406,7 +406,7 @@ static int parse_thread(struct MACH0_(obj_t)* bin, struct load_command *lc, ut64
|
|||
|
||||
// TODO: use count for checks
|
||||
len = r_buf_fread_at(bin->b, off + sizeof(struct thread_command) + sizeof(flavor),
|
||||
(ut8*)&count, bin->endian?"1I":"1i", 1);
|
||||
(ut8*)&count, bin->big_endian?"1I":"1i", 1);
|
||||
if (len == -1)
|
||||
goto wrong_read;
|
||||
|
||||
|
|
@ -454,7 +454,7 @@ static int parse_thread(struct MACH0_(obj_t)* bin, struct load_command *lc, ut64
|
|||
if (ptr_thread + sizeof (struct ppc_thread_state32) > bin->size)
|
||||
return false;
|
||||
if ((len = r_buf_fread_at (bin->b, ptr_thread,
|
||||
(ut8*)&bin->thread_state.ppc_32, bin->endian?"40I":"40i", 1)) == -1) {
|
||||
(ut8*)&bin->thread_state.ppc_32, bin->big_endian?"40I":"40i", 1)) == -1) {
|
||||
eprintf ("Error: read (thread state ppc_32)\n");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -466,7 +466,7 @@ static int parse_thread(struct MACH0_(obj_t)* bin, struct load_command *lc, ut64
|
|||
if (ptr_thread + sizeof (struct ppc_thread_state64) > bin->size)
|
||||
return false;
|
||||
if ((len = r_buf_fread_at (bin->b, ptr_thread,
|
||||
(ut8*)&bin->thread_state.ppc_64, bin->endian?"34LI3LI":"34li3li", 1)) == -1) {
|
||||
(ut8*)&bin->thread_state.ppc_64, bin->big_endian?"34LI3LI":"34li3li", 1)) == -1) {
|
||||
eprintf ("Error: read (thread state ppc_64)\n");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -480,7 +480,7 @@ static int parse_thread(struct MACH0_(obj_t)* bin, struct load_command *lc, ut64
|
|||
if (ptr_thread + sizeof (struct arm_thread_state32) > bin->size)
|
||||
return false;
|
||||
if ((len = r_buf_fread_at (bin->b, ptr_thread,
|
||||
(ut8*)&bin->thread_state.arm_32, bin->endian?"17I":"17i", 1)) == -1) {
|
||||
(ut8*)&bin->thread_state.arm_32, bin->big_endian?"17I":"17i", 1)) == -1) {
|
||||
eprintf ("Error: read (thread state arm)\n");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -493,7 +493,7 @@ static int parse_thread(struct MACH0_(obj_t)* bin, struct load_command *lc, ut64
|
|||
if (ptr_thread + sizeof (struct arm_thread_state64) > bin->size)
|
||||
return false;
|
||||
if ((len = r_buf_fread_at(bin->b, ptr_thread,
|
||||
(ut8*)&bin->thread_state.arm_64, bin->endian?"34LI1I":"34Li1i", 1)) == -1) {
|
||||
(ut8*)&bin->thread_state.arm_64, bin->big_endian?"34LI1I":"34Li1i", 1)) == -1) {
|
||||
eprintf ("Error: read (thread state arm)\n");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -543,7 +543,7 @@ static int parse_function_starts (struct MACH0_(obj_t)* bin, ut64 off) {
|
|||
" LC_FUNCTION_STARTS command\n");
|
||||
}
|
||||
bin->func_start = NULL;
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&fc, bin->endian ? "4I" : "4i", 1);
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&fc, bin->big_endian ? "4I" : "4i", 1);
|
||||
if (len < 1) {
|
||||
eprintf ("Failed to get data while parsing"
|
||||
" LC_FUNCTION_STARTS command\n");
|
||||
|
|
@ -584,7 +584,7 @@ static int parse_dylib(struct MACH0_(obj_t)* bin, ut64 off) {
|
|||
perror ("realloc (libs)");
|
||||
return false;
|
||||
}
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&dl, bin->endian?"6I":"6i", 1);
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&dl, bin->big_endian?"6I":"6i", 1);
|
||||
if (len == 0 || len == -1) {
|
||||
eprintf ("Error: read (dylib)\n");
|
||||
return false;
|
||||
|
|
@ -623,7 +623,7 @@ static int init_items(struct MACH0_(obj_t)* bin) {
|
|||
eprintf ("mach0: out of bounds command\n");
|
||||
return false;
|
||||
}
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&lc, bin->endian?"2I":"2i", 1);
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&lc, bin->big_endian?"2I":"2i", 1);
|
||||
if (len == 0 || len == -1) {
|
||||
eprintf ("Error: read (lc) at 0x%08"PFMT64x"\n", off);
|
||||
return false;
|
||||
|
|
@ -724,7 +724,7 @@ static int init_items(struct MACH0_(obj_t)* bin) {
|
|||
return false;
|
||||
}
|
||||
if (r_buf_fread_at (bin->b, off, (ut8*)&eic,
|
||||
bin->endian?"5I":"5i", 1) != -1) {
|
||||
bin->big_endian?"5I":"5i", 1) != -1) {
|
||||
bin->has_crypto = eic.cryptid;
|
||||
sdb_set (bin->kv, "crypto", "true", 0);
|
||||
sdb_num_set (bin->kv, "cryptid", eic.cryptid, 0);
|
||||
|
|
@ -745,7 +745,7 @@ static int init_items(struct MACH0_(obj_t)* bin) {
|
|||
return false;
|
||||
}
|
||||
if (r_buf_fread_at (bin->b, off, (ut8*)&dy,
|
||||
bin->endian?"3I":"3i", 1) == -1) {
|
||||
bin->big_endian?"3I":"3i", 1) == -1) {
|
||||
eprintf ("Warning: read (LC_DYLD_INFO) at 0x%08"PFMT64x"\n", off);
|
||||
} else {
|
||||
int len = dy.cmdsize;
|
||||
|
|
@ -776,7 +776,7 @@ static int init_items(struct MACH0_(obj_t)* bin) {
|
|||
return false;
|
||||
}
|
||||
r_buf_fread_at (bin->b, off+8, (void*)&ep,
|
||||
bin->endian?"2L": "2l", 1);
|
||||
bin->big_endian?"2L": "2l", 1);
|
||||
bin->entry = ep.eo;
|
||||
bin->main_cmd = lc;
|
||||
|
||||
|
|
@ -819,7 +819,7 @@ static int init_items(struct MACH0_(obj_t)* bin) {
|
|||
return false;
|
||||
}
|
||||
if (r_buf_fread_at (bin->b, off, (ut8*)bin->dyld_info,
|
||||
bin->endian?"12I":"12i", 1) == -1) {
|
||||
bin->big_endian?"12I":"12i", 1) == -1) {
|
||||
free (bin->dyld_info);
|
||||
bin->dyld_info = NULL;
|
||||
eprintf ("Error: read (LC_DYLD_INFO) at 0x%08"PFMT64x"\n", off);
|
||||
|
|
@ -1632,7 +1632,7 @@ int MACH0_(get_bits)(struct MACH0_(obj_t)* bin) {
|
|||
}
|
||||
|
||||
int MACH0_(is_big_endian)(struct MACH0_(obj_t)* bin) {
|
||||
return bin && bin->endian;
|
||||
return bin && bin->big_endian;
|
||||
}
|
||||
|
||||
const char* MACH0_(get_intrp)(struct MACH0_(obj_t)* bin) {
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ struct MACH0_(obj_t) {
|
|||
int size;
|
||||
ut64 baddr;
|
||||
ut64 entry;
|
||||
int endian;
|
||||
bool big_endian;
|
||||
const char* file;
|
||||
RBuffer* b;
|
||||
int os;
|
||||
|
|
|
|||
|
|
@ -179,12 +179,12 @@ static int check_bytes(const ut8 *buf, ut64 length) {
|
|||
bool ret = false;
|
||||
int off, version = 0;
|
||||
if (buf && length>32 && !memcmp (buf, "\xca\xfe\xba\xbe", 4)) {
|
||||
memcpy (&off, buf + 4 * sizeof(int), sizeof(int));
|
||||
// XXX not sure about endianness here
|
||||
memcpy (&off, buf + 4 * sizeof (int), sizeof (int));
|
||||
version = buf[6] | (buf[7] <<8);
|
||||
if (version>1024) {
|
||||
r_mem_copyendian ((ut8*)&off,
|
||||
(ut8*)&off, sizeof(int),
|
||||
!LIL_ENDIAN);
|
||||
// XXX is this correct in all cases? opposite of prev?
|
||||
r_mem_swapendian ((ut8*)&off, (ut8*)&off, sizeof (int));
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ static RList* sections(RBinFile *arch) {
|
|||
ret->free = free;
|
||||
|
||||
// add text segment
|
||||
textsize = r_mem_get_num (arch->buf->buf+4, 4, big_endian);
|
||||
textsize = r_mem_get_num (arch->buf->buf + 4, 4);
|
||||
if (!(ptr = R_NEW0 (RBinSection)))
|
||||
return ret;
|
||||
strncpy (ptr->name, "text", R_BIN_SIZEOF_STRINGS);
|
||||
|
|
@ -88,7 +88,7 @@ static RList* sections(RBinFile *arch) {
|
|||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
// add data segment
|
||||
datasize = r_mem_get_num (arch->buf->buf+8, 4, big_endian);
|
||||
datasize = r_mem_get_num (arch->buf->buf+8, 4);
|
||||
if (datasize>0) {
|
||||
if (!(ptr = R_NEW0 (RBinSection)))
|
||||
return ret;
|
||||
|
|
@ -103,7 +103,7 @@ static RList* sections(RBinFile *arch) {
|
|||
}
|
||||
// ignore bss or what
|
||||
// add syms segment
|
||||
symssize = r_mem_get_num (arch->buf->buf+16, 4, big_endian);
|
||||
symssize = r_mem_get_num (arch->buf->buf+16, 4);
|
||||
if (symssize) {
|
||||
if (!(ptr = R_NEW0 (RBinSection)))
|
||||
return ret;
|
||||
|
|
@ -117,7 +117,7 @@ static RList* sections(RBinFile *arch) {
|
|||
r_list_append (ret, ptr);
|
||||
}
|
||||
// add spsz segment
|
||||
spszsize = r_mem_get_num (arch->buf->buf+24, 4, big_endian);
|
||||
spszsize = r_mem_get_num (arch->buf->buf+24, 4);
|
||||
if (spszsize) {
|
||||
if (!(ptr = R_NEW0 (RBinSection)))
|
||||
return ret;
|
||||
|
|
@ -131,7 +131,7 @@ static RList* sections(RBinFile *arch) {
|
|||
r_list_append (ret, ptr);
|
||||
}
|
||||
// add pcsz segment
|
||||
pcszsize = r_mem_get_num (arch->buf->buf+24, 4, big_endian);
|
||||
pcszsize = r_mem_get_num (arch->buf->buf+24, 4);
|
||||
if (pcszsize) {
|
||||
if (!(ptr = R_NEW0 (RBinSection)))
|
||||
return ret;
|
||||
|
|
@ -192,11 +192,11 @@ static int size(RBinFile *arch) {
|
|||
if (!arch->o->info) return 0;
|
||||
big_endian = arch->o->info->big_endian;
|
||||
// TODO: reuse section list
|
||||
text = r_mem_get_num (arch->buf->buf+4, 4, big_endian);
|
||||
data = r_mem_get_num (arch->buf->buf+8, 4, big_endian);
|
||||
syms = r_mem_get_num (arch->buf->buf+16, 4, big_endian);
|
||||
spsz = r_mem_get_num (arch->buf->buf+24, 4, big_endian);
|
||||
return text+data+syms+spsz+(6*4);
|
||||
text = r_mem_get_num (arch->buf->buf + 4, 4);
|
||||
data = r_mem_get_num (arch->buf->buf + 8, 4);
|
||||
syms = r_mem_get_num (arch->buf->buf + 16, 4);
|
||||
spsz = r_mem_get_num (arch->buf->buf + 24, 4);
|
||||
return text + data + syms + spsz + (6*4);
|
||||
}
|
||||
|
||||
#if !R_BIN_P9
|
||||
|
|
|
|||
|
|
@ -241,9 +241,8 @@ static RList* symbols(RBinFile *arch) {
|
|||
}
|
||||
if (name && vtable[i]) {
|
||||
ut32 addr = 0;
|
||||
r_mem_copyendian ((ut8*)&addr,
|
||||
(const ut8*)&vtable[i],
|
||||
sizeof (addr), 0);
|
||||
// XXX don't know if always LE
|
||||
addr = r_read_le32 (&vtable[i]);
|
||||
addsym (ret, name, addr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ static int check(RBin *bin) {
|
|||
return false;
|
||||
}
|
||||
h = m->buf;
|
||||
if (m->len>=0x300 && !memcmp (h, "\xca\xfe\xba\xbe", 4)) {
|
||||
memcpy (&off, h+4*sizeof (int), sizeof (int));
|
||||
r_mem_copyendian ((ut8*)&off, (ut8*)&off, sizeof(int), !LIL_ENDIAN);
|
||||
if (m->len >= 0x300 && !memcmp (h, "\xca\xfe\xba\xbe", 4)) {
|
||||
// XXX assuming BE
|
||||
off = r_read_at_be32 (h, 4 * sizeof (int));
|
||||
if (off > 0 && off < m->len) {
|
||||
memcpy (buf, h+off, 4);
|
||||
memcpy (buf, h + off, 4);
|
||||
if (!memcmp (buf, "\xce\xfa\xed\xfe", 4) ||
|
||||
!memcmp (buf, "\xfe\xed\xfa\xce", 4) ||
|
||||
!memcmp (buf, "\xfe\xed\xfa\xcf", 4) ||
|
||||
|
|
@ -45,12 +45,13 @@ static int check_bytes(const ut8* bytes, ut64 sz) {
|
|||
if (!bytes || sz < 0x300) {
|
||||
return false;
|
||||
}
|
||||
memcpy (&off, bytes+4*sizeof (int), sizeof (int));
|
||||
r_mem_copyendian ((ut8*)&off, (ut8*)&off, sizeof(int), !LIL_ENDIAN);
|
||||
// XXX assuming BE
|
||||
off = r_read_at_be32 (bytes, 4 * sizeof (int));
|
||||
|
||||
h = bytes;
|
||||
if (sz>=0x300 && !memcmp (h, "\xca\xfe\xba\xbe", 4)) {
|
||||
r_mem_copyendian ((ut8*)&off, (ut8*)h+4*sizeof(int), sizeof(int), !LIL_ENDIAN);
|
||||
if (sz >= 0x300 && !memcmp (h, "\xca\xfe\xba\xbe", 4)) {
|
||||
// XXX assuming BE
|
||||
off = r_read_at_be32 (h, 4 * sizeof (int));
|
||||
if (off > 0 && off < sz) {
|
||||
memcpy (buf, h+off, 4);
|
||||
if (!memcmp (buf, "\xce\xfa\xed\xfe", 4) ||
|
||||
|
|
|
|||
|
|
@ -340,7 +340,8 @@ static int r_anal_try_get_fcn(RCore *core, RAnalRef *ref, int fcndepth, int refd
|
|||
ref1.at = ref->addr;
|
||||
ref1.addr = 0;
|
||||
for (offs = 0; offs < bufsz; offs += sz, ref1.at += sz) {
|
||||
r_mem_copyendian ((ut8*)&ref1.addr, buf + offs, sz, !core->anal->big_endian);
|
||||
// XXX wtf endian
|
||||
memcpy ((ut8*)&ref1.addr, buf + offs, sz);
|
||||
r_anal_try_get_fcn (core, &ref1, fcndepth, refdepth-1);
|
||||
}
|
||||
}
|
||||
|
|
@ -1745,7 +1746,7 @@ R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts) {
|
|||
|
||||
static int core_anal_followptr(RCore *core, int type, ut64 at, ut64 ptr, ut64 ref, int code, int depth) {
|
||||
ut64 dataptr;
|
||||
int wordsize, endian;
|
||||
int wordsize;
|
||||
|
||||
if (ptr == ref) {
|
||||
if (code) {
|
||||
|
|
@ -1760,11 +1761,9 @@ static int core_anal_followptr(RCore *core, int type, ut64 at, ut64 ptr, ut64 re
|
|||
}
|
||||
if (depth < 1)
|
||||
return false;
|
||||
if (core->bin && core->bin->cur && core->bin->cur->o && core->bin->cur->o->info) {
|
||||
endian = core->bin->cur->o->info->big_endian;
|
||||
} else endian = CPU_ENDIAN;
|
||||
|
||||
wordsize = (int)(core->anal->bits/8);
|
||||
if ((dataptr = r_io_read_i (core->io, ptr, wordsize, endian)) == -1)
|
||||
if ((dataptr = r_io_read_i (core->io, ptr, wordsize)) == -1)
|
||||
return false;
|
||||
return core_anal_followptr (core, type, at, dataptr, ref, code, depth - 1);
|
||||
}
|
||||
|
|
@ -2148,7 +2147,6 @@ R_API int r_core_anal_data (RCore *core, ut64 addr, int count, int depth) {
|
|||
ut8 *buf = core->block;
|
||||
int len = core->blocksize;
|
||||
int word = core->assembler->bits /8;
|
||||
int endi = core->anal->big_endian;
|
||||
char *str;
|
||||
int i, j;
|
||||
|
||||
|
|
@ -2162,12 +2160,12 @@ R_API int r_core_anal_data (RCore *core, ut64 addr, int count, int depth) {
|
|||
|
||||
for (i = j = 0; j<count; j++ ) {
|
||||
if (i>=len) {
|
||||
r_io_read_at (core->io, addr+i, buf, len);
|
||||
r_io_read_at (core->io, addr + i, buf, len);
|
||||
addr += i;
|
||||
i = 0;
|
||||
continue;
|
||||
}
|
||||
d = r_anal_data (core->anal, addr+i, buf+i, len-i);
|
||||
d = r_anal_data (core->anal, addr + i, buf + i, len - i);
|
||||
str = r_anal_data_to_string (d);
|
||||
r_cons_printf ("%s\n", str);
|
||||
|
||||
|
|
@ -2175,14 +2173,14 @@ R_API int r_core_anal_data (RCore *core, ut64 addr, int count, int depth) {
|
|||
switch (d->type) {
|
||||
case R_ANAL_DATA_TYPE_POINTER:
|
||||
r_cons_printf ("`- ");
|
||||
dstaddr = r_mem_get_num (buf+i, word, !endi);
|
||||
if (depth>0)
|
||||
r_core_anal_data (core, dstaddr, 1, depth-1);
|
||||
dstaddr = r_mem_get_num (buf + i, word);
|
||||
if (depth > 0)
|
||||
r_core_anal_data (core, dstaddr, 1, depth - 1);
|
||||
i += word;
|
||||
break;
|
||||
case R_ANAL_DATA_TYPE_STRING:
|
||||
buf[len-1] = 0;
|
||||
i += strlen ((const char*)buf+i)+1;
|
||||
i += strlen ((const char*)buf + i) + 1;
|
||||
break;
|
||||
default:
|
||||
i += (d->len > 3)? d->len: word;
|
||||
|
|
|
|||
|
|
@ -2989,7 +2989,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
|
|||
r_asm_disassemble (core->assembler, &asmop, buf, size);
|
||||
char str[512];
|
||||
r_parse_filter (core->parser, core->flags,
|
||||
asmop.buf_asm, str, sizeof (str));
|
||||
asmop.buf_asm, str, sizeof (str), core->print->big_endian);
|
||||
r_cons_printf ("{\"from\":%" PFMT64u ",\"type\":\"%c\",\"opcode\":\"%s\"}%s",
|
||||
ref->addr, ref->type, str, iter->n? ",": "");
|
||||
}
|
||||
|
|
@ -3011,7 +3011,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
|
|||
r_asm_set_pc (core->assembler, ref->addr);
|
||||
r_asm_disassemble (core->assembler, &asmop, buf, size);
|
||||
r_parse_filter (core->parser, core->flags,
|
||||
asmop.buf_asm, str, sizeof (str));
|
||||
asmop.buf_asm, str, sizeof (str), core->print->big_endian);
|
||||
fcn = r_anal_get_fcn_in (core->anal, ref->addr, 0);
|
||||
if (has_color) {
|
||||
buf_asm = r_print_colorize_opcode (str, core->cons->pal.reg,
|
||||
|
|
@ -3078,7 +3078,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
|
|||
r_asm_set_pc (core->assembler, ref->at);
|
||||
r_asm_disassemble (core->assembler, &asmop, buf, 12);
|
||||
r_parse_filter (core->parser, core->flags,
|
||||
asmop.buf_asm, str, sizeof (str));
|
||||
asmop.buf_asm, str, sizeof (str), core->print->big_endian);
|
||||
buf_asm = r_print_colorize_opcode (str, core->cons->pal.reg,
|
||||
core->cons->pal.num);
|
||||
r_cons_printf ("%c 0x%" PFMT64x " %s\n",
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue