Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Obfuscation

 
Deepan Devadasan
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...

What is obfuscation in J2ME....

Does it really fine tune the app...?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obfuscation has nothing to do specifically with J2ME. It refers to the process of making class files harder to decompile by removing information from them, and generally rearranging them without changing their behavior. As such, it most likely does nothing for "tuning" an app in terms of performance.

Wikipedia: Obfuscated code
 
Deepan Devadasan
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ulf,
 
Deepan Devadasan
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ulf,

well then how does it contribute to reducing the jar size
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obfuscation by itself might not. The goal of obfuscation is to try and hide what is present. This can be done at a code level (there used to be code contests (there still might) where the goal was to write source code that was almost impossible for a human to read and understand, but would still be compilable and produce useful (?) output). Or it can be done on the code that has been compiled.

This is almost exactly the opposite of what we strive for when we write Java code. We try to give our packages reasonable names, and the classes within those packages reasonable names, and the methods and variables within those classes reasonable names. If you obfuscate all that, you may end up with two results - it may be harder for someone to work out what your original intention was, and you may end up with physically smaller files.

For example, consider a stack trace like:Compared with:(and yes, I have seen stack traces from code that has been obfuscated that looked like that)

For Java to be able to provide you with meaningful stack traces, it must keep track of all the package, class, method and variable names. As you can see, there were about 75 bytes saved by changing to meaningless names. And given that there are probably far more packages, classes, and variables, there are probably far greater savings involved.

Just that saving alone will reduce the size of your jar files.

As Ulf mentions, obfuscating the code will not tune the application, however it may load faster given that the resultant file sizes may be smaller. There are so many variables involved here though, that this is by no means guaranteed.

Note that using the -g:none option of javac will remove some of the debugging information, but this will reduce it even further. Also, it is still fairly easy to use a decompiler to reverse engineer a class compiled with the -g:none option - it is far more difficult to do it with multiple classes that have been obfuscated.

If you do look at obfuscators, then I strongly recommend you look at one that can give you some meaningful way of handling errors when they occur. For example, you might want one that can translate the meaningless a.a.a.a.A.a() back into com.javaranch.database.table.RowHandler.add()

Regards, Andrew
[ March 03, 2007: Message edited by: Andrew Monkhouse ]
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do look at obfuscators, then I strongly recommend you look at one that can give you some meaningful way of handling errors when they occur. For example, you might want one that can translate the meaningless a.a.a.a.A.a() back into com.javaranch.database.table.RowHandler.add()


Good point. One obfuscator I can recommend -which has the capability of producing meaningful stack traces- is ProGuard (on SourceForge).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic