• HOME
  • DOCS
  • WTF
  • TECH
  • LIFE
  • PAGES
    • ARCHIVE
    • TAGS
    • ABOUT
    • FRIENDS
    • RSS
  • TOOLS
    • GEO
    • RANDOM()
    • GOO.GL
    • CSS HEART
Aj's Blog

记录时间溜走的瞬间和折腾过的那些事

Hook入门之Detour库

2016-01-07  DOCS  API  detour  hook  window  

一、编译 detour 库
系统环境:WIN7 X64、VS2015、Detours Express 3.0
编译时如果出错,尝试修改Detours src目录下Makefile中CFLAGS:移除 /WX 即可
编译结果为lib.X86版,Detour 3.0 只有detours.lib 没有detoured.lib。

二、使用
复制 Detours目录\include\ 目录所有文件 给VC的include目录
复制 Detours目录\lib.X86\ 目录所有文件 给VC的lib目录

三、例子

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <detours.h>

void RealFunc( int num ) {printf("Real number: %d\n", num);}        //Real Function
void HookFunc( int num ) {printf("Hooked number: %d", num*2);}      //Hook Function
void(*realfunction)(int) = RealFunc;

int main(){
    //call the real function
    RealFunc(1014);
    
    //hook the real function
    DetourTransactionBegin();
    DetourUpdateThread( GetCurrentThread() );
    DetourAttach( &(PVOID&)realfunction, HookFunc );
    if (DetourTransactionCommit() != NO_ERROR)
        return 0;
    printf( "RealFunc hooked successfully!\n" );
    
    //call the real function agian
    RealFunc(1024);
    getchar();
    return 0;
}
下一篇:   给博客加个HTTPS吧 (lnmp nginx+letsencrypt)
上一篇:   几种Android模拟器对比
暂无评论

Cancel reply