有关API openprocess权限的问题
我读取游戏CS的内存,可以用最高权限读取。但是读取另外一款游戏却不行,(可以返回进程句柄的最高权限是1536,但不可以用readmemory函数读取内存),估计是什么被屏蔽掉了(这里我也不怎么懂)
代码如下(代码没有问题,已经试验过了,求达人指点迷津,另外我用CE修改器就可以载入的啊)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As LongPrivate Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Any, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function RtlAdjustPrivilege& Lib "ntdll" (ByVal Privilege&, ByVal NewValue&, ByVal NewThread&, OldValue&)
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Const PROCESS_VM_OPERATION = (&H8)
Private Const PROCESS_VM_READ = (&H10)
Private Const PROCESS_VM_WRITE = (&H20)
Private Sub Command1_Click()
Dim s As Integer
Dim ihWnd As Long, iPid As Long, hProcess As Long
Dim i As Long
ihWnd = FindWindow("游戏类名", vbNullString)
If ihWnd = 0 Then MsgBox "游戏未启动": Exit Sub
MsgBox "游戏已启动" & vbCrLf
GetWindowThreadProcessId ihWnd, iPid
For i = 0 To 65535 '我想用程序罗列出所有可以读取内存的权限,但是没有。。。。。。
hProcess = OpenProcess(i, 0, iPid)
If hProcess Then
ReadProcessMemory hProcess, &H90D75F8, s, 2, 0&
If s <> 0 Then MsgBox s
CloseHandle hProcess
End If
Next i
End Sub
Private Sub Form_Load()
Call RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE, 1, 0, 0)
End Sub