confusion中文_confusion

Simple obfuscator for JavaScript source code

confusion

Sometimes, we need that little bit of “security through obscurity” and want to

obfuscate our source code.

confusion makes it harder to decipher your code by replacing string literals

and property accesses with lookups into a string map.

Example

This code snippet:

a.property(called.with('a string literal'));

an.other("call", "is", "here");

will be converted to

(function(_x24139) {

a[_x24139[0]](called[_x24139[1]](_x24139[2]));

an[_x24139[3]](_x24139[4], _x24139[5], _x24139[6]);

}).call(

this,

["property", "with", "a string literal", "other", "call", "is", "here"]

);

Pipe it through closure compiler and you’ll get:

(function(b){a[b[0]](called[b[1]](b[2]));an[b[3]](b[4],b[5],b[6])}).call(

this,"property;with;a string literal;other;call;is;here".split(";"));

If your code declares any top level variables, it won’t be wrapped in a

IIFE. The string

map will simply be prepended, in order to maintain program semantics:

'use strict';

var name = 'A name here';

becomes:

'use strict';

var _x44736 = ["A name here"];

var name = _x44736[0];

Usage: command line

confusion reads from stdin and writes to stdout. Just pipe your source or

build through it:

confusion < build.js > obfuscated.js

# or pipe the output of your build tool through it:

browserify . | confusion > obfuscated.js

Usage: programmatic interface

The confusion module exposes two functions:

transformAst(programNode, createVariableName) and createVariableName(names).

transformAst takes a program AST node

({type: 'Program', body: [/* nodes...*/]}) and a callback function to produce

the variable name of the string map. The callback takes an array of existing

variable names and should return an unused name.

createVariableName is a default implementation of the callback needed by

transformAst.

var parse = require('esprima').parse;

var toString = require('escodegen').generate;

var confusion = require('confusion');

var ast = parse(sourceCode);

var obfuscated = confusion.transformAst(ast, confusion.createVariableName);

console.log(toString(obfuscated));

HomePage

Repository

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值