🛫 系列文章导航
- 【Frida】 00_简单介绍和使用 https://blog.youkuaiyun.com/kinghzking/article/details/123225580
- 【Frida】 01_食用指南 https://blog.youkuaiyun.com/kinghzking/article/details/126849567
- 【Frida】 03_初识frida-node https://blog.youkuaiyun.com/kinghzking/article/details/136685316
- 【Frida】 04_Frida中使用TypeScript脚本(采坑) https://blog.youkuaiyun.com/kinghzking/article/details/136772475
- 【Frida】 05_读取扫雷游戏的数据 https://blog.youkuaiyun.com/kinghzking/article/details/136781623
- 【Frida】 06_分析扫雷游戏的数据,显示地雷位置 https://blog.youkuaiyun.com/kinghzking/article/details/136685316
- 【Frida】 07_让系统重新绘制指定窗口 https://blog.youkuaiyun.com/kinghzking/article/details/136829854
- 【Frida】 08_将目标窗口切换到前台 https://blog.youkuaiyun.com/kinghzking/article/details/136837275
- 【Frida】 09_获取软件窗口位置,设置鼠标指针位置 https://blog.youkuaiyun.com/kinghzking/article/details/136854052
- 【Frida】10_用鼠标自动标记棋盘上的雷区(一键过关) https://blog.youkuaiyun.com/kinghzking/article/details/136854020
- 【frida-实战】“一行”代码教你获取WeGame平台中所有的lua脚本 https://blog.youkuaiyun.com/kinghzking/article/details/125590584
- 【Frida-实战】EA游戏平台的文件监控(PsExec.exe提权) https://blog.youkuaiyun.com/kinghzking/article/details/130512479
🛫 导读
开发环境
版本号 | 描述 | |
---|---|---|
文章日期 | 2024-03-17 | |
操作系统 | Win11 - 22H2 | 22621.2715 |
node -v | v20.10.0 | |
npm -v | 10.2.3 | |
yarn -v | 3.1.1 | |
frida-compile | 10.2.1 | 高版本各种异常 |
扫雷程序下载地址 | https://download.youkuaiyun.com/download/kinghzking/88979919 | |
课程源码 | https://gitcode.net/kinghzking/MyOpen | 所在目录:/course/frida |
1️⃣ 需求分析
获取当前鼠标位置
- 通过
Memory.alloc
分配一块内存(大小为struct tagPOINT
),该内存用于保存获取到的当前鼠标位置信息。- 通过
User32.GetCursorPos
获取当前鼠标位置。
// typedef struct tagPOINT {
// LONG x;
// LONG y;
// } POINT, *PPOINT, *NPPOINT, *LPPOINT;
let lpPoint= Memory.alloc(4 * 4);
User32.GetCursorPos(lpPoint);
获取当前窗口位置
- 通过
Memory.alloc
分配一块内存(大小为struct tagRECT
),该内存用于保存指定窗口的位置信息。- 通过
User32.GetWindowRect
获取当前鼠标位置。- 打印窗口坐标位置:
- .add(4) 指针指向内存+4的地址,返回新的指针对象。
- .readU32() 读取指针指向地址的内容,返回类型为整数。
// typedef struct tagRECT {
// LONG left;
// LONG top;
// LONG right;
// LONG bottom;
// } RECT, *PRECT, *NPRECT, *LPRECT;
let lpRect = Memory.alloc(4 * 4);
User32.GetWindowRect(this.hWnd, lpRect);
console.log("left", lpRect.readU32());
console.log("top", lpRect.add(4).readU32());
console.log("right", lpRect.add(8).readU32());
console.log("bottom", lpRect.add(12).readU32());
设置鼠标指针位置到扫雷窗口上
User32.SetCursorPos
设置鼠标位置到扫雷窗口上。
User32.SetCursorPos(lpRect.readU32(), lpRect.add(4).readU32());
恢复鼠标指针位置到初始位置
- 先调用
Kernel32.Sleep
,等待2秒钟,方便查看鼠标位置。User32.SetCursorPos
设置鼠标位置到初始位置lpPoint。
Kernel32.Sleep(2000);
User32.SetCursorPos(lpPoint.readU32(), lpPoint.add(4).readU32());
2️⃣ 运行验证
编写代码如下:
获取软件窗口位置_设置鼠标指针位置() {
// typedef struct tagPOINT {
// LONG x;
// LONG y;
// } POINT, *PPOINT, *NPPOINT, *LPPOINT;
let lpPoint = Memory.alloc(4 * 2);
User32.GetCursorPos(lpPoint);
// typedef struct tagRECT {
// LONG left;
// LONG top;
// LONG right;
// LONG bottom;
// } RECT, *PRECT, *NPRECT, *LPRECT;
let lpRect = Memory.alloc(4 * 4);
User32.GetWindowRect(this.hWnd, lpRect);
console.log("left", lpRect.readU32());
console.log("top", lpRect.add(4).readU32());
console.log("right", lpRect.add(8).readU32());
console.log("bottom", lpRect.add(12).readU32());
User32.SetCursorPos(lpRect.readU32(), lpRect.add(4).readU32());
Kernel32.Sleep(2000);
User32.SetCursorPos(lpPoint.readU32(), lpPoint.add(4).readU32());
}
执行上面的代码,鼠标将跳到扫雷窗口的左上角,然后等待2秒钟,最后又回到原来的位置。
🛬 文章小结
本篇虽然代码比较少,但是,从此我们踏入了自动化的门槛。
需要注意的一点是,我们上面的代码是在目标进程中运行的,所以,所有的代码都是
调用目标进程的api
,并不是frida进程去控制目标进程完成的。
这样的调用,权限要比frida进程去控制
高,可以省去一些不必要的麻烦。
ps: 文章中内容仅用于技术交流,请勿用于违规违法行为。