-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cefdb9
commit 4dc7a41
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
from unittest import TestCase | ||
import os | ||
|
||
from cat_win.util.strings import get_strings | ||
# import sys | ||
# sys.path.append('../cat_win') | ||
|
||
|
||
test_file_dir = os.path.join(os.path.dirname(__file__), 'texts') | ||
test_file_path = os.path.join(test_file_dir, 'test.bin') | ||
with open(test_file_path, 'rb') as raw_f: | ||
test_content = [('', line) for line in raw_f.read().splitlines()] | ||
|
||
class TestFile(TestCase): | ||
def test_get_strings_default(self): | ||
# unix : "strings test.bin" | ||
c_output = """/lib64/ld-linux-x86-64.so.2 | ||
__cxa_finalize | ||
__libc_start_main | ||
puts | ||
libc.so.6 | ||
GLIBC_2.2.5 | ||
GLIBC_2.34 | ||
_ITM_deregisterTMCloneTable | ||
__gmon_start__ | ||
_ITM_registerTMCloneTable | ||
PTE1 | ||
u+UH | ||
hello world | ||
:*3$" | ||
GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 | ||
Scrt1.o | ||
__abi_tag | ||
crtstuff.c | ||
deregister_tm_clones | ||
__do_global_dtors_aux | ||
completed.0 | ||
__do_global_dtors_aux_fini_array_entry | ||
frame_dummy | ||
__frame_dummy_init_array_entry | ||
test.c | ||
__FRAME_END__ | ||
_DYNAMIC | ||
__GNU_EH_FRAME_HDR | ||
_GLOBAL_OFFSET_TABLE_ | ||
__libc_start_main@GLIBC_2.34 | ||
_ITM_deregisterTMCloneTable | ||
puts@GLIBC_2.2.5 | ||
_edata | ||
_fini | ||
__data_start | ||
__gmon_start__ | ||
__dso_handle | ||
_IO_stdin_used | ||
_end | ||
__bss_start | ||
main | ||
__TMC_END__ | ||
_ITM_registerTMCloneTable | ||
__cxa_finalize@GLIBC_2.2.5 | ||
_init | ||
.symtab | ||
.strtab | ||
.shstrtab | ||
.interp | ||
.note.gnu.property | ||
.note.gnu.build-id | ||
.note.ABI-tag | ||
.gnu.hash | ||
.dynsym | ||
.dynstr | ||
.gnu.version | ||
.gnu.version_r | ||
.rela.dyn | ||
.rela.plt | ||
.init | ||
.plt.got | ||
.plt.sec | ||
.text | ||
.fini | ||
.rodata | ||
.eh_frame_hdr | ||
.eh_frame | ||
.init_array | ||
.fini_array | ||
.dynamic | ||
.data | ||
.bss | ||
.comment""" | ||
output = get_strings(test_content, 4, '\n') | ||
self.assertEqual(c_output, '\n'.join(map(lambda x: x[1], output))) | ||
|
||
def test_get_strings_long(self): | ||
# unix : "strings test.bin -n 20" | ||
c_output = """/lib64/ld-linux-x86-64.so.2 | ||
_ITM_deregisterTMCloneTable | ||
_ITM_registerTMCloneTable | ||
GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 | ||
deregister_tm_clones | ||
__do_global_dtors_aux | ||
__do_global_dtors_aux_fini_array_entry | ||
__frame_dummy_init_array_entry | ||
_GLOBAL_OFFSET_TABLE_ | ||
__libc_start_main@GLIBC_2.34 | ||
_ITM_deregisterTMCloneTable | ||
_ITM_registerTMCloneTable | ||
__cxa_finalize@GLIBC_2.2.5""" | ||
output = get_strings(test_content, 20, '\n') | ||
self.assertEqual(c_output, '\n'.join(map(lambda x: x[1], output))) |
Binary file not shown.