为了账号安全,请及时绑定邮箱和手机立即绑定

用VB调用API函数OpenProcess的返回值是不固定的吗?

用VB调用API函数OpenProcess的返回值是不固定的吗?

炎炎设计 2018-12-06 14:23:48
我是学C#的,并且是自己学着玩不是很精通,在网上看了一个写外挂的文章,我自己试着写了一个 可就是读不出来数据?!!  并且发现 OpenProcess的返回值总是在变化??!!OpenProcess 返回值不是一个进程的句柄吗?进程句柄对于同一个程序来说应该是固定的吧?我的这个这么会总变化呢? 并且读出来的数据总是0!      (为了使问题简单一些,我自己写了个模拟游戏,用的是Visual Basic 6.0精简版)代码和现在地址如下:http://d.namipan.com/d/9cf212f12c8497fa18102a7dccf7a29a61a41c67a7120000    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate 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 LongPrivate Const PROCESS_ALL_ACCESS = &H1F0FFF '全权打开进程Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long'Dim rea As LongPrivate Sub Timer1_Timer()'Dim fw, pid, openp, readPM As LongDim fw As LongDim pid As LongDim ope As LongDim rea As Longfw = FindWindow(vbNullString, "一个模拟游戏")If fw = 0 ThenLabel3.BackColor = RGB(255, 0, 0)Label3.Caption = "FindWindow失败"ElseLabel3.Caption = "FindWindow成功!" & fwEnd IfGetWindowThreadProcessId fw, pid '返回程序进程IDIf pid = 0 ThenLabel4.BackColor = RGB(255, 0, 0)Label4.Caption = "pid失败"ElseLabel4.Caption = "pid成功!" & pidEnd Ifope = OpenProcess(PROCESS_ALL_ACCESS, False, pid)If ope = 0 ThenLabel5.BackColor = RGB(255, 0, 0)Label5.Caption = "ope失败"ElseLabel5.Caption = "ope成功!" & opeEnd If'ReadProcessMemory 进程, ByVal 地址, 输出值, 字节, 0&ReadProcessMemory ope, ByVal &H14FD74, rea, 4, 0&       '&h表示是16进制的数'蓝  0014FD7C'红 0014FD74Label1.Caption = "w" & reaEnd Sub
查看完整描述

1 回答

?
回首忆惘然

TA贡献1847条经验 获得超11个赞

ReadProcessMemory 和 WriteProcessMemory 中的参数 ByVal lpBuffer As Any 改写为 ByRef lpBuffer As Any

查看完整回答
反对 回复 2019-01-21
  • 1 回答
  • 0 关注
  • 578 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信