运行时可加载内核模块如何知道核心内核函数的地址?
我对 Linux 和 NT(或任何其他相关问题)的答案感兴趣
编辑:
感谢 Laurion 的回答。
更多信息请参见:
I would be interested in answers for both Linux and NT (or any other for that matter)
Edit:
Thanks Laurion for the answer.
More information here:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
运行时加载器通常会在加载模块时修复对导入函数的引用。它查看导入函数表并输入正确的地址。该模块通过间接表使用导入的函数。
The runtime loader normally fixes up references to imported functions when the module is loaded. It looks at the table of imported functions and puts in the proper address. The module uses the imported functions through an indirection table.
之前为 Windows 内核(和 Windows 用户空间)编写过加载程序:它的工作方式相同。基本上所有二进制文件都有称为 IAT 的东西(例如 http://msdn.microsoft.com /en-us/magazine/cc301808.aspx这是永恒的经典论文)。当加载程序为DLL分配内存时,它会将DLL复制到那里,并读取DLL的IAT以获取它需要的所有符号(按名称),然后在Windows核心DLL的导出部分中查找名称(例如,kernel32.dll),并用读取的地址填充它。在 DLL 可以继续执行之前,必须读取所有需要的文件并填充地址。
Linux 也以同样的方式工作......无论是用户空间还是内核。 ELF结构称为重定位表。
http://www.bravegnu.org/gnu-eprog/linker.html
希望有所帮助:-)(x86 arch 的详细信息类似)。
Having written a loader for both windows kernel (and windows userspace) before: it works the same way. essentially all binaries have something called IAT (eg, http://msdn.microsoft.com/en-us/magazine/cc301808.aspx this is the eternal classic paper). When the loader allocated memory for the DLL it will copy the DLL there, and read the IAT of the DLL for all the symbols that it needs (by name), and then lookup the names in the export section of the Windows core DLL (eg, kernel32.dll), and fill it up with the address read. all the needed files will have to be read and address fillup, before the DLL can continue execution.
Linux works the same way too.....be it userspace or kernel. ELF structure call it relocation table.
http://www.bravegnu.org/gnu-eprog/linker.html
Hope that help :-) (the details are similar for x86 arch).