movies netflix
movies netflix

Reputation: 1

Is the problem with the type I used to define rOffset, src and dst or is the jump instruction no longer working (if there is another method)

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 :

  1. I did put rOffset as a regular integer : DWORD rOffset; rOffset = dst-src;
  2. I replaced memcpy() with CopyMemory().
  3. I changed the patch type to BYTE : BYTE patch[5] = {0};
  4. I attempted to change the type of both patch to void * and rOffset to const void*. However, I encountered errors due to the fact that the patch will receive bytes.
  5. I don't know if the problem is with the number of bytes that need to be adjusted from 5 to a higher value.
  6. I tried to x64dbg but I didn't know how to use it , if someone could help how to deal with memory processes in it and finding bugs.
// 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

Answers (0)

Related Questions