被人嘲笑,随便说说

在编程的这条路上不时地产生迷茫,到底这条路走下去该去哪呀,这几天有空研究了一下C++的thunk机制,却被同时嘲笑浪费时间,郁闷。
下面是在下这几天自己写的非常简单的线程类,希望大家批评指教,如果真没用,那我就去学别的了
/*********************************/
/*** file:CThread.h ***/
/*********************************/
#include

#pragma pack(push, 1)
struct StdThunkContext
{
BYTE m_mov; // mov eax, %pThis
DWORD m_this; //
DWORD m_xchg_push; // xchg eax, [esp] : push eax
BYTE m_jmp; // jmp func
DWORD m_relproc; // relative jmp
};
#pragma pack(pop)

template
class CStdThunk
{
public:
struct StdThunkContext thunk;
typedef void (__stdcall T::*pTgFunc)();
public: void InitThunk(pTgFunc method, const T* pThis)
{
union { DWORD func; pTgFunc method; } addr;
addr.method = method;
thunk.m_mov = 0xB8;
thunk.m_this = (DWORD)pThis;
thunk.m_xchg_push = 0x50240487;
thunk.m_jmp = 0xE9;
thunk.m_relproc = addr.func - (DWORD)(&thunk + 1);

FlushInstructionCache(GetCurrentProcess(), &thunk, sizeof(thunk));
}
};

class CThread
{
HANDLE hThread;
DWORD ThreadID;
DWORD __stdcall _ThreadFun(LPVOID);
CStdThunk ThreadFun;

public:
CThread(LPVOID);
~CThread();
};

CThread::CThread(LPVOID lpParam)
{
hThread = NULL;
ThreadID = 0; ThreadFun.InitThunk((CStdThunk::pTgFunc)(&(CThread::_ThreadFun)),this);
hThread = CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE)&(ThreadFun.thunk),
(LPVOID)lpParam,
0, &ThreadID);
if(hThread == NULL)
{
//-----------异常处理----------//
}
}
CThread::~CThread()
{

}

DWORD __stdcall CThread::_ThreadFun(LPVOID lpParam)
{
//-------在此添加线程主体过程-------//
return 0;
}
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭