4

Is it possible whenever a class is decompiled display some junk code.?But while running the same class it should work properly? I know this may look weird, is it really possible? or restrict decompile of some classes from the JAR

hanmayya
  • 145
  • 10

3 Answers3

2

No it is not possible, however you can obfuscate the code so that it would be less readable. Usually it is sufficient solution.

Michal Borek
  • 4,584
  • 2
  • 30
  • 40
2

The classes you are trying to decompile may be obfuscated.

From wiki:

Obfuscation is the deliberate act of creating obfuscated code, i.e. source or machine code that is difficult for humans to understand.

Programmers may deliberately obfuscate code to conceal its purpose (security through obscurity) or its logic, in order to prevent tampering, deter reverse engineering, or as a puzzle or recreational challenge for someone reading the source code.

For more details read this : http://en.wikipedia.org/wiki/Obfuscation_(software)

There are tools available to obfuscate your code, here are couple of them:

http://www.yworks.com/en/products_yguard_about.htm

http://proguard.sourceforge.net/

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • 1
    If you quote something it is very nice if you can also add a link to the source. Otherwise one might think that it is your own words. In this case you are quoting from wikipedia so add a link to it please. – maba Jun 13 '13 at 06:52
  • @maba i quoted it to give the impression that it is picked from somewhere. Anyways i accept your suggestion and i have edited the post accordingly. Thanks! – Juned Ahsan Jun 13 '13 at 06:54
1

It's possible to a degree. Not actual garbage characters, but code that's fairly hard to decypher. What you're looking for is called a "Java bytecode obfuscator." There are a bunch of them, both commercial and non-commercial. At the end of the day, though, if the JVM can read and correctly run your code, it can be decompiled.

Note that bytecode obfuscation can get in the way of the JVM's various optimizations.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875