Skip to content

Commit

Permalink
feat: add custom asm for funny time fuckery
Browse files Browse the repository at this point in the history
  • Loading branch information
terminalsin committed Dec 22, 2024
1 parent adeb6e7 commit bdee13d
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
#cache: maven
- name: Build with Gradle
run: |
cd org.ow2.asm
./gradlew publishToMavenLocal --no-daemon
cd ../
./gradlew shadowJar --no-daemon
mkdir staging/ && cp dev.skidfuscator.client.standalone/build/libs/client-standalone-all.jar staging
- name: Upload a Build Artifact
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[submodule "dev.xdark.ssvm"]
url = [email protected]:terminalsin/SSVM.git
[submodule "org.ow2.asm"]
path = org.ow2.asm
url = https://gitlab.ow2.org/asm/asm.git
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ allprojects {
}

ext {
asm = 'org.ow2.asm:asm:9.7.1'
asm_commons = 'org.ow2.asm:asm-commons:9.7.1'
asm_tree = 'org.ow2.asm:asm-tree:9.7.1'
cafedude = 'com.github.Col-E:CAFED00D:2.1.1'
slf4j_api = 'org.slf4j:slf4j-api:1.7.36'
jlinker = 'com.github.xxDark:jlinker:1.0.7'
Expand Down
1 change: 1 addition & 0 deletions dev.skidfuscator.obfuscator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
testCompileOnly 'org.projectlombok:lombok:1.18.36'
compileOnly 'org.projectlombok:lombok:1.18.36'

implementation 'dev.skidfuscator.asm:asm-tree:9.8-SNAPSHOT'
api project(':commons')
api project(':pure-analysis')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
import org.mapleir.ir.cfg.BasicBlock;
import org.mapleir.ir.code.Expr;
import org.mapleir.ir.code.stmt.ConditionalJumpStmt;
import org.mapleir.ir.codegen.BytecodeFrontend;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.util.CheckMethodAdapter;
import org.objectweb.asm.util.TraceMethodVisitor;

public class FakeConditionalJumpStmt extends ConditionalJumpStmt {
public FakeConditionalJumpStmt(Expr left, Expr right, BasicBlock trueSuccessor, ComparisonType type) {
Expand All @@ -13,4 +19,17 @@ public FakeConditionalJumpStmt(Expr left, Expr right, BasicBlock trueSuccessor,
public FakeConditionalJumpStmt(Expr left, Expr right, BasicBlock trueSuccessor, ComparisonType type, ConditionalJumpEdge<BasicBlock> edge) {
super(left, right, trueSuccessor, type, edge);
}

@Override
public void toCode(MethodVisitor visitor, BytecodeFrontend assembler) {
super.toCode(new MethodVisitor(Opcodes.ASM9, visitor) {
@Override
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
if (visitor instanceof MethodNode methodNode) {
methodNode.instructions.getLast().setSkip(true);
}
}
}, assembler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,26 @@
import org.mapleir.flowgraph.edges.UnconditionalJumpEdge;
import org.mapleir.ir.cfg.BasicBlock;
import org.mapleir.ir.code.stmt.UnconditionalJumpStmt;
import org.mapleir.ir.codegen.BytecodeFrontend;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.MethodNode;

public class FakeUnconditionalJumpStmt extends UnconditionalJumpStmt {
public FakeUnconditionalJumpStmt(BasicBlock target, UnconditionalJumpEdge<BasicBlock> edge) {
super(target, edge);
}

@Override
public void toCode(MethodVisitor visitor, BytecodeFrontend assembler) {
super.toCode(new MethodVisitor(Opcodes.ASM9, visitor) {
@Override
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
if (visitor instanceof MethodNode methodNode) {
methodNode.instructions.getLast().setSkip(true);
}
}
}, assembler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ void handle(final RunMethodTransformEvent event) {

// Todo change blocks to be skiddedblocks to add method to directly add these
final ConstantExpr var_const = new AlertableConstantExpr(hash.getHash(), Type.INT_TYPE);
final ConditionalJumpStmt jump_stmt = new FakeConditionalJumpStmt(hash.getExpr(), var_const, fuckup, ConditionalJumpStmt.ComparisonType.NE);
final ConditionalJumpStmt jump_stmt = new FakeConditionalJumpStmt(hash.getExpr(), var_const,
RandomUtil.randomOfSet(cfg.vertices()),
ConditionalJumpStmt.ComparisonType.NE);

if (entry.get(entry.size() - 1) instanceof UnconditionalJumpStmt)
entry.add(entry.size() - 1, jump_stmt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.IOException;
import java.util.Random;
import java.util.Set;

@UtilityClass
public class RandomUtil {
Expand Down Expand Up @@ -52,6 +53,16 @@ public String randomAlphabeticalString(int size) {
.toString();
}

public <V> V randomOfSet(Set<V> set) {
int index = nextInt(set.size());
for (V v : set) {
if (index-- == 0) {
return v;
}
}
return null;
}

private final Class<?>[] exceptionClasses = new Class<?>[] {
IllegalAccessException.class,
IOException.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exclude: [
"""
@class dev.sim0n.app.* {
@class !dev.sim0n.app.* {
!@class util.*
!@class Main
}
Expand Down
12 changes: 8 additions & 4 deletions org.mapleir.parent/org.mapleir.modasm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ plugins {
id 'java'
}

repositories {
mavenLocal()
}

dependencies {
api project(':stdlib')
api 'org.ow2.asm:asm:9.7.1'
api 'org.ow2.asm:asm-tree:9.7.1'
api 'org.ow2.asm:asm-util:9.7.1'
api 'org.ow2.asm:asm-commons:9.7.1'
api 'dev.skidfuscator.asm:asm:9.8-SNAPSHOT'
api 'dev.skidfuscator.asm:asm-commons:9.8-SNAPSHOT'
api 'dev.skidfuscator.asm:asm-tree:9.8-SNAPSHOT'
api 'dev.skidfuscator.asm:asm-util:9.8-SNAPSHOT'
}

group = 'dev.skidfuscator.mapleir'
Expand Down
1 change: 1 addition & 0 deletions org.ow2.asm
Submodule org.ow2.asm added at c55dc7

0 comments on commit bdee13d

Please sign in to comment.