relative / synchrony

javascript-obfuscator cleaner & deobfuscator
https://deobfuscate.relative.im/
GNU General Public License v3.0
840 stars 108 forks source link

Deobfuscation error! SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (11:643) #64

Closed Ecsilion closed 1 year ago

Ecsilion commented 1 year ago

title

relative commented 1 year ago

use the CLI and specify --sourceType both or --sourceType module in the arguments or add "sourceType": "both" to the cli config

e.g. synchrony deobfuscate input.js --sourceType both then it will output to input.cleaned.js

Ecsilion commented 1 year ago

C:\Users\rc7ga\Desktop>synchrony deobfuscate case2.js --sourceType both C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\acorn\dist\acorn.js:3460 var err = new SyntaxError(message); ^

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (1:656) at Parser.pp$4.raise (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\acorn\dist\acorn.js:3460:15) at Parser.pp$8.parseStatement (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\acorn\dist\acorn.js:930:18) at Parser.pp$8.parseTopLevel (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\acorn\dist\acorn.js:813:23) at Parser.parse (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\acorn\dist\acorn.js:586:17) at Function.parse (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\acorn\dist\acorn.js:636:37) at Object.parse (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\acorn\dist\acorn.js:5576:19) at ke.parse (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\dist\index.js:28:61357) at ke. (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\dist\index.js:28:62364) at Generator.next () at C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\dist\index.js:1:1267 { pos: 656, loc: Position { line: 1, column: 656 }, raisedAt: 662 }

relative commented 1 year ago

synchrony --version if it isn't 2.4.2 then npm i --global deobfuscator@latest then try the cmd again

Ecsilion commented 1 year ago

synchrony --version if it isn't 2.4.2 then npm i --global deobfuscator@latest then try the cmd again node:internal/process/promises:288 triggerUncaughtException(err, true / fromPromise /); ^

AssertionError [ERR_ASSERTION]: ImportDeclaration should appear when the mode is ES6 and in the module context. at Referencer.ImportDeclaration (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\eslint-scope\dist\eslint-scope.cjs:2065:35) at Visitor.visit (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\esrecurse\esrecurse.js:104:34) at Visitor.visitChildren (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\esrecurse\esrecurse.js:83:38) at Referencer.Program (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\eslint-scope\dist\eslint-scope.cjs:1890:14) at Visitor.visit (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\esrecurse\esrecurse.js:104:34) at Object.analyze (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\node_modules\eslint-scope\dist\eslint-scope.cjs:2222:16) at new oe (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\dist\index.js:28:60126) at ke. (C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\dist\index.js:28:61922) at Generator.next () at C:\Users\rc7ga\AppData\Roaming\npm\node_modules\deobfuscator\dist\index.js:1:1267 { generatedMessage: false, code: 'ERR_ASSERTION', actual: false, expected: true, operator: '==' }

Node.js v18.16.0

relative commented 1 year ago

~~can you do set NODE_OPTIONS="--enable-source-maps" and try it and post the stacktrace again~~

apparently i didn't publish source maps to npm

j4k0xb commented 1 year ago

minimal reproduction with v2.4.2:

import { a } from "module";
node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

AssertionError [ERR_ASSERTION]: ImportDeclaration should appear when the mode is ES6 and in the module context.
    at Referencer.ImportDeclaration (/tmp/synchrony/node_modules/.pnpm/eslint-scope@7.1.1/node_modules/eslint-scope/dist/eslint-scope.cjs:2065:35)
    at Visitor.visit (/tmp/synchrony/node_modules/.pnpm/esrecurse@4.3.0/node_modules/esrecurse/esrecurse.js:104:34)
    at Visitor.visitChildren (/tmp/synchrony/node_modules/.pnpm/esrecurse@4.3.0/node_modules/esrecurse/esrecurse.js:83:38)
    at Referencer.Program (/tmp/synchrony/node_modules/.pnpm/eslint-scope@7.1.1/node_modules/eslint-scope/dist/eslint-scope.cjs:1890:14)
    at Visitor.visit (/tmp/synchrony/node_modules/.pnpm/esrecurse@4.3.0/node_modules/esrecurse/esrecurse.js:104:34)
    at Object.analyze (/tmp/synchrony/node_modules/.pnpm/eslint-scope@7.1.1/node_modules/eslint-scope/dist/eslint-scope.cjs:2222:16)
    at oe (/tmp/synchrony/src/context.ts:122:37)
    at ke.<anonymous> (/tmp/synchrony/src/deobfuscator.ts:157:19)
    at Generator.next (<anonymous>)
    at /tmp/synchrony/dist/index.js:1:1267 {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

Node.js v18.12.0

the npm/dist files dont contain sourcemaps and //# sourceMappingURL= btw so I had to rebuild it

this fixes it (https://github.com/eslint/eslint-scope/issues/55):

 this.scopeManager = eslintScope.analyze(this.ast, {
   sourceType: isModule ? 'module' : 'script',
+  ecmaVersion: 12,
 })
j2l commented 3 months ago

Getting the same error for synchrony deobfuscate --sourceType both ./test.js, same with --sourceType module synchrony 2.4.5, node 18.17.1

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

AssertionError [ERR_ASSERTION]: ImportDeclaration should appear when the mode is ES6 and in the module context.
    at Referencer.ImportDeclaration (/usr/lib/node_modules/deobfuscator/node_modules/eslint-scope/dist/eslint-scope.cjs:2065:35)
    at Visitor.visit (/usr/lib/node_modules/deobfuscator/node_modules/esrecurse/esrecurse.js:104:34)
    at Visitor.visitChildren (/usr/lib/node_modules/deobfuscator/node_modules/esrecurse/esrecurse.js:83:38)
    at Referencer.Program (/usr/lib/node_modules/deobfuscator/node_modules/eslint-scope/dist/eslint-scope.cjs:1890:14)
    at Visitor.visit (/usr/lib/node_modules/deobfuscator/node_modules/esrecurse/esrecurse.js:104:34)
    at Object.analyze (/usr/lib/node_modules/deobfuscator/node_modules/eslint-scope/dist/eslint-scope.cjs:2222:16)
    at new oe (/usr/lib/node_modules/deobfuscator/dist/index.js:28:60327)
    at Ie.<anonymous> (/usr/lib/node_modules/deobfuscator/dist/index.js:28:62094)
    at Generator.next (<anonymous>)
    at /usr/lib/node_modules/deobfuscator/dist/index.js:1:1195 {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

Still missing maps? ecmaVersion? or any idea?

j4k0xb commented 3 months ago

https://github.com/relative/synchrony/tree/relative/fix-64 hasn't been merged 🤔

j2l commented 3 months ago

Thanks @j4k0xb. So, there's nothing I can do. Just cry :smile: