From 9703977f218881f4d40de6d297f1cfb68821d9d3 Mon Sep 17 00:00:00 2001 From: Hackerdude <69104218+ThatHackerDudeFromCyberspace@users.noreply.github.com> Date: Sun, 4 Oct 2026 17:56:43 +0100 Subject: [PATCH] Revert "Add Rootless Support" --- .gitignore | 2 +- src/helpers/00_helpers.sh | 34 +----- src/jb_sh_jobs/04_setup_kmc.sh | 10 +- src/jb_sh_jobs/06_patch_system.sh | 9 +- .../{07_restart_gui.sh => 07_cleanup.sh} | 4 +- src/kmc/block_ota | 1 - src/kmc/rootless_menu.sh | 7 -- .../sql/appreg_register_rootless_persist.sql | 5 - .../logThis.sh => system_patches/dispatch.sh} | 0 .../{emergency.conf => kmc.conf} | 7 +- src/kmc/system_patches/run_patch.conf | 14 --- src/kmc/system_patches/run_patch.sh | 6 +- src/system_patch_jobs/00_header.sh | 6 +- .../{01_allow_rw.sh => 01_mntroot.sh} | 15 +-- .../02_install_update_keys.sh | 96 ++++++++-------- src/system_patch_jobs/03_setup_kmc.sh | 11 +- .../04_install_mkk_kindlet_jb.sh | 11 +- .../05_install_gm_debugging.sh | 10 -- src/system_patch_jobs/05_setup_dispatch.sh | 8 ++ .../06_install_gm_debugging.sh | 9 ++ .../06_remount_mntus_exec.sh | 37 ------- .../07_install_kmc_upstart.sh | 25 ----- .../07_install_mntus_exec.sh | 9 ++ .../08_install_kmc_upstart.sh | 12 ++ src/system_patch_jobs/08_patch_json_files.sh | 24 ---- src/system_patch_jobs/09_ota_block.sh | 103 ------------------ src/system_patch_jobs/09_run_patch_binary.sh | 4 + src/system_patch_jobs/10_ota_rename.sh | 33 ++++++ src/system_patch_jobs/10_reset_patch.sh | 28 ----- src/system_patch_jobs/11_cleanup.sh | 5 - src/system_patch_jobs/11_reset_patch.sh | 15 +++ .../12_rootless_gui_restart.sh | 30 ----- system_patcher/main.c | 50 +++++---- 33 files changed, 196 insertions(+), 444 deletions(-) rename src/jb_sh_jobs/{07_restart_gui.sh => 07_cleanup.sh} (94%) delete mode 100644 src/kmc/block_ota delete mode 100644 src/kmc/rootless_menu.sh delete mode 100644 src/kmc/sql/appreg_register_rootless_persist.sql rename src/kmc/{sbin/logThis.sh => system_patches/dispatch.sh} (100%) rename src/kmc/system_patches/{emergency.conf => kmc.conf} (71%) delete mode 100644 src/kmc/system_patches/run_patch.conf rename src/system_patch_jobs/{01_allow_rw.sh => 01_mntroot.sh} (50%) delete mode 100644 src/system_patch_jobs/05_install_gm_debugging.sh create mode 100644 src/system_patch_jobs/05_setup_dispatch.sh create mode 100644 src/system_patch_jobs/06_install_gm_debugging.sh delete mode 100644 src/system_patch_jobs/06_remount_mntus_exec.sh delete mode 100644 src/system_patch_jobs/07_install_kmc_upstart.sh create mode 100644 src/system_patch_jobs/07_install_mntus_exec.sh create mode 100644 src/system_patch_jobs/08_install_kmc_upstart.sh delete mode 100644 src/system_patch_jobs/08_patch_json_files.sh delete mode 100644 src/system_patch_jobs/09_ota_block.sh create mode 100644 src/system_patch_jobs/09_run_patch_binary.sh create mode 100644 src/system_patch_jobs/10_ota_rename.sh delete mode 100644 src/system_patch_jobs/10_reset_patch.sh delete mode 100644 src/system_patch_jobs/11_cleanup.sh create mode 100644 src/system_patch_jobs/11_reset_patch.sh delete mode 100644 src/system_patch_jobs/12_rootless_gui_restart.sh diff --git a/.gitignore b/.gitignore index 7afa4f3..2311ea0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /build /cache -.vscode +.vscode \ No newline at end of file diff --git a/src/helpers/00_helpers.sh b/src/helpers/00_helpers.sh index 8194fb2..5a7d06a 100644 --- a/src/helpers/00_helpers.sh +++ b/src/helpers/00_helpers.sh @@ -3,7 +3,7 @@ ### # Defines ### -JB_SH_VERSION="v2.0.0" +JB_SH_VERSION="v1.3.7" if [ ! -n "${JB_HEADER+x}" ] && [ -f "/var/local/jailbreak.txt" ]; then JB_HEADER=$(cat /var/local/jailbreak.txt) @@ -60,9 +60,6 @@ if cat /proc/cmdline | grep androidboot.veritymode; then ROOTLESS=1 fi -if [ -z "$MANPATCH" ]; then - MANPATCH=0 # passed by rootless_menu.sh when 1 -fi POS=1 log() { @@ -116,33 +113,4 @@ make_immutable() { elif [ -f "${my_path}" ] ; then ${CHATTR} +i "${my_path}" fi -} - -# Returns 0 (true) if immutable bit is set, 1 (false) if not (or if file doesn't exist) -check_immutable() { - lsattr.e2fsprogs "$1" | cut -d' ' -f1 | grep -q 'i' -} - -# Setup Bind Mount - sets up a bind mount for a file/directory (likely on rootfs) -# by making a temporary file/directory in EARLYBIRD_BINDS_PATH at a corresponding path -# Outputs the path to the temporary file/directory -# Credit to scam.net for this function - -MAX_COPY_SIZE=5192 # Max size (in KB) to copy to /var/local/kmc/binds for bind mounts -setup_bind_mount() { - local overridden_path="$(realpath "${1}")" - local bind_path="/var/local/kmc/binds${overridden_path}" - local bind_parent_path="$(dirname "${bind_path}")" - # if it doesn't already exist, we need to make it - if [ ! -e "${bind_path}" ]; then - mkdir -p "${bind_parent_path}" - # straight up copy everything, will work for both dirs and files - cp -a "${overridden_path}" "${bind_parent_path}" - fi - # Check to make sure we aren't already mounted. Yes this is sinful as fuck. I'm sorry. - if cut -d' ' -f5 /proc/self/mountinfo | grep -xq "${overridden_path}"; then - umount "${overridden_path}" # Necessary because of potential stale mounts when MANPATCHning jb.sh - fi - mount -o bind "${bind_path}" "${overridden_path}" - echo "${bind_path}" } \ No newline at end of file diff --git a/src/jb_sh_jobs/04_setup_kmc.sh b/src/jb_sh_jobs/04_setup_kmc.sh index 54d1875..f530eea 100644 --- a/src/jb_sh_jobs/04_setup_kmc.sh +++ b/src/jb_sh_jobs/04_setup_kmc.sh @@ -3,12 +3,9 @@ log "Setting KMC permissions" chmod -R a+rx /var/local/kmc/sbin/* chmod -R a+rx /var/local/kmc/kindlepw2/* chmod -R a+rx /var/local/kmc/kindlehf/* -chmod 0664 /var/local/kmc/system_patches/emergency.conf -chmod 0664 /var/local/kmc/system_patches/run_patch.conf +chmod 0664 /var/local/kmc/system_patches/kmc.conf chmod a+rx /var/local/kmc/system_patches/patch_system.sh chmod a+rx /var/local/kmc/system_patches/run_patch.sh -chmod a+rx /var/local/kmc/rootless_menu.sh -chmod 444 /var/local/kmc/block_ota log "Setting KMC gandalf permissions" for gandalf_platform in kindlepw2 kindlehf; do @@ -46,11 +43,6 @@ log "Setting up hotfix and emergency runners" log "$(cat /var/local/kmc/sql/appreg_register_hotfix.sql | sqlite3 /var/local/appreg.db)" log "$(cat /var/local/kmc/sql/appreg_register_emergency.sql | sqlite3 /var/local/appreg.db)" -if [ $ROOTLESS -eq 1 ]; then - log "Setting up rootless persistence patch" - log "$(cat /var/local/kmc/sql/appreg_register_rootless_persist.sql | sqlite3 /var/local/appreg.db)" -fi - if [ ! -d "/usr/lib/ccat" ]; then log "Setting up sh_integration" log "$(cat /var/local/kmc/sql/appreg_register_sh_integration_common.sql | sqlite3 /var/local/appreg.db)" diff --git a/src/jb_sh_jobs/06_patch_system.sh b/src/jb_sh_jobs/06_patch_system.sh index 19e86e7..cd5498f 100644 --- a/src/jb_sh_jobs/06_patch_system.sh +++ b/src/jb_sh_jobs/06_patch_system.sh @@ -20,5 +20,10 @@ fi # Run system patch script (what was once the hotfix) -log "Running system patch script" -ROOTLESS=$ROOTLESS RUN_MODE=$RUN_MODE JAILBROKEN=$JAILBROKEN sh /var/local/kmc/system_patches/patch_system.sh # Run it directly since jb.sh MUST be run as root \ No newline at end of file +# Detect rootless Kindle +if [ $ROOTLESS -eq 0 ]; then + log "Running system patch script" + ROOTLESS=$ROOTLESS RUN_MODE=$RUN_MODE JAILBROKEN=$JAILBROKEN sh /var/local/kmc/system_patches/patch_system.sh # Run it directly since jb.sh MUST be run as root +else + log "Running on rootless system with dmverity, skipping system patches" +fi \ No newline at end of file diff --git a/src/jb_sh_jobs/07_restart_gui.sh b/src/jb_sh_jobs/07_cleanup.sh similarity index 94% rename from src/jb_sh_jobs/07_restart_gui.sh rename to src/jb_sh_jobs/07_cleanup.sh index 4f4c977..df983b5 100644 --- a/src/jb_sh_jobs/07_restart_gui.sh +++ b/src/jb_sh_jobs/07_cleanup.sh @@ -1,4 +1,6 @@ -#!/bin/sh +/bin/mount -o remount,ro / +/bin/mount -o exec /mnt/us # Remount as exec +log "Done" if [ $RUN_MODE -eq 1 ] || [ $JAILBROKEN -eq 0 ]; then printf "You are jailbroken!\n" > /mnt/us/documents/JAILBROKEN.txt diff --git a/src/kmc/block_ota b/src/kmc/block_ota deleted file mode 100644 index 5d4fb50..0000000 --- a/src/kmc/block_ota +++ /dev/null @@ -1 +0,0 @@ -DO NOT REMOVE - OTA Update Blocker \ No newline at end of file diff --git a/src/kmc/rootless_menu.sh b/src/kmc/rootless_menu.sh deleted file mode 100644 index daea41e..0000000 --- a/src/kmc/rootless_menu.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -if [ ! -f "/mnt/us/ACCESS_HELPAPP" ]; then # sadly, this is probably the simplest way to not take away access to the help menus from a user - MANPATCH=1 sh /var/local/kmc/system_patches/run_patch.sh & -fi - -# exec so the shell process is replaced with mesquite -exec /usr/bin/mesquite -l com.lab126.helpapp -c file:///var/local/mesquite/help/ "$@" \ No newline at end of file diff --git a/src/kmc/sql/appreg_register_rootless_persist.sql b/src/kmc/sql/appreg_register_rootless_persist.sql deleted file mode 100644 index b435121..0000000 --- a/src/kmc/sql/appreg_register_rootless_persist.sql +++ /dev/null @@ -1,5 +0,0 @@ -BEGIN; - -UPDATE properties SET value='/bin/sh /var/local/kmc/rootless_menu.sh' WHERE handlerId='com.lab126.helpapp' AND name='command'; - -COMMIT; \ No newline at end of file diff --git a/src/kmc/sbin/logThis.sh b/src/kmc/system_patches/dispatch.sh similarity index 100% rename from src/kmc/sbin/logThis.sh rename to src/kmc/system_patches/dispatch.sh diff --git a/src/kmc/system_patches/emergency.conf b/src/kmc/system_patches/kmc.conf similarity index 71% rename from src/kmc/system_patches/emergency.conf rename to src/kmc/system_patches/kmc.conf index a43adc5..ed39513 100644 --- a/src/kmc/system_patches/emergency.conf +++ b/src/kmc/system_patches/kmc.conf @@ -1,5 +1,6 @@ ### -# Run an emergency.sh on boot +# Run our system patches on every boot juuuuust in case something gets borked +# This USED to be the bridge script - Update persistence can't be done via upstart so we handle it with appreg.db ### start on framework_ready stop on stopping framework @@ -9,7 +10,7 @@ export LANG LC_ALL pre-start script [ -f "/etc/upstart/functions" ] && source /etc/upstart/functions - f_log I bridge start "" "hello there from emergency.conf!" + f_log I bridge start "" "hello there from kmc.conf!" BRIDGE_EMERGENCY="/mnt/us/emergency.sh" @@ -25,6 +26,6 @@ pre-start script fi f_log I bridge start "" "so uncivilized" - + return 0 end script diff --git a/src/kmc/system_patches/run_patch.conf b/src/kmc/system_patches/run_patch.conf deleted file mode 100644 index 78f5183..0000000 --- a/src/kmc/system_patches/run_patch.conf +++ /dev/null @@ -1,14 +0,0 @@ -### -# Run our system patches on every boot juuuuust in case something gets borked -# This USED to be the bridge script - Update persistence can't be done via upstart so we handle it with appreg.db -### -description "run_patch" -start on started kindle -stop on stopping filesystems - -task -script - logger "hello from run_patch.conf" # bridge command is weird here - - sh /var/local/kmc/system_patches/run_patch.sh -end script diff --git a/src/kmc/system_patches/run_patch.sh b/src/kmc/system_patches/run_patch.sh index 6178eb6..a71001c 100644 --- a/src/kmc/system_patches/run_patch.sh +++ b/src/kmc/system_patches/run_patch.sh @@ -8,8 +8,4 @@ if [ -f /lib/ld-linux-armhf.so.3 ]; then PLATFORM="kindlehf" fi -if [ -z "$MANPATCH" ]; then - MANPATCH=0 # passed by rootless_menu.sh -fi - -MANPATCH=$MANPATCH /var/local/kmc/${PLATFORM}/bin/su -c "sh /var/local/kmc/system_patches/patch_system.sh" \ No newline at end of file +/var/local/kmc/${PLATFORM}/bin/su -c "sh /var/local/kmc/system_patches/patch_system.sh" \ No newline at end of file diff --git a/src/system_patch_jobs/00_header.sh b/src/system_patch_jobs/00_header.sh index ddd26e1..d9fd025 100644 --- a/src/system_patch_jobs/00_header.sh +++ b/src/system_patch_jobs/00_header.sh @@ -16,8 +16,4 @@ fi log "" log "P:$RUN_MODE:$JAILBROKEN:$ROOTLESS:$PLATFORM" -log "" - -if [ -z "$RERUN" ]; then - RERUN=0 # passed by rootless_menu.sh when 1 -fi \ No newline at end of file +log "" \ No newline at end of file diff --git a/src/system_patch_jobs/01_allow_rw.sh b/src/system_patch_jobs/01_mntroot.sh similarity index 50% rename from src/system_patch_jobs/01_allow_rw.sh rename to src/system_patch_jobs/01_mntroot.sh index c3defc1..60c7ea5 100644 --- a/src/system_patch_jobs/01_allow_rw.sh +++ b/src/system_patch_jobs/01_mntroot.sh @@ -1,6 +1,8 @@ #!/bin/sh -if [ $ROOTLESS -eq 0 ]; then +if ! /bin/mount -o remount,rw /; then + log "Failed to remount as rw, trying again" + sleep 1 if ! /bin/mount -o remount,rw /; then log "Failed to remount as rw, trying again" sleep 1 @@ -8,15 +10,8 @@ if [ $ROOTLESS -eq 0 ]; then log "Failed to remount as rw, trying again" sleep 1 if ! /bin/mount -o remount,rw /; then - log "Failed to remount as rw, trying again" - sleep 1 - if ! /bin/mount -o remount,rw /; then - log "Failed to remount as rw after 4 attempts." - fi + log "Failed to remount as rw after 4 attempts." fi fi fi -fi - -make_mutable /var/local/kmc -log "Made /var/local/kmc mutable" \ No newline at end of file +fi \ No newline at end of file diff --git a/src/system_patch_jobs/02_install_update_keys.sh b/src/system_patch_jobs/02_install_update_keys.sh index 9de748b..48e125f 100644 --- a/src/system_patch_jobs/02_install_update_keys.sh +++ b/src/system_patch_jobs/02_install_update_keys.sh @@ -1,12 +1,11 @@ #!/bin/sh -if [ $ROOTLESS -eq 0 ]; then - install_touch_update_key() - { - log "Copying the jailbreak updater key" - make_mutable "/etc/uks/pubdevkey01.pem" - rm -rf "/etc/uks/pubdevkey01.pem" - cat > "/etc/uks/pubdevkey01.pem" << EOF # do not indent this or the world will end +install_touch_update_key() +{ + log "Copying the jailbreak updater key" + make_mutable "/etc/uks/pubdevkey01.pem" + rm -rf "/etc/uks/pubdevkey01.pem" + cat > "/etc/uks/pubdevkey01.pem" << EOF -----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDJn1jWU+xxVv/eRKfCPR9e47lP WN2rH33z9QbfnqmCxBRLP6mMjGy6APyycQXg3nPi5fcb75alZo+Oh012HpMe9Lnp @@ -14,52 +13,51 @@ eEgloIdm1E4LOsyrz4kttQtGRlzCErmBGt6+cAVEV86y2phOJ3mLk0Ek9UQXbIUf rvyJnS2MKLG2cczjlQIDAQAB -----END PUBLIC KEY----- EOF - # Harmonize permissions - chown root:root "/etc/uks/pubdevkey01.pem" - chmod 0644 "/etc/uks/pubdevkey01.pem" - make_immutable "/etc/uks/pubdevkey01.pem" - } + # Harmonize permissions + chown root:root "/etc/uks/pubdevkey01.pem" + chmod 0644 "/etc/uks/pubdevkey01.pem" + make_immutable "/etc/uks/pubdevkey01.pem" +} - install_touch_update_key_squash() - { - log "Copying the jailbreak updater keystore" - make_mutable "/etc/uks.sqsh" - local my_loop="$(grep ' /etc/uks ' /proc/mounts | cut -f1 -d' ')" - umount "${my_loop}" - losetup -d "${my_loop}" - cp -f "/var/local/kmc/system_patches/updater_keys.sqsh" "/etc/uks.sqsh" - mount -o loop="${my_loop}",nodiratime,noatime -t squashfs "/etc/uks.sqsh" "/etc/uks" - #make_immutable "/etc/uks.sqsh" # Breaks 12th gen - } +install_touch_update_key_squash() +{ + log "Copying the jailbreak updater keystore" + make_mutable "/etc/uks.sqsh" + local my_loop="$(grep ' /etc/uks ' /proc/mounts | cut -f1 -d' ')" + umount "${my_loop}" + losetup -d "${my_loop}" + cp -f "/var/local/kmc/system_patches/updater_keys.sqsh" "/etc/uks.sqsh" + mount -o loop="${my_loop}",nodiratime,noatime -t squashfs "/etc/uks.sqsh" "/etc/uks" + #make_immutable "/etc/uks.sqsh" # Breaks 12th gen +} - # Check if we need to do something with the OTA pubkey - if [ ! -f "/etc/uks.sqsh" ] ; then - if [ ! -f "/etc/uks/pubdevkey01.pem" ] ; then - # No jailbreak key, install it +# Check if we need to do something with the OTA pubkey +if [ ! -f "/etc/uks.sqsh" ] ; then + if [ ! -f "/etc/uks/pubdevkey01.pem" ] ; then + # No jailbreak key, install it + install_touch_update_key + else + # Jailbreak key found... Check it. + if [ "$(md5sum "/etc/uks/pubdevkey01.pem" | cut -d' ' -f1)" != "7130ce39bb3596c5067cabb377c7a9ed" ] ; then + # Unknown (?!) jailbreak key, install it install_touch_update_key - else - # Jailbreak key found... Check it. - if [ "$(md5sum "/etc/uks/pubdevkey01.pem" | cut -d' ' -f1)" != "7130ce39bb3596c5067cabb377c7a9ed" ] ; then - # Unknown (?!) jailbreak key, install it - install_touch_update_key - fi - if [ ! -O "/etc/uks/pubdevkey01.pem" ] || [ ! -G "/etc/uks/pubdevkey01.pem" ] ; then - # Not our own? Make it so! - install_touch_update_key - fi fi - fi - - # Check if we need to do something with the OTA keystore - if [ -f "/etc/uks.sqsh" ] && [ -f "/var/local/kmc/system_patches/updater_keys.sqsh" ] ; then - # Check it. - if [ "$(md5sum "/etc/uks.sqsh" | cut -d' ' -f1)" != "17b5ca595e70ffeee1424ed5e7f09c47" ] ; then - # Unknown (?!) jailbreak keystore, install it - install_touch_update_key_squash - fi - if [ ! -O "/etc/uks.sqsh" ] || [ ! -G "/etc/uks.sqsh" ] ; then + if [ ! -O "/etc/uks/pubdevkey01.pem" ] || [ ! -G "/etc/uks/pubdevkey01.pem" ] ; then # Not our own? Make it so! - install_touch_update_key_squash + install_touch_update_key fi fi -fi \ No newline at end of file +fi + +# Check if we need to do something with the OTA keystore +if [ -f "/etc/uks.sqsh" ] && [ -f "/var/local/kmc/system_patches/updater_keys.sqsh" ] ; then + # Check it. + if [ "$(md5sum "/etc/uks.sqsh" | cut -d' ' -f1)" != "17b5ca595e70ffeee1424ed5e7f09c47" ] ; then + # Unknown (?!) jailbreak keystore, install it + install_touch_update_key_squash + fi + if [ ! -O "/etc/uks.sqsh" ] || [ ! -G "/etc/uks.sqsh" ] ; then + # Not our own? Make it so! + install_touch_update_key_squash + fi +fi diff --git a/src/system_patch_jobs/03_setup_kmc.sh b/src/system_patch_jobs/03_setup_kmc.sh index b279b1d..317d157 100644 --- a/src/system_patch_jobs/03_setup_kmc.sh +++ b/src/system_patch_jobs/03_setup_kmc.sh @@ -1,8 +1,9 @@ #!/bin/sh + if [ -d "/usr/lib/ccat" ]; then log "/usr/lib/ccat detected, patching sh_integration extractor into system" - setup_bind_mount /usr/lib/ccat # usually like 500kb, should be fine + make_mutable /usr/lib/ccat/ make_mutable /usr/lib/ccat/sh_integration_extractor.so cp -af /var/local/kmc/lib/sh_integration_extractor.so /usr/lib/ccat/sh_integration_extractor.so make_immutable /usr/lib/ccat/sh_integration_extractor.so @@ -11,17 +12,13 @@ if [ -d "/usr/lib/ccat" ]; then log "$(cat /var/local/kmc/sql/appreg_register_sh_integration_common.sql | sqlite3 /var/local/appreg.db)" log "$(cat /var/local/kmc/sql/appreg_register_sh_integration_2.sql | sqlite3 /var/local/appreg.db)" NUM=$(echo "SELECT * FROM properties WHERE handlerId='tech.hackerdude.shell_integration.extractor'" | sqlite3 /var/local/appreg.db --line | wc -l) - if [ $NUM -eq 7 ]; then - log "sh_integration successfully setup!" - else + if [ ! $NUM -eq 7 ]; then log "Failed to setup sh_integration, trying again..." sleep 1 log "$(cat /var/local/kmc/sql/appreg_register_sh_integration_common.sql | sqlite3 /var/local/appreg.db)" log "$(cat /var/local/kmc/sql/appreg_register_sh_integration_2.sql | sqlite3 /var/local/appreg.db)" NUM=$(echo "SELECT * FROM properties WHERE handlerId='tech.hackerdude.shell_integration.extractor'" | sqlite3 /var/local/appreg.db --line | wc -l) - if [ $NUM -eq 7 ]; then - log "sh_integration successfully setup!" - else + if [ ! $NUM -eq 7 ]; then log "Failed to setup sh_integraion - please report to Hackerdude" fi fi diff --git a/src/system_patch_jobs/04_install_mkk_kindlet_jb.sh b/src/system_patch_jobs/04_install_mkk_kindlet_jb.sh index 121bb97..0af8ef1 100644 --- a/src/system_patch_jobs/04_install_mkk_kindlet_jb.sh +++ b/src/system_patch_jobs/04_install_mkk_kindlet_jb.sh @@ -1,9 +1,8 @@ #!/bin/sh + # Kindlet JB doesn't match, install it -if [ $ROOTLESS -eq 0 ]; then - if [ "$(md5sum "/opt/amazon/ebook/lib/json_simple-1.1.jar" | cut -d' ' -f1)" != "$(md5sum "/var/local/kmc/system_patches/json_simple-1.1.jar" | cut -d' ' -f1)" ] ; then - log "Copying the kindlet jailbreak" - cp -f "/var/local/kmc/system_patches/json_simple-1.1.jar" "/opt/amazon/ebook/lib/json_simple-1.1.jar" - chmod 0664 "/opt/amazon/ebook/lib/json_simple-1.1.jar" - fi +if [ "$(md5sum "/opt/amazon/ebook/lib/json_simple-1.1.jar" | cut -d' ' -f1)" != "$(md5sum "/var/local/kmc/system_patches/json_simple-1.1.jar" | cut -d' ' -f1)" ] ; then + log "Copying the kindlet jailbreak" + cp -f "/var/local/kmc/system_patches/json_simple-1.1.jar" "/opt/amazon/ebook/lib/json_simple-1.1.jar" + chmod 0664 "/opt/amazon/ebook/lib/json_simple-1.1.jar" fi \ No newline at end of file diff --git a/src/system_patch_jobs/05_install_gm_debugging.sh b/src/system_patch_jobs/05_install_gm_debugging.sh deleted file mode 100644 index 15d7539..0000000 --- a/src/system_patch_jobs/05_install_gm_debugging.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -if [ $ROOTLESS -eq 0 ]; then - if [ ! -f "/PRE_GM_DEBUGGING_FEATURES_ENABLED__REMOVE_AT_GMC" ] ; then - log "Creating the debugging flag file" - make_mutable "/PRE_GM_DEBUGGING_FEATURES_ENABLED__REMOVE_AT_GMC" - rm -rf "/PRE_GM_DEBUGGING_FEATURES_ENABLED__REMOVE_AT_GMC" - touch "/PRE_GM_DEBUGGING_FEATURES_ENABLED__REMOVE_AT_GMC" - make_immutable "/PRE_GM_DEBUGGING_FEATURES_ENABLED__REMOVE_AT_GMC" - fi -fi \ No newline at end of file diff --git a/src/system_patch_jobs/05_setup_dispatch.sh b/src/system_patch_jobs/05_setup_dispatch.sh new file mode 100644 index 0000000..c6ab098 --- /dev/null +++ b/src/system_patch_jobs/05_setup_dispatch.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +log "Copying dispatch (logThis) script" +make_mutable "/usr/bin/logThis.sh" +rm -rf "/usr/bin/logThis.sh" +cp -f "/var/local/kmc/system_patches/dispatch.sh" "/usr/bin/logThis.sh" +chmod 0755 "/usr/bin/logThis.sh" +make_immutable "/usr/bin/logThis.sh" \ No newline at end of file diff --git a/src/system_patch_jobs/06_install_gm_debugging.sh b/src/system_patch_jobs/06_install_gm_debugging.sh new file mode 100644 index 0000000..fba9bf0 --- /dev/null +++ b/src/system_patch_jobs/06_install_gm_debugging.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ ! -f "/PRE_GM_DEBUGGING_FEATURES_ENABLED__REMOVE_AT_GMC" ] ; then + log "Creating the debugging flag file" + make_mutable "/PRE_GM_DEBUGGING_FEATURES_ENABLED__REMOVE_AT_GMC" + rm -rf "/PRE_GM_DEBUGGING_FEATURES_ENABLED__REMOVE_AT_GMC" + touch "/PRE_GM_DEBUGGING_FEATURES_ENABLED__REMOVE_AT_GMC" + make_immutable "/PRE_GM_DEBUGGING_FEATURES_ENABLED__REMOVE_AT_GMC" +fi \ No newline at end of file diff --git a/src/system_patch_jobs/06_remount_mntus_exec.sh b/src/system_patch_jobs/06_remount_mntus_exec.sh deleted file mode 100644 index 2210f06..0000000 --- a/src/system_patch_jobs/06_remount_mntus_exec.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh - -if [ $ROOTLESS -eq 0 ]; then # On rootful systems, we can just make the flag - if [ ! -f "/MNTUS_EXEC" ] ; then - log "Creating the mntus exec flag file" - make_mutable "/MNTUS_EXEC" - rm -rf "/MNTUS_EXEC" - touch "/MNTUS_EXEC" - make_immutable "/MNTUS_EXEC" - fi -else - if [ $MANPATCH -eq 1 ]; then # On rootless, doing this on the first run may cause some issues with jailbreaks that use /mnt/us so leave it for the manual MANPATCH. - # check if we are already exec or not - if grep ' /mnt/us ' /proc/self/mountinfo | grep -q noexec; then - if /usr/bin/fuser -m /mnt/us >/dev/null 2>&1; then - /usr/bin/fuser -km /mnt/us # kill everything touching /mnt/us, doesn't kill framework when ran via the MANPATCH method - fi - /usr/bin/fusermount -u /mnt/us # we can't use /bin/umount for this because fuse sucks - log "Remounting /mnt/us as exec" - if ! /bin/mount -o rw,exec /mnt/us; then - log "Failed to remount as exec trying again" - sleep 1 - if ! /bin/mount -o rw,exec /mnt/us; then - log "Failed to remount as exec, trying again" - sleep 1 - if ! /bin/mount -o rw,exec /mnt/us; then - log "Failed to remount as exec, trying again" - sleep 1 - if ! /bin/mount -o rw,exec /mnt/us; then - log "Failed to remount as exec after 4 attempts." - fi - fi - fi - fi - fi - fi -fi diff --git a/src/system_patch_jobs/07_install_kmc_upstart.sh b/src/system_patch_jobs/07_install_kmc_upstart.sh deleted file mode 100644 index 306e07a..0000000 --- a/src/system_patch_jobs/07_install_kmc_upstart.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -if [ $ROOTLESS -eq 0 ]; then - # Check if we need to do something with the KMC jobs - if [ -f "/var/local/kmc/system_patches/emergency.conf" ] ; then - if [ -f "/etc/upstart/kmc.conf" ]; then - make_mutable "/etc/upstart/kmc.conf" - rm -rf "/etc/upstart/kmc.conf" # Kill the old kmc.conf - fi - if [ ! -f "/etc/upstart/emergency.conf" ] ; then - make_mutable "/etc/upstart/emergency.conf" - rm -rf "/etc/upstart/emergency.conf" - cp -f "/var/local/kmc/system_patches/emergency.conf" "/etc/upstart/emergency.conf" - chmod 0664 "/etc/upstart/emergency.conf" - make_immutable "/etc/upstart/emergency.conf" - fi - if [ ! -f "/etc/upstart/run_patch.conf" ] ; then - make_mutable "/etc/upstart/run_patch.conf" - rm -rf "/etc/upstart/run_patch.conf" - cp -f "/var/local/kmc/system_patches/run_patch.conf" "/etc/upstart/run_patch.conf" - chmod 0664 "/etc/upstart/run_patch.conf" - make_immutable "/etc/upstart/run_patch.conf" - fi - fi -fi \ No newline at end of file diff --git a/src/system_patch_jobs/07_install_mntus_exec.sh b/src/system_patch_jobs/07_install_mntus_exec.sh new file mode 100644 index 0000000..1e8548f --- /dev/null +++ b/src/system_patch_jobs/07_install_mntus_exec.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ ! -f "/MNTUS_EXEC" ] ; then + log "Creating the mntus exec flag file" + make_mutable "/MNTUS_EXEC" + rm -rf "/MNTUS_EXEC" + touch "/MNTUS_EXEC" + make_immutable "/MNTUS_EXEC" +fi \ No newline at end of file diff --git a/src/system_patch_jobs/08_install_kmc_upstart.sh b/src/system_patch_jobs/08_install_kmc_upstart.sh new file mode 100644 index 0000000..ac33d1c --- /dev/null +++ b/src/system_patch_jobs/08_install_kmc_upstart.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Check if we need to do something with the KMC job +if [ -f "/var/local/kmc/system_patches/kmc.conf" ] ; then + if [ ! -f "/etc/upstart/kmc.conf" ] ; then + make_mutable "/etc/upstart/kmc.conf" + rm -rf "/etc/upstart/kmc.conf" + cp -f "/var/local/kmc/system_patches/kmc.conf" "/etc/upstart/kmc.conf" + chmod 0664 "/etc/upstart/kmc.conf" + make_immutable "/etc/upstart/kmc.conf" + fi +fi \ No newline at end of file diff --git a/src/system_patch_jobs/08_patch_json_files.sh b/src/system_patch_jobs/08_patch_json_files.sh deleted file mode 100644 index 654820d..0000000 --- a/src/system_patch_jobs/08_patch_json_files.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -command_jsons="/app/kpp_app_cmds.json /usr/share/app/kpp_sys_cmds.json /usr/share/webkit-1.0/pillow/debug_cmds.json" -patch_bin="/var/local/kmc/bin/kmc_system_patcher" - -for filepath in $command_jsons; do - if [ ! -f "$filepath" ]; then - log "$filepath does not exist, skipping" - continue - fi - make_mutable $filepath - if [ $ROOTLESS -eq 1 ]; then - file_size=$(du -sk "$filepath" | cut -f1) - if [ "$file_size" -gt "$MAX_COPY_SIZE" ]; then # if this somehow happens, we have bigger things to worry about - log "$filepath is too large to be patched, skipping" - continue - fi - if ! setup_bind_mount "$filepath" > /dev/null; then - log "Could not bind mount $filepath, skipping" - continue - fi - fi - log "$($patch_bin "$filepath")" - make_immutable $filepath -done \ No newline at end of file diff --git a/src/system_patch_jobs/09_ota_block.sh b/src/system_patch_jobs/09_ota_block.sh deleted file mode 100644 index e7f982e..0000000 --- a/src/system_patch_jobs/09_ota_block.sh +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/sh -# Credit to scam.net for a large portion of this file -log "Stopping OTA" - -stop ota-update -stop otaupd -stop otav3 - -# Kill them asap -killall otaupd -s SIGKILL s -killall otav3 -s SIGKILL s - -# If the binaries were renamed with the old method, restore them. -if [ $ROOTLESS -eq 0 ]; then - if [ -f /usr/bin/otaupd.bck ]; then - log "Restoring previously renamed OTA binaries" - make_mutable /usr/bin/otaupd.bck - mv /usr/bin/otaupd.bck /usr/bin/otaupd - fi - - if [ -f /usr/bin/otav3.bck ]; then - make_mutable /usr/bin/otav3.bck - mv /usr/bin/otav3.bck /usr/bin/otav3 - fi -fi - -ota_block_file_message="DO NOT REMOVE - OTA Update Blocker" -ota_block_file_message_hash="aa3b1f5cc508e957f26de725c4b8a46a" - -if [ -d /mnt/userstore ]; then - ota_block_file="/mnt/userstore/update.bin.tmp.partial" -else - ota_block_file="/mnt/us/update.bin.tmp.partial" -fi - -check_mount() { - [ "${ota_block_file}" != "/mnt/us/update.bin.tmp.partial" ] && return 0 # Return 0 if this is somehow called while the OTA block file is mntus - - if ! cut -d' ' -f5 /proc/self/mountinfo | grep -xq "/mnt/us/update.bin.tmp.partial"; then - return 1 - else - return 0 - fi -} - -check_ota_block_file() { - if [ ! -f "${ota_block_file}" ]; then - return 1 - fi # File disappeared somehow, bad. - if [ "${ota_block_file}" == "/mnt/us/update.bin.tmp.partial" ]; then # We have to check each file in different ways, because you can't use lsattr on a fuse mount. - check_mount || return 2 # Not mounted, bad. - elif [ "${ota_block_file}" == "/mnt/userstore/update.bin.tmp.partial" ]; then - check_immutable "${ota_block_file}" || return 2 # File mutable, bad. - fi - [ "$(md5sum "${ota_block_file}" | cut -d' ' -f1)" != "${ota_block_file_message_hash}" ] && return 3 # If the other two didn't return anything bad, run this. - return 0 -} - -write_ota_block_file() { - if [ "${ota_block_file}" == "/mnt/us/update.bin.tmp.partial" ]; then - log "Writing OTA block file to ${ota_block_file}" - if [ ! "$(md5sum "${ota_block_file}" | cut -d' ' -f1)" != "${ota_block_file_message_hash}" ]; then # all we really care about rn is the hash - log "Update file detected, removing" - rm -f "${ota_block_file}" - fi - touch "${ota_block_file}" - make_immutable "/var/local/kmc/block_ota" - /bin/umount "${ota_block_file}" # we HAVE to do this in case we're unpacking the new kmc/block_ota over an OLD kmc/block_ota, in which case the bind mount will resolve to an empty file - /bin/mount -o bind "/var/local/kmc/block_ota" "/mnt/us/update.bin.tmp.partial" - else - log "Writing OTA block file to ${ota_block_file}" - if [ -f "${ota_block_file}" ]; then - # Make existing file mutable - make_mutable "${ota_block_file}" - fi - echo -n "${ota_block_file_message}" > "${ota_block_file}" - make_immutable "${ota_block_file}" - fi -} - -stop ota-update -stop otaupd -stop otav3 - -# Kill them asap -killall otaupd -s SIGKILL s -killall otav3 -s SIGKILL s - -log "Blocking OTA" - -if check_ota_block_file; then - log "OTA Blocking already in place" -else - write_ota_block_file # Install the blocking file - # Check our work - check_ota_block_file - post_write_ota_block_status=$? - if [ $post_write_ota_block_status -eq 0 ]; then - log "OTA blocking file written successfully" - else - log "WRITING OTA BLOCK FILE FAILED WITH ERROR CODE ${post_write_ota_block_status}. YOUR JAILBREAK MAY BE AT RISK" - fi -fi diff --git a/src/system_patch_jobs/09_run_patch_binary.sh b/src/system_patch_jobs/09_run_patch_binary.sh new file mode 100644 index 0000000..825567d --- /dev/null +++ b/src/system_patch_jobs/09_run_patch_binary.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +log "Running KMC System Patcher" +log "$(/var/local/kmc/bin/kmc_system_patcher)" # Run our system patcher and log the output \ No newline at end of file diff --git a/src/system_patch_jobs/10_ota_rename.sh b/src/system_patch_jobs/10_ota_rename.sh new file mode 100644 index 0000000..c7be7fd --- /dev/null +++ b/src/system_patch_jobs/10_ota_rename.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +log "Stopping OTA" + +stop ota-update +stop otaupd +stop otav3 + +# Kill them asap +killall otaupd -s SIGKILL s +killall otav3 -s SIGKILL s + +log "Renaming OTA" + +if [ -f "/usr/bin/otaupd" ] ; then + log "Renaming otaupd" + make_mutable /usr/bin/otaupd + mv /usr/bin/otaupd /usr/bin/otaupd.bck +fi + +if [ -f "/usr/bin/otav3" ] ; then + log "Renaming otav3" + make_mutable /usr/bin/otav3 + mv /usr/bin/otav3 /usr/bin/otav3.bck +fi + +stop ota-update +stop otaupd +stop otav3 + +# Kill them asap +killall -s SIGKILL otaupd +killall -s SIGKILL otav3 \ No newline at end of file diff --git a/src/system_patch_jobs/10_reset_patch.sh b/src/system_patch_jobs/10_reset_patch.sh deleted file mode 100644 index 97f5d2e..0000000 --- a/src/system_patch_jobs/10_reset_patch.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -# This can probably just be turned into a bind mount -log "Patching factory reset script" - -if [ $ROOTLESS -eq 1 ]; then - dir_size=$(du -sk "/usr/sbin" | cut -f1) - if [ "$dir_size" -gt "$MAX_COPY_SIZE" ]; then - log "/usr/sbin is too large to patch the factory reset script, skipping." # usually 3.5mb, so our 5mb limit should be fine here - continue - fi - setup_bind_mount /usr/sbin -fi - -if [ $ROOTLESS -eq 0 ]; then - if [ ! -f /usr/sbin/factory_reset.bck ]; then - cp /usr/sbin/factory_reset /usr/sbin/factory_reset.bck - fi # not necessary on rootless systems -fi - -echo "#!/bin/sh" > /usr/sbin/factory_reset -echo "" >> /usr/sbin/factory_reset -echo "if [ -f /var/local/kmc/sbin/kmc_reset.sh ]; then" >> /usr/sbin/factory_reset -echo " sh /var/local/kmc/sbin/kmc_reset.sh" >> /usr/sbin/factory_reset -echo "fi" >> /usr/sbin/factory_reset -echo "" >> /usr/sbin/factory_reset -cat /usr/sbin/factory_reset.bck >> /usr/sbin/factory_reset - -make_immutable /var/local/kmc \ No newline at end of file diff --git a/src/system_patch_jobs/11_cleanup.sh b/src/system_patch_jobs/11_cleanup.sh deleted file mode 100644 index f8a5019..0000000 --- a/src/system_patch_jobs/11_cleanup.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# Remounting mntus as exec is left for a reboot/rerun, as it breaks the OTA block on non "userstore" systems -/bin/mount -o remount,ro / -make_immutable /var/local/kmc -log "Done" \ No newline at end of file diff --git a/src/system_patch_jobs/11_reset_patch.sh b/src/system_patch_jobs/11_reset_patch.sh new file mode 100644 index 0000000..840a3d8 --- /dev/null +++ b/src/system_patch_jobs/11_reset_patch.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +log "Patching factory reset script" + +if [ ! -f /usr/sbin/factory_reset.bck ]; then + cp /usr/sbin/factory_reset /usr/sbin/factory_reset.bck +fi + +echo "#!/bin/sh" > /usr/sbin/factory_reset +echo "" >> /usr/sbin/factory_reset +echo "if [ -f /var/local/kmc/sbin/kmc_reset.sh ]; then" >> /usr/sbin/factory_reset +echo " sh /var/local/kmc/sbin/kmc_reset.sh" >> /usr/sbin/factory_reset +echo "fi" >> /usr/sbin/factory_reset +echo "" >> /usr/sbin/factory_reset +cat /usr/sbin/factory_reset.bck >> /usr/sbin/factory_reset \ No newline at end of file diff --git a/src/system_patch_jobs/12_rootless_gui_restart.sh b/src/system_patch_jobs/12_rootless_gui_restart.sh deleted file mode 100644 index d2014a7..0000000 --- a/src/system_patch_jobs/12_rootless_gui_restart.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -if [ $MANPATCH -eq 1 ]; then # This is set in kmc/rootless_menu.sh, and is only ran when the user manually MANPATCHs it using "Get Started" in settings, on a rootless device - log "Restarting GUI..." # Necessary for sh_integration - sleep 2 # So they can read what's about to happen - lipc-set-prop com.lab126.appmgrd start app://com.lab126.booklet.home - lipc-set-prop com.lab126.appmgrd start app://com.lab126.KPPMainApp?view=KPP_HOME - if [ -f "/etc/upstart/kppmainapp.conf" ] ; then - log "Restart strategy 1" - restart lab126_gui & - sleep 3 # Wait for it to stop - elif [ -f "/etc/upstart/acxe.conf" ] ; then - log "Restart strategy 2" - restart acxe & # On older devices restart the entire gui - sleep 3 # Wait for it to stop - else - log "Restart strategy 3" - telinit 5 & - sleep 3 # Wait for it to stop - fi - /usr/sbin/eips -c # Helpapp likes to be stubborn at times - /var/local/kmc/bin/fbink -y 3 -m -S 7 "Restarting GUI" - /var/local/kmc/bin/fbink -y 4 -m -S 7 "Please Wait..." - /var/local/kmc/bin/fbink -y 16 -p -S 3 "(Kindles are slow lol) " - /var/local/kmc/bin/fbink -y -6 -m -S 4 "(Error dialog is fine)" - /var/local/kmc/bin/fbink -y -25 -m -S 4 "If you'd like to access the help menu, make an empty file named" - /var/local/kmc/bin/fbink -y -22 -m -S 4 "ACCESS_HELPAPP" - /var/local/kmc/bin/fbink -y -20 -m -S 4 "in the USB root of your Kindle!" - /var/local/kmc/bin/fbink -y -5 -m -S 4 "(Just press close and keep waiting!)" -fi \ No newline at end of file diff --git a/system_patcher/main.c b/system_patcher/main.c index 38903fb..75e8f0d 100644 --- a/system_patcher/main.c +++ b/system_patcher/main.c @@ -6,39 +6,50 @@ int main(int argc, char* argv[]) { - for (int i=1; i < argc; i++) + char* filepaths[] = { + "/app/kpp_app_cmds.json", + "/usr/share/app/kpp_sys_cmds.json", + "/usr/share/webkit-1.0/pillow/debug_cmds.json", + NULL + }; + + for (int i=0; filepaths[i] != NULL; i++) { - printf("Patching '%s'...\n", argv[i]); + printf("Patching '%s'...\n", filepaths[i]); + if (access(filepaths[i], R_OK) != 0) + { + printf("Could not access '%s'\n", filepaths[i]); + continue; + } - FILE* file = fopen(argv[i], "r+"); + FILE* file = fopen(filepaths[i], "r+"); if (file == NULL) { - printf("Could not open '%s'\n", argv[i]); + printf("Could not open '%s'\n", filepaths[i]); continue; } - - fseek(file, 0, SEEK_END); - long size = ftell(file); - fseek(file, 0, SEEK_SET); - + fseek(file, 0L, SEEK_END); + int size = ftell(file) + 1; char* buffer = malloc(size + 1); + if (buffer == NULL) { - printf("Could not allocate %ld bytes for '%s'\n", size+1, argv[i]); + printf("Could not allocate %i bytes for '%s'\n", size+1, filepaths[i]); fclose(file); continue; } - buffer[fread(buffer, 1, size, file)] = 0; + + buffer[size+1] = 0; + fseek(file, 0, SEEK_SET); + fread(buffer, 1, size, file); cJSON* json = cJSON_Parse(buffer); if (json == NULL) { printf("Could not parse JSON for file contents:\n%s\n", buffer); - free(buffer); fclose(file); continue; } - free(buffer); if (cJSON_HasObjectItem(json, ";kpm")) cJSON_DeleteItemFromObject(json, ";kpm"); @@ -50,25 +61,16 @@ int main(int argc, char* argv[]) cJSON_DeleteItemFromObject(json, ";kmclog"); cJSON_AddItemToObject(json, ";kpm", cJSON_CreateString("/var/local/kmc/sbin/kpm.sh")); - cJSON_AddItemToObject(json, ";log", cJSON_CreateString("/var/local/kmc/sbin/logThis.sh")); + cJSON_AddItemToObject(json, ";log", cJSON_CreateString("/usr/bin/logThis.sh")); cJSON_AddItemToObject(json, ";kmclog", cJSON_CreateString("/var/local/kmc/sbin/kmclog.sh")); char* patched_json = cJSON_Print(json); - cJSON_Delete(json); - if (patched_json == NULL) - { - printf("Could not serialise JSON for '%s'\n", argv[i]); - fclose(file); - continue; - } - fseek(file, 0, SEEK_SET); fwrite(patched_json, 1, strlen(patched_json), file); - fflush(file); ftruncate(fileno(file), strlen(patched_json)); - free(patched_json); fclose(file); + cJSON_Delete(json); } return 0; } \ No newline at end of file