I was wanting to try a neat little project while i was bored at work and came up with a CodeInjection class. I understand this class is VERY POORLY DESIGNED. My question is how can i fix this?? what can i do differently to make this class not so tightly coupled with the windows api functions? -thx any advice is greatly appreciated cheers
Class CodeInjection {
private:
HANDLE pHandle;
Byte *preservedBytes;
DWORD *link;
DWORD *addressOfCave;
void preserveBytes();
void restoreBytes();
static void CodeCave();
public:
void createCave();
void destroyCave();
void createLink();
void destroyLink();
CodeInjection( addressToPlaceCall, #OfBytesToOverwrite );
~CodeInjection();
};
Label1:
static void CodeInjection::CodeCave()
{
}
Label2:
CodeInjection::CodeInjection( BYTE *addressToPlaceCall, #ofBytesToOverwrite )
{
link = addressToPlaceCall;
preservedBytes = new BYTE[#ofBytesToOverwrite];
preserveBytes();
if( OPENPROCESSHANDLEHERE() )
throw ERROR;
}
void CodeInjection::createCave()
{
if ( ( addressOfCave = virtualAllocEx( pHandle, 0, Label2-Label1, MEM_COMMIT, PAGE_EXECUTE_READWRITE ) == NULL )
throw ERROR;
if( ( writeprocessMemory( pHandle, addressOfCave, Label1, Label2-Label1, 0 ) == NULL )
throw ERROR;
}
void CodeInjection::createLink()
{
if( writeproccessmemory( pHandle, link, linkbuffer, sizeof(linkbuffer), 0 ) == NULL )
throw ERROR;
}
void CodeInjection::destroyLink()
{
if( writeproccessmemory( pHandle, link, preservedBytes, sizeof(preservedBytes), 0 ) == NULL )
throw ERROR;
}
void CodeInject::preserveBytes()
{
if( readprocessmemory( pHandle, addressToPlaceCall, preservedBytes, sizeof(preservedBytes), 0 ) == NULL )
throw ERROR;
}