吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 130|回复: 2
上一主题 下一主题
收起左侧

[C&C++ 原创] FlexiHook 一个基于minhook封装的win hook库

[复制链接]
跳转到指定楼层
楼主
DeHby 发表于 2026-4-13 11:23 回帖奖励

FlexiHook

这是一个基于minhook封装的windows hook库,支持普通函数、类方法、虚函数(理论支持)、任意上下文(ContextHook 类似Frida interceptor)Hook方式

ContextHook的方式目前暂不支持修改ESP/RSP寄存器

项目开发环境

  • C++开发标准:14
  • 依赖库:minhook
  • 调用约定:默认

    编译项目

    你可以根据自己的喜好进行编译,不一定参照本教程,但请一定要更新submodules依赖

    克隆项目与获取依赖模块

    git clone --recurse-submodules https://github.com/DeHby/FlexiHook.git

    创建构建目录并进入目录

    mkdir build && cd build

    配置与编译

    cmake .. && cmake --build .


    使用例子

    APIHOOK

    
    #include "FlexiHook/FlexiHook.hpp"

static ProxyHook<decltype(MessageBoxA)> s_hookInstace;

int WINAPI MyMessageBoxW(
_Inopt HWND hWnd,
_Inopt LPCWSTR lpText,
_Inopt LPCWSTR lpCaption,
In UINT uType)
{
return s_hookInstace.Invoke(hWnd, L"测试拦截", lpCaption, uType);
}

int main()
{
MinHook::Initialize();
s_hookInstace.Install(MessageBoxW, MyMessageBoxW);
s_hookInstace.Enable();
MessageBoxW(0, L"Test", 0, 64);
return 0;
}


## MethodHook

```c_cpp
#include "FlexiHook/FlexiHook.hpp"
#include "FlexiHook/Utils.hpp"

class TestClass
{
public:
    int num;

    int add(int n)
    {
        return (num += n);
    }
};

class TestHookManager {
private:
    static auto& GetInstace()
    {
        static ProxyHook<decltype(&MyClass::myAdd)> instace;
        return instace;
    }

    class MyClass
    {
    public:
        //unknow
        int myAdd(int n)
        {
            return GetInstace().Invoke(this, 55);
        }
    };
public:
    static void Install()
    {
        GetInstace().Install(&TestClass::add, &MyClass::myAdd);
        GetInstace().Enable();
    }
};

int main()
{
      TestClass a1{};
      TestHookManager::Install();
      int ret = a1.add(100); // return 55
      return 0;
}

ContextHook X64

#include "FlexiHook/FlexiHook.hpp"
#include "FlexiHook/Utils.hpp"

int main()
{
    MinHook::Initialize();
    ContextHook ctxHook;
    ctxHook.Install(MessageBoxW, [](ThreadContext &ctx){
      static std::wstring str(pointer_cast<wchar_t*>(ctx.RDX.pu));
        str.append(L"Kai");
        ctx.RDX.pv = const_cast<wchar_t*>(str.data());
        return true; });
    ctxHook.Enable();
    MessageBoxW(0, L"Test", 0, 64);
    return 0;
}

ContextHook X86

#include "FlexiHook/FlexiHook.hpp"
#include "FlexiHook/Utils.hpp"

int main()
{
    MinHook::Initialize();

    ContextHook ctxHook;
    ctxHook.Install(MessageBoxW, [](ThreadContext &ctx){
      static std::wstring str(*reinterpret_cast<wchar_t**>(const_cast<uint8_t*>(ctx.ESP.pu + 8)));
        str.append(L"Kai");
        pointer_set(ctx.ESP.dw + 8, str.data());
        return true; });
    ctxHook.Enable();
    MessageBoxW(0, L"Test", 0, 64);
    return 0;
}

未来计划

  • [ ] 使用masm作为组译器
  • [ ] 使用RtlCaptureContext作为上下文管理
  • [ ] 实现Register类 方便快速读写寄存器 避免额外的转换

免费评分

参与人数 1威望 +1 吾爱币 +15 热心值 +1 收起 理由
苏紫方璇 + 1 + 15 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

沙发
xilou 发表于 2026-4-14 08:40
介绍要浅显易懂一点,比如:拦截按键怎么写,拦截进程创建怎么写,拦截文件创建怎么写!逛论坛的人有一半是小白吧
3#
 楼主| DeHby 发表于 2026-4-14 09:37 |楼主
xilou 发表于 2026-4-14 08:40
介绍要浅显易懂一点,比如:拦截按键怎么写,拦截进程创建怎么写,拦截文件创建怎么写!逛论坛的人有一半是 ...

只提供框架哦,这种需求还是不同人不同需要
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-4-17 09:05

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表