ASCII & hex interpretation problems

Hello everybody, I'm having problems with an auto update program of mine.

It's supposed to download updates from a website, here's how it should work:

1. Download the source
2. Write the source into a file
3. Create vbs script to rename & delete the old file
4. Finish

The problem is at step 2, the bytes are properly downloaded and saved into a buffer, however the actual bytes, are interpreted as ASCII values, let me illustrate that:

Offset      0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F

00000000   4D 5A 90 00 03 00 00 00  04 00 00 00 FF FF 00 00   MZ          ÿÿ  
00000010   B8 00 00 00 00 00 00 00  40 00 00 00 00 00 00 00   ¸       @       
00000020   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00                   
00000030   00 00 00 00 00 00 00 00  00 00 00 00 B0 00 00 00               °   


These are the actuall bytes (like they're supposed to be in the program)
But my program saves them like this:

Offset      0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F

00000000   0D 0A 34 44 35 41 39 30  30 30 30 33 30 30 30 30     4D5A9000030000
00000010   30 30 30 34 30 30 30 30  30 30 46 46 46 46 30 30   0004000000FFFF00
00000020   30 30 42 38 30 30 30 30  30 30 30 30 30 30 30 30   00B8000000000000
00000030   30 30 34 30 30 30 30 30  30 30 30 30 30 30 30 30   0040000000000000


You can see what happend, this is the code I'm using:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
char   szRecvBuff[10000] = "" ;
string szRecvHolder = "" ;      
int    iLastCharacter = 0;

    recv(Socket, szRecvBuff, sizeof(szRecvBuff), 0);

    szRecvHolder = szRecvBuff;

    iLastCharacter = szRecvHolder.find_last_of("\n");
    if(iLastCharacter < szRecvHolder.size() && iLastCharacter > 0 ){
    szRecvHolder.erase(iLastCharacter);
    }
  return szRecvHolder;
}
...
...
{
...
...
Recv();
string Edat = Recv();
std::ofstream put("Eprog.exe", ios::binary );
put <<  Edat.c_str();
put.close();


Does anyone have any suggestions?

Topic archived. No new replies allowed.