Skip to content

Commit

Permalink
Fixed class dumper
Browse files Browse the repository at this point in the history
1.Fixed class dumper
2.Custom control flow order
3.InsnSize check for arithmetic encryptor
4.Set default value to true for Interface method rename
  • Loading branch information
SpartanB312 committed Jul 15, 2024
1 parent 82d9ec7 commit 819e31e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion grunt-main/src/main/kotlin/net/spartanb312/grunt/Grunt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlin.system.measureTimeMillis
* Gruntpocalypse
* A continuation of Grunt witch is a lightweight java bytecode obfuscator
*/
const val VERSION = "2.0.0"
const val VERSION = "2.0.1"
const val SUBTITLE = "build 240715"
const val GITHUB = "https://github.com/SpartanB312/Grunt"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ object Transformers : Collection<Transformer> by mutableListOf(
DeadCodeRemoveTransformer,
ClonedClassTransformer,
TrashClassTransformer,
ImplicitJumpTransformer,
ImplicitJumpTransformer, // Execute 1
StringEncryptTransformer,
NumberEncryptTransformer,
FloatingPointEncryptTransformer,
ArithmeticEncryptTransformer,
ImplicitJumpTransformer, // Execute 2
StringEqualsRedirectTransformer,
FieldScrambleTransformer,
MethodScrambleTransformer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Hierarchy(private val resourceCache: ResourceCache) {

private fun buildClassInfo(name: String, subClassInfo: ClassInfo? = null): ClassInfo {
val info = classInfos[name]
if (info == null) {
return if (info == null) {
val classNode = resourceCache.getClassNode(name)
val newInfo = ClassInfo(name, classNode ?: ClassInfo.dummyClassNode)
if (subClassInfo != null) newInfo.children.add(subClassInfo)
Expand All @@ -97,10 +97,10 @@ class Hierarchy(private val resourceCache: ResourceCache) {
newInfo.parents.add(buildClassInfo(it, newInfo))
}
classInfos[newInfo.name] = newInfo
return newInfo
newInfo
} else {
if (subClassInfo != null) info.children.add(subClassInfo)
return info
info
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.spartanb312.grunt.process.resource

import net.spartanb312.grunt.process.hierarchy.Hierarchy
import net.spartanb312.grunt.utils.extensions.isInterface
import net.spartanb312.grunt.utils.logging.Logger
import org.objectweb.asm.ClassWriter

class ClassDumper(
Expand All @@ -19,7 +20,13 @@ class ClassDumper(
hierarchy.isSubType(type1, type2) -> type2
hierarchy.isSubType(type2, type1) -> type1
clazz1.isInterface && clazz2.isInterface -> "java/lang/Object"
else -> return "java/lang/Object"
else -> {
if (!type1.startsWith("java")
&& !type1.startsWith("sun")
&& !type1.startsWith("jdk")
) Logger.fatal("Failed to find common super class for $type1")
return super.getCommonSuperClass(type1, type2)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import kotlin.random.Random

/**
* Replace logic operations with substitutions
* Last update on 24/07/02
* Last update on 24/07/15
*/
object ArithmeticEncryptTransformer : Transformer("ArithmeticEncrypt", Category.Encryption) {

private val times by setting("Intensity", 1)
private val maxInsnSize by setting("MaxInsnSize", 16384)
private val exclusion by setting("Exclusion", listOf())

override fun ResourceCache.transform() {
Expand Down Expand Up @@ -48,6 +49,11 @@ object ArithmeticEncryptTransformer : Transformer("ArithmeticEncrypt", Category.
skipInsn--
continue
}
val currentSize = insnList.size() + methodNode.instructions.size() - index
if (currentSize >= maxInsnSize) {
+insn
continue
} // Avoid method too large
if (index < methodNode.instructions.size() - 2) {
val next = methodNode.instructions[index + 1]
val nextNext = methodNode.instructions[index + 2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import kotlin.random.Random
*/
object ImplicitJumpTransformer : Transformer("ImplicitJump", Category.Controlflow) {

private val beforeEncrypt by setting("ExecuteBeforeEncrypt", false)
private val replaceGoto by setting("ReplaceGoto", true)
private val replaceIf by setting("ReplaceIf", true)
private val useLocalVar by setting("UseLocalVar", true)
Expand All @@ -30,7 +31,11 @@ object ImplicitJumpTransformer : Transformer("ImplicitJump", Category.Controlflo
private val nonExcludedUtilList = mutableListOf<TrashCallMethod>()
private val allStaticUtilList = mutableSetOf<TrashCallMethod>()

private var flag = 0

override fun ResourceCache.transform() {
if (flag == 2) flag = 1 else flag++
if ((beforeEncrypt && flag != 1) || (!beforeEncrypt && flag == 1)) return
Logger.info(" - Replacing jumps to implicit operations")
nonExcludedUtilList.clear()
nonExcludedUtilList.addAll(generateUtilList(nonExcluded))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import kotlin.system.measureTimeMillis
object MethodRenameTransformer : Transformer("MethodRename", Category.Renaming) {

private val enums by setting("Enums", true)
private val interfaces by setting("Interfaces", false) // Make sure you've loaded all the dependencies
private val interfaces by setting("Interfaces", true) // Make sure you've loaded all the dependencies
private val dictionary by setting("Dictionary", "Alphabet")
private val heavyOverloads by setting("HeavyOverloads", false)
private val randomKeywordPrefix by setting("RandomKeywordPrefix", false)
Expand Down

0 comments on commit 819e31e

Please sign in to comment.