【Frida】 09_获取软件窗口位置,设置鼠标指针位置

🛫 系列文章导航

🛫 导读

开发环境

版本号描述
文章日期2024-03-17
操作系统Win11 - 22H222621.2715
node -vv20.10.0
npm -v10.2.3
yarn -v3.1.1
frida-compile10.2.1高版本各种异常
扫雷程序下载地址https://download.csdn.net/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: 文章中内容仅用于技术交流,请勿用于违规违法行为。

  • 13
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜猫逐梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值