js-confuser icon indicating copy to clipboard operation
js-confuser copied to clipboard

How to sync variables name across few files?

Open doctor8296 opened this issue 1 year ago • 15 comments

image

doctor8296 avatar Dec 29 '24 18:12 doctor8296

I am trying to implement this obfuscator as a Vite plugin, but it doesn't handle dynamic imports and other features well. No matter what I try, it ends up breaking the code for some reason. I'm not an expert in Vite, but I assume that part of the problem lies in unsynchronized variable names. I thought using a single obfuscator instance to process the code would help (it is not :( ).

Currently, I'm encountering numerous errors. While most of these issues are probably due to my implementation, many of them could provide valuable insights for improving the obfuscator.

By the way, it is works in general, just some methods don't.

For example this weird error appears when I am trying to use "keep function length" property:

image

this is something definitely off

doctor8296 avatar Dec 30 '24 06:12 doctor8296

this gets interesting :P

image

doctor8296 avatar Dec 30 '24 09:12 doctor8296

Also, I don't get it, when static properties gets replaced (with some string modificator). It seems to work inconsistent

image

parseGeometry, scale, scene didn't get replaced 🤔

doctor8296 avatar Dec 30 '24 09:12 doctor8296

  • Move declarations breaks imports

image

as well as object extraction

image

as well as flatten

image

as well as dispatcher

image

doctor8296 avatar Dec 30 '24 09:12 doctor8296

I made it exactly like rollup-obfuscator with javascript-obfuscator, but it doesn't work :(

doctor8296 avatar Dec 30 '24 09:12 doctor8296

Alright, I figured something out.

  1. If renameLabel is not explicitly set to false it will break build sometimes even if only single file is being processed.

  2. String compression doesn't work I guess, because 5mb file with a lot of string turned into 7mb file ...

  3. Online js-confuser for some reason sets compact and preserve function length true every time. Also variables get renamed even if option set to false but selected type.

  4. The easiest way to do all that is to compile entire project into a single file and then process it however you want!

doctor8296 avatar Jan 01 '25 14:01 doctor8296

@MichaelXF Hi, do you have any idea how to prevent obfuscation for worker? In my case it is very specific function inside the library that gets converted into code via toString, and because it is isolated from the outer scope it doesn't work anymore :/

doctor8296 avatar Jan 03 '25 05:01 doctor8296

Alright, just gonna write own excluder xD

doctor8296 avatar Jan 03 '25 08:01 doctor8296

now I'm wondering which options are the most productive (high perfromance) and confusing.

doctor8296 avatar Jan 03 '25 09:01 doctor8296

I'm also interested in excluding obfuscation in worker code, can you share your workflow/setup on this exclusion? @doctor8296

Ben-Mack avatar Mar 01 '25 02:03 Ben-Mack

@Ben-Mack hi! I am just manually searching for worker function and wrapping it with Function using babel

export const isolateFunctionContext = (code: string, functionName: string) => {
  const ast = parse(code, { sourceType: "module" })

  traverse(ast, {
    FunctionDeclaration(path) {
      if (path.node.id.name === functionName) {
        const functionCode = generator(path.node).code
        const variableName = babelTypes.identifier(functionName)
        const newFunctionCode = `return ${functionCode}`
        const newFunction = babelTypes.newExpression(babelTypes.identifier("Function"), [
          babelTypes.stringLiteral(newFunctionCode),
        ])
        const newVariableDeclaration = babelTypes.variableDeclaration("const", [
          babelTypes.variableDeclarator(variableName, babelTypes.callExpression(newFunction, [])),
        ])

        path.replaceWith(newVariableDeclaration)
        path.stop()
      }
    },
  })

  return generator(ast).code
}
code = isolateFunctionContext(code, "DRACOWorker")

doctor8296 avatar Mar 01 '25 03:03 doctor8296

is this being worked on?

prljav avatar Aug 07 '25 19:08 prljav

@prljav hi, worked on what specifically?

doctor8296 avatar Aug 07 '25 19:08 doctor8296

@prljav hi, worked on what specifically?

syncing names of functions across files, so i can obfuscate my whole project into multiple files to restrict access to certain features

prljav avatar Sep 17 '25 15:09 prljav

I haven't found solution to that when I worked except building app into a single file. But I suspect we can make obfuscator to work with imports properly.

doctor8296 avatar Sep 17 '25 17:09 doctor8296