需先安裝binutils
包(含strings
命令):
sudo apt update
sudo apt install binutils
驗證安裝:strings --version
。
從二進制文件提取可打印字符串:
strings <文件路徑>
示例:strings example.bin
。
選項 | 功能 | 示例 |
---|---|---|
-n <長度> |
設置最小字符串長度(默認4) | strings -n 6 file (僅顯示≥6字符的字符串) |
-t <格式> |
指定偏移量格式(x =十六進制,d =十進制) |
strings -t x file (以十六進制顯示偏移量) |
-e <編碼> |
指定字符編碼(ascii /utf8 /ibm ) |
strings -e utf8 file (提取UTF-8字符串) |
-a |
掃描整個文件(默認僅掃描數據段) | strings -a file |
-f |
顯示文件名(處理多個文件時) | strings -f file1 file2 |
strings file > output.txt
grep
過濾:
strings file | grep "keyword"
strings file | grep -i "password\|secret"
find /path/to/dir -type f -exec strings {} \;
grep
或less
過濾。-a
選項掃描全文件,避免遺漏非數據段字符串。-e
可減少亂碼。man strings
。