strings
命令本身不提供直接的自定義輸出格式選項,它主要用于從二進制文件中提取可打印的字符串。然而,你可以使用其他工具或腳本來處理 strings
命令的輸出,以實現自定義輸出格式。
以下是一些方法:
awk
、sed
或 grep
等文本處理工具對 strings
命令的輸出進行過濾和格式化。例如,如果你只想顯示包含特定關鍵字的字符串,可以這樣做:strings binary_file | grep "keyword"
將 strings
命令的輸出重定向到文件,然后使用文本編輯器或腳本對其進行編輯。
編寫一個簡單的腳本來處理 strings
命令的輸出。例如,以下是一個使用 Python 編寫的腳本,它讀取 strings
命令的輸出并將其格式化為每行一個字符串的形式:
#!/usr/bin/env python3
import subprocess
binary_file = "your_binary_file_here"
output = subprocess.check_output(["strings", binary_file])
for line in output.decode().splitlines():
print(line)
將此腳本保存為 custom_strings.py
,并使用 chmod +x custom_strings.py
使其可執行。然后運行腳本:./custom_strings.py
。
這些方法可以幫助你根據需要自定義 strings
命令的輸出格式。