Giter VIP home page Giter VIP logo

native-obfuscator's Introduction

native-obfuscator

Java .class to .cpp converter for use with JNI

Currently fully supports only Java 8. Java 9+ and Android support is entirely experimental

Warning: blacklist/whitelist usage is recommended because this tool slows down code significantly (like do not obfuscate full Minecraft .jar)

Also, this tool does not particularly obfuscate your code; it just transpiles it to native. Remember to use protectors like VMProtect, Themida, or obfuscator-llvm (in case of clang usage)


To run this tool, you need to have these tools installed:

  1. JDK 8

    • For Windows:

      I recommend downloading Oracle JDK 8, though you need to have some login credentials on Oracle.

    • For Linux/MacOS:

      Google "your distro install jdk 8", and install the required packages

  2. CMake

    • For Windows:

      Download the latest release from CMake

    • For Linux/MacOS:

      Google "your distro install cmake" and install the required package (default - apt/yum/brew install cmake)

  3. C++/C compiler toolchain

    • For Windows:

      Download the freeware version of MSVS from Microsoft and select Visual C++ compiler in opt-ins

      Or install mingw if you have any experience with this.

    • For Linux/MacOS:

      Google "your distro install g++"


General usage:

Usage: native-obfuscator [-ahV] [--debug] [-b=<blackListFile>]
                         [--custom-lib-dir=<customLibraryDirectory>]
                         [-l=<librariesDirectory>] [-p=<platform>]
                         [--plain-lib-name=<libraryName>] [-w=<whiteListFile>]
                         <jarFile> <outputDirectory>
Transpiles .jar file into .cpp files and generates output .jar file
      <jarFile>           Jar file to transpile
      <outputDirectory>   Output directory
  -a, --annotations       Use annotations to ignore/include native obfuscation
  -b, --black-list=<blackListFile>
                          File with a list of blacklist classes/methods for
                            transpilation
      --custom-lib-dir=<customLibraryDirectory>
                          Custom library directory for LoaderUnpack
      --debug             Enable generation of debug .jar file (non-executable)
  -h, --help              Show this help message and exit.
  -l, --libraries=<librariesDirectory>
                          Directory for dependent libraries
  -p, --platform=<platform>
                          Target platform: hotspot - standard standalone
                            HotSpot JRE, std_java - java standard, android -
                            for Android builds (w/o DefineClass)
      --plain-lib-name=<libraryName>
                          Plain library name for LoaderPlain
  -V, --version           Print version information and exit.
  -w, --white-list=<whiteListFile>
                          File with a list of whitelist classes/methods for
                            transpilation

Arguments:

<jarFile> - input .jar file to obfuscate

<outputDirectory> - output directory where C++/new .jar file where be created

-l <librariesDirectory> - directory where dependant libraries should be, optional, but preferable

-p <platform> - JVM platform to run library on

Three options are available:

  • hotspot: will use HotSpot JVM internals and should work with most obfuscators (even with stack trace checking as well)
  • std_java: will use only minor JVM internals that must be available on all JVMs
  • android: use this method when building library for Android. Will use no JVM internals, as well as no DefineClass for hidden methods (obfuscators that rely on stack for string/name obfuscator will not work due to the fact that some methods will not be hidden)

-a - enable annotation processing

To use annotations for black/whitelisting methods/classes as native you can add the following library to your project:

com.github.radioegor146.native-obfuscator:annotations:master-SNAPSHOT

Also, you need to add JitPack to your repositories.

You can add @Native annotation to include classes/methods to the native obfuscation process and add @NotNative annotation to ignore methods in classes marked as @Native

Whitelist/Blacklist has higher priority than annotations.

-w <whiteList> - path to .txt file for whitelist of methods and classes if required

-b <blackList> - path to a .txt file for a blacklist of methods and classes if required

Both of them should come in such form:

<class>
<class>#<method name>#<method descriptor>
mypackage/myotherpackage/Class1
mypackage/myotherpackage/Class1#doSomething!()V
mypackage/myotherpackage/Class1$SubClass#doOther!(I)V

It uses internal names of classes and method descriptors for filtering (you can read more about it by googling "java internal class names" or "java method descriptors")

Also, you can use a wildcard matcher like these:

mypackage/myotherpackage/*
mypackage/myotherpackagewithnested/**
mypackage/myotherpackage/*/Class1
mypackage/myotherpackagewithnested/**/Class1
mypackage/myotherpackage/Class*

* matches a single entry (divided by /) in the class/package name

** matches all entries in class/package name

--plain-lib-name - if you ship your .jar separately from the result native libraries, or you use it for Android, you can specify the name of the native library that it will try to search while using.

--custom-lib-dir - if you want to set custom directory for storing libraries inside the jar

If you want to ship your .jar with native libraries in it, you should omit that argument, and after building native files, add them in the form of

x64-windows.dll
x64-linux.so
x86-windows.dll
x64-macos.dylib
arm64-linux.so
arm64-windows.dll

to the directory of the .jar file that this tool will print in stdout (by default native0/ or custom if --custom-lib-dir is present)

Basic usage:

  1. Transpile your code using java -jar native-obfuscator.jar <input jar> <output directory>
  2. Run cmake . in the result cpp directory
  3. Add changes to .cpp code if necessary
  4. Run cmake --build . --config Release in result cpp directory to build .so/.dll file
  5. Copy result .dll/.so from build/libs/ to the path specified in the previous paragraph.
  6. Run created .jar java -jar <output jar> and enjoy!

Building the tool by yourself

  1. Run gradlew assemble to force gradle not to run tests after the build

Tests

You need to have Krakatau installed to your PATH, because test suite is using krak2 for some tests

  1. Run gradlew build to assemble and run full test suite

This tool uses tests from huzpsb/JavaObfuscatorTest


In case of any problems, feel free to open an issue or contact me at re146.dev

Stargazers over time

Stargazers over time

native-obfuscator's People

Contributors

2eui2ehi2e avatar darkkeks avatar imfl0wow avatar radioegor146 avatar xxdark avatar zaxar163 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

native-obfuscator's Issues

Some optimizations

We can unwrap stack and locals from special structs to variables because in JVM stack is not "dynamic" as it should be. Also, making them work in this way can help the C++ compiler to optimize them better.

Execute cmake. An error occurs

I successfully ran java -jar native-obfuscator.jar
It gives me a cpp folder and jar file
when I try to type cmake .
it went wrong

-- Building for: NMake Makefiles
CMake Error at CMakeLists.txt:2 (project):
  Running

   'nmake' '-?'

  failed with:

   The system can not find the file specified。


CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

I want to know what should I do to make it work

issue with that "SYNTHETIC_LOCAL_VARIABLE" thing that i see in my decompiler.

Exception in thread "main" java.lang.VerifyError: Bad local variable type.
This comes after another error, when compiling the c++ it says that clocal0 is not defined, i added it as a jvalue but that gave me this other error.

:\b\out\cpp\output\Main.cpp(137,9): error C2065: 'clocal0': undeclared identifier [C:\b\out\cpp\native_library.vcxproj]
C:\b\out\cpp\output\Main.cpp(137,38): error C2065: 'clocal0': undeclared identifier [C:\b\out\cpp\native_library.vcxproj]

Minecraft client not working after obfuscation

Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
Exception in thread "main" java.lang.UnsatisfiedLinkError: native0.Loader.registerNativesForClass(ILjava/lang/Class;)V
at native0.Loader.registerNativesForClass(Native Method)
at net.minecraft.client.main.Main.(net_minecraft_client_main_Main.cpp)

Alt class files generator.

Non sourcecode. Only classfiles. Easy to realize with asm`s ClassReader.SKIP_CODE and adding to each method Opcode NATIVE.

ConsoleAppender exception

Hi, thanks for this interesting project. When I run the released obfuscator.jar, I get the following exceptions:

2022-09-23 16:19:13,824 main ERROR Unable to inject fields into builder class for plugin type class org.apache.logging.log4j.core.appender.ConsoleAppender, element Console. java.nio.charset.UnsupportedCharsetException: cp65001
        at java.nio.charset.Charset.forName(Charset.java:531)
        at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:146)
        at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:134)
        at org.apache.logging.log4j.core.appender.ConsoleAppender$Target.getCharset(ConsoleAppender.java:85)
        at org.apache.logging.log4j.core.appender.ConsoleAppender$Target$2.getDefaultCharset(ConsoleAppender.java:78)
        at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:218)
        at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:185)
        at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
        at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
        at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
        at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:122)
        at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
        at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
        at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
        at by.radioegor146.NativeObfuscator.<clinit>(NativeObfuscator.java:39)
        at by.radioegor146.Main$NativeObfuscatorRunner.call(Main.java:68)
        at by.radioegor146.Main$NativeObfuscatorRunner.call(Main.java:20)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at by.radioegor146.Main.main(Main.java:77)

2022-09-23 16:19:13,830 main ERROR Unable to invoke factory method in class class org.apache.logging.log4j.core.appender.ConsoleAppender for element Console. java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.ConsoleAppender
        at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:224)
        at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:130)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
        at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
        at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
        at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:122)
        at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
        at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
        at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
        at by.radioegor146.NativeObfuscator.<clinit>(NativeObfuscator.java:39)
        at by.radioegor146.Main$NativeObfuscatorRunner.call(Main.java:68)
        at by.radioegor146.Main$NativeObfuscatorRunner.call(Main.java:20)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at by.radioegor146.Main.main(Main.java:77)

2022-09-23 16:19:13,833 main ERROR Null object returned for Console in Appenders.
2022-09-23 16:19:13,840 main ERROR Unable to locate appender "Console" for logger config "root"
/native0/

This is quite irritating but it seems like it still finished the job successfully. I'm using Windows 11 Pro and CMD as well as Java 8 of course.

Unknown obfuscator error

The instructions in Basic Usage states:

  • Copy result .dll/.so from build/libs/ to the specified in previous paragraph path.

The jar is written to the output folder, and I would put the binary inside the jar.
(I put the binary x64-linux.so into native0 as I use linux x64)

But that doesn't work...
I am greeted with the following exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: 'void k.a(java.io.File, java.util.function.BiConsumer, java.util.function.Consumer)'
	at k.a(Native Method)
	at me.micartey.test.Main.main(Unknown Source)

I ran the following command:

java -jar obfuscator.jar target.jar out -a

Support Class Filter

sometimes we only need to protect or obfuscate a fewer classes,such as encrypt algorithm method,

Failed to cmake

Well let's just say for every single class it say

error: 'cclasses_mtx' was not declared in this scope

Can you tell me how to make a .dll file?

Tell me how to make a .dll file or how to run the program? So I got a jar file, then there is a cpp folder for me, what do I need to do in dll right away? Tell me please

Cant build project files

Im getting this error after executing cmake -S cpp -B outputFolder

PS C:\Users\User\Desktop\NativeTranslated> cmake -S C:\Users\User\Desktop\NativeTranslated\cpp -B C:\Users\User\Desktop\NativeTranslated\output
-- Building for: NMake Makefiles
-- The C compiler identification is MSVC 19.29.30136.0
-- The CXX compiler identification is MSVC 19.29.30136.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x86/cl.exe - broken
CMake Error at D:/Program Files/CMake/share/cmake-3.21/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x86/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/User/Desktop/NativeTranslated/output/CMakeFiles/CMakeTmp

    Run Build Command(s):nmake -f Makefile /nologo cmTC_50b77\fast &&   "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x86\nmake.exe"  -f CMakeFiles\cmTC_50b77.dir\build.make /nologo -L                  CMakeFiles\cmTC_50b77.dir\build
    Building C object CMakeFiles/cmTC_50b77.dir/testCCompiler.c.obj
        "D:\Program Files\CMake\bin\cmake.exe" -E cmake_cl_compile_depends --dep-file=CMakeFiles\cmTC_50b77.dir\testCCompiler.c.obj.d --working-dir=C:\Users\User\Desktop\NativeTranslated\output\CMakeFiles\CMakeTmp --filter-prefix="Nota: file incluso  C:" -- C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x86\cl.exe @C:\Users\User\AppData\Local\Temp\nmC219.tmp
    testCCompiler.c
    Linking C executable cmTC_50b77.exe
        "D:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_50b77.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x86\link.exe /nologo @CMakeFiles\cmTC_50b77.dir\objects1.rsp @C:\Users\User\AppData\Local\Temp\nmC278.tmp
    RC Pass 1: command "rc /fo CMakeFiles\cmTC_50b77.dir/manifest.res CMakeFiles\cmTC_50b77.dir/manifest.rc" failed (exit code 0) with the following output:
    Unable to find specified fileNMAKE : fatal error U1077: '"D:\Program Files\CMake\bin\cmake.exe"' : with code '0xffffffff'
    Stop.
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x86\nmake.exe"' : with code '0x2'
    Stop.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Users/User/Desktop/NativeTranslated/output/CMakeFiles/CMakeOutput.log".
See also "C:/Users/User/Desktop/NativeTranslated/output/CMakeFiles/CMakeError.log".

Im using windows 10 and ive both visual studio & cmake installed. What to do?

Support APK file

Android APK file is based on Java too but the format is in dex/smali files. Can you add support for it too?

MethodHandle.invoke/invokeExact

currently no support for invoke/invokeExact due to unaccessibility of this methods from JNI.
change this methods to invokeWithArguments

About build up the environment

Hello, I want to build the environment for this project, but I find that build.gradle 'in the house' com.github.johnrengelman . shadow 'version' 5.0.0 'is invalid. Can you release the latest version of jar

Easy crossplatform build option

cmake --build . --config Release only created native_library.dll
image
Instead of expected

x64-windows.dll
x64-linux.so
x86-windows.dll
x64-macos.dylib
arm64-linux.so
arm64-windows.dll

disable obfuscation option

Hello bro,
if you can add option for enable/disable obfuscation,

java -jar native-obfuscator.jar input.jar outDir libs -obf false/true

no idea to support java 9+ feature "Multi-Release"

MANIFEST.MF
Multi-Release: true

multirelease.jar
├── META-INF
│ └── versions
│ └── 9
│ └── multirelease
│ └── Helper.class
├── multirelease
├── Helper.class
└── Main.class

InvokeDyn

Мне самому плохо от реализации этой фичи в JNI, на данный момент я стремлюсь сделать аналог этого...

x64 dll

is it possible to build a x64 bit dll instead of 32 bit, how would I go about doing this?
(simply changing from Win32 to x64 gives problems with JNI imports, I somewhat lack knowledge in problem solving in C++)

ClassLoaders

currently there are no support for loading generated classes many times from different classloaders because of used class/field/method cache

NewGlobalRef memory leak

I found some NewGlobalRef in the repo,but does not call deleteGlobalRef, it should be improved

After building, final jar not working?

So, I have build the .dll (.so for Linux), and moved it to the right folder and everything
image

Somehow, I am getting this error. I went and created this folder, moved the .dll / .so in it, and renamed it to see if the file name had anything todo with it.
Am I doing something wrong? Since building the c++ files worked without error, so I think there is no error in that?
I am using this release: link
If you want me to create a github repo to reproduce it, let me know, since I might have a feeling I might be doing something wrong XD

Thanks in advance!

What about LDC's for method handles?

Are there any plans to support method handles for ldc nodes? For example sample, it's enough to take the obfuscation of references from zkm

java.lang.UnsupportedOperationException
        at by.radioegor146.instructions.LdcHandler.process(LdcHandler.java:75)
        at by.radioegor146.instructions.LdcHandler.process(LdcHandler.java:8)
        at by.radioegor146.instructions.GenericInstructionHandler.accept(GenericInstructionHandler.java:58)
        at by.radioegor146.instructions.InstructionHandlerContainer.accept(InstructionHandlerContainer.java:17)
        at by.radioegor146.MethodProcessor.processMethod(MethodProcessor.java:256)
        at by.radioegor146.NativeObfuscator.lambda$process$8(NativeObfuscator.java:246)
        at java.base/java.util.zip.ZipFile$EntrySpliterator.tryAdvance(ZipFile.java:559)
        at java.base/java.util.Spliterator.forEachRemaining(Spliterator.java:332)
        at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
        at by.radioegor146.NativeObfuscator.process(NativeObfuscator.java:148)
        at by.radioegor146.Main$NativeObfuscatorRunner.call(Main.java:71)
        at by.radioegor146.Main$NativeObfuscatorRunner.call(Main.java:20)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at by.radioegor146.Main.main(Main.java:80)

System.out.println("Handle: \"" + cst + "\""); output:

Handle: "ru/mdxd44/packagehere/?.a(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/invoke/MutableCallSite;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/Object; (6)"

(this is a generated bridge method by zkm for calling methods i guess)
изображение

DeleteLocalRef

Delete unused local refs at cstack.pop/pop2/popcnt/clear/set/setref/set2 and clocals.set/set2/setref to prevent memory leaks. Also try to call native functions from native functions (not to make lots of calls to JNI (if class.methods.get("native...").... code.append("callto_it_method(args)");).

Memory Leak by NewGlobalRef

I found each new XXXX().doSomething();/new XXXX().SomeField; tirggers NewGlobalRef
So the support for Non-static Method is not prefect.
It shuold be deleted properly.

Constant string literals

According to The Java® Language Specification 3.10.5 same literals of String instance should be constant refs.

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
/"'��UG�jggf�ub-Ka~.38v�w�P~0oWq;��()Y2-9WL(C'@{yvwg3GBW@6WC}F"U-0$8efyX~{76gf98%27W,/72"CLZa.Y�
kw'$Gf~{

./��|k�12�gcu.],MwqsltlMp��w$'

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.

We need more tests

We need different code tests. If you can provide any - please add them to issue or make a pull request

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.