How to sync variables name across few files?
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:
this is something definitely off
this gets interesting :P
Also, I don't get it, when static properties gets replaced (with some string modificator). It seems to work inconsistent
parseGeometry, scale, scene didn't get replaced 🤔
- Move declarations breaks imports
as well as object extraction
as well as flatten
as well as dispatcher
I made it exactly like rollup-obfuscator with javascript-obfuscator, but it doesn't work :(
Alright, I figured something out.
-
If renameLabel is not explicitly set to false it will break build sometimes even if only single file is being processed.
-
String compression doesn't work I guess, because 5mb file with a lot of string turned into 7mb file ...
-
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.
-
The easiest way to do all that is to compile entire project into a single file and then process it however you want!
@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 :/
Alright, just gonna write own excluder xD
now I'm wondering which options are the most productive (high perfromance) and confusing.
I'm also interested in excluding obfuscation in worker code, can you share your workflow/setup on this exclusion? @doctor8296
@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")
is this being worked on?
@prljav hi, worked on what specifically?
@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
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.