native-obfuscator
native-obfuscator copied to clipboard
Breaks on obfuscated JAR
I wrote a simple Java program as follows:
import org.apache.commons.validator.routines.UrlValidator;
public class HelloWorldClient
{
public static void main(final String[] arguments)
{
UrlValidator urlValidator = new UrlValidator();
final boolean isUrlValid = urlValidator.isValid("https://stackoverflow.com");
System.out.println("Is URL valid: " + isUrlValid);
}
}
Output:
Is URL valid: true
I compiled the fat JAR (including the Apache Commons Validator
libraries but minified using maven
). The JAR ran successfully. Then, I applied a Java-based obfuscator on top of it. The JAR still ran successfully. Now I used native-obfuscator
to build the x64-windows.dll
and put it back into the native-obfuscator
generated JAR. So far so good. Upon running, the JAR however breaks with an exception:
Exception in thread "main" java.lang.ExceptionInInitializerError
at HelloWorldClient.main(Native Method)
Caused by: java.util.regex.PatternSyntaxException: Illegal repetition near index 48
/"'UGjggfub-Ka~.38vwP~0oWq;()Y2-9WL(C'@{yvwg3GBW@6WC}F"U-0$8efyX~{76gf98%27W,/72"CLZa.Y
kw'$Gf~{
./|k12gcu.],MwqsltlMpw$'
K\::(\d*))?(.*!7
^
at java.util.regex.Pattern.error(Pattern.java:1969)
at java.util.regex.Pattern.closure(Pattern.java:3171)
at java.util.regex.Pattern.sequence(Pattern.java:2148)
at java.util.regex.Pattern.expr(Pattern.java:2010)
at java.util.regex.Pattern.group0(Pattern.java:2919)
at java.util.regex.Pattern.sequence(Pattern.java:2065)
at java.util.regex.Pattern.expr(Pattern.java:2010)
at java.util.regex.Pattern.compile(Pattern.java:1702)
at java.util.regex.Pattern.<init>(Pattern.java:1352)
at java.util.regex.Pattern.compile(Pattern.java:1028)
at CoN.native0_special_clinit6(Native Method)
at CoN.<clinit>(r)
... 1 more
Without the Java-based obfuscation step, native-obfuscator
however works correctly in this case. Maybe you can figure out what goes wrong here:
JARs.zip
My transpiler command was standard with no special flags applied.
Thank you very much.
P.S. Yes, I'm aware that this project is not production ready which is a pity but maybe more bugs can be fixed regarding 3rd party library or obfuscator compatibility. Even GraalVM does not seem to be the native compilation savior here either.
Basically, the problem here is because of the obfuscation in static constructors. It uses the stack trace to generate the key for the string decryption, but I still lack proper stack trace creation for the static constructors. I'm working on it, but for you, the best solution will be to disable the usage of stack trace in it.
Finally fixed, now this should work properly (already tested on your binary)