Skip to content

Commit

Permalink
Resolve small bug in mappings redundancy transformation where private…
Browse files Browse the repository at this point in the history
… methods with the same signature were considered to be inherited
  • Loading branch information
770grappenmaker committed Apr 11, 2024
1 parent 8c14ae5 commit 70eac74
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {
}

group = "com.grappenmaker"
version = "0.1.3"
version = "0.1.4"

kotlin {
jvmToolchain(8)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/grappenmaker/mappings/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public fun Mappings.asASMMapping(
/**
* Returns whether the methods represented by this [MappedMethod] is a data method, that is, if this method
* is [hashCode], [toString], [equals] or an initializer, like a constructor or init {} block
* (this means that the jvm names are <init> and <clinit>, respectively)
* (this means that the jvm names are &lt;init&gt; and &lt;clinit&gt;, respectively)
*/
public fun MappedMethod.isData(): Boolean = desc == "(Ljava/lang/Object;)Z" && names.first() == "equals" ||
desc == "()I" && names.first() == "hashCode" ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.grappenmaker.mappings

import org.objectweb.asm.Type
import java.net.URL

/**
* Represents Proguard debug deobfuscation mappings. Note that Proguard only supports two mappings namespaces.
Expand Down
14 changes: 11 additions & 3 deletions src/main/kotlin/com/grappenmaker/mappings/Transformations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package com.grappenmaker.mappings

import org.objectweb.asm.ClassReader
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode
import java.util.jar.JarFile
import kotlin.experimental.ExperimentalTypeInference
Expand Down Expand Up @@ -322,12 +323,19 @@ public fun Mappings.removeRedundancy(bytesProvider: (name: String) -> ByteArray?

walkInheritance(bytesProvider, name).forEach { curr ->
val target = if (curr == name) ourSigs else superSigs
bytesProvider(curr)?.let { b -> ClassNode().also { ClassReader(b).accept(it, 0) } }
?.methods?.forEach { m -> target += "${m.name}${m.desc}" }
val bytes = bytesProvider(curr)

if (bytes != null) {
val methods = ClassNode().also { ClassReader(bytes).accept(it, 0) }.methods
val toConsider = if (curr == name) methods
else methods.filter { it.access and Opcodes.ACC_PRIVATE == 0 }

target += toConsider.map { it.name + it.desc }
}
}

oc.copy(methods = oc.methods.filter {
val sig = "${it.names.first()}${it.desc}"
val sig = it.names.first() + it.desc
sig in ourSigs && sig !in superSigs && !it.isData()
})
}
Expand Down

0 comments on commit 70eac74

Please sign in to comment.