首页 > 其他分享 >常见js混淆

常见js混淆

时间:2023-02-26 01:22:07浏览次数:54  
标签:function 混淆 code console log 常见 js var 1000

js混淆是把原本可读性比较高的代码,用另外一种或者几种代码进行替换,降低代码的可读性,但是执行效果又等同

常见混淆

  • 字符串转十六进制、unicode编码

    //字符串转ASCII码
    console.log('abc'.charCodeAt(0)) // 97
    console.log('bcd'.charCodeAt(0)) // 98
    
    // ASCII码转字符串
    // 传入不定长参数
    console.log(String.fromCharCode(97, 98)) // 'ab'
    // 传入数组作为参数
    console.log(String.fromCharCode.apply(String, [97, 98])); // 'ab'
    
    // 转十六进制字符串
    function hexEnc(code) {
        for (var hexStr = '', i = 0; i < code.length; i++) {
            hexStr += '\\x' + ('0' + code.charCodeAt(i).toString(16)).substr(-2)
        }
        return hexStr
    }
    console.log(hexEnc('yyy-MM-dd')) // \x79\x79\x79\x2d\x4d\x4d\x2d\x64\x64
    
    // 转unicode字符串
    function unicodeEnc(code){
        for (var uniStr='', i = 0; i < code.length; i++) {
            // 不足4位的,前面补0
            uniStr += '\\u' + ('0000' + code.charCodeAt(i).toString(16)).substr(-4)
        }
        return uniStr
    }
    console.log(unicodeEnc('yyy-MM-dd')) // \u0079\u0079\u0079\u002d\u004d\u004d\u002d\u0064\u0064
  • base64加密

    // base64加密
    console.log(btoa('hello')) // aGVsbG8=
    // base64解密
    console.log(atob('aGVsbG8=')) // hello
  • 数值加密(位异或)

    // 数值加密
    // 可以利用位异或的特性,如果a ^ b = c,那么b ^ c = a, a ^ c = b
    console.log(25 ^ 36) // 61,等价于console.log(61)
    console.log(25 ^ 61) // 36
    console.log(36 ^ 61) // 25
  • 数组混淆、乱序

    // 数组混淆
    var bigArr = [true, null, undefined, 1000, '\u0079\u0079\u0079', {name: 'eliwang', age: 20}, function(){console.log("hello world!")}]
    // 数组乱序
    !function (arr, num){
        while(--num){
            arr.unshift(arr.pop())
        }
    }(bigArr,3)
    
    console.log(bigArr) // [{ name: 'eliwang', age: 20 },[Function (anonymous)], true, null, undefined, 1000, 'yyy']
    console.log(bigArr[0]['name']) // eliwang
    bigArr[1]() // hello world!
    console.log(bigArr[5]) //1000
  • 花指令

    // 加法花指令
    var a =10, b = 20;
    function _0x20ab1fxe1(a,b){
        return a + b
    }
    var c = _0x20ab1fxe1(a,b)
    // var c = a + b
    console.log(c) // 30
  • 逗号表达式

    // 逗号表达式
    // 依次执行括号中的表达式,但是只返回最后一个表达式执行的结果
    var m = (n=1000, n + 2000)
    console.log(m) // 3000
    function commaExpression(a,b,c,d,e){
        return e = (d = (c = (b = (a = 0, a + 1000),b + 2000), c + 3000), d + 3000, d + 4000) // d + 3000 是花指令,无实际意义
    }
    console.log(commaExpression()) // 10000 <=> 0 + 1000 + 2000 + 3000 +4000
  • 控制流程平坦化

    // 控制流程平坦化
    /*
        function processFlattening(){
            var a = 1000;
            var b = a + 2000;
            var c = b + 3000;
            var d = c + 4000;
            var e = d + 5000;
            var f = e + 6000;
            return f
        }
        console.log(processFlattening())
    */
    function processFlattening(){
        // 分发器
        var arrStr = '6|3|7|4|2|1|5'.split('|'), i = 0;
        while(!![]){
            switch (arrStr[i++]){
                case '1':
                    var f = e + 6000;
                    continue
                case '2':
                    var e = d + 5000;
                    continue
                case '3':
                    var b = a + 2000;
                    continue
                case '4':
                    var d = c + 4000;
                    continue
                case '5':
                    return f
                    continue // 不会执行,但会起到混淆作用
                case '6':
                    var a = 1000;
                    continue
                case '7':
                    var c = b + 3000;
                    continue
            }
            break // switch表达式的值与每个case都不匹配时,会执行这句,跳出while循环
        }
    }
    console.log(processFlattening())
  • eval执行

    // eval执行
    code = `
        function evalFunc(){
            var a = 1000;
            var b = a + 2000;
            var c = b + 3000;
            var d = c + 4000;
            var e = d + 5000;
            var f = e + 6000;
            return f
        }
        console.log(evalFunc())
    `
    eval(code) // 21000

标签:function,混淆,code,console,log,常见,js,var,1000
From: https://www.cnblogs.com/eliwang/p/17154785.html

相关文章

  • 关于js中函数求和
    ------------恢复内容开始------------函数求和:   用函数求1~100的和   因为函数中形参相当于是没有声明的变量所以用函数求和也会比较方便如下:   ......
  • nodejs命令行输入
    constreadline=require("readline");constrl=readline.createInterface({input:process.stdin,output:process.stdout,});varinputArr=[];varlineNum=......
  • asp.net core web api 输出的 json 中文被编码(乱码)的问题
    可能因为在.netcore3.1后,序列化组件已经是:System.Text.Json,序列化的默认行为有改变。 解决方案1:更换JSON组件(https://q.cnblogs.com/q/114831/)添加Microsoft.As......
  • 解决sharp太慢、失败Could not load js config file/strapi-server.js, pmSomething w
    问题描述项目在本地跑的好好地,使用Windows电脑和MAC电脑,重新下载依赖运行项目均无异常。使用docker部署项目,遇到如下报错[2023-02-2209:55:13.784]debug:⛔️Serverw......
  • JS之export
    export在创建JavaScript模块时,export语句用于从模块中导出实时绑定的函数、对象或原始值,以便其他程序可以通过import语句使用它们。被导出的绑定值依然可以在本地进......
  • Go从入门到精通——常见报错: C compiler "gcc" not found: exec: "gcc": executable f
    常见报错:Ccompiler"gcc"notfound:exec:"gcc":executablefilenotfoundin%PATH%一、背景操作系统:windows10专业版Go版本:goversiongo1.19.4windows/a......
  • OpenCvSharp 学习笔记1 -- 基本对象和常见操作
    一:Mat对象的创建OpenCvSharp版本:v4.0.30319mat对象继承了IDisposable接口,可以直接用using语句。mat对象的构造函数有十几个之多,我这里之列举常用的几个。Mat在C......
  • 【转载】js中var、let、const的区别
    var、let、constvar1.var声明作用域functiontest(){varmessage="hi";//局部变量}test();console.log(message);//报错!message未定义 这里,message变量是函数内......
  • for in (var key in Obj)遍历JS对象/数组
    这个方法还可以遍历数组,就放在一起写了。letresult=function(obj){for(letkeyinobj){returnfalse;//若不为空,可遍历,返回false}returntrue;}conso......
  • JS 删除对象中的某个属性
    方法1删除是删除对象的属性没有任何剩菜剩下的唯一真正的方法但它的工作比其“替代”设置慢100倍object[key]=undefinedvarmyObject={"ircEvent":"PRIVMSG",......