- UID
- 66114
注册时间2010-4-1
阅读权限30
最后登录1970-1-1
龙战于野
TA的每日心情 | 慵懒 2019-3-12 17:25 |
---|
签到天数: 3 天 [LV.2]偶尔看看I
|
楼主 |
发表于 2010-7-15 22:31:54
|
显示全部楼层
If dwFunAddress Then
CopyMemory ByVal VarPtr(gbytDllFunCallOldCode(0)), ByVal dwFunAddress, 6
glpdwDllFunCallProxyAddress = VirtualAlloc(ByVal 0&, &H1000, MEM_COMMIT, PAGE_EXECUTE_READWRITE)
If glpdwDllFunCallProxyAddress Then
CopyMemory ByVal glpdwDllFunCallProxyAddress + &H200, ByVal dwFunAddress, 6
bytValue = &HB8
CopyMemory ByVal glpdwDllFunCallProxyAddress + &H200 + 6, ByVal VarPtr(bytValue), 1 'mov eax,DllFunctionCall
dwValue = dwFunAddress
CopyMemory ByVal glpdwDllFunCallProxyAddress + &H200 + 7, ByVal VarPtr(dwValue), 4
wValue = &HC083
CopyMemory ByVal glpdwDllFunCallProxyAddress + &H200 + 11, ByVal VarPtr(wValue), 2 'add eax,5
bytValue = &H6
CopyMemory ByVal glpdwDllFunCallProxyAddress + &H200 + 13, ByVal VarPtr(bytValue), 1
wValue = &HE0FF
CopyMemory ByVal glpdwDllFunCallProxyAddress + &H200 + 14, ByVal VarPtr(wValue), 2 'jmp eax
dwValue = glpdwDllFunCallProxyAddress + &H200
CopyMemory ByVal VarPtr(ShellCode(&H83)), ByVal VarPtr(dwValue), 4
wValue = &HD0FF
CopyMemory ByVal VarPtr(ShellCode(&H87)), ByVal VarPtr(wValue), 2
wValue = &H4589
CopyMemory ByVal VarPtr(ShellCode(&H89)), ByVal VarPtr(wValue), 2
wValue = &H458B
ShellCode(&H8B) = &HF8
CopyMemory ByVal VarPtr(ShellCode(&H8C)), ByVal VarPtr(wValue), 2
ShellCode(&H8E) = &HF8
ShellCode(&H8F) = &H5F
ShellCode(&H90) = &H5E
ShellCode(&H91) = &H5B
wValue = &HE58B
CopyMemory ByVal VarPtr(ShellCode(&H92)), ByVal VarPtr(wValue), 2
ShellCode(&H94) = &H5D
wValue = &H4C2
CopyMemory ByVal VarPtr(ShellCode(&H95)), ByVal VarPtr(wValue), 2
ShellCode(&H97) = &H0
CopyMemory ByVal glpdwDllFunCallProxyAddress, ByVal VarPtr(ShellCode(0)), &H98
MsgBox Hex(glpdwDllFunCallProxyAddress)
bytHookCode(0) = &HE9
dwValue = glpdwDllFunCallProxyAddress - dwFunAddress - 5
CopyMemory ByVal VarPtr(bytHookCode(1)), ByVal VarPtr(dwValue), 4 '构造hook Code
VirtualProtect ByVal dwFunAddress, 6, PAGE_EXECUTE_READWRITE, OldProtect '更改函数地址所在页面属性
CopyMemory ByVal dwFunAddress, ByVal VarPtr(bytHookCode(0)), 5 'hook
VirtualProtect ByVal dwFunAddress, 6, OldProtect, OldProtect '更改函数地址所在页面属性
HookDllFunctionCall = True
End If
End If
End Function
Public Sub UnhookDllFunctionCall()
Dim dwFunAddress As Long
Dim OldProtect As Long
dwFunAddress = GetProcAddress(GetModuleHandle("msvbvm60.dll"), "DllFunctionCall")
If dwFunAddress Then
If glpdwDllFunCallProxyAddress Then
VirtualProtect ByVal dwFunAddress, 6, PAGE_EXECUTE_READWRITE, OldProtect '更改函数地址所在页面属性
CopyMemory ByVal dwFunAddress, ByVal VarPtr(gbytDllFunCallOldCode(0)), 6 'hook
VirtualProtect ByVal dwFunAddress, 6, OldProtect, OldProtect '更改函数地址所在页面属性
Sleep 100
VirtualFree ByVal glpdwDllFunCallProxyAddress, 0, MEM_RELEASE
End If
End If
If glpdwFunAddresses Then
VirtualFree ByVal glpdwFunAddresses, 0, MEM_RELEASE
End If
If glpdwFunNames Then
VirtualFree ByVal glpdwFunNames, 0, MEM_RELEASE
End If
End Sub
下面是VB下的“函数指针”的一个应用
'***************************************************************************************
'参数说明
'lpszLibName 需要hook的函数所在动态库名称
'lpszFunName 需要Hook的函数名
'lpdwFunCallback 跳转函数(处理)的地址,使用AddressOf获取
'lpdwFunAddressPtr 这个参数和上面Hook的DllFunctionCall维护匹配的表
'有关系的。如果同时需要hook多个函数的话,就需要维护这张表了
'名称和代理函数地址成对称存在,各自起始地址是glpdwFunAddresses和glpdwFunNames
'其中glpdwFunAddresses以4为单位增长,glpdwFunNames以128个字节为单位增长,也就说明
'需要Hook的函数名称长度不能长过127个字节glpdwFunAddresses存放的是每个hook函数的一个
'代理函数地址,这个地址是由HookApi函数内部生成并且管理,请保证glpdwFunNames和glpdwFunAddresses
'对应,打个比方你现在准备hook两个函数。其中一是:DeleteFileA另一个是DeleteFileW,那么你就应该按
'下面的方法来的来调用函数过程
'1,Call HookApi("kernel32.dll", "DeleteFileA", AddressOf DeleteFileACallback, glpdwFunAddresses,glpdwFunNames) 'Hook DeleteFileA
'2,Call HookApi("kernel32.dll", "DeleteFileW", AddressOf DeleteFileWCallback, glpdwFunAddresses+4,glpdwFunNames+128) 'Hook DeleteFileW
Public Function HookApi(ByVal lpszLibName As String, _
ByVal lpszFunName As String, _
ByVal lpdwFunCallback As Long, _
ByVal lpdwFunAddressPtr As Long, _
ByVal lpdwFunNamePtr As Long _
) As Boolean |
|