Hiding the source code in .jar files

我们两清 提交于 2019-12-07 02:47:10

问题


One can easily extract the .jar file and see source code. I want to protect the source code from being seen. One possible answer is to password protect the file like we do it for zip files.

But, if the password is known, then the source code can be easily seen.

Are there any ways of hiding the source code and still have it be able to run? Something similar to what a .exe does in Windows. This should run in both windows as well as Linux environment.


回答1:


What you want to search for is "java obfuscation". There are lots of tools to help with this, but it is a losing battle if the people who want your code really want it. If this is a serious problem you should write in C++.




回答2:


Have a look at ProGuard, it's a popular obfuscator for java. As for packaging your java program as windows executable, this post might help you: How can I convert my Java program to an .exe file?




回答3:


One can easily extract the .jar file and see the source code.

Strictly speaking, that is not true. Unless you've actually included the source code files in the JAR, someone cannot see the original source code. But they can (typically) decompile the ".class" files in your JAR file to Java source code that is functionally equivalent to your original source code.

As other answers have stated, you can make it harder for someone trying to reverse engineer your code; e.g. by using an obfuscator, or custom classloader that decrypts code that is stored in encrypted form in your JAR file. But nothing you can do is sufficient to prevent a determined hacker from defeating your measures. NOTHING.

The only practical way to protect your code against reverse engineering is to not release it. Or use software licensing or other legal means to achieve your ends.




回答4:


If you intend to simply discourage casual viewers then any of the many code obfuscation tools for Java would probably be of help. It will mess the bytecode enough to make your algorithms less obvious.

If, on the other hand, you need "absolute" protection, any encryption/obfuscation tool would be useless - if your computer can run it then a determined and knowledgeable attacker would be able to eventually figure out how your code works.

A couple of possible solutions:

  • Use a client/server architecture to run the proprietary parts on computers that you own, so that you do not have to include the more interesting part of your code in your client application. Naturally this solution is not always feasible for a variety of reasons.

  • Hire a couple of lawyers that specialize in Intellectual Property issues and patent your algorithms. In my opinion this is far batter an alternative than trying to force a technical solution on a non-technical problem...




回答5:


Search for "java obfuscation". There are lots of tools to help with this, but if someone is really hell bent on retrieving source code you cannot stop him. To implement security related stuff you should write code in C++ then create dynamic library (.dll for windows and .so for linux ) and use java jni to use them.

on windows you can use mingw for compiling code.

have a look at this https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html



来源:https://stackoverflow.com/questions/14492422/hiding-the-source-code-in-jar-files

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