508 lines
8.1 KiB
C++
508 lines
8.1 KiB
C++
#ifndef _THREAD_CONTEXT_HPP_
|
|
#define _THREAD_CONTEXT_HPP_
|
|
#include <stdio.h>
|
|
#ifndef _COMMON_STRING_HPP_
|
|
#include <common/string.hpp>
|
|
#endif
|
|
#ifndef _THREAD_FLOATINGSAVEAREA_HPP_
|
|
#include <thread/savearea.hpp>
|
|
#endif
|
|
|
|
class Context : private CONTEXT
|
|
{
|
|
public:
|
|
enum ContextType{FloatingPoint=CONTEXT_FLOATING_POINT,Integer=CONTEXT_INTEGER,
|
|
Control=CONTEXT_CONTROL,Segments=CONTEXT_SEGMENTS,Full=CONTEXT_FULL,
|
|
DebugRegisters=CONTEXT_DEBUG_REGISTERS};
|
|
Context(void);
|
|
Context(const Context &someContext);
|
|
Context(const CONTEXT &someCONTEXT);
|
|
virtual ~Context(void);
|
|
Context &operator=(const Context &someContext);
|
|
Context &operator=(const CONTEXT &someCONTEXT);
|
|
WORD operator==(const Context &someContext)const;
|
|
WORD operator==(const CONTEXT &someCONTEXT)const;
|
|
operator String(void)const;
|
|
WORD getThreadContext(HANDLE hThread);
|
|
WORD setThreadContext(HANDLE hThread);
|
|
DWORD contextFlags(void)const;
|
|
void contextFlags(DWORD contextFlags);
|
|
DWORD dr0(void)const;
|
|
void dr0(DWORD dr0);
|
|
DWORD dr1(void)const;
|
|
void dr1(DWORD dr1);
|
|
DWORD dr2(void)const;
|
|
void dr2(DWORD dr2);
|
|
DWORD dr3(void)const;
|
|
void dr3(DWORD dr3);
|
|
DWORD dr6(void)const;
|
|
void dr6(DWORD dr6);
|
|
DWORD dr7(void)const;
|
|
void dr7(DWORD dr7);
|
|
FloatingSaveArea floatingSaveArea(void)const;
|
|
void floatingSaveArea(const FloatingSaveArea &someFloatingSaveArea);
|
|
DWORD segCS(void)const;
|
|
void segCS(DWORD segCS);
|
|
DWORD segGS(void)const;
|
|
void segGS(DWORD segGS);
|
|
DWORD segFS(void)const;
|
|
void segFS(DWORD segGS);
|
|
DWORD segES(void)const;
|
|
void segES(DWORD segGS);
|
|
DWORD segDS(void)const;
|
|
void segDS(DWORD segGS);
|
|
DWORD segSS(void)const;
|
|
void segSS(DWORD segSS);
|
|
DWORD edi(void)const;
|
|
void edi(DWORD edi);
|
|
DWORD esi(void)const;
|
|
void esi(DWORD esi);
|
|
DWORD ebx(void)const;
|
|
void ebx(DWORD ebx);
|
|
DWORD edx(void)const;
|
|
void edx(DWORD edx);
|
|
DWORD ecx(void)const;
|
|
void ecx(DWORD ecx);
|
|
DWORD eax(void)const;
|
|
void eax(DWORD eax);
|
|
DWORD ebp(void)const;
|
|
void ebp(DWORD ebp);
|
|
DWORD eip(void)const;
|
|
void eip(DWORD eip);
|
|
DWORD esp(void)const;
|
|
void esp(DWORD esp);
|
|
DWORD eFlags(void)const;
|
|
void eFlags(DWORD eFlags);
|
|
BOOL cf(void)const;
|
|
BOOL zf(void)const;
|
|
BOOL sf(void)const;
|
|
BOOL of(void)const;
|
|
BOOL pf(void)const;
|
|
BOOL af(void)const;
|
|
BOOL ie(void)const;
|
|
BOOL df(void)const;
|
|
private:
|
|
enum FlagMask{MaskCarry=0x0001,MaskZero=0x0040,MaskSign=0x0080,MaskOverflow=0x0800,MaskParity=0x0004,
|
|
MaskAuxiliaryCarry=0x0010,MaskInterruptEnable=0x0200,MaskDirection=0x0400};
|
|
void setZero(void);
|
|
};
|
|
|
|
inline
|
|
Context::Context(void)
|
|
{
|
|
setZero();
|
|
contextFlags(Full);
|
|
}
|
|
|
|
inline
|
|
Context::Context(const Context &someContext)
|
|
{
|
|
*this=someContext;
|
|
}
|
|
|
|
inline
|
|
Context::Context(const CONTEXT &someCONTEXT)
|
|
{
|
|
*this=someCONTEXT;
|
|
}
|
|
|
|
inline
|
|
Context::~Context(void)
|
|
{
|
|
}
|
|
|
|
inline
|
|
Context &Context::operator=(const Context &someContext)
|
|
{
|
|
::memcpy((char*)&((CONTEXT&)*this),(char*)&((CONTEXT&)someContext),sizeof(CONTEXT));
|
|
return *this;
|
|
}
|
|
|
|
inline
|
|
Context &Context::operator=(const CONTEXT &someCONTEXT)
|
|
{
|
|
::memcpy((char*)&((CONTEXT&)*this),(char*)&someCONTEXT,sizeof(CONTEXT));
|
|
return *this;
|
|
}
|
|
|
|
inline
|
|
WORD Context::operator==(const Context &someContext)const
|
|
{
|
|
return (::memcmp((char*)&((CONTEXT&)*this),(char*)&((CONTEXT&)someContext),sizeof(CONTEXT))?FALSE:TRUE);
|
|
}
|
|
|
|
inline
|
|
WORD Context::operator==(const CONTEXT &someCONTEXT)const
|
|
{
|
|
return (::memcmp((char*)&((CONTEXT&)*this),(char*)&someCONTEXT,sizeof(CONTEXT))?FALSE:TRUE);
|
|
}
|
|
|
|
inline
|
|
Context::operator String(void)const
|
|
{
|
|
String contextString;
|
|
|
|
contextString.reserve(String::MaxString*4);
|
|
::sprintf(contextString,"EAX:%08lx EBX:%08lx ECX:%08lx EDX:%08lx EIP:%08lx EBP:%08lx ESP:%08lx EDI:%08lx ESI:%08lx\nDR0:%08lx DR1:%08lx DR2:%08lx DR3:%08lx DR6:%08lx DR7:%08lx\nCS:%08lx GS:%08lx FS:%08lx ES:%08lx DS:%08lx SS:%08lx Flags:%08lx",
|
|
eax(),ebx(),ecx(),edx(),eip(),ebp(),esp(),edi(),esi(),
|
|
dr0(),dr1(),dr2(),dr3(),dr6(),dr7(),
|
|
segCS(),segGS(),segFS(),segES(),segDS(),segSS(),eFlags());
|
|
return contextString;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::contextFlags(void)const
|
|
{
|
|
return CONTEXT::ContextFlags;
|
|
}
|
|
|
|
inline
|
|
void Context::contextFlags(DWORD contextFlags)
|
|
{
|
|
CONTEXT::ContextFlags=contextFlags;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::dr0(void)const
|
|
{
|
|
return CONTEXT::Dr0;
|
|
}
|
|
|
|
inline
|
|
void Context::dr0(DWORD dr0)
|
|
{
|
|
CONTEXT::Dr0=dr0;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::dr1(void)const
|
|
{
|
|
return CONTEXT::Dr1;
|
|
}
|
|
|
|
inline
|
|
void Context::dr1(DWORD dr1)
|
|
{
|
|
CONTEXT::Dr1=dr1;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::dr2(void)const
|
|
{
|
|
return CONTEXT::Dr2;
|
|
}
|
|
|
|
inline
|
|
void Context::dr2(DWORD dr2)
|
|
{
|
|
CONTEXT::Dr2=dr2;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::dr3(void)const
|
|
{
|
|
return CONTEXT::Dr3;
|
|
}
|
|
|
|
inline
|
|
void Context::dr3(DWORD dr3)
|
|
{
|
|
CONTEXT::Dr3=dr3;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::dr6(void)const
|
|
{
|
|
return CONTEXT::Dr6;
|
|
}
|
|
|
|
inline
|
|
void Context::dr6(DWORD dr6)
|
|
{
|
|
CONTEXT::Dr6=dr6;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::dr7(void)const
|
|
{
|
|
return CONTEXT::Dr7;
|
|
}
|
|
|
|
inline
|
|
void Context::dr7(DWORD dr7)
|
|
{
|
|
CONTEXT::Dr7=dr7;
|
|
}
|
|
|
|
inline
|
|
FloatingSaveArea Context::floatingSaveArea(void)const
|
|
{
|
|
return FloatingSaveArea(CONTEXT::FloatSave);
|
|
}
|
|
|
|
inline
|
|
void Context::floatingSaveArea(const FloatingSaveArea &someFloatingSaveArea)
|
|
{
|
|
::memcpy((char*)&FloatSave,(char*)&((FLOATING_SAVE_AREA&)someFloatingSaveArea),sizeof(FLOATING_SAVE_AREA));
|
|
}
|
|
|
|
inline
|
|
DWORD Context::segCS(void)const
|
|
{
|
|
return CONTEXT::SegCs;
|
|
}
|
|
|
|
inline
|
|
void Context::segCS(DWORD segCS)
|
|
{
|
|
CONTEXT::SegCs=segCS;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::segGS(void)const
|
|
{
|
|
return CONTEXT::SegGs;
|
|
}
|
|
|
|
inline
|
|
void Context::segGS(DWORD segGS)
|
|
{
|
|
CONTEXT::SegGs=segGS;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::segFS(void)const
|
|
{
|
|
return CONTEXT::SegFs;
|
|
}
|
|
|
|
inline
|
|
void Context::segFS(DWORD segFS)
|
|
{
|
|
CONTEXT::SegFs=segFS;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::segES(void)const
|
|
{
|
|
return CONTEXT::SegEs;
|
|
}
|
|
|
|
inline
|
|
void Context::segES(DWORD segES)
|
|
{
|
|
CONTEXT::SegEs=segES;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::segDS(void)const
|
|
{
|
|
return CONTEXT::SegDs;
|
|
}
|
|
|
|
inline
|
|
void Context::segDS(DWORD segDS)
|
|
{
|
|
CONTEXT::SegDs=segDS;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::segSS(void)const
|
|
{
|
|
return CONTEXT::SegSs;
|
|
}
|
|
|
|
inline
|
|
void Context::segSS(DWORD segSS)
|
|
{
|
|
CONTEXT::SegSs=segSS;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::edi(void)const
|
|
{
|
|
return CONTEXT::Edi;
|
|
}
|
|
|
|
inline
|
|
void Context::edi(DWORD edi)
|
|
{
|
|
CONTEXT::Edi=edi;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::esi(void)const
|
|
{
|
|
return CONTEXT::Esi;
|
|
}
|
|
|
|
inline
|
|
void Context::esi(DWORD esi)
|
|
{
|
|
CONTEXT::Esi=esi;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::ebx(void)const
|
|
{
|
|
return CONTEXT::Ebx;
|
|
|
|
}
|
|
|
|
inline
|
|
void Context::ebx(DWORD ebx)
|
|
{
|
|
CONTEXT::Ebx=ebx;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::edx(void)const
|
|
{
|
|
return CONTEXT::Edx;
|
|
}
|
|
|
|
inline
|
|
void Context::edx(DWORD edx)
|
|
{
|
|
CONTEXT::Edx=edx;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::ecx(void)const
|
|
{
|
|
return CONTEXT::Ecx;
|
|
}
|
|
|
|
inline
|
|
void Context::ecx(DWORD ecx)
|
|
{
|
|
CONTEXT::Ecx=ecx;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::eax(void)const
|
|
{
|
|
return CONTEXT::Eax;
|
|
}
|
|
|
|
inline
|
|
void Context::eax(DWORD eax)
|
|
{
|
|
CONTEXT::Eax=eax;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::ebp(void)const
|
|
{
|
|
return CONTEXT::Ebp;
|
|
}
|
|
|
|
inline
|
|
void Context::ebp(DWORD ebp)
|
|
{
|
|
CONTEXT::Ebp=ebp;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::eip(void)const
|
|
{
|
|
return CONTEXT::Eip;
|
|
}
|
|
|
|
inline
|
|
void Context::eip(DWORD eip)
|
|
{
|
|
CONTEXT::Eip=eip;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::esp(void)const
|
|
{
|
|
return CONTEXT::Esp;
|
|
}
|
|
|
|
inline
|
|
void Context::esp(DWORD esp)
|
|
{
|
|
CONTEXT::Esp=esp;
|
|
}
|
|
|
|
inline
|
|
DWORD Context::eFlags(void)const
|
|
{
|
|
return CONTEXT::EFlags;
|
|
}
|
|
|
|
inline
|
|
void Context::eFlags(DWORD eFlags)
|
|
{
|
|
CONTEXT::EFlags=eFlags;
|
|
}
|
|
|
|
inline
|
|
BOOL Context::cf(void)const
|
|
{
|
|
return eFlags()&MaskCarry?TRUE:FALSE;
|
|
}
|
|
|
|
inline
|
|
BOOL Context::zf(void)const
|
|
{
|
|
return eFlags()&MaskZero?TRUE:FALSE;
|
|
}
|
|
|
|
inline
|
|
BOOL Context::sf(void)const
|
|
{
|
|
return eFlags()&MaskSign?TRUE:FALSE;
|
|
}
|
|
|
|
inline
|
|
BOOL Context::of(void)const
|
|
{
|
|
return eFlags()&MaskOverflow?TRUE:FALSE;
|
|
}
|
|
|
|
inline
|
|
BOOL Context::pf(void)const
|
|
{
|
|
return eFlags()&MaskParity?TRUE:FALSE;
|
|
}
|
|
|
|
inline
|
|
BOOL Context::af(void)const
|
|
{
|
|
return eFlags()&MaskAuxiliaryCarry?TRUE:FALSE;
|
|
}
|
|
|
|
inline
|
|
BOOL Context::ie(void)const
|
|
{
|
|
return eFlags()&&MaskInterruptEnable?TRUE:FALSE;
|
|
}
|
|
|
|
inline
|
|
BOOL Context::df(void)const
|
|
{
|
|
return eFlags()&MaskDirection?TRUE:FALSE;
|
|
}
|
|
|
|
inline
|
|
void Context::setZero(void)
|
|
{
|
|
::memset((char*)&((CONTEXT&)*this),0,sizeof(CONTEXT));
|
|
}
|
|
|
|
inline
|
|
WORD Context::getThreadContext(HANDLE hThread)
|
|
{
|
|
return ::GetThreadContext(hThread,&((CONTEXT&)*this));
|
|
}
|
|
|
|
inline
|
|
WORD Context::setThreadContext(HANDLE hThread)
|
|
{
|
|
return ::SetThreadContext(hThread,&((CONTEXT&)*this));
|
|
}
|
|
#endif
|