vendredi 2 novembre 2018

Convert char pointer hex to a string and save in text file C++

I create a dll that is injected in a process and return a hex value for example : 570AC400. I have a function of type __int64 GetLocalPlayer_EX() that return this hex values, but text saved in txt return strange string like @*░B

char *ptr = reinterpret_cast<char*>(GetLocalPlayer_EX());//GetLocalPlayer_EX() is function return hex value
std::string str(ptr);

printf("LocalPlayer = %s\n", 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, "%s\n", szString);
    fclose(pFile);


}

WriteLogFile(vOut); // call function to save txt file

PS: if I use printf("LocalPlayer =%I64X\n", ptr);// return hex value correct

Aucun commentaire:

Enregistrer un commentaire