Skip to content

Instantly share code, notes, and snippets.

@arkon
Last active March 13, 2019 08:45
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save arkon/2577a405f707fa6e3ea45a2ef218dc85 to your computer and use it in GitHub Desktop.
Save arkon/2577a405f707fa6e3ea45a2ef218dc85 to your computer and use it in GitHub Desktop.
Bash scripts for patching boot.img/build.prop for Fate/Grand Order on LineageOS (https://goo.gl/YkHgjZ)
#!/usr/bin/env bash
#
# This script replaces "ro.debuggable=1" with "ro.debuggable=0" in the
# default.prop file in a ROM's boot.img and gives you the patched boot.img.
#
# Prerequisites:
# - A UNIX system (with `unzip`)
# - These tools added to your PATH:
# - Android dev tools (adb/fastboot)
# - Various tools in "bootimg_tools_7.8.13.zip" from https://goo.gl/48Sszu
# - "mkbootimg" from : https://goo.gl/rupmpN
# - "mkbootfs" from: https://github.com/osm0sis/mkbootfs (needs to be compiled)
# - "unpackbootimg" from: https://github.com/osm0sis/mkbootimg (needs to be compiled)
# - Debugging enabled on device
#
# Some info about (un)packing images: https://goo.gl/WAkb8B
#
if [ $# -eq 0 ]; then
echo "Usage: $0 ROM_FILE"
exit
fi
# Extract boot.img from the ROM
unzip -d tmp $1
cd tmp
split_boot ./boot.img
mkdir ./boot/split_img
unpackbootimg -i ./boot.img -o ./boot/split_img
# Edit the flag
if [ "$(uname)" == "Darwin" ]; then
sed -i '' -e $'/ro.debuggable=1/c\\\nro.debuggable=0' ./boot/ramdisk/default.prop
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
sed -i $'/ro.debuggable=1/c\\\nro.debuggable=0' ./boot/ramdisk/default.prop
fi
# Repackage boot.img
mkbootfs ./boot/ramdisk | gzip > ./boot/ramdisk-new.gz
cd ./boot/split_img
kernel=`ls *-zImage`;
cmdline=`cat *-cmdline`;
board=`cat *-board`;
base=`cat *-base`;
pagesize=`cat *-pagesize`;
kerneloff=`cat *-kerneloff`;
ramdiskoff=`cat *-ramdiskoff`;
tagsoff=`cat *-tagsoff`;
cd ../..
mkbootimg \
--kernel "./boot/split_img/$kernel" \
--ramdisk ./boot/ramdisk-new.gz \
--cmdline "$cmdline" \
--board "$board" \
--base $base \
--pagesize $pagesize \
--kernel_offset $kerneloff \
--ramdisk_offset $ramdiskoff \
--tags_offset $tagsoff $dtb \
-o ../boot-new.img;
cd ..
rm -rf ./tmp
echo "Created boot-new.img"
# Flash the image and reboot
echo "Flashing patched boot image..."
adb reboot bootloader
fastboot flash boot boot-new.img
fastboot reboot
#!/usr/bin/env bash
#
# Assumes your device is already connected and recognized by adb
# You can check by running `adb devices`
#
# Prerequisites:
# - A UNIX system
# - These tools added to your PATH:
# - Android dev tools (adb/fastboot)
# - Debugging enabled on device with root allowed for ADB
#
adb root
adb remount
adb pull /system/build.prop
if [ "$(uname)" == "Darwin" ]; then
sed -i '' -e $'s/^ro\.build\.type=.*$/ro\.build\.type=user/' ./build.prop
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
sed -i $'s/^ro\.build\.type=.*$/ro\.build\.type=user/' ./build.prop
fi
adb push build.prop /system/build.prop
adb shell chmod 644 /system/build.prop
adb reboot
rm -f ./build.prop
echo "Patched build.prop, rebooting device..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment