#Region " BoxedAppPacker "
' [ BoxedAppPacker Functions ]
'
' // By Elektro H@cker
'
' Instructions:
' 1. Add the "BoxedAppPackerConsole.exe" to the project
' 2. Add the "BoxedAppPacker Class" Class to the project
'
' Examples:
'
' -----------------
' Pack Single File:
' -----------------
' BoxedAppPacker.Pack_Single_File("C:\Windows\Explorer.exe", "C:\Virtual Explorer.exe")
' BoxedAppPacker.Pack_Single_File("C:\Windows\Explorer.exe", "C:\Virtual Explorer.exe", True, True, True, True, True, BoxedAppPacker.BoxedAppPackerVariables.ExeDir)
'
' ---------------------------------
' Pack File And Include More Files:
' ---------------------------------
' BoxedAppPacker.Pack_File_And_Include_More_Files("C:\Windows\Explorer.exe", {"C:\Windows\system32\shell32.dll", "C:\Windows\system32\notepad.exe"}, "C:\Virtual Explorer.exe", True, True, True)
#Region " BoxedAppPacker Class "
Public Class BoxedAppPacker
''' <summary>
''' The BoxedAppPackerConsole.exe location.
''' </summary>
Public Shared BoxedAppPacker_Location As String = ".\BoxedAppPackerConsole.exe"
''' <summary>
''' Boxed App Packer Variables To Override CommandLine.
''' </summary>
Public Enum BoxedAppPackerVariables
ExeDir ' a directory that contains the packed exe.
CurDir ' current directory .
ProgramFiles ' ProgramFiles environment variable.
Temp ' Temp environment variable.
BoxedAppVar_ExeFileName ' exe's file name (for example, "notepad.exe")
BoxedAppVar_ExeFileExtension ' exe's file extension (for example, "exe")
BoxedAppVar_ExeFileNameWithoutExtension ' exe's file name without extension (for example, "notepad")
BoxedAppVar_ExeFullPath ' exe's full path (for example, "C_\notepad.exe")
BoxedAppVar_OldCmdLine ' a command line specified when the packed exe started, you can use it to add additional arguments, for example: <BoxedAppVar:OldCmdLine> /NewSwitch
BoxedAppVar_OldArgs ' a command line specified when the packed exe started without the exe path, for example "<BoxedAppVar:ExeFullPath>" /C virtual.cmd <BoxedAppVar:OldArgs>, Usage: packed.exe Arg1 Arg2, It works as: original.exe /C virtual.cmd Arg1 Arg2
End Enum
''' <summary>
''' Virtualize a single executable.
''' </summary>
Public Shared Function Pack_Single_File
(ByVal File As String,
ByVal OutputFile
As String, _
Optional ByVal Make_All_File_And_Registry_Changes_Virtual As Boolean = True, _
Optional ByVal Hide_Virtual_Files_From_File_Dialog As Boolean = True, _
Optional ByVal Share_Virtual_Environment_With_Child_Processes As Boolean = False, _
Optional ByVal Enable_Virtual_Registry As Boolean = True, _
Optional ByVal Enable_CommandLine_Arguments As Boolean = True, _
Optional ByVal CommandLine_Variable As BoxedAppPackerVariables = BoxedAppPackerVariables.ExeDir
) As Boolean
If Not Check_InputExecutable
(File) Then Return False
Dim CommandLine_Variable_Formatted As String = CommandLine_Variable.ToString.Replace("_", ":")
Dim BoxedProject_Options_Section As String = "<project project_version=""2"" src=""" _
""" dest=""" _
& OutputFile & _
""" cmd_line_overridden=""" _
& Enable_CommandLine_Arguments & _
""" cmd_args=""<" _
& CommandLine_Variable_Formatted & _
">"" share_virtual_environment_with_child_processes=""" _
& Share_Virtual_Environment_With_Child_Processes & _
""" enable_debug_log=""false"" " & _
"enable_virtual_registry=""" _
& Enable_Virtual_Registry & _
""" hide_virtual_files_from_file_dialog=""" _
& Hide_Virtual_Files_From_File_Dialog & _
""" all_changes_are_virtual=""" _
& Make_All_File_And_Registry_Changes_Virtual & """>"
Dim BoxedProject_File_Section As String = <a><![CDATA[
<files>
<file source_path="" name="<ExeDir>" virtual="false" virtually_deleted="false" dir="true" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="" register_as_typelib="false">
<files/>
</file>
<file source_path="" name="<SystemRoot>" virtual="false" virtually_deleted="false" dir="true" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="" register_as_typelib="false">
<files>
<file source_path="" name="System32" virtual="false" virtually_deleted="false" dir="true" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="" register_as_typelib="false">
<files/>
</file>
</files>
</file>
</files>
]]></a>.Value
Dim BoxedProject_Registry_Section As String = <a><![CDATA[
<registry>
<keys>
<key name="HKEY_CLASSES_ROOT" virtual="false" virtually_deleted="false">
<values/>
<keys/>
</key>
<key name="HKEY_CURRENT_CONFIG" virtual="false" virtually_deleted="false">
<values/>
<keys/>
</key>
<key name="HKEY_CURRENT_USER" virtual="false" virtually_deleted="false">
<values/>
<keys/>
</key>
<key name="HKEY_LOCAL_MACHINE" virtual="false" virtually_deleted="false">
<values/>
<keys/>
</key>
<key name="HKEY_USERS" virtual="false" virtually_deleted="false">
<values/>
<keys/>
</key>
</keys>
</registry>
</project>
]]></a>.Value
Try
Using TextFile As New IO.StreamWriter(System.IO.Path.GetTempPath() & "BoxedAppPacker.boxedappproj", False, System.Text.Encoding.ASCII)
TextFile.WriteLine(BoxedProject_Options_Section)
End Using
Using TextFile As New IO.StreamWriter(System.IO.Path.GetTempPath() & "BoxedAppPacker.boxedappproj", True, System.Text.Encoding.ASCII)
TextFile.WriteLine(BoxedProject_File_Section)
TextFile.WriteLine(BoxedProject_Registry_Section)
End Using
Dim BoxedAppPacker_Console As New Process()
Dim BoxedAppPacker_Console_Info As New ProcessStartInfo()
BoxedAppPacker_Console_Info.FileName = BoxedAppPacker_Location
BoxedAppPacker_Console_Info.Arguments = """" & System.IO.Path.GetTempPath() & "BoxedAppPacker.boxedappproj" & """"
BoxedAppPacker_Console_Info.CreateNoWindow = True
BoxedAppPacker_Console_Info.WindowStyle = ProcessWindowStyle.Hidden
BoxedAppPacker_Console_Info.UseShellExecute = False
BoxedAppPacker_Console.StartInfo = BoxedAppPacker_Console_Info
BoxedAppPacker_Console.Start()
BoxedAppPacker_Console.WaitForExit()
If BoxedAppPacker_Console.ExitCode <> 0 Then
Return False
Else
Return True
End If
Catch ex As Exception
' MsgBox(ex.Message)
Return False
End Try
End Function
''' <summary>
''' Virtualize a executable and include more files.
''' </summary>
Public Shared Function Pack_File_And_Include_More_Files
(ByVal File As String,
ByVal SubFiles
() As String,
ByVal OutputFile
As String, _
Optional ByVal Make_All_File_And_Registry_Changes_Virtual As Boolean = True, _
Optional ByVal Hide_Virtual_Files_From_File_Dialog As Boolean = True, _
Optional ByVal Share_Virtual_Environment_With_Child_Processes As Boolean = False, _
Optional ByVal Enable_Virtual_Registry As Boolean = True, _
Optional ByVal Enable_CommandLine_Arguments As Boolean = True, _
Optional ByVal CommandLine_Variable As BoxedAppPackerVariables = BoxedAppPackerVariables.ExeDir
) As Boolean
If Not Check_InputExecutable
(File) Then Return False
Dim CommandLine_Variable_Formatted As String = CommandLine_Variable.ToString.Replace("_", ":")
Dim BoxedProject_Options_Section As String = "<project project_version=""2"" src=""" _
""" dest=""" _
& OutputFile & _
""" cmd_line_overridden=""" _
& Enable_CommandLine_Arguments & _
""" cmd_args=""<" _
& CommandLine_Variable_Formatted & _
">"" share_virtual_environment_with_child_processes=""" _
& Share_Virtual_Environment_With_Child_Processes & _
""" enable_debug_log=""false"" " & _
"enable_virtual_registry=""" _
& Enable_Virtual_Registry & _
""" hide_virtual_files_from_file_dialog=""" _
& Hide_Virtual_Files_From_File_Dialog & _
""" all_changes_are_virtual=""" _
& Make_All_File_And_Registry_Changes_Virtual & """>"
' Generate File Section Start
Dim BoxedProject_File_Section_Start As String = <a><![CDATA[
<files>
<file source_path="" name="<ExeDir>" virtual="false" virtually_deleted="false" dir="true" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="" register_as_typelib="false">
<files>
]]></a>.Value
' Generate SubFiles Tags Section
Dim FileCount As Int16 = 0
Dim SubFile_Tag As String = Nothing
For SubFile As Integer = 1 To SubFiles.Count
Application.DoEvents()
FileCount += 1
If FileCount = 1 Then
SubFile_Tag += <a><![CDATA[
<file source_path="]]></a>.Value & SubFiles(FileCount - 1) & <a><![CDATA[" name="]]></a>.Value & SubFiles(FileCount - 1).Split("\").Last & <a><![CDATA[" virtual="true" virtually_deleted="false" dir="false" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="/RegServer" register_as_typelib="false">
<files/>
]]></a>.Value
Else
SubFile_Tag += <a><![CDATA[
</file>
<file source_path="]]></a>.Value & SubFiles(FileCount - 1) & <a><![CDATA[" name="]]></a>.Value & SubFiles(FileCount - 1).Split("\").Last & <a><![CDATA[" virtual="true" virtually_deleted="false" dir="false" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="/RegServer" register_as_typelib="false">
<files/>
]]></a>.Value
End If
Next
' Generate File Section End
Dim BoxedProject_File_Section_End As String = <a><![CDATA[
</file>
</files>
</file>
<file source_path="" name="<SystemRoot>" virtual="false" virtually_deleted="false" dir="true" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="" register_as_typelib="false">
<files>
<file source_path="" name="System32" virtual="false" virtually_deleted="false" dir="true" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="" register_as_typelib="false">
<files/>
</file>
</files>
</file>
</files>
]]></a>.Value
' Generate Registry Section
Dim BoxedProject_Registry_Section As String = <a><![CDATA[
<registry>
<keys>
<key name="HKEY_CLASSES_ROOT" virtual="false" virtually_deleted="false">
<values/>
<keys/>
</key>
<key name="HKEY_CURRENT_CONFIG" virtual="false" virtually_deleted="false">
<values/>
<keys/>
</key>
<key name="HKEY_CURRENT_USER" virtual="false" virtually_deleted="false">
<values/>
<keys/>
</key>
<key name="HKEY_LOCAL_MACHINE" virtual="false" virtually_deleted="false">
<values/>
<keys/>
</key>
<key name="HKEY_USERS" virtual="false" virtually_deleted="false">
<values/>
<keys/>
</key>
</keys>
</registry>
</project>
]]></a>.Value
Try
Using TextFile As New IO.StreamWriter(System.IO.Path.GetTempPath() & "BoxedAppPacker.boxedappproj", False, System.Text.Encoding.ASCII)
TextFile.WriteLine(BoxedProject_Options_Section)
TextFile.WriteLine(BoxedProject_File_Section_Start)
TextFile.WriteLine(SubFile_Tag)
TextFile.WriteLine(BoxedProject_File_Section_End)
TextFile.WriteLine(BoxedProject_Registry_Section)
End Using
Dim BoxedAppPacker_Console As New Process()
Dim BoxedAppPacker_Console_Info As New ProcessStartInfo()
BoxedAppPacker_Console_Info.FileName = BoxedAppPacker_Location
BoxedAppPacker_Console_Info.Arguments = """" & System.IO.Path.GetTempPath() & "BoxedAppPacker.boxedappproj" & """"
BoxedAppPacker_Console_Info.CreateNoWindow = True
BoxedAppPacker_Console_Info.WindowStyle = ProcessWindowStyle.Hidden
BoxedAppPacker_Console_Info.UseShellExecute = False
BoxedAppPacker_Console.StartInfo = BoxedAppPacker_Console_Info
BoxedAppPacker_Console.Start()
BoxedAppPacker_Console.WaitForExit()
If BoxedAppPacker_Console.ExitCode <> 0 Then
Return False
Else
Return True
End If
Catch ex As Exception
' MsgBox(ex.Message)
Return False
End Try
End Function
' Checks if InputFile exist and also is a executable.
Private Shared Function Check_InputExecutable
(ByVal File As String) As Boolean MsgBox("File don't exist.")
Return False
End If
If Not File.
ToLower.
EndsWith(".exe") Then MsgBox("Not a valid executable file.")
Return False
End If
Return True
End Function
End Class
#End Region
#End Region