VB 读取《武林外传》角色名的源码

心中要有一片海 2011-03-09

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

PrivateDeclareFunctionFindWindowLib"user32"Alias"FindWindowA"(ByVallpClassNameAsString,ByVallpWindowNameAsString)AsLong

PrivateDeclareFunctionOpenProcessLib"kernel32"(ByValdwDesiredAccessAsLong,ByValbInheritHandleAsLong,ByValdwProcessIdAsLong)AsLong

PrivateDeclareFunctionReadProcessMemoryLib"kernel32"(ByValhProcessAsLong,lpBaseAddressAsAny,lpBufferAsAny,ByValnSizeAsLong,lpNumberOfBytesWrittenAsLong)AsLong

PrivateDeclareFunctionCloseHandleLib"kernel32"(ByValhObjectAsLong)AsLong

ConstSTANDARD_RIGHTS_REQUIRED=&HF0000

ConstSYNCHRONIZE=&H100000

ConstPROCESS_ALL_ACCESS=(STANDARD_RIGHTS_REQUIREDorSYNCHRONIZEor&HFFF)

PrivateSubForm_Load()

DimhWndAsLong

DimpidAsLong

DimhProcessAsLong

DimhAsLong

DimaddrAsLong

Dimbuffer(31)AsByte

hWnd=FindWindow(vbNullString,"ElementClient")

IfhWndThen

GetWindowThreadProcessIdhWnd,pid

hProcess=OpenProcess(PROCESS_ALL_ACCESS,False,pid)

IfhProcessThen

addr=&H12F82C

ReadProcessMemoryhProcess,ByValaddr,h,4,0&

ReadProcessMemoryhProcess,ByVal(h+&H24),h,4,0&

ReadProcessMemoryhProcess,ByVal(h+&H390),h,4,0&

ReadProcessMemoryhProcess,ByValh,buffer(0),32,0&

CloseHandlehProcess

EndIf

Text1.Text=buffer

EndIf

End Sub

结束

读角色名时并没有先读取长度,因为本身就是0结尾U串,没必要。

结果也证明是对的。

如果有朋友老是出现无法读值的问题,一般来说是你搞错了传值传址的问题。

相关推荐

TiDBPingCAP / 0评论 2020-07-29