1
mirror of https://github.com/revanced/revanced-patcher synced 2025-09-06 16:38:50 +02:00

Compare commits

..

3 Commits

Author SHA1 Message Date
semantic-release-bot
1f4bc5079f chore(release): 1.8.0 [skip ci]
# [1.8.0](https://github.com/revanced/revanced-patcher/compare/v1.7.2...v1.8.0) (2022-06-22)

### Features

* logging class ([caf2745](caf2745805))
2022-06-22 23:25:29 +00:00
oSumAtrIX
caf2745805 feat: logging class 2022-06-23 01:23:35 +02:00
oSumAtrIX
a4529c3fee refactor: logging and exception strings 2022-06-22 16:47:58 +02:00
7 changed files with 54 additions and 46 deletions

View File

@@ -1,3 +1,10 @@
# [1.8.0](https://github.com/revanced/revanced-patcher/compare/v1.7.2...v1.8.0) (2022-06-22)
### Features
* logging class ([caf2745](https://github.com/revanced/revanced-patcher/commit/caf2745805ffd4b59fa81e79cc489b1a1a5c5d89))
## [1.7.2](https://github.com/revanced/revanced-patcher/compare/v1.7.1...v1.7.2) (2022-06-22)

View File

@@ -1,2 +1,2 @@
kotlin.code.style = official
version = 1.7.2
version = 1.8.0

View File

@@ -1,15 +0,0 @@
package app.revanced.patcher
interface PatchLogger {
fun error(msg: String)
fun warn(msg: String)
fun info(msg: String)
fun trace(msg: String)
}
internal object NoopPatchLogger : PatchLogger {
override fun error(msg: String) {}
override fun warn(msg: String) {}
override fun info(msg: String) {}
override fun trace(msg: String) {}
}

View File

@@ -78,7 +78,7 @@ class Patcher(private val options: PatcherOptions) {
}
} else {
logger.info("Decoding resources manually because resource decoding is disabled!")
logger.info("Decoding AndroidManifest.xml manually because resource patching is disabled")
// create decoder for the resource table
val decoder = ResAttrDecoder()
@@ -102,8 +102,9 @@ class Patcher(private val options: PatcherOptions) {
packageMetadata.metaInfo.versionInfo = resourceTable.versionInfo
packageMetadata.metaInfo.sdkInfo = resourceTable.sdkInfo
// read dex files
logger.info("Reading input as dex file")
// read dex files
val dexFile = MultiDexIO.readDexFile(true, options.inputFile, NAMER, null, null)
// get the opcodes
opcodes = dexFile.opcodes
@@ -127,25 +128,28 @@ class Patcher(private val options: PatcherOptions) {
callback: (File) -> Unit
) {
for (file in files) {
var modified = false
for (classDef in MultiDexIO.readDexFile(true, file, NAMER, null, null).classes) {
val e = data.bytecodeData.classes.internalClasses.findIndexed { it.type == classDef.type }
if (e != null) {
if (throwOnDuplicates) {
throw Exception("Class ${classDef.type} has already been added to the patcher.")
}
val (_, idx) = e
if (allowedOverwrites.contains(classDef.type)) {
data.bytecodeData.classes.internalClasses[idx] = classDef
modified = true
}
val type = classDef.type
val existingClass = data.bytecodeData.classes.internalClasses.findIndexed { it.type == type }
if (existingClass == null) {
if (throwOnDuplicates) throw Exception("Class $type has already been added to the patcher")
logger.trace("Merging $type")
data.bytecodeData.classes.internalClasses.add(classDef)
callback(file)
continue
}
data.bytecodeData.classes.internalClasses.add(classDef)
modified = true
}
if (modified) {
logger.trace("Added file ${file.name}")
if (!allowedOverwrites.contains(type)) continue
logger.trace("Overwriting $type")
val index = existingClass.second
data.bytecodeData.classes.internalClasses[index] = classDef
callback(file)
}
}
@@ -189,15 +193,13 @@ class Patcher(private val options: PatcherOptions) {
val resDirectory = cacheDirectory.resolve("res")
val includedFiles = metaInfo.usesFramework.ids.map { id ->
androlibResources.getFrameworkApk(
id,
metaInfo.usesFramework.tag
id, metaInfo.usesFramework.tag
)
}.toTypedArray()
logger.trace("Packaging using aapt")
androlibResources.aaptPackage(
aaptFile, manifestFile, resDirectory, null,
null, includedFiles
aaptFile, manifestFile, resDirectory, null, null, includedFiles
)
resourceFile = aaptFile
@@ -226,9 +228,7 @@ class Patcher(private val options: PatcherOptions) {
return PatcherResult(
dexFiles.map {
app.revanced.patcher.util.dex.DexFile(it.key, it.value.readAt(0))
},
metaInfo.doNotCompress.toList(),
resourceFile
}, metaInfo.doNotCompress.toList(), resourceFile
)
}
@@ -247,15 +247,16 @@ class Patcher(private val options: PatcherOptions) {
* @return The result of executing the [patch].
*/
private fun applyPatch(
patch: Class<out Patch<Data>>,
appliedPatches: MutableList<String>
patch: Class<out Patch<Data>>, appliedPatches: MutableList<String>
): PatchResult {
val patchName = patch.patchName
logger.trace("Applying patch $patchName")
// if the patch has already applied silently skip it
if (appliedPatches.contains(patchName)) {
logger.trace("Skipping patch $patchName because it has already been applied")
return PatchResultSuccess()
}
appliedPatches.add(patchName)
@@ -290,6 +291,7 @@ class Patcher(private val options: PatcherOptions) {
}
logger.trace("Executing patch $patchName of type: ${if (isResourcePatch) "resource" else "bytecode"}")
return try {
patchInstance.execute(data)
} catch (e: Exception) {
@@ -305,8 +307,7 @@ class Patcher(private val options: PatcherOptions) {
* If the [Patch] failed to apply, an Exception will always be returned to the wrapping Result object.
*/
fun applyPatches(
stopOnError: Boolean = false,
callback: (Class<out Patch<Data>>, Boolean) -> Unit = { _, _ -> }
stopOnError: Boolean = false, callback: (Class<out Patch<Data>>, Boolean) -> Unit = { _, _ -> }
): Map<String, Result<PatchResultSuccess>> {
logger.trace("Applying all patches")
val appliedPatches = mutableListOf<String>()

View File

@@ -1,5 +1,7 @@
package app.revanced.patcher
import app.revanced.patcher.logging.impl.NopLogger
import app.revanced.patcher.logging.Logger
import java.io.File
/**
@@ -17,5 +19,5 @@ data class PatcherOptions(
internal val patchResources: Boolean = false,
internal val aaptPath: String = "",
internal val frameworkFolderLocation: String? = null,
internal val logger: PatchLogger = NoopPatchLogger
internal val logger: Logger = NopLogger
)

View File

@@ -0,0 +1,8 @@
package app.revanced.patcher.logging
interface Logger {
fun error(msg: String) {}
fun warn(msg: String) {}
fun info(msg: String) {}
fun trace(msg: String) {}
}

View File

@@ -0,0 +1,5 @@
package app.revanced.patcher.logging.impl
import app.revanced.patcher.logging.Logger
object NopLogger : Logger