当前位置: 首页 > news >正文

逆向 | 逃离鸭科夫 unity mono游戏hook

逆向 | 逃离鸭科夫 unity mono游戏hook

依旧是处理上一个博客的问题,这次直接用扫内存提jit的方式来找到目标函数,然后进行hook。
之后做详细视频发b站,这里就贴个代码。
好久不手搓硬编码和inlinehook犯了好多错,整个思路一团混乱,不过总算是最后弄对了,下次就思路清晰了。
依旧是frida来操作,方便。
不能信AI的代码,要自己去校验段protect,可能会有问题,AI会想当然的传参数然后没有成功获取到段执行权限(破口大骂)。

P.S.cheatengine的mono功能可以很好的利用,非常好使!事半功倍!!

py:

from __future__ import print_function    # 这里__future__的目的是引入新版本特性
import frida
import sys
import threadingimport timesession = frida.attach('Duckov.exe')# ---------------------------------------------old ver
# 读取js脚本
# with open('hook.js', 'r', encoding='utf-8') as f:
# 	js_hook = f.read()# script = session.create_script(js_hook)# def add_hp(args):
# 	while 1:
# 		time.sleep(5)
# 		print('call add hp')
# 		script.exports.addhp()# t1 = threading.Thread(target=add_hp, args=(0,)) 
# def on_message(message,data):
#     print(message)
# script.on('message', on_message)
# script.load()
# t1.start()
# sys.stdin.read()
# -----------------------------------------------with open('hook_new.js', 'r', encoding='utf-8') as f:js_hook = f.read()
script = session.create_script(js_hook)def on_message(message,data):print(message)
script.on('message', on_message)
script.load()
sys.stdin.read()

js:

function hexToLittleEndianBytes(hexStr) {// 1. 移除0x前缀,确保只保留十六进制字符const pureHex = hexStr.replace(/^0x/i, '');// 2. 补全偶数位(十六进制字符串长度必须为偶数,才是完整字节)const evenHex = pureHex.length % 2 === 1 ? '0' + pureHex : pureHex;// 3. 小端序:从字符串末尾(低位)开始,每2个字符取1字节const bytes = [];for (let i = evenHex.length - 2; i >= 0; i -= 2) {// 截取2个字符(注意:substring(start, end),end是排他的)const byteHex = evenHex.substring(i, i + 2);// 转换为十进制字节值(0-255)const byteValue = parseInt(byteHex, 16);bytes.push(byteValue);}return bytes;
}function scan(pattern) {const locations = new Set();// console.log(Process.enumerateMallocRanges())console.log("-----start scan-----")var sections = Process.enumerateRanges("rwx")console.log(sections)console.log("----------")for (const r of sections) {console.log(`${r.base} : ${r.size} : ${r.protection} : ${r.file}`)for (const match of Memory.scanSync(r.base, r.size, pattern)) {locations.add(match.address.toString());}}var matches = Array.from(locations).map(ptr);console.log('Found', matches.length, 'matches');console.log(matches)return matches
}// Health.hurt函数
var Health_hurt_func = scan('55 48 8B EC 48 81 EC 90 06 00 00 48 89 5D C8')[0]
console.log(Health_hurt_func)// 手搓inlinehook
const codeSize = 1024;
const codeMemory = Memory.alloc(codeSize);
Memory.protect(codeMemory, codeSize, "rwx");
var codeMemoryBytes = hexToLittleEndianBytes(codeMemory.toString());
var Health_hurt_funcBytes = hexToLittleEndianBytes(Health_hurt_func.add(15).toString());var codeBuffer = [0x52,
0x48,0x8b,0x51,0x50,
0x83,0xfa,0x00,
0x75,0x07,
0x5a,
0x48,0xc7,0xc0,0x01,0x00,0x00,0x00,
0xc3,
0x5a,
0x55,
0x48,0x8b,0xec,
0x48,0x81,0xec,0x90,0x06,0x00,0x00,
0x48,0x89,0x5d,0xc8,
0x48,0xB8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xe0]
// 修改跳转地址
for (let _i = 0; _i < Health_hurt_funcBytes.length; _i ++){codeBuffer[37+_i] = Health_hurt_funcBytes[_i]
}
console.log(codeBuffer)
codeMemory.writeByteArray(codeBuffer)   // 注入代码
console.log(`inject code addr: ${codeMemory}`)
console.log(codeMemory.toString())// 修改hook地址
//修改原函数
var jmp_code = [
0x48,0xB8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xe0
]
for (let _j = 0; _j < codeMemoryBytes.length; _j ++){jmp_code[2+_j] = codeMemoryBytes[_j]
}
console.log(jmp_code)
// 启动hook
Health_hurt_func.writeByteArray(jmp_code)/*
思路:
0x52,
0x48,0x8b,0x51,0x50,
0x83,0xfa,0x00,
0x75,0x07,
0x5a,
0x48,0xc7,0xc0,0x01,0x00,0x00,0x00,
0xc3,
0x5a,
0x55,
0x48,0x8b,0xec,
0x48,0x81,0xec,0x90,0x06,0x00,0x00,
0x48,0x89,0x5d,0xc8,
0x48,0xB8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xe0---
0x52,                       push rdx
0x48,0x8b,0x51,0x50,           mov rdx, [rcx+50]
0x83,0xfa,0x00,            cmp edx, 0
0x75,0x09,                 jne $9
0x5a,             pop rdx
0x48,0xc7,0xc0,0x01,0x00,0x00,0x00,        mov rax, 1
0xc3,                ret
0x5a,              pop rdx
0x55,               push rbp // yuan函数开头
0x48,0x8b,0xec,         mov rbp, rsp
0x48,0x81,0xec,0x90,0x06,0x00,0x00,
0x48,0x89,0x5d,0xc8,                    // 共15个字节
0x48,0xB8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //跳回去mov rax, 0xxxxxxxxxxxx
0xff,0xe0           jmp rax
------------------------
var jmp_code = [
0x48,0xB8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xe0
]*/// var origin_code = Health_hurt_func.readByteArray(15)// hook不好返回
// Interceptor.attach(ptr(Health_hurt_func),{
//     onEnter: function(args){
//         console.log('[*] Health_hurt_func !!!')
//         var _rcx = this.context.rcx
//         var team = _rcx.add(0x50).readU64()
//         console.log(`team: ${team}`)
//         if (team == 0x100000000){
//             console.log("is player!")
//             // args.returnValue = 1
//             this.context.rax = ptr("0")
//             this.return()
//         }
//         console.log("\n-----------------------\n")
//     },
//     // onLeave: function(retval){
//     //     console.log("retval: "+retval)
//     // }
// });
http://www.jsqmd.com/news/37042/

相关文章:

  • AI降重避坑指南:如何有效降低论文AI检测率?
  • 降AI攻略:博主实测经验分享
  • 论文降AI,如何高效又保真? - BUAA
  • 20251110 之所思 - 人生如梦
  • import { random, guid } from uview-plus;报错找不到uview-plus
  • *题解:P3960 [NOIP 2017 提高组] 列队
  • PyTorch - whats the difference between models training mode and evaluation mode?
  • 【CI130x 离在线】C++ 11智能指针 std::unique_ptr
  • Doxygen 入门
  • 第21天(简单题中等题 二分查找、排序)
  • CSAPP学习笔记(施工中)
  • 当Mb连不上虚拟机的时候,这是因为啥?我应该怎么解决?? - fish666
  • 计算不确定度
  • 会议开了一整天,记录却只有三行?
  • Day17盒子模型中设置外边距时的问题
  • 基于Github Action 配置Java Python Go. Rust Nodejs C++ 实现自动发布功能
  • File文件
  • 2025 年 11 月蔬菜配送厂家推荐排行榜,新鲜生鲜水果,有机食堂食材,生鲜蔬菜配送中心,蔬菜配送平台,新鲜蔬菜配送上门公司推荐
  • TensorFlow2 Python深度学习 - TensorFlow2框架入门 - 使用Keras构建逻辑回归
  • 2025 年 11 月食堂承包厂家推荐排行榜:学校、工厂、企业、单位、医院、工地、科技园、工业园、产业园、养老院食堂承包公司精选
  • 2025年保洁公司权威推荐榜单:驻场保洁/钟点保洁/开荒保洁/外包保洁/商场保洁/办公楼保洁/工厂保洁/医院保洁/企业保洁服务优选指南
  • 今天学的是编译型与解释型的运行流程
  • 在线甘特图工具选型指南:5款产品深度对比评测
  • 2025 年 11 月食堂承包厂家推荐排行榜,学校食堂承包,工厂食堂承包,企业单位食堂承包,医院工地科技园食堂承包公司优选
  • 漏洞赏金实战:我是如何轻松获得2500美元奖金的
  • 华为网络设备重启-保存-清楚配置恢复出厂配置命令
  • 2025.11.10总结
  • 2025 年 11 月 PFA 隔膜阀厂家推荐排行榜,PFA 隔膜阀,防腐隔膜阀,高纯隔膜阀,耐酸碱隔膜阀公司推荐
  • 推荐一种异步线程执行过程中更新进度的方法
  • 2025 年 11 月食堂承包厂家推荐排行榜,学校食堂承包,工厂食堂承包,企业单位食堂承包,医院工地科技园食堂承包公司精选