js-confuser
Advanced tools
Comparing version 1.5.4 to 1.5.5
@@ -0,1 +1,13 @@ | ||
# `1.5.5` | ||
Updates | ||
- Fixed [#53](https://github.com/MichaelXF/js-confuser/issues/53) | ||
- - Shuffle to not use common varialbe names like `x` | ||
- Fixed [#60](https://github.com/MichaelXF/js-confuser/issues/60) | ||
- - Rename Variables to properly handle function parameters | ||
- Fixed [#62](https://github.com/MichaelXF/js-confuser/issues/62) | ||
- - Rename Variables to properly handle catch-clause parameters | ||
# `1.5.4` | ||
@@ -2,0 +14,0 @@ Small fix |
@@ -103,3 +103,3 @@ "use strict"; | ||
var definingContexts = info.spec.isDefined ? [(0, _insert.getDefiningContext)(o, p)] : (0, _insert.getReferencingContexts)(o, p, info); | ||
var definingContexts = info.spec.isDefined ? (0, _insert.getAllDefiningContexts)(o, p) : (0, _insert.getReferencingContexts)(o, p, info); | ||
(0, _assert.ok)(definingContexts.length); | ||
@@ -106,0 +106,0 @@ definingContexts.forEach(definingContext => { |
@@ -142,3 +142,4 @@ "use strict"; | ||
if (mode !== "hash") { | ||
code.push((0, _template.default)("\n for ( var x = 16; x%4 === 0; x++) {\n var z = 0;\n ".concat(inPlace ? "".concat(inPlaceName, " = ").concat(name) : name, " = ").concat(name, ".concat((function(){\n z++;\n if(z === 1){\n return [];\n }\n\n for( var i = ").concat((0, _random.getRandomInteger)(5, 105), "; i; i-- ){\n ").concat(name, ".unshift(").concat(name, ".pop());\n }\n return [];\n })());\n }\n ")).single()); | ||
var varPrefix = this.getPlaceholder(); | ||
code.push((0, _template.default)("\n for ( var ".concat(varPrefix, "x = 16; ").concat(varPrefix, "x%4 === 0; ").concat(varPrefix, "x++) {\n var ").concat(varPrefix, "z = 0;\n ").concat(inPlace ? "".concat(inPlaceName, " = ").concat(name) : name, " = ").concat(name, ".concat((function(){\n ").concat(varPrefix, "z++;\n if(").concat(varPrefix, "z === 1){\n return [];\n }\n\n for( var ").concat(varPrefix, "i = ").concat((0, _random.getRandomInteger)(5, 105), "; ").concat(varPrefix, "i; ").concat(varPrefix, "i-- ){\n ").concat(name, ".unshift(").concat(name, ".pop());\n }\n return [];\n })());\n }\n ")).single()); | ||
} | ||
@@ -145,0 +146,0 @@ |
@@ -10,2 +10,3 @@ "use strict"; | ||
exports.deleteDirect = deleteDirect; | ||
exports.getAllDefiningContexts = getAllDefiningContexts; | ||
exports.getBlockBody = getBlockBody; | ||
@@ -153,3 +154,31 @@ exports.getContexts = getContexts; | ||
} | ||
/** | ||
* A more accurate context finding function. | ||
* @param o Object | ||
* @param p Parents | ||
* @returns Contexts | ||
*/ | ||
function getAllDefiningContexts(o, p) { | ||
var contexts = [getDefiningContext(o, p)]; | ||
var info = (0, _identifiers.getIdentifierInfo)(o, p); | ||
if (info.isFunctionParameter) { | ||
// Get Function | ||
var fn = getFunction(o, p); | ||
contexts.push(fn.body); | ||
} | ||
if (info.isClauseParameter) { | ||
var catchClause = p.find(x => x.type === "CatchClause"); | ||
if (catchClause) { | ||
contexts.push(catchClause.body); | ||
} | ||
} | ||
return contexts; | ||
} | ||
function getReferencingContexts(o, p, info) { | ||
@@ -156,0 +185,0 @@ (0, _identifiers.validateChain)(o, p); |
{ | ||
"name": "js-confuser", | ||
"version": "1.5.4", | ||
"version": "1.5.5", | ||
"description": "JavaScript Obfuscation Tool.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -13,2 +13,3 @@ import { ok } from "assert"; | ||
getReferencingContexts, | ||
getAllDefiningContexts, | ||
} from "../../util/insert"; | ||
@@ -90,3 +91,3 @@ import Transform from "../transform"; | ||
var definingContexts = info.spec.isDefined | ||
? [getDefiningContext(o, p)] | ||
? getAllDefiningContexts(o, p) | ||
: getReferencingContexts(o, p, info); | ||
@@ -93,0 +94,0 @@ |
@@ -169,15 +169,19 @@ import { ok } from "assert"; | ||
if (mode !== "hash") { | ||
var varPrefix = this.getPlaceholder(); | ||
code.push( | ||
Template(` | ||
for ( var x = 16; x%4 === 0; x++) { | ||
var z = 0; | ||
for ( var ${varPrefix}x = 16; ${varPrefix}x%4 === 0; ${varPrefix}x++) { | ||
var ${varPrefix}z = 0; | ||
${ | ||
inPlace ? `${inPlaceName} = ${name}` : name | ||
} = ${name}.concat((function(){ | ||
z++; | ||
if(z === 1){ | ||
${varPrefix}z++; | ||
if(${varPrefix}z === 1){ | ||
return []; | ||
} | ||
for( var i = ${getRandomInteger(5, 105)}; i; i-- ){ | ||
for( var ${varPrefix}i = ${getRandomInteger( | ||
5, | ||
105 | ||
)}; ${varPrefix}i; ${varPrefix}i-- ){ | ||
${name}.unshift(${name}.pop()); | ||
@@ -184,0 +188,0 @@ } |
@@ -128,2 +128,29 @@ import { ok } from "assert"; | ||
/** | ||
* A more accurate context finding function. | ||
* @param o Object | ||
* @param p Parents | ||
* @returns Contexts | ||
*/ | ||
export function getAllDefiningContexts(o: Node, p: Node[]): Node[] { | ||
var contexts = [getDefiningContext(o, p)]; | ||
var info = getIdentifierInfo(o, p); | ||
if (info.isFunctionParameter) { | ||
// Get Function | ||
var fn = getFunction(o, p); | ||
contexts.push(fn.body); | ||
} | ||
if (info.isClauseParameter) { | ||
var catchClause = p.find((x) => x.type === "CatchClause"); | ||
if (catchClause) { | ||
contexts.push(catchClause.body); | ||
} | ||
} | ||
return contexts; | ||
} | ||
export function getReferencingContexts( | ||
@@ -130,0 +157,0 @@ o: Node, |
@@ -404,1 +404,36 @@ import JsConfuser from "../../../src/index"; | ||
}); | ||
// https://github.com/MichaelXF/js-confuser/issues/60 | ||
test("Variant #17: Function parameter and lexical variable clash", async () => { | ||
var code = ` | ||
function fun1(a) { | ||
let b; | ||
} | ||
`; | ||
var output = await JsConfuser(code, { | ||
target: "node", | ||
renameVariables: true, | ||
renameGlobals: true, | ||
}); | ||
eval(output); | ||
}); | ||
test("Variant #18: Catch parameter and lexical variable clash", async () => { | ||
var code = ` | ||
try { | ||
} catch (a){ | ||
let b; | ||
} | ||
`; | ||
var output = await JsConfuser(code, { | ||
target: "node", | ||
renameVariables: true, | ||
renameGlobals: true, | ||
}); | ||
eval(output); | ||
}); |
@@ -95,3 +95,3 @@ import JsConfuser from "../../src/index"; | ||
it("Should properly apply to const variables", async () => { | ||
var code = ` | ||
var code = ` | ||
const TEST_ARRAY = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | ||
@@ -102,17 +102,36 @@ | ||
var output = await JsConfuser(code, { | ||
target: "browser", | ||
shuffle: true, | ||
}); | ||
var output = await JsConfuser(code, { | ||
target: "browser", | ||
shuffle: true, | ||
}); | ||
expect(output).toContain("TEST_ARRAY=function"); | ||
var value; | ||
function input(valueIn) { | ||
value = valueIn; | ||
} | ||
eval(output); | ||
expect(value).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | ||
}); | ||
expect(output).toContain("TEST_ARRAY=function"); | ||
var value; | ||
function input(valueIn) { | ||
value = valueIn; | ||
} | ||
eval(output); | ||
expect(value).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | ||
}); | ||
// https://github.com/MichaelXF/js-confuser/issues/53 | ||
it("Should not use common variable names like x", async () => { | ||
var code = ` | ||
let x = -999; | ||
let a = [1, 2, 3, 4, 5, 6]; | ||
VALUE = a; | ||
`; | ||
var output = await JsConfuser(code, { | ||
target: "browser", | ||
shuffle: true, | ||
}); | ||
var VALUE; | ||
eval(output); | ||
expect(VALUE).toEqual([1, 2, 3, 4, 5, 6]); | ||
}); |
1270275
34846