我创建了一个在进程中注入的dll,并返回一个十六进制值,例如:570AC400。我有一个__int64 GetLocalPlayer_EX()
类型的函数,它返回这个十六进制值,但保存在txt中的文本返回奇怪的字符串,比如@*░B
char *ptr = reinterpret_cast<char*>(GetLocalPlayer_EX());//GetLocalPlayer_EX() is function return hex value
std::string str(ptr);
printf("LocalPlayer = %sn", ptr);//print to test, but return strange string like @*░B should be 570AC400
void WriteLogFile(const char* szString)//convert char hex to string and save in txt
{
FILE* pFile = fopen("C:\TesteArquivo\TesteFile.txt", "a");
fprintf(pFile, "%sn", szString);
fclose(pFile);
}
WriteLogFile(vOut); // call function to save txt file
PS:如果我使用printf("LocalPlayer =%I64Xn", ptr);
,则返回的十六进制值是正确的。
您可以从函数中获取原始int。你不应该把它变成一个字符。试试这个:
__int64 rv = GetLocalPlayer_EX();
printf("LocalPlayer = %ldn", rv);
printf("LocalPlayer = %Xn", rv);
但我想知道函数的签名是否正确。它真的返回__int64
而不是ClientPlayer*
吗?
编辑:由于它似乎是一个伪装的指针,
char *ptr = reinterpret_cast<char*>(GetLocalPlayer_EX());
printf("%pn", ptr);