My issue is when I read from an existing executable and convert it to string and back to executable windows says it is not a recognized 32 bit or 64 bit application? The code below is real code I have rewritten many times but to no avail. If I leave out the part where I convert the bytes to string and just copy the binary and create a new exe with the binary the program works. But the whole concept of string converting back to valid binary has me stumped? This is Visual Basic 2008 code:
Code:
Imports System.IO
Imports System.Text
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim tempPath = System.IO.Path.GetTempPath
Dim inFile() As Byte
Dim outFileB() As Byte
Dim inFileString As String
'read exe into byte array
inFile = File.ReadAllBytes(Application.StartupPath & "\run.exe")
'convert byte array to string and read into string variable
inFileString = Convert.ToString(inFile)
'convert string variable back to byte array
outFileB = System.Text.Encoding.ASCII.GetBytes(inFileString)
'write byte array to newly created exe
File.WriteAllBytes(tempPath & "\happyfeet.exe", outFileB)
'execute new executable in user temp path
System.Diagnostics.Process.Start(tempPath & "\happyfeet.exe")
Me.Close()
End Sub
Comment