-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1a6479
commit af3594d
Showing
37 changed files
with
4,458 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...main/java/dev/skidfuscator/obfuscator/transform/impl/hash/StringEqualsHashTranformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package dev.skidfuscator.obfuscator.transform.impl.hash; | ||
|
||
import dev.skidfuscator.obfuscator.Skidfuscator; | ||
import dev.skidfuscator.obfuscator.event.EventPriority; | ||
import dev.skidfuscator.obfuscator.event.annotation.Listen; | ||
import dev.skidfuscator.obfuscator.event.impl.transform.method.RunMethodTransformEvent; | ||
import dev.skidfuscator.obfuscator.skidasm.SkidMethodNode; | ||
import dev.skidfuscator.obfuscator.skidasm.cfg.SkidBlock; | ||
import dev.skidfuscator.obfuscator.transform.AbstractTransformer; | ||
import dev.skidfuscator.obfuscator.util.cfg.Variables; | ||
import org.mapleir.ir.cfg.BasicBlock; | ||
import org.mapleir.ir.cfg.ControlFlowGraph; | ||
import org.mapleir.ir.code.Expr; | ||
import org.mapleir.ir.code.Stmt; | ||
import org.mapleir.ir.code.expr.ConstantExpr; | ||
import org.mapleir.ir.code.expr.VarExpr; | ||
import org.mapleir.ir.code.expr.invoke.InvocationExpr; | ||
import org.mapleir.ir.code.expr.invoke.StaticInvocationExpr; | ||
import sdk.LongHashFunction; | ||
|
||
import java.util.HashSet; | ||
|
||
public class StringEqualsHashTranformer extends AbstractTransformer { | ||
public StringEqualsHashTranformer(final Skidfuscator skidfuscator) { | ||
super(skidfuscator, "String Equals Hash"); | ||
} | ||
|
||
@Listen(EventPriority.LOWEST) | ||
void handle(final RunMethodTransformEvent event) { | ||
final SkidMethodNode methodNode = event.getMethodNode(); | ||
|
||
if (methodNode.isAbstract() | ||
|| methodNode.isInit()) { | ||
this.skip(); | ||
return; | ||
} | ||
|
||
if (methodNode.node.instructions.size() > 10000) { | ||
this.fail(); | ||
return; | ||
} | ||
|
||
final ControlFlowGraph cfg = methodNode.getCfg(); | ||
|
||
if (cfg == null) { | ||
this.fail(); | ||
return; | ||
} | ||
|
||
for (BasicBlock vertex : new HashSet<>(cfg.vertices())) { | ||
if (vertex.isFlagSet(SkidBlock.FLAG_NO_OPAQUE)) | ||
continue; | ||
|
||
if (methodNode.isClinit()) { | ||
continue; | ||
} | ||
|
||
for (Stmt stmt : new HashSet<>(vertex)) { | ||
for (Expr expr : stmt.enumerateOnlyChildren()) { | ||
if (expr instanceof InvocationExpr invocationExpr) { | ||
final boolean isEqualsMethod = | ||
invocationExpr.getOwner().equals("java/lang/String") | ||
&& invocationExpr.getName().equals("equals") | ||
&& invocationExpr.getDesc().equals("(Ljava/lang/Object;)Z"); | ||
|
||
if (methodNode.owner.getName().contains("BlowfishTest")) { | ||
System.out.println(expr); | ||
} | ||
|
||
if (!isEqualsMethod) | ||
continue; | ||
|
||
System.out.println(String.format("Found %s with matching%n", expr)); | ||
|
||
final Expr[] args = invocationExpr.getArgumentExprs(); | ||
Expr arg0 = args[0]; | ||
Expr arg1 = args[1]; | ||
|
||
if (arg0 instanceof VarExpr var0) { | ||
arg0 = Variables.getDefinition(cfg, var0); | ||
} | ||
|
||
if (arg1 instanceof VarExpr var1) { | ||
arg1 = Variables.getDefinition(cfg, var1); | ||
} | ||
|
||
final boolean isArg0Constant = arg0 instanceof ConstantExpr; | ||
final boolean isArg1Constant = arg1 instanceof ConstantExpr; | ||
|
||
if (isArg0Constant == isArg1Constant) { | ||
continue; | ||
} | ||
|
||
ConstantExpr constantExpr = isArg0Constant ? (ConstantExpr) arg0 : (ConstantExpr) arg1; | ||
Expr otherExpr = isArg0Constant ? arg1 : arg0; | ||
|
||
constantExpr.setConstant( | ||
"" + LongHashFunction.xx3().hashChars((String) constantExpr.getConstant()) | ||
); | ||
otherExpr.getParent().overwrite(otherExpr, new StaticInvocationExpr( | ||
new Expr[] { otherExpr.copy() }, | ||
"sdk/SDK", | ||
"hash", | ||
"(Ljava/lang/String;)Ljava/lang/String;" | ||
)); | ||
this.success(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
...dev/skidfuscator/obfuscator/transform/impl/hash/StringEqualsIgnoreCaseHashTranformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package dev.skidfuscator.obfuscator.transform.impl.hash; | ||
|
||
import dev.skidfuscator.obfuscator.Skidfuscator; | ||
import dev.skidfuscator.obfuscator.event.annotation.Listen; | ||
import dev.skidfuscator.obfuscator.event.impl.transform.method.RunMethodTransformEvent; | ||
import dev.skidfuscator.obfuscator.skidasm.SkidMethodNode; | ||
import dev.skidfuscator.obfuscator.skidasm.cfg.SkidBlock; | ||
import dev.skidfuscator.obfuscator.transform.AbstractTransformer; | ||
import dev.skidfuscator.obfuscator.util.cfg.Variables; | ||
import org.mapleir.ir.cfg.BasicBlock; | ||
import org.mapleir.ir.cfg.ControlFlowGraph; | ||
import org.mapleir.ir.code.Expr; | ||
import org.mapleir.ir.code.Stmt; | ||
import org.mapleir.ir.code.expr.ConstantExpr; | ||
import org.mapleir.ir.code.expr.VarExpr; | ||
import org.mapleir.ir.code.expr.invoke.InvocationExpr; | ||
import org.mapleir.ir.code.expr.invoke.StaticInvocationExpr; | ||
import org.mapleir.ir.code.expr.invoke.VirtualInvocationExpr; | ||
import sdk.LongHashFunction; | ||
|
||
import java.util.HashSet; | ||
|
||
public class StringEqualsIgnoreCaseHashTranformer extends AbstractTransformer { | ||
public StringEqualsIgnoreCaseHashTranformer(final Skidfuscator skidfuscator) { | ||
super(skidfuscator, "String EqIgCase Hash"); | ||
} | ||
|
||
@Listen | ||
void handle(final RunMethodTransformEvent event) { | ||
final SkidMethodNode methodNode = event.getMethodNode(); | ||
|
||
if (methodNode.isAbstract() | ||
|| methodNode.isInit()) { | ||
this.skip(); | ||
return; | ||
} | ||
|
||
if (methodNode.node.instructions.size() > 10000) { | ||
this.fail(); | ||
return; | ||
} | ||
|
||
final ControlFlowGraph cfg = methodNode.getCfg(); | ||
|
||
if (cfg == null) { | ||
this.fail(); | ||
return; | ||
} | ||
|
||
for (BasicBlock vertex : new HashSet<>(cfg.vertices())) { | ||
if (vertex.isFlagSet(SkidBlock.FLAG_NO_OPAQUE)) | ||
continue; | ||
|
||
if (methodNode.isClinit() && this.heuristicSizeSkip(methodNode, 8.f)) { | ||
continue; | ||
} | ||
|
||
for (Stmt stmt : new HashSet<>(vertex)) { | ||
for (Expr expr : stmt.enumerateOnlyChildren()) { | ||
if (expr instanceof InvocationExpr invocationExpr) { | ||
final boolean isEqualsMethod = | ||
invocationExpr.getOwner().equals("java/lang/String") | ||
&& invocationExpr.getName().equals("equalsIgnoreCase") | ||
&& invocationExpr.getDesc().equals("(Ljava/lang/String;)Z"); | ||
|
||
if (!isEqualsMethod) | ||
continue; | ||
|
||
System.out.println(String.format("Found %s with matching", expr)); | ||
|
||
final Expr[] args = invocationExpr.getArgumentExprs(); | ||
Expr arg0 = args[0]; | ||
Expr arg1 = args[1]; | ||
|
||
if (arg0 instanceof VarExpr var0) { | ||
arg0 = Variables.getDefinition(cfg, var0); | ||
} | ||
|
||
if (arg1 instanceof VarExpr var1) { | ||
arg1 = Variables.getDefinition(cfg, var1); | ||
} | ||
|
||
final boolean isArg0Constant = arg0 instanceof ConstantExpr; | ||
final boolean isArg1Constant = arg1 instanceof ConstantExpr; | ||
|
||
if (isArg0Constant == isArg1Constant) { | ||
continue; | ||
} | ||
|
||
ConstantExpr constantExpr = isArg0Constant ? (ConstantExpr) arg0 : (ConstantExpr) arg1; | ||
Expr otherExpr = isArg0Constant ? arg1 : arg0; | ||
|
||
constantExpr.setConstant( | ||
"" + LongHashFunction.xx3().hashChars(((String) constantExpr.getConstant()).toLowerCase()) | ||
); | ||
otherExpr.getParent().overwrite(otherExpr, new StaticInvocationExpr( | ||
new Expr[] { new VirtualInvocationExpr( | ||
InvocationExpr.CallType.VIRTUAL, | ||
new Expr[]{otherExpr.copy()}, | ||
"java/lang/String", | ||
"toLowerCase", | ||
"()Ljava/lang/String;" | ||
)}, | ||
"sdk/SDK", | ||
"hash", | ||
"(Ljava/lang/String;)Ljava/lang/String;" | ||
)); | ||
this.success(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
.../src/main/java/dev/skidfuscator/obfuscator/transform/impl/sdk/SdkInjectorTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package dev.skidfuscator.obfuscator.transform.impl.sdk; | ||
|
||
import dev.skidfuscator.obfuscator.Skidfuscator; | ||
import dev.skidfuscator.obfuscator.event.annotation.Listen; | ||
import dev.skidfuscator.obfuscator.event.impl.transform.skid.InitSkidTransformEvent; | ||
import dev.skidfuscator.obfuscator.transform.AbstractTransformer; | ||
import dev.skidfuscator.obfuscator.util.MapleJarUtil; | ||
import org.mapleir.asm.ClassNode; | ||
import org.topdank.byteengineer.commons.data.JarClassData; | ||
import org.topdank.byteio.in.SingleJarDownloader; | ||
|
||
import java.io.*; | ||
import java.nio.file.Files; | ||
|
||
import static dev.skidfuscator.obfuscator.util.JdkDownloader.CACHE_DIR; | ||
|
||
public class SdkInjectorTransformer extends AbstractTransformer { | ||
public SdkInjectorTransformer(Skidfuscator skidfuscator) { | ||
super(skidfuscator, "SDK"); | ||
} | ||
|
||
@Listen | ||
void handle(final InitSkidTransformEvent event) { | ||
try { | ||
// Create cache directory if it doesn't exist | ||
if (!Files.exists(CACHE_DIR)) { | ||
Files.createDirectories(CACHE_DIR); | ||
} | ||
|
||
// Extract SDK jar from resources to cache | ||
File sdkFile = CACHE_DIR.resolve("sdk.jar").toFile(); | ||
try (InputStream is = getClass().getClassLoader().getResourceAsStream("resources/sdk.jar"); | ||
OutputStream os = new FileOutputStream(sdkFile)) { | ||
if (is == null) { | ||
throw new IOException("Could not find sdk.jar in resources"); | ||
} | ||
byte[] buffer = new byte[8192]; | ||
int bytesRead; | ||
while ((bytesRead = is.read(buffer)) != -1) { | ||
os.write(buffer, 0, bytesRead); | ||
} | ||
} | ||
|
||
// Import the SDK jar classes | ||
final SingleJarDownloader<ClassNode> downloader = MapleJarUtil.importJar( | ||
sdkFile, | ||
skidfuscator | ||
); | ||
|
||
// Add SDK classes to the input jar | ||
for (JarClassData classData : downloader.getJarContents().getClassContents()) { | ||
skidfuscator.getJarContents().getClassContents().add(classData); | ||
} | ||
|
||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to inject SDK", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.