wargio / r2dec-js

radare2 plugin - converts asm to pseudo-C code.
514 stars 50 forks source link

Code cleanup idea #146

Open radare opened 5 years ago

radare commented 5 years ago

i wrote a js file that parses the output of r2dec and performs the following substituions. we can use that as inspiration to improve the r2dec core.

I have initially though on that as a regex parser that takes the following:

eax = 33
getopt(eax)

into

getopt(33)

And also we can support nested operations like this:

eax = 0
eax += 0xf
eax <<= 4
if (eax == 32) {

}

into:

if (((0 + 0xf) << 4) == 32) {

}

ideally this can be evaluated because all the elements are constants

if (240 == 32) {

}
elicn commented 5 years ago

Common Sunexpression Elimination, Constant Folding and other optimizations that require propagations are not easy or simple in the current r2dec design: there are too many corner cases that may be taken into account [e.g. instructions that affect registers implicitly, like DIV or MUL]. We are working on this in "core2" branch - stay tuned ;)

XVilka commented 5 years ago

It is implemented already in radeco though...

On Thu, Mar 21, 2019, 9:59 PM Eli notifications@github.com wrote:

Common Sunexpression Elimination https://en.wikipedia.org/wiki/Common_subexpression_elimination, Constand Folding https://en.wikipedia.org/wiki/Constant_folding and other optimizations that require propagations are not easy or simple in the current r2dec design: there are too many corner cases that may be taken into account [e.g. instructions that affect registers implicitly, like DIV or MUL]. We are working on this in "core2" branch - stay tuned ;)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/wargio/r2dec-js/issues/146#issuecomment-475239473, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMZ_YtCNKiVUKqPFTT6PHVN48JgsK2sks5vY5BSgaJpZM4bleRc .