NativeDetector
Native JNI-based detector for identifying device tampering through file system checks.
This detector extends FileDetector and uses native C/C++ code through JNI (Java Native Interface) to perform more sophisticated and harder-to-bypass file existence checks. The native implementation can potentially detect files even when Java-level file system access is restricted or monitored.
The detector specifically looks for the "su" (superuser) binary, which is the primary indicator of root access on Android devices. By using native code, it can:
Bypass Java-level security restrictions
Perform low-level file system operations
Be more difficult for anti-detection tools to hook or bypass
The native library "tool-file" must be available and properly linked for this detector to function. If the library fails to load, the detector gracefully degrades and returns 0.0 for all checks.
The scoring system returns a Double value:
1.0indicates at least one suspicious file was found (high confidence of tampering)0.0indicates no suspicious files were found or native library unavailable
Example usage:
val detector = NativeDetector()
val isTampered = detector.isTampered(context)