【发布时间】:2019-10-19 09:27:32
【问题描述】:
我试图通过强制转换调用一个函数(第 15 行),但只有第一个参数被传递,我该如何解决它?
我尝试将浮点值“2”更改为 2.0f 以声明它是浮点数而不是整数,但它仍然无法正常工作。
!请注意,代码很糟糕,因为它是code golf,第15行以后必须是dll形式,这里的代码只是一个测试程序,以避免多次启动目标进程。这是我的实际代码,得分为 58 个字符
DllMain(a,b,c){((int(*)(int,float))927309216)(7903472,2);}
#include <Windows.h>
#include <stdio.h>
char * sSkelModelStencil = "SkelModelStencil"; //here I reproduce the char like it is in the memory
void SetConsoleFloat(const char *sKey, float fVal) //this is the reproduction of SetConsoleFloat in CShell.dll
{
printf("arg1: %s arg2: %f\n", sKey, fVal); //printing the arguments getting passed into the function
return;
}
int main()
{
while (1) {
SetConsoleFloat("SkelModelStencil", 2); //calling the reproduction function
((int(*)())SetConsoleFloat)(sSkelModelStencil,2); //calling the reproduction function via a cast & using SetConsoleFloat addr
system("PAUSE");
}
}
【问题讨论】:
-
请注意,第 15 行包含奇怪的演员表,因为它是代码高尔夫,我不能放太多字符。
-
这尖叫着未定义的行为,所以很难确定,但我会把钱放在被调用的函数上,期望
float在 XMM 寄存器中(假设 x86-64)和你的演员表不包括参数列表,因此调用者没有把它放在那里。 -
如果你必须保持简短,你为什么需要演员?
-
它必须是dll形式,这是我的实际代码,得分为58
DllMain(a,b,c){((int(*)(int,float))927309216)(7903472,2);} -
@ChrisHoffmann 您应该在问题中发表评论。