中国开发网: 论坛: 程序员情感CBD: 贴子 476479
holly
ABI means non-portable.
Of course, it is also easy to write such a wrapper. Just use a little assembly and stack knowledges..

After regular prolog, we know we have argument "fmt" on the stack just above eip and ebp, so...you know that is just a small trick.

int _cdecl myprintf(const char * fmt, ...)
{
if ( the-condition-is-true ) {

_asm {
mov eax, [ebp] // eax -> value of outer ebp
sub eax, 4 // last arg
mov ecx, ebp
add ecx, 8 // first arg. i.e. fmt
PUSH_ARGS:
cmp eax, ecx
jge ARGS_COMPLETED
mov ebx, [eax]
push ebx
sub eax, 4
jmp PUSH_ARGS
ARGS_COMPLETED:
call _printf
}


}
}

This code snippet is for 32-bit x86 and regular stack frame only, I didn't test it, so there may have issues or errors, but you know, I just make a illustration here.

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录