feat: migrate logger to slf4j

This commit is contained in:
oSumAtrIX 2022-06-22 14:17:09 +02:00
parent a123026f46
commit 8f66f9f606
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 17 additions and 15 deletions

View File

@ -25,6 +25,7 @@ dependencies {
implementation("app.revanced:multidexlib2:2.5.2.r2") implementation("app.revanced:multidexlib2:2.5.2.r2")
implementation("org.smali:smali:2.5.2") implementation("org.smali:smali:2.5.2")
implementation("org.apktool:apktool-lib:2.6.5-SNAPSHOT") implementation("org.apktool:apktool-lib:2.6.5-SNAPSHOT")
implementation("org.slf4j:slf4j-api:1.7.36")
testImplementation(kotlin("test")) testImplementation(kotlin("test"))
} }

View File

@ -32,9 +32,9 @@ import org.jf.dexlib2.Opcodes
import org.jf.dexlib2.iface.ClassDef import org.jf.dexlib2.iface.ClassDef
import org.jf.dexlib2.iface.DexFile import org.jf.dexlib2.iface.DexFile
import org.jf.dexlib2.writer.io.MemoryDataStore import org.jf.dexlib2.writer.io.MemoryDataStore
import org.slf4j.LoggerFactory
import java.io.File import java.io.File
import java.nio.file.Files import java.nio.file.Files
import java.util.logging.Logger
val NAMER = BasicDexFileNamer() val NAMER = BasicDexFileNamer()
@ -43,7 +43,7 @@ val NAMER = BasicDexFileNamer()
* @param options The options for the patcher. * @param options The options for the patcher.
*/ */
class Patcher(private val options: PatcherOptions) { class Patcher(private val options: PatcherOptions) {
private val logger: Logger = Logger.getLogger(::Patcher.name) private val logger = LoggerFactory.getLogger(Patcher::class.java)
val data: PatcherData val data: PatcherData
private val opcodes: Opcodes private val opcodes: Opcodes
@ -51,7 +51,7 @@ class Patcher(private val options: PatcherOptions) {
init { init {
val extInputFile = ExtFile(options.inputFile) val extInputFile = ExtFile(options.inputFile)
val outDir = File(options.resourceCacheDirectory) val outDir = File(options.resourceCacheDirectory)
if (outDir.exists()){ if (outDir.exists()) {
logger.info("Delete previous resource cache directory") logger.info("Delete previous resource cache directory")
outDir.deleteRecursively() outDir.deleteRecursively()
@ -80,7 +80,7 @@ class Patcher(private val options: PatcherOptions) {
} }
} else { } else {
logger.warning("Resource patching is disabled. Falling back to manually decode AndroidManifest.xml") logger.warn("Resource patching is disabled. Falling back to manually decode AndroidManifest.xml")
// create decoder for the resource table // create decoder for the resource table
val decoder = ResAttrDecoder() val decoder = ResAttrDecoder()
@ -136,14 +136,14 @@ class Patcher(private val options: PatcherOptions) {
} }
val (_, idx) = e val (_, idx) = e
if (allowedOverwrites.contains(type)) { if (allowedOverwrites.contains(type)) {
logger.fine("Override $type") logger.trace("Override $type")
data.bytecodeData.classes.internalClasses[idx] = classDef data.bytecodeData.classes.internalClasses[idx] = classDef
continue continue
} }
logger.fine("Skip $type") logger.trace("Skip $type")
continue continue
} }
logger.finest("Add $type") logger.trace("Add $type")
data.bytecodeData.classes.internalClasses.add(classDef) data.bytecodeData.classes.internalClasses.add(classDef)
} }
} }
@ -250,8 +250,8 @@ class Patcher(private val options: PatcherOptions) {
val patchName = patch.patchName val patchName = patch.patchName
// if the patch has already applied silently skip it // if the patch has already applied silently skip it
if (appliedPatches.contains(patchName)){ if (appliedPatches.contains(patchName)) {
logger.fine("Skip $patchName because it already has been applied") logger.warn("Skip $patchName because it already has been applied")
return PatchResultSuccess() return PatchResultSuccess()
} }
@ -284,7 +284,7 @@ class Patcher(private val options: PatcherOptions) {
data.bytecodeData data.bytecodeData
} }
logger.fine("Execute $patchName") logger.warn("Execute $patchName")
return try { return try {
patchInstance.execute(data) patchInstance.execute(data)

View File

@ -12,7 +12,8 @@ import org.jf.dexlib2.iface.Method
import org.jf.dexlib2.iface.instruction.Instruction import org.jf.dexlib2.iface.instruction.Instruction
import org.jf.dexlib2.iface.instruction.formats.Instruction21c import org.jf.dexlib2.iface.instruction.formats.Instruction21c
import org.jf.dexlib2.iface.reference.StringReference import org.jf.dexlib2.iface.reference.StringReference
import java.util.logging.Logger import org.slf4j.Logger
import org.slf4j.LoggerFactory
internal class MethodSignatureResolver( internal class MethodSignatureResolver(
private val classes: List<ClassDef>, private val classes: List<ClassDef>,
@ -20,7 +21,7 @@ internal class MethodSignatureResolver(
) { ) {
// These functions do not require the constructor values, so they can be static. // These functions do not require the constructor values, so they can be static.
companion object { companion object {
private val LOGGER: Logger = Logger.getLogger(::MethodSignatureResolver.name) private val logger: Logger = LoggerFactory.getLogger(MethodSignatureResolver::class.java)
fun resolveFromProxy( fun resolveFromProxy(
classProxy: app.revanced.patcher.util.proxy.ClassProxy, classProxy: app.revanced.patcher.util.proxy.ClassProxy,
@ -29,7 +30,7 @@ internal class MethodSignatureResolver(
for (method in classProxy.immutableClass.methods) { for (method in classProxy.immutableClass.methods) {
val result = compareSignatureToMethod(signature, method) ?: continue val result = compareSignatureToMethod(signature, method) ?: continue
LOGGER.fine("${signature.name} match to ${method.definingClass}->${method.name}") logger.trace("${signature.name} match to ${method.definingClass}->${method.name}")
return SignatureResolverResult( return SignatureResolverResult(
classProxy, classProxy,
@ -149,12 +150,12 @@ internal class MethodSignatureResolver(
fun resolve(patcherData: PatcherData) { fun resolve(patcherData: PatcherData) {
for (signature in methodSignatures) { for (signature in methodSignatures) {
val signatureName = signature.name val signatureName = signature.name
LOGGER.fine("Resolve $signatureName") logger.trace("Resolve $signatureName")
for (classDef in classes) { for (classDef in classes) {
for (method in classDef.methods) { for (method in classDef.methods) {
val patternScanData = compareSignatureToMethod(signature, method) ?: continue val patternScanData = compareSignatureToMethod(signature, method) ?: continue
LOGGER.fine("$signatureName match to ${method.definingClass}->${method.name}") logger.trace("$signatureName match to ${method.definingClass}->${method.name}")
// create class proxy, in case a patch needs mutability // create class proxy, in case a patch needs mutability
val classProxy = patcherData.bytecodeData.proxy(classDef) val classProxy = patcherData.bytecodeData.proxy(classDef)