【原创】VB超强游戏外挂帮助类,封装了很多方法
2018-06-18 04:44:54来源:未知 阅读 ()
''' <summary> ''' a very nice file that can be used on other projects ''' </summary> ''' <remarks></remarks> Module ReadWritingMemory Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer Private Declare Function WriteProcessMemory1 Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer Private Declare Function WriteProcessMemory2 Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Single, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Single Private Declare Function WriteProcessMemory3 Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Long, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Long Private Declare Function ReadProcessMemory1 Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer Private Declare Function ReadProcessMemory2 Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Single, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Single Private Declare Function ReadProcessMemory3 Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Long, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Long Const PROCESS_ALL_ACCESS = &H1F0FF Public Function WriteDMAInteger(ByVal Process As String, ByVal Address As Integer, ByVal Offsets As Integer(), ByVal Value As Integer, ByVal Level As Integer, Optional ByVal nsize As Integer = 4) As Boolean Try Dim lvl As Integer = Address For i As Integer = 1 To Level lvl = ReadInteger(Process, lvl, nsize) + Offsets(i - 1) Next WriteInteger(Process, lvl, Value, nsize) Return True Catch ex As Exception Return False End Try End Function Public Function ReadDMAInteger(ByVal Process As String, ByVal Address As Integer, ByVal Offsets As Integer(), ByVal Level As Integer, Optional ByVal nsize As Integer = 4) As Integer Try Dim lvl As Integer = Address For i As Integer = 1 To Level lvl = ReadInteger(Process, lvl, nsize) + Offsets(i - 1) Next Dim vBuffer As Integer vBuffer = ReadInteger(Process, lvl, nsize) Return vBuffer Catch ex As Exception End Try End Function Public Function WriteDMAFloat(ByVal Process As String, ByVal Address As Integer, ByVal Offsets As Integer(), ByVal Value As Single, ByVal Level As Integer, Optional ByVal nsize As Integer = 4) As Boolean Try Dim lvl As Integer = Address For i As Integer = 1 To Level lvl = ReadInteger(Process, lvl, nsize) + Offsets(i - 1) Next WriteFloat(Process, lvl, Value, nsize) Return True Catch ex As Exception Return False End Try End Function Public Function ReadDMAFloat(ByVal Process As String, ByVal Address As Integer, ByVal Offsets As Integer(), ByVal Level As Integer, Optional ByVal nsize As Integer = 4) As Single Try Dim lvl As Integer = Address For i As Integer = 1 To Level lvl = ReadFloat(Process, lvl, nsize) + Offsets(i - 1) Next Dim vBuffer As Single vBuffer = ReadFloat(Process, lvl, nsize) Return vBuffer Catch ex As Exception End Try End Function Public Function WriteDMALong(ByVal Process As String, ByVal Address As Integer, ByVal Offsets As Integer(), ByVal Value As Long, ByVal Level As Integer, Optional ByVal nsize As Integer = 4) As Boolean Try Dim lvl As Integer = Address For i As Integer = 1 To Level lvl = ReadLong(Process, lvl, nsize) + Offsets(i - 1) Next WriteLong(Process, lvl, Value, nsize) Return True Catch ex As Exception Return False End Try End Function Public Function ReadDMALong(ByVal Process As String, ByVal Address As Integer, ByVal Offsets As Integer(), ByVal Level As Integer, Optional ByVal nsize As Integer = 4) As Long Try Dim lvl As Integer = Address For i As Integer = 1 To Level lvl = ReadLong(Process, lvl, nsize) + Offsets(i - 1) Next Dim vBuffer As Long vBuffer = ReadLong(Process, lvl, nsize) Return vBuffer Catch ex As Exception End Try End Function Public Sub WriteNOPs(ByVal ProcessName As String, ByVal Address As Long, ByVal NOPNum As Integer) Dim C As Integer Dim B As Integer If ProcessName.EndsWith(".exe") Then ProcessName = ProcessName.Replace(".exe", "") End If Dim MyP As Process() = Process.GetProcessesByName(ProcessName) If MyP.Length = 0 Then MessageBox.Show(ProcessName & " isn't open!") Exit Sub End If Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id) If hProcess = IntPtr.Zero Then MessageBox.Show("Failed to open " & ProcessName & "!") Exit Sub End If B = 0 For C = 1 To NOPNum Call WriteProcessMemory1(hProcess, Address + B, &H90, 1, 0&) B = B + 1 Next C End Sub Public Sub WriteXBytes(ByVal ProcessName As String, ByVal Address As Long, ByVal Value As String) If ProcessName.EndsWith(".exe") Then ProcessName = ProcessName.Replace(".exe", "") End If Dim MyP As Process() = Process.GetProcessesByName(ProcessName) If MyP.Length = 0 Then MessageBox.Show(ProcessName & " isn't open!") Exit Sub End If Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id) If hProcess = IntPtr.Zero Then MessageBox.Show("Failed to open " & ProcessName & "!") Exit Sub End If Dim C As Integer Dim B As Integer Dim D As Integer Dim V As Byte B = 0 D = 1 For C = 1 To Math.Round((Len(Value) / 2)) V = Val("&H" & Mid$(Value, D, 2)) Call WriteProcessMemory1(hProcess, Address + B, V, 1, 0&) B = B + 1 D = D + 2 Next C End Sub Public Sub WriteInteger(ByVal ProcessName As String, ByVal Address As Integer, ByVal Value As Integer, Optional ByVal nsize As Integer = 4) If ProcessName.EndsWith(".exe") Then ProcessName = ProcessName.Replace(".exe", "") End If Dim MyP As Process() = Process.GetProcessesByName(ProcessName) If MyP.Length = 0 Then MessageBox.Show(ProcessName & " isn't open!") Exit Sub End If Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id) If hProcess = IntPtr.Zero Then MessageBox.Show("Failed to open " & ProcessName & "!") Exit Sub End If Dim hAddress, vBuffer As Integer hAddress = Address vBuffer = Value WriteProcessMemory1(hProcess, hAddress, CInt(vBuffer), nsize, 0) End Sub Public Sub WriteFloat(ByVal ProcessName As String, ByVal Address As Integer, ByVal Value As Single, Optional ByVal nsize As Integer = 4) If ProcessName.EndsWith(".exe") Then ProcessName = ProcessName.Replace(".exe", "") End If Dim MyP As Process() = Process.GetProcessesByName(ProcessName) If MyP.Length = 0 Then MessageBox.Show(ProcessName & " isn't open!") Exit Sub End If Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id) If hProcess = IntPtr.Zero Then MessageBox.Show("Failed to open " & ProcessName & "!") Exit Sub End If Dim hAddress As Integer Dim vBuffer As Single hAddress = Address vBuffer = Value WriteProcessMemory2(hProcess, hAddress, vBuffer, nsize, 0) End Sub Public Sub WriteLong(ByVal ProcessName As String, ByVal Address As Integer, ByVal Value As Long, Optional ByVal nsize As Integer = 4) If ProcessName.EndsWith(".exe") Then ProcessName = ProcessName.Replace(".exe", "") End If Dim MyP As Process() = Process.GetProcessesByName(ProcessName) If MyP.Length = 0 Then MessageBox.Show(ProcessName & " isn't open!") Exit Sub End If Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id) If hProcess = IntPtr.Zero Then MessageBox.Show("Failed to open " & ProcessName & "!") Exit Sub End If Dim hAddress As Integer Dim vBuffer As Long hAddress = Address vBuffer = Value WriteProcessMemory3(hProcess, hAddress, vBuffer, nsize, 0) End Sub Public Function ReadInteger(ByVal ProcessName As String, ByVal Address As Integer, Optional ByVal nsize As Integer = 4) As Integer If ProcessName.EndsWith(".exe") Then ProcessName = ProcessName.Replace(".exe", "") End If Dim MyP As Process() = Process.GetProcessesByName(ProcessName) If MyP.Length = 0 Then MessageBox.Show(ProcessName & " isn't open!") Exit Function End If Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id) If hProcess = IntPtr.Zero Then MessageBox.Show("Failed to open " & ProcessName & "!") Exit Function End If Dim hAddress, vBuffer As Integer hAddress = Address ReadProcessMemory1(hProcess, hAddress, vBuffer, nsize, 0) Return vBuffer End Function Public Function ReadFloat(ByVal ProcessName As String, ByVal Address As Integer, Optional ByVal nsize As Integer = 4) As Single If ProcessName.EndsWith(".exe") Then ProcessName = ProcessName.Replace(".exe", "") End If Dim MyP As Process() = Process.GetProcessesByName(ProcessName) If MyP.Length = 0 Then MessageBox.Show(ProcessName & " isn't open!") Exit Function End If Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id) If hProcess = IntPtr.Zero Then MessageBox.Show("Failed to open " & ProcessName & "!") Exit Function End If Dim hAddress As Integer Dim vBuffer As Single hAddress = Address ReadProcessMemory2(hProcess, hAddress, vBuffer, nsize, 0) Return vBuffer End Function Public Function ReadLong(ByVal ProcessName As String, ByVal Address As Integer, Optional ByVal nsize As Integer = 4) As Long If ProcessName.EndsWith(".exe") Then ProcessName = ProcessName.Replace(".exe", "") End If Dim MyP As Process() = Process.GetProcessesByName(ProcessName) If MyP.Length = 0 Then MessageBox.Show(ProcessName & " isn't open!") Exit Function End If Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id) If hProcess = IntPtr.Zero Then MessageBox.Show("Failed to open " & ProcessName & "!") Exit Function End If Dim hAddress As Integer Dim vBuffer As Long hAddress = Address ReadProcessMemory3(hProcess, hAddress, vBuffer, nsize, 0) Return vBuffer End Function End Module
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:面向对象基础进阶01
- 原创 Spring Boot 2.3 新特性分层JAR 2020-06-08
- 致程序员的头发:你若安好,便是夙愿原创 2020-05-28
- 原创 记录一次线上Mysql慢查询问题排查过程 2020-03-27
- 【原创】腾讯面试官:线程池要设置多大 2020-03-25
- 【原创】Java并发编程系列2:线程概念与基础操作 2020-03-21
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash