Advertisement
Robomatics

Hacking Program

Apr 12th, 2013
2,802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.30 KB | None | 0 0
  1.  
  2. Imports System.Runtime.InteropServices
  3.  
  4. Public Class Form1
  5.  
  6.     Dim Processz() As Process
  7.     Dim indexlist As New List(Of Long)
  8.     Dim hProcesz As Integer
  9.  
  10.     <StructLayout(LayoutKind.Sequential)> Public Structure MEMORY_BASIC_INFORMATION '64 Bit!
  11.         Dim BaseAddress As IntPtr
  12.         Dim Allocationbase As IntPtr
  13.         Dim allocationprotect As UInt32
  14.         Dim regionsize As IntPtr
  15.         Dim state As UInt32
  16.         Dim protect As UInt32
  17.         Dim ltype As UInt32
  18.     End Structure
  19.     <StructLayout(LayoutKind.Sequential)> Structure SYSTEM_INFO '64 Bit!
  20.         Dim OEMID As Integer
  21.         Dim PageSize As Integer
  22.         Dim MinAppAddress As IntPtr
  23.         Dim MaxAppAddress As IntPtr
  24.         Dim ActiveProcMask As IntPtr
  25.         Dim NumberofProcessors As Integer
  26.         Dim ProcessorType As Integer
  27.         Dim AllocGranularity As Integer
  28.         Dim ProcessorLEvel As Short
  29.         Dim ProcessorReveision As Short
  30.     End Structure
  31.     Enum ProcessAccessFlags As UInteger
  32.         All = &H1F0FFF
  33.         Terminate = &H1
  34.         CreateThread = &H2
  35.         VMOperation = &H8
  36.         VMRead = &H10
  37.         VMWrite = &H20
  38.         DupHandle = &H40
  39.         SetInformation = &H200
  40.         QueryInformation = &H400
  41.         Synchronize = &H100000
  42.     End Enum
  43.  
  44.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  45.         Processz = Process.GetProcesses
  46.         For i = 0 To Processz.Length - 1
  47.             ListBox1.Items.Add(Processz(i).ProcessName)
  48.         Next
  49.     End Sub
  50.  
  51.     Declare Auto Sub GetNativeSystemInfo Lib "Kernel32" (ByRef info As SYSTEM_INFO)
  52.     <DllImport("kernel32.dll")>
  53.     Public Shared Function ReadProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As Byte(), ByVal nSize As UInt32, ByRef lpNumberOfBytesRead As UInt32) As Boolean
  54.     End Function
  55.     <DllImport("kernel32.dll")>
  56.     Public Shared Function WriteProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As Byte(), ByVal nSize As UInt32, ByRef lpNumberOfBytesWritten As UInt32) As Boolean
  57.     End Function
  58.     <DllImport("kernel32.dll")>
  59.     Private Shared Function OpenProcess(ByVal dwDesiredAccess As ProcessAccessFlags, <MarshalAs(UnmanagedType.Bool)> ByVal bInheritHandle As Boolean, ByVal dwProcessId As Integer) As IntPtr
  60.     End Function
  61.     <DllImport("kernel32.dll")>
  62.     Private Shared Function VirtualQueryEx(ByVal hprocess As IntPtr, ByVal lpaddress As IntPtr, ByRef lpbuffer As MEMORY_BASIC_INFORMATION, ByVal dwlength As Long) As Long
  63.     End Function
  64.  
  65.     Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
  66.  
  67.         hProcesz = OpenProcess(ProcessAccessFlags.All, False, Processz(ListBox1.SelectedIndex).Id)
  68.  
  69.         Dim bytesread As UInteger = 0
  70.         Dim success As Boolean
  71.         Dim data As New List(Of Byte)
  72.         Dim indexs As New List(Of Long)
  73.         Dim address As Long
  74.         Dim sysinfo As SYSTEM_INFO
  75.         Dim meminfo As MEMORY_BASIC_INFORMATION
  76.         Dim tempint As Integer = NumericUpDown1.Value
  77.  
  78.         GetNativeSystemInfo(sysinfo)
  79.         address = sysinfo.MinAppAddress
  80.         Do While address < 2147483647 '7FFFFFFF because 7FFFFFFF
  81.             If VirtualQueryEx(hProcesz, address, meminfo, Marshal.SizeOf(meminfo)) <> 0 Then
  82.                 If (meminfo.ltype = 131072 Or meminfo.ltype = 16777216) And (meminfo.state = 4096 Or meminfo.state = 8192) Then
  83.                     'Only a type of Private(131072) or Image(16777216) and only state of Commit(4096) and Reserve(8192) wanted.
  84.  
  85.                     Dim bytez() As Byte = New Byte(meminfo.regionsize) {}
  86.  
  87.                     success = ReadProcessMemory(hProcesz, meminfo.BaseAddress, bytez, meminfo.regionsize, bytesread)
  88.  
  89.                     'minappaddress > Memory areas
  90.                     'Memory() > bytez
  91.  
  92.                     If success = True Then
  93.                         For i = 0 To bytez.Length - 1
  94.                             If bytez(i) = tempint Then
  95.                                 data.Add(bytez(i))
  96.                                 indexs.Add(meminfo.BaseAddress + i)
  97.  
  98.                             End If
  99.                         Next
  100.                     End If
  101.                 End If
  102.             End If
  103.  
  104.             address = address + meminfo.regionsize
  105.  
  106.             If data.Count > 2000000 Then 'Make sure it doesn't go nuts.
  107.                 Exit Do
  108.             End If
  109.  
  110.         Loop
  111.  
  112.         indexlist.Clear()
  113.         For i = 0 To data.Count - 1
  114.             indexlist.Add(indexs(i))
  115.         Next
  116.  
  117.         Label1.Text = "Length: " & data.Count & " Found: " & indexlist.Count
  118.  
  119.     End Sub
  120.  
  121.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  122.  
  123.         Dim bytesread As UInteger = 0
  124.         Dim success As Boolean
  125.         Dim data As New List(Of Byte)
  126.         Dim newdata As New List(Of Byte)
  127.         Dim indexs As New List(Of Long)
  128.         Dim tempint As Integer = NumericUpDown1.Value
  129.         Dim bytez() As Byte = New Byte(1) {}
  130.  
  131.         For i = 0 To indexlist.Count - 1
  132.             success = ReadProcessMemory(hProcesz, indexlist(i), bytez, 1, bytesread)
  133.             data.Add(bytez(0))
  134.             indexs.Add(indexlist(i))
  135.         Next
  136.  
  137.         indexlist.Clear()
  138.         For i = 0 To indexs.Count - 1
  139.             If data(i) = tempint Then
  140.                 newdata.Add(data(i))
  141.                 indexlist.Add(indexs(i))
  142.             End If
  143.         Next
  144.  
  145.         Dim maxshow As Integer = 100
  146.         If indexlist.Count < 100 Then
  147.             maxshow = indexlist.Count
  148.         End If
  149.         RichTextBox1.Text = ""
  150.         For i = 0 To maxshow - 1
  151.             RichTextBox1.AppendText(indexlist(i) & ": " & newdata(i) & Chr(13))
  152.         Next
  153.         Label1.Text = "Length: " & indexlist.Count
  154.  
  155.     End Sub
  156.  
  157.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  158.  
  159.         Dim success As Boolean
  160.         Dim bytez(0) As Byte
  161.         Dim tempint As Byte = NumericUpDown1.Value
  162.         bytez(0) = tempint
  163.         Dim byteswrote As Integer
  164.         success = WriteProcessMemory(hProcesz, indexlist(0), bytez, bytez.Length, byteswrote)
  165.  
  166.     End Sub
  167. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement