ورود

View Full Version : توضیح در مورد prolog and epilog code



r00tkit
دوشنبه 16 فروردین 1389, 22:50 عصر
سلام اگه کسی لطف کنه کمی در مورد مفاهیم زیر توضیح بده:""""نگید سرچ کن خودم می دونم گوگل وجود داره """"

prolog and epilog code

__declspec(naked) declarator


کد زیر


__declspec(naked) int __fastcall power(int i, int j) {
// calculates i^j, assumes that j >= 0

// prolog
__asm {
push ebp
mov ebp, esp
sub esp, __LOCAL_SIZE
// store ECX and EDX into stack locations allocated for i and j
mov i, ecx
mov j, edx
}

{
int k = 1; // return value
while (j-- > 0)
k *= i;
__asm {
mov eax, k
};
}

// epilog
__asm {
mov esp, ebp
pop ebp
ret
}
}

فکر کنم در مورد
Function calling conventions باشه

r00tkit
دوشنبه 16 فروردین 1389, 23:13 عصر
خودم گرفتم:
در کمتر از 2*3 دقیقه




All arguments are widened to 32 bits when they are passed. Return values are also widened to 32 bits and returned in the EAX register, except for 8-byte structures, which are returned in the EDX:EAX register pair. Larger structures are returned in the EAX register as pointers to hidden return structures. Parameters are pushed onto the stack from right to left. Structures that are not PODs will not be returned in registers.

The compiler generates prolog and epilog code to save and restore the ESI, EDI, EBX, and EBP registers, if they are used in the function.



و




Functions declared with the naked attribute are emitted without prolog or epilog code, enabling you to write your own custom prolog/epilog sequences using the inline assembler. Naked functions are provided as an advanced feature. They enable you to declare a function that is being called from a context other than C/C++, and thus make different assumptions about where parameters are, or which registers are preserved. Examples include routines such as interrupt handlers. This feature is particularly useful for writers of virtual device drivers (VxDs).