Harden build and injection shell scripts

This commit is contained in:
√(noham)²
2026-08-25 23:40:08 +02:00
parent b672c6596f
commit b7f27b1671
3 changed files with 89 additions and 67 deletions

View File

@@ -95,6 +95,7 @@ echo "✅ Qt libraries ready at $QT_LIB_DIR"
# --- Step 2: Compile native hooking library ---
echo "[2/2] Compiling $SO_NAME..."
# shellcheck disable=SC2086
"$CC" -shared -fPIC -O2 -std=c++17 -stdlib=libc++ -fno-exceptions -fno-rtti \
-DQT_NO_VERSION_TAGGING \
-o "$BUILD_DIR/$SO_NAME" \
@@ -120,4 +121,4 @@ echo "📍 Library: $BUILD_DIR/$SO_NAME ($(ls -lh "$BUILD_DIR/$SO_NAME" | awk '{
echo ""
echo "🚀 To inject into the reMarkable application:"
echo " ./script/inject.sh"
echo ""
echo ""

View File

@@ -33,6 +33,17 @@ KEYSTORE="$PROJECT_DIR/config/rmhook.keystore"
KEYSTORE_PASS="rmhook"
KEY_ALIAS="rmhook"
# --- Portable in-place sed (GNU sed vs BSD/macOS sed take -i differently) ---
sed_inplace() {
if sed --version >/dev/null 2>&1; then
# GNU sed
sed -i "$@"
else
# BSD/macOS sed requires an explicit (possibly empty) backup suffix
sed -i '' "$@"
fi
}
usage() {
echo "Usage: $0 [apk_dir]"
echo ""
@@ -56,6 +67,8 @@ fi
# Clean and create output directory
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
rm -rf "$BUILD_DIR/base" "$BUILD_DIR/split_arm64" "$BUILD_DIR/split_xxhdpi"
rm -f "$BUILD_DIR"/*.apk
# --- Step 1: Decompile and patch base.apk (smali injection only, no resources) ---
echo "[1/4] Patching base.apk (smali injection)..."
@@ -69,7 +82,7 @@ if [ ! -f "$MAIN_SMALI" ]; then
fi
# Insert System.loadLibrary("rmhook") at the very start of <clinit>
sed -i '' '/.method static constructor <clinit>()V/{
sed_inplace '/.method static constructor <clinit>()V/{
n
/.locals/{
a\
@@ -80,6 +93,12 @@ a\
}
}' "$MAIN_SMALI"
if ! grep -q 'invoke-static {v0}, Ljava/lang/System;->loadLibrary' "$MAIN_SMALI"; then
echo "❌ Failed to inject loadLibrary(\"rmhook\") into MainActivity.smali"
echo " The <clinit> block's shape may have changed - inspect $MAIN_SMALI manually."
exit 1
fi
echo "✅ Injected System.loadLibrary(\"rmhook\") into MainActivity.<clinit>"
apktool b "$BUILD_DIR/base" -o "$BUILD_DIR/base_patched.apk"
@@ -100,8 +119,8 @@ cp "$LIBS_DIR/libshadowhook_nothing.so" "$BUILD_DIR/split_arm64/lib/arm64-v8a/"
rm -rf "$BUILD_DIR/split_arm64/META-INF"
(cd "$BUILD_DIR/split_arm64" && zip -q -r -0 "$BUILD_DIR/split_arm64_raw.apk" . -x "*.so")
(cd "$BUILD_DIR/split_arm64" && zip -q -r "$BUILD_DIR/split_arm64_raw.apk" lib/)
# Store everything uncompressed (-0), including the native libraries.
(cd "$BUILD_DIR/split_arm64" && zip -q -r -0 "$BUILD_DIR/split_arm64_raw.apk" .)
# --- Step 3: Align APKs ---
echo "[3/4] Aligning APKs..."
@@ -160,7 +179,8 @@ echo ""
echo "🚀 To install on your reMarkable:"
echo " adb uninstall com.remarkable.mobile"
echo " adb install-multiple --no-streaming $OUTPUT_DIR/base.apk $OUTPUT_DIR/split_config.arm64_v8a.apk $OUTPUT_DIR/split_config.xxhdpi.apk"
echo " adb push rmhook.conf /sdcard/Android/data/com.remarkable.mobile/files/rmhook.conf"
echo ""
echo "🔍 To debug:"
echo " adb logcat -s 'RMHook:*'"
echo ""
echo ""