LoginSignup
0
0

More than 1 year has passed since last update.

DLL のベースアドレスを確認したい

Posted at

メモ

処理内容

#include <tlhelp32.h>

    do {
        HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetProcessId(GetCurrentProcess()));
        if (hSnapshot == INVALID_HANDLE_VALUE)
            break;

        MODULEENTRY32 me;
        me.dwSize = sizeof(me);
        if (Module32First(hSnapshot, &me))
        {
            do
            {
                if (me.dwSize < ((uint32_t)&(((MODULEENTRY32 *)0)->szModule))) continue;
                if (me.dwSize < ((uint32_t)&(((MODULEENTRY32 *)0)->modBaseAddr))) continue;
                if (me.dwSize < ((uint32_t)&(((MODULEENTRY32 *)0)->modBaseSize))) continue;

                RETAILMSG(1, (L"%08p-%08p: %s\n", me.modBaseAddr, me.modBaseAddr + me.modBaseSize, me.szModule));
            } while ((me.dwSize = sizeof(me)), Module32Next(hSnapshot, &me));
        }
        CloseToolhelp32Snapshot(hSnapshot);
    } while(0);

プロジェクト設定

Linker>Input に toolhelp.lib を追加

FIXME

Module32Next の際に me.dwSize の値が変更されるという記述はない。Module32First の時だけしか意味がないのかも?
その場合ループする必要もなくなる。

3つのメンバーのどれが最小オフセットか調べるのが面倒だったから3回比較してるけど、本当は1回で良い。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0