I'm making a packet sender.
Where the user can input the packet they want to send on a RichTextBox.
this->packetdata = (gcnew System::Windows::Forms::RichTextBox());
Sample input:
03 00 00 13 0e e0 00 00 00 00 00 01 00 08 00 00 00 00 00 03
00 00 6a 02 f0 80 7f 65 82 00 5e 04 01 01 04 01 01 01 01 ff
The server should receive:
03 00 00 13 0e e0 00 00 00 00 00 01 00 08 00 00 00 00 00 03
00 00 6a 02 f0 80 7f 65 82 00 5e 04 01 01 04 01 01 01 01 ff
But the server is receiving this instead:
30 33 20 30 30 20 30 30 20 31 33 20 30 65 20 65 03 00 00 13 0e e
30 20 30 30 20 30 30 20 30 30 20 30 30 20 30 30 0 00 00 00 00 00
20 30 31 20 30 30 20 30 38 20 30 30 20 30 30 20 01 00 08 00 00
30 30 20 30 30 20 30 30 20 30 33 0a 30 30 20 30 00 00 00 03.00 0
30 20 36 61 20 30 32 20 66 30 20 38 30 20 37 66 0 6a 02 f0 80 7f
20 36 35 20 38 32 20 30 30 20 35 65 20 30 34 20 65 82 00 5e 04
30 31 20 30 31 20 30 34 20 30 31 20 30 31 20 30 01 01 04 01 01 0
31 20 30 31 20 66 66 20 1 01 ff
How do I convert the data on the RichTextBox to remove all space and treat each as byte and send it.
This kind of approach works though:
char this[] = {0x03, 0x00, 0x00, 0x13, 0x0e, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03
0x00, 0x00, 0x6a, 0x02, 0xf0, 0x80, 0x7f, 0x65, 0x82, 0x00, 0x5e, 0x04, 0x01, 0x01, 0x04, 0x01, 0x01, 0x01, 0x01, 0xff}
With that code, the server receives the correct data.
So how do I turn the Text inside the TextBox into something like that?
This works
int mysendfunc(char *sendbuf, int size);
(...)
std::string inputpkt = marshal_as<std::string>(this->packetdata->Text);
std::istringstream reader(inputpkt);
std::vector<char> pkt;
do
{
// read as many numbers as possible.
for (int number; reader >> std::hex >> number;) {
pkt.push_back(number);
}
// consume and discard token from stream.
if (reader.fail())
{
reader.clear();
std::string token;
reader >> token;
}
}
while (!reader.eof());
int hehe = mysendfunc(pkt.data(), pkt.size());
istringstreamthe input string, then slurp out formatted data usingoperator >>(), pushing each value into astd::vector<uint8_t>and finally sendvec.size()bytes fromvec.data()reader >> numberthat assumes decimal. As I already said in my answer, you can usereader >> hex >> numberinstead.