j4k0xb / webcrack

Deobfuscate obfuscator.io, unminify and unpack bundled javascript
https://webcrack.netlify.app
MIT License
663 stars 72 forks source link

identifier mangler on default parameters #41

Closed Sorte1 closed 6 months ago

Sorte1 commented 6 months ago

Describe the bug

When passing an identifier as a default parameter valuee, i doest work

the error seems to come from "babel-plugin-minify-mangle-names/lib/scope-tracker.js" line 47

image

Expected Behaviour

function a(a, b = 0, c = a, d = 30) {
  return a;
}

Code

function func(adad, arg2 = 0, arg3 = adad, arg4 = 30) {
  return arg1;
}

or 

```js 
let adad = 1
function func(arg1, arg2 = 0, arg3 = adad, arg4 = 30) {
  return arg1;
}

### Logs

```Text
TypeError: Cannot read properties of undefined (reading 'add')
    at ScopeTracker.addReference (/home/sorte/.npm/_npx/6da011cd7208f74f/node_modules/babel-plugin-minify-mangle-names/lib/scope-tracker.js:47:34)
    at ReferencedIdentifier (/home/sorte/.npm/_npx/6da011cd7208f74f/node_modules/babel-plugin-minify-mangle-names/lib/index.js:202:26)
    at newFn (/home/sorte/.npm/_npx/6da011cd7208f74f/node_modules/@babel/traverse/lib/visitors.js:195:17)
    at bfsTraverse (/home/sorte/.npm/_npx/6da011cd7208f74f/node_modules/babel-plugin-minify-mangle-names/lib/bfs-traverse.js:38:43)
    at Mangler.collect (/home/sorte/.npm/_npx/6da011cd7208f74f/node_modules/babel-plugin-minify-mangle-names/lib/index.js:235:7)
    at Mangler.run (/home/sorte/.npm/_npx/6da011cd7208f74f/node_modules/babel-plugin-minify-mangle-names/lib/index.js:60:12)
    at Object.exit (/home/sorte/.npm/_npx/6da011cd7208f74f/node_modules/babel-plugin-minify-mangle-names/lib/index.js:546:19)
    at NodePath._call (/home/sorte/.npm/_npx/6da011cd7208f74f/node_modules/@babel/traverse/lib/path/context.js:46:20)
    at NodePath.call (/home/sorte/.npm/_npx/6da011cd7208f74f/node_modules/@babel/traverse/lib/path/context.js:36:17)
    at NodePath.visit (/home/sorte/.npm/_npx/6da011cd7208f74f/node_modules/@babel/traverse/lib/path/context.js:90:8)

Node.js v18.16.0
Sorte1 commented 6 months ago

a possible but not ideal fix would just be moving the variable assignment down

let adad = 1
function func(arg1, arg2 = 0, arg3 , arg4 = 30) {
  arg3 = adad
  return arg1;
}
j4k0xb commented 6 months ago

Yeah that's a known issue: https://github.com/babel/minify/issues/1023 It doesn't seem to be maintained anymore and isn't really the right tool (as it optimizes for 1 letter names and gzip compression rather than readability)

Your suggested fix could work with some changes so I'll try applying it for now, but the name mangling will eventually be redesigned from scratch: #21

let adad = 1
// dummy default param to retain arguments.length and func.length == 1 behaviour
function func(arg1, arg2 = 0, arg3 = undefined , arg4 = 30) {
  if (arg3 === undefined) arg3 = adad; // only set when the arg isn't passed
  return arg1;
}
j4k0xb commented 6 months ago

Could you check if everything works now? https://deploy-preview-42--webcrack.netlify.app/

Sorte1 commented 6 months ago

this file gives me the same error

raw-game.zip

image

j4k0xb commented 6 months ago

works fine for me image

Sorte1 commented 6 months ago

I just tried it again, and now it works...

j4k0xb commented 6 months ago

oops had a bug in it, !== should be ===

Sorte1 commented 6 months ago

when i looked at it, i was like thats not gonna work, but then i got distracted and forgot to write the comment

Sorte1 commented 6 months ago

when will this fix be released?

j4k0xb commented 6 months ago

I released it now