From 586fc6a34f4265c6eae3bb70d8244af9b532a1f2 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Mon, 19 Aug 2024 20:27:16 +0200 Subject: [PATCH] Build system (pretty much) complete! (Minus Java) --- TODO.txt | 8 ++---- buildtool/build.py | 6 ++--- buildtool/task/assemble_apk.py | 17 ++++++++++++ buildtool/task/compile_smali.py | 2 +- buildtool/task/merge_resources.py | 8 ++++-- buildtool/task/sign_apk.py | 45 +++++++++++++++++++++++++++++++ buildtool/task/util.py | 4 +++ test.py | 3 --- 8 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 buildtool/task/assemble_apk.py create mode 100644 buildtool/task/sign_apk.py delete mode 100644 test.py diff --git a/TODO.txt b/TODO.txt index 61a3743..9bf0ccc 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,6 +1,2 @@ -1. Add android.jar from android sdk 35 to classpath -2. Identify tumblr apk version -3. Fix enhanced block n shit -4. ??? -5. Profit -6. Fix that bug that prevents you from opening your account settings \ No newline at end of file +Implement smali patches + migrate all smali code to patches +Implement Java stack \ No newline at end of file diff --git a/buildtool/build.py b/buildtool/build.py index 4ee3a17..36ba625 100644 --- a/buildtool/build.py +++ b/buildtool/build.py @@ -1,7 +1,5 @@ # from task.extract import extract -from task.patch_smali import patch_smali -from task.patch_resources import patch_resources -from task.merge_resources import merge_resources +from task.sign_apk import sign_apk if __name__ == '__main__': - _ = merge_resources() \ No newline at end of file + _ = sign_apk() \ No newline at end of file diff --git a/buildtool/task/assemble_apk.py b/buildtool/task/assemble_apk.py new file mode 100644 index 0000000..ccff9b8 --- /dev/null +++ b/buildtool/task/assemble_apk.py @@ -0,0 +1,17 @@ +from .util import * +from .merge_resources import merge_resources + +import subprocess + +def assemble_apk(): + updated = merge_resources() + + if not updated and Path(ASSEMBLED_APK).exists(): + print("Skipping assembly") + return False + + # Assemble + print("Assembling APK...") + _ = subprocess.run([JAVA_BIN, '-jar', APKTOOL, 'b', MERGED_RSC_DIR, '-o', ASSEMBLED_APK]) + + return True \ No newline at end of file diff --git a/buildtool/task/compile_smali.py b/buildtool/task/compile_smali.py index 78c3f10..34003dd 100644 --- a/buildtool/task/compile_smali.py +++ b/buildtool/task/compile_smali.py @@ -6,7 +6,7 @@ import re # Task dependencies from .patch_smali import patch_smali -def to_dex_name(smali_name): +def to_dex_name(smali_name: str): if smali_name == 'smali': return 'classes.dex' else: diff --git a/buildtool/task/merge_resources.py b/buildtool/task/merge_resources.py index 4703a7c..c0ec436 100644 --- a/buildtool/task/merge_resources.py +++ b/buildtool/task/merge_resources.py @@ -21,7 +21,11 @@ def merge_resources(): shutil.copytree(EXTRACTED_DIR, MERGED_RSC_DIR, ignore=shutil.ignore_patterns("smali", "smali_classes*")) first_time = True + updated = first_time + print("Merging patched resources...") - _ = fileutil.merge_into(PATCHED_RSC_DIR, MERGED_RSC_DIR, check_date=not first_time) + updated = updated or fileutil.merge_into(PATCHED_RSC_DIR, MERGED_RSC_DIR, check_date=not first_time) print("Merging dex files...") - _ = fileutil.merge_into(COMPILED_SMALI_DIR, MERGED_RSC_DIR, check_date=not first_time) + updated = updated or fileutil.merge_into(COMPILED_SMALI_DIR, MERGED_RSC_DIR, check_date=not first_time) + + return updated \ No newline at end of file diff --git a/buildtool/task/sign_apk.py b/buildtool/task/sign_apk.py new file mode 100644 index 0000000..13b5f2a --- /dev/null +++ b/buildtool/task/sign_apk.py @@ -0,0 +1,45 @@ +import shutil +import sys +import subprocess + +from .util import * +from .assemble_apk import assemble_apk + +def align_apk(): + updated = assemble_apk() + + if not updated and Path(ALIGNED_APK).exists(): + print("Skipping alignment") + return False + + # Align the APK + print("Aligning APK...") + ALIGNED_APK.parent.mkdir(exist_ok=True) + _ = subprocess.run([ZIPALIGN, '-pvf', '4', ASSEMBLED_APK, ALIGNED_APK]) + +def sign_apk(): + updated = align_apk() + + # Check what kind of signing the user wants us to do + arg = sys.argv[1] if len(sys.argv) > 1 else '' + if 'd' in arg: + keystore_params = ['--ks', 'keystores/debug.keystore', '--ks-pass', 'pass:123456'] + signed_apk = SIGNED_APK_DEBUG + elif 'r' in arg: + keystore_params = ['--ks', 'keystores/debug.keystore',] + signed_apk = SIGNED_APK + else: + print("WARNING: Neither 'r' (release) nor 'd' (debug) was specified for the second parameter so the aligned apk will not be signed.") + print("STOP.") + exit(0) + + if not updated and Path(signed_apk).exists(): + print("Skipping signing") + return False + + + # Sign the APK + print("Signing APK...") + shutil.copy(ALIGNED_APK, signed_apk) + SIGNED_APK.parent.mkdir(exist_ok=True) + _ = subprocess.run([JAVA_BIN, '-jar', APKSIGNER, 'sign', *keystore_params, signed_apk]) \ No newline at end of file diff --git a/buildtool/task/util.py b/buildtool/task/util.py index 63a466a..bcee140 100644 --- a/buildtool/task/util.py +++ b/buildtool/task/util.py @@ -18,6 +18,10 @@ PATCHED_RSC_DIR = BUILD_DIR / "patched_resources" PATCHED_SMALI_DIR = BUILD_DIR / "patched_smali" MERGED_RSC_DIR = BUILD_DIR / "merged_resources" COMPILED_SMALI_DIR = BUILD_DIR / "compiled_smali" +ASSEMBLED_APK = BUILD_DIR / "assembled_apk" / "tumblr-ykit.apk" +ALIGNED_APK = BUILD_DIR / "signed_apk" / "tumblr-ykit_aligned.apk" +SIGNED_APK = BUILD_DIR / "signed_apk" / "tumblr-ykit.apk" +SIGNED_APK_DEBUG = BUILD_DIR / "signed_apk" / "tumblr-ykit_debug.apk" SRC_DIR = Path("src") SRC_RESOURCES_DIR = SRC_DIR / "resources" diff --git a/test.py b/test.py deleted file mode 100644 index 358aa9a..0000000 --- a/test.py +++ /dev/null @@ -1,3 +0,0 @@ -from buildtool.polly.patcher import process_patch_file - -process_patch_file('src/patches/public.patch', check_date=True) \ No newline at end of file