找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 65|回复: 0

FlexiHook Windows x86/x86_64 Hook库

[复制链接]
发表于 6 天前 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
本帖最后由 dehby1024 于 2024-10-10 18:36 编辑

FlexiHook

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

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

项目开发环境

  • visual studio 2022 v143
  • C++14
  • minhook 1.3.3
  • 编译器调用约定使用默认

使用例子

APIHOOK

#include "Hook/ProxyHook.hpp"

static ProxyHook<decltype(MessageBoxA)> s_hookInstace;

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

void main()
{
    MinHook::Initialize();
    s_hookInstace.Install(MessageBoxW, MyMessageBoxW);
    s_hookInstace.Enable();
}

MethodHook

#include "Hook/ProxyHook.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();
    }
};

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

ContextHook X64

#include "Hook/ContextHook.hpp"

void main()
{
      MinHook::Initialize();
      ctxHook.Install(MessageBoxW, [](ThreadContext& ctx) {
      static std::wstring str(reinterpret_cast<wchar_t*>(ctx.RDX.pu));
        str.append(L"Kai");
        ctx.RDX.pu = (unsigned char*)str.data();
        return true;
      });
      ctxHook.Enable();
}

ContextHook X86

#include "Hook/ContextHook.hpp"

void main()
{
      MinHook::Initialize();
      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();
}
回复

使用道具 举报

本版积分规则

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-10-16 08:17 , Processed in 0.031696 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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