Thunk 封装 Windows Timer Api - Jerson Ju - 博客园
来源:百度文库 编辑:神马文学网 时间:2024/06/05 14:29:31
/*
描叙:Thunk技术学习
作者:朱剑
#include "stdafx.h"
#include
#include
#pragma pack(push, 1)
//由于没有虚方法所以this地址就是m_mov成员的地址
class Thunk
{
unsigned char m_mov;
unsigned int m_this;
unsigned int m_xchg_push;
unsigned char m_jmp;
unsigned int m_relproc;
public:
typedef void (_stdcall Thunk::*TMFP)();
void start()
{
Init((TMFP)&Thunk::TimerProc,this);
::SetTimer(0,0,500,(TIMERPROC )this);//用构造的假数据欺骗回调函数
}
void Init(TMFP method, const Thunk *pThis)
{
//用union的特点巧取成员地址
union {
unsigned int func;
TMFP method;
} addr;
addr.method = method;
m_jmp = 0xE9;
m_mov = 0xB8;
m_this = (unsigned int)(void *) pThis;
m_xchg_push = 0x50240487;
m_relproc = addr.func - (unsigned int)(void *)(this + 1);
//this指针是Thunk类型的,所以this+1就
//对象地址+所有成员大小= 对象数据结束的地址
//e9进行跳转的距离 = 成员函数的地址-对象数据结束的地址
}
VOID CALLBACK TimerProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_TIMER message
UINT_PTR idEvent, // timer identifier
DWORD dwTime // current system time
)
{
printf("test timer!\n");
}
};
#pragma pack(pop)
int _tmain(int argc, _TCHAR* argv[])
{
Thunk myThunk;
MSG msg;
myThunk.start();
while (GetMessage(&msg, NULL, 0, 0)) {
if (kbhit()) {
break;
}
DispatchMessage(&msg);
}
return 0;
}
描叙:Thunk技术学习
作者:朱剑
时间:2008/8/20
环境:VC8
#include "stdafx.h"
#include
#include
#pragma pack(push, 1)
//由于没有虚方法所以this地址就是m_mov成员的地址
class Thunk
{
unsigned char m_mov;
unsigned int m_this;
unsigned int m_xchg_push;
unsigned char m_jmp;
unsigned int m_relproc;
public:
typedef void (_stdcall Thunk::*TMFP)();
void start()
{
Init((TMFP)&Thunk::TimerProc,this);
::SetTimer(0,0,500,(TIMERPROC )this);//用构造的假数据欺骗回调函数
}
void Init(TMFP method, const Thunk *pThis)
{
//用union的特点巧取成员地址
union {
unsigned int func;
TMFP method;
} addr;
addr.method = method;
m_jmp = 0xE9;
m_mov = 0xB8;
m_this = (unsigned int)(void *) pThis;
m_xchg_push = 0x50240487;
m_relproc = addr.func - (unsigned int)(void *)(this + 1);
//this指针是Thunk类型的,所以this+1就
//对象地址+所有成员大小= 对象数据结束的地址
//e9进行跳转的距离 = 成员函数的地址-对象数据结束的地址
}
VOID CALLBACK TimerProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_TIMER message
UINT_PTR idEvent, // timer identifier
DWORD dwTime // current system time
)
{
printf("test timer!\n");
}
};
#pragma pack(pop)
int _tmain(int argc, _TCHAR* argv[])
{
Thunk myThunk;
MSG msg;
myThunk.start();
while (GetMessage(&msg, NULL, 0, 0)) {
if (kbhit()) {
break;
}
DispatchMessage(&msg);
}
return 0;
}
Thunk 封装 Windows Timer Api - Jerson Ju - 博客园
WINDOWS API 程序设计(第一章:开始) | 博客网
也说说Thunk - 桃之夭夭,灼灼其华. - 博客园
WINDOWS API
什么是Windows API
什么是Windows API
windows api函数:OpenSCManager
WINDOWS API 程序设计(第一章:开始)
Windows API函数使用技巧
Windows API函数大全2
Windows API函数大全一
Windows API函数大全二
Windows API函数大全四
Windows下Hook API技术
Windows API函数大全2
Windows API函数大全四
使用JNA 调用WINDOWS API
Windows Socket API 使用经验
WINDOWS API 程序设计(第一章:开始)
Windows API实现文件操作
在Webpage上调用Windows Messenger API
C#中调用Windows API的要点
Windows API函数大全一1
在Webpage上调用Windows Messenger API