OS/2 codes: How to get a module name from a symbol

Sometimes it's needed to know the module where a symbol is. For example, it's needed to know the location of a DLL where I am.

To do this, two APIs are required. One is DosQueryModFromEIP() and the other one is DosQueryModuleName().

1. DosQueryModFromEIP()

Here is the description.

Purpose
DosQueryModFromEIP queries a module handle and name from a given flat address. It takes a flat 32 bit address as a parameter and returns information about the module (a protect mode application currently executing) owning the storage.

Syntax
#define INCL_DOSMODULEMGR
#include  os2.h>

APIRET APIENTRY DosQueryModFromEIP
    (HMODULE *phMod, ULONG *pObjNum, ULONG BuffLen, PCHAR pBuff, ULONG *pOffset, ULONG Address)
Parameters
phMod (PHMODULE) output
    Address of a location in which the module handle is returned.
pObjNum (PULONG) output
    Address of a ULONG where the module object number corresponding to the Address is returned. The object is zero based.
BuffLen (ULONG) input
    Length of the user supplied buffer pointed to by pBuff.
pBuff (PCHAR) output
    Address of a user supplied buffer in which the module name is returned.
pOffset (PULONG) output
    Address of a where the offset to the object corresponding to the Address is returned. The offset is zero based.
Address (ULONG) input Input address to be queried.
 * Reference: http://cyberkinetica.homeunix.net/os2tk45/addendum/047_L2_DosQueryModFromEIP.html

DosQueryFromEIP() provides a module name as well as a module handle. However it is a name only. That is, it is not including a path.

2. DosQueryModuleName()

To get a fully-qualified path from a module handle, you should use DosQueryModuleName().

Here is the description.

Returns the fully-qualified drive, path, file name, and extension associated with the referenced module handle.

#define INCL_DOSMODULEMGR
#include <os2.h>

HMODULE    hmod;    /*  The handle of the dynamic link module that is being referenced. */
ULONG      cbName;  /*  The maximum length of the buffer, in bytes, where the name will be stored. */
PCHAR      pch;     /*  The address of the buffer where the file specification of the module are returned. */
APIRET     ulrc;    /*  Return Code. */

ulrc = DosQueryModuleName(hmod, cbName, pch); 

* Reference: http://cyberkinetica.homeunix.net/os2tk45/cp1/1247_L2H_DosQueryModuleNameSy.html

3. Conclusion

If you want to get a fully-qualified path of a module containing a symbol, you should get a module handle by calling DosQueryModFromEIP() first and then get a fully-qualified path of a module handle by calling DosQueryModuleName().

Here is the implementation returning a module handle and a fully-qualified path of a module.


댓글

이 블로그의 인기 게시물

토렌트: < 왕좌의 게임 > 시즌 1 ~ 시즌 8 완결편 마그넷

토렌트: NGC < 코스모스 > 우리말 더빙 전편(1편~13편) 마그넷

토렌트: < 스타워즈 > Ep.1 ~ Ep.6 마그넷