Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search: Print dot in results for nonprintable chars #4880

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion librz/core/cmd/cmd_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ static char *getstring(char *b, int l) {
for (i = 0, r = res; i < l; b++, i++) {
if (IS_PRINTABLE(*b)) {
*r++ = *b;
} else {
// This is very ASCII-centric
*r++ = '.';
}
}
*r = 0;
Expand Down Expand Up @@ -456,7 +459,7 @@ static int _cb_hit(RzSearchKeyword *kw, void *user, ut64 addr) {
s = rz_str_newf("%s%s%s", pre, wrd, pos);
} else {
wrd = rz_str_utf16_encode(buf + prectx, len);
s = rz_str_newf(use_color ? ".%s" Color_YELLOW "%s" Color_RESET "%s."
s = rz_str_newf(use_color ? "\"%s" Color_YELLOW "%s" Color_RESET "%s\""
: "\"%s%s%s\"",
pre, wrd, pos);
}
Expand Down
6 changes: 3 additions & 3 deletions test/db/cmd/basic
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ b 777
EOF
EXPECT=<<EOF

0x00000000 hit0_0 "test"
0x0000014d hit0_1 "test"
0x0000029a hit0_2 "test"
0x00000000 hit0_0 "test................"
0x0000014d hit0_1 "................test................"
0x0000029a hit0_2 "................test................"
EOF
RUN

Expand Down
2 changes: 1 addition & 1 deletion test/db/cmd/cmd_json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ EXPECT=<<EOF
{
"offset": 4203952,
"type": "string",
"data": "cation1\\Release\\ConsoleApplication1.pdb "
"data": "cation1\\Release\\ConsoleApplication1.pdb..... ... ......"
}
]
EOF
Expand Down
10 changes: 5 additions & 5 deletions test/db/cmd/cmd_search
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ NAME=/j escaped
FILE=bins/mach0/escaped
CMDS=/j hello
EXPECT=<<EOF
[{"offset":8019,"type":"string","data":"]c:\\hello\\worldM"}]
[{"offset":8019,"type":"string","data":"....]........c:\\hello\\world..M......."}]
EOF
RUN

Expand All @@ -141,7 +141,7 @@ e search.to=0x00000050
/ ELF
EOF
EXPECT=<<EOF
0x00000001 hit0_0 "ELF"
0x00000001 hit0_0 ".ELF................"
EOF
RUN

Expand All @@ -157,7 +157,7 @@ e search.to=0x50
/ ELF
EOF
EXPECT=<<EOF
0x00000001 hit0_0 "ELF"
0x00000001 hit0_0 ".ELF................"
EOF
RUN

Expand All @@ -168,7 +168,7 @@ wx 666f6f005c
/j foo
EOF
EXPECT=<<EOF
[{"offset":0,"type":"string","data":"foo\\"}]
[{"offset":0,"type":"string","data":"foo.\\.............."}]
EOF
RUN

Expand All @@ -179,7 +179,7 @@ wx 666f6f00
/! ff
EOF
EXPECT=<<EOF
0x00000000 hit0_0 "foo"
0x00000000 hit0_0 "foo..............."
EOF
RUN

Expand Down
14 changes: 7 additions & 7 deletions test/db/cmd/cmd_search_hit
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ps @@/j hello
EOF
EXPECT=<<EOF
hello
[{"offset":10,"type":"string","data":"hello"}]
[{"offset":10,"type":"string","data":"..........hello................"}]
EOF
RUN

Expand All @@ -42,7 +42,7 @@ wx 0067
/j g
EOF
EXPECT=<<EOF
[{"offset":1,"type":"string","data":"g"}]
[{"offset":1,"type":"string","data":".g................"}]
EOF
RUN

Expand All @@ -69,7 +69,7 @@ wx 33 @@/ A
p8 1 @ 10
EOF
EXPECT=<<EOF
0x0000000a hit0_0 "A"
0x0000000a hit0_0 "..........A................"
33
EOF
RUN
Expand Down Expand Up @@ -110,7 +110,7 @@ w AAAAAAAAAAB
/! A
EOF
EXPECT=<<EOF
0x0000000a hit0_0 "AAAAAAAAAAB"
0x0000000a hit0_0 "AAAAAAAAAAB................"
42
EOF
RUN
Expand All @@ -137,9 +137,9 @@ w AAAAAAAAAAB
//
EOF
EXPECT=<<EOF
0x0000000a hit0_0 "AAAAAAAAAAB"
0x0000000a hit0_0 "AAAAAAAAAAB................"
42
0x0000000a hit1_0 "AAAAAAAAAAB"
0x0000000a hit1_0 "AAAAAAAAAAB................"
42
EOF
RUN
Expand Down Expand Up @@ -273,7 +273,7 @@ w AAAAAAAAAAB
/i aaaaaaaaaab
EOF
EXPECT=<<EOF
0x00000000 hit0_0 "AAAAAAAAAAB"
0x00000000 hit0_0 "AAAAAAAAAAB................"
AAAAAAAAAAB
EOF
RUN
Expand Down
58 changes: 29 additions & 29 deletions test/db/cmd/regexp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ b 777
EOF
EXPECT=<<EOF

0x00000000 hit0_0 "test"
0x000001bc hit0_1 "Test"
0x00000000 hit0_0 "test................"
0x000001bc hit0_1 "................Test................"
EOF
RUN

Expand Down Expand Up @@ -40,8 +40,8 @@ b 777
EOF
EXPECT=<<EOF

0x00000001 hit0_0 ""test123 ab""
0x000001bd hit0_1 ""Test123 ab""
0x00000001 hit0_0 ""test123 ab"..............."
0x000001bd hit0_1 "..............."Test123 ab"..............."
EOF
RUN

Expand All @@ -64,16 +64,16 @@ echo -- 5 --
EOF
EXPECT=<<EOF
-- 1 --
0x00000001 hit0_0 .abcdbccc.
0x00000010 hit0_1 .abcdbcccde.
0x00000001 hit0_0 "abcd............bccc"
0x00000010 hit0_1 "abcd............bcccde..............."
-- 2 --
-- 3 --
0x00000001 hit2_0 .abcdbccc.
0x00000010 hit2_1 .abcdbcccde.
0x00000001 hit2_0 "abcd............bccc"
0x00000010 hit2_1 "abcd............bcccde..............."
-- 4 --
0x00000001 hit3_0 .abcdbccc.
0x00000001 hit3_0 "abcd............bccc"
-- 5 --
0x00000010 hit4_0 .abcdbcccde.
0x00000010 hit4_0 "abcd............bcccde..............."
EOF
EXPECT_ERR=<<EOF
Searching in [0x0,0x200)
Expand Down Expand Up @@ -101,10 +101,10 @@ echo ----
/e /b.*d$/
EOF
EXPECT=<<EOF
0x000000fe hit0_0 .bcccde.
0x000001fe hit0_1 .bd.
0x000000fe hit0_0 "................bcccde..............."
0x000001fe hit0_1 "................bd................"
----
0x000001fe hit1_0 .bd.
0x000001fe hit1_0 "................bd................"
EOF
EXPECT_ERR=<<EOF
Searching in [0x0,0x200)
Expand All @@ -123,23 +123,23 @@ echo ----
/e /lib/
EOF
EXPECT=<<EOF
0x00400239 hit0_0 ./lib64/ld-linux-x86-.
0x00400f19 hit0_1 .alibselinux.so.1_IT.
0x00400fae hit0_2 .etfilecon_finilibacl.so.1acl_get.
0x00400feb hit0_3 .l_extended_filelibc.so.6fflushst.
0x004013c3 hit0_4 .cmptcgetpgrp__libc_start_maindir.
0x0041769a hit0_5 .system call./.libs/lt-.
0x004186e0 hit0_6 .emory exhaustedlib/xstrtol.c0 <.
0x00418e58 hit0_7 .xstrtoumax/usr/libASCIICHARSETAL.
0x00400239 hit0_0 ".............../lib64/ld-linux-x86-"
0x00400f19 hit0_1 ".a..............libselinux.so.1._IT"
0x00400fae hit0_2 "etfilecon._fini.libacl.so.1.acl_get"
0x00400feb hit0_3 "l_extended_file.libc.so.6.fflush.st"
0x004013c3 hit0_4 "cmp.tcgetpgrp.__libc_start_main.dir"
0x0041769a hit0_5 "system call.../.libs/.lt-.........."
0x004186e0 hit0_6 "emory exhausted.lib/xstrtol.c...0 <"
0x00418e58 hit0_7 "xstrtoumax./usr/lib.ASCII.CHARSETAL"
----
0x00400239 hit1_0 ./lib64/ld-linux-x86-.
0x00400f19 hit1_1 .alibselinux.so.1_IT.
0x00400fae hit1_2 .etfilecon_finilibacl.so.1acl_get.
0x00400feb hit1_3 .l_extended_filelibc.so.6fflushst.
0x004013c3 hit1_4 .cmptcgetpgrp__libc_start_maindir.
0x0041769a hit1_5 .system call./.libs/lt-.
0x004186e0 hit1_6 .emory exhaustedlib/xstrtol.c0 <.
0x00418e58 hit1_7 .xstrtoumax/usr/libASCIICHARSETAL.
0x00400239 hit1_0 ".............../lib64/ld-linux-x86-"
0x00400f19 hit1_1 ".a..............libselinux.so.1._IT"
0x00400fae hit1_2 "etfilecon._fini.libacl.so.1.acl_get"
0x00400feb hit1_3 "l_extended_file.libc.so.6.fflush.st"
0x004013c3 hit1_4 "cmp.tcgetpgrp.__libc_start_main.dir"
0x0041769a hit1_5 "system call.../.libs/.lt-.........."
0x004186e0 hit1_6 "emory exhausted.lib/xstrtol.c...0 <"
0x00418e58 hit1_7 "xstrtoumax./usr/lib.ASCII.CHARSETAL"
EOF
EXPECT_ERR=<<EOF
Searching 3 bytes in [0x61d368,0x61d720)
Expand Down
Loading