You've already forked revanced-patcher
mirror of
https://github.com/revanced/revanced-patcher
synced 2025-09-06 16:38:50 +02:00
Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c13361823d | ||
![]() |
8f66f9f606 | ||
![]() |
a123026f46 | ||
![]() |
9c39c9efdb | ||
![]() |
3ee1c01430 | ||
![]() |
64bae884dc | ||
![]() |
e94a706949 | ||
![]() |
89bb43066b | ||
![]() |
68174bbd6b | ||
![]() |
d05c9416d6 | ||
![]() |
5a2f02b97d | ||
![]() |
a3005fa08e | ||
![]() |
6628b7870f | ||
![]() |
a6411245aa | ||
![]() |
365e1d7a45 | ||
![]() |
4507cd2353 | ||
![]() |
1f75777cf9 | ||
![]() |
28d5468b07 | ||
![]() |
746496125d | ||
![]() |
835a421cc0 | ||
![]() |
99342fe033 | ||
![]() |
e47b67d7ec | ||
![]() |
ad6c5c8273 | ||
![]() |
fd690acd61 | ||
![]() |
e698b02bf6 | ||
![]() |
ab866bb8ef |
76
CHANGELOG.md
76
CHANGELOG.md
@@ -1,3 +1,79 @@
|
||||
# [1.7.0](https://github.com/revanced/revanced-patcher/compare/v1.6.0...v1.7.0) (2022-06-22)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* migrate logger to `slf4j` ([8f66f9f](https://github.com/revanced/revanced-patcher/commit/8f66f9f606a785ac947b0e553822877f211d82df))
|
||||
|
||||
# [1.6.0](https://github.com/revanced/revanced-patcher/compare/v1.5.0...v1.6.0) (2022-06-22)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* use of `java.util.logging.Logger` ([9c39c9e](https://github.com/revanced/revanced-patcher/commit/9c39c9efdb5d48ddaffce7f711c275e732b0b2d9))
|
||||
|
||||
# [1.5.0](https://github.com/revanced/revanced-patcher/compare/v1.4.0...v1.5.0) (2022-06-22)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* use streams to write the dex files ([64bae88](https://github.com/revanced/revanced-patcher/commit/64bae884dcb72550a3218e149f3ca0fd0ca03aaf))
|
||||
|
||||
# [1.4.0](https://github.com/revanced/revanced-patcher/compare/v1.3.4...v1.4.0) (2022-06-22)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* return a `File` instance instead of `ExtFile` ([68174bb](https://github.com/revanced/revanced-patcher/commit/68174bbd6b4df47a91b610c2b97dbae55b594163))
|
||||
|
||||
## [1.3.4](https://github.com/revanced/revanced-patcher/compare/v1.3.3...v1.3.4) (2022-06-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* `String.toInstructions` defaulting `forStaticMethod` to `false` ([5a2f02b](https://github.com/revanced/revanced-patcher/commit/5a2f02b97dcde95dbe901fa68cca6c6c0219cb82)), closes [revanced/revanced-patches#46](https://github.com/revanced/revanced-patches/issues/46)
|
||||
|
||||
## [1.3.3](https://github.com/revanced/revanced-patcher/compare/v1.3.2...v1.3.3) (2022-06-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add docs (trigger release) ([6628b78](https://github.com/revanced/revanced-patcher/commit/6628b7870fc052da40be0d50a7e2b0b6c57743cc))
|
||||
|
||||
|
||||
### Reverts
|
||||
|
||||
* propagate dependencies ([365e1d7](https://github.com/revanced/revanced-patcher/commit/365e1d7a4507b918a4c8170ce2c88f6c8ff1d474))
|
||||
|
||||
## [1.3.2](https://github.com/revanced/revanced-patcher/compare/v1.3.1...v1.3.2) (2022-06-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* return resourceFile to caller ([1f75777](https://github.com/revanced/revanced-patcher/commit/1f75777cf985bf08483033ec541937d3e733347b))
|
||||
|
||||
## [1.3.1](https://github.com/revanced/revanced-patcher/compare/v1.3.0...v1.3.1) (2022-06-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* `InlineSmaliCompiler.compile` using 0 registers instead of 1 by default ([835a421](https://github.com/revanced/revanced-patcher/commit/835a421cc0588b92c2995e9d74727069d14b1750))
|
||||
|
||||
# [1.3.0](https://github.com/revanced/revanced-patcher/compare/v1.2.9...v1.3.0) (2022-06-20)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* `parametersCount` for `InlineSmaliCompiler` instead of `parameters` ([ad6c5c8](https://github.com/revanced/revanced-patcher/commit/ad6c5c827389d10eae473dc66557a699df8c3280))
|
||||
* simplify adding instructions ([e47b67d](https://github.com/revanced/revanced-patcher/commit/e47b67d7ec521f288644afb89baf4146dc9bc87d))
|
||||
|
||||
## [1.2.9](https://github.com/revanced/revanced-patcher/compare/v1.2.8...v1.2.9) (2022-06-20)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* update apktool ([ab866bb](https://github.com/revanced/revanced-patcher/commit/ab866bb8ef4792d8f2a51edc79e687b5b636c621))
|
||||
|
||||
## [1.2.8](https://github.com/revanced/revanced-patcher/compare/v1.2.7...v1.2.8) (2022-06-18)
|
||||
|
||||
|
||||
|
@@ -21,15 +21,14 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib"))
|
||||
|
||||
api("xpp3:xpp3:1.1.4c")
|
||||
api("org.apktool:apktool-lib:2.6.4-SNAPSHOT")
|
||||
api("app.revanced:multidexlib2:2.5.2.r2")
|
||||
api("org.smali:smali:2.5.2")
|
||||
implementation("xpp3:xpp3:1.1.4c")
|
||||
implementation("app.revanced:multidexlib2:2.5.2.r2")
|
||||
implementation("org.smali:smali:2.5.2")
|
||||
implementation("org.apktool:apktool-lib:2.6.5-SNAPSHOT")
|
||||
implementation("org.slf4j:slf4j-api:1.7.36")
|
||||
|
||||
testImplementation(kotlin("test"))
|
||||
implementation(kotlin("reflect"))}
|
||||
}
|
||||
|
||||
tasks {
|
||||
test {
|
||||
|
@@ -1,2 +1,2 @@
|
||||
kotlin.code.style = official
|
||||
version = 1.2.8
|
||||
version = 1.7.0
|
||||
|
@@ -32,6 +32,7 @@ import org.jf.dexlib2.Opcodes
|
||||
import org.jf.dexlib2.iface.ClassDef
|
||||
import org.jf.dexlib2.iface.DexFile
|
||||
import org.jf.dexlib2.writer.io.MemoryDataStore
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
@@ -42,14 +43,20 @@ val NAMER = BasicDexFileNamer()
|
||||
* @param options The options for the patcher.
|
||||
*/
|
||||
class Patcher(private val options: PatcherOptions) {
|
||||
private val logger = LoggerFactory.getLogger(Patcher::class.java)
|
||||
|
||||
val data: PatcherData
|
||||
private val opcodes: Opcodes
|
||||
|
||||
init {
|
||||
val extInputFile = ExtFile(options.inputFile)
|
||||
val outDir = File(options.resourceCacheDirectory)
|
||||
if (outDir.exists()) outDir.deleteRecursively()
|
||||
outDir.mkdirs()
|
||||
if (outDir.exists()) {
|
||||
logger.info("Delete previous resource cache directory")
|
||||
|
||||
outDir.deleteRecursively()
|
||||
outDir.mkdirs()
|
||||
}
|
||||
|
||||
val androlib = Androlib(BuildOptions().also { it.setBuildOptions(options) })
|
||||
val resourceTable = androlib.getResTable(extInputFile, true)
|
||||
@@ -57,6 +64,8 @@ class Patcher(private val options: PatcherOptions) {
|
||||
val packageMetadata = PackageMetadata()
|
||||
|
||||
if (options.patchResources) {
|
||||
logger.info("Decode resources")
|
||||
|
||||
// decode resources to cache directory
|
||||
androlib.decodeManifestWithResources(extInputFile, outDir, resourceTable)
|
||||
androlib.decodeResourcesFull(extInputFile, outDir, resourceTable)
|
||||
@@ -71,6 +80,8 @@ class Patcher(private val options: PatcherOptions) {
|
||||
}
|
||||
|
||||
} else {
|
||||
logger.warn("Resource patching is disabled. Falling back to manually decode AndroidManifest.xml")
|
||||
|
||||
// create decoder for the resource table
|
||||
val decoder = ResAttrDecoder()
|
||||
decoder.currentPackage = ResPackage(resourceTable, 0, null)
|
||||
@@ -93,6 +104,8 @@ class Patcher(private val options: PatcherOptions) {
|
||||
packageMetadata.metaInfo.versionInfo = resourceTable.versionInfo
|
||||
packageMetadata.metaInfo.sdkInfo = resourceTable.sdkInfo
|
||||
|
||||
logger.info("Read dex files")
|
||||
|
||||
// read dex files
|
||||
val dexFile = MultiDexIO.readDexFile(true, options.inputFile, NAMER, null, null)
|
||||
// get the opcodes
|
||||
@@ -115,17 +128,22 @@ class Patcher(private val options: PatcherOptions) {
|
||||
) {
|
||||
for (file in files) {
|
||||
for (classDef in MultiDexIO.readDexFile(true, file, NAMER, null, null).classes) {
|
||||
val e = data.bytecodeData.classes.internalClasses.findIndexed { it.type == classDef.type }
|
||||
val type = classDef.type
|
||||
val e = data.bytecodeData.classes.internalClasses.findIndexed { it.type == type }
|
||||
if (e != null) {
|
||||
if (throwOnDuplicates) {
|
||||
throw Exception("Class ${classDef.type} has already been added to the patcher.")
|
||||
throw Exception("Class $type has already been added to the patcher.")
|
||||
}
|
||||
val (_, idx) = e
|
||||
if (allowedOverwrites.contains(classDef.type)) {
|
||||
if (allowedOverwrites.contains(type)) {
|
||||
logger.trace("Override $type")
|
||||
data.bytecodeData.classes.internalClasses[idx] = classDef
|
||||
continue
|
||||
}
|
||||
logger.trace("Skip $type")
|
||||
continue
|
||||
}
|
||||
logger.trace("Add $type")
|
||||
data.bytecodeData.classes.internalClasses.add(classDef)
|
||||
}
|
||||
}
|
||||
@@ -137,6 +155,7 @@ class Patcher(private val options: PatcherOptions) {
|
||||
fun save(): PatcherResult {
|
||||
val packageMetadata = data.packageMetadata
|
||||
val metaInfo = packageMetadata.metaInfo
|
||||
var resourceFile: File? = null
|
||||
|
||||
if (options.patchResources) {
|
||||
val cacheDirectory = ExtFile(options.resourceCacheDirectory)
|
||||
@@ -172,14 +191,14 @@ class Patcher(private val options: PatcherOptions) {
|
||||
)
|
||||
}.toTypedArray()
|
||||
|
||||
logger.info("Building resources. This takes some time")
|
||||
|
||||
androlibResources.aaptPackage(
|
||||
aaptFile, manifestFile, resDirectory, null,
|
||||
null, includedFiles
|
||||
)
|
||||
|
||||
// write packaged resources to cache directory
|
||||
ExtFile(aaptFile).directory.copyToDir(cacheDirectory.resolve("build/"))
|
||||
|
||||
resourceFile = aaptFile
|
||||
}
|
||||
|
||||
val newDexFile = object : DexFile {
|
||||
@@ -193,6 +212,8 @@ class Patcher(private val options: PatcherOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Write dex files")
|
||||
|
||||
// write dex modified files
|
||||
val dexFiles = mutableMapOf<String, MemoryDataStore>()
|
||||
MultiDexIO.writeDexFile(
|
||||
@@ -202,9 +223,10 @@ class Patcher(private val options: PatcherOptions) {
|
||||
|
||||
return PatcherResult(
|
||||
dexFiles.map {
|
||||
app.revanced.patcher.util.dex.DexFile(it.key, it.value)
|
||||
app.revanced.patcher.util.dex.DexFile(it.key, it.value.readAt(0))
|
||||
},
|
||||
metaInfo.doNotCompress.toList()
|
||||
metaInfo.doNotCompress.toList(),
|
||||
resourceFile
|
||||
)
|
||||
}
|
||||
|
||||
@@ -228,7 +250,11 @@ class Patcher(private val options: PatcherOptions) {
|
||||
val patchName = patch.patchName
|
||||
|
||||
// if the patch has already applied silently skip it
|
||||
if (appliedPatches.contains(patchName)) return PatchResultSuccess()
|
||||
if (appliedPatches.contains(patchName)) {
|
||||
logger.warn("Skip $patchName because it already has been applied")
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
appliedPatches.add(patchName)
|
||||
|
||||
// recursively apply all dependency patches
|
||||
@@ -258,6 +284,8 @@ class Patcher(private val options: PatcherOptions) {
|
||||
data.bytecodeData
|
||||
}
|
||||
|
||||
logger.warn("Execute $patchName")
|
||||
|
||||
return try {
|
||||
patchInstance.execute(data)
|
||||
} catch (e: Exception) {
|
||||
|
@@ -1,13 +1,17 @@
|
||||
package app.revanced.patcher
|
||||
|
||||
import app.revanced.patcher.util.dex.DexFile
|
||||
import brut.directory.ExtFile
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* The result of a patcher.
|
||||
* @param dexFiles The patched dex files.
|
||||
* @param doNotCompress List of relative paths to files to exclude from compressing.
|
||||
* @param resourceFile File containing resources that need to be extracted into the APK.
|
||||
*/
|
||||
data class PatcherResult(
|
||||
val dexFiles: List<DexFile>,
|
||||
val doNotCompress: List<String>? = null
|
||||
val doNotCompress: List<String>? = null,
|
||||
val resourceFile: File?
|
||||
)
|
@@ -1,6 +1,9 @@
|
||||
package app.revanced.patcher.extensions
|
||||
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||
import app.revanced.patcher.util.smali.toInstruction
|
||||
import app.revanced.patcher.util.smali.toInstructions
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.builder.BuilderInstruction
|
||||
import org.jf.dexlib2.builder.MutableMethodImplementation
|
||||
@@ -62,6 +65,22 @@ internal fun Method.clone(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add smali instructions to the method.
|
||||
* @param index The index to insert the instructions at.
|
||||
* @param instruction The smali instruction to add.
|
||||
*/
|
||||
fun MutableMethod.addInstruction(index: Int, instruction: String) =
|
||||
this.implementation!!.addInstruction(index, instruction.toInstruction(this))
|
||||
|
||||
/**
|
||||
* Add smali instructions to the method.
|
||||
* @param index The index to insert the instructions at.
|
||||
* @param instructions The smali instructions to add.
|
||||
*/
|
||||
fun MutableMethod.addInstructions(index: Int, instructions: String) =
|
||||
this.implementation!!.addInstructions(index, instructions.toInstructions(this))
|
||||
|
||||
/**
|
||||
* Clones the method.
|
||||
* @param registerCount This parameter allows you to change the register count of the method.
|
||||
|
@@ -9,5 +9,5 @@ import app.revanced.patcher.signature.implementation.method.MethodSignature
|
||||
* @param signatures A list of [MethodSignature] this patch relies on.
|
||||
*/
|
||||
abstract class BytecodePatch(
|
||||
val signatures: Iterable<MethodSignature>
|
||||
internal val signatures: Iterable<MethodSignature>
|
||||
) : Patch<BytecodeData>()
|
@@ -3,6 +3,7 @@ package app.revanced.patcher.signature.implementation.method.resolver
|
||||
import app.revanced.patcher.data.PatcherData
|
||||
import app.revanced.patcher.data.implementation.proxy
|
||||
import app.revanced.patcher.extensions.MethodSignatureExtensions.fuzzyThreshold
|
||||
import app.revanced.patcher.extensions.MethodSignatureExtensions.name
|
||||
import app.revanced.patcher.extensions.parametersEqual
|
||||
import app.revanced.patcher.signature.implementation.method.MethodSignature
|
||||
import org.jf.dexlib2.Opcode
|
||||
@@ -11,37 +12,26 @@ import org.jf.dexlib2.iface.Method
|
||||
import org.jf.dexlib2.iface.instruction.Instruction
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction21c
|
||||
import org.jf.dexlib2.iface.reference.StringReference
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
internal class MethodSignatureResolver(
|
||||
private val classes: List<ClassDef>,
|
||||
private val methodSignatures: Iterable<MethodSignature>
|
||||
) {
|
||||
fun resolve(patcherData: PatcherData) {
|
||||
for (signature in methodSignatures) {
|
||||
for (classDef in classes) {
|
||||
for (method in classDef.methods) {
|
||||
val patternScanData = compareSignatureToMethod(signature, method) ?: continue
|
||||
|
||||
// create class proxy, in case a patch needs mutability
|
||||
val classProxy = patcherData.bytecodeData.proxy(classDef)
|
||||
signature.result = SignatureResolverResult(
|
||||
classProxy,
|
||||
patternScanData,
|
||||
method,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// These functions do not require the constructor values, so they can be static.
|
||||
companion object {
|
||||
private val logger: Logger = LoggerFactory.getLogger(MethodSignatureResolver::class.java)
|
||||
|
||||
fun resolveFromProxy(
|
||||
classProxy: app.revanced.patcher.util.proxy.ClassProxy,
|
||||
signature: MethodSignature
|
||||
): SignatureResolverResult? {
|
||||
for (method in classProxy.immutableClass.methods) {
|
||||
val result = compareSignatureToMethod(signature, method) ?: continue
|
||||
|
||||
logger.trace("${signature.name} match to ${method.definingClass}->${method.name}")
|
||||
|
||||
return SignatureResolverResult(
|
||||
classProxy,
|
||||
result,
|
||||
@@ -156,6 +146,28 @@ internal class MethodSignatureResolver(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun resolve(patcherData: PatcherData) {
|
||||
for (signature in methodSignatures) {
|
||||
val signatureName = signature.name
|
||||
logger.trace("Resolve $signatureName")
|
||||
for (classDef in classes) {
|
||||
for (method in classDef.methods) {
|
||||
val patternScanData = compareSignatureToMethod(signature, method) ?: continue
|
||||
|
||||
logger.trace("$signatureName match to ${method.definingClass}->${method.name}")
|
||||
|
||||
// create class proxy, in case a patch needs mutability
|
||||
val classProxy = patcherData.bytecodeData.proxy(classDef)
|
||||
signature.result = SignatureResolverResult(
|
||||
classProxy,
|
||||
patternScanData,
|
||||
method,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private operator fun ClassDef.component1() = this
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package app.revanced.patcher.util.dex
|
||||
|
||||
import org.jf.dexlib2.writer.io.MemoryDataStore
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* Wrapper for dex files.
|
||||
* @param name The original name of the dex file
|
||||
* @param memoryDataStore The data store for the dex file.
|
||||
* @param name The original name of the dex file.
|
||||
* @param dexFileInputStream The dex file as [InputStream].
|
||||
*/
|
||||
data class DexFile(val name: String, val memoryDataStore: MemoryDataStore)
|
||||
data class DexFile(val name: String, val dexFileInputStream: InputStream)
|
@@ -3,8 +3,10 @@ package app.revanced.patcher.util.smali
|
||||
import org.antlr.runtime.CommonTokenStream
|
||||
import org.antlr.runtime.TokenSource
|
||||
import org.antlr.runtime.tree.CommonTreeNodeStream
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcodes
|
||||
import org.jf.dexlib2.builder.BuilderInstruction
|
||||
import org.jf.dexlib2.iface.Method
|
||||
import org.jf.dexlib2.writer.builder.DexBuilder
|
||||
import org.jf.smali.LexerErrorInterface
|
||||
import org.jf.smali.smaliFlexLexer
|
||||
@@ -13,12 +15,12 @@ import org.jf.smali.smaliTreeWalker
|
||||
import java.io.InputStreamReader
|
||||
|
||||
private const val METHOD_TEMPLATE = """
|
||||
.class LInlineCompiler;
|
||||
.super Ljava/lang/Object;
|
||||
.method %s dummyMethod(%s)V
|
||||
.registers %d
|
||||
%s
|
||||
.end method
|
||||
.class LInlineCompiler;
|
||||
.super Ljava/lang/Object;
|
||||
.method %s dummyMethod(%s)V
|
||||
.registers %d
|
||||
%s
|
||||
.end method
|
||||
"""
|
||||
|
||||
class InlineSmaliCompiler {
|
||||
@@ -32,13 +34,11 @@ class InlineSmaliCompiler {
|
||||
* be messed up and results in broken Dalvik bytecode.
|
||||
* FIXME: Fix the above issue. When this is fixed, add the proper conversions in [InstructionConverter].
|
||||
*/
|
||||
fun compileMethodInstructions(
|
||||
instructions: String,
|
||||
parameters: String,
|
||||
registers: Int,
|
||||
forStaticMethod: Boolean
|
||||
fun compile(
|
||||
instructions: String, parameters: String, registers: Int, forStaticMethod: Boolean
|
||||
): List<BuilderInstruction> {
|
||||
val input = METHOD_TEMPLATE.format(if (forStaticMethod) "static" else "", parameters, registers, instructions)
|
||||
val input =
|
||||
METHOD_TEMPLATE.format(if (forStaticMethod) "static" else "", parameters, registers, instructions)
|
||||
val reader = InputStreamReader(input.byteInputStream())
|
||||
val lexer: LexerErrorInterface = smaliFlexLexer(reader, 15)
|
||||
val tokens = CommonTokenStream(lexer as TokenSource)
|
||||
@@ -59,8 +59,20 @@ class InlineSmaliCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
fun String.toInstructions(parameters: String = "", registers: Int = 1, forStaticMethod: Boolean = true) =
|
||||
InlineSmaliCompiler.compileMethodInstructions(this, parameters, registers, forStaticMethod)
|
||||
/**
|
||||
* Compile lines of Smali code to a list of instructions.
|
||||
* @param templateMethod The method to compile the instructions against.
|
||||
* @returns A list of instructions.
|
||||
*/
|
||||
fun String.toInstructions(templateMethod: Method? = null) = InlineSmaliCompiler.compile(this,
|
||||
templateMethod?.parameters?.joinToString("") { it } ?: "",
|
||||
templateMethod?.implementation?.registerCount ?: 1,
|
||||
templateMethod?.let { AccessFlags.STATIC.isSet(it.accessFlags) } ?: true
|
||||
)
|
||||
|
||||
fun String.toInstruction(parameters: String = "", registers: Int = 1, forStaticMethod: Boolean = true) =
|
||||
this.toInstructions(parameters, registers, forStaticMethod).first()
|
||||
/**
|
||||
* Compile a line of Smali code to an instruction.
|
||||
* @param templateMethod The method to compile the instructions against.
|
||||
* @return The instruction.
|
||||
*/
|
||||
fun String.toInstruction(templateMethod: Method? = null) = this.toInstructions(templateMethod).first()
|
||||
|
@@ -15,7 +15,6 @@ import app.revanced.patcher.usage.resource.annotation.ExampleResourceCompatibili
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||
import app.revanced.patcher.util.smali.toInstruction
|
||||
import app.revanced.patcher.util.smali.toInstructions
|
||||
import com.google.common.collect.ImmutableList
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Format
|
||||
@@ -47,7 +46,7 @@ class ExampleBytecodePatch : BytecodePatch(
|
||||
// You can treat it as a constructor
|
||||
override fun execute(data: BytecodeData): PatchResult {
|
||||
// Get the resolved method for the signature from the resolver cache
|
||||
val result = signatures.first().result!!
|
||||
val result = ExampleSignature.result!!
|
||||
|
||||
// Get the implementation for the resolved method
|
||||
val implementation = result.method.implementation!!
|
||||
@@ -126,8 +125,8 @@ class ExampleBytecodePatch : BytecodePatch(
|
||||
invoke-static { }, LTestClass;->returnHello()Ljava/lang/String;
|
||||
move-result-object v1
|
||||
invoke-virtual { v0, v1 }, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
|
||||
""".trimIndent().toInstructions()
|
||||
implementation.addInstructions(startIndex + 2, instructions)
|
||||
"""
|
||||
result.method.addInstructions(startIndex + 2, instructions)
|
||||
|
||||
// Finally, tell the patcher that this patch was a success.
|
||||
// You can also return PatchResultError with a message.
|
||||
|
Reference in New Issue
Block a user