查找DLL在内存中的地址

发布于 2024-07-08 03:51:24 字数 217 浏览 11 评论 0原文

我刚刚进入低级编程(读/写内存之类的事情)并且遇到了一个我找不到答案的问题。

我想要读取的信息有一个与内存中加载的 DLL 相关的地址,例如,它位于 mydll.dll + 0x01234567。 我遇到的问题是 dll 在内存中移动,但偏移量保持不变。 有没有办法找出这个dll在内存中的位置。

我目前正在尝试最好在 C# 中执行此操作,但我将感谢大多数高级语言的帮助。

I have just been getting into low level programming (reading/writing to memory that sort of thing) and have run into an issue i cannot find an answer to.

The piece of information i want to read from has an address that is relative to a DLL loaded in memory e,g, it is at mydll.dll + 0x01234567. the problem im having is that the dll moves around in memory but the offset stays the same. Is there anyway to find out the location of this dll in memory.

I am currently trying to do this preferably in c# but i would be grateful for help in most highish level languages.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

染年凉城似染瑾 2024-07-15 03:51:24

我尝试了 Rob Walker 建议的方法,但无法使其工作(我认为它不起作用,因为该 dll 是作为另一个可执行文件的一部分加载的,因此无法轻易找到它)。

然而,我确实发现了一个对我有用的解决方案,所以这里是:

我创建了一个 Process 类型的对象,

String appToHookTo = "applicationthatloadedthedll";
Process[] foundProcesses = Process.GetProcessesByName(appToHookTo)
ProcessModuleCollection modules = foundProcesses[0].Modules;
ProcessModule dllBaseAdressIWant = null;
foreach (ProcessModule i in modules) {
if (i.ModuleName == "nameofdlliwantbaseadressof") {
                    dllBaseAdressIWant = i;
                }
        }

现在您拥有了模块,您可以执行 dllbaseAdressIWant.BaseAddress 来获取值。

希望这可以帮助

i tried the method Rob Walker suggested and could not get it to work (i think it did not work because the dll was loaded as part of another executable so it could not be found so easily).

I did however discover a solution that worked for me so here it is:

i created an object of type Process

String appToHookTo = "applicationthatloadedthedll";
Process[] foundProcesses = Process.GetProcessesByName(appToHookTo)
ProcessModuleCollection modules = foundProcesses[0].Modules;
ProcessModule dllBaseAdressIWant = null;
foreach (ProcessModule i in modules) {
if (i.ModuleName == "nameofdlliwantbaseadressof") {
                    dllBaseAdressIWant = i;
                }
        }

now you have the module you can just do dllbaseAdressIWant.BaseAddress to get the value.

Hope this helps

空袭的梦i 2024-07-15 03:51:24

从 Win32 角度来看,您需要使用 GetModuleHandleGetModuleInformation 函数。 这些使您可以按名称查找模块句柄,然后检索信息,包括有关该句柄的基地址。

使用标准 P/Invoke 包装器来包装这些 API 应该很简单。

From a Win32 perspective you need to use the GetModuleHandle and GetModuleInformation functions. These let you look the module handle up by name, and then retrieve information, including the base address about that handle.

It should be straight forward to wrap these APIs using the standard P/Invoke wrappers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文