vb 从零开始(六)

vb 从零开始(六)

--------------------------------------------------------------------------------------------------------------------------------------------------------

应用实战

--------------------------------------------------------------------------------------------------------------------------------------------------------

需要vbapi函数:

findwindow

getwindowthreadprocessid

openprocess

readprocessmemory

closehandle

--------------------------------------------------------------------------------------------------------------------------------------------------------

相关api声明:

findwindow

privatedeclarefunctionfindwindowlib"user32"alias"findwindowa"(byvallpclassnamestring,byvallpwindownamestring)long

getwindowthreadprocessid

privatedeclarefunctiongetwindowthreadprocessidlib"user32"(byvalhwndlong,lpdwprocessidlong)

long

openprocess

privatedeclarefunctionopenprocesslib"kernel32"(byvaldwdesiredaccesslong,byvalbinherithandlelong,byvaldwprocessidlong)long

readprocessmemory

privatedeclarefunctionreadprocessmemorylib"kernel32"(byvalhprocesslong,byvallpbaseaddressany,byvallpbufferany,byvalnsizelong,lpnumberofbyteswrittenlong)long

closehandle

privatedeclarefunctionclosehandlelib"kernel32"(byvalhobjectlong)long

getcurrentprocess

privatedeclarefunctiongetcurrentprocesslib"kernel32"long

--------------------------------------------------------------------------------------------------------------------------------------------------------

需要的控件:label、timer(interval不为空)、text

--------------------------------------------------------------------------------------------------------------------------------------------------------

定义函数:

dimsethpinteger'定义设定的体力值

dimsetmpinteger'定义设定的魔法值

dimnowhplong'定义目前的体力值

dimnowmplong'定义目前的魔法值

dimmaxhplong'定义角色的最高体力值

dimmaxmplong'定义角色的最高魔法值

dimdizhilong'定义内存地址函数

dimhwndlong'储存findwindow函数返回的句柄

--------------------------------------------------------------------------------------------------------------------------------------------------------

代码:

privatedeclarefunctionfindwindowlib"user32"alias"findwindowa"(byvallpclassnamestring,byvallpwindownamestring)long

privatedeclarefunctiongetwindowthreadprocessidlib"user32"(byvalhwndlong,lpdwprocessidlong)

long

privatedeclarefunctionopenprocesslib"kernel32"(byvaldwdesiredaccesslong,byvalbinherithandlelong,byvaldwprocessidlong)long

privatedeclarefunctionreadprocessmemorylib"kernel32"(byvalhprocesslong,byvallpbaseaddressany,byvallpbufferany,byvalnsizelong,lpnumberofbyteswrittenlong)long

privatedeclarefunctionclosehandlelib"kernel32"(byvalhobjectlong)long

privatedeclarefunctiongetcurrentprocesslib"kernel32"long

dimsethpinteger'定义设定的体力值

dimsetmpinteger'定义设定的魔法值

dimnowhplong'定义目前的体力值

dimnowmplong'定义目前的魔法值

dimmaxhplong'定义角色的最高体力值

dimmaxmplong'定义角色的最高魔法值

dimdizhilong'定义内存地址函数

privatefunctionncnr(lpaddresslong)integer

'声明一些需要的变量

dimhwndlong'储存findwindow函数返回的句柄

dimpidlong'储存进程标识符(process)

dimphandlelong'储存进程句柄

hwnd=findwindow(vbnullstring,"封神榜·网络版")

'取得进程标识符

getwindowthreadprocessidhwnd,pid

'使用进程标识符取得进程句柄

phandle=openprocess(process_all_access,false,pid)

'在内存地址中读取数据

readprocessmemoryphandle,lpaddress,byvalvarptr(ncnr),4,0&

'关闭进程句柄

closehandlehprocess

endfunction

conststandard_rights_required=&hf0000

constsynchronize=&h100000

constspecific_rights_all=&hffff

conststandard_rights_all=&h1f0000

constprocess_all_access=standard_rights_requiredsynchronize&hfff

constprocess_vm_operation=&h8&

constprocess_vm_read=&h10&

constprocess_vm_write=&h20&

privatesubform_load

'体力:07f68f3这里替换你所搜索到的地址魔法:07f6860同前

dizhi=07f68fbxwx.org=trubxwx.org=falsbxwx.org=false

endsub

privatesubtimer1_timer

dimhwndlong

hwnd=findwindow(vbnullstring,"封神榜·网络版")

hwnd=0thebxwx.org="游戏未加载"

bxwx.org=trubxwx.org=falsbxwx.org=false

exitsub

endibxwx.org="游戏已加载"

sethp=bxwx.org'获取设定的体力值

setmp=bxwx.org'获取设定的魔法值

nowhp=ncnr(dizhi)'获取当前的体力值

nowmp=ncnr(dizhi+12)'获取当前的魔法值

maxhp=ncnr(dizhi+4)'获取角色的最高体力值

maxmp=ncnr(dizhi+16)'获取角色的最高魔法值

bxwx.org=str(nowhp)+"/"+str(maxhp)'显示角色体力值状态

bxwx.org=str(nowmp)+"/"+str(maxmp)'显示角色魔法值状态

bxwx.orgthebxwx.org=true

elsbxwx.org=false

endibxwx.orgthebxwx.org=true

elsbxwx.org=false

end

endsub

privatesubtimer2_timer

'体力值小于设定值按下数字键1

(nowhp)

上一章书籍页下一章

super红客

···
加入書架
上一章
首頁 都市青春 super红客
上一章下一章

vb 从零开始(六)

%