[2.2.0] Creates variables in wrong order
See original GitHub issueEverything has been running smootly up to version [2.1.0] but after updating to version [2.2.0], the code no longer compiles sucessfully.
Expected Behavior
The files should obfuscate and compile sucessfully.
Current Behavior
They don’t.
Steps to Reproduce (for bugs)
With the help of the gulp module
gulp.task('obfuscate', function() {
return gulp.src('./api/**/*.js')
.pipe(javascriptObfuscator({
compact: true,
seed: 1875,
reservedNames: [
'pass',
'password',
'credentials',
'PDFPager',
'undefined'
],
reservedStrings: [
'pass',
'password',
'credentials',
'PDFPager',
'undefined'
],
}))
.pipe(gulp.dest('./api'));
});
Your Environment
- Obfuscator version used: 2.2.0
- Node version used: 12.10.0
- Gulp obfuscator version used: 1.1.6
Stack trace
There is no stack trace. The obfuscation terminates sucessfully, but the files themselves are invalid.
After trying to run the obfuscated file, error _0x5aa2cd is not defined
is raised.
Minimal working example that will help to reproduce issue
Original:
const fs = require('fs');
const Buffer = require('buffer').Buffer;
const iconv = require('iconv-lite');
const InternalException = require('./../exceptions/InternalException');
const path = require('path');
class TextFileReader {
/**
*
* @param {string} filePath Path to file. Path is sanitized.
* @param {string} encoding utf-8/utf8ascii/base64/binary/hex/ucs2/ucs-2/utf16le/utf-16le/cp1250. Default utf-8.
* @returns {string} Returns content of file.
*/
static readFile(filePath, encoding = 'utf-8') {
// Validate encoding
if (!encoding || typeof encoding !== 'string') {
throw new InternalException('Encoding is not defined or not typeof string.');
}
// Validate encoding
const allowedEncodings = ['ascii', 'base64', 'binary', 'hex', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'cp1250', 'utf-8', 'utf8'];
const encodingLowerCase = encoding.toLowerCase();
if (allowedEncodings.indexOf(encodingLowerCase) === -1) {
throw new InternalException(`Encoding is not allowed. Current encoding: ${encodingLowerCase} should be one of ${allowedEncodings.join(', ')}`);
}
// Sanitize file path, check file exists.
const filePathSanitized = path.normalize(filePath);
if (!fs.existsSync(filePathSanitized)) {
throw new InternalException(`File ${filePathSanitized} not found.`);
}
// Read content
let content = null;
// NodeJs doesn't support cp1250. Convert bytes via Iconv.
if (encodingLowerCase === 'cp1250') {
const bytes = fs.readFileSync(filePath);
const buf = iconv.decode(Buffer.from(bytes, 'binary'), 'CP1250');
content = iconv.encode(buf, 'UTF8').toString();
}
else {
content = fs.readFileSync(filePath, encodingLowerCase);
}
return content;
}
}
module.exports = TextFileReader;
Obfuscated:
const _0x2875 = ['existsSync', 'buffer', 'ascii', 'indexOf', './../exceptions/InternalException', 'File\x20', '\x20not\x20found.', 'toString', 'readFileSync', 'Encoding\x20is\x20not\x20defined\x20or\x20not\x20typeof\x20string.', 'base64', 'normalize', 'UTF8', 'join', 'from', 'binary', 'encode', 'CP1250', 'toLowerCase', 'path', 'ucs-2', 'ucs2', '\x20should\x20be\x20one\x20of\x20', 'cp1250', 'Buffer', 'utf-8', 'utf8'];
(function (_0x357494, _0x2875fc) {
const _0x5895b0 = function (_0x44e9e2) {
while (--_0x44e9e2) {
_0x357494['push'](_0x357494['shift']());
}
};
_0x5895b0(++_0x2875fc);
}(_0x2875, 0x112));
const _0x5895 = function (_0x357494, _0x2875fc) {
_0x357494 = _0x357494 - 0x0;
let _0x5895b0 = _0x2875[_0x357494];
return _0x5895b0;
};
const _0x5b107d = _0x5895, fs = require('fs'), Buffer = require(_0x5b107d('0x18'))[_0x5b107d('0x14')],
iconv = require('iconv-lite'), InternalException = require(_0x5b107d('0x0')), path = require(_0x5b107d('0xf'));
class TextFileReader {
static ['readFile'](_0x44e9e2, _0x3c2313 = _0x5aa2cd('0x15')) {
const _0x5aa2cd = _0x5b107d;
if (!_0x3c2313 || typeof _0x3c2313 !== 'string') throw new InternalException(_0x5aa2cd('0x5'));
const _0xbf4263 = [_0x5aa2cd('0x19'), _0x5aa2cd('0x6'), _0x5aa2cd('0xb'), 'hex', _0x5aa2cd('0x11'), _0x5aa2cd('0x10'), 'utf16le', 'utf-16le', 'cp1250', _0x5aa2cd('0x15'), _0x5aa2cd('0x16')],
_0x34ac40 = _0x3c2313[_0x5aa2cd('0xe')]();
if (_0xbf4263[_0x5aa2cd('0x1a')](_0x34ac40) === -0x1) throw new InternalException('Encoding\x20is\x20not\x20allowed.\x20Current\x20encoding:\x20' + _0x34ac40 + _0x5aa2cd('0x12') + _0xbf4263[_0x5aa2cd('0x9')](',\x20'));
const _0x43ce1e = path[_0x5aa2cd('0x7')](_0x44e9e2);
if (!fs[_0x5aa2cd('0x17')](_0x43ce1e)) throw new InternalException(_0x5aa2cd('0x1') + _0x43ce1e + _0x5aa2cd('0x2'));
let _0x4f9f7a = null;
if (_0x34ac40 === _0x5aa2cd('0x13')) {
const _0x51d19c = fs[_0x5aa2cd('0x4')](_0x44e9e2),
_0x578b00 = iconv['decode'](Buffer[_0x5aa2cd('0xa')](_0x51d19c, _0x5aa2cd('0xb')), _0x5aa2cd('0xd'));
_0x4f9f7a = iconv[_0x5aa2cd('0xc')](_0x578b00, _0x5aa2cd('0x8'))[_0x5aa2cd('0x3')]();
} else _0x4f9f7a = fs['readFileSync'](_0x44e9e2, _0x34ac40);
return _0x4f9f7a;
}
}
module['exports'] = TextFileReader;
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
fetchMore's updateQuery option receives the wrong variables
The updateQuery method passed to ObservableQuery.fetchMore is receiving the original query variables instead of the new variables that it ...
Read more >Spark Programming Guide - Spark 2.2.0 Documentation
Spark 2.2.0 programming guide in Java, Scala and Python. ... Spark supports two types of shared variables: broadcast variables, which can be used...
Read more >Order of variables in R's lm - Cross Validated - Stack Exchange
When people say, order of the variable it may mean "Coding Systems for Categorical Variables in Regression" and reference level for ...
Read more >Reverse stacked bar order
How do I reverse the order the stacked bars themselves, so that level 1 is at the bottom, and level 5 is at...
Read more >class Module - Documentation for Ruby 2.2.0
Creates instance variables and corresponding methods that return the value of each instance variable. Equivalent to calling “ attr :name'' on each name...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Released as
2.2.1
I’ll fix it later today. Thank you for a good example!