holly:
ABI means non-portable.
[阅读: 518] 2007-02-23 15:56:31
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.