SILENCESILENCE
Desktop Apps

Hera Klass: Java Bytecode Security & Obfuscation Guide

Java bytecode retains extensive symbolic metadata—class descriptors, method signatures, local variable tables, and line numbers. Consequently, modern decompilers (CFR, Procyon, Fernflower, JD-GUI) can reconstruct readable high-level Java source code from raw binaries within seconds.

Hera Klass is an enterprise-grade bytecode protection suite engineered to safeguard intellectual property across desktop software and custom Minecraft mod ecosystems without compromising runtime performance.


1. Multi-Tier Transformation Mechanics

Hera Klass strictly adheres to OWASP anti-reverse-engineering guidelines through a four-phase transformation pipeline:

[ Input Application JAR ]
           │
           ▼
[ ASM Bytecode Parsing & Hierarchy Analysis ]
           │
           ├─► Phase 1: Identifier Collisions (Unprintable Unicode / Overload Collisions)
           │
           ├─► Phase 2: Control Flow Flattening (Dispatcher State Machines & Opaque Predicates)
           │
           ├─► Phase 3: Dynamic Polymorphic Constant Encryption (String/Number Hashing)
           │
           └─► Phase 4: Debug Strip & Anti-Decompiler Trap Injection
           │
           ▼
[ Protected & Cryptographically Signed Binary ]

A. Identifier Collision & Renaming

Transforms readable identifiers into non-printable Unicode sequences or platform-reserved file naming tokens. It utilizes overload collisions—assigning identical names to methods with differing parameter or return signatures—confounding the heuristic algorithms of static decompilers.

B. Control Flow Flattening

Converts structured loops and conditional blocks into monolithic switch-case state machines. By injecting opaque predicates—branch conditions whose outcomes are invariant at runtime but indecipherable via static analysis—decompilers encounter recursion timeouts or stack overflow faults during control flow graph (CFG) analysis.

C. Dynamic Constant Encryption

Hardcoded literals (strings, cryptographic keys, URLs, and numeric constants) are compiled into encrypted byte arrays. Decryption keys are derived dynamically from invocation call stacks and classloader state hashes, defeating memory scraping and symbolic tracing.


2. Reflection & Keep Rules Configuration Syntax

Arbitrary obfuscation breaks reflection-dependent frameworks (Spring, Jackson, Gson, Fabric Mixins), triggering NoSuchMethodException or JSON parsing errors. Hera Klass uses an expressive regex-based Keep Rules system:

# 1. Preserve public API endpoints and interfaces
-keep class net.silencehub.api.** {
    public *;
}

# 2. Preserve fields and no-arg constructors for JSON DTO serialization
-keep class net.silencehub.model.** {
    <fields>;
    <init>();
}

# 3. Preserve Fabric Mixin annotated injection points
-keepclassmembers class * {
    @org.spongepowered.asm.mixin.injection.Inject *;
    @org.spongepowered.asm.mixin.injection.ModifyVariable *;
}

# 4. Standard preservation for Enum value resolution
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

3. Workflow & CI/CD Automation

Graphical Dashboard Workflow

  1. Load Artifact: Drag and drop your compiled target .jar onto the dashboard.
  2. Apply Security Preset:
    • Lightweight: Minimal overhead, basic renaming and line number scrubbing.
    • Standard (Recommended): Balanced control flow restructuring with string encryption.
    • Maximum Security: Aggressive state flattening and decompiler traps.
  3. Verify Dependencies: Register library JARs (lib/*.jar) to assist inheritance tree resolution.
  4. Compile: Click 'Build Protected JAR' to generate the protected binary.

Automated Gradle Integration

Incorporate Hera Klass directly into your continuous integration workflow:

task obfuscateJar(type: Exec) {
    dependsOn jar
    commandLine 'java', '-jar', 'tools/heraklass-cli.jar',
        '--input', "${buildDir}/libs/app.jar",
        '--output', "${buildDir}/libs/app-protected.jar",
        '--rules', 'heraklass.rules',
        '--libraries', configurations.runtimeClasspath.asPath
}

4. Troubleshooting & FAQ

Q1: The protected JAR throws a ClassNotFoundException.

Cause: An external library relies on reflective naming that was obfuscated without an explicit rule.
Resolution: Append -keep class com.example.service.** to preserve the necessary reflection targets.

Q2: Noticeable performance dips in numeric loops.

Cause: Heavy control flow flattening applied to high-frequency math routines.
Resolution: Exclude performance-critical packages using -noflatten class com.example.math.**.

Q3: Fabric Mixin fails to apply at game start.

Cause: Target method descriptors in the injection signature were altered during renaming.
Resolution: Always keep Mixin accessor classes and preserve method descriptors across injected boundaries.