利用 Debian Strings 进行软件测试
一 工具与概念澄清
二 安装与快速验证
sudo apt-get update && sudo apt-get install binutilsgcc -o test test.c
strings -n 6 test
三 典型测试场景与命令示例
strings -n 6 app | grep -E 'Version|Build|ERROR|CRITICAL'
strings -n 4 app | grep -i 'français\|fr_FR'
strings -n 4 app | grep -E '/home|/tmp|/usr/local|debug'
strings -n 8 app | grep -Ei 'secret|password|token|api_key|@example\.com'
strings -n 6 -t x app | head
time strings -n 6 large_binary > /dev/null
strings -n 4 -e UTF-8 app
四 自动化测试与 CI 集成
#!/usr/bin/env bash
set -euo pipefail
BIN="$1"
MINLEN="${2:-6}"
die() { echo "$*" >&2; exit 1; }
[[ -f "$BIN" ]] || die "Binary not found: $BIN"
count() { strings -n "$MINLEN" "$BIN" | grep -c "$1"; }
# 必须包含
for s in "Version:" "Build:"; do
[[ $(count "$s") -gt 0 ]] || die "Missing string: $s"
done
# 必须不包含
for s in "SECRET_KEY" "password="; do
[[ $(count "$s") -eq 0 ]] || die "Forbidden string found: $s"
done
echo "Strings checks passed."
name: Strings Check
on: [push, pull_request]
jobs:
strings:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install binutils
run: sudo apt-get update && sudo apt-get install -y binutils
- name: Run strings tests
run: bash scripts/strings-test.sh ./myapp 6
五 准确性与质量保障
sudo apt-get install lintian
lintian yourpackage.changes
sudo apt-get install checkstrings
checkstrings /path/to/package