Format with ktlint

bzip2
Graham 5 years ago
parent 10052a7a08
commit e9a9a8f962
  1. 6
      asm/src/main/java/dev/openrs2/asm/MemberRef.kt
  2. 6
      asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt
  3. 7
      asm/src/main/java/dev/openrs2/asm/StackMetadata.kt
  4. 3
      asm/src/main/java/dev/openrs2/asm/classpath/Library.kt
  5. 6
      asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.kt
  6. 7
      bundler/src/main/java/dev/openrs2/bundler/Bundler.kt
  7. 6
      bundler/src/main/java/dev/openrs2/bundler/transform/HostCheckTransformer.kt
  8. 19
      bundler/src/main/java/dev/openrs2/bundler/transform/MacResizeTransformer.kt
  9. 7
      bundler/src/main/java/dev/openrs2/bundler/transform/RightClickTransformer.kt
  10. 3
      common/src/main/java/dev/openrs2/common/collect/ForestDisjointSet.kt
  11. 12
      deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscator.kt
  12. 7
      deob-ast/src/main/java/dev/openrs2/deob/ast/util/ExprUtils.kt
  13. 15
      deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt
  14. 6
      deob/src/main/java/dev/openrs2/deob/transform/BitwiseOpTransformer.kt
  15. 34
      deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.kt
  16. 15
      deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.kt
  17. 17
      deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt
  18. 8
      deob/src/main/java/dev/openrs2/deob/transform/ResetTransformer.kt
  19. 6
      deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.kt

@ -1,6 +1,10 @@
package dev.openrs2.asm
import org.objectweb.asm.tree.*
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.FieldNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
data class MemberRef(val owner: String, val name: String, val desc: String) {
constructor(clazz: ClassNode, field: FieldNode) : this(clazz.name, field.name, field.desc)

@ -2,7 +2,11 @@ package dev.openrs2.asm
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.tree.*
import org.objectweb.asm.tree.FrameNode
import org.objectweb.asm.tree.IincInsnNode
import org.objectweb.asm.tree.LabelNode
import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.VarInsnNode
import org.objectweb.asm.tree.analysis.Analyzer
import org.objectweb.asm.tree.analysis.BasicInterpreter
import org.objectweb.asm.tree.analysis.BasicValue

@ -2,7 +2,12 @@ package dev.openrs2.asm
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.tree.*
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.InvokeDynamicInsnNode
import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MultiANewArrayInsnNode
data class StackMetadata(val pops: Int, val pushes: Int)

@ -16,7 +16,8 @@ import java.io.ByteArrayInputStream
import java.io.SequenceInputStream
import java.nio.file.Files
import java.nio.file.Path
import java.util.*
import java.util.HashSet
import java.util.TreeMap
import java.util.jar.JarEntry
import java.util.jar.JarInputStream
import java.util.jar.JarOutputStream

@ -17,9 +17,9 @@ object ClassForNameRemapper {
}
val invokestatic = match[1] as MethodInsnNode
return invokestatic.owner == "java/lang/Class"
&& invokestatic.name == "forName"
&& invokestatic.desc == "(Ljava/lang/String;)Ljava/lang/Class;"
return invokestatic.owner == "java/lang/Class" &&
invokestatic.name == "forName" &&
invokestatic.desc == "(Ljava/lang/String;)Ljava/lang/Class;"
}
fun remap(remapper: Remapper, method: MethodNode) {

@ -1,6 +1,11 @@
package dev.openrs2.bundler
import dev.openrs2.bundler.transform.*
import dev.openrs2.bundler.transform.BufferSizeTransformer
import dev.openrs2.bundler.transform.CachePathTransformer
import dev.openrs2.bundler.transform.HostCheckTransformer
import dev.openrs2.bundler.transform.LoadLibraryTransformer
import dev.openrs2.bundler.transform.MacResizeTransformer
import dev.openrs2.bundler.transform.RightClickTransformer
class Bundler {
companion object {

@ -36,7 +36,11 @@ class HostCheckTransformer : Transformer() {
}
val insn3 = it[2] as MethodInsnNode
if (insn3.owner != "java/lang/String" || insn3.name != "toLowerCase" || insn3.desc != "()Ljava/lang/String;") {
if (
insn3.owner != "java/lang/String" ||
insn3.name != "toLowerCase" ||
insn3.desc != "()Ljava/lang/String;"
) {
return@forEach
}

@ -6,7 +6,12 @@ import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.*
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.JumpInsnNode
import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
class MacResizeTransformer : Transformer() {
private var branchesRemoved = 0
@ -18,7 +23,11 @@ class MacResizeTransformer : Transformer() {
override fun transformCode(classPath: ClassPath, library: Library, clazz: ClassNode, method: MethodNode): Boolean {
DETECT_MAC_MATCHER.match(method).forEach {
val getstatic = it[0] as FieldInsnNode
if (getstatic.owner == "loader" || getstatic.owner == clazz.name || getstatic.desc != "Ljava/lang/String;") {
if (
getstatic.owner == "loader" ||
getstatic.owner == clazz.name ||
getstatic.desc != "Ljava/lang/String;"
) {
return@forEach
}
@ -28,7 +37,11 @@ class MacResizeTransformer : Transformer() {
}
val invokevirtual = it[2] as MethodInsnNode
if (invokevirtual.owner != "java/lang/String" || invokevirtual.name != "startsWith" || invokevirtual.desc != "(Ljava/lang/String;)Z") {
if (
invokevirtual.owner != "java/lang/String" ||
invokevirtual.name != "startsWith" ||
invokevirtual.desc != "(Ljava/lang/String;)Z"
) {
return@forEach
}

@ -5,7 +5,12 @@ import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.*
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.InsnList
import org.objectweb.asm.tree.InsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
class RightClickTransformer : Transformer() {
private var metaDownCalls = 0

@ -1,7 +1,6 @@
package dev.openrs2.common.collect
import java.util.*
import kotlin.NoSuchElementException
import java.util.ArrayDeque
class ForestDisjointSet<T> : DisjointSet<T> {
private class Node<T>(val value: T) : DisjointSet.Partition<T> {

@ -9,7 +9,17 @@ import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSol
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver
import com.github.javaparser.utils.SourceRoot
import dev.openrs2.deob.ast.transform.*
import dev.openrs2.deob.ast.transform.AddSubTransformer
import dev.openrs2.deob.ast.transform.BinaryExprOrderTransformer
import dev.openrs2.deob.ast.transform.BitMaskTransformer
import dev.openrs2.deob.ast.transform.ComplementTransformer
import dev.openrs2.deob.ast.transform.EncloseTransformer
import dev.openrs2.deob.ast.transform.IfElseTransformer
import dev.openrs2.deob.ast.transform.NegativeLiteralTransformer
import dev.openrs2.deob.ast.transform.NewInstanceTransformer
import dev.openrs2.deob.ast.transform.TernaryTransformer
import dev.openrs2.deob.ast.transform.UnencloseTransformer
import dev.openrs2.deob.ast.transform.ValueOfTransformer
import java.nio.file.Path
import java.nio.file.Paths
import java.util.function.Function

@ -1,6 +1,11 @@
package dev.openrs2.deob.ast.util
import com.github.javaparser.ast.expr.*
import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.expr.BooleanLiteralExpr
import com.github.javaparser.ast.expr.Expression
import com.github.javaparser.ast.expr.IntegerLiteralExpr
import com.github.javaparser.ast.expr.LongLiteralExpr
import com.github.javaparser.ast.expr.UnaryExpr
fun Expression.isIntegerOrLongLiteral(): Boolean {
return isIntegerLiteralExpr || isLongLiteralExpr

@ -8,7 +8,20 @@ import dev.openrs2.asm.classpath.Library.Companion.readPack
import dev.openrs2.bundler.Bundler
import dev.openrs2.deob.SignedClassUtils.move
import dev.openrs2.deob.remap.PrefixRemapper.create
import dev.openrs2.deob.transform.*
import dev.openrs2.deob.transform.AccessTransformer
import dev.openrs2.deob.transform.BitShiftTransformer
import dev.openrs2.deob.transform.BitwiseOpTransformer
import dev.openrs2.deob.transform.CanvasTransformer
import dev.openrs2.deob.transform.CounterTransformer
import dev.openrs2.deob.transform.DummyArgTransformer
import dev.openrs2.deob.transform.DummyLocalTransformer
import dev.openrs2.deob.transform.ExceptionTracingTransformer
import dev.openrs2.deob.transform.FieldOrderTransformer
import dev.openrs2.deob.transform.OpaquePredicateTransformer
import dev.openrs2.deob.transform.OriginalNameTransformer
import dev.openrs2.deob.transform.RemapTransformer
import dev.openrs2.deob.transform.ResetTransformer
import dev.openrs2.deob.transform.UnusedArgTransformer
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

@ -8,7 +8,11 @@ import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.hasCode
import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.*
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.InsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.VarInsnNode
import kotlin.streams.asSequence
class BitwiseOpTransformer : Transformer() {

@ -3,9 +3,17 @@ package dev.openrs2.deob.transform
import com.github.michaelbull.logging.InlineLogger
import com.google.common.collect.HashMultimap
import com.google.common.collect.Multimap
import dev.openrs2.asm.*
import dev.openrs2.asm.InsnMatcher
import dev.openrs2.asm.MemberRef
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.createIntConstant
import dev.openrs2.asm.deleteSimpleExpression
import dev.openrs2.asm.intConstant
import dev.openrs2.asm.nextReal
import dev.openrs2.asm.pure
import dev.openrs2.asm.replaceSimpleExpression
import dev.openrs2.asm.stackMetadata
import dev.openrs2.asm.transform.Transformer
import dev.openrs2.common.collect.DisjointSet
import dev.openrs2.deob.ArgRef
@ -14,7 +22,12 @@ import dev.openrs2.deob.analysis.IntValue
import dev.openrs2.deob.analysis.SourcedIntValue
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.tree.*
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.JumpInsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.VarInsnNode
import org.objectweb.asm.tree.analysis.Analyzer
class DummyArgTransformer : Transformer() {
@ -247,7 +260,8 @@ class DummyArgTransformer : Transformer() {
BranchResult.NEVER_TAKEN -> neverTakenBranches.add(insn as JumpInsnNode)
}
}
Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPNE, Opcodes.IF_ICMPLT, Opcodes.IF_ICMPGE, Opcodes.IF_ICMPGT, Opcodes.IF_ICMPLE -> {
Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPNE, Opcodes.IF_ICMPLT, Opcodes.IF_ICMPGE, Opcodes.IF_ICMPGT,
Opcodes.IF_ICMPLE -> {
val value1 = frame.getStack(stackSize - 2)
val value2 = frame.getStack(stackSize - 1)
if (value1 !is IntValue.Constant || value2 !is IntValue.Constant) {
@ -340,8 +354,18 @@ class DummyArgTransformer : Transformer() {
companion object {
private val logger = InlineLogger()
private val CONDITIONAL_CALL_MATCHER =
InsnMatcher.compile("ILOAD (IFEQ | IFNE | (ICONST | BIPUSH | SIPUSH | LDC) (IF_ICMPEQ | IF_ICMPNE | IF_ICMPLT | IF_ICMPGE | IF_ICMPGT | IF_ICMPLE)) ALOAD? (ICONST | FCONST | DCONST | BIPUSH | SIPUSH | LDC | ACONST_NULL CHECKCAST)+ (INVOKEVIRTUAL | INVOKESTATIC | INVOKEINTERFACE)")
private val CONDITIONAL_CALL_MATCHER = InsnMatcher.compile(
"""
ILOAD
(IFEQ | IFNE |
(ICONST | BIPUSH | SIPUSH | LDC)
(IF_ICMPEQ | IF_ICMPNE | IF_ICMPLT | IF_ICMPGE | IF_ICMPGT | IF_ICMPLE)
)
ALOAD?
(ICONST | FCONST | DCONST | BIPUSH | SIPUSH | LDC | ACONST_NULL CHECKCAST)+
(INVOKEVIRTUAL | INVOKESTATIC | INVOKEINTERFACE)
"""
)
private fun evaluateUnaryBranch(opcode: Int, values: Set<Int>): BranchResult {
require(values.isNotEmpty())

@ -41,7 +41,18 @@ class ExceptionTracingTransformer : Transformer() {
companion object {
private val logger = InlineLogger()
private val CATCH_MATCHER =
InsnMatcher.compile("ASTORE ALOAD (| LDC INVOKESTATIC | NEW DUP (LDC INVOKESPECIAL | INVOKESPECIAL LDC INVOKEVIRTUAL) ((ILOAD | LLOAD | FLOAD | DLOAD | (ALOAD IFNULL LDC GOTO LDC) | BIPUSH) INVOKEVIRTUAL)* INVOKEVIRTUAL INVOKESTATIC) ATHROW")
private val CATCH_MATCHER = InsnMatcher.compile(
"""
ASTORE
ALOAD
(| LDC INVOKESTATIC |
NEW DUP
(LDC INVOKESPECIAL | INVOKESPECIAL LDC INVOKEVIRTUAL)
((ILOAD | LLOAD | FLOAD | DLOAD | (ALOAD IFNULL LDC GOTO LDC) | BIPUSH) INVOKEVIRTUAL)*
INVOKEVIRTUAL INVOKESTATIC
)
ATHROW
"""
)
}
}

@ -8,7 +8,12 @@ import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.hasCode
import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.*
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.JumpInsnNode
import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.VarInsnNode
class OpaquePredicateTransformer : Transformer() {
private val flowObstructors = mutableSetOf<MemberRef>()
@ -105,8 +110,14 @@ class OpaquePredicateTransformer : Transformer() {
companion object {
private val logger = InlineLogger()
private val FLOW_OBSTRUCTOR_INITIALIZER_MATCHER =
InsnMatcher.compile("(GETSTATIC | ILOAD) IFEQ (((GETSTATIC ISTORE)? IINC ILOAD) | ((GETSTATIC | ILOAD) IFEQ ICONST GOTO ICONST)) PUTSTATIC")
private val FLOW_OBSTRUCTOR_INITIALIZER_MATCHER = InsnMatcher.compile(
"""
(GETSTATIC | ILOAD)
IFEQ
(((GETSTATIC ISTORE)? IINC ILOAD) | ((GETSTATIC | ILOAD) IFEQ ICONST GOTO ICONST))
PUTSTATIC
"""
)
private val OPAQUE_PREDICATE_MATCHER = InsnMatcher.compile("(GETSTATIC | ILOAD) (IFEQ | IFNE)")
private val STORE_MATCHER = InsnMatcher.compile("GETSTATIC ISTORE")
}

@ -9,7 +9,13 @@ import dev.openrs2.asm.nextReal
import dev.openrs2.asm.removeDeadCode
import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.*
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.InsnNode
import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.VarInsnNode
class ResetTransformer : Transformer() {
private val resetMethods = mutableSetOf<MemberRef>()

@ -14,7 +14,11 @@ import dev.openrs2.deob.analysis.ConstSourceValue
import dev.openrs2.deob.remap.TypedRemapper
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.tree.*
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.VarInsnNode
import org.objectweb.asm.tree.analysis.Analyzer
class UnusedArgTransformer : Transformer() {

Loading…
Cancel
Save