Skip to content

Commit 92a95ef

Browse files
committed
Fake Exceptions + Fake interfaces + method inliner
1 parent 9be70cd commit 92a95ef

File tree

8 files changed

+1348
-7
lines changed

8 files changed

+1348
-7
lines changed

README.md

Lines changed: 255 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ A powerful and flexible Java bytecode obfuscator built with ASM that provides co
1111
- **Local Variable Renaming** - Obfuscate local variable names for additional protection
1212
- **Condition Obfuscation** - Transform simple boolean constants (true/false) into complex arithmetic expressions
1313
- **String Compression** - Compress string literals using deflate/base64 encoding to reduce size and obfuscate content
14-
- **String Compression** - Compress string literals using deflate/base64 encoding to reduce size and obfuscate content
14+
- **Method Inlining** - Inline simple methods to reduce call overhead and obfuscate control flow
15+
- **Fake Interface Flooding** - Generate fake interfaces and implement them to confuse reverse engineering tools
16+
- **Fake Exception Insertion** - Insert fake exception checks that never execute to complicate static analysis
1517
- **Anti-Debugging Protection** - Runtime detection and response to debugging attempts
1618
- **Reference Updating** - Automatically updates all references to renamed elements throughout the codebase
1719
- **Inheritance-Aware Renaming** - Properly handles interface implementations and method overrides
@@ -577,6 +579,254 @@ The transformer automatically determines which strings to compress based on:
577579
- Single words and short constants
578580
- Format strings and patterns
579581

582+
## 🔧 Method Inlining
583+
584+
Method inlining replaces method calls with the actual method body, reducing call overhead and making the code harder to analyze by eliminating method boundaries.
585+
586+
### How It Works
587+
588+
The transformer identifies simple methods that are good candidates for inlining and replaces calls to these methods with their actual implementation.
589+
590+
**Original Code:**
591+
```java
592+
public class Calculator {
593+
public int add(int a, int b) {
594+
return a + b;
595+
}
596+
597+
public int calculate() {
598+
return add(5, 3); // Method call
599+
}
600+
}
601+
```
602+
603+
**Obfuscated Code:**
604+
```java
605+
public class a1 {
606+
public int a1(int a, int b) {
607+
return a + b; // Method still exists but may not be called
608+
}
609+
610+
public int a2() {
611+
return 5 + 3; // Method call inlined
612+
}
613+
}
614+
```
615+
616+
### Features
617+
618+
- **Smart Method Selection** - Only inlines simple methods without complex control flow
619+
- **Safety Checks** - Avoids inlining methods with field access or complex operations
620+
- **Conservative Approach** - Prevents inlining that could break functionality
621+
- **Stack-Safe** - Generates proper bytecode that passes JVM verification
622+
- **Selective Inlining** - Only processes methods that benefit from inlining
623+
624+
### Usage
625+
626+
```bash
627+
# Enable method inlining via CLI
628+
java -jar obfuscator.jar input.jar output.jar --inline-simple-methods
629+
630+
# Combined with other obfuscation techniques
631+
java -jar obfuscator.jar input.jar output.jar \
632+
--rename-classes --rename-methods --inline-simple-methods \
633+
--obfuscate-conditions --verbose
634+
```
635+
636+
### Configuration File
637+
638+
```json
639+
{
640+
"obfuscation": {
641+
"renameClasses": true,
642+
"renameMethods": true,
643+
"inlineSimpleMethods": true
644+
}
645+
}
646+
```
647+
648+
### Inlining Criteria
649+
650+
Methods are considered for inlining if they:
651+
- Are short (< 5 instructions)
652+
- Don't access fields
653+
- Don't contain loops or branches
654+
- Don't throw exceptions
655+
- Are not constructors or static initializers
656+
657+
## 🎭 Fake Interface Flooding
658+
659+
Fake interface flooding generates synthetic interfaces and makes classes implement them, creating false inheritance relationships that confuse reverse engineering tools and static analysis.
660+
661+
### How It Works
662+
663+
The transformer creates fake interfaces with random methods and makes target classes implement these interfaces, adding noise to the class hierarchy without affecting functionality.
664+
665+
**Original Code:**
666+
```java
667+
public class DataProcessor {
668+
public void process(String data) {
669+
System.out.println("Processing: " + data);
670+
}
671+
}
672+
```
673+
674+
**Obfuscated Code:**
675+
```java
676+
// Generated fake interfaces
677+
interface a1 {
678+
void m1();
679+
int m2(String s);
680+
}
681+
682+
interface a2 {
683+
boolean m3();
684+
}
685+
686+
public class a3 implements a1, a2 {
687+
public void process(String data) { // Original method
688+
System.out.println("Processing: " + data);
689+
}
690+
691+
// Fake implementations that never execute
692+
public void m1() { throw new UnsupportedOperationException(); }
693+
public int m2(String s) { throw new UnsupportedOperationException(); }
694+
public boolean m3() { throw new UnsupportedOperationException(); }
695+
}
696+
```
697+
698+
### Features
699+
700+
- **Dynamic Interface Generation** - Creates unique interfaces for each obfuscation run
701+
- **Configurable Quantity** - Control how many fake interfaces are added per class
702+
- **Method Variety** - Generates diverse method signatures with different return types
703+
- **Exception Throwing** - Fake methods throw exceptions to prevent accidental execution
704+
- **Inheritance Safe** - Doesn't interfere with existing inheritance hierarchies
705+
706+
### Usage
707+
708+
```bash
709+
# Enable fake interface flooding with default count (10)
710+
java -jar obfuscator.jar input.jar output.jar --flood-fake-interfaces
711+
712+
# Specify custom interface count
713+
java -jar obfuscator.jar input.jar output.jar --flood-fake-interfaces --fake-interface-count 25
714+
715+
# Combined with other obfuscation
716+
java -jar obfuscator.jar input.jar output.jar \
717+
--rename-classes --flood-fake-interfaces --fake-interface-count 15 \
718+
--rename-methods --verbose
719+
```
720+
721+
### Configuration File
722+
723+
```json
724+
{
725+
"obfuscation": {
726+
"renameClasses": true,
727+
"renameMethods": true,
728+
"floodFakeInterfaces": true,
729+
"fakeInterfaceCount": 20
730+
}
731+
}
732+
```
733+
734+
### Benefits
735+
736+
- **Analysis Confusion** - Makes automated tools report false inheritance relationships
737+
- **Code Bloat** - Increases apparent code complexity
738+
- **Pattern Breaking** - Disrupts class hierarchy analysis
739+
- **Reverse Engineering Difficulty** - Makes understanding class relationships harder
740+
741+
## ⚡ Fake Exception Insertion
742+
743+
Fake exception insertion adds conditional exception checks throughout the code that appear functional but never actually execute, creating complex control flow that complicates static analysis.
744+
745+
### How It Works
746+
747+
The transformer inserts exception checks with conditions that are mathematically impossible to satisfy, adding apparent complexity without affecting program execution.
748+
749+
**Original Code:**
750+
```java
751+
public void processData(String input) {
752+
if (input != null) {
753+
System.out.println("Processing: " + input);
754+
}
755+
}
756+
```
757+
758+
**Obfuscated Code:**
759+
```java
760+
public void a1(String a2) {
761+
// Fake exception check - hash will never equal Integer.MAX_VALUE
762+
"fake_check_123".hashCode(); // Complex calculation that's discarded
763+
764+
if (a2 != null) {
765+
// Another fake check - 1.0 + 2.0 never equals 3.0 comparison
766+
1.0 + 2.0; // Result discarded
767+
768+
System.out.println("Processing: " + a2);
769+
}
770+
}
771+
```
772+
773+
### Features
774+
775+
- **Non-Executing Checks** - All fake checks are mathematically designed to never trigger
776+
- **Diverse Patterns** - Uses various types of calculations (string hash, math operations, etc.)
777+
- **Stack-Safe Operations** - All operations properly manage the JVM stack
778+
- **Conservative Insertion** - Only adds checks at safe insertion points
779+
- **Performance Neutral** - Minimal runtime impact from simple calculations
780+
781+
### Usage
782+
783+
```bash
784+
# Enable fake exception insertion
785+
java -jar obfuscator.jar input.jar output.jar --insert-fake-exceptions
786+
787+
# Combined with comprehensive obfuscation
788+
java -jar obfuscator.jar input.jar output.jar \
789+
--rename-classes --rename-methods --insert-fake-exceptions \
790+
--obfuscate-conditions --compress-strings --verbose
791+
```
792+
793+
### Configuration File
794+
795+
```json
796+
{
797+
"obfuscation": {
798+
"renameClasses": true,
799+
"renameMethods": true,
800+
"insertFakeExceptions": true,
801+
"obfuscateConditions": true
802+
}
803+
}
804+
```
805+
806+
### Check Types
807+
808+
The transformer uses several types of fake checks:
809+
810+
| Type | Description | Example |
811+
|------|-------------|---------|
812+
| **String Hash** | Computes hash codes that never match target values | `"fake_check".hashCode()` |
813+
| **Math Operations** | Simple arithmetic with known results | `1.0 + 2.0` |
814+
| **String Length** | String length calculations | `"test".length()` |
815+
816+
### Benefits
817+
818+
- **Static Analysis Confusion** - Makes control flow appear more complex
819+
- **Code Pattern Disruption** - Breaks up recognizable code patterns
820+
- **Reverse Engineering Difficulty** - Adds apparent exception handling logic
821+
- **Minimal Performance Impact** - Simple operations with negligible runtime cost
822+
823+
### Best Practices
824+
825+
1. **Combine with Other Techniques** - Use alongside renaming and condition obfuscation
826+
2. **Test Thoroughly** - Verify that fake checks don't interfere with application logic
827+
3. **Monitor Performance** - While minimal, ensure no unexpected performance impact
828+
4. **Validate Functionality** - Confirm all original exception handling still works correctly
829+
580830
## CLI Reference
581831

582832
### Command Line Options
@@ -604,6 +854,10 @@ Obfuscation Options:
604854
--rename-local-variables Enable local variable renaming
605855
--obfuscate-conditions Enable condition obfuscation (transforms boolean constants)
606856
--compress-strings Enable string compression (deflate/base64 encoding)
857+
--inline-simple-methods Enable simple method inlining
858+
--flood-fake-interfaces Enable fake interface flooding
859+
--fake-interface-count <n> Number of fake interfaces per class (1-50, default: 10)
860+
--insert-fake-exceptions Insert fake exception checks
607861
--shuffle-members Enable member shuffling
608862
--optimize-code Enable code optimization
609863

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ public class Main implements Callable<Integer>
4949
@Option(names = {"--compress-strings"}, description = "Enable string compression (compresses string literals using deflate/base64)")
5050
private Boolean compressStrings;
5151

52+
@Option(names = {"--flood-fake-interfaces"}, description = "Enable fake interface flooding (adds confusing fake interfaces to classes)")
53+
private Boolean floodFakeInterfaces;
54+
55+
@Option(names = {"--fake-interface-count"}, description = "Number of fake interfaces to add per class (1-50, default: 10)")
56+
private Integer fakeInterfaceCount;
57+
58+
@Option(names = {"--inline-simple-methods"}, description = "Enable simple method inlining (inlines short methods to reduce call overhead)")
59+
private Boolean inlineSimpleMethods;
60+
61+
@Option(names = {"--insert-fake-exceptions"}, description = "Insert fake exception checks (adds complex conditional exception throws that never execute)")
62+
private Boolean insertFakeExceptions;
63+
5264
@Option(names = {"--mappings", "--output-mappings"}, description = "Output mappings file")
5365
private File mappingsFile;
5466

@@ -410,6 +422,22 @@ private ObfuscationConfig buildConfiguration() throws Exception
410422
builder.compressStrings(compressStrings);
411423
}
412424

425+
if (floodFakeInterfaces != null) {
426+
builder.floodFakeInterfaces(floodFakeInterfaces);
427+
}
428+
429+
if (fakeInterfaceCount != null) {
430+
builder.fakeInterfaceCount(fakeInterfaceCount);
431+
}
432+
433+
if (inlineSimpleMethods != null) {
434+
builder.inlineSimpleMethods(inlineSimpleMethods);
435+
}
436+
437+
if (insertFakeExceptions != null) {
438+
builder.insertFakeExceptions(insertFakeExceptions);
439+
}
440+
413441
if (verbose) {
414442
builder.verbose(true);
415443
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import net.cvs0.transformers.LocalVariableRenameTransformer;
1010
import net.cvs0.transformers.ConditionObfuscationTransformer;
1111
import net.cvs0.transformers.StringCompressionTransformer;
12+
import net.cvs0.transformers.FakeInterfaceTransformer;
13+
import net.cvs0.transformers.FakeExceptionTransformer;
14+
import net.cvs0.transformers.MethodInlinerTransformer;
1215

1316
import net.cvs0.utils.AntiDebugger;
1417

@@ -34,6 +37,9 @@ private void registerDefaultTransformers()
3437
engine.registerTransformer(new ConditionObfuscationTransformer());
3538
engine.registerTransformer(new LocalVariableRenameTransformer());
3639
engine.registerTransformer(new StringCompressionTransformer());
40+
engine.registerTransformer(new FakeInterfaceTransformer());
41+
engine.registerTransformer(new FakeExceptionTransformer());
42+
engine.registerTransformer(new MethodInlinerTransformer());
3743
}
3844

3945
public void obfuscate(File inputJar, File outputJar, ObfuscationConfig config, File mappingsFile, MappingExporter.MappingFormat format) throws IOException

0 commit comments

Comments
 (0)