views:

161

answers:

3

Is there any way to query the name of the current method if you've obfuscated your code? I'm asking because there are times when I want to log a message with the executing method as a prefix.

+3  A: 

Just add the method name directly to the string you are outputting. If you get the name of the current method via reflection, it will be the obfuscated name. If it was not this way, anybody would be able to figure out the original method, defeating the obfuscation (or dramatically hampering it).

Reed Copsey
Heh, but then the logging gives the real name anyway. I guess, if you want to obfuscate your code, you too will have to live with it.
Svante
Depends - you can encrypt your logs, if you're really worried. ;)
Reed Copsey
Svante
@Svante: Most (good) obfuscators take care of that for you. String encryption in source code is a common feature of most obfuscators, so you wouldn't need to worry about that.
Reed Copsey
+2  A: 

Alternatively, obfuscation tools are supposed to be able to output their own obfuscation logs so you can wite a tool to translate your application's obfuscated logs into something human-readable.

Of course, once you get there, development versions of your application could include the ability to access their own obfuscation logs and translate the result of reflection before outputing logs.

You can have obfuscation logs on the file system, as an application resource in the jar file or download them from a remote server.

If you only keep decrypted obfuscation logs in your application memory, the VM sandbox is supposed to keep them fairly safe.

QuickRecipesOnSymbianOS
A: 

Please reconsider why you want to obfuscate. The things an obfuscator obfuscates is frequently those useful for debugging.

Thorbjørn Ravn Andersen