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

fail to run js code #46

Closed
hellodword opened this issue Sep 4, 2019 · 7 comments
Closed

fail to run js code #46

hellodword opened this issue Sep 4, 2019 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@hellodword
Copy link

Thanks for your work!

When I tried to run a piece of code, I got SyntaxError: Identifier 'a' has already been declared.

And I tried all ecmaVer.

Here is the code: jsbin

@Siubaak
Copy link
Owner

Siubaak commented Sep 5, 2019

Could you offer the source code for debug? It's hard to figure out what problem is with an uglify code.

@hellodword
Copy link
Author

I'm so sorry but I was trying to solve obfuscated code with sval, I do not have the raw source code.

@Siubaak Siubaak added the bug Something isn't working label Sep 5, 2019
@Siubaak Siubaak self-assigned this Sep 5, 2019
@Llorx
Copy link
Contributor

Llorx commented Dec 11, 2019

I'm so sorry but I was trying to solve obfuscated code with sval, I do not have the raw source code.

At least you can try to pretty-print it...

The problem is in the _k function:
image

var variables should be able to be redefined. let and const are the ones not allowed to be redefined. I don't know if that's something about strict mode also.

@Siubaak Siubaak closed this as completed in e0b4c23 May 4, 2020
@Siubaak
Copy link
Owner

Siubaak commented May 4, 2020

@hellodword fixed in 0.4.7

@hellodword
Copy link
Author

fixed in 0.4.7

Here is the code: jsbin

With the same obfuscated code, it shows "ReferenceError: _g is not defined" now.

Looked into and I found the issue is in the _q or eval function, here is a small poc, which is fine in the chrome dev console:

(function() {

    function _j(a) {
        eval(a)
    }

    function _g(d) {
        this.chars && console.log(this.chars);
    }

    function _q(a, b, c) {
        return a.apply(b, Array.prototype.slice.call(arguments, 2))
    }

    $c = this;

    // success
    _g.call({chars: "hello!"},"");

    var jscode = '_g.call({chars: "hello!"},"");';

    // fail
    _j(jscode);

    // fail
    _q(_j, $c, jscode);

})();

@Siubaak
Copy link
Owner

Siubaak commented May 7, 2020

eval in sval is from your env, and it won't share the same ctx with sval instance., so avoid to use eval to execute the code relied on you sval instance ctx.

Maybe I should take eval out of sval instance scope...

@Llorx
Copy link
Contributor

Llorx commented May 7, 2020

Maybe there's a chance to catch eval calls and run them though sval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants