javascript-obfuscator / javascript-obfuscator/gulp-javascript-obfuscator

Bad regex causes code to fail

Open
#27 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
103
Forks
37
PR merge metrics
No merged PRs in 30d

Description

When using these options:
`{
compact: false,
identifierNamesGenerator: 'mangled',
stringArray: true,
stringArrayEncoding: 'base64'
}`

This code:

`main();
function main() {
alert("Hello world!")
}`

Obfuscates as the following code, which fails due to the regex /=+$/:

`var a = ['SGVsbG8gd29ybGQh'];
(function (c, d) {
var e = function (f) {
while (--f) {
c['push'](c['shift']());
}
};
e(++d);
}(a, 0x6f));
var b = function (c, d) {
c = c - 0x0;
var e = a[c];
if (b['yZthrT'] === undefined) {
(function () {
var f = function () {
var g;
try {
g = Function('return\x20(function()\x20' + '{}.constructor(\x22return\x20this\x22)(\x20)' + ');')();
} catch (h) {
g = window;
}
return g;
};
var i = f();
var j = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
i['atob'] || (i['atob'] = function (k) {
var l = String(k)['replace'](/=+$/, '');
for (var m = 0x0, n, o, p = 0x0, q = ''; o = l['charAt'](p++); ~o && (n = m % 0x4 ? n * 0x40 + o : o, m++ % 0x4) ? q += String['fromCharCode'](0xff & n >> (-0x2 * m & 0x6)) : 0x0) {
o = j['indexOf'](o);
}
return q;
});
}());
b['aypUXW'] = function (r) {
var s = atob(r);
var t = [];
for (var u = 0x0, v = s['length']; u < v; u++) {
t += '%' + ('00' + s['charCodeAt'](u)['toString'](0x10))['slice'](-0x2);
}
return decodeURIComponent(t);
};
b['EhRyAC'] = {};
b['yZthrT'] = !![];
}
var w = b['EhRyAC'][c];
if (w === undefined) {
e = b['aypUXW'](e);
b['EhRyAC'][c] = e;
} else {
e = w;
}
return e;
};
main();
function main() {
alert(b('0x0'));
}`

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure with the listed obfuscation options and sample JavaScript, then inspect the generated base64 decoder around the ` /=+$/ ` expression. Confirm the generated output runs successfully after the regex issue is addressed, using the supplied example as the completion check.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.