在Shell腳本中使用strings
命令可以幫助你從二進制文件中提取可打印的字符串
以下是如何在Shell腳本中使用strings
命令的示例:
extract_strings.sh
的Shell腳本文件:#!/bin/bash
# 檢查參數數量
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <binary_file>"
exit 1
fi
# 獲取二進制文件名
binary_file="$1"
# 使用strings命令提取可打印字符串
strings "$binary_file"
chmod +x extract_strings.sh
strings
命令提取二進制文件中的字符串:./extract_strings.sh /path/to/binary_file
這將輸出二進制文件中的所有可打印字符串。
你還可以使用strings
命令的其他選項來自定義輸出。例如,你可以使用-n
選項指定最小字符串長度,只顯示長度大于或等于指定值的字符串:
strings -n 6 /path/to/binary_file
有關strings
命令的更多信息,請參閱其手冊頁(通過運行man strings
)。