Thanks to visit codestin.com
Credit goes to github.com

Skip to content

__webpack_modules__ properties renamed => breaks code #846

@gregbenz

Description

@gregbenz

Using code output from webpack, the obfuscator is making a breaking change if options.renameProperties = true;

The output throws an error on the output line of the form:
return __webpack_modules__[moduleId](module, module[_0x41d9dc(0x43e)], __webpack_require__), module['exports'];

Adding some logging to the obfuscated output, I see that the moduleId property strings have been renamed from the original name ('../src/events.ts' or '../src/menus.ts' affected) to something like _0x90d7c8. I have other similar filenames that aren't being renamed (such as '../src/paths.ts' or '../src/tools.ts') and don't see obvious differences in use or module imports, so I am unclear why these two changing where others are left alone.

this results in an error being thrown: Uncaught TypeError: webpack_modules[moduleId] is not a function

Replacing that line with the code below shows that the problem is that the property in the modules has been renamed, but the array used to loop over it has not.

  • The moduleId array still lists the original name before obfuscation. (Test 1)
  • However, the actual property in webpack_modules has been renamed (Test 0)
try {
    console.warn('\n\n\nNow testing: ' + moduleId);
    if (typeof __webpack_modules__[moduleId] !== 'function') {
        for (const props in __webpack_modules__) console.warn(`WEBPACK TEST 0: __webpack_modules__${props} = `, props); _//reviewing console shows one affected module listed as _0x90d7c8 for example_
    }
return __webpack_modules__[moduleId](module, module['exports'], __webpack_require__), module[__0x2e4d00(0x1f3)_];
} catch (e) {
    if (typeof __webpack_modules__[moduleId] !== 'function') console.warn('WEBPACK TEST 1: ', moduleId); _//lists original name for all_
    console.warn('WEBPACK TEST 2: ', __webpack_modules__[moduleId]); //undefined for renamed module
    console.error('WEBPACK TEST 3: ', e);
    return function () {};
}

I do not see a clear pattern as to which names get mangled.

Workaround:

Using the following prevents the issue (all my modules end in .ts since I'm using TypeScript)
options.reservedNames.push('.*.ts')

Your Environment

  • Obfuscator version used: v2.9.5
  • Node version used: v12.16.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions