Option Explicit
Private Declare Function CreateRemoteThread Lib "kernel32" (ByVal hProcess As Long, lpThreadAttributes As Any, ByVal dwStackSize As Long, lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) 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 WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Boolean
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Boolean
Private Declare Function Module32First Lib "kernel32" (ByVal hSnapshot As Long, lpme As MODULEENTRY32) As Boolean
Private Declare Function Module32Next Lib "kernel32" (ByVal hSnapshot As Long, lpme As MODULEENTRY32) As Boolean
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const TH32CS_SNAPPROCESS As Long = &H2
Private Const TH32CS_SNAPALL As Long = &HF
Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
Const MEM_COMMIT As Long = &H1000&
Const PAGE_EXECUTE_READWRITE As Long = &H40
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * 260
End Type
Private Type MODULEENTRY32
dwSize As Long
th32ModuleID As Long
th32ProcessID As Long
GlblcntUsage As Long
ProccntUsage As Long
modBaseAddr As Long
modBaseSize As Long
hModule As Long
szModule As String * 256
szExePath As String * 260
End Type
'当前hprocess,以及当前hprocess的factory.dll的基址
Dim hProcess As Long
Dim modFactory As Long
Private Sub Command1_Click()
Dim Pn As PROCESSENTRY32
Dim sHandle As Long
If Process32First(sHandle, Pn) Then
Do
If InStr(1, Pn.szExeFile, "QQGame.exe", vbTextCompare) > 0 Then
modFactory = GetFactoryBase(Pn.th32ProcessID)
Call CloseMutex(Pn.th32ProcessID)
End If
Loop While Process32Next(sHandle, Pn)
End If
Call CloseHandle(sHandle)
End Sub
Private Function GetFactoryBase(dwProcessId As Long) As Long
Dim Mn As MODULEENTRY32
Dim sHandle As Long
sHandle = CreateToolhelp32Snapshot(TH32CS_SNAPALL, dwProcessId)
Mn.dwSize = Len(Mn)
If Module32First(sHandle, Mn) Then
Do
If InStr(1, Mn.szModule, "Factory.dll", vbTextCompare) > 0 Then
GetFactoryBase = Mn.modBaseAddr
Exit Do
End If
Loop While Module32Next(sHandle, Mn)
End If
Call CloseHandle(sHandle)
End Function
Private Sub CloseMutex(dwProcessId As Long)
Dim MachineCode(24) As Byte
Dim hModule As Long, fnCloseHandle As Long
Dim virtualAdr As Long, offsetAdr As Long, ret As Long
Dim hndAdr As Long
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, dwProcessId)
If hProcess = 0 Then MsgBox "打开进程失败": Exit Sub
hModule = LoadLibrary("kernel32.dll")
If hModule = 0 Then MsgBox "加载模块失败": Exit Sub
fnCloseHandle = GetProcAddress(hModule, "CloseHandle")
If fnCloseHandle = 0 Then MsgBox "查找函数失败": Exit Sub
virtualAdr = VirtualAllocEx(hProcess, ByVal 0, &H1000, MEM_COMMIT, PAGE_EXECUTE_READWRITE)
If virtualAdr = 0 Then MsgBox "内存分配失败": Exit Sub
offsetAdr = fnCloseHandle - (virtualAdr + 16)
hndAdr = GetHandle()
ret = WriteProcessMemory(hProcess, ByVal virtualAdr, MachineCode(0), 25, ByVal 0)
If ret = 0 Then MsgBox "写内存失败": Exit Sub
ret = CreateRemoteThread(hProcess, ByVal 0, 0, ByVal virtualAdr, ByVal 0, 0, ByVal 0)
If ret = 0 Then MsgBox "创建线程失败": Exit Sub
Call CloseHandle(ret)
MsgBox "成功"
End Sub
Private Function GetHandle() As Long
Dim ptr1 As Long, ptr2 As Long
ptr1 = A(A(modFactory + &H97C0&) + &H54&)
ptr2 = ptr1
If A(A(ptr1 + &HC) + 4) <> A(modFactory + &H181BC) Then
ptr1 = A(A(ptr1 + &HC) + 4)
Do
If A(ptr1 + &HC) < &H3001 Then
ptr1 = A(ptr1 + 8)
Else
ptr2 = ptr1
ptr1 = A(ptr1)
End If
Loop Until ptr1 = A(modFactory + &H181BC)
End If
GetHandle = A(A(A(ptr2 + &H10) + &H174) + &H38)
End Function
Private Function A(ByVal address As Long) As Long
Call ReadProcessMemory(hProcess, ByVal address, A, 4, ByVal 0)
End Function
Dim ptr1 As Long, ptr2 As Long, ptr3 As Long
ptr1 = [[0xdc97c0]+0x54]
If [[ptr1+0xc]+4] = [0xdd81bc] Then
ptr2 = ptr1
Else
ptr1 = [[ptr1+0xc]+4]
Do
if [ptr1+0xc] < 0x3001 then
ptr1 = [ptr1+8]
Else
ptr2 = ptr1
ptr1 = [ptr1]
End If
Loop Until ptr1 = [0xdd81bc]
End If