More work on the patching system

This commit is contained in:
maelstrom 2024-08-17 22:16:36 +02:00
parent 8a7b95beee
commit 7229e518d3
11 changed files with 82 additions and 20 deletions

View file

@ -1,5 +1,7 @@
# 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
if __name__ == '__main__':
_ = patch_resources()
_ = merge_resources()

View file

@ -57,6 +57,9 @@ def process_patch_file(patch_file: str, check_date: bool = True):
i2["pos"] += len(insertion["content"])
# Make parent dirs
target_dest.parent.mkdir(parents=True, exist_ok=True)
# Write the changed output
with open(target_dest, 'w') as f:
f.write(src)
@ -64,8 +67,6 @@ def process_patch_file(patch_file: str, check_date: bool = True):
def process_all_patches(dir: Path | str, check_date: bool = True):
dir = Path(dir)
for (cd, _, files) in dir.walk():
for f in files:
if f.endswith(".patch"):
print("Processing patch {}".format((cd / f).relative_to(dir)))
process_patch_file(str(cd / f), check_date=check_date)
for patch_file in dir.rglob("*.patch"):
print("Processing patch {}".format(patch_file.relative_to(dir)))
process_patch_file(str(patch_file), check_date=check_date)

View file

@ -0,0 +1,27 @@
from .util import *
from . import fileutil
import shutil
# Task dependencies
from .patch_resources import patch_resources
from .patch_smali import patch_smali
# Merges resources from all the previous steps
def merge_resources():
_ = patch_resources()
_ = patch_smali()
first_time = False
# Copy original resources only the first time
if not MERGED_RSC_DIR.exists():
print("Merging original resources...")
shutil.copytree(EXTRACTED_DIR, MERGED_RSC_DIR, ignore=shutil.ignore_patterns("smali*"))
first_time = True
print("Merging patched resources...")
_ = fileutil.merge_into(PATCHED_RSC_DIR, MERGED_RSC_DIR, check_date=not first_time)
print("Merging patched smali...")
_ = fileutil.merge_into(PATCHED_SMALI_DIR, MERGED_RSC_DIR, check_date=not first_time)

View file

@ -1,8 +1,6 @@
from .util import *
from . import fileutil
import shutil
from polly.patcher import process_all_patches
# Task dependencies
@ -11,19 +9,13 @@ from .extract import extract
def patch_resources():
_ = extract()
first_time = False
# Previously, we populated patched_resources with original resources too, now that is covered in the merge_resources step
# Copy original resources only the first time
if not PATCHED_RSC_DIR.exists():
print("Copying original resources...")
shutil.copytree(EXTRACTED_DIR, PATCHED_RSC_DIR, ignore=shutil.ignore_patterns("smali*"))
first_time = True
s = fileutil.merge_into(SRC_RESOURCES_DIR, PATCHED_RSC_DIR, check_date=not first_time)
s = fileutil.merge_into(SRC_RESOURCES_DIR, PATCHED_RSC_DIR)
if s:
print("Copied custom resources from src/resources")
else:
print("Skipped copying resources from src/resources")
# Patch other resources
process_all_patches(SRC_PATCHES_DIR, check_date=not first_time)
process_all_patches(SRC_RESOURCE_PATCHES_DIR)

View file

@ -0,0 +1,30 @@
from .util import *
from . import fileutil
import shutil
from polly.patcher import process_all_patches
# Task dependencies
from .extract import extract
def patch_smali():
_ = extract()
first_time = False
# Copy original resources only the first time
if not PATCHED_SMALI_DIR.exists():
print("Copying original smali...")
for smali_dir in EXTRACTED_DIR.glob("smali*"):
shutil.copytree(smali_dir, PATCHED_SMALI_DIR / smali_dir.relative_to(EXTRACTED_DIR))
first_time = True
s = fileutil.merge_into(SRC_SMALI_DIR, PATCHED_SMALI_DIR, check_date=not first_time)
if s:
print("Copied custom code from src/smali")
else:
print("Skipped copying code from src/smali")
# Patch other resources
process_all_patches(SRC_SMALI_PATCHES_DIR, check_date=not first_time)

View file

@ -5,7 +5,11 @@ SOURCE_APK_DIR = Path("source-apk")
BUILD_DIR = Path("build")
EXTRACTED_DIR = BUILD_DIR / "extracted"
PATCHED_RSC_DIR = BUILD_DIR / "patched_resources"
PATCHED_SMALI_DIR = BUILD_DIR / "patched_smali"
MERGED_RSC_DIR = BUILD_DIR / "merged_resources"
SRC_DIR = Path("src")
SRC_RESOURCES_DIR = SRC_DIR / "resources"
SRC_PATCHES_DIR = SRC_DIR / "patches"
SRC_SMALI_DIR = SRC_DIR / "smali"
SRC_RESOURCE_PATCHES_DIR = SRC_DIR / "patches" / "resource"
SRC_SMALI_PATCHES_DIR = SRC_DIR / "patches" / "smali"

View file

@ -1,5 +1,7 @@
file 'res/values/public.xml'
# IDs and resources used by various ykit elements
insert ln17595 << @end
<!-- Ykit -->

View file

@ -1,5 +1,7 @@
file 'res/layout/color_options_toolbar.xml'
# Adds yellow into the list of colors in the toolbar
insert ln8 << @end
<androidx.appcompat.widget.AppCompatImageButton android:id="@id/text_color_yellow" android:background="?selectableItemBackgroundBorderless" android:layout_width="48.0dip" android:layout_height="48.0dip" android:layout_marginLeft="2.0dip" android:layout_marginRight="2.0dip" android:layout_weight="0.5" app:srcCompat="@drawable/oval_yellow" />

View file

@ -1,5 +1,7 @@
file 'res/layout/fragment_blog_settings.xml'
# Adds the YKit Settings entry to the account settings menu
insert ln10 << @end
<com.tumblr.ui.widget.TMBlogSettingsTextRow android:id="@id/ykit_settings" tumblr:listItemDetail="Change settings for YKit" tumblr:listItemTitle="YKit Settings" style="@style/DetailedListItem" />

View file

@ -7,7 +7,7 @@
.method static constructor <clinit>()V
.locals 0
invoke-static {}, Ldev/maelstrom/ykit/java/Test;->test()V
# invoke-static {}, Ldev/maelstrom/ykit/java/Test;->test()V
return-void
.end method

BIN
tools/apksigner.jar Normal file

Binary file not shown.