【发布时间】:2015-11-11 12:04:43
【问题描述】:
我想知道是否可以调用 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;
}
你们碰巧有时间演示一个工作示例吗?在互联网上找不到任何关于它的信息。
【问题讨论】:
-
是的,但是(我假设你知道),不是那个代码。
-
这是可能的,但您需要将指针推送到格式字符串,而不是格式字符串本身。
-
你如何判断
3710092110与%d\n有任何 关系? -
@Ville-ValtteriTiittanen:好吧,也许你应该在与我交谈之前测试一下。
-
@Mamma:如果你认为
%d\n等于字节37、100、92和92和110,你需要了解这两个转义码和空终止。