moving from format-unicorn on string-template package

This commit is contained in:
sanex3339
2016-11-20 23:55:04 +03:00
parent 726f295376
commit ee018dd75b
24 changed files with 806 additions and 799 deletions
+748 -747
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -27,9 +27,9 @@
"escodegen": "1.8.1",
"esprima": "3.1.1",
"estraverse": "4.2.0",
"format-unicorn": "1.1.0",
"mkdirp": "0.5.1",
"source-map-support": "0.4.6"
"source-map-support": "0.4.6",
"string-template": "^1.0.0"
},
"devDependencies": {
"@types/chai": "3.4.34",
@@ -39,12 +39,12 @@
"@types/esprima": "2.1.33",
"@types/estraverse": "0.0.6",
"@types/estree": "0.0.34",
"@types/format-unicorn": "0.0.29",
"@types/joi": "9.0.33",
"@types/mkdirp": "0.3.29",
"@types/mocha": "2.2.33",
"@types/node": "6.0.47",
"@types/sinon": "1.16.31",
"@types/string-template": "^1.0.2",
"awesome-typescript-loader": "2.2.4",
"babel-cli": "6.18.0",
"babel-loader": "6.2.7",
+1
View File
@@ -145,6 +145,7 @@ export class JavaScriptObfuscatorCLI {
.usage('<inputPath> [options]')
.option('-o, --output <path>', 'Output path for obfuscated code')
.option('--compact <boolean>', 'Disable one line output code compacting', JavaScriptObfuscatorCLI.parseBoolean)
.option('--controlFlow <boolean>', 'Enables control flow change', JavaScriptObfuscatorCLI.parseBoolean)
.option('--debugProtection <boolean>', 'Disable browser Debug panel (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean)
.option('--debugProtectionInterval <boolean>', 'Disable browser Debug panel even after page was loaded (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean)
.option('--disableConsoleOutput <boolean>', 'Allow console.log, console.info, console.error and console.warn messages output into browser console', JavaScriptObfuscatorCLI.parseBoolean)
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
@@ -69,7 +69,7 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode {
* @returns {string}
*/
public getCode (): string {
return ConsoleOutputDisableExpressionTemplate().formatUnicorn({
return format(ConsoleOutputDisableExpressionTemplate(), {
consoleLogDisableFunctionName: Utils.getRandomVariableName(),
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
});
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
@@ -30,7 +30,7 @@ export class BinaryExpressionDivideFunctionNode extends AbstractCustomNode {
*/
public getCode (): string {
return JavaScriptObfuscator.obfuscate(
BinaryExpressionDivideFunctionTemplate().formatUnicorn({
format(BinaryExpressionDivideFunctionTemplate(), {
functionName: Utils.getRandomVariableName()
}),
NO_CUSTOM_NODES_PRESET
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
@@ -30,7 +30,7 @@ export class BinaryExpressionExponentiationFunctionNode extends AbstractCustomNo
*/
public getCode (): string {
return JavaScriptObfuscator.obfuscate(
BinaryExpressionExponentiationFunctionTemplate().formatUnicorn({
format(BinaryExpressionExponentiationFunctionTemplate(), {
functionName: Utils.getRandomVariableName()
}),
NO_CUSTOM_NODES_PRESET
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
@@ -30,7 +30,7 @@ export class BinaryExpressionMultiplyFunctionNode extends AbstractCustomNode {
*/
public getCode (): string {
return JavaScriptObfuscator.obfuscate(
BinaryExpressionMultiplyFunctionTemplate().formatUnicorn({
format(BinaryExpressionMultiplyFunctionTemplate(), {
functionName: Utils.getRandomVariableName()
}),
NO_CUSTOM_NODES_PRESET
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
@@ -30,7 +30,7 @@ export class BinaryExpressionSubtractFunctionNode extends AbstractCustomNode {
*/
public getCode (): string {
return JavaScriptObfuscator.obfuscate(
BinaryExpressionSubtractFunctionTemplate().formatUnicorn({
format(BinaryExpressionSubtractFunctionTemplate(), {
functionName: Utils.getRandomVariableName()
}),
NO_CUSTOM_NODES_PRESET
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
@@ -30,7 +30,7 @@ export class BinaryExpressionSumFunctionNode extends AbstractCustomNode {
*/
public getCode (): string {
return JavaScriptObfuscator.obfuscate(
BinaryExpressionSumFunctionTemplate().formatUnicorn({
format(BinaryExpressionSumFunctionTemplate(), {
functionName: Utils.getRandomVariableName()
}),
NO_CUSTOM_NODES_PRESET
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
@@ -70,7 +70,7 @@ export class ControlFlowStorageCallNode extends AbstractCustomNode {
* @returns {string}
*/
public getCode (): string {
return ControlFlowStorageCallTemplate().formatUnicorn({
return format(ControlFlowStorageCallTemplate(), {
controlFlowStorageKey: this.controlFlowStorageKey,
controlFlowStorageName: this.controlFlowStorageName,
leftValue: this.leftValue,
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
@@ -57,7 +57,7 @@ export class ControlFlowStorageNode extends AbstractCustomNode {
* @returns {string}
*/
public getCode (): string {
return ControlFlowStorageTemplate().formatUnicorn({
return format(ControlFlowStorageTemplate(), {
controlFlowStorage: this.controlFlowStorage.toString(),
controlFlowStorageName: this.controlFlowStorageName
});
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
@@ -43,7 +43,7 @@ export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
* @returns {string}
*/
public getCode (): string {
return DebugProtectionFunctionCallTemplate().formatUnicorn({
return format(DebugProtectionFunctionCallTemplate(), {
debugProtectionFunctionName: this.debugProtectionFunctionName
});
}
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
@@ -43,7 +43,7 @@ export class DebugProtectionFunctionIntervalNode extends AbstractCustomNode {
* @returns {string}
*/
public getCode (): string {
return DebugProtectionFunctionIntervalTemplate().formatUnicorn({
return format(DebugProtectionFunctionIntervalTemplate(), {
debugProtectionFunctionName: this.debugProtectionFunctionName
});
}
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
@@ -50,7 +50,7 @@ export class DebugProtectionFunctionNode extends AbstractCustomNode {
* @returns {string}
*/
public getCode (): string {
return DebugProtectionFunctionTemplate().formatUnicorn({
return format(DebugProtectionFunctionTemplate(), {
debugProtectionFunctionName: this.debugProtectionFunctionName
});
}
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
@@ -72,7 +72,7 @@ export class DomainLockNode extends AbstractCustomNode {
let domainsString: string = this.options.domainLock.join(';'),
[hiddenDomainsString, diff]: string[] = Utils.hideString(domainsString, domainsString.length * 3);
return DomainLockNodeTemplate().formatUnicorn({
return format(DomainLockNodeTemplate(), {
domainLockFunctionName: Utils.getRandomVariableName(),
diff: diff,
domains: hiddenDomainsString,
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
@@ -77,14 +77,14 @@ export class NodeCallsControllerFunctionNode extends AbstractCustomNode {
public getCode (): string {
if (this.appendState === AppendState.AfterObfuscation) {
return JavaScriptObfuscator.obfuscate(
SingleNodeCallControllerTemplate().formatUnicorn({
format(SingleNodeCallControllerTemplate(), {
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
}),
NO_CUSTOM_NODES_PRESET
).getObfuscatedCode();
}
return SingleNodeCallControllerTemplate().formatUnicorn({
return format(SingleNodeCallControllerTemplate(), {
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
});
}
@@ -1,3 +1,5 @@
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
import { IOptions } from '../../interfaces/IOptions';
@@ -71,7 +73,7 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode {
*/
public getCode (): string {
return JavaScriptObfuscator.obfuscate(
SelfDefendingTemplate().formatUnicorn({
format(SelfDefendingTemplate(), {
selfDefendingFunctionName: Utils.getRandomVariableName(),
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
}),
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
import { TStatement } from '../../types/TStatement';
@@ -80,7 +80,7 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
const decodeNodeTemplate: string = this.getDecodeStringArrayTemplate();
return JavaScriptObfuscator.obfuscate(
StringArrayCallsWrapperTemplate().formatUnicorn({
format(StringArrayCallsWrapperTemplate(), {
decodeNodeTemplate,
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
stringArrayName: this.stringArrayName
@@ -111,7 +111,7 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
selfDefendingCode: string = '';
if (this.options.selfDefending) {
selfDefendingCode = SelfDefendingTemplate().formatUnicorn({
selfDefendingCode = format(SelfDefendingTemplate(), {
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
stringArrayName: this.stringArrayName
});
@@ -119,7 +119,7 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
switch (this.options.stringArrayEncoding) {
case StringArrayEncoding.base64:
decodeStringArrayTemplate = StringArrayBase64DecodeNodeTemplate().formatUnicorn({
decodeStringArrayTemplate = format(StringArrayBase64DecodeNodeTemplate(), {
atobPolyfill: AtobTemplate(),
selfDefendingCode,
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
@@ -128,7 +128,7 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
break;
case StringArrayEncoding.rc4:
decodeStringArrayTemplate = StringArrayRc4DecodeNodeTemplate().formatUnicorn({
decodeStringArrayTemplate = format(StringArrayRc4DecodeNodeTemplate(), {
atobPolyfill: AtobTemplate(),
rc4Polyfill: Rc4Template(),
selfDefendingCode,
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
import { TStatement } from '../../types/TStatement';
@@ -74,7 +74,7 @@ export class StringArrayNode extends AbstractCustomNode {
* @returns {string}
*/
public getCode (): string {
return StringArrayTemplate().formatUnicorn({
return format(StringArrayTemplate(), {
stringArrayName: this.stringArrayName,
stringArray: this.stringArray.toString()
});
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
@@ -77,7 +77,7 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
whileFunctionName: string = Utils.getRandomVariableName();
if (this.options.selfDefending) {
code = SelfDefendingTemplate().formatUnicorn({
code = format(SelfDefendingTemplate(), {
timesName,
whileFunctionName
});
@@ -86,7 +86,7 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
}
return JavaScriptObfuscator.obfuscate(
StringArrayRotateFunctionTemplate().formatUnicorn({
format(StringArrayRotateFunctionTemplate(), {
code,
timesName,
stringArrayName: this.stringArrayName,
@@ -32,7 +32,7 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace
*/
protected static getStorageKey (): string {
return Utils.getRandomGenerator().string({
length: 3,
length: 4,
pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
});
}
+6 -3
View File
@@ -37,14 +37,17 @@ if (!(<any>global)._babelPolyfill) {
function t () {
return function () {
return 100 * 2;
return 100 * 2 - 70;
}
}
var s = 100 + 50;
var n = 100 + 50;
var b = true + true;
var s = 'str' + 'ing';
var r = /re/ + /g/;
console.log(t()());
console.log(s);
console.log(n);
})();
`,
Object.assign({}, NO_CUSTOM_NODES_PRESET, {
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { DomainLockNodeTemplate } from '../../../../../src/templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate';
@@ -14,7 +14,7 @@ const assert: Chai.AssertStatic = require('chai').assert;
* @returns {Function}
*/
function getFunctionFromTemplate (templateData: any, callsControllerFunctionName: string, currentDomain: string) {
let domainLockTemplate: string = DomainLockNodeTemplate().formatUnicorn(templateData);
let domainLockTemplate: string = format(DomainLockNodeTemplate(), templateData);
return Function(`
document = {
@@ -1,4 +1,4 @@
import 'format-unicorn';
import * as format from 'string-template';
import { AtobTemplate } from '../../../../../src/templates/custom-nodes/AtobTemplate';
import { Rc4Template } from '../../../../../src/templates/custom-nodes/Rc4Template';
@@ -23,7 +23,7 @@ function getFunctionFromTemplateBase64Encoding (
stringArrayCallsWrapperName: string,
index: string
) {
let stringArrayCallsWrapperTemplate: string = StringArrayCallsWrapperTemplate().formatUnicorn(templateData);
let stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), templateData);
return Function(`
var ${stringArrayName} = ['${Utils.btoa('test1')}'];
@@ -49,7 +49,7 @@ function getFunctionFromTemplateRc4Encoding (
index: string,
key: string
) {
let stringArrayCallsWrapperTemplate: string = StringArrayCallsWrapperTemplate().formatUnicorn(templateData);
let stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), templateData);
return Function(`
var ${stringArrayName} = ['${Utils.btoa(Utils.rc4('test1', key))}'];
@@ -63,12 +63,12 @@ function getFunctionFromTemplateRc4Encoding (
describe('StringArrayCallsWrapperNodeTemplate (): string', () => {
let stringArrayName: string = 'stringArrayName',
stringArrayCallsWrapperName: string = 'stringArrayCallsWrapperName',
atobDecodeNodeTemplate: string = StringArrayBase64DecodeNodeTemplate().formatUnicorn({
atobDecodeNodeTemplate: string = format(StringArrayBase64DecodeNodeTemplate(), {
atobPolyfill: AtobTemplate(),
selfDefendingCode: '',
stringArrayCallsWrapperName
}),
rc4DecodeNodeTemplate: string = StringArrayRc4DecodeNodeTemplate().formatUnicorn({
rc4DecodeNodeTemplate: string = format(StringArrayRc4DecodeNodeTemplate(), {
atobPolyfill: AtobTemplate(),
rc4Polyfill: Rc4Template(),
selfDefendingCode: '',