Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

366 lines
8.0 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. modimage.h
  5. Abstract:
  6. Implements a set of routines for examining EXE modules
  7. Author:
  8. Calin Negreanu (calinn) 27-Nov-1997
  9. Revision History:
  10. calinn 08-Mar-2000 Moved over from Win9xUpg project.
  11. --*/
  12. #pragma once
  13. //
  14. // Includes
  15. //
  16. // None
  17. //
  18. // Debug constants
  19. //
  20. // None
  21. //
  22. // Strings
  23. //
  24. // None
  25. //
  26. // Constants
  27. //
  28. #define MODULETYPE_UNKNOWN 0x00000000
  29. #define MODULETYPE_DOS 0x00000001
  30. #define MODULETYPE_WIN16 0x00000002
  31. #define MODULETYPE_WIN32 0x00000003
  32. //
  33. // Macros
  34. //
  35. // None
  36. //
  37. // Types
  38. //
  39. typedef struct _MD_IMPORT_ENUM16 {
  40. CHAR ImportModule[MAX_MBCHAR_PATH];
  41. CHAR ImportFunction[MAX_MBCHAR_PATH];
  42. ULONG ImportFunctionOrd;
  43. PVOID Handle;
  44. } MD_IMPORT_ENUM16A, *PMD_IMPORT_ENUM16A;
  45. typedef struct _MD_IMPORT_ENUM32 {
  46. PCSTR ImportModule;
  47. PCSTR ImportFunction;
  48. ULONG ImportFunctionOrd;
  49. PVOID Handle;
  50. } MD_IMPORT_ENUM32A, *PMD_IMPORT_ENUM32A;
  51. typedef struct _MD_MODULE_IMAGE {
  52. UINT ModuleType;
  53. union {
  54. struct {
  55. LOADED_IMAGE Image;
  56. } W32Data;
  57. struct {
  58. PBYTE Image;
  59. HANDLE FileHandle;
  60. HANDLE MapHandle;
  61. } W16Data;
  62. } ModuleData;
  63. } MD_MODULE_IMAGE, *PMD_MODULE_IMAGE;
  64. //
  65. // Globals
  66. //
  67. // None
  68. //
  69. // Macro expansion list
  70. //
  71. // None
  72. //
  73. // Function prototypes
  74. //
  75. BOOL
  76. MdLoadModuleDataA (
  77. IN PCSTR ModuleName,
  78. OUT PMD_MODULE_IMAGE ModuleImage
  79. );
  80. BOOL
  81. MdLoadModuleDataW (
  82. IN PCWSTR ModuleName,
  83. OUT PMD_MODULE_IMAGE ModuleImage
  84. );
  85. BOOL
  86. MdUnloadModuleDataA (
  87. IN OUT PMD_MODULE_IMAGE ModuleImage
  88. );
  89. BOOL
  90. MdUnloadModuleDataW (
  91. IN OUT PMD_MODULE_IMAGE ModuleImage
  92. );
  93. BOOL
  94. MdEnumFirstImport16A (
  95. IN PBYTE ModuleImage,
  96. IN OUT PMD_IMPORT_ENUM16A ImportsEnum
  97. );
  98. BOOL
  99. MdEnumNextImport16A (
  100. IN OUT PMD_IMPORT_ENUM16A ImportsEnum
  101. );
  102. BOOL
  103. MdAbortImport16EnumA (
  104. IN PMD_IMPORT_ENUM16A ImportsEnum
  105. );
  106. BOOL
  107. MdEnumFirstImportModule32A (
  108. IN PLOADED_IMAGE ModuleImage,
  109. IN OUT PMD_IMPORT_ENUM32A ImportsEnum
  110. );
  111. BOOL
  112. MdEnumNextImportModule32A (
  113. IN OUT PMD_IMPORT_ENUM32A ImportsEnum
  114. );
  115. BOOL
  116. MdEnumFirstImportFunction32A (
  117. IN OUT PMD_IMPORT_ENUM32A ImportsEnum
  118. );
  119. BOOL
  120. MdEnumNextImportFunction32A (
  121. IN OUT PMD_IMPORT_ENUM32A ImportsEnum
  122. );
  123. BOOL
  124. MdAbortImport32EnumA (
  125. IN PMD_IMPORT_ENUM32A ImportsEnum
  126. );
  127. DWORD
  128. MdGetModuleTypeA (
  129. IN PCSTR ModuleName
  130. );
  131. DWORD
  132. MdGetModuleTypeW (
  133. IN PCWSTR ModuleName
  134. );
  135. PCSTR
  136. MdGet16ModuleDescriptionA (
  137. IN PCSTR ModuleName
  138. );
  139. PCWSTR
  140. MdGet16ModuleDescriptionW (
  141. IN PCWSTR ModuleName
  142. );
  143. ULONG
  144. MdGetPECheckSumA (
  145. IN PCSTR ModuleName
  146. );
  147. DWORD
  148. MdGetCheckSumA (
  149. IN PCSTR ModuleName
  150. );
  151. DWORD
  152. MdGetCheckSumW (
  153. IN PCWSTR ModuleName
  154. );
  155. //
  156. // New Executable resource access
  157. //
  158. HANDLE
  159. NeOpenFileA (
  160. PCSTR FileName
  161. );
  162. HANDLE
  163. NeOpenFileW (
  164. PCWSTR FileName
  165. );
  166. VOID
  167. NeCloseFile (
  168. HANDLE Handle
  169. );
  170. //
  171. // Once upon a time ENUMRESTYPEPROC was defined as a TCHAR prototype,
  172. // which was broken. If ENUMRESTYPEPROCA isn't defined, we'll define
  173. // it. (NOTE: The current winbase.h has these typedefs.)
  174. //
  175. #ifndef ENUMRESTYPEPROCA
  176. typedef BOOL (CALLBACK* ENUMRESTYPEPROCA)(HMODULE hModule, PSTR lpType, LONG_PTR lParam);
  177. typedef BOOL (CALLBACK* ENUMRESTYPEPROCW)(HMODULE hModule, PWSTR lpType, LONG_PTR lParam);
  178. typedef BOOL (CALLBACK* ENUMRESNAMEPROCA)(HMODULE hModule, PCSTR lpType, PSTR lpName, LONG_PTR lParam);
  179. typedef BOOL (CALLBACK* ENUMRESNAMEPROCW)(HMODULE hModule, PCWSTR lpType, PWSTR lpName, LONG_PTR lParam);
  180. #endif
  181. BOOL
  182. NeEnumResourceTypesA (
  183. IN HANDLE Handle,
  184. IN ENUMRESTYPEPROCA EnumFunc,
  185. IN LONG_PTR lParam
  186. );
  187. BOOL
  188. NeEnumResourceTypesW (
  189. IN HANDLE Handle,
  190. IN ENUMRESTYPEPROCW EnumFunc,
  191. IN LONG_PTR lParam
  192. );
  193. BOOL
  194. NeEnumResourceNamesA (
  195. IN HANDLE Handle,
  196. IN PCSTR Type,
  197. IN ENUMRESNAMEPROCA EnumFunc,
  198. IN LONG_PTR lParam
  199. );
  200. BOOL
  201. NeEnumResourceNamesW (
  202. IN HANDLE Handle,
  203. IN PCWSTR Type,
  204. IN ENUMRESNAMEPROCW EnumFunc,
  205. IN LONG_PTR lParam
  206. );
  207. DWORD
  208. NeSizeofResourceA (
  209. IN HANDLE Handle,
  210. IN PCSTR Type,
  211. IN PCSTR Name
  212. );
  213. DWORD
  214. NeSizeofResourceW (
  215. IN HANDLE Handle,
  216. IN PCWSTR Type,
  217. IN PCWSTR Name
  218. );
  219. PBYTE
  220. NeFindResourceExA (
  221. IN HANDLE Handle,
  222. IN PCSTR Type,
  223. IN PCSTR Name
  224. );
  225. PBYTE
  226. NeFindResourceExW (
  227. IN HANDLE Handle,
  228. IN PCWSTR Type,
  229. IN PCWSTR Name
  230. );
  231. #define NeFindResourceA(h,n,t) NeFindResourceExA(h,t,n)
  232. #define NeFindResourceW(h,n,t) NeFindResourceExW(h,t,n)
  233. //
  234. // Macro expansion definition
  235. //
  236. // None
  237. //
  238. // TCHAR mappings
  239. //
  240. #ifndef UNICODE
  241. #define MD_IMPORT_ENUM16 MD_IMPORT_ENUM16A
  242. #define MD_IMPORT_ENUM32 MD_IMPORT_ENUM32A
  243. #define MdLoadModuleData MdLoadModuleDataA
  244. #define MdUnloadModuleData MdUnloadModuleDataA
  245. #define MdEnumFirstImport16 MdEnumFirstImport16A
  246. #define MdEnumNextImport16 MdEnumNextImport16A
  247. #define MdAbortImport16Enum MdAbortImport16EnumA
  248. #define MdEnumFirstImportModule32 MdEnumFirstImportModule32A
  249. #define MdEnumNextImportModule32 MdEnumNextImportModule32A
  250. #define MdEnumFirstImportFunction32 MdEnumFirstImportFunction32A
  251. #define MdEnumNextImportFunction32 MdEnumNextImportFunction32A
  252. #define MdAbortImport32Enum MdAbortImport32EnumA
  253. #define MdGetModuleType MdGetModuleTypeA
  254. #define MdGet16ModuleDescription MdGet16ModuleDescriptionA
  255. #define MdGetPECheckSum MdGetPECheckSumA
  256. #define MdGetCheckSum MdGetCheckSumA
  257. #define NeOpenFile NeOpenFileA
  258. #define NeEnumResourceTypes NeEnumResourceTypesA
  259. #define NeEnumResourceNames NeEnumResourceNamesA
  260. #define NeSizeofResource NeSizeofResourceA
  261. #define NeFindResource NeFindResourceA
  262. #define NeFindResourceEx NeFindResourceExA
  263. #else
  264. #define MD_IMPORT_ENUM16 MD_IMPORT_ENUM16W
  265. #define MD_IMPORT_ENUM32 MD_IMPORT_ENUM32W
  266. #define MdLoadModuleData MdLoadModuleDataW
  267. #define MdUnloadModuleData MdUnloadModuleDataW
  268. #define MdEnumFirstImport16 MdEnumFirstImport16W
  269. #define MdEnumNextImport16 MdEnumNextImport16W
  270. #define MdAbortImport16Enum MdAbortImport16EnumW
  271. #define MdEnumFirstImportModule32 MdEnumFirstImportModule32W
  272. #define MdEnumNextImportModule32 MdEnumNextImportModule32W
  273. #define MdEnumFirstImportFunction32 MdEnumFirstImportFunction32W
  274. #define MdEnumNextImportFunction32 MdEnumNextImportFunction32W
  275. #define MdAbortImport32Enum MdAbortImport32EnumW
  276. #define MdGetModuleType MdGetModuleTypeW
  277. #define MdGet16ModuleDescription MdGet16ModuleDescriptionW
  278. #define MdGetPECheckSum MdGetPECheckSumW
  279. #define MdGetCheckSum MdGetCheckSumW
  280. #define NeOpenFile NeOpenFileW
  281. #define NeEnumResourceTypes NeEnumResourceTypesW
  282. #define NeEnumResourceNames NeEnumResourceNamesW
  283. #define NeSizeofResource NeSizeofResourceW
  284. #define NeFindResource NeFindResourceW
  285. #define NeFindResourceEx NeFindResourceExW
  286. #endif