Reliable method for getting the size of a naked function.
Anyone know of any compile-time macros that could be used? I've been searching for awhile and got some crap solutions that were very unpredictable and unreliable.
Anyway, I was writing an injector and I wrote my own solution - I'm not sure how applicable it is though but it should be reliable, does anyone want to give it a shot?
NOTE: The epilog(the part that determines the size of the function at runtime) is not supposed to be factored into the function's size.
Also: If you have variables local to the function you need to make sure the compiler isn't using eax for those local variables.
*edit* Made it more neat, I just quickly hacked this up.
Anyway, I was writing an injector and I wrote my own solution - I'm not sure how applicable it is though but it should be reliable, does anyone want to give it a shot?
NOTE: The epilog(the part that determines the size of the function at runtime) is not supposed to be factored into the function's size.
Also: If you have variables local to the function you need to make sure the compiler isn't using eax for those local variables.
*edit* Made it more neat, I just quickly hacked this up.
Code:
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
const unsigned long SIGOFSIZE = 'SGSZ';
const void* LOADLIBA = (void*)LoadLibraryA; //Should be constant for every application...
void __declspec(naked) inject()
{
start:
__asm
{
push ebp;
mov ebp, esp;
mov eax, dword ptr [ebp + 0x8];
cmp eax, SIGOFSIZE;
jz getSize;
push eax;
call LOADLIBA;
pop ebp
ret 0x4;
};
getSize:
__asm
{
mov eax, getSize;
sub eax, start;
pop ebp
ret 0x4;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
unsigned long cb;
printf("Alterations Injector\n");
__asm
{
push SIGOFSIZE;
call inject;
mov cb, eax;
}
printf("Injectee is of %u bytes in length..\n", cb);
return 0;
}
