Files
overlord/scripts/build-backstage-dll.sh
T

62 lines
2.1 KiB
Bash
Raw Normal View History

2026-03-11 23:11:44 -05:00
#!/usr/bin/env bash
2026-08-19 14:37:43 -05:00
# Build the BackstageInjection DLL from the Rust crate for Windows x64 using the
# windows-gnu target. Cross-compiles on Linux (CI / Docker) and works on Windows.
2026-03-11 23:11:44 -05:00
#
# Requirements:
2026-08-19 14:37:43 -05:00
# - cargo + the x86_64-pc-windows-gnu target installed (rustup target add ...)
# - gcc-mingw-w64-x86-64 (provides x86_64-w64-mingw32-gcc; cc uses it to build
# the bundled MinHook C source and link the payload)
2026-03-11 23:11:44 -05:00
set -euo pipefail
2026-06-12 09:14:49 -05:00
SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)"
cd "$ROOT"
2026-03-11 23:11:44 -05:00
2026-08-19 14:37:43 -05:00
CRATE_DIR="${BACKSTAGE_CRATE_DIR:-BackstageInjection-Rust}"
OUT_DIR="${BACKSTAGE_OUT_DIR:-Overlord-Server/dist-clients}"
2026-08-19 14:37:43 -05:00
TARGET="x86_64-pc-windows-gnu"
2026-05-22 20:34:20 -05:00
DLL_NAME="BackstageInjection.x64.dll"
2026-08-20 09:01:27 -05:00
LEGACY_DLL_NAME="BackstageInjection.legacy.x64.dll"
2026-03-11 23:11:44 -05:00
2026-08-19 14:37:43 -05:00
if ! command -v cargo >/dev/null 2>&1; then
echo "ERROR: cargo not found. Install a Rust toolchain (rustup)."
2026-03-11 23:20:51 -05:00
exit 1
fi
2026-08-19 14:37:43 -05:00
if ! rustup target list --installed 2>/dev/null | grep -qx "$TARGET"; then
echo "ERROR: target not installed: $TARGET"
echo "Install it with: rustup target add $TARGET"
exit 1
2026-03-11 23:20:51 -05:00
fi
2026-08-19 14:37:43 -05:00
if ! command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
echo "ERROR: cross compiler not found: x86_64-w64-mingw32-gcc"
echo "Install mingw-w64 (e.g. apt install gcc-mingw-w64-x86-64)."
exit 1
2026-03-11 23:20:51 -05:00
fi
2026-08-19 14:37:43 -05:00
mkdir -p "$OUT_DIR"
2026-03-11 23:11:44 -05:00
2026-08-20 09:01:27 -05:00
echo "Building randomized Rust BackstageInjection DLL ($TARGET) ..."
env -u BACKSTAGE_LOADER_EXPORT BACKSTAGE_LOADER_SEED="${BACKSTAGE_FRESH:-$(date +%s%N)}" \
cargo build --release --target "$TARGET" --manifest-path "$CRATE_DIR/Cargo.toml"
2026-03-11 23:29:38 -05:00
2026-08-19 14:37:43 -05:00
SRC_DLL="$CRATE_DIR/target/$TARGET/release/BackstageInjection.dll"
if [ ! -f "$SRC_DLL" ]; then
echo "ERROR: expected built DLL at $SRC_DLL"
exit 1
2026-03-11 23:11:44 -05:00
fi
2026-08-19 14:37:43 -05:00
cp -f "$SRC_DLL" "$OUT_DIR/$DLL_NAME"
2026-03-11 23:11:44 -05:00
echo "Built: $OUT_DIR/$DLL_NAME"
ls -la "$OUT_DIR/$DLL_NAME"
2026-08-20 09:01:27 -05:00
echo "Building legacy Rust BackstageInjection DLL ($TARGET) ..."
BACKSTAGE_LOADER_EXPORT=ReflectiveLoader \
cargo build --release --target "$TARGET" --manifest-path "$CRATE_DIR/Cargo.toml"
cp -f "$SRC_DLL" "$OUT_DIR/$LEGACY_DLL_NAME"
echo "Built: $OUT_DIR/$LEGACY_DLL_NAME"
ls -la "$OUT_DIR/$LEGACY_DLL_NAME"
echo "Done."