Package com.craftingdead.protect
Class NativeProtection
java.lang.Object
com.craftingdead.protect.NativeProtection
JNI wrapper for native protection layer (cdprotect library).
This class provides access to native (C/C++) implementations of protection checks
that are harder to reverse-engineer and tamper with than pure Java code.
CURSEFORGE-SAFE GUARANTEES:
- Native library operates ONLY on this JVM process (no system-wide hooks)
- NO automatic downloads or updates
- NO network calls from native code
- NO filesystem modifications (except temp extraction if needed)
- NO scanning of other processes
- NO data collection or telemetry
- NO kernel-level hooks or rootkit behavior
The native layer ONLY provides:
- Enhanced integrity checking (harder to bypass than pure Java)
- Enhanced environment detection (debuggers, agents within our process)
- Challenge-response verification (anti-tamper)
GRACEFUL DEGRADATION:
If the native library fails to load, all methods return safe defaults and
the protection system falls back to pure Java implementations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanSafe wrapper for nativeEnvClean() that handles library not loaded.static booleanSafe wrapper for nativeIntegrityOk() that handles library not loaded.static intcomputeExpectedChallenge(int seed) Computes the expected response for a challenge seed (Java-side verification).static StringGets a status string describing the native protection state.static booleanisLoaded()Checks if the native protection library was successfully loaded.static intnativeChallenge(int seed) Performs a challenge-response computation for anti-tamper verification.static booleanPerforms native-level environment cleanliness check.static booleanPerforms native-level integrity verification.static intperformChallenge(int seed) Safe wrapper for nativeChallenge() that handles library not loaded.static booleanverifyNativeLibrary(int seed) Verifies that the native library is genuine by performing a challenge-response check.
-
Method Details
-
isLoaded
public static boolean isLoaded()Checks if the native protection library was successfully loaded.- Returns:
- true if native library is available, false otherwise
-
nativeIntegrityOk
public static boolean nativeIntegrityOk()Performs native-level integrity verification. This method verifies the integrity of the JAR file containing this class using native code that is harder to tamper with than pure Java. Implementation details (native side): - Computes SHA-256 hash of the JAR file - Compares against expected hash (baked into native library) - Returns false if tampering is detected - Returns false on any error (safe default) CURSEFORGE-SAFE: - Only checks our own JAR file - NO network calls - NO filesystem modifications - NO scanning of other files- Returns:
- true if integrity check passes, false if tampering detected or library not loaded
-
nativeEnvClean
public static boolean nativeEnvClean()Performs native-level environment cleanliness check. This method detects suspicious debugging/profiling environments using native code that is harder to bypass than pure Java checks. Implementation details (native side): - Checks for debugger attachment (within this process only) - Detects known profiling agents (via JVM args inspection) - Looks for suspicious JNI/JVMTI agents - Returns false if hostile environment detected - Returns false on any error (safe default) CURSEFORGE-SAFE: - Only inspects THIS JVM process - NO scanning of other processes - NO system-wide hooks - NO kernel-level checks- Returns:
- true if environment appears clean, false if suspicious or library not loaded
-
nativeChallenge
public static int nativeChallenge(int seed) Performs a challenge-response computation for anti-tamper verification. This method computes a non-trivial response based on the input seed, using native code that is harder to reverse-engineer. The Java side can verify the response to ensure the native library hasn't been replaced. Implementation details (native side): - Performs a deterministic computation on the seed - Uses obfuscated algorithm (not cryptographically secure, just hard to RE) - Returns consistent results for same seed - Returns 0 on any error Usage pattern:int seed = new Random().nextInt(); int nativeResult = NativeProtection.nativeChallenge(seed); int expectedResult = computeExpectedChallenge(seed); // Java implementation if (nativeResult != expectedResult) { // Native library may have been tampered with }CURSEFORGE-SAFE: - Pure computation, no side effects - NO network calls - NO filesystem access - NO system modifications- Parameters:
seed- Input value for the challenge- Returns:
- Computed response value, or 0 if library not loaded
-
checkIntegrity
public static boolean checkIntegrity()Safe wrapper for nativeIntegrityOk() that handles library not loaded.- Returns:
- true if native library is loaded AND integrity check passes, false otherwise
-
checkEnvironment
public static boolean checkEnvironment()Safe wrapper for nativeEnvClean() that handles library not loaded.- Returns:
- true if native library is loaded AND environment is clean, false otherwise
-
performChallenge
public static int performChallenge(int seed) Safe wrapper for nativeChallenge() that handles library not loaded.- Parameters:
seed- Input seed for challenge- Returns:
- Challenge response, or 0 if library not loaded or error occurs
-
computeExpectedChallenge
public static int computeExpectedChallenge(int seed) Computes the expected response for a challenge seed (Java-side verification). This should match the native implementation's algorithm. It's intentionally simpler than the native version (which may use more obfuscation). This is used to verify the native library hasn't been replaced with a stub.- Parameters:
seed- Input seed- Returns:
- Expected response value
-
verifyNativeLibrary
public static boolean verifyNativeLibrary(int seed) Verifies that the native library is genuine by performing a challenge-response check.- Parameters:
seed- Random seed for the challenge- Returns:
- true if native library responds correctly, false otherwise
-
getStatus
Gets a status string describing the native protection state. Useful for logging and diagnostics.- Returns:
- Human-readable status string
-