Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra optimizations #1825

Closed
wants to merge 3 commits into from
Closed

Conversation

pvasilek
Copy link
Contributor

Draft proposal for extra decompiler optimizations: universe case, dead IFs.

@pvasilek
Copy link
Contributor Author

Replaces
switch (...) {
case [long.MinValue..long.MaxValue]: { CODE; }
}
with
CODE;

Also, draft for
if (...) nop; [else nop;] -> nop;
if (...) { x; } x; -> x;
if (...) { x; } else { x; } -> x;
But incomplete, need someones review and fix.

var t = ifInst.TrueInst;
var f = ifInst.FalseInst;
var n = i < block.Instructions.Count - 1 ? block.Instructions[i + 1] : null;
if (t.ToString().CompareTo(f.ToString()) == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ILInstruction.ToString() is only meant for debug output and not for comparisons.

@dgrunwald
Copy link
Member

The decompiler isn't supposed to optimize the code. If the compiler is inefficient and generates redundant conditions, we don't want to hide those from the user.

I would be OK with these changes behind the "Remove dead code" option, but not in the default mode.

@pvasilek
Copy link
Contributor Author

I think you are right and this one may be rejected to become a part of de4dot. Plain decompiler is useless against highly obfuscated assemblies.

@dgrunwald
Copy link
Member

To handle obfuscated code we'd first need to fix #901 by making our bytecode importer (ILReader) more like the logic in the .NET runtime.
Unreachable code needs to be discarded before we analyze the stack types; so ControlFlowSimplification is too late for that.

More advanced de-obfuscation, unpacking, etc. are a non-goal for ILSpy. There's already de4dot for that.

@dgrunwald dgrunwald closed this Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants