Advertisement
Ajay_kumar

Bat2exe(form source code)

Jul 24th, 2014
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.78 KB | None | 0 0
  1. '   Bat2exe converter
  2. '   Author : skyte
  3. '   http://sec-articles.blogspot.com
  4. '
  5. '   Credits :  MrvbDude for file binder
  6. '
  7.  
  8. Imports System
  9. Imports System.Text
  10. Imports System.IO
  11. Imports System.Threading
  12. Imports System.CodeDom.Compiler
  13. Imports Microsoft.CSharp
  14. Imports System.Collections.Generic
  15.  
  16. Public Class Form1
  17.    
  18.     Dim batchpath As String = Nothing
  19.     Dim iconpath As String = Nothing
  20.     Dim bindfilepath As String = Nothing
  21.     Dim bindfilename As String = Nothing
  22.     Dim outputfile As String = Nothing
  23.     Dim src As String = My.Resources.stub
  24.  
  25.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  26.         TextBox2.Enabled = False
  27.         TextBox3.Enabled = False
  28.  
  29.     End Sub
  30.    
  31.    
  32.     Private Sub Compile(ByVal Exename As String, ByVal SourceCode As String, ByVal Icon As String)
  33.         Dim compiler As CodeDomProvider = CodeDomProvider.CreateProvider("VisualBasic")
  34.         Dim param As New CompilerParameters
  35.         Dim results As CompilerResults = Nothing
  36.         param.GenerateExecutable = True
  37.         param.OutputAssembly = Exename
  38.         param.ReferencedAssemblies.Add("System.dll")
  39.         param.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll")
  40.         param.CompilerOptions = " /target:winexe"
  41.         param.TreatWarningsAsErrors = False
  42.         If (Icon = Nothing) Then
  43.             'do nothing
  44.         Else
  45.             File.Copy(Icon, "icon.ico")
  46.             param.CompilerOptions += " /win32icon:" & "icon.ico"
  47.         End If
  48.  
  49.         results = compiler.CompileAssemblyFromSource(param, SourceCode)
  50.  
  51.         If (results.Errors.Count <> 0) Then
  52.             MsgBox("Some Error Occured During Code Compiletion, Try Again!!", MsgBoxStyle.Critical)
  53.             For Each E As CompilerError In results.Errors
  54.                 MessageBox.Show(E.ErrorText)
  55.             Next
  56.         End If
  57.  
  58.         If (Icon = Nothing) Then
  59.             'do nothing
  60.         Else
  61.             File.Delete("icon.ico")
  62.         End If
  63.  
  64.     End Sub
  65.  
  66.     Function secure(ByVal data As Byte()) As Byte()
  67.         Using SA As New System.Security.Cryptography.RijndaelManaged
  68.             SA.IV = New Byte() {1, 9, 2, 8, 3, 7, 4, 5, 6, 0, 1, 4, 3, 0, 0, 7}
  69.             SA.Key = New Byte() {7, 0, 0, 3, 4, 1, 0, 6, 5, 4, 7, 3, 8, 2, 9, 1}
  70.             Return SA.CreateEncryptor.TransformFinalBlock(data, 0, data.Length)
  71.         End Using
  72.     End Function
  73.  
  74.     Sub Replace(ByRef main As String, ByVal old As String, ByVal [new] As String)
  75.         main = main.Replace(old, [new])
  76.     End Sub
  77.  
  78.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button4.Click
  79.         Dim src As String = Nothing
  80.         Dim Compressor As Boolean = False
  81.  
  82.         ' Configuring iconpath for second use
  83.         If CheckBox1.Checked = False Then
  84.             iconpath = Nothing
  85.         End If
  86.  
  87.         If TextBox1.Text = "Click Here to Browse the Batch File" Then
  88.             MsgBox("Select A Batch File First .!!", MsgBoxStyle.Critical, "Error ..!!")
  89.             Exit Sub
  90.         End If
  91.  
  92.         If CheckBox1.Checked = True Then
  93.             If TextBox2.Text = "Click Here to Browse Icon" Then
  94.                 MsgBox("Select An Icon File First .!!", MsgBoxStyle.Critical, "Error ..!!")
  95.                 Exit Sub
  96.             Else
  97.                 'do nothing
  98.             End If
  99.         End If
  100.  
  101.         If CheckBox2.Checked = True Then
  102.             If TextBox3.Text = "Click Here to Browse File" Then
  103.                 MsgBox("Please Select A File To Bind First .!!", MsgBoxStyle.Critical, "Error ..!!")
  104.                 Exit Sub
  105.             Else
  106.                 ' do nothing
  107.             End If
  108.         End If
  109.  
  110.         Using s As New SaveFileDialog()
  111.             s.Title = "Save File ...!!"
  112.             s.Filter = "Executable |*.exe"
  113.             If (s.ShowDialog = Windows.Forms.DialogResult.OK) Then
  114.                 outputfile = s.FileName
  115.  
  116.                 src = My.Resources.stub
  117.  
  118.                 If CheckBox3.Checked = True Then
  119.                     Replace(src, "Dim hiddenmode As Boolean = False", "Dim hiddenmode As Boolean = True")
  120.                 End If
  121.  
  122.                 If CheckBox2.Checked = True Then
  123.                     Replace(src, "'[BDPROC]", Nothing)
  124.                 End If
  125.  
  126.  
  127.                 Label1.Text = "Creating Stub"
  128.                
  129.                 Try
  130.                     ' !!!   Make call to compile stub File !!!
  131.                     Label1.Text = "Compiling Stub"
  132.                     Compile(outputfile, src, iconpath)
  133.  
  134.                     ' Writing Files into stub
  135.                     Dim sp As String = "[SPLITTING_POINT]"
  136.                     Dim batchf As Byte() = secure(My.Computer.FileSystem.ReadAllBytes(batchpath))
  137.                     Label1.Text = "Reading Batch File"
  138.                     If CheckBox2.Checked = True Then
  139.                         Label1.Text = "Reading Binded File"
  140.                         Dim bindf As Byte() = secure(My.Computer.FileSystem.ReadAllBytes(bindfilepath))
  141.                         Label1.Text = "Writing Files To Stub"
  142.                         System.IO.File.AppendAllText(outputfile, sp & Convert.ToBase64String(batchf) & sp & bindfilename & sp & Convert.ToBase64String(bindf))
  143.                     Else
  144.                         Label1.Text = "Writing File To Stub"
  145.                         System.IO.File.AppendAllText(outputfile, sp & Convert.ToBase64String(batchf))
  146.                     End If
  147.                 Catch ex As Exception
  148.                     Label1.Text = "Error !!"
  149.                     MsgBox("Some !Error Occured During Compilation ...?", MsgBoxStyle.Critical, "Error..!!")
  150.                     Exit Sub
  151.                 End Try
  152.                 Label1.Text = "[#] Done..!!"
  153.                 MsgBox("SuccessFully Created", MsgBoxStyle.Information, "Success !")
  154.  
  155.             End If
  156.         End Using
  157.     End Sub
  158.  
  159.     Private Sub TextBox1_Click(sender As Object, e As EventArgs) Handles TextBox1.Click
  160.         Label1.Text = "Status ..."
  161.         Using O As New OpenFileDialog()
  162.             O.Title = "Select Batch File.."
  163.             O.Filter = "Batch File|*.bat"
  164.             If O.ShowDialog = Windows.Forms.DialogResult.OK Then
  165.                 batchpath = O.FileName
  166.                 TextBox1.Text = O.FileName
  167.             End If
  168.         End Using
  169.     End Sub
  170.  
  171.     Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
  172.         If CheckBox1.Checked = True Then
  173.             TextBox2.Enabled = True
  174.         Else
  175.             TextBox2.Enabled = False
  176.         End If
  177.     End Sub
  178.  
  179.     Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
  180.         If CheckBox2.Checked = True Then
  181.             TextBox3.Enabled = True
  182.         Else
  183.             TextBox3.Enabled = False
  184.         End If
  185.     End Sub
  186.  
  187.     Private Function components() As Object
  188.         Throw New NotImplementedException
  189.     End Function
  190.    
  191.     Private Sub TextBox2_Click(sender As Object, e As EventArgs) Handles TextBox2.Click
  192.         Using O As New OpenFileDialog()
  193.             O.Title = "Select Icon File.."
  194.             O.Filter = "Icon File|*.ico"
  195.             If O.ShowDialog = Windows.Forms.DialogResult.OK Then
  196.                 iconpath = O.FileName
  197.                 TextBox2.Text = O.SafeFileName
  198.             End If
  199.         End Using
  200.     End Sub
  201.  
  202.     Private Sub TextBox3_Click(sender As Object, e As EventArgs) Handles TextBox3.Click
  203.         Using O As New OpenFileDialog()
  204.             O.Title = "Select File To Bind.."
  205.             O.Filter = "All Files|*.*"
  206.             If O.ShowDialog = Windows.Forms.DialogResult.OK Then
  207.                 bindfilepath = O.FileName
  208.                 bindfilename = O.SafeFileName
  209.                 TextBox3.Text = O.SafeFileName
  210.             End If
  211.         End Using
  212.     End Sub
  213.  
  214. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement