请各大高手帮我将VB6上修改内存数据的代码转成在VB.net可用的

2024-12-04 06:44:25
推荐回答(1个)
回答1:

Imports System.Runtime.InteropServices
Public Class Form1
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As IntPtr, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer
Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer() As Byte, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
Declare Function WriteProcessMemory Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer As IntPtr, ByVal nSize As Integer, ByVal lpNumberOfBytesWritten As Integer) As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim hWnd As Integer
Dim pHandle As Integer
Dim pid As Integer
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const SYNCHRONIZE = &H100000
Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
hWnd = FindWindow(vbNullString, "游戏窗口1")
If hWnd = 0 Then
Label1.Text = " 提示:游戏窗口1未运行"
Label2.Text = " 未开启任何功能"
CheckBox1.Enabled = False
CheckBox2.Enabled = False
CheckBox3.Enabled = False
CheckBox4.Enabled = False
Else
GetWindowThreadProcessId(hWnd, pid)
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
CheckBox1.Enabled = True
CheckBox2.Enabled = True
CheckBox3.Enabled = True
CheckBox4.Enabled = True
Label1.Text = " 提示:游戏窗口1正在运行"
End If
If CheckBox1.Enabled = True Then
CheckBox1.Checked = True
End If
If CheckBox2.Enabled = True Then
CheckBox2.Checked = True
End If
If CheckBox3.Enabled = True Then
CheckBox3.Checked = True
End If
If CheckBox1.Checked = True Then
WriteProcessMemory(pHandle, &H76998C, &H44, 1, 0&)
WriteProcessMemory(pHandle, &H7699A0, &H42, 1, 0&)
Else
WriteProcessMemory(pHandle, &H76998C, &H42, 1, 0&)
WriteProcessMemory(pHandle, &H7699A0, &H44, 1, 0&)
End If
If CheckBox3.Checked = True Then
WriteProcessMemory(pHandle, &H51AEC0, &HC2, 1, 0&)
WriteProcessMemory(pHandle, &H51AEC1, &HC, 1, 0&)
WriteProcessMemory(pHandle, &H51AEC2, &H0, 1, 0&)
WriteProcessMemory(pHandle, &H51AEE0, &HC2, 1, 0&)
WriteProcessMemory(pHandle, &H51AEE1, &H14, 1, 0&)
WriteProcessMemory(pHandle, &H51AEE2, &H0, 1, 0&)
Else
WriteProcessMemory(pHandle, &H51AEC0, &H55, 1, 0&)
WriteProcessMemory(pHandle, &H51AEC1, &H8B, 1, 0&)
WriteProcessMemory(pHandle, &H51AEC2, &HEC, 1, 0&)
WriteProcessMemory(pHandle, &H51AEE0, &H55, 1, 0&)
WriteProcessMemory(pHandle, &H51AEE1, &H8B, 1, 0&)
WriteProcessMemory(pHandle, &H51AEE2, &HEC, 1, 0&)
End If
CloseHandle(pHandle)
If CheckBox1.Checked = True Then
Label2.Text = " Cheat1 开启 Cheat2 开启 Cheat3 开启 "
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Timer1.Start()
End Sub
End Class