You've already forked revanced-patcher
mirror of
https://github.com/revanced/revanced-patcher
synced 2025-09-13 18:30:49 +02:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1f4bc5079f | ||
![]() |
caf2745805 | ||
![]() |
a4529c3fee |
@@ -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)
|
## [1.7.2](https://github.com/revanced/revanced-patcher/compare/v1.7.1...v1.7.2) (2022-06-22)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 1.7.2
|
version = 1.8.0
|
||||||
|
@@ -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) {}
|
|
||||||
}
|
|
@@ -78,7 +78,7 @@ class Patcher(private val options: PatcherOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} 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
|
// create decoder for the resource table
|
||||||
val decoder = ResAttrDecoder()
|
val decoder = ResAttrDecoder()
|
||||||
@@ -102,8 +102,9 @@ class Patcher(private val options: PatcherOptions) {
|
|||||||
packageMetadata.metaInfo.versionInfo = resourceTable.versionInfo
|
packageMetadata.metaInfo.versionInfo = resourceTable.versionInfo
|
||||||
packageMetadata.metaInfo.sdkInfo = resourceTable.sdkInfo
|
packageMetadata.metaInfo.sdkInfo = resourceTable.sdkInfo
|
||||||
|
|
||||||
// read dex files
|
|
||||||
logger.info("Reading input as dex file")
|
logger.info("Reading input as dex file")
|
||||||
|
|
||||||
|
// read dex files
|
||||||
val dexFile = MultiDexIO.readDexFile(true, options.inputFile, NAMER, null, null)
|
val dexFile = MultiDexIO.readDexFile(true, options.inputFile, NAMER, null, null)
|
||||||
// get the opcodes
|
// get the opcodes
|
||||||
opcodes = dexFile.opcodes
|
opcodes = dexFile.opcodes
|
||||||
@@ -127,25 +128,28 @@ class Patcher(private val options: PatcherOptions) {
|
|||||||
callback: (File) -> Unit
|
callback: (File) -> Unit
|
||||||
) {
|
) {
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
var modified = false
|
|
||||||
for (classDef in MultiDexIO.readDexFile(true, file, NAMER, null, null).classes) {
|
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
|
||||||
if (e != null) {
|
|
||||||
if (throwOnDuplicates) {
|
val existingClass = data.bytecodeData.classes.internalClasses.findIndexed { it.type == type }
|
||||||
throw Exception("Class ${classDef.type} has already been added to the patcher.")
|
if (existingClass == null) {
|
||||||
}
|
if (throwOnDuplicates) throw Exception("Class $type has already been added to the patcher")
|
||||||
val (_, idx) = e
|
|
||||||
if (allowedOverwrites.contains(classDef.type)) {
|
logger.trace("Merging $type")
|
||||||
data.bytecodeData.classes.internalClasses[idx] = classDef
|
data.bytecodeData.classes.internalClasses.add(classDef)
|
||||||
modified = true
|
|
||||||
}
|
callback(file)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
data.bytecodeData.classes.internalClasses.add(classDef)
|
|
||||||
modified = true
|
if (!allowedOverwrites.contains(type)) continue
|
||||||
}
|
|
||||||
if (modified) {
|
logger.trace("Overwriting $type")
|
||||||
logger.trace("Added file ${file.name}")
|
|
||||||
|
val index = existingClass.second
|
||||||
|
data.bytecodeData.classes.internalClasses[index] = classDef
|
||||||
|
|
||||||
callback(file)
|
callback(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,15 +193,13 @@ class Patcher(private val options: PatcherOptions) {
|
|||||||
val resDirectory = cacheDirectory.resolve("res")
|
val resDirectory = cacheDirectory.resolve("res")
|
||||||
val includedFiles = metaInfo.usesFramework.ids.map { id ->
|
val includedFiles = metaInfo.usesFramework.ids.map { id ->
|
||||||
androlibResources.getFrameworkApk(
|
androlibResources.getFrameworkApk(
|
||||||
id,
|
id, metaInfo.usesFramework.tag
|
||||||
metaInfo.usesFramework.tag
|
|
||||||
)
|
)
|
||||||
}.toTypedArray()
|
}.toTypedArray()
|
||||||
|
|
||||||
logger.trace("Packaging using aapt")
|
logger.trace("Packaging using aapt")
|
||||||
androlibResources.aaptPackage(
|
androlibResources.aaptPackage(
|
||||||
aaptFile, manifestFile, resDirectory, null,
|
aaptFile, manifestFile, resDirectory, null, null, includedFiles
|
||||||
null, includedFiles
|
|
||||||
)
|
)
|
||||||
|
|
||||||
resourceFile = aaptFile
|
resourceFile = aaptFile
|
||||||
@@ -226,9 +228,7 @@ class Patcher(private val options: PatcherOptions) {
|
|||||||
return PatcherResult(
|
return PatcherResult(
|
||||||
dexFiles.map {
|
dexFiles.map {
|
||||||
app.revanced.patcher.util.dex.DexFile(it.key, it.value.readAt(0))
|
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].
|
* @return The result of executing the [patch].
|
||||||
*/
|
*/
|
||||||
private fun applyPatch(
|
private fun applyPatch(
|
||||||
patch: Class<out Patch<Data>>,
|
patch: Class<out Patch<Data>>, appliedPatches: MutableList<String>
|
||||||
appliedPatches: MutableList<String>
|
|
||||||
): PatchResult {
|
): PatchResult {
|
||||||
val patchName = patch.patchName
|
val patchName = patch.patchName
|
||||||
|
|
||||||
logger.trace("Applying patch $patchName")
|
logger.trace("Applying 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.trace("Skipping patch $patchName because it has already been applied")
|
logger.trace("Skipping patch $patchName because it has already been applied")
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
appliedPatches.add(patchName)
|
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"}")
|
logger.trace("Executing patch $patchName of type: ${if (isResourcePatch) "resource" else "bytecode"}")
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
patchInstance.execute(data)
|
patchInstance.execute(data)
|
||||||
} catch (e: Exception) {
|
} 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.
|
* If the [Patch] failed to apply, an Exception will always be returned to the wrapping Result object.
|
||||||
*/
|
*/
|
||||||
fun applyPatches(
|
fun applyPatches(
|
||||||
stopOnError: Boolean = false,
|
stopOnError: Boolean = false, callback: (Class<out Patch<Data>>, Boolean) -> Unit = { _, _ -> }
|
||||||
callback: (Class<out Patch<Data>>, Boolean) -> Unit = { _, _ -> }
|
|
||||||
): Map<String, Result<PatchResultSuccess>> {
|
): Map<String, Result<PatchResultSuccess>> {
|
||||||
logger.trace("Applying all patches")
|
logger.trace("Applying all patches")
|
||||||
val appliedPatches = mutableListOf<String>()
|
val appliedPatches = mutableListOf<String>()
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
package app.revanced.patcher
|
package app.revanced.patcher
|
||||||
|
|
||||||
|
import app.revanced.patcher.logging.impl.NopLogger
|
||||||
|
import app.revanced.patcher.logging.Logger
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,5 +19,5 @@ data class PatcherOptions(
|
|||||||
internal val patchResources: Boolean = false,
|
internal val patchResources: Boolean = false,
|
||||||
internal val aaptPath: String = "",
|
internal val aaptPath: String = "",
|
||||||
internal val frameworkFolderLocation: String? = null,
|
internal val frameworkFolderLocation: String? = null,
|
||||||
internal val logger: PatchLogger = NoopPatchLogger
|
internal val logger: Logger = NopLogger
|
||||||
)
|
)
|
||||||
|
8
src/main/kotlin/app/revanced/patcher/logging/Logger.kt
Normal file
8
src/main/kotlin/app/revanced/patcher/logging/Logger.kt
Normal 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) {}
|
||||||
|
}
|
@@ -0,0 +1,5 @@
|
|||||||
|
package app.revanced.patcher.logging.impl
|
||||||
|
|
||||||
|
import app.revanced.patcher.logging.Logger
|
||||||
|
|
||||||
|
object NopLogger : Logger
|
Reference in New Issue
Block a user