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.
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.
* 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.
To do this, two APIs are required. One is DosQueryModFromEIP() and the other one is DosQueryModuleName().
1. DosQueryModFromEIP()
Here is the description.
Purpose* Reference: http://cyberkinetica.homeunix.net/os2tk45/addendum/047_L2_DosQueryModFromEIP.html
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.
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.
- source: https://github.com/komh/os2codes/blob/master/misc/getmodulename.c
- header: https://github.com/komh/os2codes/blob/master/misc/getmodulename.h
- test: https://github.com/komh/os2codes/blob/master/misc/getmodulename-test.c
댓글
댓글 쓰기