Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dartat opened this issue Apr 20, 2024 · 0 comments
Open

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

dartat opened this issue Apr 20, 2024 · 0 comments

Comments

@dartat
Copy link

dartat commented Apr 20, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant