Skip to content

Commit 291445b

Browse files
committed
chore(community): wip on frames
1 parent 711d080 commit 291445b

12 files changed

Lines changed: 324 additions & 35 deletions

File tree

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/Skidfuscator.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535
import dev.skidfuscator.obfuscator.skidasm.SkidClassNode;
3636
import dev.skidfuscator.obfuscator.skidasm.SkidGroup;
3737
import dev.skidfuscator.obfuscator.skidasm.SkidMethodNode;
38+
import dev.skidfuscator.obfuscator.transform.Transformer;
3839
import dev.skidfuscator.obfuscator.transform.impl.SwitchTransformer;
3940
import dev.skidfuscator.obfuscator.transform.impl.flow.*;
4041
import dev.skidfuscator.obfuscator.transform.impl.misc.AhegaoTransformer;
4142
import dev.skidfuscator.obfuscator.transform.impl.number.NumberTransformer;
43+
import dev.skidfuscator.obfuscator.transform.impl.outliner.SimpleOutlinerTransformer;
4244
import dev.skidfuscator.obfuscator.transform.impl.string.StringTransformer;
4345
import dev.skidfuscator.obfuscator.util.MapleJarUtil;
4446
import dev.skidfuscator.obfuscator.util.MiscUtil;
@@ -103,6 +105,7 @@ public class Skidfuscator {
103105
*/
104106
public Skidfuscator(SkidfuscatorSession session) {
105107
this.session = session;
108+
this.exemptAnalysis = new SimpleExemptAnalysis();
106109
}
107110

108111
/**
@@ -123,13 +126,11 @@ public void run() {
123126
SkiddedDirectory.init(null);
124127

125128
/*
126-
* Here is initialized both the exempt analysis and the skid cache.
129+
* Here is initialized the skid cache.
127130
*
128131
* The SkidCache is an extension of MapleIR's IRCache
129-
* The ExemptAnalysis is a manager which handles exemptions
130132
*/
131133
this.irFactory = new SkidCache(this);
132-
this.exemptAnalysis = new SimpleExemptAnalysis();
133134

134135
/*
135136
* Here we initialize our opaque predicate type. As of right now
@@ -514,8 +515,14 @@ protected void _importClasspath() {
514515
}
515516

516517
protected void _loadTransformer() {
517-
for (Listener o : Arrays.asList(
518-
new StringTransformer(this),
518+
for (Listener o : this.getTransformers()) {
519+
EventBus.register(o);
520+
}
521+
}
522+
523+
public List<Transformer> getTransformers() {
524+
return Arrays.asList(
525+
/*new StringTransformer(this),
519526
//new NegationTransformer(this),
520527
//new FlatteningFlowTransformer(this),
521528
new NumberTransformer(this),
@@ -524,11 +531,10 @@ protected void _loadTransformer() {
524531
new BasicConditionTransformer(this),
525532
new BasicExceptionTransformer(this),
526533
new BasicRangeTransformer(this),
527-
new AhegaoTransformer(this)
534+
new AhegaoTransformer(this)*/
535+
//new SimpleOutlinerTransformer()
528536
//
529-
)) {
530-
EventBus.register(o);
531-
}
537+
);
532538
}
533539

534540
private void _verify() {

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/creator/SkidFlowGraphDumper.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.mapleir.ir.code.stmt.copy.CopyVarStmt;
2525
import org.mapleir.ir.codegen.BytecodeFrontend;
2626
import org.mapleir.stdlib.collections.graph.*;
27-
import org.mapleir.stdlib.collections.graph.algorithms.LT79Dom;
2827
import org.mapleir.stdlib.collections.graph.algorithms.SimpleDfs;
2928
import org.mapleir.stdlib.collections.graph.algorithms.TarjanSCC;
3029
import org.mapleir.stdlib.collections.list.IndexedList;
@@ -56,6 +55,8 @@ public class SkidFlowGraphDumper implements BytecodeFrontend {
5655

5756
private int beginIndex;
5857

58+
public static boolean TEST_COMPUTE = true;
59+
5960
public SkidFlowGraphDumper(Skidfuscator skidfuscator, ControlFlowGraph cfg, MethodNode m) {
6061
this.skidfuscator = skidfuscator;
6162
this.cfg = cfg;
@@ -90,7 +91,9 @@ public void dump() {
9091

9192
// Compute frames
9293
//computeFrames();
93-
//new FrameComputer(skidfuscator).compute(cfg);
94+
if (TEST_COMPUTE) {
95+
new FrameComputer(skidfuscator).compute(cfg);
96+
}
9497

9598
// Stuff
9699
/*
@@ -141,7 +144,7 @@ public void dump() {
141144
m.node.visitLabel(getLabel(b));
142145

143146
iter: {
144-
if (b.isEmpty() || cfg.getJumpReverseEdges(b).isEmpty()|| true)
147+
if (b.isEmpty() || cfg.getJumpReverseEdges(b).isEmpty() || !TEST_COMPUTE)
145148
break iter;
146149

147150
final SkidExpressionPool frameTypes = (SkidExpressionPool) b.getPool();
@@ -312,6 +315,8 @@ private Object _getFrameType(final Type type) {
312315
frameType = Opcodes.NULL;
313316
} else if (type.getSort() == Type.ARRAY) {
314317
frameType = type.getDescriptor();
318+
} else if (type == TypeUtil.UNINITIALIZED_THIS) {
319+
frameType = Opcodes.UNINITIALIZED_THIS;
315320
} else {
316321
frameType = type.getInternalName();
317322
}

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/frame_V2/frame/FrameComputer.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import dev.skidfuscator.obfuscator.Skidfuscator;
55
import dev.skidfuscator.obfuscator.skidasm.SkidClassNode;
66
import dev.skidfuscator.obfuscator.skidasm.SkidExpressionPool;
7+
import dev.skidfuscator.obfuscator.skidasm.SkidMethodNode;
78
import dev.skidfuscator.obfuscator.skidasm.SkidTypeStack;
9+
import dev.skidfuscator.obfuscator.skidasm.cfg.SkidBlock;
810
import dev.skidfuscator.obfuscator.util.TypeUtil;
911
import dev.skidfuscator.obfuscator.util.misc.Parameter;
1012
import org.mapleir.asm.ClassNode;
@@ -50,7 +52,12 @@ public FrameComputer(Skidfuscator skidfuscator) {
5052
public void compute(final ControlFlowGraph cfg) {
5153
if (cfg.getEntries().size() != 1)
5254
throw new IllegalStateException("CFG doesn't have exactly 1 entry");
55+
56+
57+
5358
final BasicBlock entry = cfg.getEntries().iterator().next();
59+
final boolean isInit = cfg.getMethodNode().isInit();
60+
5461
final FrameGraph frameGraph = new FrameGraph();
5562

5663
final Map<BasicBlock, FrameNode> frameMap = new HashMap<>();
@@ -101,7 +108,18 @@ public void compute(final ControlFlowGraph cfg) {
101108
* of "this." which is itself
102109
*/
103110
if (!cfg.getMethodNode().isStatic()) {
104-
entryFrame.set(index, Type.getType("L" + cfg.getMethodNode().owner.getName() + ";"));
111+
if (isInit) {
112+
((SkidMethodNode) cfg.getMethodNode()).getEntryBlock();
113+
frameMap.forEach((block, frame) -> {
114+
entryFrame.set(0,
115+
block.isFlagSet(SkidBlock.FLAG_NO_OPAQUE)
116+
? TypeUtil.UNINITIALIZED_THIS
117+
: cfg.getMethodNode().getOwnerType()
118+
);
119+
});
120+
} else {
121+
entryFrame.set(index, Type.getType("L" + cfg.getMethodNode().owner.getName() + ";"));
122+
}
105123
protectedIndex = index;
106124
index++;
107125
}

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/phantom/jphantom/PhantomResolvingJarDumper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public int dumpClass(JarOutputStream out, JarClassData classData) throws IOExcep
119119

120120
try {
121121
try {
122-
ClassWriter writer = this.buildClassWriter(tree, ClassWriter.COMPUTE_FRAMES);
122+
ClassWriter writer = this.buildClassWriter(tree, ClassWriter.COMPUTE_MAXS);
123123
cn.node.accept(writer); // must use custom writer which overrides getCommonSuperclass
124124
out.write(writer.toByteArray());
125125
} catch (Exception e) {

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/skidasm/cfg/SkidControlFlowGraph.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.mapleir.ir.code.expr.invoke.DynamicInvocationExpr;
1010
import org.mapleir.ir.code.expr.invoke.Invocation;
1111
import org.mapleir.ir.code.expr.invoke.Invokable;
12+
import org.mapleir.ir.locals.Local;
1213
import org.mapleir.ir.locals.LocalsPool;
1314

1415
import java.util.Collection;
@@ -46,4 +47,14 @@ public Stream<CodeUnit> allExprStream() {
4647
.map(Stmt::enumerateWithSelf)
4748
.flatMap(Streams::stream);
4849
}
50+
51+
public Local getSelfLocal() {
52+
assert !getMethodNode().isStatic() : "Trying to get instance local on static method";
53+
54+
return getLocals().get(0);
55+
}
56+
57+
public BasicBlock getEntry() {
58+
return getEntries().iterator().next();
59+
}
4960
}

0 commit comments

Comments
 (0)