首页 > 开发 > 综合 > 正文

VB 从零开始编外挂(六)

2024-07-21 02:20:40
字体:
来源:转载
供稿:网友

应用实战
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要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 = &h07f68f3
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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表