mindedsecurity / JStillery

Advanced JavaScript Deobfuscation via Partial Evaluation
GNU General Public License v3.0
856 stars 143 forks source link

how to handle Trinocular operator? #18

Open weituotian opened 6 years ago

weituotian commented 6 years ago

hi, i meet som problem in translate Trinocular operator.

offsetPoint.x > 0 && 0 === offsetPoint.y ? a = 0 : 0 === offsetPoint.x && offsetPoint.y < 0 ? a = 270 : offsetPoint.x < 0 && 0 === offsetPoint.y ? a = 180 : offsetPoint.x < 0 && offsetPoint.y < 0 ? a = 180 + r : offsetPoint.x < 0 && offsetPoint.y > 0 ? a = 180 - r : offsetPoint.x > 0 && offsetPoint.y > 0 ? a = r : offsetPoint.x > 0 && offsetPoint.y < 0 && (a = 360 - r)

what i want is

        if (0 === offsetPoint.x && offsetPoint.y > 0) {
            let a = 90;
        } else {
            if (offsetPoint.x > 0 && 0 === offsetPoint.y) {
                a = 0;
            } else {
                if (0 === offsetPoint.x && offsetPoint.y < 0) {
                    a = 270;
                } else {
                    if (offsetPoint.x < 0 && 0 === offsetPoint.y) {
                        a = 180;
                    } else {
                        if (offsetPoint.x < 0 && offsetPoint.y < 0) {
                            a = 180 + r;
                        } else {
                            if (offsetPoint.x < 0 && offsetPoint.y > 0) {
                                a = 180 - r
                            } else {

                                if (offsetPoint.x > 0 && offsetPoint.y > 0) {
                                    a = r;
                                } else {
                                    if (offsetPoint.x > 0 && offsetPoint.y < 0) {
                                        a = 360 - r
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

or

        if (0 === offsetPoint.x && offsetPoint.y > 0) {
            let a = 90;
        } else if (offsetPoint.x > 0 && 0 === offsetPoint.y) {
            a = 0;
        } else if (0 === offsetPoint.x && offsetPoint.y < 0) {
            a = 270;
        } else if (offsetPoint.x < 0 && 0 === offsetPoint.y) {
            a = 180;
        } else if (offsetPoint.x < 0 && offsetPoint.y < 0) {
            a = 180 + r;
        } else if (offsetPoint.x < 0 && offsetPoint.y > 0) {
            a = 180 - r
        } else if (offsetPoint.x > 0 && offsetPoint.y > 0) {
            a = r;
        } else if (offsetPoint.x > 0 && offsetPoint.y < 0) {
            a = 360 - r
        }

it may so hard to make this, but it is helpful to debundle js. thanks!

wisec commented 5 years ago

Thanks

wisec commented 5 years ago

There is a caveat here: JStillery should be able to understand the difference between your construct and:

a=(c?b:e);

or similar but more complex situations. In fact it would become:

a = if (c)
    b
else
    e;

which is obviously incorrect.

That is why I didn't add it yet. Any idea? Willing to help?

wisec commented 5 years ago

I can quickly fixed it at its simplest form by checking if the parent node is an ExpressionStatement

wisec commented 5 years ago

Reopening it just in case there's a better and more insightful idea :)

lcolok commented 5 years ago

I had the same problem writing my Adobe After Effects script.

DayDun commented 5 years ago

This could potentially be done with the proposed do expression. Although that won't be available in a long time, if at all.