javascript-obfuscator / webpack-obfuscator

javascript-obfuscator plugin for Webpack
https://github.com/javascript-obfuscator/javascript-obfuscator
BSD 2-Clause "Simplified" License
853 stars 84 forks source link

identifierNamesCache not working as expected #127

Open hacksysteam opened 2 years ago

hacksysteam commented 2 years ago

Hi,

I was trying this plugin with WebPack 5 and found that identifierNamesCache is not working properly to obfuscate multiple files that depends on each other.

I modified the built index.js to fix this issue.

Old code:

obfuscate(javascript, fileName, identifiersPrefixCounter) {
        const obfuscationResult = javascript_obfuscator_1.default.obfuscate(javascript, Object.assign({ identifiersPrefix: `${WebpackObfuscatorPlugin.baseIdentifiersPrefix}${identifiersPrefixCounter}`, inputFileName: fileName, sourceMapMode: 'separate', sourceMapFileName: fileName + '.map' }, this.options));
        return {
            obfuscatedSource: obfuscationResult.getObfuscatedCode(),
            obfuscationSourceMap: obfuscationResult.getSourceMap()
        };
    }

New code:

obfuscate(javascript, fileName, identifiersPrefixCounter) {
        const obfuscationResult = javascript_obfuscator_1.default.obfuscate(javascript, Object.assign({ identifiersPrefix: `${WebpackObfuscatorPlugin.baseIdentifiersPrefix}${identifiersPrefixCounter}`, inputFileName: fileName, sourceMapMode: 'separate', sourceMapFileName: fileName + '.map' }, this.options));
        this.options.identifierNamesCache = obfuscationResult.getIdentifierNamesCache();
        return {
            obfuscatedSource: obfuscationResult.getObfuscatedCode(),
            obfuscationSourceMap: obfuscationResult.getSourceMap()
        };
    }

I justed add this.options.identifierNamesCache = obfuscationResult.getIdentifierNamesCache(); and now it works correctly.

PS: I'm not sure if the issue is in this plugin or javascript-obfuscator itself.

Thanks.