Skip to content

Commit 1492c35

Browse files
committed
wip(obfuscator): fixing stuff
1 parent da3605b commit 1492c35

13 files changed

Lines changed: 166 additions & 9 deletions

File tree

dev.skidfuscator.maple-ir/org.mapleir.ir/src/main/java/org/mapleir/ir/cfg/ControlFlowGraph.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,16 @@ public List<BasicBlock> getJumpEdges(BasicBlock b) {
387387
return jes;
388388
}
389389

390+
public List<BasicBlock> getJumpReverseEdges(BasicBlock b) {
391+
List<BasicBlock> jes = new ArrayList<>();
392+
for (FlowEdge<BasicBlock> e : getReverseEdges(b)) {
393+
if (!(e instanceof ImmediateEdge)) {
394+
jes.add(e.dst());
395+
}
396+
}
397+
return jes;
398+
}
399+
390400
public boolean isHandler(BasicBlock b) {
391401
for(FlowEdge<BasicBlock> e : getReverseEdges(b)) {
392402
if(e instanceof TryCatchEdge) {

dev.skidfuscator.maple-ir/org.mapleir.ir/src/main/java/org/mapleir/ir/code/ExpressionPool.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.mapleir.ir.code;
22

3+
import org.mapleir.ir.TypeUtils;
34
import org.objectweb.asm.Type;
45

56
import javax.lang.model.util.Types;
@@ -151,7 +152,9 @@ public int computeSize() {
151152
int lastExist = 0;
152153

153154
for (int i = size(); i > 0; i--) {
154-
if (!get(i - 1).equals(Type.VOID_TYPE)) {
155+
final Type grab = get(i - 1);
156+
final boolean skip = grab.equals(Type.VOID_TYPE) || grab.equals(TypeUtils.UNDEFINED_TYPE);
157+
if (!skip) {
155158
lastExist = i;
156159
break;
157160
}

dev.skidfuscator.obfuscator/commons/pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,32 @@
3131
</dependency>
3232
</dependencies>
3333

34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-shade-plugin</artifactId>
39+
<version>3.0.0</version>
40+
<executions>
41+
<execution>
42+
<phase>package</phase>
43+
<goals>
44+
<goal>shade</goal>
45+
</goals>
46+
<configuration>
47+
<transformers>
48+
<transformer
49+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
50+
<manifestEntries>
51+
<Main-Class>dev.skidfuscator.obfuscator.SkidfuscatorMain</Main-Class>
52+
</manifestEntries>
53+
</transformer>
54+
</transformers>
55+
</configuration>
56+
</execution>
57+
</executions>
58+
</plugin>
59+
</plugins>
60+
</build>
61+
3462
</project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package dev.skidfuscator.inflator;
2+
3+
import lombok.experimental.UtilityClass;
4+
5+
import java.io.ByteArrayOutputStream;
6+
import java.io.IOException;
7+
import java.util.zip.DataFormatException;
8+
import java.util.zip.Deflater;
9+
import java.util.zip.Inflater;
10+
11+
@UtilityClass
12+
public class SkidInflator {
13+
private final int ARRAY_SIZE = 1024;
14+
15+
public byte[] compress(byte[] data) throws IOException {
16+
final Deflater deflater = new Deflater();
17+
deflater.setInput(data);
18+
19+
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
20+
final byte[] buffer = new byte[ARRAY_SIZE];
21+
22+
while (!deflater.finished()) {
23+
int count = deflater.deflate(buffer);
24+
outputStream.write(buffer, 0, count);
25+
}
26+
outputStream.close();
27+
28+
final byte[] output = outputStream.toByteArray();
29+
30+
return output;
31+
}
32+
33+
public byte[] decompress(byte[] data) throws IOException, DataFormatException {
34+
final Inflater inflater = new Inflater();
35+
inflater.setInput(data);
36+
37+
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
38+
final byte[] buffer = new byte[ARRAY_SIZE];
39+
40+
while (!inflater.finished()) {
41+
int count = inflater.inflate(buffer);
42+
outputStream.write(buffer, 0, count);
43+
}
44+
outputStream.close();
45+
46+
final byte[] output = outputStream.toByteArray();
47+
48+
return output;
49+
}
50+
}

dev.skidfuscator.obfuscator/commons/src/main/java/dev/skidfuscator/jghost/tree/GhostLibrary.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,8 @@ public GhostContents getContents() {
5757
public void setContents(GhostContents contents) {
5858
this.contents = contents;
5959
}
60+
61+
public void merge(final GhostLibrary library) {
62+
this.getContents().getClasses().putAll(library.getContents().getClasses());
63+
}
6064
}

dev.skidfuscator.obfuscator/commons/src/main/java/dev/skidfuscator/obfuscator/SkidfuscatorSession.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class SkidfuscatorSession {
1313
private File input;
1414
private File output;
1515
private File libs;
16+
private File mappings;
1617
private File exempt;
1718
private File runtime;
1819
private boolean phantom;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void dump() {
9090

9191
// Compute frames
9292
//computeFrames();
93-
//new FrameComputer(skidfuscator).compute(cfg);
93+
new FrameComputer(skidfuscator).compute(cfg);
9494

9595
// Stuff
9696
/*
@@ -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() || cfg.getJumpReverseEdges(b).isEmpty())
145145
break iter;
146146

147147
final SkidExpressionPool frameTypes = (SkidExpressionPool) b.getPool();
@@ -167,7 +167,8 @@ public void dump() {
167167
}
168168
}
169169

170-
final int frameComputedSize = frameTypes.computeSize();
170+
int eeee = isStatic ? 0 : 1 + parameterSize;
171+
final int frameComputedSize = Math.max(frameTypes.computeSize(), eeee);
171172

172173
/* Implicit frame */
173174
/*if (initialFrame.length >= frameComputedSize)
@@ -256,7 +257,7 @@ public void dump() {
256257

257258
} else {
258259
m.node.visitFrame(Opcodes.F_FULL, frame.length, frame, stack.length, stack);
259-
m.node.visitInsn(Opcodes.NOP);
260+
//m.node.visitInsn(Opcodes.NOP);
260261
}
261262
}
262263

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dev.skidfuscator.obfuscator.protection;
2+
3+
import dev.skidfuscator.obfuscator.event.Listener;
4+
5+
public interface ProtectionProvider extends Listener {
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package dev.skidfuscator.obfuscator.protection;
2+
3+
import dev.skidfuscator.obfuscator.event.annotation.Listen;
4+
import dev.skidfuscator.obfuscator.event.impl.transform.method.InitMethodTransformEvent;
5+
import dev.skidfuscator.obfuscator.skidasm.SkidMethodNode;
6+
import dev.skidfuscator.obfuscator.util.TypeUtil;
7+
import org.mapleir.ir.code.expr.ConstantExpr;
8+
9+
public class TokenLoggerProtectionProvider implements ProtectionProvider {
10+
11+
@Listen
12+
void handle(final InitMethodTransformEvent event) {
13+
final SkidMethodNode methodNode = event.getMethodNode();
14+
15+
methodNode.getCfg().allExprStream()
16+
.filter(ConstantExpr.class::isInstance)
17+
.map(ConstantExpr.class::cast)
18+
.filter(e -> e.getType().equals(TypeUtil.STRING_TYPE))
19+
.forEach(e -> {
20+
21+
});
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package dev.skidfuscator.obfuscator.protection;
2+
3+
import dev.skidfuscator.obfuscator.event.annotation.Listen;
4+
import dev.skidfuscator.obfuscator.event.impl.transform.method.InitMethodTransformEvent;
5+
import dev.skidfuscator.obfuscator.skidasm.SkidMethodNode;
6+
import dev.skidfuscator.obfuscator.util.TypeUtil;
7+
import org.mapleir.ir.code.expr.ConstantExpr;
8+
9+
public class WebhookProtectionProvider implements ProtectionProvider {
10+
11+
@Listen
12+
void handle(final InitMethodTransformEvent event) {
13+
final SkidMethodNode methodNode = event.getMethodNode();
14+
15+
methodNode.getCfg().allExprStream()
16+
.filter(ConstantExpr.class::isInstance)
17+
.map(ConstantExpr.class::cast)
18+
.filter(e -> e.getType().equals(TypeUtil.STRING_TYPE))
19+
.forEach(e -> {
20+
21+
});
22+
}
23+
}

0 commit comments

Comments
 (0)