Skip to content

Commit

Permalink
Junkcode range for Controlflow
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanB312 committed Jul 11, 2024
1 parent cbc7994 commit 4f31d8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ object ImplicitJumpTransformer : Transformer("ImplicitJump", Category.Controlflo
private val replaceGoto by setting("ReplaceGoto", true)
private val replaceIf by setting("ReplaceIf", true)
private val junkCode by setting("JunkCode", true)
private val expandedJunkCode by setting("ExpandedJunkCode", true)
private val exclusion by setting("Exclusion", listOf())

private val staticUtilList = mutableSetOf<TrashCallMethod>()
private val nonExcludedUtilList = mutableListOf<TrashCallMethod>()
private val allStaticUtilList = mutableSetOf<TrashCallMethod>()

override fun ResourceCache.transform() {
Logger.info(" - Replacing jumps to implicit operations")
staticUtilList.clear()
staticUtilList.addAll(generateUtilList(allClasses))
nonExcludedUtilList.clear()
nonExcludedUtilList.addAll(generateUtilList(nonExcluded))
if (expandedJunkCode) {
allStaticUtilList.clear()
allStaticUtilList.addAll(generateUtilList(allClasses))
}
val count = count {
nonExcluded.asSequence()
.filter { it.name.notInList(exclusion) }
Expand Down Expand Up @@ -210,7 +216,9 @@ object ImplicitJumpTransformer : Transformer("ImplicitJump", Category.Controlflo
}

private fun findRandomGivenReturnTypeMethod(sort: Int): TrashCallMethod? {
return staticUtilList.filter { it.returnType.sort == sort }.randomOrNull()
val nonExcluded = nonExcludedUtilList.filter { it.returnType.sort == sort }.randomOrNull()
if (!expandedJunkCode) return nonExcluded
return nonExcluded ?: allStaticUtilList.filter { it.returnType.sort == sort }.randomOrNull()
}

private fun generateTrashCode(methodNode: MethodNode, returnType: Type): InsnList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ object FieldRedirectTransformer : Transformer("FieldRedirect", Category.Redirect
return this
}

private fun genMethod(field: FieldInsnNode, signature: String?, methodName: String): MethodNode {
private fun genMethod(field: FieldInsnNode, methodName: String, signature: String?): MethodNode {
val access = Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC
return when (field.opcode) {
Opcodes.GETFIELD -> method(
access,
methodName,
"(L${field.owner};)${field.desc}",
null,
signature,
null
) {
InsnList {
Expand All @@ -181,7 +181,7 @@ object FieldRedirectTransformer : Transformer("FieldRedirect", Category.Redirect
access,
methodName,
"(L${field.owner};${field.desc})V",
null,
signature,
null,
) {
InsnList {
Expand All @@ -199,7 +199,7 @@ object FieldRedirectTransformer : Transformer("FieldRedirect", Category.Redirect
access,
methodName,
"()${field.desc}",
null,
signature,
null
) {
InsnList {
Expand All @@ -212,7 +212,7 @@ object FieldRedirectTransformer : Transformer("FieldRedirect", Category.Redirect
access,
methodName,
"(${field.desc})V",
null,
signature,
null,
) {
InsnList {
Expand Down

0 comments on commit 4f31d8b

Please sign in to comment.