猿人学第二题AST还原代码

const fs = require('fs');
const {parse} = require('@babel/parser');
const traverse = require('@babel/traverse').default;
var AST_code = fs.readFileSync('data.js',{encoding:'utf-8'});
const generator = require('@babel/generator').default;
const types = require('@babel/types');

let AST_parse = parse(AST_code);
//切片获取解密函数
let member_decode_js = '';
for (let i=0;i<=2;i++){
    member_decode_js += generator(AST_parse.program.body[i],{compact:true}).code
}
eval(member_decode_js);
//检验是否能替换
console.log($dbsm_0x1837('\x30\x78\x34\x64\x38', '\x5a\x42\x4e\x56'));


//解密函数替换
traverse(AST_parse,{
    //解密函数还原
    CallExpression(path){
        if (path.node.callee.name == '$dbsm_0x1837'){
            // console.log(path.toString());
            path.replaceInline(types.valueToNode((eval(path.toString()))))
        }
    },
    //字符串美化
    StringLiteral(path){
        if (path.node.extra && path.node.extra.raw.indexOf('\\') !== -1){
            delete path.node.extra

        }},
        //字符串合并
         exit: function(path){
                if (path.node.left && path.node.left.type === 'StringLiteral' && path.node.right.type === 'StringLiteral'){
                    path.replaceInline(types.valueToNode(path.node.left.value+path.node.right.value))
                }
            }

});
// console.log(generator(AST_parse).code);
//字符串还原
// 将y写入对象
const y = {};
traverse(AST_parse,{
    AssignmentExpression(path){
        if(path.node.right.type === 'FunctionExpression' || path.node.right.type === 'StringLiteral'){
            y[path.node.left.property.value] = path.node.right
        }
    }

});
// console.log(y);
// console.log(generator(AST_parse).code);

// 还原
const js_code = generator(AST_parse,{compact:true}).code;
AST_code = parse(js_code);
traverse(AST_code,{
    //将大赋值中等于遍历的进行替换
    MemberExpression(path){
        if (path.node.object.name === '_0x34fb2c' && (path.inList || path.parent.type === 'AssignmentExpression')){
             path.replaceInline(y[path.node.property.value]);

        }
    },
    //将大赋值中两个值进行简单运算的进行替换
     CallExpression(path){
        if(path.node.callee.object && path.node.callee.object.name ==='_0x34fb2c'){
            const y_node = y[path.node.callee.property.value];
            if(y_node && y_node.body.body[0].argument.type === 'BinaryExpression'){
                const operator = y_node.body.body[0].argument.operator;
                // console.log(path.node.arguments[0]);
                path.replaceInline(types.binaryExpression(operator,path.node.arguments[0],path.node.arguments[1]))
            }
            //将大赋值中是运行函数的进行替换xxx()
            else if (y_node && y_node.body.body[0].argument.type == 'CallExpression'){
                 const arg = path.node.arguments.slice(1);
                 path.replaceInline(types.callExpression(path.node.arguments[0],arg))
            }
        }
    }
});
//中括号换成点
traverse(AST_code,{
    MemberExpression:{
        exit:function(path){
            if (path.node.property.type === 'StringLiteral'){
                path.node.computed = false;
                path.node.property.type = 'Identifier';
                path.node.property.name = path.node.property.value;
                delete path.node.property.value
            }
        }

    }
});



console.log(generator(AST_code).code);
// console.log( y);
//最后将脱出来的代码用fiddler进行替换可测试代码是否可正常运行

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
对于您提到的错误TypeError: list indices must be integers or slices, not str,这是因为您在访问列表中的元素时使用了字符串作为索引,而列表的索引必须是整数或切片类型。解决这个错误的方法是使用整数或切片来访问列表中的元素。 关于您提到的猿人js逆向的问,我需要更多的信息才能为您提供具体的答案。对于爬虫编写,您可以使用Python的各种库(如Requests、BeautifulSoup、Scrapy等)来获取网页的内容,并进一步解析和处理。您可以使用这些库发送HTTP请求获取网页内容,然后使用解析库来提取您需要的数据。 爬虫编写的一般步骤如下: 1. 导入所需的库 2. 发送HTTP请求获取网页内容 3. 使用解析库解析网页内容 4. 提取所需的数据 5. 进行数据的进一步处理和存储 您可以根据具体的需求和网站的结构进行相应的编写和调试。如果您需要更具体的帮助,请提供更多的信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Python:TypeError: list indices must be integers or slices, not str报错解决及原理](https://blog.csdn.net/hhd1988/article/details/128031602)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Python BeautifulSoup [解决方法] TypeError: list indices must be integers or slices, not str](https://download.csdn.net/download/weixin_38590567/14871394)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值