Skip to content

Commit e4a5531

Browse files
committed
fix(obfuscator): make entrypoint analysis properly iterate all blocks
1 parent 2353d6e commit e4a5531

6 files changed

Lines changed: 46 additions & 17 deletions

File tree

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/predicate/renderer/impl/IntegerBlockPredicateRenderer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ void handle(final InitMethodTransformEvent event) {
8888
.getLocals()
8989
.get(methodNode.getCfg().getLocals().getMaxLocals() + 3);
9090

91+
methodNode.getEntryBlock();
92+
9193
/*
9294
* The getter right now is quite simple:
9395
*

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/skidasm/SkidMethodNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ public BasicBlock getEntryBlock() {
230230

231231
initBlock.setFlag(SkidBlock.FLAG_NO_OPAQUE, true);
232232

233-
cfg.getPredecessors(initBlock).forEach(vertex -> {
233+
234+
cfg.getAllChildren(initBlock).forEach(vertex -> {
234235
if (IntegerBlockPredicateRenderer.DEBUG) {
235236
final Local debugLocal = cfg.getLocals().get(cfg.getLocals().getMaxLocals() + 2);
236237
vertex.add(

dev.skidfuscator.obfuscator/src/test/java/dev/skidfuscator/core/TestSkidfuscator.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,20 @@ protected void _dump() {
166166
} catch (Exception ex) {
167167
ex.printStackTrace();
168168

169-
final ClassWriter writer = resolver.buildClassWriter(tree, ClassWriter.COMPUTE_MAXS);
170-
e.node.accept(writer); // must use custom writer which overrides getCommonSuperclass
171-
bytes.set(writer.toByteArray());
172-
System.err.println("\rFailed to write " + e.getName()
173-
+ "! Writing with COMPUTE_MAXS, " +
174-
"which may cause runtime abnormalities\n");
169+
try {
170+
final ClassWriter writer = resolver.buildClassWriter(tree, ClassWriter.COMPUTE_MAXS);
171+
e.node.accept(writer); // must use custom writer which overrides getCommonSuperclass
172+
bytes.set(writer.toByteArray());
173+
System.err.println("\rFailed to write " + e.getName()
174+
+ "! Writing with COMPUTE_MAXS, " +
175+
"which may cause runtime abnormalities\n");
176+
} catch (Exception ex2) {
177+
System.err.println("\rFailed to write " + e.getName()
178+
+ "!");
179+
180+
bytes.set(jarContents.getClassContents().namedMap().get(e.getName() + ".class").getData());
181+
}
182+
175183
}
176184
dataMap.add(new Map.Entry<String, byte[]>() {
177185
@Override

dev.skidfuscator.obfuscator/src/test/java/dev/skidfuscator/test/EncryptionTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ public void simpleStringEncryptTest() {
1111
final String string = RandomUtil.randomAlphabeticalString(10);
1212

1313
final Integer[] keysT = this._genKeys();
14+
15+
final BasicEncryptionGenerator generator = new BasicEncryptionGenerator(keysT);
1416
final int seed = this._genSeed();
1517

16-
final String encrypted = BasicEncryptionGenerator.encrypt(string, seed, keysT);
17-
final String decrypted = BasicEncryptionGenerator.decrypt(encrypted, seed, keysT);
18+
final String encrypted = generator.encrypt(string, seed);
19+
final String decrypted = generator.decrypt(encrypted, seed);
1820

1921
assert string.equals(decrypted) : "Encrypted string failed: " + string + " became " + decrypted;
2022
System.out.println("Passed Encryption Test #1");
@@ -25,10 +27,11 @@ public void simpleStringEncryptTestUTF8() {
2527
final String string = "Œüèé€ìàò";
2628

2729
final Integer[] keysT = this._genKeys();
30+
final BasicEncryptionGenerator generator = new BasicEncryptionGenerator(keysT);
2831
final int seed = this._genSeed();
2932

30-
final String encrypted = BasicEncryptionGenerator.encrypt(string, seed, keysT);
31-
final String decrypted = BasicEncryptionGenerator.decrypt(encrypted, seed, keysT);
33+
final String encrypted = generator.encrypt(string, seed);
34+
final String decrypted = generator.decrypt(encrypted, seed);
3235

3336
assert string.equals(decrypted) : "Encrypted string failed: " + string + " became " + decrypted;
3437
System.out.println("Passed Encryption Test #2");

org.mapleir.parent/org.mapleir.app-services/src/main/java/org/mapleir/app/service/ClassTree.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,19 @@ private Collection<ClassNode> __getnodes(Collection<? extends FastGraphEdge<Clas
103103
}
104104

105105
// returns a topoorder (supers first) traversal of the graph starting from cn.
106-
public List<ClassNode> getAllParents(ClassNode cn) {
107-
if(!containsVertex(cn)) {
106+
public List<ClassNode> getAllParents(ClassNode d) {
107+
if(!containsVertex(d)) {
108108
return new ArrayList<>();
109109
}
110-
return SimpleDfs.topoorder(this, cn, false);
110+
return SimpleDfs.topoorder(this, d, false);
111111
}
112112

113113
// returns a postorder traversal of the graph starting from cn following edges in opposite direction.
114-
public List<ClassNode> getAllChildren(ClassNode cn) {
115-
if(!containsVertex(cn)) {
114+
public List<ClassNode> getAllChildren(ClassNode d) {
115+
if(!containsVertex(d)) {
116116
return new ArrayList<>();
117117
}
118-
return SimpleDfs.postorder(this, cn, true);
118+
return SimpleDfs.postorder(this, d, true);
119119
}
120120

121121
/**

org.mapleir.parent/org.mapleir.stdlib/src/main/java/org/mapleir/stdlib/collections/graph/FastDirectedGraph.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.mapleir.dot4j.model.DotGraph;
99
import org.mapleir.propertyframework.api.IPropertyDictionary;
10+
import org.mapleir.stdlib.collections.graph.algorithms.SimpleDfs;
1011

1112
public abstract class FastDirectedGraph<N extends FastGraphVertex, E extends FastGraphEdge<N>> implements FastGraph<N, E>{
1213

@@ -161,6 +162,20 @@ public Stream<N> getPredecessors(N v) {
161162
return getReverseEdges(v).stream().map(E::src);
162163
}
163164

165+
public List<N> getAllParents(N d) {
166+
if(!containsVertex(d)) {
167+
return new ArrayList<>();
168+
}
169+
return SimpleDfs.topoorder(this, d, false);
170+
}
171+
172+
public List<N> getAllChildren(N d) {
173+
if(!containsVertex(d)) {
174+
return new ArrayList<>();
175+
}
176+
return SimpleDfs.postorder(this, d, true);
177+
}
178+
164179
@Override
165180
public int size() {
166181
return map.size();

0 commit comments

Comments
 (0)