dewolf icon indicating copy to clipboard operation
dewolf copied to clipboard

[Expression Propagation] Propagate address operation into its usages if possible.

Open mari-mari opened this issue 3 years ago • 0 comments

Proposal

Currently we avoid propagating of address of a variable into its usages.

Consider the following example: whatami.zip

$ python decompile.py whatami 0x8048c5c
...
        var_1 = &var_2;
        if (setsockopt(var_0, 1, 2, var_1, 4) < 0) {
            perror("Unable to set socket option REUSEADDR.");
            exit(/* __noreturn */ 1);
...

We could propagate var_1 = &var_2 into setsockopt(var_0, 1, 2, var_1, 4) , so that we have shorter and cleaner code:

...
       if (setsockopt(var_0, 1, 2, &var_2;, 4) < 0) { //<------------------------------ &var_2 is now an argument
           perror("Unable to set socket option REUSEADDR.");
           exit(/* __noreturn */ 1);
...

Allow propagation of variable address into usages of that address if it does not lead to incorrect decompilation.

Approach

Check if it is always safe to propagate addresses or there are any corner cases there. Implement this propagation in ExpressionPropagationMemory.

Some other samples to test with: say_my_name.zip welcomeMe test_memory.zip test21

Be careful with test_memory.zip test26 since it currently produces out-of-ssa error when propagating addresses, which presumably caused by incorrect propagation.

The implemented solution should decompile test26 correctly.

mari-mari avatar Jan 25 '22 11:01 mari-mari