So I'm wanting to profile my app and I specifically want to record the time from program start of when each of the functions called inside the program (ingnoring functions in DLL's) are entered and exited ie I want a simple table which looks something like this:
THREAD_ID FUNCTION_ADDRESS TIME EVENT_TYPE
5520 0xFF435360 0 ENTERED
5520 0xFF435ED3 25 ENTERED
5520 0xFF433550 40 ENTERED
5520 0xFF433550 50 EXITED
5520 0xFF433550 60 ENTERED
5520 0xFF433550 70 EXITED
5520 0xFF435ED3 82 EXITED
5520 0xFF435360 90 EXITED
For a program looking like this ignoring compiler optimisation:
void test1(void)
{
int a = 0;
++a;
}
void test(void)
{
test1();
test1();
}
void main(void)
{
test();
}
I couldn't find any off the shelf solution to this the nearest I could find was Microsofts VSPerfReport but it just outputs how long was spent in each function not when entered and exited.
So I started to looking into hooking all my functions with a simple function that produces a buffer which I can generate the above table from. In order to do this I was just thinking of creating a function that is called at the start of main that can go through the entire exe modify the CALL instructions to call into my hook function instead.
The libraries out there like MinHook etc all seem a little OTT for me and probably wouldn't work because its a x64 app and I'm not trying to hook DLL functions.
So I was thinking of just modifying the JMP instruction inside each of the CALL instructions ie this program:
void main(void)
{
...asm prologue
test();
002375C9 call test (235037h)
}
...asm epilogue
The call here goes to a table of JMP's:
@ILT+40(__set_errno):
0023502D jmp _set_errno (243D80h)
@ILT+45(___crtGetEnvironmentStringsA):
00235032 jmp __crtGetEnvironmentStringsA (239B10h)
test:
00235037 jmp test (237170h)
@ILT+55(_wcstoul):
0023503C jmp wcstoul (27C5D0h)
@ILT+60(__vsnprintf_s_l):
I want to go through this table and re-route all the JMP's relating to functions in my application's .exe to my hook functions that contain the timing code and then return back to the calling function.
So what does ILT stand for I'm assuming something Lookup Table and how would I go about getting hold of it?
Is this possible I've heard of IAT hooking but that looks to me to be only when hooking DLL's. Also here I've ignored exiting although another JMP in place of the RET instruction might help there?
Thanks for any help