QByteArray can't read all the data provided
I am inserting a HEX code in the QByteArray variable,
That hex isn't for a normal txt file, it's for an EXECUTABLE one, so it contains binary information
Code:
QByteArray hex
= "fff0000b800000000000000400";
// Very long hex string hex = hex.data();
int hexx = hex.size(); // outputs "3" while the real size is about 486400 byte
also when I output the result it only shows "MZ" and these are the first two characters of the .exe when opend with notpad.
and th rest characters are ASCII and unknown ones.
I need your help to complete this task.
Reason: I want to inject a binary data converted from hex into another process using QProcess.
Thanx.
Re: QByteArray can't read all the data provided
First remember that QByteArray::data returns char pointer i.e. the pointer to NULL terminated string and so it is used.
Second QByteArray::data says The pointer remains valid as long as the byte array isn't reallocated or destroyed. I think that line 3 is pointless.
Re: QByteArray can't read all the data provided
Okay, I deleted the line 3.
I used QFile to write the data directly to an executable file.
Successfully I executed the program. I gave you a thanx for that.
But the main issue is using QProcess to execute this binary without writing it in external file.
I will make another thread for that, and keep this one for the people wwho had the same issue.
Thank you.