获取DLL函数的内存地址 [英] Getting The Memory Address Of A DLL Function

查看:684
本文介绍了获取DLL函数的内存地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用C和WindowsAPI,是否有一个函数可以让我获得dll中某个函数的32位(我认为)内存地址.例如.如何在kernel32.dll中获取Beep()的32位$ xxxxxxxx地址.其次,如果我在汇编中使用内存地址而不是函数名,可以避免链接.例如

I want to know if it is possible, using C and the WindowsAPI, if there is a function that will get me the 32 bit(I think) memory address of a function in a dll. For example. How do I get the 32 bit $xxxxxxxx address of Beep() in kernel32.dll. Secondly, if I use the memory address instead of the function name in assembly, can I avoid linking. For example

mov eax, $xxxxxxxx

代替

mov eax, Beep

推荐答案

该程序将在kernel32中打印Beep的地址:

This program will print the address of Beep in kernel32:

#include <windows.h>
#include <stdio.h>

int main(void)
{
    HMODULE hMod = GetModuleHandle("kernel32.dll");
    void* fn = GetProcAddress(hMod, "Beep");
    printf("%p", fn);
}

为简单起见,我省略了错误检查.在真实程序中,您不会这样做.

I omitted error checking for the sake of simplicity. In a real program you would not do so.

这篇关于获取DLL函数的内存地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆