2

How to hook to external library function, such as OpenGL for example.

I have a function used by the program I am trying to change behaviour of. The function is:

lVar17 = glfwCreateWindow(uVar22,uVar25,pplVar29,uVar30,0);

Now, I want to change that function without changing the caller function. I.e. the caller function and the call above will remain exactly the same, but the glfwCreateWindow will return something different, i.e. it will be re-written like this:

glfwCreateWindow (uVar22,uVar25,pplVar29,uVar30,0) {

    GLFWwindow* window = glfwCreateWindow(uVar22,uVar25,pplVar29,uVar30,0);
    HWND hwnd = FindWindow(NULL, WindowName);
    GLFWwindow* atchdHwd = glfwAttachWin32Window(hwnd, window); 
    return atchdHwd;
}

Any way of doing this?

1 Answer 1

4

Two possibilities:

  1. Patch the call instruction to point to a destination of your choosing, such as a "code cave" between the end of the .text section and the subsequent section. Write your function there, or jmp to your DLL / a piece of allocated memory containing your function.
  2. Overwrite the IAT entry for glfwCreateWindow, and point it to your new function. Note that this will affect all calls to that function. If you want to affect only individual call sites, you can, for example, check the return address of the caller to ensure that it's the specific call site that you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.