Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


[VB.Net]bat 2 exe filter_list
Author
Message
[VB.Net]bat 2 exe #1
This is my bat2exe converter..but not really convert it..this code will create new *.exe file and write this code in it
Code:
"Module BtE" & vbNewLine & _
        "Sub Main()" & vbNewLine & _
        "If System.IO.File.Exists(System.Environment.GetEnvironmentVariable(" & Chr(34) & "TMP" & Chr(34) & ") & " & Chr(34) & "\cmd.bat" & Chr(34) & ") Then" & vbNewLine & _
        "System.IO.File.Delete(System.Environment.GetEnvironmentVariable(" & Chr(34) & "TMP" & Chr(34) & ") & " & Chr(34) & "\cmd.bat" & Chr(34) & ")" & vbNewLine & _
        "End If" & vbNewLine & _
        "System.IO.File.WriteAllText(System.Environment.GetEnvironmentVariable(" & Chr(34) & "TMP" & Chr(34) & ") & " & Chr(34) & "\cmd.bat" & Chr(34) & ", {BATCH})" & vbNewLine & _
        "System.Diagnostics.Process.Start(System.Environment.GetEnvironmentVariable(" & Chr(34) & "TMP" & Chr(34) & ") & " & Chr(34) & "\cmd.bat" & Chr(34) & ")" & vbNewLine & _
        "End Sub" & vbNewLine & _
        "End Module"

sample:
before convert:click here
after convert:click here

now create new project and add
label1="file:"
label2=leave it empty
button1=convert
button2=browse
textbox1
progressbar1

now add this code:
Code:
Imports System.CodeDom.Compiler
Public Class Form1
    Dim Source As String = _
        "Module BtE" & vbNewLine & _
        "Sub Main()" & vbNewLine & _
        "If System.IO.File.Exists(System.Environment.GetEnvironmentVariable(" & Chr(34) & "TMP" & Chr(34) & ") & " & Chr(34) & "\cmd.bat" & Chr(34) & ") Then" & vbNewLine & _
        "System.IO.File.Delete(System.Environment.GetEnvironmentVariable(" & Chr(34) & "TMP" & Chr(34) & ") & " & Chr(34) & "\cmd.bat" & Chr(34) & ")" & vbNewLine & _
        "End If" & vbNewLine & _
        "System.IO.File.WriteAllText(System.Environment.GetEnvironmentVariable(" & Chr(34) & "TMP" & Chr(34) & ") & " & Chr(34) & "\cmd.bat" & Chr(34) & ", {BATCH})" & vbNewLine & _
        "System.Diagnostics.Process.Start(System.Environment.GetEnvironmentVariable(" & Chr(34) & "TMP" & Chr(34) & ") & " & Chr(34) & "\cmd.bat" & Chr(34) & ")" & vbNewLine & _
        "End Sub" & vbNewLine & _
        "End Module"

    Public Sub GenerateExecutable(ByVal Output As String, ByVal Source As String)
        Try
            Dim Param As New CompilerParameters()
            Dim Res As CompilerResults
            Param.GenerateExecutable = True
            Param.IncludeDebugInformation = False
            Param.CompilerOptions = "/target:winexe /optimize+ /filealign:512"
            Param.OutputAssembly = Output
            Res = New VBCodeProvider(New Dictionary(Of String, String)() From {{"Version", "v2"}}).CompileAssemblyFromSource(Param, Source)
            If Res.Errors.Count <> 0 Then
                For Each [Error] In Res.Errors
                    MessageBox.Show("Error: " & [Error].ErrorText, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Next
            End If
        Catch ex As Exception
            MsgBox("Error: " & ex.ToString)
        End Try
    End Sub
    Function TobString(ByVal b As String)
        Dim ret As String = ""
        For i As Integer = 0 To Split(b, vbNewLine).Count - 1
            Dim line As String = Split(b, vbNewLine)(i).Replace(Chr(34), Chr(34) & " & System.Text.Encoding.ASCII.GetString(New Byte() {34}) & " & Chr(34))
            ret &= Chr(34) & line & Chr(34) & " & System.Environment.NewLine & _" & vbNewLine
        Next
        Return ret.Remove(ret.Length - 6)
    End Function
    Sub ConvertBtE(ByVal Output As String)
        UpdateStatus("Reading from batch file...", 50)
        Dim batch As String = IO.File.ReadAllText(TextBox1.Text)
        UpdateStatus("Preparing executable code...", 0)
        Dim code As String = Source
        UpdateStatus("", 50)
        code = code.Replace("{BATCH}", TobString(batch))
        UpdateStatus("Compiling...", 50)
        GenerateExecutable(Output, code)
        UpdateStatus("Done.", 100)
    End Sub
    Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Click
        Dim ofd As New OpenFileDialog
        ofd.Filter = "Batch Files|*.bat"
        If ofd.ShowDialog <> vbOK Then
            Exit Sub
        End If
        TextBox1.Text = ofd.FileName
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not IO.File.Exists(TextBox1.Text) Then
            MsgBox("Please select a valid batch file!", MsgBoxStyle.Critical, "Error")
            Exit Sub
        End If
        Dim sfd As New SaveFileDialog
        sfd.Filter = "Executables|*.exe"
        If sfd.ShowDialog <> vbOK Then
            Exit Sub
        End If
        Dim tConvert As New Threading.Thread(AddressOf ConvertBtE)
        tConvert.Start(sfd.FileName)
    End Sub

    Delegate Sub delUpdateStatus(ByVal lbl As String, ByVal prgs As Integer)
    Sub UpdateStatus(ByVal lbl As String, ByVal prgs As Integer)
        If InvokeRequired Then
            Invoke(New delUpdateStatus(AddressOf UpdateStatus), New Object() {lbl, prgs})
        Else
            If lbl <> "" Then Label2.Text = lbl
            ProgressBar1.Value = prgs
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim ofd As New OpenFileDialog
        ofd.Filter = "Batch Files|*.bat"
        If ofd.ShowDialog <> vbOK Then
            Exit Sub
        End If
        TextBox1.Text = ofd.FileName
    End Sub
End Class

NOTE:MAYBE NOT WORKING ON VB2008..TESTED ON VSE2012

download here
[Image: Untitaled.png]

Reply

RE: [VB.Net]bat 2 exe #2
No offense, but this is just like every other "batch script to exe" lame trick. Lots of these just write off to %temp% and execute it, thus this isn't actually a batch script to an exe. I criticize all of these converters for this reason, it's the lamest thing ever.

Even a crappy system() call or something in .NET to execute through cmd.exe would be better, and it would also be a legit, batch to exe if that were the case. I would encrypt the strings though, decrypt them, and run them that way in memory. Anything past that is a waste of time if you really cared to "try" to protect a batch script because batch isn't very powerful to begin with. It's mostly used to automate simple tasks. Although unless they were to actually debug the program and/or decrypt the strings, it would still be more secure than direct system() calls with plaintext strings, or a shovel-off to the %temp% for invoking.

Actually, I would say even going through one of these converters to boot, is nearly a waste of time.

Just my few cents...
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: [VB.Net]bat 2 exe #3
Maybe this code can help some beginner(like me)..:lol:
[Image: Untitaled.png]

Reply

RE: [VB.Net]bat 2 exe #4
I can give you a few string encryption functions to try out. Actually you could probably write your own pretty easily also. But if I were to take this thing to another level, that's where I would start, and I would do it all in memory, no dumps. Because no matter what you do in your application, you will still have to dump the batch file out in plaintext anyways.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply







Users browsing this thread: 1 Guest(s)