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.

373 lines
14 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Certain calls are dynamically linked so that the user-mode
  4. // DLL can be used on Win9x and NT4.
  5. //
  6. // Copyright (C) Microsoft Corporation, 2000-2002.
  7. //
  8. //----------------------------------------------------------------------------
  9. #ifndef __DLLIMP_H__
  10. #define __DLLIMP_H__
  11. #define SECURITY_WIN32
  12. #include <security.h>
  13. #ifndef _WIN32_WCE
  14. #include <schannel.h>
  15. #define __DI_CDECL__
  16. #ifndef _NTDBG_
  17. typedef int DEBUGOBJECTINFOCLASS;
  18. #endif
  19. #else
  20. #define __DI_CDECL__ __cdecl
  21. typedef int PROCESSINFOCLASS;
  22. typedef int THREADINFOCLASS;
  23. typedef int DEBUGOBJECTINFOCLASS;
  24. typedef int OBJECT_INFORMATION_CLASS;
  25. typedef int SYSTEM_INFORMATION_CLASS;
  26. typedef int SYSDBG_COMMAND;
  27. #endif
  28. #include <tlhelp32.h>
  29. struct DYNAMIC_CALL_NAME
  30. {
  31. PCSTR Name;
  32. BOOL Required;
  33. };
  34. struct DYNAMIC_CALLS_DESC
  35. {
  36. PCSTR DllName;
  37. ULONG Count;
  38. DYNAMIC_CALL_NAME* Names;
  39. FARPROC* Procs;
  40. HINSTANCE Dll;
  41. BOOL Initialized;
  42. };
  43. #ifdef NTDLL_APIS
  44. // Calls from ntdll.dll.
  45. typedef struct _NTDLL_CALLS
  46. {
  47. HANDLE (NTAPI* CsrGetProcessId)
  48. (VOID);
  49. VOID (NTAPI* DbgBreakPoint)
  50. (VOID);
  51. ULONG (__DI_CDECL__* DbgPrint)
  52. (PCH Format, ...);
  53. ULONG (NTAPI* DbgPrompt)
  54. (PCH Prompt, PCH Response, ULONG MaximumResponseLength);
  55. NTSTATUS (NTAPI* DbgUiConvertStateChangeStructure)
  56. (IN struct _DBGUI_WAIT_STATE_CHANGE* StateChange,
  57. OUT struct _DEBUG_EVENT *DebugEvent);
  58. HANDLE (NTAPI* DbgUiGetThreadDebugObject)
  59. (VOID);
  60. NTSTATUS (NTAPI* DbgUiIssueRemoteBreakin)
  61. (IN HANDLE Process);
  62. VOID (NTAPI* DbgUiSetThreadDebugObject)
  63. (IN HANDLE DebugObject);
  64. NTSTATUS (NTAPI* NtAllocateVirtualMemory)
  65. (IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress,
  66. IN ULONG_PTR ZeroBits, IN OUT PSIZE_T RegionSize,
  67. IN ULONG AllocationType, IN ULONG Protect);
  68. NTSTATUS (NTAPI* NtClose)
  69. (IN HANDLE Handle);
  70. NTSTATUS (NTAPI* NtCreateDebugObject)
  71. (OUT HANDLE* DebugObjectHandle, IN ACCESS_MASK DesiredAccess,
  72. IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG Flags);
  73. NTSTATUS (NTAPI* NtDebugActiveProcess)
  74. (IN HANDLE ProcessHandle, IN HANDLE DebugObjectHandle);
  75. NTSTATUS (NTAPI* NtDebugContinue)
  76. (IN HANDLE DebugObjectHandle, IN PCLIENT_ID ClientId,
  77. IN NTSTATUS ContinueStatus);
  78. NTSTATUS (NTAPI* NtFreeVirtualMemory)
  79. (IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress,
  80. IN OUT PSIZE_T RegionSize, IN ULONG FreeType);
  81. NTSTATUS (NTAPI* NtOpenProcess)
  82. (OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess,
  83. IN POBJECT_ATTRIBUTES ObjectAttributes,
  84. IN PCLIENT_ID ClientId OPTIONAL);
  85. NTSTATUS (NTAPI* NtOpenThread)
  86. (OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess,
  87. IN POBJECT_ATTRIBUTES ObjectAttributes,
  88. IN PCLIENT_ID ClientId OPTIONAL);
  89. NTSTATUS (NTAPI* NtQueryInformationProcess)
  90. (IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass,
  91. OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength,
  92. OUT PULONG ReturnLength OPTIONAL);
  93. NTSTATUS (NTAPI* NtQueryInformationThread)
  94. (IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass,
  95. OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength,
  96. OUT PULONG ReturnLength OPTIONAL);
  97. NTSTATUS (NTAPI* NtQueryObject)
  98. (IN HANDLE Handle, IN OBJECT_INFORMATION_CLASS ObjectInformationClass,
  99. OUT PVOID ObjectInformation, IN ULONG Length,
  100. OUT PULONG ReturnLength OPTIONAL);
  101. NTSTATUS (NTAPI* NtQuerySystemInformation)
  102. (IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
  103. OUT PVOID SystemInformation, IN ULONG SystemInformationLength,
  104. OUT PULONG ReturnLength OPTIONAL);
  105. NTSTATUS (NTAPI* NtRemoveProcessDebug)
  106. (IN HANDLE ProcessHandle, IN HANDLE DebugObjectHandle);
  107. NTSTATUS (NTAPI* NtResumeThread)
  108. (IN HANDLE ThreadHandle, OUT PULONG PreviousSuspendCount OPTIONAL);
  109. NTSTATUS (NTAPI* NtSetInformationDebugObject)
  110. (IN HANDLE DebugObjectHandle,
  111. IN DEBUGOBJECTINFOCLASS DebugObjectInformationClass,
  112. IN PVOID DebugInformation, IN ULONG DebugInformationLength,
  113. OUT PULONG ReturnLength OPTIONAL);
  114. NTSTATUS (NTAPI* NtSetInformationProcess)
  115. (IN HANDLE ProcessHandle,
  116. IN PROCESSINFOCLASS ProcessInformationClass,
  117. IN PVOID ProcessInformation, IN ULONG ProcessInformationLength);
  118. NTSTATUS (NTAPI* NtSystemDebugControl)
  119. (IN SYSDBG_COMMAND Command, IN PVOID InputBuffer,
  120. IN ULONG InputBufferLength, OUT PVOID OutputBuffer,
  121. IN ULONG OutputBufferLength, OUT PULONG ReturnLength);
  122. NTSTATUS (NTAPI* NtWaitForDebugEvent)
  123. (IN HANDLE DebugObjectHandle, IN BOOLEAN Alertable,
  124. IN PLARGE_INTEGER Timeout OPTIONAL,
  125. OUT struct _DBGUI_WAIT_STATE_CHANGE* WaitStateChange);
  126. NTSTATUS (NTAPI* RtlAnsiStringToUnicodeString)
  127. (PUNICODE_STRING DestinationString, PCANSI_STRING SourceString,
  128. BOOLEAN AllocateDestinationString);
  129. NTSTATUS (NTAPI* RtlCreateProcessParameters)
  130. (struct _RTL_USER_PROCESS_PARAMETERS** ProcessParameters,
  131. PUNICODE_STRING ImagePathName,
  132. PUNICODE_STRING DllPath,
  133. PUNICODE_STRING CurrentDirectory,
  134. PUNICODE_STRING CommandLine,
  135. PVOID Environment,
  136. PUNICODE_STRING WindowTitle,
  137. PUNICODE_STRING DesktopInfo,
  138. PUNICODE_STRING ShellInfo,
  139. PUNICODE_STRING RuntimeData);
  140. NTSTATUS (NTAPI* RtlCreateUserProcess)
  141. (PUNICODE_STRING NtImagePathName, ULONG Attributes,
  142. struct _RTL_USER_PROCESS_PARAMETERS* ProcessParameters,
  143. PSECURITY_DESCRIPTOR ProcessSecurityDescriptor,
  144. PSECURITY_DESCRIPTOR ThreadSecurityDescriptor,
  145. HANDLE ParentProcess, BOOLEAN InheritHandles, HANDLE DebugPort,
  146. HANDLE ExceptionPort,
  147. struct _RTL_USER_PROCESS_INFORMATION* ProcessInformation);
  148. NTSTATUS (NTAPI* RtlDestroyProcessParameters)
  149. (struct _RTL_USER_PROCESS_PARAMETERS* ProcessParameters);
  150. BOOLEAN (NTAPI* RtlDosPathNameToNtPathName_U)
  151. (PCWSTR DosFileName, PUNICODE_STRING NtFileName,
  152. PWSTR *FilePart OPTIONAL,
  153. PVOID Reserved);
  154. NTSTATUS (NTAPI* RtlFindMessage)
  155. (PVOID DllHandle, ULONG MessageTableId, ULONG MessageLanguageId,
  156. ULONG MessageId, PMESSAGE_RESOURCE_ENTRY *MessageEntry);
  157. BOOLEAN (NTAPI* RtlFreeHeap)
  158. (IN PVOID HeapHandle, IN ULONG Flags, IN PVOID BaseAddress);
  159. VOID (NTAPI* RtlFreeUnicodeString)
  160. (PUNICODE_STRING UnicodeString);
  161. PLIST_ENTRY (NTAPI* RtlGetFunctionTableListHead)
  162. (VOID);
  163. PRTL_UNLOAD_EVENT_TRACE (NTAPI* RtlGetUnloadEventTrace)
  164. (VOID);
  165. VOID (NTAPI* RtlInitAnsiString)
  166. (PANSI_STRING DestinationString, char const *SourceString);
  167. VOID (NTAPI* RtlInitUnicodeString)
  168. (PUNICODE_STRING DestinationString, PCWSTR SourceString);
  169. BOOLEAN (NTAPI* RtlTryEnterCriticalSection)
  170. (PRTL_CRITICAL_SECTION CriticalSection);
  171. NTSTATUS (NTAPI* RtlUnicodeStringToAnsiString)
  172. (PANSI_STRING DestinationString, PCUNICODE_STRING SourceString,
  173. BOOLEAN AllocateDestinationString);
  174. } NTDLL_CALLS;
  175. extern NTDLL_CALLS g_NtDllCalls;
  176. extern DYNAMIC_CALLS_DESC g_NtDllCallsDesc;
  177. #endif
  178. // Calls from kernel32.dll.
  179. typedef struct _KERNEL32_CALLS
  180. {
  181. HANDLE (WINAPI* CreateToolhelp32Snapshot)
  182. (DWORD dwFlags, DWORD th32ProcessID);
  183. BOOL (WINAPI* DebugActiveProcessStop)
  184. (DWORD ProcessId);
  185. VOID (WINAPI* DebugBreak)
  186. (VOID);
  187. BOOL (WINAPI* DebugBreakProcess)
  188. (HANDLE Process);
  189. BOOL (WINAPI* DebugSetProcessKillOnExit)
  190. (BOOL KillOnExit);
  191. BOOL (WINAPI* Module32First)
  192. (HANDLE hSnapshot, LPMODULEENTRY32 lpme);
  193. BOOL (WINAPI* Module32Next)
  194. (HANDLE hSnapshot, LPMODULEENTRY32 lpme);
  195. HANDLE (WINAPI* OpenThread)
  196. (DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId);
  197. BOOL (WINAPI* Process32First)
  198. (HANDLE hSnapshot, LPPROCESSENTRY32 lppe);
  199. BOOL (WINAPI* Process32Next)
  200. (HANDLE hSnapshot, LPPROCESSENTRY32 lppe);
  201. BOOL (WINAPI* Thread32First)
  202. (HANDLE hSnapshot, LPTHREADENTRY32 lpte);
  203. BOOL (WINAPI* Thread32Next)
  204. (HANDLE hSnapshot, LPTHREADENTRY32 lpte);
  205. } KERNEL32_CALLS;
  206. extern KERNEL32_CALLS g_Kernel32Calls;
  207. extern DYNAMIC_CALLS_DESC g_Kernel32CallsDesc;
  208. // Calls from user32.dll.
  209. typedef struct _USER32_CALLS
  210. {
  211. void (WINAPI* PrivateKDBreakPoint) (void);
  212. HDESK (WINAPI* GetThreadDesktop) (DWORD dwThreadId);
  213. BOOL (WINAPI* SwitchDesktop) (HDESK hDesktop);
  214. BOOL (WINAPI* CloseDesktop) (HDESK hDesktop);
  215. } USER32_CALLS;
  216. extern USER32_CALLS g_User32Calls;
  217. extern DYNAMIC_CALLS_DESC g_User32CallsDesc;
  218. // Calls from ole32.dll.
  219. typedef struct _OLE32_CALLS
  220. {
  221. HRESULT (STDAPICALLTYPE* CLSIDFromString)
  222. (IN LPOLESTR lpsz, OUT LPCLSID pclsid);
  223. HRESULT (STDAPICALLTYPE* CoCreateInstance)
  224. (IN REFCLSID rclsid, IN LPUNKNOWN pUnkOuter,
  225. IN DWORD dwClsContext, IN REFIID riid, OUT LPVOID FAR* ppv);
  226. HRESULT (STDAPICALLTYPE* CoGetInterfaceAndReleaseStream)
  227. (IN LPSTREAM pStm, IN REFIID iid, OUT LPVOID FAR* ppv);
  228. HRESULT (STDAPICALLTYPE* CoInitializeEx)
  229. (void * pvReserved, DWORD dwCoInit);
  230. HRESULT (STDAPICALLTYPE* CoMarshalInterThreadInterfaceInStream)
  231. (IN REFIID riid, IN LPUNKNOWN pUnk, OUT LPSTREAM *ppStm);
  232. void (STDAPICALLTYPE* CoUninitialize)
  233. (void);
  234. HRESULT (STDAPICALLTYPE* CoUnmarshalInterface)
  235. (IN LPSTREAM pStm, IN REFIID riid, OUT LPVOID FAR* ppv);
  236. HRESULT (STDAPICALLTYPE* CoCreateGuid)(OUT GUID FAR *pguid);
  237. } OLE32_CALLS;
  238. extern OLE32_CALLS g_Ole32Calls;
  239. extern DYNAMIC_CALLS_DESC g_Ole32CallsDesc;
  240. // Calls from oleaut32.dll.
  241. typedef struct _OLEAUT32_CALLS
  242. {
  243. BSTR (STDAPICALLTYPE* SysAllocStringLen)
  244. (const OLECHAR *, UINT) ;
  245. void (STDAPICALLTYPE* SysFreeString)
  246. (BSTR Str);
  247. HRESULT (STDAPICALLTYPE *VariantClear)
  248. (VARIANTARG * pvarg);
  249. HRESULT (STDAPICALLTYPE *VariantCopy)
  250. (VARIANTARG * pvargDest, VARIANTARG * pvargSrc);
  251. void (STDAPICALLTYPE *VariantInit)
  252. (VARIANTARG * pvarg);
  253. } OLEAUT32_CALLS;
  254. extern OLEAUT32_CALLS g_OleAut32Calls;
  255. extern DYNAMIC_CALLS_DESC g_OleAut32CallsDesc;
  256. // Calls from shlwapi.dll.
  257. typedef struct _SHLWAPI_CALLS
  258. {
  259. BOOL (STDAPICALLTYPE* PathIsDirectoryA)
  260. (LPCSTR pszPath);
  261. } SHLWAPI_CALLS;
  262. extern SHLWAPI_CALLS g_ShlWapiCalls;
  263. extern DYNAMIC_CALLS_DESC g_ShlWapiCallsDesc;
  264. #ifndef _WIN32_WCE
  265. // Calls from security.dll.
  266. extern SecurityFunctionTable g_SecurityFunc;
  267. // Calls from crypt32.dll.
  268. typedef struct _CRYPT32_CALLS
  269. {
  270. PCCERT_CONTEXT (WINAPI* CertFindCertificateInStore)
  271. (IN HCERTSTORE hCertStore,
  272. IN DWORD dwCertEncodingType,
  273. IN DWORD dwFindFlags,
  274. IN DWORD dwFindType,
  275. IN const void *pvFindPara,
  276. IN PCCERT_CONTEXT pPrevCertContext);
  277. PCCERT_CHAIN_CONTEXT (WINAPI* CertFindChainInStore)
  278. (IN HCERTSTORE hCertStore,
  279. IN DWORD dwCertEncodingType,
  280. IN DWORD dwFindFlags,
  281. IN DWORD dwFindType,
  282. IN const void *pvFindPara,
  283. IN PCCERT_CHAIN_CONTEXT pPrevChainContext);
  284. VOID (WINAPI* CertFreeCertificateChain)
  285. (IN PCCERT_CHAIN_CONTEXT pChainContext);
  286. BOOL (WINAPI* CertFreeCertificateContext)
  287. (IN PCCERT_CONTEXT pCertContext);
  288. BOOL (WINAPI* CertGetCertificateChain)
  289. (IN OPTIONAL HCERTCHAINENGINE hChainEngine,
  290. IN PCCERT_CONTEXT pCertContext,
  291. IN OPTIONAL LPFILETIME pTime,
  292. IN OPTIONAL HCERTSTORE hAdditionalStore,
  293. IN PCERT_CHAIN_PARA pChainPara,
  294. IN DWORD dwFlags,
  295. IN LPVOID pvReserved,
  296. OUT PCCERT_CHAIN_CONTEXT* ppChainContext);
  297. HCERTSTORE (WINAPI* CertOpenStore)
  298. (IN LPCSTR lpszStoreProvider,
  299. IN DWORD dwEncodingType,
  300. IN HCRYPTPROV hCryptProv,
  301. IN DWORD dwFlags,
  302. IN const void *pvPara);
  303. HCERTSTORE (WINAPI* CertOpenSystemStoreA)
  304. (HCRYPTPROV hProv,
  305. LPCSTR szSubsystemProtocol);
  306. BOOL (WINAPI* CertVerifyCertificateChainPolicy)
  307. (IN LPCSTR pszPolicyOID,
  308. IN PCCERT_CHAIN_CONTEXT pChainContext,
  309. IN PCERT_CHAIN_POLICY_PARA pPolicyPara,
  310. IN OUT PCERT_CHAIN_POLICY_STATUS pPolicyStatus);
  311. } CRYPT32_CALLS;
  312. extern CRYPT32_CALLS g_Crypt32Calls;
  313. extern DYNAMIC_CALLS_DESC g_Crypt32CallsDesc;
  314. // Calls from advapi32.dll.
  315. typedef struct _ADVAPI32_CALLS
  316. {
  317. BOOL (WINAPI* EnumServicesStatusExA)
  318. (SC_HANDLE hSCManager,
  319. SC_ENUM_TYPE InfoLevel,
  320. DWORD dwServiceType,
  321. DWORD dwServiceState,
  322. LPBYTE lpServices,
  323. DWORD cbBufSize,
  324. LPDWORD pcbBytesNeeded,
  325. LPDWORD lpServicesReturned,
  326. LPDWORD lpResumeHandle,
  327. LPCSTR pszGroupName);
  328. BOOL (WINAPI* EnumServicesStatusExW)
  329. (SC_HANDLE hSCManager,
  330. SC_ENUM_TYPE InfoLevel,
  331. DWORD dwServiceType,
  332. DWORD dwServiceState,
  333. LPBYTE lpServices,
  334. DWORD cbBufSize,
  335. LPDWORD pcbBytesNeeded,
  336. LPDWORD lpServicesReturned,
  337. LPDWORD lpResumeHandle,
  338. LPCWSTR pszGroupName);
  339. SC_HANDLE (WINAPI* OpenSCManagerA)
  340. (LPCSTR lpMachineName, LPCSTR lpDatabaseName, DWORD dwDesiredAccess);
  341. SC_HANDLE (WINAPI* OpenSCManagerW)
  342. (LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess);
  343. BOOL(WINAPI * GetEventLogInformation)
  344. (HANDLE hEventLog,
  345. DWORD dwInfoLevel,
  346. LPVOID lpBuffer,
  347. DWORD cbBufSize,
  348. LPDWORD pcbBytesNeeded);
  349. } ADVAPI32_CALLS;
  350. extern ADVAPI32_CALLS g_Advapi32Calls;
  351. extern DYNAMIC_CALLS_DESC g_Advapi32CallsDesc;
  352. #endif // #ifndef _WIN32_WCE
  353. HRESULT InitDynamicCalls(DYNAMIC_CALLS_DESC* Desc);
  354. #endif // #ifndef __DLLIMP_H__