Handle multiline comments in pdsf ##print

This commit is contained in:
pancake 2024-09-01 18:12:11 +02:00 committed by GitHub
parent 1d6e1a66e1
commit f415c27c1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 95 additions and 36 deletions

View File

@ -3264,7 +3264,7 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
r_config_set_i (core->config, "asm.cmt.right", asm_cmt_right);
goto restore_conf;
}
} else if (!strncmp (input, "ds ", 3)) {
} else if (r_str_startswith (input, "ds ")) {
line = s = r_core_cmd_strf (core, "pD %s", input + 3);
} else {
line = s = r_core_cmd_str (core, "pd");
@ -3279,14 +3279,17 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
// R_FREE (s);
goto restore_conf;
}
ut64 addr = UT64_MAX;
ut64 oaddr = UT64_MAX;
for (i = 0; i < count; i++) {
ut64 addr = UT64_MAX;
addr = UT64_MAX;
char *str;
ox = strstr (line, "0x");
qo = strchr (line, '\"');
R_FREE (string);
if (ox) {
if (ox && ox < line + 20) {
addr = r_num_get (NULL, ox);
oaddr = addr;
}
if (qo) {
char *qoe = strrchr (qo + 1, '"');
@ -3345,50 +3348,50 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
}
}
}
// eprintf ("--> (%s)\n", line);
if (pdsfs) {
str = strstr (line, " str.");
} else {
#define USE_PREFIXES 1
#if USE_PREFIXES
// XXX leak
str = strstr (line, " obj.");
if (!str) {
str = strstr (line, " str.");
// XXX leak
str = strstr (line, " obj.");
if (!str) {
str = strstr (line, " imp.");
str = strstr (line, " str.");
if (!str) {
str = strstr (line, " fcn.");
str = strstr (line, " imp.");
if (!str) {
str = strstr (line, " sub.");
str = strstr (line, " fcn.");
if (!str) {
str = strstr (line, " hit.");
if (!str) {
str = strstr (line, " sub.");
}
}
}
}
}
}
#else
if (strchr (line, ';')) {
const char *dot = r_str_rchr (line, NULL, '.');
if (dot) {
const char *o = r_str_rchr (line, dot, ' ');
if (o) {
str = (char*)o;
} else {
R_LOG_WARN ("missing summary reference: %s", dot);
if (strchr (line, ';')) {
const char *dot = r_str_rchr (line, NULL, '.');
if (dot) {
const char *o = r_str_rchr (line, dot, ' ');
if (o) {
str = (char*)o;
} else {
R_LOG_WARN ("missing summary reference: %s", dot);
}
}
}
}
#endif
}
if (str) {
char *qoe = NULL;
if (!qoe) {
qoe = strchr (str + 1, '\x1b');
}
char *qoe = strchr (str + 1, '\x1b');
if (!qoe) {
qoe = strchr (str + 1, ';');
}
if (!qoe) {
qoe = strchr (str + 1, ' ');
if (!qoe) {
qoe = strchr (str + 1, ' ');
}
}
if (qoe) {
free (string2);
@ -3434,6 +3437,10 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
if (strstr (line, "XREF")) {
addr = UT64_MAX;
}
if (addr == UT64_MAX) {
addr = oaddr;
oaddr = UT64_MAX;
}
if (addr != UT64_MAX) {
const char *str = NULL;
if (show_comments && !pdsfs) {
@ -3497,10 +3504,10 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
}
}
if (R_STR_ISNOTEMPTY (string)) {
if (string && !strncmp (string, "0x", 2)) {
if (string && r_str_startswith (string, "0x")) {
str = string;
}
if (string2 && !strncmp (string2, "0x", 2)) {
if (string2 && r_str_startswith (string2, "0x")) {
str = string2;
}
ut64 ptr = r_num_math (NULL, str);
@ -3509,10 +3516,10 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
flag = r_core_flag_get_by_spaces (core->flags, ptr);
}
if (!flag) {
if (string && !strncmp (string, "0x", 2)) {
if (string && r_str_startswith (string, "0x")) {
R_FREE (string);
}
if (string2 && !strncmp (string2, "0x", 2)) {
if (string2 && r_str_startswith (string2, "0x")) {
R_FREE (string2);
}
}

23
test/db/anal/arm64-crypto Normal file
View File

@ -0,0 +1,23 @@
NAME=jump table for swift on arm64
FILE=bins/mach0/MASTestApp-2
CMDS=<<EOF
f hit.key.base 1 0x1000100a8
f hit.key.bytes 1 0x1000100c8
f hit.key.lastQword 1 0x1000100e0
f sym.generatePrivateKey 720 0x1000086dc
f sym.calledFromGeneratePrivKey 64 0x100008ab8
e emu.str=true
e asm.var.summary=true
Cd 4[16] @ hit.key.base
CCu base64:WzI0XSAtcnctIHNlY3Rpb24gc2l6ZSAyNzIgbmFtZWQgMjQuX19EQVRBLl9fYnNz @ 0x100010300
s 0x100008710
af
pdsf~key
EOF
EXPECT=<<EOF
0x10000871c hit.key.lastQword
0x100008758 hit.key.base
0x10000888c "Failed to create private key."
0x1000088c8 "Failed to create private key."
EOF
RUN

View File

@ -627,13 +627,14 @@ EXPECT=<<EOF
0x100001085 call newname
0x100001093 call sym.imp.setlocale
0x1000010a3 call sym.imp.isatty
0x1000054e0 [10] -rw- section size 40 named 10.__DATA.__data
0x1000010b6 str.COLUMNS
0x1000010bd call sym.imp.getenv
0x1000010bd "COLUMNS"
0x1000010cf call sym.imp.atoi
0x1000010e6 call sym.imp.ioctl
0x10000110d str.COLUMNS
0x100001114 call sym.imp.getenv
0x100001114 "COLUMNS"
0x100001121 call sym.imp.atoi
0x10000112c call sym.imp.getuid
EOF

View File

@ -133,55 +133,74 @@ EXPECT=<<EOF
0x100001085 call sym.func.100004401
0x100001093 call sym.imp.setlocale
0x1000010a3 call sym.imp.isatty
0x1000054e0 [10] -rw- section size 40 named 10.__DATA.__data
0x1000010b6 str.COLUMNS
0x1000010bd call sym.imp.getenv
0x1000010bd "COLUMNS"
0x1000010cf call sym.imp.atoi
0x1000010e6 call sym.imp.ioctl
0x10000110d str.COLUMNS
0x100001114 call sym.imp.getenv
0x100001114 "COLUMNS"
0x100001121 call sym.imp.atoi
0x10000112c call sym.imp.getuid
0x1000011b5 switch table (72 cases) at 0x10000192c
;-- default: ; from 0x1000011b5
0x10000116e call sym.func.100004401
0x100001179 str.1_ABCFGHLOPRSTUWabcdefghiklmnopqrstuvwx
0x100001186 call sym.imp.getopt
0x100001186 "1@ABCFGHLOPRSTUWabcdefghik"
;-- switch:
0x1000011b5 switch table (72 cases) at 0x10000192c
0x100001233 str.CLICOLOR
0x100001246 call sym.imp.setenv
0x100001246 "CLICOLOR", ""
0x100001253 str.bin_ls
0x10000125a str.Unix2003
0x100001261 call sym.imp.compat_mode
0x100001261 "bin/ls", "Unix2003"
0x10000128c str.bin_ls
0x100001293 str.Unix2003
0x10000129a call sym.imp.compat_mode
0x10000129a "bin/ls", "Unix2003"
0x1000013a2 str.bin_ls
0x1000013a9 str.Unix2003
0x1000013b0 call sym.imp.compat_mode
0x1000013b0 "bin/ls", "Unix2003"
0x1000013d3 str.bin_ls
0x1000013da str.Unix2003
0x1000013e1 call sym.imp.compat_mode
0x1000013e1 "bin/ls", "Unix2003"
0x10000143a str.bin_ls
0x100001441 str.Unix2003
0x100001448 call sym.imp.compat_mode
0x100001448 "bin/ls", "Unix2003"
0x10000145a str.bin_ls
0x100001461 str.Unix2003
0x100001468 call sym.imp.compat_mode
0x100001468 "bin/ls", "Unix2003"
0x1000015b4 str.CLICOLOR
0x1000015bb call sym.imp.getenv
0x1000015bb "CLICOLOR"
0x1000015ce call sym.imp.isatty
0x1000015d7 str.CLICOLOR_FORCE
0x1000015de call sym.imp.getenv
0x1000015de "CLICOLOR_FORCE"
0x1000015ec str.TERM
0x1000015f3 call sym.imp.getenv
0x1000015f3 "TERM"
0x100001602 call sym.imp.tgetent
0x100001602 "", ""
0x100001621 call sym.imp.tgetstr
0x100001621 "AF", ""
0x100001637 call sym.imp.tgetstr
0x100001637 "AB", ""
0x10000164d call sym.imp.tgetstr
0x10000164d "me", ""
0x100001663 call sym.imp.tgetstr
0x100001663 "md", ""
0x100001679 call sym.imp.tgetstr
0x100001679 "op", ""
0x100001698 call sym.imp.tgetstr
0x100001698 "oc", ""
0x1000016e1 sym.func.100003b48
0x1000016ed sym.func.100003b48
0x1000016f0 call sym.imp.signal
@ -189,6 +208,7 @@ EXPECT=<<EOF
0x1000016fd call sym.imp.signal
0x100001702 str.LSCOLORS
0x100001709 call sym.imp.getenv
0x100001709 "LSCOLORS"
0x100001711 call sym.func.1000039b6
0x1000017a2 call sym.imp.getbsize
0x1000017e6 sym.func.100000f58

View File

@ -27,7 +27,7 @@ af
pdsf
EOF
EXPECT=<<EOF
0x00002900&nbsp;argc<br />0x00002904&nbsp;argv<br />0x00002918&nbsp;"alloc"<br />0x00002920&nbsp;str.alloc<br />0x00002928&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002934&nbsp;"init"<br />0x0000293c&nbsp;str.init<br />0x00002940&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x0000294c&nbsp;"X\x10\x9d\xe5"<br />0x0000295c&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002970&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002998&nbsp;"Usage:&nbsp;FileDP&nbsp;[-f/-d]&nbsp;[Full&nbsp;path&nbsp;to&nbsp;file/directory]&nbsp;"<br />0x0000299c&nbsp;bl&nbsp;sym.imp.puts<br />0x000029c8&nbsp;bl&nbsp;sym.imp.strcmp<br />0x00002a1c&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002a38&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002a64&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002a90&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002aa4&nbsp;bl&nbsp;sym.imp.NSLog<br />0x00002ab0&nbsp;str.File_Not_Found<br />0x00002ab4&nbsp;bl&nbsp;sym.imp.puts<br />0x00002b00&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002b1c&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002b48&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002b64&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002ba4&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002c00&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002c54&nbsp;bl&nbsp;sym.imp.objc_enumerationMutation<br />0x00002ca0&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002cc0&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002cec&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002cfc&nbsp;str.cstr.file_name_is:_____protection_class:__<br />0x00002d04&nbsp;bl&nbsp;sym.imp.NSLog<br />0x00002d50&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002d84&nbsp;str.Directory_Not_found<br />0x00002d88&nbsp;bl&nbsp;sym.imp.puts<br />0x00002dac&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002dcc&nbsp;bx&nbsp;lr
0x00002900&nbsp;argc<br />0x00002904&nbsp;argv<br />0x00002918&nbsp;"alloc"<br />0x00002920&nbsp;str.alloc<br />0x00002928&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002928&nbsp;"alloc"<br />0x00002934&nbsp;"init"<br />0x0000293c&nbsp;str.init<br />0x00002940&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002940&nbsp;"init"<br />0x0000294c&nbsp;"X\x10\x9d\xe5"<br />0x0000295c&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002970&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002998&nbsp;"Usage:&nbsp;FileDP&nbsp;[-f/-d]&nbsp;[Full&nbsp;path&nbsp;to&nbsp;file/directory]&nbsp;"<br />0x0000299c&nbsp;bl&nbsp;sym.imp.puts<br />0x0000299c&nbsp;"Usage:&nbsp;FileDP&nbsp;[-f/-d]&nbsp;[Full&nbsp;path&nbsp;to&nbsp;"<br />0x000029c8&nbsp;bl&nbsp;sym.imp.strcmp<br />0x00002a1c&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002a38&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002a64&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002a90&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002aa4&nbsp;bl&nbsp;sym.imp.NSLog<br />0x00002ab0&nbsp;str.File_Not_Found<br />0x00002ab4&nbsp;bl&nbsp;sym.imp.puts<br />0x00002ab4&nbsp;"File&nbsp;Not&nbsp;Found&nbsp;"<br />0x00002b00&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002b1c&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002b48&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002b64&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002ba4&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002c00&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002c54&nbsp;bl&nbsp;sym.imp.objc_enumerationMutation<br />0x00002ca0&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002cc0&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002cec&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002cfc&nbsp;str.cstr.file_name_is:_____protection_class:__<br />0x00002d04&nbsp;bl&nbsp;sym.imp.NSLog<br />0x00002d50&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002d84&nbsp;str.Directory_Not_found<br />0x00002d88&nbsp;bl&nbsp;sym.imp.puts<br />0x00002d88&nbsp;"Directory&nbsp;Not&nbsp;fo"<br />0x00002dac&nbsp;bl&nbsp;sym.imp.objc_msgSend<br />0x00002dcc&nbsp;bx&nbsp;lr
EOF
RUN
@ -46,14 +46,17 @@ EXPECT=<<EOF
0x00002918 "alloc"
0x00002920 str.alloc
0x00002928 bl sym.imp.objc_msgSend
0x00002928 "alloc"
0x00002934 "init"
0x0000293c str.init
0x00002940 bl sym.imp.objc_msgSend
0x00002940 "init"
0x0000294c "X\x10\x9d\xe5"
0x0000295c bl sym.imp.objc_msgSend
0x00002970 bl sym.imp.objc_msgSend
0x00002998 "Usage: FileDP [-f/-d] [Full path to file/directory] "
0x0000299c bl sym.imp.puts
0x0000299c "Usage: FileDP [-f/-d] [Full path to "
0x000029c8 bl sym.imp.strcmp
0x00002a1c bl sym.imp.objc_msgSend
0x00002a38 bl sym.imp.objc_msgSend
@ -62,6 +65,7 @@ EXPECT=<<EOF
0x00002aa4 bl sym.imp.NSLog
0x00002ab0 str.File_Not_Found
0x00002ab4 bl sym.imp.puts
0x00002ab4 "File Not Found "
0x00002b00 bl sym.imp.objc_msgSend
0x00002b1c bl sym.imp.objc_msgSend
0x00002b48 bl sym.imp.objc_msgSend
@ -77,6 +81,7 @@ EXPECT=<<EOF
0x00002d50 bl sym.imp.objc_msgSend
0x00002d84 str.Directory_Not_found
0x00002d88 bl sym.imp.puts
0x00002d88 "Directory Not fo"
0x00002dac bl sym.imp.objc_msgSend
0x00002dcc bx lr
EOF

View File

@ -48,6 +48,7 @@ vaddr paddr type ntype name
4 relocations
0x100004a0 str.Simple_PPC_program. str.Simple_PPC_program.
0x100004a4 "Simple PPC program."
EOF
RUN

View File

@ -15,6 +15,7 @@ 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
@ -23,6 +24,7 @@ EXPECT=<<EOF
0x00000b98 _JNIEnv::GetArrayLength(_jarray*)
;-- _JNIEnv::GetObjectArrayElement(_jobjectArray*, int):
0x00000bd0 _JNIEnv::GetObjectArrayElement(_jobjectArray*, int)
0x00000bd0 _JNIEnv::GetObjectArrayElement(_jobjectArray*, int)
imports
[Imports]
nth vaddr bind type lib name