mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-27 15:10:53 +00:00
Refactor the io/oi commands and fix io behaviour ##io
This commit is contained in:
parent
560c02deac
commit
8e37c73859
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2023 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2024 - pancake */
|
||||
|
||||
#define R_LOG_ORIGIN "cfile"
|
||||
|
||||
@ -32,7 +32,7 @@ static bool its_a_mips(RCore *core) {
|
||||
return cfg && cfg->arch && !strcmp (cfg->arch, "mips");
|
||||
}
|
||||
|
||||
static void loadGP(RCore *core) {
|
||||
static void load_gp(RCore *core) {
|
||||
// R2R db/cmd/cmd_eval
|
||||
if (its_a_mips (core)) {
|
||||
ut64 e0 = r_num_math (core->num, "entry0");
|
||||
@ -190,7 +190,7 @@ R_API bool r_core_file_reopen(RCore *core, const char *args, int perm, int loadb
|
||||
r_core_cmd0 (core, ".dr*");
|
||||
r_core_cmd_call (core, "sr PC");
|
||||
} else {
|
||||
loadGP (core);
|
||||
load_gp (core);
|
||||
}
|
||||
// update anal io bind
|
||||
r_io_bind (core->io, &(core->anal->iob));
|
||||
@ -631,8 +631,6 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
r_return_val_if_fail (r && r->io, false);
|
||||
R_CRITICAL_ENTER (r);
|
||||
ut64 laddr = r_config_get_i (r->config, "bin.laddr");
|
||||
RBinFile *binfile = NULL;
|
||||
RBinPlugin *plugin = NULL;
|
||||
RIODesc *desc = r->io->desc;
|
||||
if (!desc && filenameuri) {
|
||||
desc = r_io_desc_get_byuri (r->io, filenameuri);
|
||||
@ -654,36 +652,34 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
// dont try to guess the bin file in the address 0 if we are using r2frida
|
||||
is_io_load = false;
|
||||
}
|
||||
// r_io_use_fd (r->io, desc->fd);
|
||||
}
|
||||
r->bin->minstrlen = r_config_get_i (r->config, "bin.str.min");
|
||||
r->bin->maxstrbuf = r_config_get_i (r->config, "bin.str.maxbuf");
|
||||
R_CRITICAL_LEAVE (r);
|
||||
if (is_io_load) {
|
||||
if (desc && is_io_load) {
|
||||
// TODO? necessary to restore the desc back?
|
||||
// Fix to select pid before trying to load the binary
|
||||
if ((desc->plugin && desc->plugin->isdbg) || r_config_get_b (r->config, "cfg.debug")) {
|
||||
r_core_file_load_for_debug (r, baddr, filenameuri);
|
||||
} else {
|
||||
if (filenameuri && filenameuri[0] != '-' && strcmp (filenameuri, desc->uri)) {
|
||||
r_core_file_open (r, filenameuri, 0, baddr);
|
||||
}
|
||||
r_core_file_load_for_io_plugin (r, baddr, 0LL);
|
||||
}
|
||||
r_io_use_fd (r->io, desc->fd);
|
||||
// Restore original desc
|
||||
} else if (desc != NULL) {
|
||||
r_io_use_fd (r->io, desc->fd);
|
||||
r_io_map_add (r->io, desc->fd, R_PERM_RWX, 0LL, 0, r_io_desc_size (desc));
|
||||
}
|
||||
if (binfile && desc) {
|
||||
binfile->fd = desc->fd;
|
||||
}
|
||||
binfile = r_bin_cur (r->bin);
|
||||
RBinFile *binfile = r_bin_cur (r->bin);
|
||||
if (r->bin->cur && r->bin->cur->bo && r->bin->cur->bo->plugin && r->bin->cur->bo->plugin->strfilter) {
|
||||
char msg[2];
|
||||
msg[0] = r->bin->cur->bo->plugin->strfilter;
|
||||
msg[1] = 0;
|
||||
r_config_set (r->config, "bin.str.filter", msg);
|
||||
}
|
||||
plugin = r_bin_file_cur_plugin (binfile);
|
||||
RBinPlugin *plugin = r_bin_file_cur_plugin (binfile);
|
||||
#if 0
|
||||
//r_core_bin_set_env (r, binfile);
|
||||
if (plugin && plugin->name) {
|
||||
@ -714,7 +710,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
if (!va) {
|
||||
r_config_set_i (r->config, "io.va", 0);
|
||||
}
|
||||
//workaround to map correctly malloc:// and raw binaries
|
||||
// workaround to map correctly malloc:// and raw binaries
|
||||
if (r_io_desc_is_dbg (desc) || (!obj->sections || !va)) {
|
||||
r_io_map_add (r->io, desc->fd, desc->perm, 0, laddr, r_io_desc_size (desc));
|
||||
}
|
||||
@ -746,7 +742,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
r_core_cmd0 (r, "'(fix-dex;wx `ph sha1 $s-32 @32` @12;wx `ph adler32 $s-12 @12` @8)");
|
||||
}
|
||||
if (!r_config_get_b (r->config, "cfg.debug")) {
|
||||
loadGP (r);
|
||||
load_gp (r);
|
||||
}
|
||||
if (r_config_get_b (r->config, "bin.libs")) {
|
||||
const char *lib;
|
||||
@ -969,8 +965,8 @@ R_API RIODesc *r_core_file_open(RCore *r, const char *file, int flags, ut64 load
|
||||
}
|
||||
}
|
||||
}
|
||||
//used by r_core_bin_load otherwise won't load correctly
|
||||
//this should be argument of r_core_bin_load <shrug>
|
||||
// used by r_core_bin_load otherwise won't load correctly
|
||||
// this should be argument of r_core_bin_load <shrug>
|
||||
if (loadaddr != UT64_MAX) {
|
||||
r_config_set_i (r->config, "bin.laddr", loadaddr);
|
||||
}
|
||||
|
@ -1602,6 +1602,24 @@ static void cmd_ik(RCore *core, const char *input) {
|
||||
}
|
||||
}
|
||||
|
||||
struct fdof_t {
|
||||
RCore *core;
|
||||
const char *fn;
|
||||
int fd;
|
||||
};
|
||||
|
||||
static bool fdof_cb(void *user, void *data, ut32 id) {
|
||||
struct fdof_t *fof = (struct fdof_t *)user;
|
||||
RIODesc *desc = (RIODesc *)data;
|
||||
if (fof && desc) {
|
||||
if (!strcmp (desc->uri, fof->fn)) {
|
||||
fof->fd = desc->fd;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int cmd_info(void *data, const char *input) {
|
||||
RCore *core = (RCore *) data;
|
||||
int fd = r_io_fd_get_current (core->io);
|
||||
@ -1933,9 +1951,21 @@ static int cmd_info(void *data, const char *input) {
|
||||
break;
|
||||
case 'o': // "io"
|
||||
if (desc) {
|
||||
const char *fn = input[1] == ' '? input + 2: desc->name;
|
||||
int oldfd = -1;
|
||||
const char *fn = (input[1] == ' ')
|
||||
? r_str_trim_head_ro (input + 2): desc->name;
|
||||
struct fdof_t fof = { core, fn, -1 };
|
||||
r_id_storage_foreach (core->io->files, fdof_cb, &fof);
|
||||
if (fof.fd != -1) {
|
||||
oldfd = fof.fd;
|
||||
}
|
||||
ut64 baddr = r_config_get_i (core->config, "bin.baddr");
|
||||
fof.fd = -1;
|
||||
r_core_bin_load (core, fn, baddr);
|
||||
r_id_storage_foreach (core->io->files, fdof_cb, &fof);
|
||||
if (fof.fd != oldfd) {
|
||||
r_core_cmdf (core, "o-%d", fof.fd);
|
||||
}
|
||||
} else {
|
||||
R_LOG_ERROR ("Core file not open");
|
||||
return 0;
|
||||
|
@ -40,3 +40,17 @@ EXPECT=<<EOF
|
||||
EOF
|
||||
RUN
|
||||
|
||||
# we shouldnt be using anal.emu=true to find this xref
|
||||
NAME=aaa missing stref
|
||||
FILE=bins/elf/libtoolocore.so
|
||||
ARGS=-e anal.emu=true
|
||||
CMDS=<<EOF
|
||||
aaa
|
||||
s 0x00001373
|
||||
axt
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
fcn.00003004 0x337c [STRN:-w-] add x1, x1, str.3082058830820370a00302010202147dc6315182dee2344f870acce7b12d5fea665fa4300d06092a864886f70d01010b05003074310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f69643110300e06035504031307416e64726f69643020170d3233303333313033313632355a180f32303533303333313033313632355a3074310b3009060355040613025553311330110603550408130a43616c69666f726e69613116301406035504071
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
@ -46,46 +46,6 @@ vaddr name
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=ooi
|
||||
FILE=bins/elf/analysis/main
|
||||
CMDS=<<EOF
|
||||
e bin.baddr=0
|
||||
e asm.cmt.calls=false
|
||||
ooi
|
||||
op 3
|
||||
e io.va=0
|
||||
s entry0
|
||||
pi 1
|
||||
?p
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
xor ebp, ebp
|
||||
0x00000410
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=ooiooi
|
||||
FILE=bins/elf/analysis/main
|
||||
CMDS=<<EOF
|
||||
?e works
|
||||
ooi;ooi
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
works
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=ooiooi2
|
||||
FILE=bins/elf/analysis/main
|
||||
CMDS=<<EOF
|
||||
ooi;ooi
|
||||
?e works
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
works
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=iZ
|
||||
FILE=bins/elf/analysis/x86-helloworld-gcc
|
||||
CMDS=iZ
|
||||
@ -302,82 +262,6 @@ EXPECT=<<EOF
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=ooi java class file
|
||||
FILE=malloc://1024
|
||||
CMDS=<<EOF
|
||||
e asm.cmt.calls=false
|
||||
e asm.comments=false
|
||||
e asm.cmt.flgrefs=false
|
||||
e scr.color=false
|
||||
e asm.lines.jmp=false
|
||||
e asm.xrefs=false
|
||||
wx cafebabe00000032003a070002010014546573745661726961626c6553776974636855700700040100106a6176612f6c616e672f4f626a6563740100063c696e69743e010003282956010004436f64650a000300090c0005000601000f4c696e654e756d6265725461626c650100124c6f63616c5661726961626c655461626c65010004746869730100164c546573745661726961626c6553776974636855703b010014546573744d756c7469706c655661726961626c650a001000120700110100116a6176612f6c616e672f496e74656765720c0013001401000776616c75654f660100162849294c6a6176612f6c616e672f496e74656765723b0800160100067472796f6e65090018001a0700190100106a6176612f6c616e672f53797374656d0c001b001c0100036f75740100154c6a6176612f696f2f5072696e7453747265616d3b07001e0100176a6176612f6c616e672f537472696e674275696c646572080020010011417474656d7074696e67207072696e74200a001d00220c00050023010015284c6a6176612f6c616e672f537472696e673b29560a001d00250c00260027010006617070656e6401002d284c6a6176612f6c616e672f537472696e673b294c6a6176612f6c616e672f537472696e674275696c6465723b0a001d00290c002a002b010008746f537472696e6701001428294c6a6176612f6c616e672f537472696e673b0a002d002f07002e0100136a6176612f696f2f5072696e7453747265616d0c003000230100057072696e74010001690100134c6a6176612f6c616e672f496e74656765723b01000170010001490100016b0100124c6a6176612f6c616e672f537472696e673b0100016a01000a536f7572636546696c65010019546573745661726961626c6553776974636855702e6a617661002100010003000000000002000100050006000100070000002f00010001000000052ab70008b100000002000a00000006000100000002000b0000000c000100000005000c000d00000008000e0006000100070000008100040004000000251064b8000f4b10643c12154d033eb20017bb001d59121fb700212cb60024b60028b6002cb100000002000a0000001a0006000000040006000500090006000c0007000e000800240009000b0000002a00040006001f0031003200000009001c003300340001000c0019003500360002000e001700370034000300010038000000020039
|
||||
ooi
|
||||
i
|
||||
af
|
||||
pdf
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
fd 3
|
||||
file malloc://1024
|
||||
size 0x400
|
||||
humansz 1K
|
||||
mode rwx
|
||||
format java
|
||||
iorw true
|
||||
block 0x100
|
||||
type JAVA CLASS
|
||||
arch java
|
||||
baddr 0x0
|
||||
binsz 1024
|
||||
bintype class
|
||||
bits 32
|
||||
canary false
|
||||
injprot false
|
||||
retguard false
|
||||
class 0x3200 0x0000
|
||||
crypto false
|
||||
endian little
|
||||
havecode true
|
||||
laddr 0x0
|
||||
lang java 6
|
||||
linenum true
|
||||
lsyms true
|
||||
machine jvm
|
||||
nx false
|
||||
os any
|
||||
pic false
|
||||
relocs false
|
||||
sanitize false
|
||||
static false
|
||||
stripped false
|
||||
subsys any
|
||||
va false
|
||||
;-- entry1:
|
||||
;-- sym.TestVariableSwitchUp.TestMultipleVariable:
|
||||
/ (fcn) method.TestVariableSwitchUp.TestMultipleVariable 37
|
||||
| 0x000002fd 1064 bipush 100
|
||||
| 0x000002ff b8000f invokestatic java/lang/Integer/valueOf(I)Ljava/lang/Integer;
|
||||
| 0x00000302 4b astore_0
|
||||
| 0x00000303 1064 bipush 100
|
||||
| 0x00000305 3c istore_1
|
||||
| 0x00000306 1215 ldc "tryone"
|
||||
| 0x00000308 4d astore_2
|
||||
| 0x00000309 03 iconst_0
|
||||
| 0x0000030a 3e istore_3
|
||||
| 0x0000030b b20017 getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
| 0x0000030e bb001d new java/lang/StringBuilder
|
||||
| 0x00000311 59 dup
|
||||
| 0x00000312 121f ldc "Attempting print "
|
||||
| 0x00000314 b70021 invokespecial java/lang/StringBuilder/<init>(Ljava/lang/String;)V
|
||||
| 0x00000317 2c aload_2
|
||||
| 0x00000318 b60024 invokevirtual java/lang/StringBuilder/append(Ljava/lang/String;)Ljava/lang/StringBuilder;
|
||||
| 0x0000031b b60028 invokevirtual java/lang/StringBuilder/toString()Ljava/lang/String;
|
||||
| 0x0000031e b6002c invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V
|
||||
\ 0x00000321 b1 return
|
||||
EOF
|
||||
|
||||
RUN
|
||||
|
||||
NAME=iq
|
||||
FILE=bins/elf/libmagic.so
|
||||
|
146
test/db/cmd/cmd_io
Normal file
146
test/db/cmd/cmd_io
Normal file
@ -0,0 +1,146 @@
|
||||
NAME=ooi java class file
|
||||
FILE=malloc://1024
|
||||
CMDS=<<EOF
|
||||
e asm.cmt.calls=false
|
||||
e asm.comments=false
|
||||
e asm.cmt.flgrefs=false
|
||||
e scr.color=false
|
||||
e asm.lines.jmp=false
|
||||
e asm.xrefs=false
|
||||
wx cafebabe00000032003a070002010014546573745661726961626c6553776974636855700700040100106a6176612f6c616e672f4f626a6563740100063c696e69743e010003282956010004436f64650a000300090c0005000601000f4c696e654e756d6265725461626c650100124c6f63616c5661726961626c655461626c65010004746869730100164c546573745661726961626c6553776974636855703b010014546573744d756c7469706c655661726961626c650a001000120700110100116a6176612f6c616e672f496e74656765720c0013001401000776616c75654f660100162849294c6a6176612f6c616e672f496e74656765723b0800160100067472796f6e65090018001a0700190100106a6176612f6c616e672f53797374656d0c001b001c0100036f75740100154c6a6176612f696f2f5072696e7453747265616d3b07001e0100176a6176612f6c616e672f537472696e674275696c646572080020010011417474656d7074696e67207072696e74200a001d00220c00050023010015284c6a6176612f6c616e672f537472696e673b29560a001d00250c00260027010006617070656e6401002d284c6a6176612f6c616e672f537472696e673b294c6a6176612f6c616e672f537472696e674275696c6465723b0a001d00290c002a002b010008746f537472696e6701001428294c6a6176612f6c616e672f537472696e673b0a002d002f07002e0100136a6176612f696f2f5072696e7453747265616d0c003000230100057072696e74010001690100134c6a6176612f6c616e672f496e74656765723b01000170010001490100016b0100124c6a6176612f6c616e672f537472696e673b0100016a01000a536f7572636546696c65010019546573745661726961626c6553776974636855702e6a617661002100010003000000000002000100050006000100070000002f00010001000000052ab70008b100000002000a00000006000100000002000b0000000c000100000005000c000d00000008000e0006000100070000008100040004000000251064b8000f4b10643c12154d033eb20017bb001d59121fb700212cb60024b60028b6002cb100000002000a0000001a0006000000040006000500090006000c0007000e000800240009000b0000002a00040006001f0031003200000009001c003300340001000c0019003500360002000e001700370034000300010038000000020039
|
||||
ooi
|
||||
i
|
||||
af
|
||||
pdf
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
fd 3
|
||||
file malloc://1024
|
||||
size 0x400
|
||||
humansz 1K
|
||||
mode rwx
|
||||
format java
|
||||
iorw true
|
||||
block 0x100
|
||||
type JAVA CLASS
|
||||
arch java
|
||||
baddr 0x0
|
||||
binsz 1024
|
||||
bintype class
|
||||
bits 32
|
||||
canary false
|
||||
injprot false
|
||||
retguard false
|
||||
class 0x3200 0x0000
|
||||
crypto false
|
||||
endian little
|
||||
havecode true
|
||||
laddr 0x0
|
||||
lang java 6
|
||||
linenum true
|
||||
lsyms true
|
||||
machine jvm
|
||||
nx false
|
||||
os any
|
||||
pic false
|
||||
relocs false
|
||||
sanitize false
|
||||
static false
|
||||
stripped false
|
||||
subsys any
|
||||
va false
|
||||
;-- entry1:
|
||||
;-- sym.TestVariableSwitchUp.TestMultipleVariable:
|
||||
/ (fcn) method.TestVariableSwitchUp.TestMultipleVariable 37
|
||||
| 0x000002fd 1064 bipush 100
|
||||
| 0x000002ff b8000f invokestatic java/lang/Integer/valueOf(I)Ljava/lang/Integer;
|
||||
| 0x00000302 4b astore_0
|
||||
| 0x00000303 1064 bipush 100
|
||||
| 0x00000305 3c istore_1
|
||||
| 0x00000306 1215 ldc "tryone"
|
||||
| 0x00000308 4d astore_2
|
||||
| 0x00000309 03 iconst_0
|
||||
| 0x0000030a 3e istore_3
|
||||
| 0x0000030b b20017 getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
| 0x0000030e bb001d new java/lang/StringBuilder
|
||||
| 0x00000311 59 dup
|
||||
| 0x00000312 121f ldc "Attempting print "
|
||||
| 0x00000314 b70021 invokespecial java/lang/StringBuilder/<init>(Ljava/lang/String;)V
|
||||
| 0x00000317 2c aload_2
|
||||
| 0x00000318 b60024 invokevirtual java/lang/StringBuilder/append(Ljava/lang/String;)Ljava/lang/StringBuilder;
|
||||
| 0x0000031b b60028 invokevirtual java/lang/StringBuilder/toString()Ljava/lang/String;
|
||||
| 0x0000031e b6002c invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V
|
||||
\ 0x00000321 b1 return
|
||||
EOF
|
||||
|
||||
RUN
|
||||
NAME=ooi
|
||||
FILE=bins/elf/analysis/main
|
||||
CMDS=<<EOF
|
||||
e bin.baddr=0
|
||||
e asm.cmt.calls=false
|
||||
ooi
|
||||
op 3
|
||||
e io.va=0
|
||||
s entry0
|
||||
pi 1
|
||||
?p
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
xor ebp, ebp
|
||||
0x00000410
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=ooiooi
|
||||
FILE=bins/elf/analysis/main
|
||||
CMDS=<<EOF
|
||||
?e works
|
||||
ooi;ooi
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
works
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=ooiooi2
|
||||
FILE=bins/elf/analysis/main
|
||||
CMDS=<<EOF
|
||||
ooi;ooi
|
||||
?e works
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
works
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=ioioio
|
||||
FILE=bins/mach0/ls-m1
|
||||
ARGS=-n
|
||||
CMDS=<<EOF
|
||||
o
|
||||
ob
|
||||
?e --
|
||||
io bins/mach0/hello-puts
|
||||
o
|
||||
ob
|
||||
ii
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
3 * r-x 0x0002daa0 bins/mach0/ls-m1
|
||||
--
|
||||
3 * r-x 0x0002daa0 bins/mach0/ls-m1
|
||||
5 - rw- 0x00000008 null://8
|
||||
* 0 4 x86-64 ba:0x00000000 sz:14705 bins/mach0/hello-puts
|
||||
[Imports]
|
||||
nth vaddr bind type lib name
|
||||
-------------------------------------
|
||||
1 ---------- WEAK NOTYPE _ITM_deregisterTMCloneTable
|
||||
2 0x00001050 GLOBAL FUNC puts
|
||||
3 ---------- GLOBAL FUNC __libc_start_main
|
||||
4 ---------- WEAK NOTYPE __gmon_start__
|
||||
5 ---------- WEAK NOTYPE _ITM_registerTMCloneTable
|
||||
6 ---------- WEAK FUNC __cxa_finalize
|
||||
|
||||
EOF
|
||||
RUN
|
Loading…
Reference in New Issue
Block a user