How to hook API using its Ordinal Number?

c++ / delphi package - dll injection and api hooking
Post Reply
manutai
Posts: 85
Joined: Sun Aug 03, 2008 1:40 am

How to hook API using its Ordinal Number?

Post by manutai »

Can we hook APis using its Ordinal Number?
If yes then how can we achieve this?


http://msdn.microsoft.com/en-us/library ... 80%29.aspx
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to hook API using its Ordinal Number?

Post by madshi »

Good question. I think you should be able to use GetProcAddress() to get the API address and then HookCode().
immer000
Posts: 22
Joined: Tue Sep 04, 2012 12:05 am

Re: How to hook API using its Ordinal Number?

Post by immer000 »

Use the MAKEINTRESOURCE macro with the ordinal. ie GetProcAddress(hInstance, MAKEINTRESOURCE(2))
wassily
Posts: 12
Joined: Sun Dec 16, 2012 6:37 pm

Re: How to hook API using its Ordinal Number?

Post by wassily »

madshi wrote:Good question. I think you should be able to use GetProcAddress() to get the API address and then HookCode().
not really, there are also delay loaded dlls which load after hook dll so at the hook time GetModuleHandle gives 0. As a temporary workaround I put LoadLibrary("target.dll") to make GetProcAddress work but it is actually illegal to call LoadLibrary in DllMain:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
"The entry-point function should perform only simple initialization or termination tasks. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order. This can result in a DLL being used before the system has executed its initialization code."

So some HookOrdinal (in addition to HookCode and HookAPI) would be really nice!
wassily
Posts: 12
Joined: Sun Dec 16, 2012 6:37 pm

Re: How to hook API using its Ordinal Number?

Post by wassily »

problem solved by installing a hook to LoadLibrary and waiting for the target dll being loaded
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to hook API using its Ordinal Number?

Post by madshi »

I'll put this on my to do list, but it might take a while until I get to implementing it.
Post Reply