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
7 Commits
v1.0.0-dev
...
v1.0.0-dev
Author | SHA1 | Date | |
---|---|---|---|
![]() |
14f7667156 | ||
![]() |
cd57a8c9a0 | ||
![]() |
0d3beb353d | ||
![]() |
ddef338631 | ||
![]() |
fc4b673087 | ||
![]() |
8d1bb5f3d9 | ||
![]() |
c8a017a4c0 |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,3 +1,17 @@
|
|||||||
|
# [1.0.0-dev.6](https://github.com/ReVancedTeam/revanced-patcher/compare/v1.0.0-dev.5...v1.0.0-dev.6) (2022-03-24)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **MethodResolver:** strip labels nodes so opcode patterns match ([cd57a8c](https://github.com/ReVancedTeam/revanced-patcher/commit/cd57a8c9a0db7e3ae5ad0bca202e5955930319ab))
|
||||||
|
|
||||||
|
# [1.0.0-dev.5](https://github.com/ReVancedTeam/revanced-patcher/compare/v1.0.0-dev.4...v1.0.0-dev.5) (2022-03-24)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **MethodResolver:** strip labels and line numbers so opcode patterns match ([8d1bb5f](https://github.com/ReVancedTeam/revanced-patcher/commit/8d1bb5f3d9da544cf6e3e3848bfcc56327cde810))
|
||||||
|
|
||||||
# [1.0.0-dev.4](https://github.com/ReVancedTeam/revanced-patcher/compare/v1.0.0-dev.3...v1.0.0-dev.4) (2022-03-23)
|
# [1.0.0-dev.4](https://github.com/ReVancedTeam/revanced-patcher/compare/v1.0.0-dev.3...v1.0.0-dev.4) (2022-03-23)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 1.0.0-dev.4
|
version = 1.0.0-dev.6
|
||||||
|
@@ -7,9 +7,9 @@ import app.revanced.patcher.cache.PatternScanData
|
|||||||
import app.revanced.patcher.signature.Signature
|
import app.revanced.patcher.signature.Signature
|
||||||
import app.revanced.patcher.util.ExtraTypes
|
import app.revanced.patcher.util.ExtraTypes
|
||||||
import org.objectweb.asm.Type
|
import org.objectweb.asm.Type
|
||||||
import org.objectweb.asm.tree.ClassNode
|
import org.objectweb.asm.tree.*
|
||||||
import org.objectweb.asm.tree.InsnList
|
import kotlin.reflect.KType
|
||||||
import org.objectweb.asm.tree.MethodNode
|
import kotlin.reflect.typeOf
|
||||||
|
|
||||||
private val logger = KotlinLogging.logger("MethodResolver")
|
private val logger = KotlinLogging.logger("MethodResolver")
|
||||||
|
|
||||||
@@ -21,16 +21,16 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
|
|||||||
for (method in methods) {
|
for (method in methods) {
|
||||||
for (signature in signatures) {
|
for (signature in signatures) {
|
||||||
if (methodMap.containsKey(signature.name)) { // method already found for this sig
|
if (methodMap.containsKey(signature.name)) { // method already found for this sig
|
||||||
logger.debug { "Sig ${signature.name} already found, skipping." }
|
logger.trace { "Sig ${signature.name} already found, skipping." }
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
logger.debug { "Resolving sig ${signature.name}: ${classNode.name} / ${method.name}" }
|
logger.trace { "Resolving sig ${signature.name}: ${classNode.name} / ${method.name}" }
|
||||||
val (r, sr) = cmp(method, signature)
|
val (r, sr) = cmp(method, signature)
|
||||||
if (!r || sr == null) {
|
if (!r || sr == null) {
|
||||||
logger.debug { "Compare result for sig ${signature.name} has failed!" }
|
logger.trace { "Compare result for sig ${signature.name} has failed!" }
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
logger.debug { "Method for sig ${signature.name} found!" }
|
logger.trace { "Method for sig ${signature.name} found!" }
|
||||||
methodMap[signature.name] = PatchData(
|
methodMap[signature.name] = PatchData(
|
||||||
classNode,
|
classNode,
|
||||||
method,
|
method,
|
||||||
@@ -71,7 +71,7 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
|
|||||||
signature.returns?.let { _ ->
|
signature.returns?.let { _ ->
|
||||||
val methodReturns = Type.getReturnType(method.desc).convertObject()
|
val methodReturns = Type.getReturnType(method.desc).convertObject()
|
||||||
if (signature.returns != methodReturns) {
|
if (signature.returns != methodReturns) {
|
||||||
logger.debug {
|
logger.trace {
|
||||||
"""
|
"""
|
||||||
Comparing sig ${signature.name}: invalid return type:
|
Comparing sig ${signature.name}: invalid return type:
|
||||||
expected ${signature.returns},
|
expected ${signature.returns},
|
||||||
@@ -84,7 +84,7 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
|
|||||||
|
|
||||||
signature.accessors?.let { _ ->
|
signature.accessors?.let { _ ->
|
||||||
if (signature.accessors != method.access) {
|
if (signature.accessors != method.access) {
|
||||||
logger.debug {
|
logger.trace {
|
||||||
"""
|
"""
|
||||||
Comparing sig ${signature.name}: invalid accessors:
|
Comparing sig ${signature.name}: invalid accessors:
|
||||||
expected ${signature.accessors},
|
expected ${signature.accessors},
|
||||||
@@ -98,7 +98,7 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
|
|||||||
signature.parameters?.let { _ ->
|
signature.parameters?.let { _ ->
|
||||||
val parameters = Type.getArgumentTypes(method.desc).convertObjects()
|
val parameters = Type.getArgumentTypes(method.desc).convertObjects()
|
||||||
if (!signature.parameters.contentEquals(parameters)) {
|
if (!signature.parameters.contentEquals(parameters)) {
|
||||||
logger.debug {
|
logger.trace {
|
||||||
"""
|
"""
|
||||||
Comparing sig ${signature.name}: invalid parameter types:
|
Comparing sig ${signature.name}: invalid parameter types:
|
||||||
expected ${signature.parameters.joinToString()}},
|
expected ${signature.parameters.joinToString()}},
|
||||||
@@ -112,7 +112,7 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
|
|||||||
signature.opcodes?.let { _ ->
|
signature.opcodes?.let { _ ->
|
||||||
val result = method.instructions.scanFor(signature.opcodes)
|
val result = method.instructions.scanFor(signature.opcodes)
|
||||||
if (!result.found) {
|
if (!result.found) {
|
||||||
logger.debug { "Comparing sig ${signature.name}: invalid opcode pattern" }
|
logger.trace { "Comparing sig ${signature.name}: invalid opcode pattern" }
|
||||||
return@cmp false to null
|
return@cmp false to null
|
||||||
}
|
}
|
||||||
return@cmp true to result
|
return@cmp true to result
|
||||||
@@ -123,19 +123,21 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private operator fun ClassNode.component1(): ClassNode {
|
private operator fun ClassNode.component1() = this
|
||||||
return this
|
private operator fun ClassNode.component2() = this.methods
|
||||||
}
|
|
||||||
|
|
||||||
private operator fun ClassNode.component2(): List<MethodNode> {
|
|
||||||
return this.methods
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun InsnList.scanFor(pattern: IntArray): ScanResult {
|
private fun InsnList.scanFor(pattern: IntArray): ScanResult {
|
||||||
for (i in 0 until this.size()) {
|
for (i in 0 until this.size()) {
|
||||||
var occurrence = 0
|
var occurrence = 0
|
||||||
while (i + occurrence < this.size()) {
|
while (i + occurrence < this.size()) {
|
||||||
if (this[i + occurrence].opcode != pattern[occurrence]) break
|
val n = this[i + occurrence]
|
||||||
|
if (
|
||||||
|
!n.anyOf(
|
||||||
|
typeOf<LabelNode>(),
|
||||||
|
typeOf<LineNumberNode>()
|
||||||
|
) &&
|
||||||
|
n.opcode != pattern[occurrence]
|
||||||
|
) break
|
||||||
if (++occurrence >= pattern.size) {
|
if (++occurrence >= pattern.size) {
|
||||||
val current = i + occurrence
|
val current = i + occurrence
|
||||||
return ScanResult(true, current - pattern.size, current)
|
return ScanResult(true, current - pattern.size, current)
|
||||||
@@ -157,3 +159,7 @@ private fun Type.convertObject(): Type {
|
|||||||
private fun Array<Type>.convertObjects(): Array<Type> {
|
private fun Array<Type>.convertObjects(): Array<Type> {
|
||||||
return this.map { it.convertObject() }.toTypedArray()
|
return this.map { it.convertObject() }.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun AbstractInsnNode.anyOf(vararg types: KType): Boolean {
|
||||||
|
return types.any { it.javaClass.isAssignableFrom(this.javaClass) }
|
||||||
|
}
|
||||||
|
@@ -79,10 +79,7 @@ internal class Io(
|
|||||||
jos.putNextEntry(JarEntry(name))
|
jos.putNextEntry(JarEntry(name))
|
||||||
|
|
||||||
// parse the patched class to a byte array and write it to the output stream
|
// parse the patched class to a byte array and write it to the output stream
|
||||||
val cw = ClassWriter(
|
val cw = ClassWriter(classReaders[name]!!, ClassWriter.COMPUTE_MAXS)
|
||||||
classReaders[name]!!,
|
|
||||||
ClassWriter.COMPUTE_FRAMES or ClassWriter.COMPUTE_MAXS
|
|
||||||
)
|
|
||||||
patchedClass.accept(cw)
|
patchedClass.accept(cw)
|
||||||
jos.write(cw.toByteArray())
|
jos.write(cw.toByteArray())
|
||||||
|
|
||||||
|
@@ -38,7 +38,8 @@ private class NodeStringBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
if (sb.isEmpty()) return ""
|
||||||
val s = sb.toString()
|
val s = sb.toString()
|
||||||
return s.substring(0 until s.length - 2) // remove the last ", "
|
return s.substring(0 .. (s.length - 2).coerceAtLeast(0)) // remove the last ", "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user