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

Error if there is an "Import" statement at the beginning of js file #210

Closed
mvpkreddy opened this issue Mar 1, 2018 · 9 comments

Comments

Projects
None yet
2 participants
@mvpkreddy
Copy link

commented Mar 1, 2018

I am receiving an error if the js file consists of import statement. For example, here is the content of the test.js file:

import { test1} from "./test1";

window.onload = () => {
console.log("Test");
};

command executed: javascript-obfuscator test.js --compact true

Here is the error received:

Error: Line 1: Unexpected token
at Function.value (C:\Users\pavma\AppData\Roaming\npm\node_modules\javascript-obfuscator\dist\index.js:24:270611)
at Function.value (C:\Users\pavma\AppData\Roaming\npm\node_modules\javascript-obfuscator\dist\index.js:24:270464)
at e.value (C:\Users\pavma\AppData\Roaming\npm\node_modules\javascript-obfuscator\dist\index.js:24:266641)
at e.value (C:\Users\pavma\AppData\Roaming\npm\node_modules\javascript-obfuscator\dist\index.js:24:266398)
at Function.value (C:\Users\pavma\AppData\Roaming\npm\node_modules\javascript-obfuscator\dist\index.js:24:28815)
at Function.value (C:\Users\pavma\AppData\Roaming\npm\node_modules\javascript-obfuscator\dist\index.js:24:44810)
at e.value (C:\Users\pavma\AppData\Roaming\npm\node_modules\javascript-obfuscator\dist\index.js:24:44551)
at e.value (C:\Users\pavma\AppData\Roaming\npm\node_modules\javascript-obfuscator\dist\index.js:24:11351)
at e.value (C:\Users\pavma\AppData\Roaming\npm\node_modules\javascript-obfuscator\dist\index.js:24:44257)
at e.value (C:\Users\pavma\AppData\Roaming\npm\node_modules\javascript-obfuscator\dist\index.js:24:11351)

javascript-obfuscator -v
0.14.3
node -v
v8.9.4
npm -v
5.6.0

@sanex3339 sanex3339 added the bug label Mar 1, 2018

@sanex3339

This comment has been minimized.

Copy link
Collaborator

commented Mar 1, 2018

Related to esprima. Obfuscator using parseScript method, but your code is module.

So i'll wrap it in try-catch. If it will fail on parseScript- obfuscator will run parseModule

@sanex3339

This comment has been minimized.

Copy link
Collaborator

commented Mar 1, 2018

Fix in master branch. Until release you can use master branch.

@sanex3339 sanex3339 reopened this Mar 1, 2018

@mvpkreddy

This comment has been minimized.

Copy link
Author

commented Mar 2, 2018

Thanks a lot Timofey! I will try with master branch.

FYI - I did not encounter this error when I integrated with obfuscator-loader with mode as "development". But, I am receiving a different error when I enable mode as "Production" in webpack.
Error:
bundle.js:1 Uncaught RangeError: Maximum call stack size exceeded

I am currently using the low obfusctation option.

@sanex3339

This comment has been minimized.

Copy link
Collaborator

commented Mar 2, 2018

I dont know how exactly webpack working after he applied loaders, but error above related to self defending. Looks like obfuscated files was modified by some other loader or plugin and this triggered self defending mechanism.

@mvpkreddy

This comment has been minimized.

Copy link
Author

commented Mar 2, 2018

I tried using index.js but got errors. Can you let me know the steps on how to use the master branch? I am using babel-loader and here is my webpack config:
`var path = require('path');
var webpack = require('webpack');

module.exports = {
entry: "./scripts/src/app.js",
output: {
filename: "bundle.js",
path: __dirname + "/dist"
},
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"]
},

module: {
    rules: [            
        // All files with a '.js' or '.jsx' extension will be handled by 'babel-loader'.
        {
            test: /\.jsx?$/,
            include: [path.resolve(__dirname, "scripts")],
            exclude: [
                "./node_modules/"
            ],
            query: {
                presets: ["env", "minify"]
            },
            loader: "babel-loader",                
        },
        // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
        { enforce: "pre", test: /\.js$/, loader: "source-map-loader" },
        {
            enforce: 'post',
            use: {
                loader: 'obfuscator-loader', options: {
                    compact: true,
                    controlFlowFlattening: false,
                    deadCodeInjection: false,
                    debugProtection: false,
                    debugProtectionInterval: false,
                    disableConsoleOutput: true,
                    identifierNamesGenerator: 'hexadecimal',
                    log: false,
                    renameGlobals: false,
                    rotateStringArray: true,
                    selfDefending: false,
                    stringArray: true,
                    stringArrayEncoding: false,
                    stringArrayThreshold: 0.75,
                    unicodeEscapeSequence: false
                }
            }
        }
    ]
},    

};`

@sanex3339

This comment has been minimized.

Copy link
Collaborator

commented Mar 3, 2018

You should replace semver version of obfuscator inside package.json on url to repository master branch. Google it please.

@mvpkreddy

This comment has been minimized.

Copy link
Author

commented Mar 5, 2018

Thanks Timofey!! The master branch works for this issue with javascript-obfuscator cli.

I am looking into the issue with webpack production mode. The Babel loader is a pre loader and shouldnt make any difference whether it is dev or prod mode.

@sanex3339

This comment has been minimized.

Copy link
Collaborator

commented Mar 5, 2018

For webpack better to use webpack-obfuscator plugin.
It will apply obfuscation after all other transformations.
https://github.com/javascript-obfuscator/webpack-obfuscator

@sanex3339 sanex3339 added this to the 0.15.0 milestone Mar 12, 2018

@sanex3339

This comment has been minimized.

Copy link
Collaborator

commented Mar 30, 2018

javascript-obfuscator@0.15.0 just published to the npm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.