1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
// Codecave function
VOID Codecave(DWORD destAddress, VOID (*func)(VOID), BYTE nopCount)
{
// Calculate the code cave for chat interception
DWORD offset = (PtrToUlong(func) - destAddress) - 5;
// Buffer of NOPs, static since we limit to 'UCHAR_MAX' NOPs
BYTE nopPatch[0xFF] = {0};
// Construct the patch to the function call
BYTE patch[5] = {0xE8, 0x00, 0x00, 0x00, 0x00}; // E8 = 'CALL' opcode
memcpy(patch + 1, &offset, sizeof(DWORD));
WriteBytesASM(destAddress, patch, 5);
// We are done if we do not have NOPs
if(nopCount == 0)
return;
// Fill it with nops
memset(nopPatch, 0x90, nopCount);
// Make the patch now
WriteBytesASM(destAddress + 5, nopPatch, nopCount);
}
|