了解了一下thunk,怎么感觉好像写shellcode,但觉得比较好玩,自己也写了一个示例程序,跟实际的thunk有点区别,供自己参考
#include <windows.h>
#include <TCHAR.h>
#include <iostream>
#pragma pack(push,1)
struct Thunk
{
BYTE m_nop;
BYTE m_push; DWORD m_fun;
BYTE m_push4; DWORD m_arg4;
BYTE m_push3; DWORD m_arg3;
BYTE m_push2; DWORD m_arg2;
BYTE m_push1; DWORD m_arg1;
DWORD m_call;
DWORD m_ret;
BOOL Init(HWND hWnd , LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
{
m_nop = 0x90; // nop;
m_push = 0x68; m_fun = PtrToUlong(::MessageBox);// push m_fun;
m_push1 = 0x68; m_arg1 = HandleToUlong(hWnd);// push m_arg1;
m_push2 = 0x68; m_arg2 = PtrToUlong(lpText);// push m_arg2;
m_push3 = 0x68; m_arg3 = PtrToUlong(lpCaption);// push m_arg3;
m_push4 = 0x68; m_arg4 = uType;// push m_arg4;
m_call = 0x102454ff;// call [esp+10h];
m_ret = 0xc304c483;// add esp,4; ret;
::FlushInstructionCache(::GetCurrentProcess(), this, sizeof(Thunk));
return TRUE;
}
};
#pragma pack(pop)
void main()
{
Thunk thunk;
void (*MsgBox)() = (void(*)())(&thunk);
thunk.Init(NULL, _T("hello world"), _T("YSHE"), MB_OK);
MsgBox(); //((void(*)())(&thunk))();
std::cout<< "this is thunk test" <<std::endl;
}