Skip to content

Commit

Permalink
Improve 'pdsfq', avoid some dupes and handle fn flags ##print
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae authored Dec 19, 2024
1 parent 3165104 commit 3d85801
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
67 changes: 46 additions & 21 deletions libr/core/cmd_print.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3532,6 +3532,33 @@ static void _handle_call(RCore *core, char *line, char **str) {
}
}

static char *strpfx(char *line) {
char *str = strstr (line, " reloc.");
if (!str) {
// XXX leak
str = strstr (line, " fn.");
if (str) {
return str;
}
str = strstr (line, " obj.");
if (!str) {
str = strstr (line, " str.");
if (!str) {
str = strstr (line, " imp.");
if (!str) {
str = strstr (line, " fcn.");
if (!str) {
str = strstr (line, " hit.");
if (!str) {
str = strstr (line, " sub.");
}
}
}
}
}
}
return str;
}
// TODO: this is just a PoC, the disasm loop should be rewritten
// TODO: this is based on string matching, it should be written upon RAnalOp to know
// when we have a call and such
Expand All @@ -3547,6 +3574,7 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
bool orig_show_offset = show_offset;
int asm_tabs = r_config_get_i (core->config, "asm.tabs");
bool scr_html = r_config_get_b (core->config, "scr.html");
bool asm_bytes = r_config_get_b (core->config, "asm.bytes");
bool asm_dwarf = r_config_get_b (core->config, "asm.dwarf");
bool asm_flags = r_config_get_b (core->config, "asm.flags");
bool asm_cmt_right = r_config_get_b (core->config, "asm.cmt.right");
Expand All @@ -3558,6 +3586,7 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
r_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED);
r_config_set_b (core->config, "asm.dwarf", true);
r_config_set_i (core->config, "asm.tabs", 0);
r_config_set_b (core->config, "asm.bytes", false);
r_config_set_b (core->config, "scr.html", false);
r_config_set_b (core->config, "asm.cmt.right", true);
r_config_set_b (core->config, "asm.offset", true);
Expand Down Expand Up @@ -3604,15 +3633,20 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
r_config_set_i (core->config, "scr.color", use_color);
r_config_set_i (core->config, "asm.cmt.right", asm_cmt_right);
count = r_str_split (s, '\n');
if (!line || !*line || count < 1) {
if (R_STR_ISEMPTY (line) || count < 1) {
// R_FREE (s);
goto restore_conf;
}
ut64 addr = UT64_MAX;
ut64 oaddr = UT64_MAX;
// r_core_cmd0 (core, "afs"); // TODO include function name
for (i = 0; i < count; i++) {
addr = UT64_MAX;
char *str;
if (strstr (line, "XREF from")) {
line += strlen (line) + 1;
continue;
}
ox = strstr (line, "0x");
qo = strchr (line, '\"');
R_FREE (string);
Expand Down Expand Up @@ -3683,26 +3717,7 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
} else {
#define USE_PREFIXES 1
#if USE_PREFIXES
str = strstr (line, " reloc.");
if (!str) {
// XXX leak
str = strstr (line, " obj.");
if (!str) {
str = strstr (line, " str.");
if (!str) {
str = strstr (line, " imp.");
if (!str) {
str = strstr (line, " fcn.");
if (!str) {
str = strstr (line, " hit.");
if (!str) {
str = strstr (line, " sub.");
}
}
}
}
}
}
str = strpfx (line);
#else
if (strchr (line, ';')) {
const char *dot = r_str_rchr (line, NULL, '.');
Expand All @@ -3718,6 +3733,10 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
#endif
}
if (str) {
char *atsign = strchr (str, '@');
if (atsign) {
*atsign = 0;
}
char *qoe = strchr (str + 1, '\x1b');
if (!qoe) {
qoe = strchr (str + 1, ';');
Expand Down Expand Up @@ -3890,6 +3909,11 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
if (show_offset) {
r_cons_printf ("%s0x%08"PFMT64x" "Color_RESET, use_color? pal->offset: "", addr);
}
if (string2) {
if (!strcmp (string, string2)) {
string2 = NULL;
}
}
r_cons_printf ("%s%s%s%s%s%s%s\n",
r_str_get (linecolor),
r_str_get (string2), string2? " ": "", string,
Expand All @@ -3916,6 +3940,7 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
restore_conf:
r_config_set_b (core->config, "asm.offset", orig_show_offset);
r_config_set_b (core->config, "asm.dwarf", asm_dwarf);
r_config_set_b (core->config, "asm.bytes", asm_bytes);
r_config_set_i (core->config, "asm.tabs", asm_tabs);
r_config_set_b (core->config, "scr.html", scr_html);
r_config_set_b (core->config, "asm.emu", asm_emu);
Expand Down
1 change: 0 additions & 1 deletion test/db/formats/elf/reloc-arm64
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ EXPECT=<<EOF
0x00000ae8 arg3
0x00000aec arg1
0x00000af8 bl rsym._ZN7_JNIEnv14GetArrayLengthEP7_jarray
0x00000b00 sym.Java_com_scottyab_rootbeer_RootBeerNative_checkForRoot @ 0xb74(x)
0x00000b24 bl rsym._ZN7_JNIEnv21GetObjectArrayElementEP13_jobjectArrayi
0x00000b3c bl rsym._ZN7_JNIEnv17GetStringUTFCharsEP8_jstringPh
0x00000b48 bl rsym._Z6existsPKc
Expand Down

0 comments on commit 3d85801

Please sign in to comment.