Skip to content

Commit 6b3d53c

Browse files
radaretrufae
authored andcommitted
Implement iesj to list symbol entrypoints in json format
1 parent b53672b commit 6b3d53c

File tree

1 file changed

+46
-14
lines changed

1 file changed

+46
-14
lines changed

libr/core/cmd_info.inc.c

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ static RCoreHelpMessage help_msg_iic = {
9393

9494
static RCoreHelpMessage help_msg_ie = {
9595
"Usage: ie", "[qj=]", "Show entrypoints and constructors",
96-
"ie", "", "show entrypointsie=entrypoint",
97-
"iee", "", "list constructors and destructors",
98-
"ies", "", "list entrypoint symbols (see 'ise')",
96+
"ie", "[j]", "show entrypointsie=entrypoint",
97+
"iee", "[j]", "list constructors and destructors",
98+
"ies", "[j]", "list entrypoint symbols (see 'ise')",
9999
NULL
100100
};
101101

@@ -1920,7 +1920,14 @@ static void cmd_ies(RCore *core, const char *input, PJ *pj, int mode, int va) {
19201920
R_VEC_FOREACH (symbols, sym) {
19211921
const char *name = r_bin_name_tostring2 (sym->name, 'o');
19221922
if (is_entrypoint_symbol (name)) {
1923-
r_kons_printf (core->cons, "0x%08"PFMT64x" %s\n", sym->vaddr, name);
1923+
if (pj) {
1924+
pj_o (pj);
1925+
pj_kn (pj, "addr", sym->vaddr);
1926+
pj_ks (pj, "name", name);
1927+
pj_end (pj);
1928+
} else {
1929+
r_kons_printf (core->cons, "0x%08"PFMT64x" %s\n", sym->vaddr, name);
1930+
}
19241931
}
19251932
}
19261933
}
@@ -1941,19 +1948,42 @@ static void cmd_ies(RCore *core, const char *input, PJ *pj, int mode, int va) {
19411948
const char *name = r_bin_name_tostring2 (method->name, 'o');
19421949
if (is_entrypoint_symbol (name)) {
19431950
const char *kname = r_bin_name_tostring2 (klass->name, 'o');
1944-
r_kons_printf (core->cons, "0x%08"PFMT64x" %s.%s\n",
1945-
method->vaddr, kname, name);
1951+
if (pj) {
1952+
pj_o (pj);
1953+
pj_kn (pj, "addr", method->vaddr);
1954+
char *fname = r_str_newf ("%s.%s", kname, name);
1955+
pj_ks (pj, "name", fname);
1956+
free (fname);
1957+
pj_end (pj);
1958+
} else {
1959+
r_kons_printf (core->cons, "0x%08"PFMT64x" %s.%s\n",
1960+
method->vaddr, kname, name);
1961+
}
19461962
}
19471963
}
19481964
}
19491965
}
19501966
RFlagItem *fi = r_flag_get (core->flags, "main");
19511967
if (fi) {
1952-
r_kons_printf (core->cons, "0x%08"PFMT64x" main\n", fi->addr);
1968+
if (pj) {
1969+
pj_o (pj);
1970+
pj_kn (pj, "addr", fi->addr);
1971+
pj_ks (pj, "name", "main");
1972+
pj_end (pj);
1973+
} else {
1974+
r_kons_printf (core->cons, "0x%08"PFMT64x" main\n", fi->addr);
1975+
}
19531976
}
19541977
fi = r_flag_get (core->flags, "entry0");
19551978
if (fi) {
1956-
r_kons_printf (core->cons, "0x%08"PFMT64x" entry0\n", fi->addr);
1979+
if (pj) {
1980+
pj_o (pj);
1981+
pj_kn (pj, "addr", fi->addr);
1982+
pj_ks (pj, "name", "entry0");
1983+
pj_end (pj);
1984+
} else {
1985+
r_kons_printf (core->cons, "0x%08"PFMT64x" entry0\n", fi->addr);
1986+
}
19571987
}
19581988
}
19591989

@@ -2075,22 +2105,24 @@ static int cmd_info(void *data, const char *input) {
20752105
if (mode == R_MODE_JSON) {
20762106
INIT_PJ ();
20772107
int suffix_shift = 0;
2078-
if (r_str_startswith (input, "SS") || r_str_startswith (input, "ee") || r_str_startswith (input, "zz")) {
2108+
if (r_str_startswith (input, "SS") || r_str_startswith (input, "es") || r_str_startswith (input, "zz")) {
2109+
// very ugly
20792110
suffix_shift = 1;
20802111
}
20812112
if (strlen (input + 1 + suffix_shift) > 1) {
20822113
is_array = true;
2083-
}
2084-
if (r_str_startswith (input, "zzz")) {
2114+
} else if (r_str_startswith (input, "esj")) {
2115+
is_array = true;
2116+
} else if (r_str_startswith (input, "zzz")) {
20852117
is_izzzj = true;
2086-
}
2087-
if (r_str_startswith (input, "dpi")) {
2118+
} else if (r_str_startswith (input, "dpi")) {
20882119
is_idpij = true;
20892120
}
20902121
}
20912122
r_core_return_value (core, 0);
20922123
if (is_array && !is_izzzj && !is_idpij) {
2093-
pj_o (pj);
2124+
pj_a (pj);
2125+
// pj_o (pj);
20942126
}
20952127
if (!*input) {
20962128
cmd_info_bin (core, va, pj, mode);

0 commit comments

Comments
 (0)