我想知道是否可以在不声明数据段中的格式数组的情况下调用printf。这个问题是关于x86的。
#include <stdio.h>
int main()
{
__asm
{
push 1 ; number to print
push 3710092110 ; format in ascii for %d\n
call printf
add esp, 8
}
return 0;
}
好的,我们需要推送格式的地址,而不是格式本身,所以类似这样的内容应该足够接近吧?
#include <stdio.h>
int main()
{
__asm
{
push 3710092110 ; 3710092110 = format in ascii for %d\n
push 1; argument to print
lea edx, dword ptr[esp + 4]; get address of the format on stack
push edx ; push the address of the format
call printf
add esp, 12
}
return 0;
}
你们碰巧有时间演示一个有效的例子吗?在互联网上找不到任何有关它的信息。
您的第二个代码段接近,但对于格式字符串%d \ n的内容,仍需要使用其他值。
涉及的字符转换为% = 37,d = 100,\ n = 10(十进制)。
但是使用十六进制要容易得多:% = 25h,d = 64h,\ n = 0Ah由于缺乏端正性,我们必须将第一个字符放在dword的最低字节中以压入堆栈。我们将最高字节保留为零以具有必要的null终止。
%d\n --> 000A6425h
您的代码:
#include <stdio.h>
int main()
{
__asm
{
push 000A6425h ;= format in ascii for %d\n
push 1; argument to print
lea edx, dword ptr[esp + 4]; get address of the format on stack
push edx ; push the address of the format
call printf
add esp, 12
}
return 0;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句