Files
verify/shell/boot/build-blob.sh

31 lines
1.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 从源码重建引导 blob
# 用法: ./build-blob.sh <bootstrap.c> [x64|x86] [输出文件]
# 例: ./build-blob.sh bootstrap5.c x64 blob64.bin
# 详见 ../README.md「构建引导 blob」——重编产物与仓库里的预编译 blob 行为不一致,替换前务必实测。
set -euo pipefail
SRC=${1:?用法: $0 <bootstrap.c> [x64|x86] [out.bin]}
ARCH=${2:-x64}
OUT=${3:-blob64.bin}
DIR=$(cd "$(dirname "$0")" && pwd)
DEFS=""
if [ "$ARCH" = "x64" ]; then DEFS="-D_WIN64"; fi
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
gcc -c $DEFS -ffreestanding -fno-stack-protector -fno-asynchronous-unwind-tables \
-mno-stack-arg-probe "$SRC" -o "$TMP/blob.o"
# 别用 ld --oformat=binary(会报 cannot perform PE operations on non PE output file),
# 走链接脚本把 .text/.rdata/.data 合成单节再 objcopy 提取
ld -e blob_main -nostdlib -T "$DIR/blob.ld" "$TMP/blob.o" -o "$TMP/blob.elf" 2>/dev/null
objcopy -O binary -j .blob "$TMP/blob.elf" "$OUT"
echo "生成 $OUT($(stat -c%s "$OUT") 字节,arch=$ARCH)"
echo "注意:本机 gcc 重编的 blob 与 assets/ 里的预编译 blob 行为不同(详见 ../README.md),"
echo " 替换资产前先把「单层 / 双层 / 篡改 .vfy & PE 头」四类用例实测一遍。"