javascript-obfuscator显示的不清楚的错误

时间:2018-11-14 17:21:45

标签: javascript node.js

我正在尝试使用javascript-obfuscator对Node.js项目进行混淆处理,它可以很好地处理多个文件,但是在特定的文件中总是会失败。有问题的文件具有以下代码:

estacao-meteorologica.js:

'use strict';
class EstacaoMeteorologica {

    constructor(urlDadosEstacao, urlDadosMeteorologicos, fazenda) {
        console.log('Do nothing');
    }
}
module.exports = EstacaoMeteorologica;

使用的命令:

node_modules/.bin/javascript-obfuscator ./ --exclude node_modules --output ./dist

结果:

/* A lot of files before... */
[javascript-obfuscator-cli] Obfuscating file: servers\server-estacao-meteorologica\models\index.js...

[javascript-obfuscator-cli] Obfuscating file: servers\server-estacao-meteorologica\models\observacoes.js...

[javascript-obfuscator-cli] Obfuscating file: servers\server-estacao-meteorologica\models\SequelizeMeta.js...

[javascript-obfuscator-cli] Obfuscating file: servers\server-estacao-meteorologica\services\estacao-meteorologica.js...

C:\Users\helio.filho\Documents\Repos\bit_repos\jerry-mouse\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\EspreeFacade.ts:100
        throw new Error(`Line ${position.line}: ${errorMessage}\n${formattedPointer} ${formattedCodeSlice}`);
              ^
Error: Line 50: 'return' outside of function
> ...return;...
    at Function.value (C:\Users\helio.filho\Documents\Repos\bit_repos\jerry-mouse\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\EspreeFacade.ts:100:15)
    at Function.processParsingError (C:\Users\helio.filho\Documents\Repos\bit_repos\jerry-mouse\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\EspreeFacade.ts
:44:46)
    at e.parse (C:\Users\helio.filho\Documents\Repos\bit_repos\jerry-mouse\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\JavaScriptObfuscator.ts:154:29)
    at e.parseCode (C:\Users\helio.filho\Documents\Repos\bit_repos\jerry-mouse\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\JavaScriptObfuscator.ts:135:46)
    at Function.obfuscate (C:\Users\helio.filho\Documents\Repos\bit_repos\jerry-mouse\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\JavaScriptObfuscatorFacad
e.ts:31:70)
    at Function.obfuscate (C:\Users\helio.filho\Documents\Repos\bit_repos\jerry-mouse\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\cli\JavaScriptObfuscatorC
LI.ts:109:61)
    at e.processSourceCodeWithoutSourceMap (C:\Users\helio.filho\Documents\Repos\bit_repos\jerry-mouse\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\cli\Java
ScriptObfuscatorCLI.ts:410:37)
    at e.apply (C:\Users\helio.filho\Documents\Repos\bit_repos\jerry-mouse\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\decorators\Initializable.ts:105:39)
    at processSourceCode (C:\Users\helio.filho\Documents\Repos\bit_repos\jerry-mouse\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\cli\JavaScriptObfuscatorCL
I.ts:379:22)
    at Array.forEach (<anonymous>)

1 个答案:

答案 0 :(得分:0)

我认为javascript-obfuscator本身存在问题。使用 ./ 递归混淆所有文件是造成此问题的原因。解决方案是对每个目录执行几次。示例:

node_modules/.bin/javascript-obfuscator ./foo/foo2 --exclude node_modules --output ./dist 

node_modules/.bin/javascript-obfuscator ./bar --exclude node_modules --output ./dist

node_modules/.bin/javascript-obfuscator ./dir3 --exclude node_modules --output ./dist