ray_code, I tried your code on my .exe file. As you said the bytes before and after differ.
The reason why they differ:
Below is a line from msdn (Understanding Encodings:
http://msdn.microsoft.com/en-us/library/ms404377.aspx)
"•If your application has content that is not strictly ASCII and encodes it with ASCIIEncoding, each non-ASCII character encodes as a question mark ("?"). If the application then decodes this data, the information is lost."
Obvioursly the byte data from the .exe file is "not ASCII" and information is lost.
What is the solution for this:
Below is a line from msdn (Encoding class:
http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx)
"If your application must encode arbitrary binary data into text, it should use a protocol such as uuencode, which is implemented by methods such as Convert.ToBase64CharArray.
"
Obviously the byte data from the .exe file is arbitrary binary data and you should consider using Base64 encoding instead as shown in the code below: