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)