都是很成熟的东西了,这几天看了看,总结一下而已。
讨论了Windows下hook函数的几种方法。提供了一个hook TextOutA的完整例子。通过CreateRemoteThread的方法把hook dll注入到一个普通的应用程序中。
Hooking Imported Functions by name
调用imported functions时的步骤/实现
在程序中调用从其它模块引入的函数的方法和普通的函数调用有所不同。对于普通的函数调用,直接使用call address来调用即可,但是对于imported functions,在编译的时候compiler/link并不知道实际的函数实现会被加载到那个地址,函数实现在那个地址在运行的时候才会确定。对于imported functions,首先是call 引入表中的一个函数,在运行时再初始化引入表,使用jmp跳转到真实的函数实现。
引入表:
The PE file IMAGE_IMPORT_DESCRIPTOR structure, which holds all the information about functions imported from a specific DLL, has pointers to two arrays in the executable. These arrays are called import address tables (IATs), or sometimes thunk data arrays. The first pointer references the real IAT, which the program loader fixes up when the executable is loaded. The second pointer references the original IAT, which is untouched by the loader and lists the imported functions.
实现原理