PDA

View Full Version : QByteArray can't read all the data provided



Vladimir_
15th September 2014, 17:51
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



QByteArray hex = "fff0000b800000000000000400"; // Very long hex string
hex = QByteArray::fromHex(hex);
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.

Lesiok
15th September 2014, 18:29
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.

Vladimir_
15th September 2014, 18:57
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.