BATCH To EXE Converter Softwere written in VB.net with Source code

This little program will convert a Batch Script file into an Executable file.




This Program's features are :


  • File Binder 
  • Icon Changer 
  • CodeDom Compiler 
  • Run Script in Background 
  • Base64 Encoding

Download Bat2Exe Converter From here 

For Windows 7 [ Compiled with dotnetframework 2.0]
For Windows 8 [ Compiled with dotnetframework 4.0 ]

Project Files   :
This program does not work on windows xp

How To Use Video : 




Source Code are here :

Form Code



1:  '  Bat2exe converter   
2:  '
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  
215:    



Stub Code


1:  '  Bat2exe converter Stub Code  
2:  ' 
3:  '  http://sec-articles.blogspot.com  
4:    
5:  Imports System  
6:  Imports System.IO  
7:  Imports System.AppDomain  
8:  Imports System.Diagnostics  
9:  Imports Microsoft.VisualBasic  
10:    
11:  Module Module1  
12:    
13:    Private Declare Auto Function GetConsoleWindow Lib "kernel32.dll" () As IntPtr  
14:    Private Declare Auto Function ShowWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean  
15:    
16:    Private Const SW_HIDE As Integer = 0  
17:    Private Const SW_SHOW As Integer = 5  
18:    
19:    Sub Main()  
20:      Dim hiddenmode As Boolean = False  
21:      Dim hWndConsole As Integer  
22:      hWndConsole = GetConsoleWindow()  
23:      ShowWindow(hWndConsole, SW_HIDE)  
24:        
25:      Try  
26:        Dim exepath As String = AppDomain.CurrentDomain.BaseDirectory + Process.GetCurrentProcess.ProcessName + ".exe"  
27:        Dim tempdir As String = My.Computer.FileSystem.SpecialDirectories.Temp  
28:        'For exe path  
29:        Dim SP() As String = Split(System.IO.File.ReadAllText(exepath), "[SPLITTING_POINT]")  
30:        Dim batchf As Byte() = unsecure(Convert.FromBase64String(SP(1)))  
31:        '[BDPROC]Dim bindedf As Byte() = unsecure(Convert.FromBase64String(SP(3)))  
32:        My.Computer.FileSystem.WriteAllBytes(tempdir & "\cmd.bat", batchf, False)  
33:        '[BDPROC]My.Computer.FileSystem.WriteAllBytes(tempdir & "\" & SP(2), bindedf, False)  
34:        If hiddenmode = True Then  
35:          Dim vbwriter As New IO.StreamWriter(tempdir + "\" + "start.vbs")  
36:          vbwriter.WriteLine("set objShell = CreateObject(""WScript.Shell"")")  
37:          vbwriter.WriteLine("objShell.Run """ + tempdir + "\cmd.bat"", vbHide, TRUE")  
38:          vbwriter.Close()  
39:    
40:          ' run program  
41:          Dim ps As ProcessStartInfo  
42:          Dim psname As String = (tempdir & "\" & "start.vbs")  
43:          ps = New ProcessStartInfo(psname)  
44:          Dim proc As New Process()  
45:          proc.StartInfo = ps  
46:          proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden  
47:          proc.Start()  
48:          proc.WaitForExit()  
49:          File.Delete(psname)  
50:          File.Delete(tempdir & "\" & "cmd.bat")  
51:        Else  
52:          Dim ps As ProcessStartInfo  
53:          Dim psname As String = (tempdir & "\" & "cmd.bat")  
54:          ps = New ProcessStartInfo(psname)  
55:          Dim proc As New Process()  
56:          proc.StartInfo = ps  
57:          proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal  
58:          proc.Start()  
59:          proc.WaitForExit()  
60:          File.Delete(psname)  
61:        End If  
62:        '[BDPROC]Process.Start(tempdir & "\" & SP(2))  
63:      Catch ex As Exception  
64:        Process.GetCurrentProcess.Kill()  
65:      End Try  
66:      Process.GetCurrentProcess.Kill()  
67:    
68:    End Sub  
69:    
70:    Function unsecure(ByVal data As Byte()) As Byte()  
71:      Using SA As New System.Security.Cryptography.RijndaelManaged  
72:        SA.IV = New Byte() {1, 9, 2, 8, 3, 7, 4, 5, 6, 0, 1, 4, 3, 0, 0, 7}  
73:        SA.Key = New Byte() {7, 0, 0, 3, 4, 1, 0, 6, 5, 4, 7, 3, 8, 2, 9, 1}  
74:        Return SA.CreateDecryptor.TransformFinalBlock(data, 0, data.Length)  
75:      End Using  
76:    End Function  
77:    
78:  End Module  
79:    
80:    


Download Codes :

Bat2exe (Form Source Code) :

Bat2exe (Stub Source Code)  :