中国开发网: 论坛: 程序员情感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.
若你在年轻时上过水木, 它会一生跟随着你, 如一场浮动的盛宴

禁色和禁果仍被保存吗?
这世界有否给潜移默化?
离过家回了家仍住中环吗?
-----信有带到新居里烧吗?

一切美好的都会消失

人要是没有理想, 跟咸鱼有什么两样?

“把人们引向艺术和科学的最强烈动机之一,是要逃避日常生活中令人厌恶的粗俗和使人绝望的沉闷,是要摆脱人们自己反复无常的欲望的桎梏。一个修养有素的人总是渴望逃避个人生活而进入客观直觉和思维的世界。”

不要忘了,这个世界穿透一切高墙的东西,它就在我们的内心深处,他们无法达到,也接触不到,那就是希望。(FROM《肖申克的救赎》)

相关信息:


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