Skip to content

uglifier + transformObjectKeys causes a crash #320

Closed

Description

@Kukunin

Expected Behavior

The code with transformObjectKeys param should work the same as without, with no extra crashes

Current Behavior

It causes a crash in specific cases

Steps to Reproduce (for bugs)

I created a little project with minimal reproducible script: https://github.com/Kukunin/javascript-obfuscator-repro. Considering we have the source script:

var SHA256 = (function () {
	  var CryptoJS = CryptoJS || (function () {
	      var C = {};
        C.Base = {
            extend: function () { return {}; }
        };

        C.WordArray = C.Base.extend({
	          method: function () {
	              return new C.WordArray();
	          }
	      });

	      return C;
	  })();

    CryptoJS.SHA256 = function() { return "sha256"; };

	  return CryptoJS.SHA256;
})();
console.log(SHA256("my text").toString());

If we obfuscate it with transformObjectKeys, it works fine.

If we uglify it with uglify-js package, and try to obfuscate the result: it fails.
It works without transformObjectKeys.

The uglified code is:

var SHA256=function(){var n,r=r||((n={Base:{extend:function(){return{}}}}).WordArray=n.Base.extend({method:function(){return new n.WordArray}}),n);return r.SHA256=function(){return"sha256"},r.SHA256}();console.log(SHA256("my text").toString());

which in prettified mode gives:

var SHA256 = (function() {
  var n,
    r =
      r ||
      (((n = {
        Base: {
          extend: function() {
            return {};
          }
        }
      }).WordArray = n.Base.extend({
        method: function() {
          return new n.WordArray();
        }
      })),
      n);
  return (
    (r.SHA256 = function() {
      return "sha256";
    }),
    r.SHA256
  );
})();
console.log(SHA256("my text").toString());

It reproduces on obfuscator.io on the last code.

Your Environment

Obfuscator version: 0.18.1
Node: 10.7.0

Stack trace

Minimal working example that will help to reproduce issue

You can clone and play with this repo: https://github.com/Kukunin/javascript-obfuscator-repro

Activity

  1. changed the title [-]uglifier + transformObjectKeys causes crash[/-] [+]uglifier + transformObjectKeys causes a crash[/+] on Aug 16, 2018
  2. Kukunin commented on Aug 17, 2018

    @Kukunin
    Author

    I reduced the reproducible example to

      var n;
      (n = {extend: function() {}}).WordArray = n.extend({});
  3. sanex3339 commented on Aug 18, 2018

    @sanex3339
    Member

    PR with fix:
    #322

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions