How can I convert an offset in text segment of an Win32 executable into a pointer at runtime?
When using a disassembler, I can see the relative addresses. But how can I convert them to an absolute address at runtime?
For example:
.text:402BE620
Which address is that at runtime? How can I convert that number into a pointer?
Some background: I have to fix a bug in a end-of-life DLL and we don't have access to the source code. For that I want to hook a specific function and override it at runtime.
(It contains a call to WaitForSingleObject
where MsgWaitForMultipleObjects
had to be used, and because of the additional parameters it cannot be fixed with a hex editor)
EDIT: Thank you for your suggestions, but I added that stuff about hooking only to give you some context. I don't need a hooking framework!. I have a good hooking framework which does all the heavy lifting and - at least for now - I don't need any more information about hooking itself.
I just have to provide the address of the function to hook to my hooking framework and for that I have to know how to calculate it and I don't know how to determine it.
EDIT 2: I have used two different disassembler, both show the address as noted above. Somewhat odd: Both reject "402BE620" as an offset if I use their "goto" feature. I have to enter the offset as "2BE620" to make it work...