• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

VB 从零开始编外挂(六)

发布: 2007-6-21 21:57 | 作者:   | 来源:   | 查看: 24次 | 进入软件测试论坛讨论

领测软件测试网

   

--------------------------------------------------------------------------------------------------------------------------------------------------------
应用实战
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要VB API函数:
FindWindow
GetWindowThreadProcessId
OpenProcess
ReadProcessMemory
CloseHandle
--------------------------------------------------------------------------------------------------------------------------------------------------------
相关API声明:
FindWindow

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( ByVal lpClassName As String , ByVal lpWindowName As String ) As Long

GetWindowThreadProcessId

Private Declare Function GetWindowThreadProcessId Lib "user32" ( ByVal hwnd As Long , lpdwProcessId As Long )
As Long

OpenProcess

Private Declare Function OpenProcess Lib "kernel32" ( ByVal dwDesiredAccess As Long , ByVal bInheritHandle As Long , ByVal dwProcessId As Long ) As Long

ReadProcessMemory

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

CloseHandle

Private Declare Function CloseHandle Lib "kernel32" ( ByVal hObject As Long ) As Long

GetCurrentProcess

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要的控件: Label 、 Timer(interval不为空)、Text
--------------------------------------------------------------------------------------------------------------------------------------------------------
定义函数:
Dim SetHp As Integer ' 定义设定的体力值
Dim SetMp As Integer ' 定义设定的魔法值
Dim NowHp As Long ' 定义目前的体力值
Dim NowMp As Long ' 定义目前的魔法值
Dim MaxHp As Long ' 定义角色的最高体力值
Dim MaxMp As Long ' 定义角色的最高魔法值
Dim DiZhi As Long '定义内存地址函数
Dim hwnd As Long ' 储存 FindWindow 函数返回的句柄
--------------------------------------------------------------------------------------------------------------------------------------------------------
代码:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( ByVal lpClassName As String , ByVal lpWindowName As String ) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" ( ByVal hwnd As Long , lpdwProcessId As Long )
As Long
Private Declare Function OpenProcess Lib "kernel32" ( ByVal dwDesiredAccess As Long , ByVal bInheritHandle As Long , ByVal dwProcessId As Long ) As Long
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
Private Declare Function CloseHandle Lib "kernel32" ( ByVal hObject As Long ) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Dim SetHp As Integer ' 定义设定的体力值
Dim SetMp As Integer ' 定义设定的魔法值
Dim NowHp As Long ' 定义目前的体力值
Dim NowMp As Long ' 定义目前的魔法值
Dim MaxHp As Long ' 定义角色的最高体力值
Dim MaxMp As Long ' 定义角色的最高魔法值
Dim DiZhi As Long '定义内存地址函数

Private Function ncnr(lpADDress As Long ) As Integer
' 声明一些需要的变量
Dim hwnd As Long ' 储存 FindWindow 函数返回的句柄
Dim pid As Long ' 储存进程标识符( Process Id )
Dim pHandle As Long ' 储存进程句柄
hwnd = FindWindow(vbNullString, "封神榜·网络版")
' 取得进程标识符
GetWindowThreadProcessId hwnd, pid
' 使用进程标识符取得进程句柄
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
' 在内存地址中读取数据
ReadProcessMemory pHandle, lpADDress, ByVal VarPtr(ncnr), 4, 0&
' 关闭进程句柄
CloseHandle hProcess
End Function
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const SYNCHRONIZE = &H100000
Const SPECIFIC_RIGHTS_ALL = &HFFFF
Const STANDARD_RIGHTS_ALL = &H1F0000
Const PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
Const PROCESS_VM_OPERATION = &H8&
Const PROCESS_VM_READ = &H10&
Const PROCESS_VM_WRITE = &H20&

Private Sub Form_Load()
' 体力:07F68F3 这里替换你所搜索到的地址 魔法:07F6860 同前
DiZhi = &H 07F68F3
Timer1.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
End Sub

Private Sub Timer1_Timer()
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "封神榜·网络版")

If hwnd = 0 Then
Label12.Caption = "游戏未加载"
Timer1.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
Exit Sub
End If

Label12.Caption = "游戏已加载"
SetHp = Text1.Text ' 获取设定的体力值
SetMp = Text2.Text ' 获取设定的魔法值
NowHp = ncnr(DiZhi) ' 获取当前的体力值
NowMp = ncnr(DiZhi + 12) ' 获取当前的魔法值
MaxHp = ncnr(DiZhi + 4) ' 获取角色的最高体力值
MaxMp = ncnr(DiZhi + 16) ' 获取角色的最高魔法值
Label3.Caption = Str(NowHp) + "/" + Str(MaxHp) ' 显示角色体力值状态
Label4.Caption = Str(NowMp) + "/" + Str(MaxMp) ' 显示角色魔法值状态

If Check1.Value Then
Timer2.Enabled = True
Else
Timer2.Enabled = False
End If
If Check2.Value Then
Timer3.Enabled = True
Else
Timer3.Enabled = False
End If
End Sub

Private Sub Timer2_Timer()
' 体力值小于设定值按下数字键1
If (NowHp) < SetHp Then
SendKeys "1"
End If
End Sub

Private Sub Timer3_Timer()
' 魔法值小于设定值按下数字键2
If (NowMp) < SetMp Then
SendKeys "2"
End If
End Sub
--------------------------------------------------------------------------------------------------------------------------------------------------------

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网