-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(obf): mom new encryption system dropped
- Loading branch information
1 parent
f81321a
commit acbce8f
Showing
16 changed files
with
12,535 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
10,567 changes: 10,567 additions & 0 deletions
10,567
dev.skidfuscator.obfuscator/skidfuscator.log.1
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
120 changes: 120 additions & 0 deletions
120
.../src/main/java/dev/skidfuscator/obfuscator/transform/impl/string/StringTransformerV2.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,120 @@ | ||
package dev.skidfuscator.obfuscator.transform.impl.string; | ||
|
||
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.event.impl.transform.skid.PostSkidTransformEvent; | ||
import dev.skidfuscator.obfuscator.skidasm.SkidClassNode; | ||
import dev.skidfuscator.obfuscator.skidasm.SkidMethodNode; | ||
import dev.skidfuscator.obfuscator.skidasm.cfg.SkidBlock; | ||
import dev.skidfuscator.obfuscator.skidasm.expr.SkidConstantExpr; | ||
import dev.skidfuscator.obfuscator.transform.AbstractTransformer; | ||
import dev.skidfuscator.obfuscator.transform.Transformer; | ||
import dev.skidfuscator.obfuscator.transform.impl.string.generator.EncryptionGeneratorV3; | ||
import dev.skidfuscator.obfuscator.transform.impl.string.generator.v3.ByteBufferClinitV3EncryptionGenerator; | ||
import dev.skidfuscator.obfuscator.transform.impl.string.generator.v3.BytesClinitV3EncryptionGenerator; | ||
import dev.skidfuscator.obfuscator.util.RandomUtil; | ||
import org.mapleir.asm.ClassNode; | ||
import org.mapleir.ir.cfg.ControlFlowGraph; | ||
import org.mapleir.ir.code.CodeUnit; | ||
import org.mapleir.ir.code.Expr; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
public class StringTransformerV2 extends AbstractTransformer { | ||
private final Map<SkidClassNode, EncryptionGeneratorV3> keyMap = new HashMap<>(); | ||
|
||
private final Set<String> INJECTED = new HashSet<>(); | ||
|
||
public StringTransformerV2(Skidfuscator skidfuscator) { | ||
this(skidfuscator, Collections.emptyList()); | ||
} | ||
|
||
public StringTransformerV2(Skidfuscator skidfuscator, List<Transformer> children) { | ||
super(skidfuscator, "String Encryption", children); | ||
} | ||
|
||
@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; | ||
} | ||
|
||
final SkidClassNode parentNode = methodNode.getParent(); | ||
|
||
EncryptionGeneratorV3 generator = keyMap.get(parentNode); | ||
|
||
if (generator == null) { | ||
switch (RandomUtil.nextInt(1)) { | ||
default: { | ||
final int size = RandomUtil.nextInt(127) + 1; | ||
final byte[] keys = new byte[size]; | ||
|
||
for (int i = 0; i < size; i++) { | ||
keys[i] = (byte) (RandomUtil.nextInt(127) + 1); | ||
} | ||
|
||
keyMap.put(parentNode, (generator = new ByteBufferClinitV3EncryptionGenerator())); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (!INJECTED.contains(parentNode.getName())) { | ||
generator.visitPre((SkidClassNode) methodNode.owner); | ||
INJECTED.add(parentNode.getName()); | ||
} | ||
|
||
EncryptionGeneratorV3 finalGenerator = generator; | ||
cfg.allExprStream() | ||
/* | ||
* | ||
*/ | ||
.filter(SkidConstantExpr.class::isInstance) | ||
.map(SkidConstantExpr.class::cast) | ||
.filter(e -> !e.isExempt()) | ||
.filter(constantExpr -> constantExpr.getConstant() instanceof String) | ||
/* | ||
* We collect since we're modifying the expression stream | ||
* we kinda need to just not cause any concurrency issue. | ||
* ¯\_(ツ)_/¯ | ||
*/ | ||
.collect(Collectors.toList()) | ||
.forEach(unit -> { | ||
final CodeUnit parent = unit.getParent(); | ||
final String constant = (String) unit.getConstant(); | ||
final SkidBlock block = (SkidBlock) unit.getBlock(); | ||
|
||
final Expr encrypted = finalGenerator.encrypt(constant, methodNode, block); | ||
|
||
try { | ||
parent.overwrite(unit, encrypted); | ||
} catch (IllegalStateException e) { | ||
return; | ||
} | ||
}); | ||
this.success(); | ||
} | ||
|
||
@Listen | ||
void handle(final PostSkidTransformEvent event) { | ||
keyMap.forEach((clazz, generator) -> generator.visitPost(clazz)); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...va/dev/skidfuscator/obfuscator/transform/impl/string/generator/EncryptionGeneratorV3.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,88 @@ | ||
package dev.skidfuscator.obfuscator.transform.impl.string.generator; | ||
|
||
import dev.skidfuscator.obfuscator.skidasm.SkidClassNode; | ||
import dev.skidfuscator.obfuscator.skidasm.SkidMethodNode; | ||
import dev.skidfuscator.obfuscator.skidasm.cfg.SkidBlock; | ||
import org.mapleir.ir.code.Expr; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public interface EncryptionGeneratorV3 { | ||
Expr encrypt(String input, final SkidMethodNode node, final SkidBlock block); | ||
|
||
String decrypt(DecryptorDictionary input, int key); | ||
|
||
void visitPre(final SkidClassNode node); | ||
|
||
default void visitPost(final SkidClassNode node) {}; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
@interface InjectMethod { | ||
// empty | ||
String value(); | ||
InjectMethodTag[] tags() default {}; | ||
} | ||
|
||
enum InjectMethodTag { | ||
RANDOM_NAME | ||
} | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
@interface InjectField { | ||
// empty | ||
String value(); | ||
InjectFieldTag[] tags() default {}; | ||
} | ||
|
||
enum InjectFieldTag { | ||
RANDOM_NAME, | ||
FINAL, | ||
NO_INTERFACE_COMPAT | ||
} | ||
|
||
class DecryptorDictionary { | ||
private final Map<String, DecryptorItem<?>> items; | ||
|
||
public DecryptorDictionary(Map<String, DecryptorItem<?>> items) { | ||
this.items = items; | ||
} | ||
|
||
public <T> T get(String key) { | ||
return (T) items.get(key).getKey(); | ||
} | ||
|
||
public DecryptorDictionary of(String key, Object value) { | ||
items.put(key, new DecryptorItem<>(key, value)); | ||
return this; | ||
} | ||
|
||
public static DecryptorDictionary create() { | ||
return new DecryptorDictionary(new HashMap<>()); | ||
} | ||
} | ||
|
||
class DecryptorItem<T> { | ||
private final String key; | ||
private final T value; | ||
|
||
public DecryptorItem(String key, T value) { | ||
this.key = key; | ||
this.value = value; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public T getValue() { | ||
return value; | ||
} | ||
} | ||
} |
Oops, something went wrong.