Reputation: 1
I tried this project about windows API hooking : https://cocomelonc.github.io/tutorial/2021/11/30/basic-hooking-1.html
So I tried some things like but it doesn't work :
DWORD rOffset;
rOffset = dst-src;
memcpy()
with CopyMemory()
.BYTE patch[5] = {0};
void *
and rOffset to const void*
. However, I encountered errors due to the fact that the patch will receive bytes.// hooking logic
void setMySuperHook() {
HINSTANCE hLib;
VOID *myFuncAddress;
DWORD *rOffset;
DWORD src;
DWORD dst;
CHAR patch[5]= {0};
// get memory address of function Cat
hLib = LoadLibraryA("pet.dll");
hookedAddress = GetProcAddress(hLib, "Cat");
// save the first 5 bytes into originalBytes (buffer)
ReadProcessMemory(GetCurrentProcess(), (LPCVOID) hookedAddress, originalBytes, 5, NULL);
// overwrite the first 5 bytes with a jump to myFunc
myFuncAddress = &myFunc;
// will jump from the next instruction (after our 5 byte jmp instruction)
src = (DWORD)hookedAddress + 5;
dst = (DWORD)myFuncAddress;
rOffset = (DWORD *)(dst-src);
// \xE9 - jump instruction
memcpy(patch, "\xE9", 1);
memcpy(patch + 1, &rOffset, 4);
WriteProcessMemory(GetCurrentProcess(), (LPVOID)hookedAddress, patch, 5, NULL);
}
int main() {
// I delated some code here to get a small
// call original Cat function
(catFunc)("meow-meow");
// install hook
setMySuperHook();
// call Cat function after install hook
(catFunc)("meow-meow");
}
If someone could help to understand the whole project , I have only few simple questions.
Upvotes: 0
Views: 40