revert "feat: use of java.util.logging.Logger"

This reverts commit 9c39c9efdb.
This reverts commit 8f66f9f606.
This commit is contained in:
Lucaskyy 2022-06-22 14:37:31 +02:00
parent c13361823d
commit e8488b3e86
No known key found for this signature in database
GPG key ID: 1530BFF96D1EEB89
3 changed files with 24 additions and 65 deletions

View file

@ -25,7 +25,6 @@ dependencies {
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"))
}

View file

@ -32,7 +32,6 @@ 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
@ -43,20 +42,14 @@ 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()) {
logger.info("Delete previous resource cache directory")
outDir.deleteRecursively()
outDir.mkdirs()
}
if (outDir.exists()) outDir.deleteRecursively()
outDir.mkdirs()
val androlib = Androlib(BuildOptions().also { it.setBuildOptions(options) })
val resourceTable = androlib.getResTable(extInputFile, true)
@ -64,8 +57,6 @@ 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)
@ -80,8 +71,6 @@ 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)
@ -104,8 +93,6 @@ 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
@ -128,22 +115,17 @@ class Patcher(private val options: PatcherOptions) {
) {
for (file in files) {
for (classDef in MultiDexIO.readDexFile(true, file, NAMER, null, null).classes) {
val type = classDef.type
val e = data.bytecodeData.classes.internalClasses.findIndexed { it.type == type }
val e = data.bytecodeData.classes.internalClasses.findIndexed { it.type == classDef.type }
if (e != null) {
if (throwOnDuplicates) {
throw Exception("Class $type has already been added to the patcher.")
throw Exception("Class ${classDef.type} has already been added to the patcher.")
}
val (_, idx) = e
if (allowedOverwrites.contains(type)) {
logger.trace("Override $type")
if (allowedOverwrites.contains(classDef.type)) {
data.bytecodeData.classes.internalClasses[idx] = classDef
continue
}
logger.trace("Skip $type")
continue
}
logger.trace("Add $type")
data.bytecodeData.classes.internalClasses.add(classDef)
}
}
@ -191,8 +173,6 @@ class Patcher(private val options: PatcherOptions) {
)
}.toTypedArray()
logger.info("Building resources. This takes some time")
androlibResources.aaptPackage(
aaptFile, manifestFile, resDirectory, null,
null, includedFiles
@ -212,8 +192,6 @@ class Patcher(private val options: PatcherOptions) {
}
}
logger.info("Write dex files")
// write dex modified files
val dexFiles = mutableMapOf<String, MemoryDataStore>()
MultiDexIO.writeDexFile(
@ -250,11 +228,7 @@ class Patcher(private val options: PatcherOptions) {
val patchName = patch.patchName
// if the patch has already applied silently skip it
if (appliedPatches.contains(patchName)) {
logger.warn("Skip $patchName because it already has been applied")
return PatchResultSuccess()
}
if (appliedPatches.contains(patchName)) return PatchResultSuccess()
appliedPatches.add(patchName)
// recursively apply all dependency patches
@ -284,8 +258,6 @@ class Patcher(private val options: PatcherOptions) {
data.bytecodeData
}
logger.warn("Execute $patchName")
return try {
patchInstance.execute(data)
} catch (e: Exception) {

View file

@ -3,7 +3,6 @@ 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
@ -12,26 +11,37 @@ 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,
@ -146,28 +156,6 @@ 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