Update Comments

This commit is contained in:
2026-05-21 14:58:15 +10:00
parent b8a064ca29
commit e5f186b264
@@ -38,16 +38,11 @@ class SmaliPatchStep : Step(), IDexProvider, KoinComponent {
val patches = mutableListOf<LoadedPatch>() val patches = mutableListOf<LoadedPatch>()
// Load and parse all the patches from the smali patch archive. // Load and parse all the patches from the smali archive.
// Extension classes (extension/**/*.smali) are extracted into smaliDir
// so they get assembled into the new dex alongside patched classes.
container.log("Loading patches from smali patch archive: ${patchesZip.absolutePath}") container.log("Loading patches from smali patch archive: ${patchesZip.absolutePath}")
smaliDir.mkdirs() smaliDir.mkdirs()
ZipReader(patchesZip).use { zip -> ZipReader(patchesZip).use { zip ->
// Iterate in filename order so patches apply deterministically, matching // Iterate in filename order so patches apply deterministically
// the apply-order contract in patches/README. Zip iteration order would
// otherwise depend on archive layout and could break ordered patches that
// share a target file.
for (patchFile in zip.entryNames.sorted()) { for (patchFile in zip.entryNames.sorted()) {
container.log("Parsing patch file $patchFile") container.log("Parsing patch file $patchFile")
if (patchFile.endsWith("/")) continue if (patchFile.endsWith("/")) continue
@@ -73,8 +68,8 @@ class SmaliPatchStep : Step(), IDexProvider, KoinComponent {
val lines = zip.openEntry(patchFile)!!.read() val lines = zip.openEntry(patchFile)!!.read()
.decodeToString() .decodeToString()
.replace("\r\n", "\n") // Replace CRLF endings with LF endings to be sure here .replace("\r\n", "\n") // Replace CRLF endings with LF
.trimEnd { it == '\n' } // Remove trailing new lines to work with diff output properly .trimEnd { it == '\n' } // Remove trailing new lines
.split('\n') .split('\n')
try { try {
@@ -96,7 +91,7 @@ class SmaliPatchStep : Step(), IDexProvider, KoinComponent {
} }
} }
// Disassemble all the classes we have patches for from all the dex files // Disassemble all the classes
container.log("Disassembling target classes in APK") container.log("Disassembling target classes in APK")
ZipReader(apk).use { zip -> ZipReader(apk).use { zip ->
for (file in zip.entryNames) { for (file in zip.entryNames) {
@@ -117,11 +112,10 @@ class SmaliPatchStep : Step(), IDexProvider, KoinComponent {
/* dexFile = */ dexFile, /* dexFile = */ dexFile,
/* outputDir = */ smaliDir, /* outputDir = */ smaliDir,
/* jobs = */ coreCount - 1, /* jobs = */ coreCount - 1,
/* options = */ BaksmaliOptions().apply { /* options = */
BaksmaliOptions().apply {
localsDirective = true localsDirective = true
// Match apktool's label naming (:cond_0, :cond_1, ...) so patches // Match apktool label naming
// authored from `apktool d` decompilation apply cleanly. Default
// would emit offset-based labels like :cond_8de.
sequentialLabels = true sequentialLabels = true
}, },
/* classes = */ patches.map { "L${it.fullClassName};" }, /* classes = */ patches.map { "L${it.fullClassName};" },
@@ -135,7 +129,7 @@ class SmaliPatchStep : Step(), IDexProvider, KoinComponent {
} }
} }
// Apply all the patches to the smali files // Apply all the patches to smali files
container.log("Applying smali patches to disassembled files") container.log("Applying smali patches to disassembled files")
for ((fullClassName, patch) in patches) { for ((fullClassName, patch) in patches) {
container.log("Applying patch to class $fullClassName") container.log("Applying patch to class $fullClassName")
@@ -156,11 +150,11 @@ class SmaliPatchStep : Step(), IDexProvider, KoinComponent {
} }
} }
// Assemble the patched classes back into a single dex // Assemble patched dex
container.log("Reassembling patches smali classes into new dex") container.log("Reassembling patches smali classes into new dex")
smaliDir.mkdir() smaliDir.mkdir()
// Capture stdout/stderr while assembling smali // Capture stdout/stderr assembling smali
val originalStdout = System.out val originalStdout = System.out
val originalStderr = System.err val originalStderr = System.err
val captured = ByteArrayOutputStream() val captured = ByteArrayOutputStream()