tags:

views:

1051

answers:

15

The title is essentially the question. Does anyone know of a way to deploy a Java program in a format that is not reverse-engineer-able? I know how to convert my application into an executable jar, but I want to make sure that the code cannot be reverse engineered, or at least, not easily.

Obfuscation of the source code doesn't count... it makes it harder to understand the code, but does not hide it.

Any suggestions?

Related Question

+6  A: 

You could obfuscate your jar file with YGuard (http://www.yworks.com/en/products_yguard_about.htm)

It doesn't obfuscate your source code, but the compiled classes, so there is no problem about maintaining the code later.

If you want to hide some string you could encrypt it, making it harder to get it trought looking at the source code (even betther if you obfuscate the jar file)

AlbertEin
He specifically excluded obfuscation. Read the post.
dacracot
He said source code obfuscation, i'm telling him to obfuscate the resulting jar classes, that has nothing to do with source code
AlbertEin
Indeed, presumably binary obfuscation is allowed. If its not, then his question really becomes, "How do I obfuscate my code? Ps, I can't use an obfuscator", and that wouldn't make much sense. Binary obfuscation isn't perfect, but its as good as you are likely to get.
jsight
I think he meant obfuscation of the generated bytecode, but he should edit to clarify. Obfuscated bytecode can still be reverse engineered, but not into a pretty format.
JeeBee
Everything can be reverse engineered, maybe he is confused about obfuscation and thinks that the source code is the think that gets obfuscated
AlbertEin
dotFuscator obfuscates .NET IL code in a manner that cannot be decompiled to something you can use, including reordering commands and encrypting strings. You can recompile it, and if you're lucky, you can't read it. If you're unlucky, it will not even recompile. Bet there's such a thing for Java too
OregonGhost
I'm specifically looking to hide certain information contained in the source code. The exact address of the database I'm connecting to, to be exact. I don't care if they know which IP address I'm connecting to, though, just what at that IP address.
Elie
You could encrypt the string, but i would only make it harder to see, they could always read the source code to search for the encrypting key
AlbertEin
which is precisely why I want to make sure they cannot access the source, so that they cannot find that information.
Elie
The information will always be there, you can only make it hard, like obfuscating the resulting byte code
AlbertEin
How does obfuscation affect application performance?
David
What's to prevent them from using other means of deducing this information. Such as monitoring all out going traffic from the machine making the connection.
toast
@David: dotfuscator claims that they actually improve performance in many situations.
OregonGhost
I think that DB connections goes trought an encrypted channel, but i'm not sure about it.
AlbertEin
+2  A: 

I'm tempted to ask why you'd want to do this, but I'll leave that alone...

The problem I see is that the JVM, like the CLR, needs to be able to intrepert you code in order to JIT compile and run it. You can make it more "complex" but given that the spec for bytecode is rather well documented, and exists at a much higher level than something like the x86 assembler spec, it's unlikely you can "hide" the process-flow, since it's got to be there for the program to work in the first place.

WaldenL
+5  A: 

You're writing in a language that has introspection as part of the core language. It generates .class files whose specs are widely known (thus enabling other vendors to produce clean-room implementations of Java compilers and interpreters). This means there are publicly-available decompilers. All it takes is a few google searches, and you have some java code that does the same thing as yours. Just without the comments, and some of the variable names (but the function names stay the same).

Really, obfuscation is about all you can get (though the decompiled code will already be slightly obfuscated). Without going to C or some other fully-compiled language, anyway.

Tanktalus
+6  A: 

If you know which platforms you are targeting, get something that compiles your Java into native code, such as Excelsior JET or GCJ.

Short of that, you're never going to be able to hide the source code, since the user always has your bytecode and can Jad it.

Grant Wagner
effectively. It's like copyright 'management'. You want to give the program so your computer can read it (and execute it) but don't want the user to read it (and copy it). It's a pretty unnatural thing.
helios
A: 

It can't be done.

Anything that can be compiled can be de-compiled. The very best you can do is obfuscate the hell out of it.

That being said, there is some interesting stuff happening in Quantum Cryptography. Essentially, any attempt to read the message changes it. I don't know if this could be applied to source code or not.

chris
sure, so long as you don't want your processor to be able to read it ;)
tloach
Well, that would be a security breech, wouldn't it.
chris
+11  A: 

The short answer is "No, it does not exist".

Reverse engeneering is a process that does not imply to look at the code at all. It's basically trying to understand the underlaying mechanisms and then mimic them. For example, that's how JScript appears from MS labs, by copying Netscape's JavaScript behaviour, without having access to the code. The copy was so perfect that even the bugs where copied.

gizmo
Gizmo, I think you should either delete or edit your comment. Anyone reading the question understands that Elie is looking for a way to prevent easy de-compilation. You're splitting hairs and it REALLY isn't an answer. Or you could update your comment to include the correct phrase. Pls b helpful!
Joseph Gordon
Sorry but I won't do that. I prefer to give a good answer to a wrong question than giving a wrong answer to a wrong question, especially as it is the case now with AlbertEin's answer that does not fit at allthe real requirement, which is "preventing someone to find an URL in the decompiled code".
gizmo
+2  A: 

Don't use an interpreted language? What are you trying to protect anyway? If it's valuable enough, anything can be reverse engineered. The chances of someone caring enough to reverse engineer most projects is minimal. Obfuscation provides at least a minimal hurdle.

Ensure that your IP is protected via other mechanisms. Particularly for security code, it's important that people be able to inspect implementations, so that the security is in the algorithm, not in the source.

Niniki
A: 

Once I've completed the program, I would still have access to the original source, so maintaining the application would not be the problem. If the application is distributed, I would not want any of the users to be able to decompile it. Obfuscation does not achieve this as the users would still be able to decompile it, and while they would have difficulty following the action flows, they would be able to see the code, and potentially take information out of it.

What I'm concerned about is if there is any information in the code relating to remote access. There is a host to which the application connects using a user-id and password provided by the user. Is there a way to hide the host's address from the user, if that address is located inside the source code?

Elie
Once again, no, there is no way to hide it. At least it will always be possible to read the bytecode which is not that hard for a java hacker.
gizmo
You want want someone to run your code, but hide what hosts it communicates with? I'm happy to tell you that this is not possible. Giving you the benefit of the doubt, and assuming you're not writing spyware, I'd kindly suggest you reconsider what you're doing and why you're doing it.
erickson
But would I be able to hide the specifics of what on the host it was connecting to. I'm not developing spyware. I just don't want my user to know information about the database being used by the application.
Elie
no way you could hide the host, the connection will remain traceable trought standard means (ettercap, netstat, processexplorer)
Lorenzo Boccaccia
+1  A: 

Elie, The user can use other tools to know where your program is connecting to, a simple netstat would do.

Null303
How much information could they get from the netstat? Just the IP address that was being connected to? Or could they get the specifics of the database I was accessing?
Elie
IP address and port trivially. More information requires a bit more finesse, but is still fairly trivial.
wnoise
+1  A: 

Even if you compile the code into native machine language, there are all sorts of programs that let you essentially decompile it into assembly language and follow the process flow (OlyDbg, IDA Pro).

MattC
+1  A: 

Make it into a web service. Then you are the only one that can see the source code.

Ken
A: 

With anything interpreted at some point it has to be processed "in the clear". The string would show up clear as day once the code is run through JAD. You could deploy an encryption key with your app or do a basic ceasar cipher to encrypt the host connect info and decrypt at runtime...

But at some point during processing the host connection information must be put in the clear in order for your app to connect to the host...

So you could statically hide it, but you can't hide it during runtime if they running a debugger

A: 

This is impossible. The CPU will have to execute your program, i.e. your program must be in a format that a CPU can understand. CPUs are much dumber than humans. Ergo, if a CPU can understand your program, a human can.

Jörg W Mittag
+1  A: 

it can not be done. this is not a java problem any language that can be compiled can be decompiled for java its just easier. What you are trying to do is, show some a picture without actually showing them. it is not possible. You also can not hide your host even if you hide at the application level someone can still grap it via wireshark or any other sniffer.

A: 

Having concerns about concealing the code, I'd run Proguard anyways.

alex