X Tutup
Skip to content

uglifier + transformObjectKeys causes a crash #320

@Kukunin

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

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

      X Tutup