Hello,
Unexported functions can be tricky to hook only because they can be tricky to "find". Most common approach, but not the best in this case, is to use binary signature pattern scanning.
If you break down the below function:
BOOL TestFunction()
{
...............
return TRUE;
}
You would only have these bytes to search for, unless ... is indicative of more code you can scan for, of course.
- Code: Select all
0xb8, 0x01, 0x00, 0x00, 0x00, 0xc3
with the assembly code looking like this
- Code: Select all
mov eax, 0x00000001
ret
You can scan the specific module containing your target function by searching through its PE sections that contain executable code, usually .text and/or .code sections are the most common.
Once your signature function locates the code pattern you can return the (hModule + code section base address + code section index you matched at) for the function pointer and then
pass this into HookCode(). It's actually rather simple to do but creating unique code signature patterns can prove difficult and depends on what the binary code structure looks like.
--Iconic