Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/build
/cache
.vscode
.vscode
34 changes: 1 addition & 33 deletions src/helpers/00_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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}"
}
10 changes: 1 addition & 9 deletions src/jb_sh_jobs/04_setup_kmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)"
Expand Down
9 changes: 7 additions & 2 deletions src/jb_sh_jobs/06_patch_system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/kmc/block_ota

This file was deleted.

7 changes: 0 additions & 7 deletions src/kmc/rootless_menu.sh

This file was deleted.

5 changes: 0 additions & 5 deletions src/kmc/sql/appreg_register_rootless_persist.sql

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"

Expand All @@ -25,6 +26,6 @@ pre-start script
fi

f_log I bridge start "" "so uncivilized"

return 0
end script
14 changes: 0 additions & 14 deletions src/kmc/system_patches/run_patch.conf

This file was deleted.

6 changes: 1 addition & 5 deletions src/kmc/system_patches/run_patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/var/local/kmc/${PLATFORM}/bin/su -c "sh /var/local/kmc/system_patches/patch_system.sh"
6 changes: 1 addition & 5 deletions src/system_patch_jobs/00_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
log ""
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
#!/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
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
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"
fi
96 changes: 47 additions & 49 deletions src/system_patch_jobs/02_install_update_keys.sh
Original file line number Diff line number Diff line change
@@ -1,65 +1,63 @@
#!/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
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
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
11 changes: 4 additions & 7 deletions src/system_patch_jobs/03_setup_kmc.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions src/system_patch_jobs/04_install_mkk_kindlet_jb.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 0 additions & 10 deletions src/system_patch_jobs/05_install_gm_debugging.sh

This file was deleted.

Loading
Loading