jwawinternl.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  1. {******************************************************************************}
  2. { }
  3. { Windows Internal Services API interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: winternl.h, released August 2001. The original Pascal }
  9. { code is: Winternl.pas, released December 2000. The initial developer of the }
  10. { Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
  11. { }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  13. { Marcel van Brakel. All Rights Reserved. }
  14. { }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  16. { }
  17. { You may retrieve the latest version of this file at the Project JEDI }
  18. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  19. { }
  20. { The contents of this file are used with permission, subject to the Mozilla }
  21. { Public License Version 1.1 (the "License"); you may not use this file except }
  22. { in compliance with the License. You may obtain a copy of the License at }
  23. { http://www.mozilla.org/MPL/MPL-1.1.html }
  24. { }
  25. { Software distributed under the License is distributed on an "AS IS" basis, }
  26. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  27. { the specific language governing rights and limitations under the License. }
  28. { }
  29. { Alternatively, the contents of this file may be used under the terms of the }
  30. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  31. { provisions of the LGPL License are applicable instead of those above. }
  32. { If you wish to allow use of your version of this file only under the terms }
  33. { of the LGPL License and not to allow others to use your version of this file }
  34. { under the MPL, indicate your decision by deleting the provisions above and }
  35. { replace them with the notice and other provisions required by the LGPL }
  36. { License. If you do not delete the provisions above, a recipient may use }
  37. { your version of this file under either the MPL or the LGPL License. }
  38. { }
  39. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  40. { }
  41. {******************************************************************************}
  42. // $Id: JwaWinternl.pas,v 1.3 2005/09/06 16:36:51 marquardt Exp $
  43. (************************************************************************
  44. * *
  45. * winternl.h -- This module defines the internal NT APIs and data *
  46. * structures that are intended for the use only by internal core *
  47. * Windows components. These APIs and data structures may change *
  48. * at any time. *
  49. * *
  50. * These APIs and data structures are subject to changes from one *
  51. * Windows release to another Windows release. To maintain the *
  52. * compatiblity of your application, avoid using these APIs and *
  53. * data structures. *
  54. * *
  55. * The appropriate mechanism for accessing the functions defined in *
  56. * this header is to use LoadLibrary() for ntdll.dll and *
  57. * GetProcAddress() for the particular function. By using this *
  58. * approach, your application will be more resilient to changes *
  59. * for these functions between Windows releases. If a function *
  60. * prototype does change, then GetProcAddress() for that function *
  61. * might detect the change and fail the function call, which your *
  62. * application will be able to detect. GetProcAddress() may not *
  63. * be able to detect all signature changes, thus avoid using these *
  64. * internal functions. Instead, your application should use the *
  65. * appropriate Win32 function that provides equivalent or similiar *
  66. * functionality. *
  67. * *
  68. * Copyright (c) Microsoft Corp. All rights reserved. *
  69. * *
  70. ************************************************************************)
  71. unit JwaWinternl;
  72. {$WEAKPACKAGEUNIT}
  73. {$HPPEMIT ''}
  74. {$HPPEMIT '#include "Winternl.h"'}
  75. {$HPPEMIT ''}
  76. {$I jediapilib.inc}
  77. {$STACKFRAMES ON}
  78. interface
  79. uses
  80. {$IFDEF USE_DELPHI_TYPES}
  81. Windows,
  82. {$ENDIF USE_DELPHI_TYPES}
  83. JwaWindows;
  84. //
  85. // The PEB and TEB structures are subject to changes between Windows
  86. // releases, thus the fields offsets may change as well as the Reserved
  87. // fields. The Reserved fields are reserved for use only by the Windows
  88. // operating systems. Do not assume a maximum size for the structures.
  89. //
  90. //
  91. // Instead of using the BeingDebugged field, use the Win32 APIs
  92. // IsDebuggerPresent, CheckRemoteDebuggerPresent
  93. // Instead of using the SessionId field, use the Win32 APIs
  94. // GetCurrentProcessId and ProcessIdToSessionId
  95. // Sample x86 assembly code that gets the SessionId (subject to change
  96. // between Windows releases, use the Win32 APIs to make your application
  97. // resilient to changes)
  98. // mov eax,fs:[00000018]
  99. // mov eax,[eax+0x30]
  100. // mov eax,[eax+0x1d4]
  101. //
  102. type
  103. _PEB = record
  104. Reserved1: array [0..1] of Byte;
  105. BeingDebugged: Byte;
  106. Reserved2: array [0..228] of Byte;
  107. Reserved3: array [0..58] of PVOID;
  108. SessionId: ULONG;
  109. end;
  110. PEB = _PEB;
  111. PPEB = ^PEB;
  112. TPeb = PEB;
  113. //
  114. // Instead of using the Tls fields, use the Win32 TLS APIs
  115. // TlsAlloc, TlsGetValue, TlsSetValue, TlsFree
  116. //
  117. // Instead of using the ReservedForOle field, use the COM API
  118. // CoGetContextToken
  119. //
  120. type
  121. _TEB = record
  122. Reserved1: array [0..1951] of Byte;
  123. Reserved2: array [0..411] of PVOID;
  124. TlsSlots: array [0..63] of PVOID;
  125. Reserved3: array [0..78] of Byte;
  126. Reserved4: array [0..25] of PVOID;
  127. ReservedForOle: PVOID; // Windows 2000 only
  128. Reserved5: array [0..3] of PVOID;
  129. TlsExpansionSlots: PVOID;
  130. end;
  131. TEB = _TEB;
  132. PTEB = ^TEB;
  133. TTeb = TEB;
  134. //
  135. // These data structures and type definitions are needed for compilation and
  136. // use of the internal Windows APIs defined in this header.
  137. //
  138. type
  139. NTSTATUS = Longword;
  140. PCSZ = PChar;
  141. _STRING = record
  142. Length: USHORT;
  143. MaximumLength: USHORT;
  144. Buffer: PChar;
  145. end;
  146. TString = _STRING;
  147. PString = ^TString;
  148. //typedef STRING *PSTRING;
  149. ANSI_STRING = _STRING;
  150. PANSI_STRING = ^ANSI_STRING;
  151. PCANSI_STRING = PSTRING;
  152. OEM_STRING = _STRING;
  153. POEM_STRING = ^OEM_STRING;
  154. PCOEM_STRING = POEM_STRING;
  155. _UNICODE_STRING = record
  156. Length: USHORT;
  157. MaximumLength: USHORT;
  158. Buffer: PWSTR;
  159. end;
  160. UNICODE_STRING = _UNICODE_STRING;
  161. PUNICODE_STRING = ^UNICODE_STRING;
  162. PCUNICODE_STRING = PUNICODE_STRING;
  163. TUnicodeString = UNICODE_STRING;
  164. PUnicodeString = ^TUnicodeString;
  165. _OBJECT_ATTRIBUTES = record
  166. Length: ULONG;
  167. RootDirectory: HANDLE;
  168. ObjectName: PUNICODE_STRING;
  169. Attributes: ULONG;
  170. SecurityDescriptor: PVOID;
  171. SecurityQualityOfService: PVOID;
  172. end;
  173. OBJECT_ATTRIBUTES = _OBJECT_ATTRIBUTES;
  174. POBJECT_ATTRIBUTES = ^OBJECT_ATTRIBUTES;
  175. TObjectAttributes = OBJECT_ATTRIBUTES;
  176. PObjectAttributes = ^TObjectAttributes;
  177. _IO_STATUS_BLOCK = record
  178. (*
  179. union {
  180. Status: NTSTATUS;
  181. Pointer: PVOID;
  182. }; *)
  183. Status: NTSTATUS;
  184. Information: ULONG_PTR;
  185. end;
  186. IO_STATUS_BLOCK = _IO_STATUS_BLOCK;
  187. PIO_STATUS_BLOCK = ^IO_STATUS_BLOCK;
  188. TIoStatusBlock = IO_STATUS_BLOCK;
  189. PIoStatusBlock = ^TIoStatusBlock;
  190. type
  191. PIO_APC_ROUTINE = procedure (ApcContext: PVOID; IoStatusBlock: PIO_STATUS_BLOCK; Reserved: ULONG); stdcall;
  192. {$IFDEF _M_IA64}
  193. typedef struct _FRAME_POINTERS {
  194. ULONGLONG MemoryStackFp;
  195. ULONGLONG BackingStoreFp;
  196. } FRAME_POINTERS, *PFRAME_POINTERS;
  197. #define UNWIND_HISTORY_TABLE_SIZE 12
  198. typedef struct _RUNTIME_FUNCTION {
  199. ULONG BeginAddress;
  200. ULONG EndAddress;
  201. ULONG UnwindInfoAddress;
  202. } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
  203. typedef struct _UNWIND_HISTORY_TABLE_ENTRY {
  204. ULONG64 ImageBase;
  205. ULONG64 Gp;
  206. PRUNTIME_FUNCTION FunctionEntry;
  207. } UNWIND_HISTORY_TABLE_ENTRY, *PUNWIND_HISTORY_TABLE_ENTRY;
  208. typedef struct _UNWIND_HISTORY_TABLE {
  209. ULONG Count;
  210. UCHAR Search;
  211. ULONG64 LowAddress;
  212. ULONG64 HighAddress;
  213. UNWIND_HISTORY_TABLE_ENTRY Entry[UNWIND_HISTORY_TABLE_SIZE];
  214. } UNWIND_HISTORY_TABLE, *PUNWIND_HISTORY_TABLE;
  215. {$ENDIF _M_IA64}
  216. type
  217. _PROCESS_BASIC_INFORMATION = record
  218. Reserved1: PVOID;
  219. PebBaseAddress: PPEB;
  220. Reserved2: array [0..1] of PVOID;
  221. UniqueProcessId: ULONG_PTR;
  222. Reserved3: PVOID;
  223. end;
  224. PROCESS_BASIC_INFORMATION = _PROCESS_BASIC_INFORMATION;
  225. PPROCESS_BASIC_INFORMATION = ^PROCESS_BASIC_INFORMATION;
  226. TProcessBasicInformation = PROCESS_BASIC_INFORMATION;
  227. PProcessBasicInformation = ^TProcessBasicInformation;
  228. _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION = record
  229. IdleTime: LARGE_INTEGER;
  230. KernelTime: LARGE_INTEGER;
  231. UserTime: LARGE_INTEGER;
  232. Reserved1: array [0..1] of LARGE_INTEGER;
  233. Reserved2: ULONG;
  234. end;
  235. SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION = _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
  236. PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION = ^SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
  237. TSystemProcessorPerformanceInformation = SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
  238. PSystemProcessorPerformanceInformation = ^TSystemProcessorPerformanceInformation;
  239. _SYSTEM_PROCESS_INFORMATION = record
  240. NextEntryOffset: ULONG;
  241. Reserved1: array [0..51] of BYTE;
  242. Reserved2: array [0..2] of PVOID;
  243. UniqueProcessId: HANDLE;
  244. Reserved3: PVOID;
  245. HandleCount: ULONG;
  246. Reserved4: array [0..3] of BYTE;
  247. Reserved5: array [0..11] of PVOID;
  248. PeakPagefileUsage: SIZE_T;
  249. PrivatePageCount: SIZE_T;
  250. Reserved6: array [0..5] of LARGE_INTEGER;
  251. end;
  252. SYSTEM_PROCESS_INFORMATION = _SYSTEM_PROCESS_INFORMATION;
  253. PSYSTEM_PROCESS_INFORMATION = ^SYSTEM_PROCESS_INFORMATION;
  254. TSystemProcessorInformation = SYSTEM_PROCESS_INFORMATION;
  255. PSystemProcessorInformation = ^TSystemProcessorInformation;
  256. _SYSTEM_REGISTRY_QUOTA_INFORMATION = record
  257. RegistryQuotaAllowed: ULONG;
  258. RegistryQuotaUsed: ULONG;
  259. Reserved1: PVOID;
  260. end;
  261. SYSTEM_REGISTRY_QUOTA_INFORMATION = _SYSTEM_REGISTRY_QUOTA_INFORMATION;
  262. PSYSTEM_REGISTRY_QUOTA_INFORMATION = ^SYSTEM_REGISTRY_QUOTA_INFORMATION;
  263. TSystemRegistryInformation = SYSTEM_REGISTRY_QUOTA_INFORMATION;
  264. PSystemRegistryInformation = ^TSystemRegistryInformation;
  265. _SYSTEM_BASIC_INFORMATION = record
  266. Reserved1: array [0..23] of BYTE;
  267. Reserved2: array [0..3] of PVOID;
  268. NumberOfProcessors: CCHAR;
  269. end;
  270. SYSTEM_BASIC_INFORMATION = _SYSTEM_BASIC_INFORMATION;
  271. PSYSTEM_BASIC_INFORMATION = ^SYSTEM_BASIC_INFORMATION;
  272. TSystemBasicInformation = SYSTEM_BASIC_INFORMATION;
  273. PSystemBasicInformation = ^TSystemBasicInformation;
  274. _SYSTEM_TIMEOFDAY_INFORMATION = record
  275. Reserved1: array [0..47] of BYTE;
  276. end;
  277. SYSTEM_TIMEOFDAY_INFORMATION = _SYSTEM_TIMEOFDAY_INFORMATION;
  278. PSYSTEM_TIMEOFDAY_INFORMATION = ^SYSTEM_TIMEOFDAY_INFORMATION;
  279. TSystemTimeOfDayInformation = SYSTEM_TIMEOFDAY_INFORMATION;
  280. PSystemTimeOfDayInformation = ^TSystemTimeOfDayInformation;
  281. _SYSTEM_PERFORMANCE_INFORMATION = record
  282. Reserved1: array [0..311] of BYTE;
  283. end;
  284. SYSTEM_PERFORMANCE_INFORMATION = _SYSTEM_PERFORMANCE_INFORMATION;
  285. PSYSTEM_PERFORMANCE_INFORMATION = ^SYSTEM_PERFORMANCE_INFORMATION;
  286. TSystemPerformanceInformation = SYSTEM_PERFORMANCE_INFORMATION;
  287. PSystemPerformanceInformation = ^TSystemPerformanceInformation;
  288. _SYSTEM_EXCEPTION_INFORMATION = record
  289. Reserved1: array [0..15] of BYTE;
  290. end;
  291. SYSTEM_EXCEPTION_INFORMATION = _SYSTEM_EXCEPTION_INFORMATION;
  292. PSYSTEM_EXCEPTION_INFORMATION = ^SYSTEM_EXCEPTION_INFORMATION;
  293. TSystemExceptionInformation = SYSTEM_EXCEPTION_INFORMATION;
  294. PSystemExceptionInformation = ^TSystemExceptionInformation;
  295. _SYSTEM_LOOKASIDE_INFORMATION = record
  296. Reserved1: array [0..31] of BYTE;
  297. end;
  298. SYSTEM_LOOKASIDE_INFORMATION = _SYSTEM_LOOKASIDE_INFORMATION;
  299. PSYSTEM_LOOKASIDE_INFORMATION = ^SYSTEM_LOOKASIDE_INFORMATION;
  300. TSystemLookASideInformation = SYSTEM_LOOKASIDE_INFORMATION;
  301. PSystemLookASideInformation = ^TSystemLookASideInformation;
  302. _SYSTEM_INTERRUPT_INFORMATION = record
  303. Reserved1: array [0..23] of BYTE;
  304. end;
  305. SYSTEM_INTERRUPT_INFORMATION = _SYSTEM_INTERRUPT_INFORMATION;
  306. PSYSTEM_INTERRUPT_INFORMATION = ^SYSTEM_INTERRUPT_INFORMATION;
  307. TSystemInterruptInformation = SYSTEM_INTERRUPT_INFORMATION;
  308. PSystemInterruptInformation = ^TSystemInterruptInformation;
  309. const
  310. FileDirectoryInformation = 1;
  311. type
  312. _FILE_INFORMATION_CLASS = DWORD;
  313. FILE_INFORMATION_CLASS = _FILE_INFORMATION_CLASS;
  314. TFileInformationClass = FILE_INFORMATION_CLASS;
  315. const
  316. ProcessBasicInformation = 0;
  317. ProcessWow64Information = 26;
  318. type
  319. _PROCESSINFOCLASS = DWORD;
  320. PROCESSINFOCLASS = _PROCESSINFOCLASS;
  321. TProcessInfoClass = PROCESSINFOCLASS;
  322. type
  323. _THREADINFOCLASS = DWORD;
  324. THREADINFOCLASS = _THREADINFOCLASS;
  325. TThreadInfoClass = THREADINFOCLASS;
  326. const
  327. SystemBasicInformation = 0;
  328. SystemPerformanceInformation = 2;
  329. SystemTimeOfDayInformation = 3;
  330. SystemProcessInformation = 5;
  331. SystemProcessorPerformanceInformation = 8;
  332. SystemInterruptInformation = 23;
  333. SystemExceptionInformation = 33;
  334. SystemRegistryQuotaInformation = 37;
  335. SystemLookasideInformation = 45;
  336. type
  337. _SYSTEM_INFORMATION_CLASS = DWORD;
  338. SYSTEM_INFORMATION_CLASS = _SYSTEM_INFORMATION_CLASS;
  339. {$IFDEF WINXP}
  340. //#if (_WIN32_WINNT >= 0x0501)
  341. //
  342. // use the WTS API instead
  343. // WTSGetActiveConsoleSessionId
  344. // The active console id is cached as a volatile ULONG in a constant
  345. // memory location. This x86 memory location is subject to changes between
  346. // Windows releases. Use the WTS API to make your application resilient to
  347. // changes.
  348. //
  349. function INTERNAL_TS_ACTIVE_CONSOLE_ID: ULONG;
  350. {$ENDIF WINXP}
  351. //
  352. // These functions are intended for use by internal core Windows components
  353. // since these functions may change between Windows releases.
  354. //
  355. //todo #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  356. //todo #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  357. //todo #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  358. //
  359. // use the Win32 API instead
  360. // CloseHandle
  361. //
  362. function NtClose(_Handle: HANDLE): NTSTATUS; stdcall;
  363. //
  364. // use the Win32 API instead
  365. // CreateFile
  366. //
  367. function NtCreateFile (
  368. FileHandle: PHANDLE;
  369. DesiredAccess: ACCESS_MASK;
  370. ObjectAttributes: POBJECT_ATTRIBUTES;
  371. IoStatusBlock: PIO_STATUS_BLOCK;
  372. AllocationSize: PLARGE_INTEGER;
  373. FileAttributes: ULONG;
  374. ShareAccess: ULONG;
  375. CreateDisposition: ULONG;
  376. CreateOptions: ULONG;
  377. EaBuffer: PVOID;
  378. EaLength: ULONG): NTSTATUS; stdcall;
  379. //
  380. // use the Win32 API instead
  381. // CreateFile
  382. //
  383. function NtOpenFile (
  384. FileHandle: PHANDLE;
  385. DesiredAccess: ACCESS_MASK;
  386. ObjectAttributes: POBJECT_ATTRIBUTES;
  387. IoStatusBlock: PIO_STATUS_BLOCK;
  388. ShareAccess: ULONG;
  389. OpenOptions: ULONG): NTSTATUS; stdcall;
  390. //
  391. // use the Win32 API instead
  392. // DeviceIoControl
  393. //
  394. function NtDeviceIoControlFile (
  395. FileHandle: HANDLE;
  396. Event: HANDLE;
  397. ApcRoutine: PIO_APC_ROUTINE;
  398. ApcContext: PVOID;
  399. IoStatusBlock: PIO_STATUS_BLOCK;
  400. IoControlCode: ULONG;
  401. InputBuffer: PVOID;
  402. InputBufferLength: ULONG;
  403. OutputBuffer: PVOID;
  404. OutputBufferLength: ULONG): NTSTATUS; stdcall;
  405. //
  406. // use the Win32 API instead
  407. // WaitForSingleObjectEx
  408. //
  409. function NtWaitForSingleObject (
  410. Handle: HANDLE;
  411. Alertable: BOOLEAN;
  412. Timeout: PLARGE_INTEGER): NTSTATUS; stdcall;
  413. //
  414. // use the Win32 API instead
  415. // CheckNameLegalDOS8Dot3
  416. //
  417. function RtlIsNameLegalDOS8Dot3 (
  418. Name: PUNICODE_STRING;
  419. OemName: POEM_STRING;
  420. NameContainsSpaces: PBOOLEAN): BOOLEAN; stdcall;
  421. //
  422. // This function might be needed for some of the internal Windows functions,
  423. // defined in this header file.
  424. //
  425. function RtlNtStatusToDosError(Status: NTSTATUS): ULONG; stdcall;
  426. //
  427. // use the Win32 APIs instead
  428. // GetProcessHandleCount
  429. // GetProcessId
  430. //
  431. function NtQueryInformationProcess (
  432. ProcessHandle: HANDLE;
  433. ProcessInformationClass: PROCESSINFOCLASS;
  434. ProcessInformation: PVOID;
  435. ProcessInformationLength: ULONG;
  436. ReturnLength: PULONG): NTSTATUS; stdcall;
  437. //
  438. // use the Win32 API instead
  439. // GetThreadIOPendingFlag
  440. //
  441. function NtQueryInformationThread (
  442. ThreadHandle: HANDLE;
  443. ThreadInformationClass: THREADINFOCLASS;
  444. ThreadInformation: PVOID;
  445. ThreadInformationLength: ULONG;
  446. ReturnLength: PULONG): NTSTATUS; stdcall;
  447. //
  448. // use the Win32 APIs instead
  449. // GetSystemRegistryQuota
  450. // GetSystemTimes
  451. // use the CryptoAPIs instead for generating random data
  452. // CryptGenRandom
  453. //
  454. function NtQuerySystemInformation (
  455. SystemInformationClass: SYSTEM_INFORMATION_CLASS;
  456. SystemInformation: PVOID;
  457. SystemInformationLength: ULONG;
  458. ReturnLength: PULONG): NTSTATUS; stdcall;
  459. //
  460. // use the Win32 API instead
  461. // GetSystemTimeAsFileTime
  462. //
  463. function NtQuerySystemTime (SystemTime: PLARGE_INTEGER): NTSTATUS; stdcall;
  464. //
  465. // use the Win32 API instead
  466. // LocalFileTimeToFileTime
  467. //
  468. function RtlLocalTimeToSystemTime(
  469. LocalTime: PLARGE_INTEGER;
  470. SystemTime: PLARGE_INTEGER): NTSTATUS; stdcall;
  471. //
  472. // use the Win32 API instead
  473. // SystemTimeToFileTime to convert to FILETIME structures
  474. // copy the resulting FILETIME structures to ULARGE_INTEGER structures
  475. // perform the calculation
  476. //
  477. function RtlTimeToSecondsSince1970(
  478. Time: PLARGE_INTEGER;
  479. ElapsedSeconds: PULONG): BOOLEAN; stdcall;
  480. //
  481. // These APIs might be need for some of the internal Windows functions,
  482. // defined in this header file.
  483. //
  484. procedure RtlFreeAnsiString(AnsiString: PANSI_STRING); stdcall;
  485. procedure RtlFreeUnicodeString(UnicodeString: PUNICODE_STRING); stdcall;
  486. procedure RtlFreeOemString(OemString: POEM_STRING); stdcall;
  487. procedure RtlInitString(DestinationString: PSTRING; SourceString: PCSZ); stdcall;
  488. procedure RtlInitAnsiString(DestinationString: PANSI_STRING; SourceString: PCSZ); stdcall;
  489. procedure RtlInitUnicodeString(DestinationString: PUNICODE_STRING; SourceString: PWSTR); stdcall;
  490. function RtlAnsiStringToUnicodeString(
  491. DestinationString: PUNICODE_STRING;
  492. SourceString: PCANSI_STRING;
  493. AllocateDestinationString: BOOLEAN): NTSTATUS; stdcall;
  494. function RtlUnicodeStringToAnsiString(
  495. DestinationString: PANSI_STRING;
  496. SourceString: PCUNICODE_STRING;
  497. AllocateDestinationString: BOOLEAN): NTSTATUS; stdcall;
  498. function RtlUnicodeStringToOemString(
  499. DestinationString: POEM_STRING;
  500. SourceString: PCUNICODE_STRING;
  501. AllocateDestinationString: BOOLEAN): NTSTATUS; stdcall;
  502. //
  503. // Use the Win32 API instead
  504. // WideCharToMultiByte
  505. // set CodePage to CP_ACP
  506. // set cbMultiByte to 0
  507. //
  508. function RtlUnicodeToMultiByteSize(
  509. BytesInMultiByteString: PULONG;
  510. UnicodeString: PWSTR;
  511. BytesInUnicodeString: ULONG): NTSTATUS; stdcall;
  512. //
  513. // Use the C runtime function instead
  514. // strtol
  515. //
  516. function RtlCharToInteger(Str: PCSZ; Base: ULONG; Value: PULONG): NTSTATUS; stdcall;
  517. //
  518. // use the Win32 API instead
  519. // ConvertSidToStringSid
  520. //
  521. function RtlConvertSidToUnicodeString(
  522. UnicodeString: PUNICODE_STRING;
  523. Sid: PSID;
  524. AllocateDestinationString: BOOLEAN): NTSTATUS; stdcall;
  525. //
  526. // use the CryptoAPIs instead
  527. // CryptGenRandom
  528. //
  529. function RtlUniform(Seed: PULONG): ULONG; stdcall;
  530. //
  531. // Use the default built-in system exception handling instead of these
  532. // functions
  533. //
  534. procedure RtlUnwind(
  535. TargetFrame: PVOID;
  536. TargetIp: PVOID;
  537. ExceptionRecord: PEXCEPTION_RECORD;
  538. ReturnValue: PVOID); stdcall;
  539. {$IFDEF _M_IA64}
  540. VOID
  541. RtlUnwind2 (
  542. IN FRAME_POINTERS TargetFrame OPTIONAL,
  543. IN PVOID TargetIp OPTIONAL,
  544. IN PEXCEPTION_RECORD ExceptionRecord OPTIONAL,
  545. IN PVOID ReturnValue,
  546. IN PCONTEXT ContextRecord
  547. );
  548. VOID
  549. RtlUnwindEx (
  550. IN FRAME_POINTERS TargetFrame OPTIONAL,
  551. IN PVOID TargetIp OPTIONAL,
  552. IN PEXCEPTION_RECORD ExceptionRecord OPTIONAL,
  553. IN PVOID ReturnValue,
  554. IN PCONTEXT ContextRecord,
  555. IN PUNWIND_HISTORY_TABLE HistoryTable OPTIONAL
  556. );
  557. {$ENDIF _M_IA64}
  558. const
  559. LOGONID_CURRENT = ULONG(-1);
  560. SERVERNAME_CURRENT = 0;
  561. WinStationInformation = 8;
  562. type
  563. _WINSTATIONINFOCLASS = DWORD;
  564. WINSTATIONINFOCLASS = _WINSTATIONINFOCLASS;
  565. TWinStationInfoClass = WINSTATIONINFOCLASS;
  566. _WINSTATIONINFORMATIONW = record
  567. Reserved2: array [0..69] of Byte;
  568. LogonId: ULONG;
  569. Reserved3: array [0..1139] of Byte;
  570. end;
  571. WINSTATIONINFORMATIONW = _WINSTATIONINFORMATIONW;
  572. PWINSTATIONINFORMATIONW = ^WINSTATIONINFORMATIONW;
  573. TWinStationInformationW = WINSTATIONINFORMATIONW;
  574. //
  575. // this function is implemented in winsta.dll (you need to loadlibrary to call this function)
  576. // this internal function retrives the LogonId (also called SessionId) for the current process
  577. // You should avoid using this function as it can change. you can retrieve the same information
  578. // Using public api WTSQuerySessionInformation. Pass WTSSessionId as the WTSInfoClass parameter
  579. //
  580. type
  581. PWINSTATIONQUERYINFORMATIONW = function (p1: HANDLE; p2: ULONG; p3: WINSTATIONINFOCLASS; p4: PVOID; p5: ULONG; p6: PULONG): BOOLEAN; stdcall;
  582. implementation
  583. uses
  584. JwaWinDLLNames;
  585. {$IFDEF WINXP}
  586. function INTERNAL_TS_ACTIVE_CONSOLE_ID: ULONG;
  587. begin
  588. Result := PULONG($7ffe02d8)^; // ( *((volatile ULONG*)(0x7ffe02d8)) )
  589. end;
  590. {$ENDIF WINXP}
  591. {$IFDEF DYNAMIC_LINK}
  592. function NtClose;
  593. begin
  594. GetProcedureAddress(_NtClose, winternl_lib, 'NtClose');
  595. asm
  596. MOV ESP, EBP
  597. POP EBP
  598. JMP [_NtClose]
  599. end;
  600. end;
  601. function NtCreateFile;
  602. begin
  603. GetProcedureAddress(_,NtCreateFile winternl_lib, 'NtCreateFile');
  604. asm
  605. MOV ESP, EBP
  606. POP EBP
  607. JMP [_NtCreateFile]
  608. end;
  609. end;
  610. function NtOpenFile;
  611. begin
  612. GetProcedureAddress(_NtOpenFile, winternl_lib, 'NtOpenFile');
  613. asm
  614. MOV ESP, EBP
  615. POP EBP
  616. JMP [_NtOpenFile]
  617. end;
  618. end;
  619. function NtDeviceIoControlFile;
  620. begin
  621. GetProcedureAddress(_NtDeviceIoControlFile, winternl_lib, 'NtDeviceIoControlFile');
  622. asm
  623. MOV ESP, EBP
  624. POP EBP
  625. JMP [_NtDeviceIoControlFile]
  626. end;
  627. end;
  628. function NtWaitForSingleObject;
  629. begin
  630. GetProcedureAddress(_NtWaitForSingleObject, winternl_lib, 'NtWaitForSingleObject');
  631. asm
  632. MOV ESP, EBP
  633. POP EBP
  634. JMP [_NtWaitForSingleObject]
  635. end;
  636. end;
  637. function RtlIsNameLegalDOS8Dot3;
  638. begin
  639. GetProcedureAddress(_RtlIsNameLegalDOS8Dot3, winternl_lib, 'RtlIsNameLegalDOS8Dot3');
  640. asm
  641. MOV ESP, EBP
  642. POP EBP
  643. JMP [_RtlIsNameLegalDOS8Dot3]
  644. end;
  645. end;
  646. function RtlNtStatusToDosError;
  647. begin
  648. GetProcedureAddress(_RtlNtStatusToDosError, winternl_lib, 'RtlNtStatusToDosError');
  649. asm
  650. MOV ESP, EBP
  651. POP EBP
  652. JMP [_RtlNtStatusToDosError]
  653. end;
  654. end;
  655. function NtQueryInformationProcess;
  656. begin
  657. GetProcedureAddress(_NtQueryInformationProcess, winternl_lib, 'NtQueryInformationProcess');
  658. asm
  659. MOV ESP, EBP
  660. POP EBP
  661. JMP [_NtQueryInformationProcess]
  662. end;
  663. end;
  664. function NtQueryInformationThread;
  665. begin
  666. GetProcedureAddress(_NtQueryInformationThread, winternl_lib, 'NtQueryInformationThread');
  667. asm
  668. MOV ESP, EBP
  669. POP EBP
  670. JMP [_NtQueryInformationThread]
  671. end;
  672. end;
  673. function NtQuerySystemInformation;
  674. begin
  675. GetProcedureAddress(_NtQuerySystemInformation, winternl_lib, 'NtQuerySystemInformation');
  676. asm
  677. MOV ESP, EBP
  678. POP EBP
  679. JMP [_NtQuerySystemInformation]
  680. end;
  681. end;
  682. function NtQuerySystemTime;
  683. begin
  684. GetProcedureAddress(_NtQuerySystemTime, winternl_lib, 'NtQuerySystemTime');
  685. asm
  686. MOV ESP, EBP
  687. POP EBP
  688. JMP [_NtQuerySystemTime]
  689. end;
  690. end;
  691. function RtlLocalTimeToSystemTime;
  692. begin
  693. GetProcedureAddress(_RtlLocalTimeToSystemTime, winternl_lib, 'RtlLocalTimeToSystemTime');
  694. asm
  695. MOV ESP, EBP
  696. POP EBP
  697. JMP [_RtlLocalTimeToSystemTime]
  698. end;
  699. end;
  700. function RtlTimeToSecondsSince1970;
  701. begin
  702. GetProcedureAddress(_RtlTimeToSecondsSince1970, winternl_lib, 'RtlTimeToSecondsSince1970');
  703. asm
  704. MOV ESP, EBP
  705. POP EBP
  706. JMP [_RtlTimeToSecondsSince1970]
  707. end;
  708. end;
  709. function RtlFreeAnsiString;
  710. begin
  711. GetProcedureAddress(_RtlFreeAnsiString, winternl_lib, 'RtlFreeAnsiString');
  712. asm
  713. MOV ESP, EBP
  714. POP EBP
  715. JMP [_RtlFreeAnsiString]
  716. end;
  717. end;
  718. function RtlFreeUnicodeString;
  719. begin
  720. GetProcedureAddress(_RtlFreeUnicodeString, winternl_lib, 'RtlFreeUnicodeString');
  721. asm
  722. MOV ESP, EBP
  723. POP EBP
  724. JMP [_RtlFreeUnicodeString]
  725. end;
  726. end;
  727. function RtlFreeOemString;
  728. begin
  729. GetProcedureAddress(_RtlFreeOemString, winternl_lib, 'RtlFreeOemString');
  730. asm
  731. MOV ESP, EBP
  732. POP EBP
  733. JMP [_RtlFreeOemString]
  734. end;
  735. end;
  736. function RtlInitString;
  737. begin
  738. GetProcedureAddress(_RtlInitString, winternl_lib, 'RtlInitString');
  739. asm
  740. MOV ESP, EBP
  741. POP EBP
  742. JMP [_RtlInitString]
  743. end;
  744. end;
  745. function RtlInitAnsiString;
  746. begin
  747. GetProcedureAddress(_RtlInitAnsiString, winternl_lib, 'RtlInitAnsiString');
  748. asm
  749. MOV ESP, EBP
  750. POP EBP
  751. JMP [_RtlInitAnsiString]
  752. end;
  753. end;
  754. function RtlInitUnicodeString;
  755. begin
  756. GetProcedureAddress(_RtlInitUnicodeString, winternl_lib, 'RtlInitUnicodeString');
  757. asm
  758. MOV ESP, EBP
  759. POP EBP
  760. JMP [_RtlInitUnicodeString]
  761. end;
  762. end;
  763. function RtlAnsiStringToUnicodeString;
  764. begin
  765. GetProcedureAddress(_RtlAnsiStringToUnicodeString, winternl_lib, 'RtlAnsiStringToUnicodeString');
  766. asm
  767. MOV ESP, EBP
  768. POP EBP
  769. JMP [_RtlAnsiStringToUnicodeString]
  770. end;
  771. end;
  772. function RtlUnicodeStringToAnsiString;
  773. begin
  774. GetProcedureAddress(_RtlUnicodeStringToAnsiString, winternl_lib, 'RtlUnicodeStringToAnsiString');
  775. asm
  776. MOV ESP, EBP
  777. POP EBP
  778. JMP [_RtlUnicodeStringToAnsiString]
  779. end;
  780. end;
  781. function RtlUnicodeStringToOemString;
  782. begin
  783. GetProcedureAddress(_RtlUnicodeStringToOemString, winternl_lib, 'RtlUnicodeStringToOemString');
  784. asm
  785. MOV ESP, EBP
  786. POP EBP
  787. JMP [_RtlUnicodeStringToOemString]
  788. end;
  789. end;
  790. function RtlUnicodeToMultiByteSize;
  791. begin
  792. GetProcedureAddress(_RtlUnicodeToMultiByteSize, winternl_lib, 'RtlUnicodeToMultiByteSize');
  793. asm
  794. MOV ESP, EBP
  795. POP EBP
  796. JMP [_RtlUnicodeToMultiByteSize]
  797. end;
  798. end;
  799. function RtlCharToInteger;
  800. begin
  801. GetProcedureAddress(_RtlCharToInteger, winternl_lib, 'RtlCharToInteger');
  802. asm
  803. MOV ESP, EBP
  804. POP EBP
  805. JMP [_RtlCharToInteger]
  806. end;
  807. end;
  808. function RtlConvertSidToUnicodeString;
  809. begin
  810. GetProcedureAddress(_RtlConvertSidToUnicodeString, winternl_lib, 'RtlConvertSidToUnicodeString');
  811. asm
  812. MOV ESP, EBP
  813. POP EBP
  814. JMP [_RtlConvertSidToUnicodeString]
  815. end;
  816. end;
  817. function RtlUniform;
  818. begin
  819. GetProcedureAddress(_RtlUniform, winternl_lib, 'RtlUniform');
  820. asm
  821. MOV ESP, EBP
  822. POP EBP
  823. JMP [_RtlUniform]
  824. end;
  825. end;
  826. function RtlUnwind;
  827. begin
  828. GetProcedureAddress(_RtlUnwind, winternl_lib, 'RtlUnwind');
  829. asm
  830. MOV ESP, EBP
  831. POP EBP
  832. JMP [_RtlUnwind]
  833. end;
  834. end;
  835. {$ELSE}
  836. function NtClose; external winternl_lib name 'NtClose';
  837. function NtCreateFile; external winternl_lib name 'NtCreateFile';
  838. function NtOpenFile; external winternl_lib name 'NtOpenFile';
  839. function NtDeviceIoControlFile; external winternl_lib name 'NtDeviceIoControlFile';
  840. function NtWaitForSingleObject; external winternl_lib name 'NtWaitForSingleObject';
  841. function RtlIsNameLegalDOS8Dot3; external winternl_lib name 'RtlIsNameLegalDOS8Dot3';
  842. function RtlNtStatusToDosError; external winternl_lib name 'RtlNtStatusToDosError';
  843. function NtQueryInformationProcess; external winternl_lib name 'NtQueryInformationProcess';
  844. function NtQueryInformationThread; external winternl_lib name 'NtQueryInformationThread';
  845. function NtQuerySystemInformation; external winternl_lib name 'NtQuerySystemInformation';
  846. function NtQuerySystemTime; external winternl_lib name 'NtQuerySystemTime';
  847. function RtlLocalTimeToSystemTime; external winternl_lib name 'RtlLocalTimeToSystemTime';
  848. function RtlTimeToSecondsSince1970; external winternl_lib name 'RtlTimeToSecondsSince1970';
  849. procedure RtlFreeAnsiString; external winternl_lib name 'RtlFreeAnsiString';
  850. procedure RtlFreeUnicodeString; external winternl_lib name 'RtlFreeUnicodeString';
  851. procedure RtlFreeOemString; external winternl_lib name 'RtlFreeOemString';
  852. procedure RtlInitString; external winternl_lib name 'RtlInitString';
  853. procedure RtlInitAnsiString; external winternl_lib name 'RtlInitAnsiString';
  854. procedure RtlInitUnicodeString; external winternl_lib name 'RtlInitUnicodeString';
  855. function RtlAnsiStringToUnicodeString; external winternl_lib name 'RtlAnsiStringToUnicodeString';
  856. function RtlUnicodeStringToAnsiString; external winternl_lib name 'RtlUnicodeStringToAnsiString';
  857. function RtlUnicodeStringToOemString; external winternl_lib name 'RtlUnicodeStringToOemString';
  858. function RtlUnicodeToMultiByteSize; external winternl_lib name 'RtlUnicodeToMultiByteSize';
  859. function RtlCharToInteger; external winternl_lib name 'RtlCharToInteger';
  860. function RtlConvertSidToUnicodeString; external winternl_lib name 'RtlConvertSidToUnicodeString';
  861. function RtlUniform; external winternl_lib name 'RtlUniform';
  862. procedure RtlUnwind; external winternl_lib name 'RtlUnwind';
  863. {$ENDIF DYNAMIC_LINK}
  864. {$IFDEF _M_IA64}
  865. RtlUnwind2
  866. RtlUnwindEx
  867. {$ENDIF _M_IA64}
  868. end.