Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Al4ise committed Jan 7, 2022
1 parent e99e14d commit e7cf7df
Showing 1 changed file with 74 additions and 117 deletions.
191 changes: 74 additions & 117 deletions azule
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,8 @@ while getopts an:i:o:c:b:x:f:d:p:huSewsrqjmzlv args; do
fi

# iOS ONLY
if [[ "$args" == @(a|x|l|m|z|j) ]]; then
if [ "$os" != "iOS" ]; then
Announce "-$args is not supported on your platform" 6
fi
if [[ "$args" == @(a|x|l|m|z|j) && "$os" != "iOS" ]]; then
Announce "-$args is not supported on your platform" 6
fi

case "$args" in
Expand All @@ -269,7 +267,7 @@ while getopts an:i:o:c:b:x:f:d:p:huSewsrqjmzlv args; do

# SWITCHES
u) remove_uisd=1 && run=1 ;;
v) verbose="-v" ;;
v) verbose=1 ;;
e) remove_extensions=1 && run=1 ;;
w) remove_watchapp=1 && run=1 ;;
S) fakesign=1 && run=1 ;;
Expand All @@ -288,56 +286,40 @@ while getopts an:i:o:c:b:x:f:d:p:huSewsrqjmzlv args; do
esac
done

# READING IPA
if [ -z "$ipadir" ]; then while
printf '[*] Path to IPA: '
read -r tmp
ipadir="$(eval echo "$tmp")"
[ -z "$ipadir" ] && Announce "No iPA Specified"
do true; done; fi
# VARIABLE CHECK
if [[ -z "$outdir" || -z "$ipadir" ]] || { [ -z "$run" ] && [[ "$os" != "iOS" || -e "$ipadir" ]]; }; then help; fi

# CREATING .TMP DIRECTORIES
dir="$(mktemp -d)"

tweakid="$RANDOM"
mkdir -p "$dir/$tweakid/Tweak"
Verbose "Temporary Directory $dir/$tweakid/Tweak has been created" "Couldn't create Temporary Directory" 10 -v

cd "$dir/$tweakid" || exit

if [ ! -e "$ipadir" ]; then
if [ "$os" != "iOS" ]; then
Announce "Invalid iPA" 7
else
Announce "Checking for App Updates..."

# CHECK IF APP IS INSTALLED
while read -r i; do
if [ "$(ExtractPlistValue MCMMetadataIdentifier "$i")" = "$ipadir" ]; then
info_plist="$(find "$(dirname "$i")"/*.app/ -maxdepth 1 -name Info.plist)"
thinned="$(ExtractPlistValue variantID "$(dirname "$i")/iTunesMetadata.plist")"
break
fi
done < <(find /var/containers/Bundle/Application -name .com.apple.mobile_container_manager.metadata.plist)
Announce "Checking for App Updates..."

# CHECK IF APP IS OUTDATED
if ! curl -I google.com &>/dev/null; then Announce "No Connection to the Internet" 26; fi
latestv="$(curl -s "http://itunes.apple.com/lookup?bundleId=$ipadir" | jq -r '.results[].version')"
currentv="$(ExtractPlistValue CFBundleShortVersionString "$info_plist")"

if [ -z "$latestv" ] && [ -z "$currentv" ]; then
Announce "Invalid App" 8
# CHECK IF APP IS INSTALLED
while read -r i; do
if [ "$(ExtractPlistValue MCMMetadataIdentifier "$i")" = "$ipadir" ]; then
info_plist="$(find "$(dirname "$i")"/*.app/ -maxdepth 1 -name Info.plist)"
thinned="$(ExtractPlistValue variantID "$(dirname "$i")/iTunesMetadata.plist")"
break
fi
done < <(find /var/containers/Bundle/Application -name .com.apple.mobile_container_manager.metadata.plist)

if [ -n "$latestv" ] && [[ "$latestv" != "$currentv" || -n "$thinned" ]]; then
if [ -z "$ignore_outdated" ]; then
Announce "Update Available"
outdated=1
fi
fi
# CHECK IF APP IS OUTDATED
if ! curl -I google.com &>/dev/null; then Announce "No Connection to the Internet" 26; fi
latestv="$(curl -s "http://itunes.apple.com/lookup?bundleId=$ipadir" | jq -r '.results[].version')"
currentv="$(ExtractPlistValue CFBundleShortVersionString "$info_plist")"

if [ -n "$outdated" ]; then
if [ -z "$latestv" ] && [ -z "$currentv" ]; then
Announce "Invalid App" 8
fi

if [ -n "$outdated" ] || { [ -n "$latestv" ] && [[ "$latestv" != "$currentv" || -n "$thinned" ]]; }; then
if [ -z "$ignore_outdated" ]; then
Announce "Update Available"
# VARIABLE CHECK
if [ -z "$appleid" ]; then while
printf '[*] Apple ID: '
Expand All @@ -357,93 +339,71 @@ if [ ! -e "$ipadir" ]; then
Announce "Installing $(basename "$dir/$tweakid"/*.ipa) ..."
appinst "$dir/$tweakid"/*.ipa &>/dev/null
Announce "Installed $(basename "$dir/$tweakid"/*.ipa)"
else
Announce "No Updates Available"
fi
else
Announce "No Updates Available"
fi
fi

# VARIABLE CHECK
if [ -z "$run" ] && [ -e "$ipadir" ]; then
Announce "Insufficient Arguements"
Announce "Run "azule -h" for usage instructions" 27
fi
# DECRYPTION: GET MAIN INFO.PLIST
while read -r i; do
if [ "$(ExtractPlistValue MCMMetadataIdentifier "$i")" = "$ipadir" ]; then
bfplist="$(find "$(dirname "$i")"/*.app/ -maxdepth 1 -name Info.plist)"
break
fi
done < <(find /var/containers/Bundle/Application -name .com.apple.mobile_container_manager.metadata.plist)

# READING OUTPUT DIRECTORY
if [ -z "$outdir" ]; then while
printf '[*] Output Directory: '
read -r outdir
[ -z "$outdir" ] && Announce "No Output Directory Specified"
do true; done; fi
# DECRYPT
mkdir -p Payload
appname="$(basename "$(dirname "$bfplist")")"

while read -r i; do
CFBundleExecutable="$(ExtractPlistValue CFBundleExecutable "$i")"
DTPlatformName="$(ExtractPlistValue DTPlatformName "$i")"
if [ -n "$CFBundleExecutable" ] && [ -e "$(dirname "$i")/$CFBundleExecutable" ] && otool -l "$(dirname "$i")/$CFBundleExecutable" | grep -q 'cryptid 1' && [ "$DTPlatformName" != "watchos" ]; then
if [ -z "$status" ]; then
Announce "Decrypting App..."
fi
mkdir -p "Payload/$(dirname "$i" | sed "s|^.*$appname|$appname|")"
flexdecrypt "$(dirname "$i")/$CFBundleExecutable" --output "Payload/$(dirname "$i" | sed "s|^.*$appname|$appname|")/$CFBundleExecutable" &>/dev/null
Verbose "Decrypted $CFBundleExecutable" "Couldn't Decrypt $CFBundleExecutable" -v
status=0
fi
done < <(find "$(dirname "$bfplist")" -name "Info.plist")

rsync --ignore-existing -a "$(dirname "$bfplist")" Payload
Verbose "Finished Decryption" "App Was Not Encrypted" -x

elif [ -n "$run" ]; then
# EXTRACTING IPA
Announce "Extracting iPA..."
unzip -q "$ipadir" -d "$dir/$tweakid"
Verbose "IPA extracted" "Couldn't extract IPA" 11
fi

# SETTING OUTPUT DIRECTORY AND NAME
outdir="$(eval echo "$outdir" | sed "s|\.|$rootdir|")"
if [ "${outdir: -4}" == ".ipa" ]; then
output="$outdir"
else
if ! [ "${outdir: -4}" == ".ipa" ]; then
if [ -z "$name" ]; then
name="$(basename "$ipadir" .ipa)"
for i in "${files[@]}"; do
name+="+$(basename "$i")"
done
fi
output="$outdir/$name.ipa"
outdir="$outdir/$name.ipa"
fi

# SHORTEN OUTPUT NAME IF NEEDED
if [[ ${#output} -gt 264 ]]; then
output="${output::${#output}-4}"
characters_to_remove=$(( ${#output} - 264 ))
output="${output::${#output}-$characters_to_remove}.ipa"
if [[ ${#outdir} -gt 264 ]]; then
outdir="${outdir::${#outdir}-4}"
characters_to_remove=$(( ${#outdir} - 264 ))
outdir="${outdir::${#outdir}-$characters_to_remove}.ipa"
Announce "Shortened File Name"
fi

# CREATING OUTPUT DIRECTORY
mkdir -p "$(dirname "$output")"
test -w "$(dirname "$output")"
Verbose "iPA will be written to $output" "$output is an invalid output path" 9 -v

# DECRYPTION
if [ ! -e "$ipadir" ]; then

# GET MAIN INFO.PLIST
while read -r i; do
if [ "$(ExtractPlistValue MCMMetadataIdentifier "$i")" = "$ipadir" ]; then
bfplist="$(find "$(dirname "$i")"/*.app/ -maxdepth 1 -name Info.plist)"
break
fi
done < <(find /var/containers/Bundle/Application -name .com.apple.mobile_container_manager.metadata.plist)

# DECRYPT
if [ -n "$bfplist" ]; then
mkdir -p Payload
appname="$(basename "$(dirname "$bfplist")")"

while read -r i; do
CFBundleExecutable="$(ExtractPlistValue CFBundleExecutable "$i")"
DTPlatformName="$(ExtractPlistValue DTPlatformName "$i")"
if [ -n "$CFBundleExecutable" ] && [ -e "$(dirname "$i")/$CFBundleExecutable" ] && otool -l "$(dirname "$i")/$CFBundleExecutable" | grep -q 'cryptid 1' && [ "$DTPlatformName" != "watchos" ]; then
if [ -z "$status" ]; then
Announce "Decrypting App..."
fi
mkdir -p "Payload/$(dirname "$i" | sed "s|^.*$appname|$appname|")"
flexdecrypt "$(dirname "$i")/$CFBundleExecutable" --output "Payload/$(dirname "$i" | sed "s|^.*$appname|$appname|")/$CFBundleExecutable" &>/dev/null
Verbose "Decrypted $CFBundleExecutable" "Couldn't Decrypt $CFBundleExecutable" -v
status=0
fi
done < <(find "$(dirname "$bfplist")" -name "Info.plist")

rsync --ignore-existing -a "$(dirname "$bfplist")" Payload
Verbose "Finished Decryption" "App Was Not Encrypted" -x
fi
fi

# EXTRACTING IPA
if [[ -n "$run" && -z "$bfplist" ]]; then
Announce "Extracting iPA..."
unzip -q "$ipadir" -d "$dir/$tweakid"
Verbose "IPA extracted" "Couldn't extract IPA" 11
fi
mkdir -p "$(dirname "$outdir")"
test -w "$(dirname "$outdir")"
Verbose "iPA will be written to $outdir" "$outdir is an invalid output path" 9 -v

# REMOVING PLUGINS
if [ -n "$remove_extensions" ]; then
Expand All @@ -469,7 +429,6 @@ if [ -n "$remove_watchapp" ] || [ -n "$bfplist" ]; then
fi
done < <(find "$dir/$tweakid/Payload" -name "Info.plist")


if [ -n "$status" ]; then
Verbose "Removed Watch App" "Couldn't Remove Watch App" -x
else
Expand All @@ -487,10 +446,8 @@ fi
appname="$(basename Payload/*.app)"
executable="Payload/$appname/$(ExtractPlistValue CFBundleExecutable Payload/"$appname"/Info.plist)"
Verbose "App executable is $(echo "$executable" | sed "s|^.*.app/|@executable_path/|")" "Couldn't set app executable" 12 -v
rpath="$(otool -l "$executable" | grep RPATH -A2 | sed 's/.*path \(.*\)/\1/' | grep -o '^\S*' | grep "^@executable_path*" | tail -1 | sed "s|@executable_path|Payload/$appname|g"
)"
rpath="$(otool -l "$executable" | grep RPATH -A2 | sed 's/.*path \(.*\)/\1/' | grep -o '^\S*' | grep "^@executable_path*" | tail -1 | sed "s|@executable_path|Payload/$appname|g")"
Verbose "App rpath is $(echo "$rpath" | sed "s|^.*.app/|@executable_path/|")" "Couldn't set app rpath" 13 -v

mkdir -p "$rpath"

# ENCRYPTION CHECK
Expand Down Expand Up @@ -818,17 +775,17 @@ if [ -n "$fakesign" ]; then
fi

# CLEANING UP OUTDIR
if [ -e "$output" ]; then
rm -rf "$output"
if [ -e "$outdir" ]; then
rm -rf "$outdir"
fi

# GENERATING IPA
if [ -n "$run" ] || [ -n "$bfplist" ]; then
Announce "Generating iPA..."
zip -rq "$output" Payload
zip -rq "$outdir" Payload
status="$?"
else
mv "$ipadir" "$output"
mv "$ipadir" "$outdir"
status="$?"
fi
Verbose "Generated IPA at $output" "Couldn't generate IPA" 25 -x
Verbose "Generated IPA at $outdir" "Couldn't generate IPA" 25 -x

0 comments on commit e7cf7df

Please sign in to comment.