在 Linux 下使用 strings 命令出现“乱码”,通常不是 strings 本身坏了,而是数据本身或查看方式导致的。常见原因和解决办法如下:
strings 只能提取可打印字符,如果文件是:
就会看起来像乱码。
✅ 解决:
file 文件名
看看真实编码。
如果是 UTF-16:
strings -e l 文件名 # little-endian UTF-16
strings -e b 文件名 # big-endian
你的终端是 UTF-8,但文件是 GBK / GB2312。
✅ 解决:
locale
如果不是 UTF-8:
export LANG=zh_CN.UTF-8
或临时转换:
strings file | iconv -f gbk -t utf-8
strings 会从二进制里抽字符,比如:
\xe4\xb8\xad\xe6\x96\x87
这其实是 UTF-8 中文,但被当成字节看。
✅ 解决:
strings -n 6 file
提高最小字符串长度,减少噪音。
例如:
.gz.zip✅ 解决:
file file
先解压或脱壳。
有些 strings 输出像:
0000000 �%@
这是正常二进制残留。
✅ 解决:
strings -n 8 file
file 文件
locale
strings -n 6 文件
strings -e l 文件
你可以把:
file 文件名 的输出发给我,我可以直接告诉你为什么乱、怎么读。