Skip to content

Commit c99bd6a

Browse files
committed
String compression / anti debugger
1 parent 263ef5b commit c99bd6a

20 files changed

+2630
-89
lines changed

README.md

Lines changed: 672 additions & 40 deletions
Large diffs are not rendered by default.

config-examples/enhanced.json

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"obfuscationLevel": "AGGRESSIVE",
3+
"mainClass": "com/example/MyApp",
4+
5+
"obfuscation": {
6+
"renameClasses": true,
7+
"renameFields": true,
8+
"renameMethods": true,
9+
"renameLocalVariables": true,
10+
"obfuscateConditions": true,
11+
"compressStrings": true,
12+
"shuffleMembers": true,
13+
"optimizeCode": true
14+
},
15+
16+
"naming": {
17+
"namingMode": "RANDOM_SHORT"
18+
},
19+
20+
"security": {
21+
"antiDebugging": true,
22+
"debuggerAction": "CORRUPT_EXECUTION"
23+
},
24+
25+
"packages": {
26+
"includePackages": [
27+
"com/example/core",
28+
"com/example/business"
29+
],
30+
"excludePackages": [
31+
"com/example/test",
32+
"com/example/debug"
33+
]
34+
},
35+
36+
"keepRules": {
37+
"keepMainClass": true,
38+
"keepStandardEntryPoints": true,
39+
"keepClasses": [
40+
"com/example/api/PublicAPI",
41+
"com/example/config/Configuration"
42+
],
43+
"keepClassPatterns": [
44+
".*Controller",
45+
"com/example/dto/.*",
46+
".*Exception"
47+
],
48+
"keepMethods": {
49+
"com/example/api/PublicAPI": [
50+
"publicMethod",
51+
{
52+
"name": "specificMethod",
53+
"descriptor": "(Ljava/lang/String;)V"
54+
}
55+
]
56+
},
57+
"keepMethodPatterns": {
58+
".*Controller": ["handle.*", "process.*"],
59+
".*Service": ["get.*", "set.*"]
60+
},
61+
"keepFields": {
62+
"com/example/Constants": ["VERSION", "BUILD_DATE"]
63+
},
64+
"keepFieldPatterns": {
65+
".*Entity": ["id", ".*Date"],
66+
".*Config": [".*"]
67+
}
68+
},
69+
70+
"debugging": {
71+
"preserveLineNumbers": false,
72+
"preserveLocalVariableNames": false,
73+
"verbose": false,
74+
"generateScore": true
75+
},
76+
77+
"performance": {
78+
"maxThreads": 4,
79+
"sequentialTransformers": false
80+
},
81+
82+
"backup": {
83+
"enableBackup": true,
84+
"backupDir": "./backups"
85+
},
86+
87+
"customSettings": {
88+
"stringEncryptionKey": "myCustomKey123",
89+
"customTransformerEnabled": true,
90+
"aggressiveOptimization": true
91+
}
92+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"mainClass": "com/example/SecureApplication",
3+
"renameClasses": true,
4+
"renameFields": true,
5+
"renameMethods": true,
6+
"renameLocalVariables": true,
7+
"obfuscateConditions": true,
8+
"antiDebugging": true,
9+
"debuggerAction": "CORRUPT_EXECUTION",
10+
"generateScore": true,
11+
"namingMode": "RANDOM_LONG",
12+
"verbose": false,
13+
"keepRules": {
14+
"keepMainClass": true,
15+
"keepStandardEntryPoints": true
16+
}
17+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"obfuscationLevel": "AGGRESSIVE",
3+
"mainClass": "StringCompressionExample",
4+
5+
"obfuscation": {
6+
"renameClasses": true,
7+
"renameFields": true,
8+
"renameMethods": true,
9+
"renameLocalVariables": true,
10+
"obfuscateConditions": true,
11+
"compressStrings": true,
12+
"shuffleMembers": false,
13+
"optimizeCode": true
14+
},
15+
16+
"naming": {
17+
"namingMode": "RANDOM_SHORT"
18+
},
19+
20+
"security": {
21+
"antiDebugging": false,
22+
"debuggerAction": "EXIT_SILENTLY"
23+
},
24+
25+
"keepRules": {
26+
"keepMainClass": true,
27+
"keepStandardEntryPoints": true
28+
},
29+
30+
"debugging": {
31+
"preserveLineNumbers": false,
32+
"preserveLocalVariableNames": false,
33+
"verbose": true,
34+
"generateScore": true
35+
},
36+
37+
"performance": {
38+
"maxThreads": 2,
39+
"sequentialTransformers": false
40+
},
41+
42+
"backup": {
43+
"enableBackup": true,
44+
"backupDir": "./backups"
45+
},
46+
47+
"customSettings": {
48+
"stringCompressionMinLength": 10,
49+
"stringCompressionProbability": 0.7
50+
}
51+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class StringCompressionExample {
2+
public static void main(String[] args) {
3+
String shortString = "Hello";
4+
String longString = "This is a very long string that contains a lot of text and should be compressed when the obfuscator processes it. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
5+
String repeatedString = "Java Bytecode Obfuscation is awesome! ".repeat(5);
6+
String configString = "com.example.application.configuration.DatabaseConnectionProperties";
7+
8+
System.out.println("Short string: " + shortString);
9+
System.out.println("Long string: " + longString);
10+
System.out.println("Repeated string: " + repeatedString);
11+
System.out.println("Config string: " + configString);
12+
13+
processStrings(shortString, longString, repeatedString, configString);
14+
}
15+
16+
private static void processStrings(String... strings) {
17+
for (int i = 0; i < strings.length; i++) {
18+
System.out.println("Processing string " + (i + 1) + ": " + strings[i].substring(0, Math.min(50, strings[i].length())) + "...");
19+
}
20+
}
21+
}

src/main/java/net/cvs0/Main.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.cvs0.config.ConfigLoader;
99
import net.cvs0.config.NamingMode;
1010
import net.cvs0.mappings.export.MappingExporter;
11+
import net.cvs0.utils.AntiDebugger;
1112
import net.cvs0.utils.Logger;
1213

1314
import java.io.File;
@@ -45,6 +46,9 @@ public class Main implements Callable<Integer>
4546
@Option(names = {"--obfuscate-conditions"}, description = "Enable condition obfuscation (transforms true/false into complex expressions)")
4647
private Boolean obfuscateConditions;
4748

49+
@Option(names = {"--compress-strings"}, description = "Enable string compression (compresses string literals using deflate/base64)")
50+
private Boolean compressStrings;
51+
4852
@Option(names = {"--mappings", "--output-mappings"}, description = "Output mappings file")
4953
private File mappingsFile;
5054

@@ -84,6 +88,24 @@ public class Main implements Callable<Integer>
8488
" SINGLE_CHAR - Single character names (a, b, c...)")
8589
private NamingMode namingMode;
8690

91+
@Option(names = {"--anti-debugging"}, description = "Enable anti-debugging protection")
92+
private Boolean antiDebugging;
93+
94+
@Option(names = {"--debugger-action"},
95+
description = "Action to take when debugger is detected:%n" +
96+
" EXIT_SILENTLY - Exit without error%n" +
97+
" EXIT_WITH_ERROR - Exit with error code%n" +
98+
" CORRUPT_EXECUTION - Corrupt execution flow%n" +
99+
" INFINITE_LOOP - Enter infinite loop%n" +
100+
" FAKE_EXECUTION - Continue with fake behavior")
101+
private AntiDebugger.DebuggerAction debuggerAction;
102+
103+
@Option(names = {"--generate-score"}, description = "Generate obfuscation resistance score")
104+
private Boolean generateScore;
105+
106+
@Option(names = {"--sequential-transformers"}, description = "Run transformers sequentially - each transformer processes all classes before the next starts (disabled by default)")
107+
private Boolean sequentialTransformers;
108+
87109
public static void main(String[] args)
88110
{
89111
int exitCode = new CommandLine(new Main()).execute(args);
@@ -177,6 +199,10 @@ private ObfuscationConfig buildConfiguration() throws Exception
177199
builder.obfuscateConditions(obfuscateConditions);
178200
}
179201

202+
if (compressStrings != null) {
203+
builder.compressStrings(compressStrings);
204+
}
205+
180206
if (verbose) {
181207
builder.verbose(true);
182208
}
@@ -206,6 +232,22 @@ private ObfuscationConfig buildConfiguration() throws Exception
206232
builder.namingMode(namingMode);
207233
}
208234

235+
if (antiDebugging != null) {
236+
builder.antiDebugging(antiDebugging);
237+
}
238+
239+
if (debuggerAction != null) {
240+
builder.debuggerAction(debuggerAction);
241+
}
242+
243+
if (generateScore != null) {
244+
builder.generateScore(generateScore);
245+
}
246+
247+
if (sequentialTransformers != null) {
248+
builder.sequentialTransformers(sequentialTransformers);
249+
}
250+
209251
if (configFile == null && renameClasses == null && renameFields == null && renameMethods == null && renameLocalVariables == null) {
210252
builder.renameClasses(true)
211253
.renameFields(true)

src/main/java/net/cvs0/Obfuscator.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import net.cvs0.config.ObfuscationConfig;
44
import net.cvs0.core.ObfuscationEngine;
5+
import net.cvs0.transformers.AntiDebuggingTransformer;
56
import net.cvs0.transformers.ClassRenameTransformer;
67
import net.cvs0.transformers.FieldRenameTransformer;
78
import net.cvs0.transformers.MethodRenameTransformer;
89
import net.cvs0.transformers.LocalVariableRenameTransformer;
910
import net.cvs0.transformers.ConditionObfuscationTransformer;
11+
import net.cvs0.transformers.StringCompressionTransformer;
12+
import net.cvs0.utils.AntiDebugger;
1013

1114
import java.io.File;
1215
import java.io.IOException;
@@ -29,15 +32,22 @@ private void registerDefaultTransformers()
2932
engine.registerTransformer(new MethodRenameTransformer());
3033
engine.registerTransformer(new ConditionObfuscationTransformer());
3134
engine.registerTransformer(new LocalVariableRenameTransformer());
35+
engine.registerTransformer(new StringCompressionTransformer());
3236
}
3337

3438
public void obfuscate(File inputJar, File outputJar, ObfuscationConfig config, File mappingsFile) throws IOException
3539
{
40+
if (config.isAntiDebugging()) {
41+
engine.registerTransformer(new AntiDebuggingTransformer(AntiDebugger.DebuggerAction.EXIT_SILENTLY));
42+
}
3643
engine.obfuscate(inputJar, outputJar, config, mappingsFile);
3744
}
3845

3946
public void obfuscate(File inputJar, File outputJar, ObfuscationConfig config, File mappingsFile, MappingExporter.MappingFormat format) throws IOException
4047
{
48+
if (config.isAntiDebugging()) {
49+
engine.registerTransformer(new AntiDebuggingTransformer(AntiDebugger.DebuggerAction.EXIT_SILENTLY));
50+
}
4151
engine.obfuscate(inputJar, outputJar, config, mappingsFile, format);
4252
}
4353

0 commit comments

Comments
 (0)