Skip to content

Commit

Permalink
feat: major rework and optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
terminalsin committed Jan 1, 2025
1 parent ff796d5 commit 1e41127
Show file tree
Hide file tree
Showing 34 changed files with 400 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import dev.skidfuscator.obfuscator.transform.impl.sdk.SdkInjectorTransformer;
import dev.skidfuscator.obfuscator.transform.impl.string.StringEncryptionType;
import dev.skidfuscator.obfuscator.transform.impl.string.StringTransformerV2;
import dev.skidfuscator.obfuscator.transform.impl.vm.VmConditionTransformer;
import dev.skidfuscator.obfuscator.util.ConsoleColors;
import dev.skidfuscator.obfuscator.util.MapleJarUtil;
import dev.skidfuscator.obfuscator.util.MiscUtil;
Expand All @@ -84,10 +85,8 @@
import org.mapleir.deob.PassGroup;
import org.mapleir.deob.dataflow.LiveDataFlowAnalysisImpl;
import org.mapleir.ir.cfg.ControlFlowGraph;
import org.matomo.java.tracking.MatomoTracker;
import org.matomo.java.tracking.TrackerConfiguration;
import org.matomo.java.tracking.*;
import org.objectweb.asm.Opcodes;
import org.matomo.java.tracking.MatomoRequest;
import org.topdank.byteengineer.commons.data.JarClassData;
import org.topdank.byteengineer.commons.data.JarContents;

Expand All @@ -114,6 +113,7 @@ public class Skidfuscator {
public static boolean CLOUD = false;

public static final String VERSION = "2.1.0";
public static final Double VERSION_DOUBLE = 2.1;

private final SkidfuscatorSession session;

Expand Down Expand Up @@ -383,36 +383,62 @@ public void run() {
}

private void _runAnalytics() {
final MatomoTracker tracker = new MatomoTracker(
final String sessionId = UUID.randomUUID().toString();
try (MatomoTracker tracker = new MatomoTracker(
TrackerConfiguration
.builder()
.apiEndpoint(URI.create("https://analytics.ghast.dev/matomo.php"))
.build()
);
final MatomoRequest request = MatomoRequest.request()
.siteId(1)
.actionUrl("https://app.skidfuscator.dev")
.actionName("skidfuscator/launch")
.campaignName("community")
.campaignKeyword("launch")
.pluginJava(true)
.userId(MiscUtil.getHwid())
.additionalParameters(Map.of(
"version", VERSION,
"java_version", String.valueOf(MiscUtil.getJavaVersion()),
"os", System.getProperty("os.name"),
"os_version", System.getProperty("os.version"),
"os_arch", System.getProperty("os.arch")
))
.serverTime(System.currentTimeMillis())
.customAction(true)
.apiVersion(VERSION)
.eventAction("launch")
.eventCategory("skidfuscator/community")
.eventName("Java")
.eventValue((double) MiscUtil.getJavaVersion())
.build();
tracker.sendRequestAsync(request);
)) {
final MatomoRequest versionRequest = MatomoRequests
.event("skidfuscator", "version", VERSION, null)
.userId(MiscUtil.getHwid())
.siteId(1)
.pluginJava(true)
.campaignName("community")
.campaignKeyword("launch")
.sessionId(sessionId)
.build();
final MatomoRequest javaRequest = MatomoRequests
.event("skidfuscator", "java_version", null, (double) MiscUtil.getJavaVersion())
.userId(MiscUtil.getHwid())
.siteId(1)
.pluginJava(true)
.campaignName("community")
.campaignKeyword("launch")
.sessionId(sessionId)
.build();
final MatomoRequest osRequest = MatomoRequests
.event("skidfuscator", "os", System.getProperty("os.name"), null)
.userId(MiscUtil.getHwid())
.siteId(1)
.pluginJava(true)
.campaignName("community")
.campaignKeyword("launch")
.sessionId(sessionId)
.build();
final MatomoRequest osVersionRequest = MatomoRequests
.event("skidfuscator", "os_version", System.getProperty("os.version"), null)
.userId(MiscUtil.getHwid())
.siteId(1)
.pluginJava(true)
.campaignName("community")
.campaignKeyword("launch")
.sessionId(sessionId)
.build();
final MatomoRequest osArchRequest = MatomoRequests
.event("skidfuscator", "os_arch", System.getProperty("os.arch"), null)
.userId(MiscUtil.getHwid())
.siteId(1)
.pluginJava(true)
.campaignName("community")
.campaignKeyword("launch")
.sessionId(sessionId)
.build();
tracker.sendBulkRequestAsync(versionRequest, javaRequest, osRequest, osVersionRequest, osArchRequest);
} catch (Exception e) {
LOGGER.warn("Failed to send analytics request");
}
}

protected void _verifyEnvironment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.Map;
import java.util.Set;

import com.google.gson.internal.bind.ArrayTypeAdapter;
import lombok.Getter;
import org.mapleir.app.service.ApplicationClassSource;
import org.mapleir.app.service.ClassTree;
import org.objectweb.asm.Opcodes;
Expand All @@ -32,50 +34,55 @@ private static Set<Type> __getIntrinsicErrors() {
public static final Type CLASS = Type.getType(Class.class);
public static final Type STRING_TYPE = Type.getType(String.class);
public static final Type OBJECT_TYPE = Type.getType(Object.class);
public static final Type OBJECT_ARRAY_TYPE = Type.getType(Object[].class);
public static final Type CLONEABLE_TYPE = Type.getType(Cloneable.class);
public static final Type SERIALIZABLE_TYPE = Type.getType(Serializable.class);
public static final Type THROWABLE = Type.getType(Throwable.class);
public static final Type NULL_TYPE = Type.getType(Null.class);
public static final Type UNDEFINED_TYPE = Type.getType(Undefined.class);
public static final Type UNINITIALIZED_TYPE = Type.getType(Uninitialized.class);

public static final Type INT_ARRAY_TYPE = Type.getType(int[].class);
public static final Type LONG_ARRAY_TYPE = Type.getType(long[].class);
public static final Type DOUBLE_ARRAY_TYPE = Type.getType(double[].class);
public static final Type FLOAT_ARRAY_TYPE = Type.getType(float[].class);

// TODO: remove
public static final Type ANY = Type.getType("L<any>;");


public enum ArrayType {
INT(Type.INT_TYPE, 0),
LONG(Type.LONG_TYPE, 1),
FLOAT(Type.FLOAT_TYPE, 2),
DOUBLE(Type.DOUBLE_TYPE, 3),
OBJECT(OBJECT_TYPE, 4),
BYTE(Type.BYTE_TYPE, 5),
CHAR(Type.CHAR_TYPE, 6),
SHORT(Type.SHORT_TYPE, 7);
public static ArrayType arrayTypeOfObject(final Type type) {
return ArrayType.ofObj(type);
}

@Getter
public static class ArrayType {
public static ArrayType INT = new ArrayType(Type.INT_TYPE, 0);
public static ArrayType LONG = new ArrayType(Type.LONG_TYPE, 1);
public static ArrayType FLOAT = new ArrayType(Type.FLOAT_TYPE, 2);
public static ArrayType DOUBLE = new ArrayType(Type.DOUBLE_TYPE, 3);
public static ArrayType OBJECT = new ArrayType(OBJECT_TYPE, 4);
public static ArrayType BYTE = new ArrayType(Type.BYTE_TYPE, 5);
public static ArrayType CHAR = new ArrayType(Type.CHAR_TYPE, 6);
public static ArrayType SHORT = new ArrayType(Type.SHORT_TYPE, 7);

private final Type type;
private final int loadOpcode, storeOpcode;

private static final ArrayType[] VALUES = new ArrayType[] {
INT, LONG, FLOAT, DOUBLE, OBJECT, BYTE, CHAR, SHORT
};

public static ArrayType[] values() {
return VALUES;
}

private ArrayType(Type type, int offset) {
public ArrayType(Type type, int offset) {
this.type = type;
loadOpcode = IALOAD + offset;
storeOpcode = IASTORE + offset;
}

public Type getType() {
return type;
}

public int getLoadOpcode() {
return loadOpcode;
}

public int getStoreOpcode() {
return storeOpcode;
}

public static ArrayType resolve(int opcode) {

public static ArrayType resolve(int opcode) {
if(opcode >= IALOAD && opcode <= SALOAD) {
return values()[opcode - IALOAD];
} else if(opcode >= IASTORE && opcode <= SASTORE) {
Expand All @@ -84,6 +91,10 @@ public static ArrayType resolve(int opcode) {
throw new UnsupportedOperationException(Printer.OPCODES[opcode]);
}
}

public static ArrayType ofObj(final Type objectType) {
return new ArrayType(objectType, 4);
}
}

public static final Type[] OPCODE_TYPE_TABLE = new Type[] { Type.INT_TYPE, Type.LONG_TYPE, Type.FLOAT_TYPE, Type.DOUBLE_TYPE, OBJECT_TYPE, Type.BYTE_TYPE, Type.CHAR_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ public Stmt set(int index, Stmt stmt) {
return statements.set(index, stmt);
}

public void replace(final Stmt o, final Stmt n) {
statements.add(indexOf(o), n);
statements.remove(o);
}

@Override
public int size() {
return statements.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public int makeBlockId() {
return blockCounter++;
}

public Stream<CodeUnit> traverse() {
return vertices().stream().flatMap(Collection::stream)
.map(Stmt::traverse)
.flatMap(Streams::stream);
}

public Stream<CodeUnit> allExprStream() {
return vertices().stream().flatMap(Collection::stream).map(Stmt::enumerateWithSelf).flatMap(Streams::stream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ControlFlowGraphBuilder {

public final MethodNode method;
protected final SSAFactory factory;
protected final ControlFlowGraph graph;
public final ControlFlowGraph graph;
protected final Set<Local> locals;
protected final NullPermeableHashMap<Local, Set<BasicBlock>> assigns;
protected BasicBlock head;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import org.mapleir.stdlib.util.TabbedStringWriter;
import org.objectweb.asm.MethodVisitor;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;

/**
* This is the shared base between the {@link Stmt} and {@link Expr} classes,
Expand Down Expand Up @@ -406,6 +403,10 @@ public static String print(CodeUnit node) {
return printer.toString();
}

public List<CodeUnit> traverse() {
return Collections.emptyList();
}

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

import java.util.Collections;
import java.util.List;

public class AllocObjectExpr extends Expr {

private Type type;
Expand Down Expand Up @@ -60,4 +63,9 @@ public boolean canChangeFlow() {
public boolean equivalent(CodeUnit s) {
return s instanceof AllocObjectExpr && type.equals(((AllocObjectExpr) s).type);
}

@Override
public List<CodeUnit> traverse() {
return List.of(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import org.objectweb.asm.Type;
import org.objectweb.asm.util.Printer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.objectweb.asm.Opcodes.*;

public class ArithmeticExpr extends Expr {
Expand Down Expand Up @@ -301,4 +305,15 @@ public void overwrite(Expr previous, Expr newest) {
// // TODO Auto-generated method stub
// return 0;
// }


@Override
public List<CodeUnit> traverse() {
final List<CodeUnit> self = new ArrayList<>();
self.add(this);
self.addAll(left.traverse());
self.addAll(right.traverse());

return self;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

import java.util.ArrayList;
import java.util.List;

public class ArrayLengthExpr extends Expr {

private Expr expression;
Expand Down Expand Up @@ -85,4 +88,11 @@ public void overwrite(Expr previous, Expr newest) {
public boolean equivalent(CodeUnit s) {
return (s instanceof ArrayLengthExpr) && expression.equivalent(((ArrayLengthExpr)s).expression);
}

@Override
public List<CodeUnit> traverse() {
final List<CodeUnit> self = new ArrayList<>(List.of(this));
self.addAll(expression.traverse());
return self;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;

import java.util.ArrayList;
import java.util.List;

public class ArrayLoadExpr extends Expr {

private Expr arrayExpression;
Expand Down Expand Up @@ -53,7 +56,9 @@ public Expr copy() {

@Override
public Type getType() {
return type.getType();
return arrayExpression.getType().getSort() == Type.ARRAY
? arrayExpression.getType().getElementType()
: type.getType();
}

@Override
Expand Down Expand Up @@ -125,4 +130,12 @@ public boolean equivalent(CodeUnit s) {
}
return false;
}

@Override
public List<CodeUnit> traverse() {
final List<CodeUnit> self = new ArrayList<>(List.of(this));
self.addAll(arrayExpression.traverse());
self.addAll(indexExpression.traverse());
return self;
}
}
Loading

0 comments on commit 1e41127

Please sign in to comment.