温馨提示×

怎样写debian strings脚本

小樊
35
2026-10-12 21:51:39
栏目: 智能运维

在 Debian 包装(packaging)或相关开发里,常说的 “debian strings 脚本” 一般有两种理解:

  1. 在 Debian 软件包中使用的脚本(放在 debian/ 目录里)
  2. 用于处理二进制文件、提取字符串(类似 strings 命令)的脚本(常用于 Debian 维护或逆向分析)

下面我分别说明,并给你可直接用的示例。


一、Debian 打包中的“strings 脚本”(debian/ 下脚本)

如果你是Debian 包维护者,想在构建过程中提取或检查字符串,可以在 debian/ 目录放一个脚本,比如:

示例:debian/extract-strings

#!/bin/sh
# debian/extract-strings

set -e

BINARY="$1"

if [ -z "$BINARY" ]; then
    echo "Usage: $0 <binary>" >&2
    exit 1
fi

if [ ! -f "$BINARY" ]; then
    echo "File not found: $BINARY" >&2
    exit 1
fi

strings "$BINARY" | sort | uniq

使用方法

chmod +x debian/extract-strings
debian/extract-strings debian/myapp/usr/bin/myapp

如果你希望在 debhelper 流程中自动执行,可以加到:

  • debian/rules
  • 或 debian/<package>.lintian-overrides 配合检查

二、通用的“strings 脚本”(处理 Debian 二进制)

如果你想写一个 shell / Python 脚本,从 Debian 包或二进制中提取字符串:

Shell 版本(最简单)

#!/bin/bash

for f in "$@"; do
    echo "=== $f ==="
    strings -n 6 "$f"
done

使用:

./strings.sh /usr/bin/* debian/myapp/usr/bin/*

Python 版本(更可控)

#!/usr/bin/env python3
import sys
import re

def extract_strings(path, min_len=6):
    with open(path, 'rb') as f:
        data = f.read()

    pattern = rb'[\x20-\x7e]{%d,}' % min_len
    return re.findall(pattern, data)

if __name__ == '__main__':
    for path in sys.argv[1:]:
        print(f"=== {path} ===")
        for s in extract_strings(path):
            print(s.decode('utf-8', errors='ignore'))

三、Debian 包中“strings”相关常见用途

  • 检查是否泄露路径 / 用户名
  • 提取版本信息
  • Lintian 问题排查
  • 国际化(i18n)字符串分析
  • 安全审计

四、如果你是指“deb 包里的字符串资源”

有时开发者想:

  • 从 .deb 提取字符串
  • 检查 .mo / .po

示例:

dpkg-deb -x package.deb out/
strings out/usr/bin/app

五、总结

场景 推荐方式
Debian 构建脚本 debian/xxx + chmod +x
快速提取 strings
复杂分析 Python
包内容检查 dpkg-deb -x

如果你能具体说一下:

  • 是 Debian 打包脚本
  • 还是 分析二进制
  • 或是 提取翻译字符串

我可以给你更精准的模板。

0 踩