Skip to content

Instantly share code, notes, and snippets.

@Teutates
Last active March 30, 2024 08:22
Show Gist options
  • Save Teutates/ee52995cee1e6a6ee5a5c61466471b1f to your computer and use it in GitHub Desktop.
Save Teutates/ee52995cee1e6a6ee5a5c61466471b1f to your computer and use it in GitHub Desktop.
Rootless Repacker
#!/bin/sh
### Procursus 2
### INFO: Repacks deb as rootless with iphoneos-arm64 arch, moves legacy tweak dir to
### new directory, and resigns. Does not do any further modification.
set -e
if ! type dpkg-deb >/dev/null 2>&1; then
echo "Please install dpkg-deb."
fi
if ! type file >/dev/null 2>&1; then
echo "Please install file."
fi
if ! type fakeroot >/dev/null 2>&1; then
echo "Please install fakeroot."
fi
if ! ldid 2>&1 | grep -q procursus; then
echo "Please install Procursus ldid."
fi
LDID="ldid -Hsha256"
if [ -z "$1" ] || ! file "$1" | grep -q "Debian binary package" ; then
echo "Usage: $0 [/path/to/deb]"
exit 1;
fi
echo "Creating workspace"
TEMPDIR_OLD="$(mktemp -d)"
TEMPDIR_NEW="$(mktemp -d)"
if [ ! -d "$TEMPDIR_OLD" ] || [ ! -d "$TEMPDIR_NEW" ]; then
echo "Creating temporary directories failed."
exit 1;
fi
### Real script start
dpkg-deb -R "$1" "$TEMPDIR_OLD"
if [ -d "$TEMPDIR_OLD/var/jb" ]; then
echo "Deb already rootless. Skipping and exiting cleanly."
rm -rf "$TEMPDIR_OLD" "$TEMPDIR_NEW"
exit 0;
fi
mkdir -p "$TEMPDIR_NEW"/var/jb
cp -a "$TEMPDIR_OLD"/DEBIAN "$TEMPDIR_NEW"
sed 's|iphoneos-arm|iphoneos-arm64|' < "$TEMPDIR_OLD"/DEBIAN/control > "$TEMPDIR_NEW"/DEBIAN/control
rm -rf "$TEMPDIR_OLD"/DEBIAN
mv -f "$TEMPDIR_OLD"/.* "$TEMPDIR_OLD"/* "$TEMPDIR_NEW"/var/jb >/dev/null 2>&1 || true
if [ -d "$TEMPDIR_NEW/var/jb/Library/MobileSubstrate/DynamicLibraries" ]; then
mkdir -p "$TEMPDIR_NEW/var/jb/usr/lib"
mv "$TEMPDIR_NEW/var/jb/Library/MobileSubstrate/DynamicLibraries" "$TEMPDIR_NEW/var/jb/usr/lib/TweakInject"
fi
find "$TEMPDIR_NEW" -type f | while read -r file; do
if file -ib "$file" | grep -q "x-mach-binary; charset=binary"; then
echo "$file"
INSTALL_NAME=$(otool -D "$file" | grep -v -e ":$" -e "^Archive :" | head -n1)
otool -L "$file" | tail -n +2 | grep /usr/lib/'[^/]'\*.dylib | cut -d' ' -f1 | tr -d "[:blank:]" > "$TEMPDIR_OLD"/._lib_cache
if [ -n "$INSTALL_NAME" ]; then
install_name_tool -id @rpath/"$(basename "$INSTALL_NAME")" "$file" >/dev/null 2>&1
fi
if otool -L "$file" | grep -q CydiaSubstrate; then
install_name_tool -change /Library/Frameworks/CydiaSubstrate.framework/CydiaSubstrate @rpath/libsubstrate.dylib "$file" >/dev/null 2>&1
fi
if [ -f "$TEMPDIR_OLD"/._lib_cache ]; then
cat "$TEMPDIR_OLD"/._lib_cache | while read line; do
install_name_tool -change "$line" @rpath/"$(basename "$line")" "$file" >/dev/null 2>&1
done
fi
install_name_tool -add_rpath "/usr/lib" "$file" >/dev/null 2>&1
install_name_tool -add_rpath "/var/jb/usr/lib" "$file" >/dev/null 2>&1
$LDID -s "$file"
fi
done
fakeroot dpkg-deb -b "$TEMPDIR_NEW" "$(pwd)"/"$(grep Package: "$TEMPDIR_NEW"/DEBIAN/control | cut -f2 -d ' ')"_"$(grep Version: "$TEMPDIR_NEW"/DEBIAN/control | cut -f2 -d ' ')"_"$(grep Architecture: "$TEMPDIR_NEW"/DEBIAN/control | cut -f2 -d ' ')".deb
### Real script end
echo "Cleaning up"
rm -rf "$TEMPDIR_OLD" "$TEMPDIR_NEW"
@rainbowcardiod
Copy link

I had to remove dependency from org.swift.libswift from the control file.
With palera1n rootless, theos installed on the phone with install-theos and tutorial, using "swift" package of Sileo, with this patch on your script it works:

54c56
< sed 's|iphoneos-arm|iphoneos-arm64|' < "$TEMPDIR_OLD"/DEBIAN/control > "$TEMPDIR_NEW"/DEBIAN/control
---
> sed -e 's|iphoneos-arm|iphoneos-arm64|' -e 's/Depends:\(.*\)org.swift.libswift/Depends:\1swift/' < "$TEMPDIR_OLD"/DEBIAN/control > "$TEMPDIR_NEW"/DEBIAN/control

@masckmaster2007
Copy link

any way to make it work with x86_64 linux OSes? I'm stuck at the 64-85 part. I have ldid and somehow install_name_tool built for this arch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment