From 642c4ea97e0d8d2ac177dcb6ddada49dd076b310 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 10 Oct 2023 20:05:46 +0200 Subject: [PATCH] refactor: Use correct class structure --- .../app/revanced/patcher/PatcherContext.kt | 3 +- .../revanced/patcher/data/BytecodeContext.kt | 56 +++++++++---------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/revanced-patcher/src/main/kotlin/app/revanced/patcher/PatcherContext.kt b/revanced-patcher/src/main/kotlin/app/revanced/patcher/PatcherContext.kt index c21cfa6..fffba74 100644 --- a/revanced-patcher/src/main/kotlin/app/revanced/patcher/PatcherContext.kt +++ b/revanced-patcher/src/main/kotlin/app/revanced/patcher/PatcherContext.kt @@ -37,4 +37,5 @@ class PatcherContext internal constructor(options: PatcherOptions) { * The [BytecodeContext] of this [PatcherContext]. * This holds the current state of the bytecode. */ - internal val bytecodeContext = BytecodeContext(options) } \ No newline at end of file + internal val bytecodeContext = BytecodeContext(options) +} \ No newline at end of file diff --git a/revanced-patcher/src/main/kotlin/app/revanced/patcher/data/BytecodeContext.kt b/revanced-patcher/src/main/kotlin/app/revanced/patcher/data/BytecodeContext.kt index 0dee449..abea9ba 100644 --- a/revanced-patcher/src/main/kotlin/app/revanced/patcher/data/BytecodeContext.kt +++ b/revanced-patcher/src/main/kotlin/app/revanced/patcher/data/BytecodeContext.kt @@ -90,6 +90,34 @@ class BytecodeContext internal constructor(private val options: PatcherOptions) */ fun toMethodWalker(startMethod: Method) = MethodWalker(this, startMethod) + /** + * Compile bytecode from the [BytecodeContext]. + * + * @return The compiled bytecode. + */ + override fun get(): List { + logger.info("Compiling patched dex files") + + val patchedDexFileResults = options.resourceCachePath.resolve("dex").also { + it.deleteRecursively() // Make sure the directory is empty. + it.mkdirs() + }.apply { + MultiDexIO.writeDexFile( + true, + if (options.multithreadingDexFileWriter) -1 else 1, + this, + BasicDexFileNamer(), + object : DexFile { + override fun getClasses() = this@BytecodeContext.classes.also(ProxyClassList::replaceClasses) + override fun getOpcodes() = this@BytecodeContext.opcodes + }, + DexIO.DEFAULT_MAX_DEX_POOL_SIZE + ) { _, entryName, _ -> logger.info("Compiled $entryName") } + }.listFiles(FileFilter { it.isFile })!!.map { PatcherResult.PatchedDexFile(it.name, it.inputStream()) } + + return patchedDexFileResults + } + /** * The integrations of a [PatcherContext]. */ @@ -135,32 +163,4 @@ class BytecodeContext internal constructor(private val options: PatcherOptions) clear() } } - - /** - * Compile bytecode from the [BytecodeContext]. - * - * @return The compiled bytecode. - */ - override fun get(): List { - logger.info("Compiling patched dex files") - - val patchedDexFileResults = options.resourceCachePath.resolve("dex").also { - it.deleteRecursively() // Make sure the directory is empty. - it.mkdirs() - }.apply { - MultiDexIO.writeDexFile( - true, - if (options.multithreadingDexFileWriter) -1 else 1, - this, - BasicDexFileNamer(), - object : DexFile { - override fun getClasses() = this@BytecodeContext.classes.also(ProxyClassList::replaceClasses) - override fun getOpcodes() = this@BytecodeContext.opcodes - }, - DexIO.DEFAULT_MAX_DEX_POOL_SIZE - ) { _, entryName, _ -> logger.info("Compiled $entryName") } - }.listFiles(FileFilter { it.isFile })!!.map { PatcherResult.PatchedDexFile(it.name, it.inputStream()) } - - return patchedDexFileResults - } } \ No newline at end of file