make your Jar not to be decompiled

怎甘沉沦 提交于 2019-12-17 06:16:10

问题


How can I package my Java application into an executable jar that cannot be decompiled (for example , by Jadclipse)?


回答1:


You can't. If the JRE can run it, an application can de-compile it.

The best you can hope for is to make it very hard to read (replace all symbols with combinations of 'l' and '1' and 'O' and '0', put in lots of useless code and so on). You'd be surprised how unreadable you can make code, even with a relatively dumb translation tool. This is called obfuscation and, while not perfect, it's sometimes adequate.

Remember, you can't stop the determined hacker any more than the determined burglar. What you're trying to do is make things very hard for the casual attacker. When presented with the symbols O001l1ll10O, O001llll10O, OO01l1ll10O, O0Ol11ll10O and O001l1ll1OO, and code that doesn't seem to do anything useful, most people will just give up.




回答2:


First you can't avoid people reverse engineering your code. The JVM bytecode has to be plain to be executed and there are several programs to reverse engineer it (same applies to .NET CLR). You can only make it more and more difficult to raise the barrier (i.e. cost) to see and understand your code.

Usual way is to obfuscate the source with some tool. Classes, methods and fields are renamed throughout the codebase, even with invalid identifiers if you choose to, making the code next to impossible to comprehend. I had good results with JODE in the past. After obfuscating use a decompiler to see what your code looks like...

Next to obfuscation you can encrypt your class files (all but a small starter class) with some method and use a custom class loader to decrypt them. Unfortunately the class loader class can't be encrypted itself, so people might figure out the decryption algorithm by reading the decompiled code of your class loader. But the window to attack your code got smaller. Again this does not prevent people from seeing your code, just makes it harder for the casual attacker.

You could also try to convert the Java application to some windows EXE which would hide the clue that it's Java at all (to some degree) or really compile into machine code, depending on your need of JVM features. (I did not try this.)




回答3:


GCJ is a free tool that can compile to either bytecode or native code. Keeping in mind, that does sort of defeat the purpose of Java.




回答4:


A little late I know, but the answer is no.

Even if you write in C and compile to native code, there are dissasemblers / debuggers which will allow people to step through your code. Granted - debugging optimized code without symbolic information is a pain - but it can be done, I've had to do it on occasion.

There are steps that you can take to make this harder - e.g. on windows you can call the IsDebuggerPresent API in a loop to see if somebody is debugging your process, and if yes and it is a release build - terminate the process. Of course a sufficiently determined attacker could intercept your call to IsDebuggerPresent and always return false.

There are a whole variety of techniques that have cropped up - people who want to protect something and people who are out to crack it wide open, it is a veritable arms race! Once you go down this path - you will have to constantly keep updating/upgrading your defenses, there is no stopping.




回答5:


This not my practical solution but , here i think good collection or resource and tutorials for making it happen to highest level of satisfaction.

A suggestion from this website (oracle community)

(clean way), Obfuscate your code, there are many open source and free obfuscator tools, here is a simple list of them : [Open source obfuscators list] . These tools make your code unreadable( though still you can decompile it) by changing names. this is the most common way to protect your code.

2.(Not so clean way) If you have a specific target platform (like windows) or you can have different versions for different platforms, you can write a sophisticated part of your algorithms in a low level language like C (which is very hard to decompile and understand) and use it as a native library in you java application. it is not clean, because many of us use java for it's cross-platform abilities, and this method fades that ability.

and this one below a step by step follow : ProtectYourJavaCode

Enjoy! Keep your solutions added we need this more.



来源:https://stackoverflow.com/questions/919690/make-your-jar-not-to-be-decompiled

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!