Initial
This commit is contained in:
78
socket/HOOKER.CPP
Normal file
78
socket/HOOKER.CPP
Normal file
@@ -0,0 +1,78 @@
|
||||
#include <socket/hooker.hpp>
|
||||
#include <common/winsock.hpp>
|
||||
|
||||
BlockHooker::BlockHooker(void)
|
||||
: mIsHooked(FALSE)
|
||||
{
|
||||
ProcAddress<BlockHooker> procAddress;
|
||||
mCodeGenerator.push(procAddress.getProcAddress(BlockHooker::hookProc));
|
||||
mCodeGenerator.movECX(int(this));
|
||||
mCodeGenerator.popEAX();
|
||||
mCodeGenerator.callEAX();
|
||||
mCodeGenerator.retn();
|
||||
mCodeGenerator.execute();
|
||||
}
|
||||
|
||||
BlockHooker::BlockHooker(const BlockHooker &someBlockHooker)
|
||||
{ // private implementation
|
||||
}
|
||||
|
||||
BlockHooker::~BlockHooker()
|
||||
{
|
||||
unhookBlock();
|
||||
}
|
||||
|
||||
BlockHooker &BlockHooker::operator=(const BlockHooker &/*someBlockHooker*/)
|
||||
{ // private implementation
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOL BlockHooker::operator==(const BlockHooker &/*someBlockHooker*/)const
|
||||
{ // private implementation
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL BlockHooker::hookProc(void)
|
||||
{
|
||||
if(mCallback.callback(CallbackData()))cancelBlockingCall();
|
||||
return yield();
|
||||
}
|
||||
|
||||
BOOL BlockHooker::yield(void)
|
||||
{
|
||||
BOOL haveMessage(FALSE);
|
||||
MSG msg;
|
||||
|
||||
while(::PeekMessage(&msg,NULL,0,0,PM_REMOVE))
|
||||
{
|
||||
::TranslateMessage(&msg);
|
||||
::DispatchMessage(&msg);
|
||||
haveMessage=TRUE;
|
||||
}
|
||||
return haveMessage;
|
||||
}
|
||||
|
||||
BOOL BlockHooker::hookBlock(void)
|
||||
{
|
||||
if(mIsHooked)return FALSE;
|
||||
mIsHooked=TRUE;
|
||||
return (::WSASetBlockingHook((FARPROC)mCodeGenerator.base())?TRUE:FALSE);
|
||||
}
|
||||
|
||||
BOOL BlockHooker::unhookBlock(void)
|
||||
{
|
||||
if(!mIsHooked)return FALSE;
|
||||
mIsHooked=FALSE;
|
||||
return ::WSAUnhookBlockingHook();
|
||||
}
|
||||
|
||||
BOOL BlockHooker::isBlocking(void)
|
||||
{
|
||||
return ::WSAIsBlocking();
|
||||
}
|
||||
|
||||
BOOL BlockHooker::cancelBlockingCall(void)
|
||||
{
|
||||
return ::WSACancelBlockingCall();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user