Skip to content

Commit 96b254b

Browse files
authored
Merge pull request #10 from terminalsin/dev
Dev
2 parents 4ed65de + 805c542 commit 96b254b

File tree

12 files changed

+396
-72
lines changed

12 files changed

+396
-72
lines changed

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obf/SkidMethodRenderer.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.common.collect.Streams;
44
import dev.skidfuscator.obf.init.SkidSession;
5+
import dev.skidfuscator.obf.maple.FakeConditionalJumpStmt;
56
import dev.skidfuscator.obf.skidasm.NoNoSkidMethod;
67
import dev.skidfuscator.obf.skidasm.v2.SStorage;
78
import dev.skidfuscator.obf.transform.impl.ProjectPass;
@@ -49,10 +50,7 @@ public void render(final SkidSession skidSession) {
4950
projectPass.pass(skidSession);
5051
}
5152

52-
logger.log("[*] Passing fun passes...");
53-
for (ProjectPass projectPass : projectPasses) {
54-
projectPass.pass(skidSession);
55-
}
53+
5654

5755
final List<ClassNode> nodeList = Streams.stream(skidSession.getClassSource().iterate())
5856
.parallel()
@@ -180,11 +178,13 @@ public void render(final SkidSession skidSession) {
180178
logger.log("[*] Finished initial seed of " + skidMethods.size() + " methods");
181179
logger.post("[*] Gen3 Flow... Beginning obfuscation...");
182180
final FlowPass[] flowPasses = new FlowPass[]{
183-
//new NumberMutatorPass(),
184-
//new SwitchMutatorPass(),
185-
//new ConditionMutatorPass(),
186-
//new FakeExceptionJumpFlowPass(),
187-
//new FakeJumpFlowPass(),
181+
new NumberMutatorPass(),
182+
new SwitchMutatorPass(),
183+
//new FakeTryCatchFlowPass(),
184+
//new ConditionV2MutatorPass(),
185+
new ConditionMutatorPass(),
186+
new FakeExceptionJumpFlowPass(),
187+
new FakeJumpFlowPass(),
188188
new SeedFlowPass(),
189189
};
190190

@@ -220,6 +220,14 @@ public void render(final SkidSession skidSession) {
220220
+ "]");
221221
}
222222

223+
logger.log("[*] Passing fun passes...");
224+
for (ProjectPass projectPass : projectPasses) {
225+
projectPass.pass(skidSession);
226+
logger.log(" [@G3#flow] Finished running "
227+
+ projectPass.getName()
228+
+ " [Changed: " + skidSession.popCount()
229+
+ "]");
230+
}
223231

224232
logger.log("[*] Linearizing GEN3...");
225233

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package dev.skidfuscator.obf.maple;
2+
3+
import org.mapleir.ir.cfg.BasicBlock;
4+
import org.mapleir.ir.cfg.ControlFlowGraph;
5+
6+
public class FakeBlock extends BasicBlock {
7+
public FakeBlock(ControlFlowGraph cfg) {
8+
super(cfg);
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package dev.skidfuscator.obf.maple;
2+
3+
import org.mapleir.flowgraph.edges.ConditionalJumpEdge;
4+
import org.mapleir.stdlib.collections.graph.FastGraphVertex;
5+
6+
public class FakeConditionalJumpEdge<N extends FastGraphVertex> extends ConditionalJumpEdge<N> {
7+
public FakeConditionalJumpEdge(N src, N dst, int opcode) {
8+
super(src, dst, opcode);
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package dev.skidfuscator.obf.maple;
2+
3+
import org.mapleir.ir.cfg.BasicBlock;
4+
import org.mapleir.ir.code.stmt.UnconditionalJumpStmt;
5+
6+
public class FakeUnconditionalJumpStmt extends UnconditionalJumpStmt {
7+
public FakeUnconditionalJumpStmt(BasicBlock target) {
8+
super(target);
9+
}
10+
}

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obf/skidasm/SkidGraph.java

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package dev.skidfuscator.obf.skidasm;
22

3+
import dev.skidfuscator.obf.maple.FakeBlock;
4+
import dev.skidfuscator.obf.maple.FakeConditionalJumpEdge;
35
import dev.skidfuscator.obf.maple.FakeConditionalJumpStmt;
6+
import dev.skidfuscator.obf.maple.FakeUnconditionalJumpStmt;
47
import dev.skidfuscator.obf.number.NumberManager;
58
import dev.skidfuscator.obf.number.encrypt.impl.XorNumberTransformer;
69
import dev.skidfuscator.obf.number.hash.HashTransformer;
@@ -37,7 +40,8 @@ public class SkidGraph {
3740
@Getter
3841
private Local local;
3942
private final Map<BasicBlock, SkidBlock> cache = new HashMap<>();
40-
private final Set<LinearLink> linearLinks = new HashSet<>();
43+
44+
public static final boolean DEBUG = false;
4145

4246
public SkidGraph(MethodNode node, SkidMethod method) {
4347
this.node = node;
@@ -73,7 +77,6 @@ public void postlinearize(final ControlFlowGraph cfg) {
7377
// Phase 2
7478
linearize(cfg);
7579

76-
range(cfg, local);
7780
linkage(cfg, local);
7881

7982
/*BasicBlock next = cfg.verticesInOrder().iterator().next();
@@ -97,6 +100,9 @@ public void postlinearize(final ControlFlowGraph cfg) {
97100
}*/
98101

99102
for (BasicBlock vertex : cfg.vertices()) {
103+
if (vertex instanceof FakeBlock)
104+
continue;
105+
100106
cfg.getEdges(vertex).stream()
101107
.filter(e -> e instanceof ImmediateEdge)
102108
.forEach(e -> {
@@ -132,17 +138,17 @@ public void postlinearize(final ControlFlowGraph cfg) {
132138
}
133139
}*/
134140

135-
for (BasicBlock block : cfg.vertices()) {
136-
final SkidBlock targetSeededBlock = getBlock(block);
137-
/*final Local local1 = block.cfg.getLocals().get(block.cfg.getLocals().getMaxLocals() + 2);
138-
block.add(0, new CopyVarStmt(new VarExpr(local1, Type.getType(String.class)),
139-
new ConstantExpr(block.getDisplayName() +" : c-var - begin : " + targetSeededBlock.getSeed())));
140-
final Local local2 = block.cfg.getLocals().get(block.cfg.getLocals().getMaxLocals() + 2);
141-
block.add(block.size() - 1, new CopyVarStmt(new VarExpr(local2, Type.getType(String.class)),
142-
new ConstantExpr(block.getDisplayName() +" : c-var - end : " + targetSeededBlock.getSeed())));
143-
*/
141+
if (DEBUG) {
142+
for (BasicBlock block : cfg.vertices()) {
143+
final SkidBlock targetSeededBlock = getBlock(block);
144+
final Local local1 = block.cfg.getLocals().get(block.cfg.getLocals().getMaxLocals() + 2);
145+
block.add(0, new CopyVarStmt(new VarExpr(local1, Type.getType(String.class)),
146+
new ConstantExpr(block.getDisplayName() +" : c-var - begin : " + targetSeededBlock.getSeed())));
147+
final Local local2 = block.cfg.getLocals().get(block.cfg.getLocals().getMaxLocals() + 2);
148+
block.add(block.size() - 1, new CopyVarStmt(new VarExpr(local2, Type.getType(String.class)),
149+
new ConstantExpr(block.getDisplayName() +" : c-var - end : " + targetSeededBlock.getSeed())));
150+
}
144151
}
145-
146152
}
147153

148154
private void linearize(final ControlFlowGraph cfg) {
@@ -165,11 +171,19 @@ private void linkage(final ControlFlowGraph cfg, final Local local) {
165171
});
166172
}
167173

168-
for (BasicBlock entry : cfg.vertices()) {
174+
range(cfg, local);
175+
176+
for (BasicBlock entry : new HashSet<>(cfg.vertices())) {
169177
new HashSet<>(entry).forEach(e -> {
170-
if (e instanceof UnconditionalJumpStmt) {
178+
if (e instanceof UnconditionalJumpStmt && !(e instanceof FakeUnconditionalJumpStmt)) {
171179
addSeedToUncJump(local, entry, (UnconditionalJumpStmt) e);
172-
} else if (e instanceof ConditionalJumpStmt && !(e instanceof FakeConditionalJumpStmt)) {
180+
}
181+
});
182+
}
183+
184+
for (BasicBlock entry : new HashSet<>(cfg.vertices())) {
185+
new HashSet<>(entry).forEach(e -> {
186+
if (e instanceof ConditionalJumpStmt && !(e instanceof FakeConditionalJumpStmt)) {
173187
addSeedToCondJump(local, entry, (ConditionalJumpStmt) e);
174188
}
175189
});
@@ -228,10 +242,13 @@ private void addSeedToImmediate(final Local local, final BasicBlock block, final
228242
final SkidBlock seededBlock = getBlock(block);
229243
final SkidBlock targetSeededBlock = getBlock(immediate);
230244
seededBlock.addSeedLoader(-1, local, seededBlock.getSeed(), targetSeededBlock.getSeed());
231-
/*final Local local1 = block.cfg.getLocals().get(block.cfg.getLocals().getMaxLocals() + 2);
232-
block.add(block.size(), new CopyVarStmt(new VarExpr(local1, Type.getType(String.class)),
233-
new ConstantExpr(block.getDisplayName() +" : c-loc - immediate : " + targetSeededBlock.getSeed())));
234-
*/
245+
246+
if (DEBUG) {
247+
final Local local1 = block.cfg.getLocals().get(block.cfg.getLocals().getMaxLocals() + 2);
248+
block.add(block.size(), new CopyVarStmt(new VarExpr(local1, Type.getType(String.class)),
249+
new ConstantExpr(block.getDisplayName() +" : c-loc - immediate : " + targetSeededBlock.getSeed())));
250+
}
251+
235252
// Ignore, this is for debugging
236253
/*
237254
final Local local1 = block.cfg.getLocals().get(block.cfg.getLocals().getMaxLocals() + 2);
@@ -248,10 +265,12 @@ private void addSeedToUncJump(final Local local, final BasicBlock block, final U
248265
final SkidBlock targetSeededBlock = getBlock(stmt.getTarget());
249266
seededBlock.addSeedLoader(index, local, seededBlock.getSeed(), targetSeededBlock.getSeed());
250267

251-
/*final Local local1 = block.cfg.getLocals().get(block.cfg.getLocals().getMaxLocals() + 2);
252-
block.add(index, new CopyVarStmt(new VarExpr(local1, Type.getType(String.class)),
253-
new ConstantExpr(block.getDisplayName() +" : c-loc - uncond : " + targetSeededBlock.getSeed())));
254-
*/
268+
if (DEBUG) {
269+
final Local local1 = block.cfg.getLocals().get(block.cfg.getLocals().getMaxLocals() + 2);
270+
block.add(index, new CopyVarStmt(new VarExpr(local1, Type.getType(String.class)),
271+
new ConstantExpr(block.getDisplayName() +" : c-loc - uncond : " + targetSeededBlock.getSeed())));
272+
}
273+
255274
/*
256275
final Local local1 = block.cfg.getLocals().get(block.cfg.getLocals().getMaxLocals() + 2);
257276
block.add(new CopyVarStmt(new VarExpr(local1, Type.getType(String.class)),
@@ -262,7 +281,7 @@ private void addSeedToUncJump(final Local local, final BasicBlock block, final U
262281
private void addSeedToCondJump(final Local local, final BasicBlock block, final ConditionalJumpStmt stmt) {
263282
// Todo Add support for various different types of conditional jumps
264283
// support such as block splitting and shit to mess with reversers
265-
if (true) {
284+
if (false) {
266285
final SkidBlock seededBlock = getBlock(block);
267286
final SkidBlock targetSeededBlock = getBlock(stmt.getTrueSuccessor());
268287

@@ -286,7 +305,7 @@ private void addSeedToCondJump(final Local local, final BasicBlock block, final
286305
}
287306

288307
final ConditionalJumpEdge<BasicBlock> edge = block.cfg.getEdges(block).stream()
289-
.filter(e -> !(e instanceof ImmediateEdge))
308+
.filter(e -> e instanceof ConditionalJumpEdge && !(e instanceof FakeConditionalJumpEdge))
290309
.map(e -> (ConditionalJumpEdge<BasicBlock>) e)
291310
.filter(e -> e.dst().equals(stmt.getTrueSuccessor()))
292311
.findFirst()
@@ -311,6 +330,12 @@ private void addSeedToCondJump(final Local local, final BasicBlock block, final
311330
// Replace successor
312331
stmt.setTrueSuccessor(basicBlock);
313332
block.cfg.addEdge(new ConditionalJumpEdge<>(block, basicBlock, stmt.getOpcode()));
333+
334+
if (DEBUG) {
335+
final Local local1 = block.cfg.getLocals().get(block.cfg.getLocals().getMaxLocals() + 2);
336+
block.add(block.indexOf(stmt), new CopyVarStmt(new VarExpr(local1, Type.getType(String.class)),
337+
new ConstantExpr(block.getDisplayName() +" : c-loc - cond : " + targetSeeded.getSeed())));
338+
}
314339
//seededBlock.addSeedLoader(index + 2, local, targetSeededBlock.getSeed(), seededBlock.getSeed());
315340
}
316341

@@ -356,15 +381,15 @@ private void addSeedToRange(final Local local, final ControlFlowGraph cfg, final
356381
final SkidBlock internal = getBlock(node);
357382

358383
// Create a new switch block and get it's seeded variant
359-
final BasicBlock block = new BasicBlock(cfg);
384+
final BasicBlock block = new FakeBlock(cfg);
360385
cfg.addVertex(block);
361386
final SkidBlock seededBlock = getBlock(block);
362387

363388
// Add a seed loader for the incoming block and convert it to the handler's
364389
seededBlock.addSeedLoader(0, local, internal.getSeed(), handler.getSeed());
365390

366391
// Jump to handler
367-
block.add(new UnconditionalJumpStmt(basicHandler));
392+
block.add(new FakeUnconditionalJumpStmt(basicHandler));
368393
cfg.addEdge(new UnconditionalJumpEdge<>(block, basicHandler));
369394

370395
// Final hashed
@@ -391,7 +416,7 @@ private void addSeedToRange(final Local local, final ControlFlowGraph cfg, final
391416
// Haha get fucked
392417
// Todo Fix the other shit to re-enable this; this is for the lil shits
393418
// (love y'all tho) that are gonna try reversing this
394-
for (int i = 0; i < 10; i++) {
419+
/*for (int i = 0; i < 10; i++) {
395420
// Generate random seed + prevent conflict
396421
final int seed = RandomUtil.nextInt();
397422
if (sortedList.contains(seed))
@@ -412,7 +437,7 @@ private void addSeedToRange(final Local local, final ControlFlowGraph cfg, final
412437
413438
basicBlockMap.put(seed, block);
414439
cfg.addEdge(new SwitchEdge<>(handler.getBlock(), block, seed));
415-
}
440+
}*/
416441

417442
// Hash
418443
final Expr hash = hashTransformer.hash(local);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dev.skidfuscator.obf.transform.impl.fixer;
2+
3+
import dev.skidfuscator.obf.init.SkidSession;
4+
import dev.skidfuscator.obf.skidasm.SkidGraph;
5+
import dev.skidfuscator.obf.skidasm.SkidMethod;
6+
import dev.skidfuscator.obf.transform.impl.flow.FlowPass;
7+
import org.mapleir.flowgraph.edges.DefaultSwitchEdge;
8+
import org.mapleir.flowgraph.edges.UnconditionalJumpEdge;
9+
import org.mapleir.ir.cfg.BasicBlock;
10+
import org.mapleir.ir.cfg.ControlFlowGraph;
11+
import org.mapleir.ir.code.Stmt;
12+
import org.mapleir.ir.code.stmt.SwitchStmt;
13+
import org.mapleir.ir.code.stmt.UnconditionalJumpStmt;
14+
15+
import java.util.HashSet;
16+
17+
public class ReturnFixerPass implements FlowPass {
18+
@Override
19+
public void pass(SkidSession session, SkidMethod method) {
20+
for (SkidGraph methodNode : method.getMethodNodes()) {
21+
final ControlFlowGraph cfg = session.getCxt().getIRCache().get(methodNode.getNode());
22+
23+
if (cfg == null)
24+
continue;
25+
26+
27+
}
28+
}
29+
30+
@Override
31+
public String getName() {
32+
return "Switch Fixer";
33+
}
34+
}

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obf/transform/impl/flow/ConditionMutatorPass.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import dev.skidfuscator.obf.init.SkidSession;
44
import dev.skidfuscator.obf.maple.FakeArithmeticExpr;
5+
import dev.skidfuscator.obf.maple.FakeConditionalJumpStmt;
56
import dev.skidfuscator.obf.number.NumberManager;
67
import dev.skidfuscator.obf.number.hash.HashTransformer;
78
import dev.skidfuscator.obf.number.hash.SkiddedHash;

0 commit comments

Comments
 (0)