mirror of
https://github.com/radareorg/radare2.git
synced 2025-04-02 01:22:02 +00:00
Use PJ in oij
##json (#17642)
* Use PJ in `oj` * Replace `r_cons_printf()` and other minor fixes * Fix output and add a basic test for `oij` * Use `pj_kb` in writable and raised * Move `pj_new()` and `pj_a()` outside the loop * Fix \`oij\` by creating a new PJ array before the case begins, add the objects, and print and free it at the end of the function. Co-authored-by: Liumeo <liumeo@pku.edu.cn>
This commit is contained in:
parent
b81cf6665f
commit
046a1fe324
@ -1061,8 +1061,13 @@ R_API int r_core_file_list(RCore *core, int mode) {
|
||||
RListIter *it;
|
||||
RBinFile *bf;
|
||||
RListIter *iter;
|
||||
PJ *pj;
|
||||
if (mode == 'j') {
|
||||
r_cons_printf ("[");
|
||||
pj = pj_new ();
|
||||
if (!pj) {
|
||||
return 0;
|
||||
}
|
||||
pj_a (pj);
|
||||
}
|
||||
r_list_foreach (core->files, iter, f) {
|
||||
desc = r_io_desc_get (core->io, f->fd);
|
||||
@ -1072,15 +1077,17 @@ R_API int r_core_file_list(RCore *core, int mode) {
|
||||
}
|
||||
from = 0LL;
|
||||
switch (mode) {
|
||||
case 'j':
|
||||
r_cons_printf ("{\"raised\":%s,\"fd\":%d,\"uri\":\"%s\",\"from\":%"
|
||||
PFMT64d ",\"writable\":%s,\"size\":%d}%s",
|
||||
r_str_bool (core->io->desc->fd == f->fd),
|
||||
(int) f->fd, desc->uri, (ut64) from,
|
||||
r_str_bool (desc->perm & R_PERM_W),
|
||||
(int) r_io_desc_size (desc),
|
||||
iter->n? ",": "");
|
||||
case 'j': { // "oij"
|
||||
pj_o (pj);
|
||||
pj_kb (pj, "raised", core->io->desc->fd == f->fd);
|
||||
pj_ki (pj, "fd", f->fd);
|
||||
pj_ks (pj, "uri", desc->uri);
|
||||
pj_kn (pj, "from", (ut64) from);
|
||||
pj_kb (pj, "writable", desc->perm & R_PERM_W);
|
||||
pj_ki (pj, "size", (int) r_io_desc_size (desc));
|
||||
pj_end (pj);
|
||||
break;
|
||||
}
|
||||
case '*':
|
||||
case 'r':
|
||||
// TODO: use a getter
|
||||
@ -1145,7 +1152,9 @@ R_API int r_core_file_list(RCore *core, int mode) {
|
||||
count++;
|
||||
}
|
||||
if (mode == 'j') {
|
||||
r_cons_printf ("]\n");
|
||||
pj_end (pj);
|
||||
r_cons_println (pj_string (pj));
|
||||
pj_free (pj);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
@ -98,6 +98,17 @@ EXPECT=<<EOF
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=oij-pj
|
||||
FILE=<<EOF
|
||||
bins/elf/crackme0x05
|
||||
bins/elf/crackme0x00b
|
||||
EOF
|
||||
CMDS=oij
|
||||
EXPECT=<<EOF
|
||||
[{"raised":false,"fd":3,"uri":"bins/elf/crackme0x05","from":0,"writable":false,"size":7656},{"raised":true,"fd":5,"uri":"bins/elf/crackme0x00b","from":0,"writable":false,"size":7375}]
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=o -
|
||||
FILE=malloc://1024
|
||||
CMDS=<<EOF
|
||||
|
@ -23,6 +23,7 @@ izj
|
||||
izzj
|
||||
Lsj
|
||||
oj
|
||||
oij
|
||||
oLj
|
||||
omj
|
||||
p-j
|
||||
|
Loading…
x
Reference in New Issue
Block a user