Skip to content

Commit 78bbfe0

Browse files
committed
wip(obfuscator): frame coompootation
1 parent 12a0e29 commit 78bbfe0

5 files changed

Lines changed: 37 additions & 9 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void dump() {
141141
m.node.visitLabel(getLabel(b));
142142

143143
iter: {
144-
if (b.isEmpty() || true)
144+
if (b.isEmpty())
145145
break iter;
146146

147147
final SkidExpressionPool frameTypes = (SkidExpressionPool) b.getPool();

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void compute(final ControlFlowGraph cfg) {
158158

159159
TypeHeader currentPool = poppedFrame.getPool().createChild();
160160

161-
TypeHeader highestPoolNoRandoAssExpression = currentPool;
161+
TypeHeader highestPoolNoRandoAssExpression = null;
162162
boolean yeahNo = false;
163163

164164
for (Stmt stmt : popped) {
@@ -382,15 +382,18 @@ else if (stmt instanceof UnconditionalJumpStmt) {
382382
}
383383
}
384384

385-
final TypeHeader finalHighestPoolNoRandoAssExpression = cfg
385+
/*final TypeHeader finalHighestPoolNoRandoAssExpression = cfg
386386
.getReverseEdges(popped)
387387
.stream()
388388
.filter(TryCatchEdge.class::isInstance)
389389
.map(e -> (TryCatchEdge<BasicBlock>) e)
390390
.anyMatch(e -> e.erange.getHandler().equals(popped))
391391
? highestPoolNoRandoAssExpression.createChild()
392-
: poppedFrame.getPool().createChild();
392+
: poppedFrame.getPool().createChild();*/
393393

394+
final TypeHeader lastValidTryCatchPool = highestPoolNoRandoAssExpression == null
395+
? currentPool.createChild()
396+
: highestPoolNoRandoAssExpression;
394397
cfg.getSuccessors(new Predicate<FlowEdge<BasicBlock>>() {
395398
@Override
396399
public boolean test(FlowEdge<BasicBlock> basicBlockFlowEdge) {
@@ -407,12 +410,12 @@ public boolean test(FlowEdge<BasicBlock> basicBlockFlowEdge) {
407410
frameGraph.addEdge(new FrameEdge(
408411
poppedFrame,
409412
targetFrame,
410-
finalHighestPoolNoRandoAssExpression
413+
lastValidTryCatchPool
411414
));
412415

413416
// TODO: Check if we should instead take the first
414417
// dominator index of the graph
415-
targetFrame.getPool().addParent(finalHighestPoolNoRandoAssExpression);
418+
targetFrame.getPool().addParent(lastValidTryCatchPool);
416419

417420
next.add(value);
418421
});
@@ -499,8 +502,9 @@ public boolean test(FlowEdge<BasicBlock> basicBlockFlowEdge) {
499502

500503
if (currentType.contains(desiredType)) {
501504
poppedFrame.set(localIndex, desiredType);
502-
} else if (currentType.stream().anyMatch(c -> c.getSort() != Type.OBJECT)) {
505+
} else if (currentType.stream().allMatch(c -> c.getSort() == Type.OBJECT)) {
503506
//final Type peekedType =
507+
poppedFrame.set(localIndex, desiredType);
504508
}
505509
// TODO: Var expr merging
506510
/*if (currentType.equals(TypeUtil.OBJECT_TYPE)) {
@@ -655,6 +659,7 @@ public boolean test(FlowEdge<BasicBlock> basicBlockFlowEdge) {
655659
}
656660
}
657661

662+
658663
for (BasicBlock vertex : cfg.verticesInOrder()) {
659664
final FrameNode frameNode = frameMap.get(vertex);
660665

@@ -718,6 +723,24 @@ public boolean test(FlowEdge<BasicBlock> basicBlockFlowEdge) {
718723
vertex.setPool(expressionPool);
719724
}
720725

726+
final Set<FrameEdge> visitedEdges = new HashSet<>();
727+
728+
for (FrameNode vertex : frameGraph.vertices()) {
729+
visitedEdges.addAll(frameGraph.getEdges(vertex));
730+
}
731+
732+
for (FrameEdge frameEdge : visitedEdges) {
733+
final Type[] types = new Type[frameEdge.frame().size()];
734+
for (int i = 0; i < types.length; i++) {
735+
final Set<Type> computed = frameEdge.frame().get(i);
736+
for (Type type : computed) {
737+
types[i] = TypeUtil.mergeTypes(skidfuscator, type, types[i]);
738+
}
739+
740+
frameEdge.frame().set(i, types[i]);
741+
}
742+
}
743+
721744
if (cfg.getName().equals("exportLog")) {
722745
IPropertyDictionary dict = PropertyHelper.createDictionary();
723746
dict.put(new BooleanProperty(CFGExporterUtils.OPT_EDGES, true));

dev.skidfuscator.obfuscator/obfuscator/src/main/java/dev/skidfuscator/obfuscator/frame_V2/frame/type/TypeHeader.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.skidfuscator.obfuscator.frame_V2.frame.type;
22

33
import dev.skidfuscator.obfuscator.Skidfuscator;
4+
import dev.skidfuscator.obfuscator.util.TypeUtil;
45
import org.objectweb.asm.Type;
56

67
import java.util.Arrays;
@@ -95,7 +96,7 @@ private Set<Type> _get(final int index, final Set<TypeHeader> visited) {
9596
final Set<Type> types = new HashSet<>();
9697

9798
if (type != null && (excluded == null || !excluded.contains(type))) {
98-
types.add(type);
99+
return new HashSet<>(Collections.singleton(type));
99100
}
100101

101102
for (TypeHeader parent : parents) {
@@ -112,6 +113,10 @@ private Set<Type> _get(final int index, final Set<TypeHeader> visited) {
112113
}
113114
}
114115

116+
if (types.isEmpty()) {
117+
types.add(TypeUtil.UNDEFINED_TYPE);
118+
}
119+
115120
return types;
116121
}
117122

dev.skidfuscator.obfuscator/obfuscator/src/main/java/dev/skidfuscator/obfuscator/util/MapleJarUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public int dumpClass(JarOutputStream out, JarClassData classData) throws IOExcep
6262
try {
6363
out.putNextEntry(entry);
6464
try {
65-
ClassWriter writer = this.buildClassWriter(tree, ClassWriter.COMPUTE_FRAMES);
65+
ClassWriter writer = this.buildClassWriter(tree, ClassWriter.COMPUTE_MAXS);
6666
cn.node.accept(writer);
6767
out.write(writer.toByteArray());
6868
} catch (Exception var8) {
Binary file not shown.

0 commit comments

Comments
 (0)