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