mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-11 23:16:05 +00:00
Random enhacements for RHex apis and relocs
This commit is contained in:
parent
424e16626d
commit
4790375679
@ -380,7 +380,8 @@ R_API RAsmCode* r_asm_mdisassemble(RAsm *a, const ut8 *buf, int len) {
|
||||
ret = r_asm_disassemble (a, &op, buf+idx, len-idx);
|
||||
if (ret<1) {
|
||||
eprintf ("disassemble error at offset %"PFMT64d"\n", idx);
|
||||
return acode;
|
||||
ret = 1;
|
||||
// return acode;
|
||||
}
|
||||
if (a->ofilter)
|
||||
r_parse_parse (a->ofilter, op.buf_asm, op.buf_asm);
|
||||
|
@ -1038,6 +1038,15 @@ struct r_bin_elf_symbol_t* Elf_(r_bin_elf_get_symbols)(struct Elf_(r_bin_elf_obj
|
||||
Elf_(Shdr) *strtab_section;
|
||||
Elf_(Sym) *sym;
|
||||
char *strtab;
|
||||
Elf_(Shdr)* section_text = NULL;
|
||||
ut64 section_text_offset = 0LL;
|
||||
|
||||
if (bin->ehdr.e_type== ET_REL) {
|
||||
section_text = Elf_(r_bin_elf_get_section_by_name)(bin, ".text");
|
||||
if (section_text) {
|
||||
section_text_offset = section_text->sh_offset;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bin || !bin->shdr || bin->ehdr.e_shnum == 0 || bin->ehdr.e_shnum == 0xffff)
|
||||
return NULL;
|
||||
@ -1049,6 +1058,7 @@ struct r_bin_elf_symbol_t* Elf_(r_bin_elf_get_symbols)(struct Elf_(r_bin_elf_obj
|
||||
data_offset = 0;
|
||||
}
|
||||
shdr_size = bin->ehdr.e_shnum * sizeof (Elf_(Shdr));
|
||||
|
||||
for (i = 0; i < bin->ehdr.e_shnum; i++) {
|
||||
#define BUGGY 0
|
||||
#if BUGGY
|
||||
@ -1136,6 +1146,8 @@ if (
|
||||
}
|
||||
#endif
|
||||
ret[ret_ctr].offset = (toffset >= bin->baddr ? toffset -= bin->baddr : toffset);
|
||||
if (section_text)
|
||||
ret[ret_ctr].offset += section_text_offset;
|
||||
ret[ret_ctr].size = tsize;
|
||||
if (sym[k].st_name > strtab_section->sh_size) {
|
||||
eprintf ("Warning: index out of strtab range\n");
|
||||
|
@ -492,7 +492,6 @@ static int bin_pdb (RCore *core, int mode) {
|
||||
static int bin_main (RCore *r, int mode, ut64 baddr, int va) {
|
||||
RBinAddr *binmain = r_bin_get_sym (r->bin, R_BIN_SYM_MAIN);
|
||||
if (!binmain) return R_FALSE;
|
||||
|
||||
baddr = 0LL; // This is broken, just to make t.formats/elf/main happy
|
||||
if ((mode & R_CORE_BIN_SIMPLE) || mode & R_CORE_BIN_JSON) {
|
||||
r_cons_printf ("%"PFMT64d, va? (baddr+binmain->vaddr):binmain->paddr);
|
||||
|
@ -1177,9 +1177,9 @@ static int cmd_print(void *data, const char *input) {
|
||||
r_core_block_size (core, obsz);
|
||||
break;
|
||||
case 'a': //pa
|
||||
if (input[1]=='e') {
|
||||
if (input[1]=='e') { // "pae"
|
||||
if (input[2]=='?') {
|
||||
r_cons_printf("|Usage: pae [hex] assemble esil from hexpairs\n");
|
||||
r_cons_printf ("|Usage: pae [hex] assemble esil from hexpairs\n");
|
||||
} else {
|
||||
int ret, bufsz;
|
||||
RAnalOp aop = {0};
|
||||
@ -1194,9 +1194,9 @@ static int cmd_print(void *data, const char *input) {
|
||||
}
|
||||
r_anal_op_fini (&aop);
|
||||
}
|
||||
} else if (input[1]=='d') {
|
||||
} else if (input[1]=='d') { // "pad"
|
||||
if (input[2]=='?') {
|
||||
r_cons_printf("|Usage: pad [asm] disasm\n");
|
||||
r_cons_printf ("|Usage: pad [asm] disasm\n");
|
||||
} else {
|
||||
RAsmCode *c;
|
||||
r_asm_set_pc (core->assembler, core->offset);
|
||||
|
@ -134,7 +134,6 @@ typedef struct r_bin_object_t {
|
||||
} RBinObject;
|
||||
|
||||
// XXX: this is a copy of RBinObject
|
||||
// TODO: rename RBinFile to RBinFile
|
||||
typedef struct r_bin_file_t {
|
||||
char *file;
|
||||
int fd;
|
||||
|
@ -190,7 +190,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
|
||||
open_pidmem (riop);
|
||||
pidpath = r_sys_pid_to_path (pid);
|
||||
// sleep 1s to get proper path (racy)
|
||||
r_sys_sleep (1);
|
||||
//r_sys_sleep (1);
|
||||
desc = r_io_desc_new (&r_io_plugin_ptrace, pid,
|
||||
pidpath, rw | R_IO_EXEC, mode, riop);
|
||||
free (pidpath);
|
||||
|
@ -112,11 +112,16 @@ R_API int r_hex_str2bin(const char *in, ut8 *out) {
|
||||
int len = 0, j = 0;
|
||||
const char *ptr;
|
||||
ut8 c = 0, d = 0;
|
||||
int outbuf = 0;
|
||||
|
||||
if (!in || !*in)
|
||||
return 0;
|
||||
if (!memcmp (in, "0x", 2))
|
||||
in += 2;
|
||||
if (!out) {
|
||||
outbuf = 1;
|
||||
out = malloc (strlen (in));
|
||||
}
|
||||
for (ptr = in; ; ptr++) {
|
||||
/* comments */
|
||||
if (*ptr=='#') {
|
||||
@ -176,16 +181,20 @@ R_API int r_hex_str2bin(const char *in, ut8 *out) {
|
||||
}
|
||||
if (r_hex_to_byte (&c, ptr[0])) {
|
||||
//eprintf("binstr: Invalid hexa string at %d ('0x%02x') (%s).\n", (int)(ptr-in), ptr[0], in);
|
||||
return len;
|
||||
goto beach;
|
||||
}
|
||||
c |= d;
|
||||
if (j++ == 0) c <<= 4;
|
||||
}
|
||||
// has nibbles. requires a mask
|
||||
beach:
|
||||
if (j) {
|
||||
out[len] = c;
|
||||
len = -len;
|
||||
}
|
||||
if (outbuf) {
|
||||
free (out);
|
||||
}
|
||||
return (int)len;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user