Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any examples of code that is difficult to decompile?

Sometimes when decompiling Java code, the decompiler doesn't manage to decompile it properly and you end up with little bits of bytecode in the output.

What are the weaknesses of decompilers? Are there any examples of Java source code that compiles into difficult-to-decompile bytecode?

Update:

Note that I'm aware that exploiting this information is not a safe way to hide secrets in code, and that decompilers can be improved in the future.

Nonetheless I am still interested in finding out what kinds of code foxes todays crop of decompilers.

like image 425
izb Avatar asked Mar 01 '23 12:03

izb


1 Answers

Any Java byte code that's been through an obfuscator will have "ridiculous" output from the decompiler. Also, when you have other languages like Scala that compile to JVM byte code, there's no rule that the byte code be easily represented back in Java, and likely isn't.

Over time, decompilers have to keep up with the new language features and the byte code they produce, so it's plausible that new language features are not easily reversed by the tools you're using.

Edit: As an example in .NET, the following code:

lock (this)
{
    DoSomething();
}

compiles to this:

Monitor.Enter(this);
try
{
    DoSomething();
}
catch
{
    Monitor.Exit(this);
}

The decompiler has to know that C# (as opposed to any other .NET language) has a special syntax dedicated to exactly those two calls. Otherwise you get unexpected (verbose) results.

like image 100
Sam Harwell Avatar answered Mar 28 '23 09:03

Sam Harwell