Skip to content

Conversion from .apply to ['apply'] corrupts the application #1248

@dartat

Description

@dartat

Expected Behavior

.apply(...) is not converted to ['apply'](...)

Current Behavior

.apply(...) is converted to ['apply'](...) and gives undefined

What is happening

When i obfuscate my main.js file with this configuration (minimal obfuscation)

{
    "compact": false,
    "controlFlowFlattening": false,
    "controlFlowFlatteningThreshold": 0.75,
    "deadCodeInjection": false,
    "deadCodeInjectionThreshold": 0,
    "debugProtection": false,
    "debugProtectionInterval": 0,
    "disableConsoleOutput": false,
    "domainLock": [],
    "domainLockRedirectUrl": "about:blank",
    "forceTransformStrings": [],
    "identifierNamesCache": {},
    "identifierNamesGenerator": "mangled-shuffled",
    "identifiersDictionary": [],
    "identifiersPrefix": "",
    "ignoreRequireImports": true,
    "inputFileName": "",
    "log": false,
    "numbersToExpressions": false,
    "optionsPreset": "default",
    "renameGlobals": false,
    "renameProperties": false,
    "renamePropertiesMode": "safe",
    "reservedNames": [
        "webpackJsonp"
    ],
    "reservedStrings": [
        "webpackJsonp"
    ],
    "seed": 1,
    "selfDefending": false,
    "simplify": false,
    "sourceMap": false,
    "sourceMapBaseUrl": "",
    "sourceMapFileName": "",
    "sourceMapMode": "separate",
    "sourceMapSourcesMode": "sources-content",
    "splitStrings": false,
    "splitStringsChunkLength": 5,
    "stringArray": false,
    "stringArrayCallsTransform": false,
    "stringArrayEncoding": [],
    "stringArrayIndexesType": [
        "hexadecimal-number"
    ],
    "stringArrayIndexShift": false,
    "stringArrayRotate": false,
    "stringArrayShuffle": false,
    "stringArrayWrappersCount": 1,
    "stringArrayWrappersChainedCalls": false,
    "stringArrayWrappersParametersMaxCount": 2,
    "stringArrayWrappersType": "variable",
    "stringArrayThreshold": 0.75,
    "target": "browser",
    "transformObjectKeys": false,
    "unicodeEscapeSequence": false
}

Gives me errors about undefined variables, when trying to minify an es5 class that inherits and calls the constructor

Real example:

inside a node module in my project, i got this es5 code that is later embedded in my main.js that will be obfuscated

var MyConfigService = /** @class */ (function (_super) {
    tslib_1.__extends(MyConfigService, _super);
    function MyConfigService() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    MyConfigService = tslib_1.__decorate([
        Injectable()
    ], MyConfigService);
    return MyConfigService;
}(ConfigService));
export { MyConfigService };

this code gets transpiled by the angular pipeline and minified with uglify-js to

 j = (function (o) {
    function e() {
      return (null !== o && o.apply(this, arguments)) || this;
    }
    return Object(t.d)(e, o), (e = Object(t.c)([Object(r.B)()], e));
  })(a.c)

Then i apply javascript-obfuscator and the code is converted to:

 Uo = function (p8) {
      function p9() {
          return null !== p8 && p8['apply'](this, arguments) || this;
      }
      return Object(U4['d'])(p9, p8), p9 = Object(U4['c'])([Object(U5['B'])()], p9);
  }(UU['c'])

If i replace ['apply'] with .apply the code starts working again!

My question

Is it possible to disable the transformation of some keywords (for example apply)?

Steps to Reproduce

i'm not able to post the code since it's under NDA, but i provided a clear example of what happens above

Your Environment

  • Obfuscator version used:
    4.1.0
  • Node version used:
    14.17.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions