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.

3895 lines
92 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. vfzwapi.c
  5. Abstract:
  6. Zw interfaces verifier.
  7. Author:
  8. Silviu Calinoiu (silviuc) 23-Jul-2002
  9. Revision History:
  10. --*/
  11. #include "vfdef.h"
  12. #include "zwapi.h"
  13. #include "vfzwapi.h"
  14. VOID
  15. VfZwCheckAddress (
  16. PVOID Address,
  17. PVOID Caller
  18. );
  19. VOID
  20. VfZwCheckHandle (
  21. PVOID Handle,
  22. PVOID Caller
  23. );
  24. VOID
  25. VfZwCheckObjectAttributes (
  26. POBJECT_ATTRIBUTES ObjectAttributes,
  27. PVOID Caller
  28. );
  29. VOID
  30. VfZwCheckUnicodeString (
  31. PUNICODE_STRING String,
  32. PVOID Caller
  33. );
  34. LOGICAL
  35. VfZwShouldCheck (
  36. PVOID Caller
  37. );
  38. VOID
  39. VfZwReportIssue (
  40. ULONG IssueType,
  41. PVOID Information,
  42. PVOID Caller
  43. );
  44. LOGICAL
  45. VfZwShouldReportIssue (
  46. PVOID Caller
  47. );
  48. LOGICAL
  49. VfZwShouldSimulateDecommitAttack (
  50. VOID
  51. );
  52. ULONG
  53. VfZwExceptionFilter (
  54. PVOID ExceptionInfo
  55. );
  56. VOID
  57. VfZwReportUserModeVirtualSpaceOperation (
  58. PVOID Caller
  59. );
  60. #define VF_ZW_CHECK_ADDRESS(Address) try {VfZwCheckAddress(Address, Caller);}except(VfZwExceptionFilter(_exception_info())){}
  61. #define VF_ZW_CHECK_HANDLE(Handle) try {VfZwCheckHandle(Handle, Caller);}except(VfZwExceptionFilter(_exception_info())){}
  62. #define VF_ZW_CHECK_OBJECT_ATTRIBUTES(A) try {VfZwCheckObjectAttributes(A, Caller);}except(VfZwExceptionFilter(_exception_info())){}
  63. #define VF_ZW_CHECK_UNICODE_STRING(S) try {VfZwCheckUnicodeString(S, Caller);}except(VfZwExceptionFilter(_exception_info())){}
  64. //
  65. // Put all verifier globals into the verifier data section so
  66. // that it can be paged out whenever verifier is not enabled.
  67. // Note that this declaration affects all global declarations
  68. // within the module since there is no `data_seg()' counterpart.
  69. //
  70. #ifdef ALLOC_DATA_PRAGMA
  71. #pragma data_seg("PAGEVRFD")
  72. #endif
  73. /////////////////////////////////////////////////////////////////////
  74. /////////////////////////////////////////////////////////////////////
  75. /////////////////////////////////////////////////////////////////////
  76. #ifdef ALLOC_PRAGMA
  77. #pragma alloc_text(PAGEVRFY, VfZwShouldCheck)
  78. #pragma alloc_text(PAGEVRFY, VfZwReportIssue)
  79. #pragma alloc_text(PAGEVRFY, VfZwShouldReportIssue)
  80. #pragma alloc_text(PAGEVRFY, VfZwExceptionFilter)
  81. #pragma alloc_text(PAGEVRFY, VfZwReportUserModeVirtualSpaceOperation)
  82. #pragma alloc_text(PAGEVRFY, VfZwShouldSimulateDecommitAttack)
  83. #pragma alloc_text(PAGEVRFY, VfZwCheckAddress)
  84. #pragma alloc_text(PAGEVRFY, VfZwCheckHandle)
  85. #pragma alloc_text(PAGEVRFY, VfZwCheckObjectAttributes)
  86. #pragma alloc_text(PAGEVRFY, VfZwCheckUnicodeString)
  87. #pragma alloc_text(PAGEVRFY, VfZwAccessCheckAndAuditAlarm)
  88. #pragma alloc_text(PAGEVRFY, VfZwAddBootEntry)
  89. #pragma alloc_text(PAGEVRFY, VfZwAddDriverEntry)
  90. #pragma alloc_text(PAGEVRFY, VfZwAdjustPrivilegesToken)
  91. #pragma alloc_text(PAGEVRFY, VfZwAlertThread)
  92. #pragma alloc_text(PAGEVRFY, VfZwAllocateVirtualMemory)
  93. #pragma alloc_text(PAGEVRFY, VfZwAssignProcessToJobObject)
  94. #pragma alloc_text(PAGEVRFY, VfZwCancelIoFile)
  95. #pragma alloc_text(PAGEVRFY, VfZwCancelTimer)
  96. #pragma alloc_text(PAGEVRFY, VfZwClearEvent)
  97. #pragma alloc_text(PAGEVRFY, VfZwClose)
  98. #pragma alloc_text(PAGEVRFY, VfZwCloseObjectAuditAlarm)
  99. #pragma alloc_text(PAGEVRFY, VfZwConnectPort)
  100. #pragma alloc_text(PAGEVRFY, VfZwCreateDirectoryObject)
  101. #pragma alloc_text(PAGEVRFY, VfZwCreateEvent)
  102. #pragma alloc_text(PAGEVRFY, VfZwCreateFile)
  103. #pragma alloc_text(PAGEVRFY, VfZwCreateJobObject)
  104. #pragma alloc_text(PAGEVRFY, VfZwCreateKey)
  105. #pragma alloc_text(PAGEVRFY, VfZwCreateSection)
  106. #pragma alloc_text(PAGEVRFY, VfZwCreateSymbolicLinkObject)
  107. #pragma alloc_text(PAGEVRFY, VfZwCreateTimer)
  108. #pragma alloc_text(PAGEVRFY, VfZwDeleteBootEntry)
  109. #pragma alloc_text(PAGEVRFY, VfZwDeleteDriverEntry)
  110. #pragma alloc_text(PAGEVRFY, VfZwDeleteFile)
  111. #pragma alloc_text(PAGEVRFY, VfZwDeleteKey)
  112. #pragma alloc_text(PAGEVRFY, VfZwDeleteValueKey)
  113. #pragma alloc_text(PAGEVRFY, VfZwDeviceIoControlFile)
  114. #pragma alloc_text(PAGEVRFY, VfZwDisplayString)
  115. #pragma alloc_text(PAGEVRFY, VfZwDuplicateObject)
  116. #pragma alloc_text(PAGEVRFY, VfZwDuplicateToken)
  117. #pragma alloc_text(PAGEVRFY, VfZwEnumerateBootEntries)
  118. #pragma alloc_text(PAGEVRFY, VfZwEnumerateDriverEntries)
  119. #pragma alloc_text(PAGEVRFY, VfZwEnumerateKey)
  120. #pragma alloc_text(PAGEVRFY, VfZwEnumerateValueKey)
  121. #pragma alloc_text(PAGEVRFY, VfZwFlushInstructionCache)
  122. #pragma alloc_text(PAGEVRFY, VfZwFlushKey)
  123. #pragma alloc_text(PAGEVRFY, VfZwFlushVirtualMemory)
  124. #pragma alloc_text(PAGEVRFY, VfZwFreeVirtualMemory)
  125. #pragma alloc_text(PAGEVRFY, VfZwFsControlFile)
  126. #pragma alloc_text(PAGEVRFY, VfZwInitiatePowerAction)
  127. #pragma alloc_text(PAGEVRFY, VfZwIsProcessInJob)
  128. #pragma alloc_text(PAGEVRFY, VfZwLoadDriver)
  129. #pragma alloc_text(PAGEVRFY, VfZwLoadKey)
  130. #pragma alloc_text(PAGEVRFY, VfZwMakeTemporaryObject)
  131. #pragma alloc_text(PAGEVRFY, VfZwMapViewOfSection)
  132. #pragma alloc_text(PAGEVRFY, VfZwModifyBootEntry)
  133. #pragma alloc_text(PAGEVRFY, VfZwModifyDriverEntry)
  134. #pragma alloc_text(PAGEVRFY, VfZwNotifyChangeKey)
  135. #pragma alloc_text(PAGEVRFY, VfZwOpenDirectoryObject)
  136. #pragma alloc_text(PAGEVRFY, VfZwOpenEvent)
  137. #pragma alloc_text(PAGEVRFY, VfZwOpenFile)
  138. #pragma alloc_text(PAGEVRFY, VfZwOpenJobObject)
  139. #pragma alloc_text(PAGEVRFY, VfZwOpenKey)
  140. #pragma alloc_text(PAGEVRFY, VfZwOpenProcess)
  141. #pragma alloc_text(PAGEVRFY, VfZwOpenProcessToken)
  142. #pragma alloc_text(PAGEVRFY, VfZwOpenProcessTokenEx)
  143. #pragma alloc_text(PAGEVRFY, VfZwOpenSection)
  144. #pragma alloc_text(PAGEVRFY, VfZwOpenSymbolicLinkObject)
  145. #pragma alloc_text(PAGEVRFY, VfZwOpenThread)
  146. #pragma alloc_text(PAGEVRFY, VfZwOpenThreadToken)
  147. #pragma alloc_text(PAGEVRFY, VfZwOpenThreadTokenEx)
  148. #pragma alloc_text(PAGEVRFY, VfZwOpenTimer)
  149. #pragma alloc_text(PAGEVRFY, VfZwPowerInformation)
  150. #pragma alloc_text(PAGEVRFY, VfZwPulseEvent)
  151. #pragma alloc_text(PAGEVRFY, VfZwQueryBootEntryOrder)
  152. #pragma alloc_text(PAGEVRFY, VfZwQueryBootOptions)
  153. #pragma alloc_text(PAGEVRFY, VfZwQueryDefaultLocale)
  154. #pragma alloc_text(PAGEVRFY, VfZwQueryDefaultUILanguage)
  155. #pragma alloc_text(PAGEVRFY, VfZwQueryDriverEntryOrder)
  156. #pragma alloc_text(PAGEVRFY, VfZwQueryInstallUILanguage)
  157. #pragma alloc_text(PAGEVRFY, VfZwQueryDirectoryFile)
  158. #pragma alloc_text(PAGEVRFY, VfZwQueryDirectoryObject)
  159. #pragma alloc_text(PAGEVRFY, VfZwQueryEaFile)
  160. #pragma alloc_text(PAGEVRFY, VfZwQueryFullAttributesFile)
  161. #pragma alloc_text(PAGEVRFY, VfZwQueryInformationFile)
  162. #pragma alloc_text(PAGEVRFY, VfZwQueryInformationJobObject)
  163. #pragma alloc_text(PAGEVRFY, VfZwQueryInformationProcess)
  164. #pragma alloc_text(PAGEVRFY, VfZwQueryInformationThread)
  165. #pragma alloc_text(PAGEVRFY, VfZwQueryInformationToken)
  166. #pragma alloc_text(PAGEVRFY, VfZwQueryInformationToken)
  167. #pragma alloc_text(PAGEVRFY, VfZwQueryKey)
  168. #pragma alloc_text(PAGEVRFY, VfZwQueryObject)
  169. #pragma alloc_text(PAGEVRFY, VfZwQuerySection)
  170. #pragma alloc_text(PAGEVRFY, VfZwQuerySecurityObject)
  171. #pragma alloc_text(PAGEVRFY, VfZwQuerySymbolicLinkObject)
  172. #pragma alloc_text(PAGEVRFY, VfZwQuerySystemInformation)
  173. #pragma alloc_text(PAGEVRFY, VfZwQueryValueKey)
  174. #pragma alloc_text(PAGEVRFY, VfZwQueryVolumeInformationFile)
  175. #pragma alloc_text(PAGEVRFY, VfZwReadFile)
  176. #pragma alloc_text(PAGEVRFY, VfZwReplaceKey)
  177. #pragma alloc_text(PAGEVRFY, VfZwRequestWaitReplyPort)
  178. #pragma alloc_text(PAGEVRFY, VfZwResetEvent)
  179. #pragma alloc_text(PAGEVRFY, VfZwRestoreKey)
  180. #pragma alloc_text(PAGEVRFY, VfZwSaveKey)
  181. #pragma alloc_text(PAGEVRFY, VfZwSaveKeyEx)
  182. #pragma alloc_text(PAGEVRFY, VfZwSetBootEntryOrder)
  183. #pragma alloc_text(PAGEVRFY, VfZwSetBootOptions)
  184. #pragma alloc_text(PAGEVRFY, VfZwSetDefaultLocale)
  185. #pragma alloc_text(PAGEVRFY, VfZwSetDefaultUILanguage)
  186. #pragma alloc_text(PAGEVRFY, VfZwSetDriverEntryOrder)
  187. #pragma alloc_text(PAGEVRFY, VfZwSetEaFile)
  188. #pragma alloc_text(PAGEVRFY, VfZwSetEvent)
  189. #pragma alloc_text(PAGEVRFY, VfZwSetInformationFile)
  190. #pragma alloc_text(PAGEVRFY, VfZwSetInformationJobObject)
  191. #pragma alloc_text(PAGEVRFY, VfZwSetInformationObject)
  192. #pragma alloc_text(PAGEVRFY, VfZwSetInformationProcess)
  193. #pragma alloc_text(PAGEVRFY, VfZwSetInformationThread)
  194. #pragma alloc_text(PAGEVRFY, VfZwSetSecurityObject)
  195. #pragma alloc_text(PAGEVRFY, VfZwSetSystemInformation)
  196. #pragma alloc_text(PAGEVRFY, VfZwSetSystemTime)
  197. #pragma alloc_text(PAGEVRFY, VfZwSetTimer)
  198. #pragma alloc_text(PAGEVRFY, VfZwSetValueKey)
  199. #pragma alloc_text(PAGEVRFY, VfZwSetVolumeInformationFile)
  200. #pragma alloc_text(PAGEVRFY, VfZwTerminateJobObject)
  201. #pragma alloc_text(PAGEVRFY, VfZwTerminateProcess)
  202. #pragma alloc_text(PAGEVRFY, VfZwTranslateFilePath)
  203. #pragma alloc_text(PAGEVRFY, VfZwUnloadDriver)
  204. #pragma alloc_text(PAGEVRFY, VfZwUnloadKey)
  205. #pragma alloc_text(PAGEVRFY, VfZwUnmapViewOfSection)
  206. #pragma alloc_text(PAGEVRFY, VfZwWaitForMultipleObjects)
  207. #pragma alloc_text(PAGEVRFY, VfZwWaitForSingleObject)
  208. #pragma alloc_text(PAGEVRFY, VfZwWriteFile)
  209. #pragma alloc_text(PAGEVRFY, VfZwYieldExecution)
  210. #endif
  211. /////////////////////////////////////////////////////////////////////
  212. /////////////////////////////////////////////////////////////////////
  213. /////////////////////////////////////////////////////////////////////
  214. //NTSYSAPI
  215. NTSTATUS
  216. NTAPI
  217. VfZwAccessCheckAndAuditAlarm (
  218. IN PUNICODE_STRING SubsystemName,
  219. IN PVOID HandleId,
  220. IN PUNICODE_STRING ObjectTypeName,
  221. IN PUNICODE_STRING ObjectName,
  222. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  223. IN ACCESS_MASK DesiredAccess,
  224. IN PGENERIC_MAPPING GenericMapping,
  225. IN BOOLEAN ObjectCreation,
  226. OUT PACCESS_MASK GrantedAccess,
  227. OUT PNTSTATUS AccessStatus,
  228. OUT PBOOLEAN GenerateOnClose
  229. )
  230. {
  231. NTSTATUS Status;
  232. PVOID Caller = _ReturnAddress();
  233. if (VfZwShouldCheck (Caller)) {
  234. VF_ZW_CHECK_UNICODE_STRING (SubsystemName);
  235. VF_ZW_CHECK_UNICODE_STRING (ObjectTypeName);
  236. VF_ZW_CHECK_UNICODE_STRING (ObjectName);
  237. VF_ZW_CHECK_ADDRESS (SecurityDescriptor);
  238. VF_ZW_CHECK_ADDRESS (GenericMapping);
  239. VF_ZW_CHECK_ADDRESS (GrantedAccess);
  240. VF_ZW_CHECK_ADDRESS (GenerateOnClose);
  241. }
  242. Status = ZwAccessCheckAndAuditAlarm (SubsystemName,
  243. HandleId,
  244. ObjectTypeName,
  245. ObjectName,
  246. SecurityDescriptor,
  247. DesiredAccess,
  248. GenericMapping,
  249. ObjectCreation,
  250. GrantedAccess,
  251. AccessStatus,
  252. GenerateOnClose);
  253. return Status;
  254. }
  255. //NTSYSAPI
  256. NTSTATUS
  257. NTAPI
  258. VfZwAddBootEntry (
  259. IN PBOOT_ENTRY BootEntry,
  260. OUT PULONG Id OPTIONAL
  261. )
  262. {
  263. NTSTATUS Status;
  264. PVOID Caller = _ReturnAddress();
  265. if (VfZwShouldCheck (Caller)) {
  266. VF_ZW_CHECK_ADDRESS (BootEntry);
  267. VF_ZW_CHECK_ADDRESS (Id);
  268. }
  269. Status = ZwAddBootEntry (BootEntry,
  270. Id);
  271. return Status;
  272. }
  273. //NTSYSAPI
  274. NTSTATUS
  275. NTAPI
  276. VfZwAddDriverEntry (
  277. IN PEFI_DRIVER_ENTRY DriverEntry,
  278. OUT PULONG Id OPTIONAL
  279. )
  280. {
  281. NTSTATUS Status;
  282. PVOID Caller = _ReturnAddress();
  283. if (VfZwShouldCheck (Caller)) {
  284. VF_ZW_CHECK_ADDRESS (DriverEntry);
  285. VF_ZW_CHECK_ADDRESS (Id);
  286. }
  287. Status = ZwAddDriverEntry (DriverEntry,
  288. Id);
  289. return Status;
  290. }
  291. //NTSYSAPI
  292. NTSTATUS
  293. NTAPI
  294. VfZwAdjustPrivilegesToken (
  295. IN HANDLE TokenHandle,
  296. IN BOOLEAN DisableAllPrivileges,
  297. IN PTOKEN_PRIVILEGES NewState OPTIONAL,
  298. IN ULONG BufferLength OPTIONAL,
  299. OUT PTOKEN_PRIVILEGES PreviousState OPTIONAL,
  300. OUT PULONG ReturnLength
  301. )
  302. {
  303. NTSTATUS Status;
  304. PVOID Caller = _ReturnAddress();
  305. if (VfZwShouldCheck (Caller)) {
  306. VF_ZW_CHECK_HANDLE (TokenHandle);
  307. VF_ZW_CHECK_ADDRESS (NewState);
  308. VF_ZW_CHECK_ADDRESS (PreviousState);
  309. VF_ZW_CHECK_ADDRESS (ReturnLength);
  310. }
  311. Status = ZwAdjustPrivilegesToken (TokenHandle,
  312. DisableAllPrivileges,
  313. NewState OPTIONAL,
  314. BufferLength OPTIONAL,
  315. PreviousState OPTIONAL,
  316. ReturnLength);
  317. return Status;
  318. }
  319. //NTSYSAPI
  320. NTSTATUS
  321. NTAPI
  322. VfZwAlertThread(
  323. IN HANDLE ThreadHandle
  324. )
  325. {
  326. NTSTATUS Status;
  327. PVOID Caller = _ReturnAddress();
  328. if (VfZwShouldCheck (Caller)) {
  329. VF_ZW_CHECK_HANDLE (ThreadHandle);
  330. }
  331. Status = ZwAlertThread (ThreadHandle);
  332. return Status;
  333. }
  334. //NTSYSAPI
  335. NTSTATUS
  336. NTAPI
  337. VfZwAllocateVirtualMemory(
  338. IN HANDLE ProcessHandle,
  339. IN OUT PVOID *BaseAddress,
  340. IN ULONG_PTR ZeroBits,
  341. IN OUT PSIZE_T RegionSize,
  342. IN ULONG AllocationType,
  343. IN ULONG Protect
  344. )
  345. {
  346. NTSTATUS Status;
  347. PVOID Caller = _ReturnAddress();
  348. if (VfZwShouldCheck (Caller)) {
  349. VF_ZW_CHECK_HANDLE (ProcessHandle);
  350. VF_ZW_CHECK_ADDRESS (BaseAddress);
  351. VF_ZW_CHECK_ADDRESS (RegionSize);
  352. VfZwReportUserModeVirtualSpaceOperation (Caller);
  353. if (VfZwShouldSimulateDecommitAttack() &&
  354. Protect == PAGE_READWRITE) {
  355. DbgPrint ("DVRF:ZW: simulating decommit attack for caller %p \n", Caller);
  356. Protect = PAGE_READONLY;
  357. }
  358. }
  359. Status = ZwAllocateVirtualMemory (ProcessHandle,
  360. BaseAddress,
  361. ZeroBits,
  362. RegionSize,
  363. AllocationType,
  364. Protect);
  365. return Status;
  366. }
  367. //NTSYSAPI
  368. NTSTATUS
  369. NTAPI
  370. VfZwAssignProcessToJobObject(
  371. IN HANDLE JobHandle,
  372. IN HANDLE ProcessHandle
  373. )
  374. {
  375. NTSTATUS Status;
  376. PVOID Caller = _ReturnAddress();
  377. if (VfZwShouldCheck (Caller)) {
  378. VF_ZW_CHECK_HANDLE (JobHandle);
  379. VF_ZW_CHECK_HANDLE (ProcessHandle);
  380. }
  381. Status = ZwAssignProcessToJobObject (JobHandle,
  382. ProcessHandle);
  383. return Status;
  384. }
  385. //NTSYSAPI
  386. NTSTATUS
  387. NTAPI
  388. VfZwCancelIoFile(
  389. IN HANDLE FileHandle,
  390. OUT PIO_STATUS_BLOCK IoStatusBlock
  391. )
  392. {
  393. NTSTATUS Status;
  394. PVOID Caller = _ReturnAddress();
  395. if (VfZwShouldCheck (Caller)) {
  396. VF_ZW_CHECK_HANDLE (FileHandle);
  397. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  398. }
  399. Status = ZwCancelIoFile (FileHandle,
  400. IoStatusBlock);
  401. return Status;
  402. }
  403. //NTSYSAPI
  404. NTSTATUS
  405. NTAPI
  406. VfZwCancelTimer (
  407. IN HANDLE TimerHandle,
  408. OUT PBOOLEAN CurrentState OPTIONAL
  409. )
  410. {
  411. NTSTATUS Status;
  412. PVOID Caller = _ReturnAddress();
  413. if (VfZwShouldCheck (Caller)) {
  414. VF_ZW_CHECK_HANDLE (TimerHandle);
  415. VF_ZW_CHECK_ADDRESS (CurrentState);
  416. }
  417. Status = ZwCancelTimer (TimerHandle,
  418. CurrentState);
  419. return Status;
  420. }
  421. //NTSYSAPI
  422. NTSTATUS
  423. NTAPI
  424. VfZwClearEvent (
  425. IN HANDLE EventHandle
  426. )
  427. {
  428. NTSTATUS Status;
  429. PVOID Caller = _ReturnAddress();
  430. if (VfZwShouldCheck (Caller)) {
  431. VF_ZW_CHECK_HANDLE (EventHandle);
  432. }
  433. Status = ZwClearEvent (EventHandle);
  434. return Status;
  435. }
  436. //NTSYSAPI
  437. NTSTATUS
  438. NTAPI
  439. VfZwClose(
  440. IN HANDLE Handle
  441. )
  442. {
  443. NTSTATUS Status;
  444. PVOID Caller = _ReturnAddress();
  445. if (VfZwShouldCheck (Caller)) {
  446. VF_ZW_CHECK_HANDLE (Handle);
  447. }
  448. Status = ZwClose (Handle);
  449. return Status;
  450. }
  451. //NTSYSAPI
  452. NTSTATUS
  453. NTAPI
  454. VfZwCloseObjectAuditAlarm (
  455. IN PUNICODE_STRING SubsystemName,
  456. IN PVOID HandleId,
  457. IN BOOLEAN GenerateOnClose
  458. )
  459. {
  460. NTSTATUS Status;
  461. PVOID Caller = _ReturnAddress();
  462. if (VfZwShouldCheck (Caller)) {
  463. VF_ZW_CHECK_UNICODE_STRING (SubsystemName);
  464. }
  465. Status = ZwCloseObjectAuditAlarm (SubsystemName,
  466. HandleId,
  467. GenerateOnClose);
  468. return Status;
  469. }
  470. //NTSYSAPI
  471. NTSTATUS
  472. NTAPI
  473. VfZwConnectPort(
  474. OUT PHANDLE PortHandle,
  475. IN PUNICODE_STRING PortName,
  476. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos,
  477. IN OUT PPORT_VIEW ClientView OPTIONAL,
  478. IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL,
  479. OUT PULONG MaxMessageLength OPTIONAL,
  480. IN OUT PVOID ConnectionInformation OPTIONAL,
  481. IN OUT PULONG ConnectionInformationLength OPTIONAL
  482. )
  483. {
  484. NTSTATUS Status;
  485. PVOID Caller = _ReturnAddress();
  486. if (VfZwShouldCheck (Caller)) {
  487. VF_ZW_CHECK_ADDRESS (PortHandle);
  488. VF_ZW_CHECK_UNICODE_STRING (PortName);
  489. VF_ZW_CHECK_ADDRESS (SecurityQos);
  490. VF_ZW_CHECK_ADDRESS (ClientView);
  491. VF_ZW_CHECK_ADDRESS (ServerView);
  492. VF_ZW_CHECK_ADDRESS (MaxMessageLength);
  493. VF_ZW_CHECK_ADDRESS (ConnectionInformation);
  494. VF_ZW_CHECK_ADDRESS (ConnectionInformationLength);
  495. }
  496. Status = ZwConnectPort(PortHandle,
  497. PortName,
  498. SecurityQos,
  499. ClientView OPTIONAL,
  500. ServerView OPTIONAL,
  501. MaxMessageLength OPTIONAL,
  502. ConnectionInformation OPTIONAL,
  503. ConnectionInformationLength OPTIONAL);
  504. return Status;
  505. }
  506. //NTSYSAPI
  507. NTSTATUS
  508. NTAPI
  509. VfZwCreateDirectoryObject(
  510. OUT PHANDLE DirectoryHandle,
  511. IN ACCESS_MASK DesiredAccess,
  512. IN POBJECT_ATTRIBUTES ObjectAttributes
  513. )
  514. {
  515. NTSTATUS Status;
  516. PVOID Caller = _ReturnAddress();
  517. if (VfZwShouldCheck (Caller)) {
  518. VF_ZW_CHECK_ADDRESS (DirectoryHandle);
  519. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  520. }
  521. Status = ZwCreateDirectoryObject(DirectoryHandle,
  522. DesiredAccess,
  523. ObjectAttributes);
  524. return Status;
  525. }
  526. //NTSYSAPI
  527. NTSTATUS
  528. NTAPI
  529. VfZwCreateEvent (
  530. OUT PHANDLE EventHandle,
  531. IN ACCESS_MASK DesiredAccess,
  532. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  533. IN EVENT_TYPE EventType,
  534. IN BOOLEAN InitialState
  535. )
  536. {
  537. NTSTATUS Status;
  538. PVOID Caller = _ReturnAddress();
  539. if (VfZwShouldCheck (Caller)) {
  540. VF_ZW_CHECK_ADDRESS (EventHandle);
  541. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  542. }
  543. Status = ZwCreateEvent(EventHandle,
  544. DesiredAccess,
  545. ObjectAttributes,
  546. EventType,
  547. InitialState);
  548. return Status;
  549. }
  550. //NTSYSAPI
  551. NTSTATUS
  552. NTAPI
  553. VfZwCreateFile(
  554. OUT PHANDLE FileHandle,
  555. IN ACCESS_MASK DesiredAccess,
  556. IN POBJECT_ATTRIBUTES ObjectAttributes,
  557. OUT PIO_STATUS_BLOCK IoStatusBlock,
  558. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  559. IN ULONG FileAttributes,
  560. IN ULONG ShareAccess,
  561. IN ULONG CreateDisposition,
  562. IN ULONG CreateOptions,
  563. IN PVOID EaBuffer OPTIONAL,
  564. IN ULONG EaLength
  565. )
  566. {
  567. NTSTATUS Status;
  568. PVOID Caller = _ReturnAddress();
  569. if (VfZwShouldCheck (Caller)) {
  570. VF_ZW_CHECK_ADDRESS (FileHandle);
  571. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  572. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  573. VF_ZW_CHECK_ADDRESS (AllocationSize);
  574. VF_ZW_CHECK_ADDRESS (EaBuffer);
  575. }
  576. Status = ZwCreateFile(FileHandle,
  577. DesiredAccess,
  578. ObjectAttributes,
  579. IoStatusBlock,
  580. AllocationSize OPTIONAL,
  581. FileAttributes,
  582. ShareAccess,
  583. CreateDisposition,
  584. CreateOptions,
  585. EaBuffer OPTIONAL,
  586. EaLength);
  587. return Status;
  588. }
  589. //NTSYSAPI
  590. NTSTATUS
  591. NTAPI
  592. VfZwCreateJobObject (
  593. OUT PHANDLE JobHandle,
  594. IN ACCESS_MASK DesiredAccess,
  595. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL
  596. )
  597. {
  598. NTSTATUS Status;
  599. PVOID Caller = _ReturnAddress();
  600. if (VfZwShouldCheck (Caller)) {
  601. VF_ZW_CHECK_ADDRESS (JobHandle);
  602. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  603. }
  604. Status = ZwCreateJobObject (JobHandle,
  605. DesiredAccess,
  606. ObjectAttributes);
  607. return Status;
  608. }
  609. //NTSYSAPI
  610. NTSTATUS
  611. NTAPI
  612. VfZwCreateKey(
  613. OUT PHANDLE KeyHandle,
  614. IN ACCESS_MASK DesiredAccess,
  615. IN POBJECT_ATTRIBUTES ObjectAttributes,
  616. IN ULONG TitleIndex,
  617. IN PUNICODE_STRING Class OPTIONAL,
  618. IN ULONG CreateOptions,
  619. OUT PULONG Disposition OPTIONAL
  620. )
  621. {
  622. NTSTATUS Status;
  623. PVOID Caller = _ReturnAddress();
  624. if (VfZwShouldCheck (Caller)) {
  625. VF_ZW_CHECK_ADDRESS (KeyHandle);
  626. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  627. VF_ZW_CHECK_UNICODE_STRING (Class);
  628. VF_ZW_CHECK_ADDRESS (Disposition);
  629. }
  630. Status = ZwCreateKey(KeyHandle,
  631. DesiredAccess,
  632. ObjectAttributes,
  633. TitleIndex,
  634. Class OPTIONAL,
  635. CreateOptions,
  636. Disposition OPTIONAL);
  637. return Status;
  638. }
  639. //NTSYSAPI
  640. NTSTATUS
  641. NTAPI
  642. VfZwCreateSection (
  643. OUT PHANDLE SectionHandle,
  644. IN ACCESS_MASK DesiredAccess,
  645. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  646. IN PLARGE_INTEGER MaximumSize OPTIONAL,
  647. IN ULONG SectionPageProtection,
  648. IN ULONG AllocationAttributes,
  649. IN HANDLE FileHandle OPTIONAL
  650. )
  651. {
  652. NTSTATUS Status;
  653. PVOID Caller = _ReturnAddress();
  654. if (VfZwShouldCheck (Caller)) {
  655. VF_ZW_CHECK_ADDRESS (SectionHandle);
  656. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  657. VF_ZW_CHECK_ADDRESS (MaximumSize);
  658. VF_ZW_CHECK_HANDLE (FileHandle);
  659. }
  660. Status = ZwCreateSection (SectionHandle,
  661. DesiredAccess,
  662. ObjectAttributes OPTIONAL,
  663. MaximumSize OPTIONAL,
  664. SectionPageProtection,
  665. AllocationAttributes,
  666. FileHandle OPTIONAL);
  667. return Status;
  668. }
  669. //NTSYSAPI
  670. NTSTATUS
  671. NTAPI
  672. VfZwCreateSymbolicLinkObject(
  673. OUT PHANDLE LinkHandle,
  674. IN ACCESS_MASK DesiredAccess,
  675. IN POBJECT_ATTRIBUTES ObjectAttributes,
  676. IN PUNICODE_STRING LinkTarget
  677. )
  678. {
  679. NTSTATUS Status;
  680. PVOID Caller = _ReturnAddress();
  681. if (VfZwShouldCheck (Caller)) {
  682. VF_ZW_CHECK_ADDRESS (LinkHandle);
  683. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  684. VF_ZW_CHECK_UNICODE_STRING (LinkTarget);
  685. }
  686. Status = ZwCreateSymbolicLinkObject(LinkHandle,
  687. DesiredAccess,
  688. ObjectAttributes,
  689. LinkTarget);
  690. return Status;
  691. }
  692. //NTSYSAPI
  693. NTSTATUS
  694. NTAPI
  695. VfZwCreateTimer (
  696. OUT PHANDLE TimerHandle,
  697. IN ACCESS_MASK DesiredAccess,
  698. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  699. IN TIMER_TYPE TimerType
  700. )
  701. {
  702. NTSTATUS Status;
  703. PVOID Caller = _ReturnAddress();
  704. if (VfZwShouldCheck (Caller)) {
  705. VF_ZW_CHECK_ADDRESS (TimerHandle);
  706. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  707. }
  708. Status = ZwCreateTimer(TimerHandle,
  709. DesiredAccess,
  710. ObjectAttributes,
  711. TimerType);
  712. return Status;
  713. }
  714. //NTSYSAPI
  715. NTSTATUS
  716. NTAPI
  717. VfZwDeleteBootEntry (
  718. IN ULONG Id
  719. )
  720. {
  721. NTSTATUS Status;
  722. PVOID Caller = _ReturnAddress();
  723. if (VfZwShouldCheck (Caller)) {
  724. VF_ZW_CHECK_ADDRESS (NULL);
  725. }
  726. Status = ZwDeleteBootEntry(Id);
  727. return Status;
  728. }
  729. //NTSYSAPI
  730. NTSTATUS
  731. NTAPI
  732. VfZwDeleteDriverEntry (
  733. IN ULONG Id
  734. )
  735. {
  736. NTSTATUS Status;
  737. PVOID Caller = _ReturnAddress();
  738. if (VfZwShouldCheck (Caller)) {
  739. VF_ZW_CHECK_ADDRESS (NULL);
  740. }
  741. Status = ZwDeleteDriverEntry(Id);
  742. return Status;
  743. }
  744. //NTSYSAPI
  745. NTSTATUS
  746. NTAPI
  747. VfZwDeleteFile(
  748. IN POBJECT_ATTRIBUTES ObjectAttributes
  749. )
  750. {
  751. NTSTATUS Status;
  752. PVOID Caller = _ReturnAddress();
  753. if (VfZwShouldCheck (Caller)) {
  754. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  755. }
  756. Status = ZwDeleteFile(ObjectAttributes);
  757. return Status;
  758. }
  759. //NTSYSAPI
  760. NTSTATUS
  761. NTAPI
  762. VfZwDeleteKey(
  763. IN HANDLE KeyHandle
  764. )
  765. {
  766. NTSTATUS Status;
  767. PVOID Caller = _ReturnAddress();
  768. if (VfZwShouldCheck (Caller)) {
  769. VF_ZW_CHECK_HANDLE (KeyHandle);
  770. }
  771. Status = ZwDeleteKey(KeyHandle);
  772. return Status;
  773. }
  774. //NTSYSAPI
  775. NTSTATUS
  776. NTAPI
  777. VfZwDeleteValueKey(
  778. IN HANDLE KeyHandle,
  779. IN PUNICODE_STRING ValueName
  780. )
  781. {
  782. NTSTATUS Status;
  783. PVOID Caller = _ReturnAddress();
  784. if (VfZwShouldCheck (Caller)) {
  785. VF_ZW_CHECK_HANDLE (KeyHandle);
  786. VF_ZW_CHECK_UNICODE_STRING (ValueName);
  787. }
  788. Status = ZwDeleteValueKey(KeyHandle,
  789. ValueName);
  790. return Status;
  791. }
  792. //NTSYSAPI
  793. NTSTATUS
  794. NTAPI
  795. VfZwDeviceIoControlFile(
  796. IN HANDLE FileHandle,
  797. IN HANDLE Event OPTIONAL,
  798. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  799. IN PVOID ApcContext OPTIONAL,
  800. OUT PIO_STATUS_BLOCK IoStatusBlock,
  801. IN ULONG IoControlCode,
  802. IN PVOID InputBuffer OPTIONAL,
  803. IN ULONG InputBufferLength,
  804. OUT PVOID OutputBuffer OPTIONAL,
  805. IN ULONG OutputBufferLength
  806. )
  807. {
  808. NTSTATUS Status;
  809. PVOID Caller = _ReturnAddress();
  810. if (VfZwShouldCheck (Caller)) {
  811. VF_ZW_CHECK_HANDLE (FileHandle);
  812. VF_ZW_CHECK_HANDLE (Event);
  813. VF_ZW_CHECK_ADDRESS ((PVOID)ApcRoutine);
  814. VF_ZW_CHECK_ADDRESS (ApcContext);
  815. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  816. VF_ZW_CHECK_ADDRESS (InputBuffer);
  817. VF_ZW_CHECK_ADDRESS (OutputBuffer);
  818. }
  819. Status = ZwDeviceIoControlFile(FileHandle,
  820. Event OPTIONAL,
  821. ApcRoutine OPTIONAL,
  822. ApcContext OPTIONAL,
  823. IoStatusBlock,
  824. IoControlCode,
  825. InputBuffer OPTIONAL,
  826. InputBufferLength,
  827. OutputBuffer OPTIONAL,
  828. OutputBufferLength);
  829. return Status;
  830. }
  831. //NTSYSAPI
  832. NTSTATUS
  833. NTAPI
  834. VfZwDisplayString(
  835. IN PUNICODE_STRING String
  836. )
  837. {
  838. NTSTATUS Status;
  839. PVOID Caller = _ReturnAddress();
  840. if (VfZwShouldCheck (Caller)) {
  841. VF_ZW_CHECK_UNICODE_STRING (String);
  842. }
  843. Status = ZwDisplayString(String);
  844. return Status;
  845. }
  846. //NTSYSAPI
  847. NTSTATUS
  848. NTAPI
  849. VfZwDuplicateObject(
  850. IN HANDLE SourceProcessHandle,
  851. IN HANDLE SourceHandle,
  852. IN HANDLE TargetProcessHandle OPTIONAL,
  853. OUT PHANDLE TargetHandle OPTIONAL,
  854. IN ACCESS_MASK DesiredAccess,
  855. IN ULONG HandleAttributes,
  856. IN ULONG Options
  857. )
  858. {
  859. NTSTATUS Status;
  860. PVOID Caller = _ReturnAddress();
  861. if (VfZwShouldCheck (Caller)) {
  862. VF_ZW_CHECK_HANDLE (SourceProcessHandle);
  863. VF_ZW_CHECK_HANDLE (SourceHandle);
  864. VF_ZW_CHECK_HANDLE (TargetProcessHandle);
  865. VF_ZW_CHECK_ADDRESS (TargetHandle);
  866. }
  867. Status = ZwDuplicateObject(SourceProcessHandle,
  868. SourceHandle,
  869. TargetProcessHandle OPTIONAL,
  870. TargetHandle OPTIONAL,
  871. DesiredAccess,
  872. HandleAttributes,
  873. Options);
  874. return Status;
  875. }
  876. //NTSYSAPI
  877. NTSTATUS
  878. NTAPI
  879. VfZwDuplicateToken(
  880. IN HANDLE ExistingTokenHandle,
  881. IN ACCESS_MASK DesiredAccess,
  882. IN POBJECT_ATTRIBUTES ObjectAttributes,
  883. IN BOOLEAN EffectiveOnly,
  884. IN TOKEN_TYPE TokenType,
  885. OUT PHANDLE NewTokenHandle
  886. )
  887. {
  888. NTSTATUS Status;
  889. PVOID Caller = _ReturnAddress();
  890. if (VfZwShouldCheck (Caller)) {
  891. VF_ZW_CHECK_HANDLE (ExistingTokenHandle);
  892. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  893. VF_ZW_CHECK_ADDRESS (NewTokenHandle);
  894. }
  895. Status = ZwDuplicateToken (ExistingTokenHandle,
  896. DesiredAccess,
  897. ObjectAttributes,
  898. EffectiveOnly,
  899. TokenType,
  900. NewTokenHandle);
  901. return Status;
  902. }
  903. //NTSYSAPI
  904. NTSTATUS
  905. NTAPI
  906. VfZwEnumerateBootEntries (
  907. OUT PVOID Buffer,
  908. IN OUT PULONG BufferLength
  909. )
  910. {
  911. NTSTATUS Status;
  912. PVOID Caller = _ReturnAddress();
  913. if (VfZwShouldCheck (Caller)) {
  914. VF_ZW_CHECK_ADDRESS (Buffer);
  915. VF_ZW_CHECK_ADDRESS (BufferLength);
  916. }
  917. Status = ZwEnumerateBootEntries (Buffer,
  918. BufferLength);
  919. return Status;
  920. }
  921. //NTSYSAPI
  922. NTSTATUS
  923. NTAPI
  924. VfZwEnumerateDriverEntries (
  925. OUT PVOID Buffer,
  926. IN OUT PULONG BufferLength
  927. )
  928. {
  929. NTSTATUS Status;
  930. PVOID Caller = _ReturnAddress();
  931. if (VfZwShouldCheck (Caller)) {
  932. VF_ZW_CHECK_ADDRESS (Buffer);
  933. VF_ZW_CHECK_ADDRESS (BufferLength);
  934. }
  935. Status = ZwEnumerateDriverEntries (Buffer,
  936. BufferLength);
  937. return Status;
  938. }
  939. //NTSYSAPI
  940. NTSTATUS
  941. NTAPI
  942. VfZwEnumerateKey(
  943. IN HANDLE KeyHandle,
  944. IN ULONG Index,
  945. IN KEY_INFORMATION_CLASS KeyInformationClass,
  946. OUT PVOID KeyInformation,
  947. IN ULONG Length,
  948. OUT PULONG ResultLength
  949. )
  950. {
  951. NTSTATUS Status;
  952. PVOID Caller = _ReturnAddress();
  953. if (VfZwShouldCheck (Caller)) {
  954. VF_ZW_CHECK_HANDLE (KeyHandle);
  955. VF_ZW_CHECK_ADDRESS (KeyInformation);
  956. VF_ZW_CHECK_ADDRESS (ResultLength);
  957. }
  958. Status = ZwEnumerateKey(KeyHandle,
  959. Index,
  960. KeyInformationClass,
  961. KeyInformation,
  962. Length,
  963. ResultLength);
  964. return Status;
  965. }
  966. //NTSYSAPI
  967. NTSTATUS
  968. NTAPI
  969. VfZwEnumerateValueKey(
  970. IN HANDLE KeyHandle,
  971. IN ULONG Index,
  972. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  973. OUT PVOID KeyValueInformation,
  974. IN ULONG Length,
  975. OUT PULONG ResultLength
  976. )
  977. {
  978. NTSTATUS Status;
  979. PVOID Caller = _ReturnAddress();
  980. if (VfZwShouldCheck (Caller)) {
  981. VF_ZW_CHECK_HANDLE (KeyHandle);
  982. VF_ZW_CHECK_ADDRESS (KeyValueInformation);
  983. VF_ZW_CHECK_ADDRESS (ResultLength);
  984. }
  985. Status = ZwEnumerateValueKey(KeyHandle,
  986. Index,
  987. KeyValueInformationClass,
  988. KeyValueInformation,
  989. Length,
  990. ResultLength);
  991. return Status;
  992. }
  993. //NTSYSAPI
  994. NTSTATUS
  995. NTAPI
  996. VfZwFlushInstructionCache (
  997. IN HANDLE ProcessHandle,
  998. IN PVOID BaseAddress OPTIONAL,
  999. IN SIZE_T Length
  1000. )
  1001. {
  1002. NTSTATUS Status;
  1003. PVOID Caller = _ReturnAddress();
  1004. if (VfZwShouldCheck (Caller)) {
  1005. VF_ZW_CHECK_HANDLE (ProcessHandle);
  1006. VF_ZW_CHECK_ADDRESS (BaseAddress);
  1007. }
  1008. Status = ZwFlushInstructionCache (ProcessHandle,
  1009. BaseAddress OPTIONAL,
  1010. Length);
  1011. return Status;
  1012. }
  1013. //NTSYSAPI
  1014. NTSTATUS
  1015. NTAPI
  1016. VfZwFlushKey(
  1017. IN HANDLE KeyHandle
  1018. )
  1019. {
  1020. NTSTATUS Status;
  1021. PVOID Caller = _ReturnAddress();
  1022. if (VfZwShouldCheck (Caller)) {
  1023. VF_ZW_CHECK_HANDLE (KeyHandle);
  1024. }
  1025. Status = ZwFlushKey (KeyHandle);
  1026. return Status;
  1027. }
  1028. //NTSYSAPI
  1029. NTSTATUS
  1030. NTAPI
  1031. VfZwFlushVirtualMemory(
  1032. IN HANDLE ProcessHandle,
  1033. IN OUT PVOID *BaseAddress,
  1034. IN OUT PSIZE_T RegionSize,
  1035. OUT PIO_STATUS_BLOCK IoStatus
  1036. )
  1037. {
  1038. NTSTATUS Status;
  1039. PVOID Caller = _ReturnAddress();
  1040. if (VfZwShouldCheck (Caller)) {
  1041. VF_ZW_CHECK_HANDLE (ProcessHandle);
  1042. VF_ZW_CHECK_ADDRESS (BaseAddress);
  1043. VF_ZW_CHECK_ADDRESS (RegionSize);
  1044. VF_ZW_CHECK_ADDRESS (IoStatus);
  1045. }
  1046. Status = ZwFlushVirtualMemory(ProcessHandle,
  1047. BaseAddress,
  1048. RegionSize,
  1049. IoStatus);
  1050. return Status;
  1051. }
  1052. //NTSYSAPI
  1053. NTSTATUS
  1054. NTAPI
  1055. VfZwFreeVirtualMemory(
  1056. IN HANDLE ProcessHandle,
  1057. IN OUT PVOID *BaseAddress,
  1058. IN OUT PSIZE_T RegionSize,
  1059. IN ULONG FreeType
  1060. )
  1061. {
  1062. NTSTATUS Status;
  1063. PVOID Caller = _ReturnAddress();
  1064. if (VfZwShouldCheck (Caller)) {
  1065. VF_ZW_CHECK_HANDLE (ProcessHandle);
  1066. VF_ZW_CHECK_ADDRESS (BaseAddress);
  1067. VF_ZW_CHECK_ADDRESS (RegionSize);
  1068. }
  1069. Status = ZwFreeVirtualMemory (ProcessHandle,
  1070. BaseAddress,
  1071. RegionSize,
  1072. FreeType);
  1073. return Status;
  1074. }
  1075. //NTSYSAPI
  1076. NTSTATUS
  1077. NTAPI
  1078. VfZwFsControlFile(
  1079. IN HANDLE FileHandle,
  1080. IN HANDLE Event OPTIONAL,
  1081. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  1082. IN PVOID ApcContext OPTIONAL,
  1083. OUT PIO_STATUS_BLOCK IoStatusBlock,
  1084. IN ULONG FsControlCode,
  1085. IN PVOID InputBuffer OPTIONAL,
  1086. IN ULONG InputBufferLength,
  1087. OUT PVOID OutputBuffer OPTIONAL,
  1088. IN ULONG OutputBufferLength
  1089. )
  1090. {
  1091. NTSTATUS Status;
  1092. PVOID Caller = _ReturnAddress();
  1093. if (VfZwShouldCheck (Caller)) {
  1094. VF_ZW_CHECK_HANDLE (FileHandle);
  1095. VF_ZW_CHECK_HANDLE (Event);
  1096. VF_ZW_CHECK_ADDRESS ((PVOID)ApcRoutine);
  1097. VF_ZW_CHECK_ADDRESS (ApcContext);
  1098. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  1099. VF_ZW_CHECK_ADDRESS (InputBuffer);
  1100. VF_ZW_CHECK_ADDRESS (OutputBuffer);
  1101. }
  1102. Status = ZwFsControlFile(FileHandle,
  1103. Event OPTIONAL,
  1104. ApcRoutine OPTIONAL,
  1105. ApcContext OPTIONAL,
  1106. IoStatusBlock,
  1107. FsControlCode,
  1108. InputBuffer OPTIONAL,
  1109. InputBufferLength,
  1110. OutputBuffer OPTIONAL,
  1111. OutputBufferLength);
  1112. return Status;
  1113. }
  1114. //NTSYSAPI
  1115. NTSTATUS
  1116. NTAPI
  1117. VfZwInitiatePowerAction(
  1118. IN POWER_ACTION SystemAction,
  1119. IN SYSTEM_POWER_STATE MinSystemState,
  1120. IN ULONG Flags, // POWER_ACTION_xxx flags
  1121. IN BOOLEAN Asynchronous
  1122. )
  1123. {
  1124. NTSTATUS Status;
  1125. PVOID Caller = _ReturnAddress();
  1126. if (VfZwShouldCheck (Caller)) {
  1127. // no-op call to avoid warnings for `Caller' local.
  1128. VF_ZW_CHECK_ADDRESS (NULL);
  1129. }
  1130. Status = ZwInitiatePowerAction(SystemAction,
  1131. MinSystemState,
  1132. Flags, // POWER_ACTION_xxx flags
  1133. Asynchronous);
  1134. return Status;
  1135. }
  1136. //NTSYSAPI
  1137. NTSTATUS
  1138. NTAPI
  1139. VfZwIsProcessInJob (
  1140. IN HANDLE ProcessHandle,
  1141. IN HANDLE JobHandle
  1142. )
  1143. {
  1144. NTSTATUS Status;
  1145. PVOID Caller = _ReturnAddress();
  1146. if (VfZwShouldCheck (Caller)) {
  1147. VF_ZW_CHECK_HANDLE (ProcessHandle);
  1148. VF_ZW_CHECK_HANDLE (JobHandle);
  1149. }
  1150. Status = ZwIsProcessInJob(ProcessHandle,
  1151. JobHandle);
  1152. return Status;
  1153. }
  1154. //NTSYSAPI
  1155. NTSTATUS
  1156. NTAPI
  1157. VfZwLoadDriver(
  1158. IN PUNICODE_STRING DriverServiceName
  1159. )
  1160. {
  1161. NTSTATUS Status;
  1162. PVOID Caller = _ReturnAddress();
  1163. if (VfZwShouldCheck (Caller)) {
  1164. VF_ZW_CHECK_UNICODE_STRING (DriverServiceName);
  1165. }
  1166. Status = ZwLoadDriver(DriverServiceName);
  1167. return Status;
  1168. }
  1169. //NTSYSAPI
  1170. NTSTATUS
  1171. NTAPI
  1172. VfZwLoadKey(
  1173. IN POBJECT_ATTRIBUTES TargetKey,
  1174. IN POBJECT_ATTRIBUTES SourceFile
  1175. )
  1176. {
  1177. NTSTATUS Status;
  1178. PVOID Caller = _ReturnAddress();
  1179. if (VfZwShouldCheck (Caller)) {
  1180. VF_ZW_CHECK_OBJECT_ATTRIBUTES (TargetKey);
  1181. VF_ZW_CHECK_OBJECT_ATTRIBUTES (SourceFile);
  1182. }
  1183. Status = ZwLoadKey(TargetKey,
  1184. SourceFile);
  1185. return Status;
  1186. }
  1187. //NTSYSAPI
  1188. NTSTATUS
  1189. NTAPI
  1190. VfZwMakeTemporaryObject(
  1191. IN HANDLE Handle
  1192. )
  1193. {
  1194. NTSTATUS Status;
  1195. PVOID Caller = _ReturnAddress();
  1196. if (VfZwShouldCheck (Caller)) {
  1197. VF_ZW_CHECK_HANDLE (Handle);
  1198. }
  1199. Status = ZwMakeTemporaryObject(Handle);
  1200. return Status;
  1201. }
  1202. //NTSYSAPI
  1203. NTSTATUS
  1204. NTAPI
  1205. VfZwMapViewOfSection(
  1206. IN HANDLE SectionHandle,
  1207. IN HANDLE ProcessHandle,
  1208. IN OUT PVOID *BaseAddress,
  1209. IN ULONG_PTR ZeroBits,
  1210. IN SIZE_T CommitSize,
  1211. IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
  1212. IN OUT PSIZE_T ViewSize,
  1213. IN SECTION_INHERIT InheritDisposition,
  1214. IN ULONG AllocationType,
  1215. IN ULONG Protect
  1216. )
  1217. {
  1218. NTSTATUS Status;
  1219. PVOID Caller = _ReturnAddress();
  1220. if (VfZwShouldCheck (Caller)) {
  1221. VF_ZW_CHECK_HANDLE (SectionHandle);
  1222. VF_ZW_CHECK_HANDLE (ProcessHandle);
  1223. VF_ZW_CHECK_ADDRESS (BaseAddress);
  1224. VF_ZW_CHECK_ADDRESS (SectionOffset);
  1225. VF_ZW_CHECK_ADDRESS (ViewSize);
  1226. VfZwReportUserModeVirtualSpaceOperation (Caller);
  1227. if (VfZwShouldSimulateDecommitAttack() &&
  1228. Protect == PAGE_READWRITE) {
  1229. DbgPrint ("DVRF:ZW: simulating unmap attack for caller %p \n", Caller);
  1230. Protect = PAGE_READONLY;
  1231. }
  1232. }
  1233. Status = ZwMapViewOfSection(SectionHandle,
  1234. ProcessHandle,
  1235. BaseAddress,
  1236. ZeroBits,
  1237. CommitSize,
  1238. SectionOffset OPTIONAL,
  1239. ViewSize,
  1240. InheritDisposition,
  1241. AllocationType,
  1242. Protect);
  1243. return Status;
  1244. }
  1245. //NTSYSAPI
  1246. NTSTATUS
  1247. NTAPI
  1248. VfZwModifyBootEntry (
  1249. IN PBOOT_ENTRY BootEntry
  1250. )
  1251. {
  1252. NTSTATUS Status;
  1253. PVOID Caller = _ReturnAddress();
  1254. if (VfZwShouldCheck (Caller)) {
  1255. VF_ZW_CHECK_ADDRESS (BootEntry);
  1256. }
  1257. Status = ZwModifyBootEntry (BootEntry);
  1258. return Status;
  1259. }
  1260. //NTSYSAPI
  1261. NTSTATUS
  1262. NTAPI
  1263. VfZwModifyDriverEntry (
  1264. IN PEFI_DRIVER_ENTRY DriverEntry
  1265. )
  1266. {
  1267. NTSTATUS Status;
  1268. PVOID Caller = _ReturnAddress();
  1269. if (VfZwShouldCheck (Caller)) {
  1270. VF_ZW_CHECK_ADDRESS (DriverEntry);
  1271. }
  1272. Status = ZwModifyDriverEntry (DriverEntry);
  1273. return Status;
  1274. }
  1275. //NTSYSAPI
  1276. NTSTATUS
  1277. NTAPI
  1278. VfZwNotifyChangeKey(
  1279. IN HANDLE KeyHandle,
  1280. IN HANDLE Event OPTIONAL,
  1281. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  1282. IN PVOID ApcContext OPTIONAL,
  1283. OUT PIO_STATUS_BLOCK IoStatusBlock,
  1284. IN ULONG CompletionFilter,
  1285. IN BOOLEAN WatchTree,
  1286. OUT PVOID Buffer,
  1287. IN ULONG BufferSize,
  1288. IN BOOLEAN Asynchronous
  1289. )
  1290. {
  1291. NTSTATUS Status;
  1292. PVOID Caller = _ReturnAddress();
  1293. if (VfZwShouldCheck (Caller)) {
  1294. VF_ZW_CHECK_HANDLE (KeyHandle);
  1295. VF_ZW_CHECK_HANDLE (Event);
  1296. VF_ZW_CHECK_ADDRESS ((PVOID)ApcRoutine);
  1297. VF_ZW_CHECK_ADDRESS (ApcContext);
  1298. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  1299. VF_ZW_CHECK_ADDRESS (Buffer);
  1300. }
  1301. Status = ZwNotifyChangeKey(KeyHandle,
  1302. Event OPTIONAL,
  1303. ApcRoutine OPTIONAL,
  1304. ApcContext OPTIONAL,
  1305. IoStatusBlock,
  1306. CompletionFilter,
  1307. WatchTree,
  1308. Buffer,
  1309. BufferSize,
  1310. Asynchronous);
  1311. return Status;
  1312. }
  1313. //NTSYSAPI
  1314. NTSTATUS
  1315. NTAPI
  1316. VfZwOpenDirectoryObject(
  1317. OUT PHANDLE DirectoryHandle,
  1318. IN ACCESS_MASK DesiredAccess,
  1319. IN POBJECT_ATTRIBUTES ObjectAttributes
  1320. )
  1321. {
  1322. NTSTATUS Status;
  1323. PVOID Caller = _ReturnAddress();
  1324. if (VfZwShouldCheck (Caller)) {
  1325. VF_ZW_CHECK_ADDRESS (DirectoryHandle);
  1326. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  1327. }
  1328. Status = ZwOpenDirectoryObject(DirectoryHandle,
  1329. DesiredAccess,
  1330. ObjectAttributes);
  1331. return Status;
  1332. }
  1333. //NTSYSAPI
  1334. NTSTATUS
  1335. NTAPI
  1336. VfZwOpenEvent (
  1337. OUT PHANDLE EventHandle,
  1338. IN ACCESS_MASK DesiredAccess,
  1339. IN POBJECT_ATTRIBUTES ObjectAttributes
  1340. )
  1341. {
  1342. NTSTATUS Status;
  1343. PVOID Caller = _ReturnAddress();
  1344. if (VfZwShouldCheck (Caller)) {
  1345. VF_ZW_CHECK_ADDRESS (EventHandle);
  1346. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  1347. }
  1348. Status = ZwOpenEvent(EventHandle,
  1349. DesiredAccess,
  1350. ObjectAttributes);
  1351. return Status;
  1352. }
  1353. //NTSYSAPI
  1354. NTSTATUS
  1355. NTAPI
  1356. VfZwOpenFile(
  1357. OUT PHANDLE FileHandle,
  1358. IN ACCESS_MASK DesiredAccess,
  1359. IN POBJECT_ATTRIBUTES ObjectAttributes,
  1360. OUT PIO_STATUS_BLOCK IoStatusBlock,
  1361. IN ULONG ShareAccess,
  1362. IN ULONG OpenOptions
  1363. )
  1364. {
  1365. NTSTATUS Status;
  1366. PVOID Caller = _ReturnAddress();
  1367. if (VfZwShouldCheck (Caller)) {
  1368. VF_ZW_CHECK_ADDRESS (FileHandle);
  1369. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  1370. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  1371. }
  1372. Status = ZwOpenFile(FileHandle,
  1373. DesiredAccess,
  1374. ObjectAttributes,
  1375. IoStatusBlock,
  1376. ShareAccess,
  1377. OpenOptions);
  1378. return Status;
  1379. }
  1380. //NTSYSAPI
  1381. NTSTATUS
  1382. NTAPI
  1383. VfZwOpenJobObject(
  1384. OUT PHANDLE JobHandle,
  1385. IN ACCESS_MASK DesiredAccess,
  1386. IN POBJECT_ATTRIBUTES ObjectAttributes
  1387. )
  1388. {
  1389. NTSTATUS Status;
  1390. PVOID Caller = _ReturnAddress();
  1391. if (VfZwShouldCheck (Caller)) {
  1392. VF_ZW_CHECK_ADDRESS (JobHandle);
  1393. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  1394. }
  1395. Status = ZwOpenJobObject(JobHandle,
  1396. DesiredAccess,
  1397. ObjectAttributes);
  1398. return Status;
  1399. }
  1400. //NTSYSAPI
  1401. NTSTATUS
  1402. NTAPI
  1403. VfZwOpenKey(
  1404. OUT PHANDLE KeyHandle,
  1405. IN ACCESS_MASK DesiredAccess,
  1406. IN POBJECT_ATTRIBUTES ObjectAttributes
  1407. )
  1408. {
  1409. NTSTATUS Status;
  1410. PVOID Caller = _ReturnAddress();
  1411. if (VfZwShouldCheck (Caller)) {
  1412. VF_ZW_CHECK_ADDRESS (KeyHandle);
  1413. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  1414. }
  1415. Status = ZwOpenKey(KeyHandle,
  1416. DesiredAccess,
  1417. ObjectAttributes);
  1418. return Status;
  1419. }
  1420. //NTSYSAPI
  1421. NTSTATUS
  1422. NTAPI
  1423. VfZwOpenProcess (
  1424. OUT PHANDLE ProcessHandle,
  1425. IN ACCESS_MASK DesiredAccess,
  1426. IN POBJECT_ATTRIBUTES ObjectAttributes,
  1427. IN PCLIENT_ID ClientId OPTIONAL
  1428. )
  1429. {
  1430. NTSTATUS Status;
  1431. PVOID Caller = _ReturnAddress();
  1432. if (VfZwShouldCheck (Caller)) {
  1433. VF_ZW_CHECK_ADDRESS (ProcessHandle);
  1434. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  1435. VF_ZW_CHECK_ADDRESS (ClientId);
  1436. }
  1437. Status = ZwOpenProcess (ProcessHandle,
  1438. DesiredAccess,
  1439. ObjectAttributes,
  1440. ClientId OPTIONAL);
  1441. return Status;
  1442. }
  1443. //NTSYSAPI
  1444. NTSTATUS
  1445. NTAPI
  1446. VfZwOpenProcessToken(
  1447. IN HANDLE ProcessHandle,
  1448. IN ACCESS_MASK DesiredAccess,
  1449. OUT PHANDLE TokenHandle
  1450. )
  1451. {
  1452. NTSTATUS Status;
  1453. PVOID Caller = _ReturnAddress();
  1454. if (VfZwShouldCheck (Caller)) {
  1455. VF_ZW_CHECK_HANDLE (ProcessHandle);
  1456. VF_ZW_CHECK_ADDRESS (TokenHandle);
  1457. }
  1458. Status = ZwOpenProcessToken(ProcessHandle,
  1459. DesiredAccess,
  1460. TokenHandle);
  1461. return Status;
  1462. }
  1463. //NTSYSAPI
  1464. NTSTATUS
  1465. NTAPI
  1466. VfZwOpenProcessTokenEx(
  1467. IN HANDLE ProcessHandle,
  1468. IN ACCESS_MASK DesiredAccess,
  1469. IN ULONG HandleAttributes,
  1470. OUT PHANDLE TokenHandle
  1471. )
  1472. {
  1473. NTSTATUS Status;
  1474. PVOID Caller = _ReturnAddress();
  1475. if (VfZwShouldCheck (Caller)) {
  1476. VF_ZW_CHECK_HANDLE (ProcessHandle);
  1477. VF_ZW_CHECK_ADDRESS (TokenHandle);
  1478. }
  1479. Status = ZwOpenProcessTokenEx(ProcessHandle,
  1480. DesiredAccess,
  1481. HandleAttributes,
  1482. TokenHandle);
  1483. return Status;
  1484. }
  1485. //NTSYSAPI
  1486. NTSTATUS
  1487. NTAPI
  1488. VfZwOpenSection(
  1489. OUT PHANDLE SectionHandle,
  1490. IN ACCESS_MASK DesiredAccess,
  1491. IN POBJECT_ATTRIBUTES ObjectAttributes
  1492. )
  1493. {
  1494. NTSTATUS Status;
  1495. PVOID Caller = _ReturnAddress();
  1496. if (VfZwShouldCheck (Caller)) {
  1497. VF_ZW_CHECK_ADDRESS (SectionHandle);
  1498. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  1499. }
  1500. Status = ZwOpenSection(SectionHandle,
  1501. DesiredAccess,
  1502. ObjectAttributes);
  1503. return Status;
  1504. }
  1505. //NTSYSAPI
  1506. NTSTATUS
  1507. NTAPI
  1508. VfZwOpenSymbolicLinkObject(
  1509. OUT PHANDLE LinkHandle,
  1510. IN ACCESS_MASK DesiredAccess,
  1511. IN POBJECT_ATTRIBUTES ObjectAttributes
  1512. )
  1513. {
  1514. NTSTATUS Status;
  1515. PVOID Caller = _ReturnAddress();
  1516. if (VfZwShouldCheck (Caller)) {
  1517. VF_ZW_CHECK_ADDRESS (LinkHandle);
  1518. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  1519. }
  1520. Status = ZwOpenSymbolicLinkObject(LinkHandle,
  1521. DesiredAccess,
  1522. ObjectAttributes);
  1523. return Status;
  1524. }
  1525. //NTSYSAPI
  1526. NTSTATUS
  1527. NTAPI
  1528. VfZwOpenThread (
  1529. OUT PHANDLE ThreadHandle,
  1530. IN ACCESS_MASK DesiredAccess,
  1531. IN POBJECT_ATTRIBUTES ObjectAttributes,
  1532. IN PCLIENT_ID ClientId OPTIONAL
  1533. )
  1534. {
  1535. NTSTATUS Status;
  1536. PVOID Caller = _ReturnAddress();
  1537. if (VfZwShouldCheck (Caller)) {
  1538. VF_ZW_CHECK_ADDRESS (ThreadHandle);
  1539. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  1540. VF_ZW_CHECK_ADDRESS (ClientId);
  1541. }
  1542. Status = ZwOpenThread (ThreadHandle,
  1543. DesiredAccess,
  1544. ObjectAttributes,
  1545. ClientId OPTIONAL);
  1546. return Status;
  1547. }
  1548. //NTSYSAPI
  1549. NTSTATUS
  1550. NTAPI
  1551. VfZwOpenThreadToken(
  1552. IN HANDLE ThreadHandle,
  1553. IN ACCESS_MASK DesiredAccess,
  1554. IN BOOLEAN OpenAsSelf,
  1555. OUT PHANDLE TokenHandle
  1556. )
  1557. {
  1558. NTSTATUS Status;
  1559. PVOID Caller = _ReturnAddress();
  1560. if (VfZwShouldCheck (Caller)) {
  1561. VF_ZW_CHECK_HANDLE (ThreadHandle);
  1562. VF_ZW_CHECK_ADDRESS (TokenHandle);
  1563. }
  1564. Status = ZwOpenThreadToken(ThreadHandle,
  1565. DesiredAccess,
  1566. OpenAsSelf,
  1567. TokenHandle);
  1568. return Status;
  1569. }
  1570. //NTSYSAPI
  1571. NTSTATUS
  1572. NTAPI
  1573. VfZwOpenThreadTokenEx(
  1574. IN HANDLE ThreadHandle,
  1575. IN ACCESS_MASK DesiredAccess,
  1576. IN BOOLEAN OpenAsSelf,
  1577. IN ULONG HandleAttributes,
  1578. OUT PHANDLE TokenHandle
  1579. )
  1580. {
  1581. NTSTATUS Status;
  1582. PVOID Caller = _ReturnAddress();
  1583. if (VfZwShouldCheck (Caller)) {
  1584. VF_ZW_CHECK_HANDLE (ThreadHandle);
  1585. VF_ZW_CHECK_ADDRESS (TokenHandle);
  1586. }
  1587. Status = ZwOpenThreadTokenEx(ThreadHandle,
  1588. DesiredAccess,
  1589. OpenAsSelf,
  1590. HandleAttributes,
  1591. TokenHandle);
  1592. return Status;
  1593. }
  1594. //NTSYSAPI
  1595. NTSTATUS
  1596. NTAPI
  1597. VfZwOpenTimer (
  1598. OUT PHANDLE TimerHandle,
  1599. IN ACCESS_MASK DesiredAccess,
  1600. IN POBJECT_ATTRIBUTES ObjectAttributes
  1601. )
  1602. {
  1603. NTSTATUS Status;
  1604. PVOID Caller = _ReturnAddress();
  1605. if (VfZwShouldCheck (Caller)) {
  1606. VF_ZW_CHECK_ADDRESS (TimerHandle);
  1607. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  1608. }
  1609. Status = ZwOpenTimer (TimerHandle,
  1610. DesiredAccess,
  1611. ObjectAttributes);
  1612. return Status;
  1613. }
  1614. //NTSYSAPI
  1615. NTSTATUS
  1616. NTAPI
  1617. VfZwPowerInformation(
  1618. IN POWER_INFORMATION_LEVEL InformationLevel,
  1619. IN PVOID InputBuffer OPTIONAL,
  1620. IN ULONG InputBufferLength,
  1621. OUT PVOID OutputBuffer OPTIONAL,
  1622. IN ULONG OutputBufferLength
  1623. )
  1624. {
  1625. NTSTATUS Status;
  1626. PVOID Caller = _ReturnAddress();
  1627. if (VfZwShouldCheck (Caller)) {
  1628. VF_ZW_CHECK_ADDRESS (InputBuffer);
  1629. VF_ZW_CHECK_ADDRESS (OutputBuffer);
  1630. }
  1631. Status = ZwPowerInformation(InformationLevel,
  1632. InputBuffer OPTIONAL,
  1633. InputBufferLength,
  1634. OutputBuffer OPTIONAL,
  1635. OutputBufferLength);
  1636. return Status;
  1637. }
  1638. //NTSYSAPI
  1639. NTSTATUS
  1640. NTAPI
  1641. VfZwPulseEvent (
  1642. IN HANDLE EventHandle,
  1643. OUT PLONG PreviousState OPTIONAL
  1644. )
  1645. {
  1646. NTSTATUS Status;
  1647. PVOID Caller = _ReturnAddress();
  1648. if (VfZwShouldCheck (Caller)) {
  1649. VF_ZW_CHECK_HANDLE (EventHandle);
  1650. VF_ZW_CHECK_ADDRESS (PreviousState);
  1651. }
  1652. Status = ZwPulseEvent (EventHandle,
  1653. PreviousState OPTIONAL);
  1654. return Status;
  1655. }
  1656. //NTSYSAPI
  1657. NTSTATUS
  1658. NTAPI
  1659. VfZwQueryBootEntryOrder (
  1660. OUT PULONG Ids,
  1661. IN OUT PULONG Count
  1662. )
  1663. {
  1664. NTSTATUS Status;
  1665. PVOID Caller = _ReturnAddress();
  1666. if (VfZwShouldCheck (Caller)) {
  1667. VF_ZW_CHECK_ADDRESS (Ids);
  1668. VF_ZW_CHECK_ADDRESS (Count);
  1669. }
  1670. Status = ZwQueryBootEntryOrder(Ids,
  1671. Count);
  1672. return Status;
  1673. }
  1674. //NTSYSAPI
  1675. NTSTATUS
  1676. NTAPI
  1677. VfZwQueryBootOptions (
  1678. OUT PBOOT_OPTIONS BootOptions,
  1679. IN OUT PULONG BootOptionsLength
  1680. )
  1681. {
  1682. NTSTATUS Status;
  1683. PVOID Caller = _ReturnAddress();
  1684. if (VfZwShouldCheck (Caller)) {
  1685. VF_ZW_CHECK_ADDRESS (BootOptions);
  1686. VF_ZW_CHECK_ADDRESS (BootOptionsLength);
  1687. }
  1688. Status = ZwQueryBootOptions (BootOptions,
  1689. BootOptionsLength);
  1690. return Status;
  1691. }
  1692. //NTSYSAPI
  1693. NTSTATUS
  1694. NTAPI
  1695. VfZwQueryDefaultLocale(
  1696. IN BOOLEAN UserProfile,
  1697. OUT PLCID DefaultLocaleId
  1698. )
  1699. {
  1700. NTSTATUS Status;
  1701. PVOID Caller = _ReturnAddress();
  1702. if (VfZwShouldCheck (Caller)) {
  1703. VF_ZW_CHECK_ADDRESS (DefaultLocaleId);
  1704. }
  1705. Status = ZwQueryDefaultLocale(UserProfile,
  1706. DefaultLocaleId);
  1707. return Status;
  1708. }
  1709. //NTSYSAPI
  1710. NTSTATUS
  1711. NTAPI
  1712. VfZwQueryDefaultUILanguage(
  1713. OUT LANGID *DefaultUILanguageId
  1714. )
  1715. {
  1716. NTSTATUS Status;
  1717. PVOID Caller = _ReturnAddress();
  1718. if (VfZwShouldCheck (Caller)) {
  1719. VF_ZW_CHECK_ADDRESS (DefaultUILanguageId);
  1720. }
  1721. Status = ZwQueryDefaultUILanguage(DefaultUILanguageId);
  1722. return Status;
  1723. }
  1724. //NTSYSAPI
  1725. NTSTATUS
  1726. NTAPI
  1727. VfZwQueryDirectoryFile(
  1728. IN HANDLE FileHandle,
  1729. IN HANDLE Event OPTIONAL,
  1730. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  1731. IN PVOID ApcContext OPTIONAL,
  1732. OUT PIO_STATUS_BLOCK IoStatusBlock,
  1733. OUT PVOID FileInformation,
  1734. IN ULONG Length,
  1735. IN FILE_INFORMATION_CLASS FileInformationClass,
  1736. IN BOOLEAN ReturnSingleEntry,
  1737. IN PUNICODE_STRING FileName OPTIONAL,
  1738. IN BOOLEAN RestartScan
  1739. )
  1740. {
  1741. NTSTATUS Status;
  1742. PVOID Caller = _ReturnAddress();
  1743. if (VfZwShouldCheck (Caller)) {
  1744. VF_ZW_CHECK_HANDLE (FileHandle);
  1745. VF_ZW_CHECK_HANDLE (Event);
  1746. VF_ZW_CHECK_ADDRESS ((PVOID)ApcRoutine);
  1747. VF_ZW_CHECK_ADDRESS (ApcContext);
  1748. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  1749. VF_ZW_CHECK_ADDRESS (FileInformation);
  1750. VF_ZW_CHECK_UNICODE_STRING (FileName);
  1751. }
  1752. Status = ZwQueryDirectoryFile(FileHandle,
  1753. Event OPTIONAL,
  1754. ApcRoutine OPTIONAL,
  1755. ApcContext OPTIONAL,
  1756. IoStatusBlock,
  1757. FileInformation,
  1758. Length,
  1759. FileInformationClass,
  1760. ReturnSingleEntry,
  1761. FileName OPTIONAL,
  1762. RestartScan);
  1763. return Status;
  1764. }
  1765. //NTSYSAPI
  1766. NTSTATUS
  1767. NTAPI
  1768. VfZwQueryDirectoryObject(
  1769. IN HANDLE DirectoryHandle,
  1770. OUT PVOID Buffer,
  1771. IN ULONG Length,
  1772. IN BOOLEAN ReturnSingleEntry,
  1773. IN BOOLEAN RestartScan,
  1774. IN OUT PULONG Context,
  1775. OUT PULONG ReturnLength OPTIONAL
  1776. )
  1777. {
  1778. NTSTATUS Status;
  1779. PVOID Caller = _ReturnAddress();
  1780. if (VfZwShouldCheck (Caller)) {
  1781. VF_ZW_CHECK_HANDLE (DirectoryHandle);
  1782. VF_ZW_CHECK_ADDRESS (Buffer);
  1783. VF_ZW_CHECK_ADDRESS (Context);
  1784. VF_ZW_CHECK_ADDRESS (ReturnLength);
  1785. }
  1786. Status = ZwQueryDirectoryObject(DirectoryHandle,
  1787. Buffer,
  1788. Length,
  1789. ReturnSingleEntry,
  1790. RestartScan,
  1791. Context,
  1792. ReturnLength OPTIONAL);
  1793. return Status;
  1794. }
  1795. //NTSYSAPI
  1796. NTSTATUS
  1797. NTAPI
  1798. VfZwQueryDriverEntryOrder (
  1799. OUT PULONG Ids,
  1800. IN OUT PULONG Count
  1801. )
  1802. {
  1803. NTSTATUS Status;
  1804. PVOID Caller = _ReturnAddress();
  1805. if (VfZwShouldCheck (Caller)) {
  1806. VF_ZW_CHECK_ADDRESS (Ids);
  1807. VF_ZW_CHECK_ADDRESS (Count);
  1808. }
  1809. Status = ZwQueryDriverEntryOrder (Ids,
  1810. Count);
  1811. return Status;
  1812. }
  1813. //NTSYSAPI
  1814. NTSTATUS
  1815. NTAPI
  1816. VfZwQueryEaFile(
  1817. IN HANDLE FileHandle,
  1818. OUT PIO_STATUS_BLOCK IoStatusBlock,
  1819. OUT PVOID Buffer,
  1820. IN ULONG Length,
  1821. IN BOOLEAN ReturnSingleEntry,
  1822. IN PVOID EaList OPTIONAL,
  1823. IN ULONG EaListLength,
  1824. IN PULONG EaIndex OPTIONAL,
  1825. IN BOOLEAN RestartScan
  1826. )
  1827. {
  1828. NTSTATUS Status;
  1829. PVOID Caller = _ReturnAddress();
  1830. if (VfZwShouldCheck (Caller)) {
  1831. VF_ZW_CHECK_HANDLE (FileHandle);
  1832. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  1833. VF_ZW_CHECK_ADDRESS (Buffer);
  1834. VF_ZW_CHECK_ADDRESS (EaList);
  1835. VF_ZW_CHECK_ADDRESS (EaIndex);
  1836. }
  1837. Status = ZwQueryEaFile(FileHandle,
  1838. IoStatusBlock,
  1839. Buffer,
  1840. Length,
  1841. ReturnSingleEntry,
  1842. EaList OPTIONAL,
  1843. EaListLength,
  1844. EaIndex OPTIONAL,
  1845. RestartScan);
  1846. return Status;
  1847. }
  1848. //NTSYSAPI
  1849. NTSTATUS
  1850. NTAPI
  1851. VfZwQueryFullAttributesFile(
  1852. IN POBJECT_ATTRIBUTES ObjectAttributes,
  1853. OUT PFILE_NETWORK_OPEN_INFORMATION FileInformation
  1854. )
  1855. {
  1856. NTSTATUS Status;
  1857. PVOID Caller = _ReturnAddress();
  1858. if (VfZwShouldCheck (Caller)) {
  1859. VF_ZW_CHECK_OBJECT_ATTRIBUTES (ObjectAttributes);
  1860. VF_ZW_CHECK_ADDRESS (FileInformation);
  1861. }
  1862. Status = ZwQueryFullAttributesFile(ObjectAttributes,
  1863. FileInformation);
  1864. return Status;
  1865. }
  1866. //NTSYSAPI
  1867. NTSTATUS
  1868. NTAPI
  1869. VfZwQueryInformationFile(
  1870. IN HANDLE FileHandle,
  1871. OUT PIO_STATUS_BLOCK IoStatusBlock,
  1872. OUT PVOID FileInformation,
  1873. IN ULONG Length,
  1874. IN FILE_INFORMATION_CLASS FileInformationClass
  1875. )
  1876. {
  1877. NTSTATUS Status;
  1878. PVOID Caller = _ReturnAddress();
  1879. if (VfZwShouldCheck (Caller)) {
  1880. VF_ZW_CHECK_HANDLE (FileHandle);
  1881. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  1882. VF_ZW_CHECK_ADDRESS (FileInformation);
  1883. }
  1884. Status = ZwQueryInformationFile(FileHandle,
  1885. IoStatusBlock,
  1886. FileInformation,
  1887. Length,
  1888. FileInformationClass);
  1889. return Status;
  1890. }
  1891. //NTSYSAPI
  1892. NTSTATUS
  1893. NTAPI
  1894. VfZwQueryInformationJobObject(
  1895. IN HANDLE JobHandle,
  1896. IN JOBOBJECTINFOCLASS JobObjectInformationClass,
  1897. OUT PVOID JobObjectInformation,
  1898. IN ULONG JobObjectInformationLength,
  1899. OUT PULONG ReturnLength OPTIONAL
  1900. )
  1901. {
  1902. NTSTATUS Status;
  1903. PVOID Caller = _ReturnAddress();
  1904. if (VfZwShouldCheck (Caller)) {
  1905. VF_ZW_CHECK_HANDLE (JobHandle);
  1906. VF_ZW_CHECK_ADDRESS (JobObjectInformation);
  1907. VF_ZW_CHECK_ADDRESS (ReturnLength);
  1908. }
  1909. Status = ZwQueryInformationJobObject(JobHandle,
  1910. JobObjectInformationClass,
  1911. JobObjectInformation,
  1912. JobObjectInformationLength,
  1913. ReturnLength OPTIONAL);
  1914. return Status;
  1915. }
  1916. //NTSYSAPI
  1917. NTSTATUS
  1918. NTAPI
  1919. VfZwQueryInformationProcess(
  1920. IN HANDLE ProcessHandle,
  1921. IN PROCESSINFOCLASS ProcessInformationClass,
  1922. OUT PVOID ProcessInformation,
  1923. IN ULONG ProcessInformationLength,
  1924. OUT PULONG ReturnLength OPTIONAL
  1925. )
  1926. {
  1927. NTSTATUS Status;
  1928. PVOID Caller = _ReturnAddress();
  1929. if (VfZwShouldCheck (Caller)) {
  1930. VF_ZW_CHECK_HANDLE (ProcessHandle);
  1931. VF_ZW_CHECK_ADDRESS (ProcessInformation);
  1932. VF_ZW_CHECK_ADDRESS (ReturnLength);
  1933. }
  1934. Status = ZwQueryInformationProcess(ProcessHandle,
  1935. ProcessInformationClass,
  1936. ProcessInformation,
  1937. ProcessInformationLength,
  1938. ReturnLength OPTIONAL);
  1939. return Status;
  1940. }
  1941. //NTSYSAPI
  1942. NTSTATUS
  1943. NTAPI
  1944. VfZwQueryInformationThread(
  1945. IN HANDLE ThreadHandle,
  1946. IN THREADINFOCLASS ThreadInformationClass,
  1947. OUT PVOID ThreadInformation,
  1948. IN ULONG ThreadInformationLength,
  1949. OUT PULONG ReturnLength OPTIONAL
  1950. )
  1951. {
  1952. NTSTATUS Status;
  1953. PVOID Caller = _ReturnAddress();
  1954. if (VfZwShouldCheck (Caller)) {
  1955. VF_ZW_CHECK_HANDLE (ThreadHandle);
  1956. VF_ZW_CHECK_ADDRESS (ThreadInformation);
  1957. VF_ZW_CHECK_ADDRESS (ReturnLength);
  1958. }
  1959. Status = ZwQueryInformationThread(ThreadHandle,
  1960. ThreadInformationClass,
  1961. ThreadInformation,
  1962. ThreadInformationLength,
  1963. ReturnLength OPTIONAL);
  1964. return Status;
  1965. }
  1966. //NTSYSAPI
  1967. NTSTATUS
  1968. NTAPI
  1969. VfZwQueryInformationToken (
  1970. IN HANDLE TokenHandle,
  1971. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  1972. OUT PVOID TokenInformation,
  1973. IN ULONG TokenInformationLength,
  1974. OUT PULONG ReturnLength
  1975. )
  1976. {
  1977. NTSTATUS Status;
  1978. PVOID Caller = _ReturnAddress();
  1979. if (VfZwShouldCheck (Caller)) {
  1980. VF_ZW_CHECK_HANDLE (TokenHandle);
  1981. VF_ZW_CHECK_ADDRESS (TokenInformation);
  1982. VF_ZW_CHECK_ADDRESS (ReturnLength);
  1983. }
  1984. Status = ZwQueryInformationToken (TokenHandle,
  1985. TokenInformationClass,
  1986. TokenInformation,
  1987. TokenInformationLength,
  1988. ReturnLength);
  1989. return Status;
  1990. }
  1991. //NTSYSAPI
  1992. NTSTATUS
  1993. NTAPI
  1994. VfZwQueryInstallUILanguage(
  1995. OUT LANGID *InstallUILanguageId
  1996. )
  1997. {
  1998. NTSTATUS Status;
  1999. PVOID Caller = _ReturnAddress();
  2000. if (VfZwShouldCheck (Caller)) {
  2001. VF_ZW_CHECK_ADDRESS (InstallUILanguageId);
  2002. }
  2003. Status = ZwQueryInstallUILanguage(InstallUILanguageId);
  2004. return Status;
  2005. }
  2006. //NTSYSAPI
  2007. NTSTATUS
  2008. NTAPI
  2009. VfZwQueryKey(
  2010. IN HANDLE KeyHandle,
  2011. IN KEY_INFORMATION_CLASS KeyInformationClass,
  2012. OUT PVOID KeyInformation,
  2013. IN ULONG Length,
  2014. OUT PULONG ResultLength
  2015. )
  2016. {
  2017. NTSTATUS Status;
  2018. PVOID Caller = _ReturnAddress();
  2019. if (VfZwShouldCheck (Caller)) {
  2020. VF_ZW_CHECK_HANDLE (KeyHandle);
  2021. VF_ZW_CHECK_ADDRESS (KeyInformation);
  2022. VF_ZW_CHECK_ADDRESS (ResultLength);
  2023. }
  2024. Status = ZwQueryKey(KeyHandle,
  2025. KeyInformationClass,
  2026. KeyInformation,
  2027. Length,
  2028. ResultLength);
  2029. return Status;
  2030. }
  2031. //NTSYSAPI
  2032. NTSTATUS
  2033. NTAPI
  2034. VfZwQueryObject(
  2035. IN HANDLE Handle,
  2036. IN OBJECT_INFORMATION_CLASS ObjectInformationClass,
  2037. OUT PVOID ObjectInformation,
  2038. IN ULONG Length,
  2039. OUT PULONG ReturnLength OPTIONAL
  2040. )
  2041. {
  2042. NTSTATUS Status;
  2043. PVOID Caller = _ReturnAddress();
  2044. if (VfZwShouldCheck (Caller)) {
  2045. VF_ZW_CHECK_HANDLE (Handle);
  2046. VF_ZW_CHECK_ADDRESS (ObjectInformation);
  2047. VF_ZW_CHECK_ADDRESS (ReturnLength);
  2048. }
  2049. Status = ZwQueryObject(Handle,
  2050. ObjectInformationClass,
  2051. ObjectInformation,
  2052. Length,
  2053. ReturnLength OPTIONAL);
  2054. return Status;
  2055. }
  2056. //NTSYSAPI
  2057. NTSTATUS
  2058. NTAPI
  2059. VfZwQuerySection(
  2060. IN HANDLE SectionHandle,
  2061. IN SECTION_INFORMATION_CLASS SectionInformationClass,
  2062. OUT PVOID SectionInformation,
  2063. IN SIZE_T SectionInformationLength,
  2064. OUT PSIZE_T ReturnLength OPTIONAL
  2065. )
  2066. {
  2067. NTSTATUS Status;
  2068. PVOID Caller = _ReturnAddress();
  2069. if (VfZwShouldCheck (Caller)) {
  2070. VF_ZW_CHECK_HANDLE (SectionHandle);
  2071. VF_ZW_CHECK_ADDRESS (SectionInformation);
  2072. VF_ZW_CHECK_ADDRESS (ReturnLength);
  2073. }
  2074. Status = ZwQuerySection(SectionHandle,
  2075. SectionInformationClass,
  2076. SectionInformation,
  2077. SectionInformationLength,
  2078. ReturnLength OPTIONAL);
  2079. return Status;
  2080. }
  2081. //NTSYSAPI
  2082. NTSTATUS
  2083. NTAPI
  2084. VfZwQuerySecurityObject(
  2085. IN HANDLE Handle,
  2086. IN SECURITY_INFORMATION SecurityInformation,
  2087. OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  2088. IN ULONG Length,
  2089. OUT PULONG LengthNeeded
  2090. )
  2091. {
  2092. NTSTATUS Status;
  2093. PVOID Caller = _ReturnAddress();
  2094. if (VfZwShouldCheck (Caller)) {
  2095. VF_ZW_CHECK_HANDLE (Handle);
  2096. VF_ZW_CHECK_ADDRESS (SecurityDescriptor);
  2097. VF_ZW_CHECK_ADDRESS (LengthNeeded);
  2098. }
  2099. Status = ZwQuerySecurityObject(Handle,
  2100. SecurityInformation,
  2101. SecurityDescriptor,
  2102. Length,
  2103. LengthNeeded);
  2104. return Status;
  2105. }
  2106. //NTSYSAPI
  2107. NTSTATUS
  2108. NTAPI
  2109. VfZwQuerySymbolicLinkObject(
  2110. IN HANDLE LinkHandle,
  2111. IN OUT PUNICODE_STRING LinkTarget,
  2112. OUT PULONG ReturnedLength OPTIONAL
  2113. )
  2114. {
  2115. NTSTATUS Status;
  2116. PVOID Caller = _ReturnAddress();
  2117. if (VfZwShouldCheck (Caller)) {
  2118. VF_ZW_CHECK_HANDLE (LinkHandle);
  2119. VF_ZW_CHECK_UNICODE_STRING (LinkTarget);
  2120. VF_ZW_CHECK_ADDRESS (ReturnedLength);
  2121. }
  2122. Status = ZwQuerySymbolicLinkObject(LinkHandle,
  2123. LinkTarget,
  2124. ReturnedLength OPTIONAL);
  2125. return Status;
  2126. }
  2127. //NTSYSAPI
  2128. NTSTATUS
  2129. NTAPI
  2130. VfZwQuerySystemInformation (
  2131. IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
  2132. OUT PVOID SystemInformation,
  2133. IN ULONG SystemInformationLength,
  2134. OUT PULONG ReturnLength OPTIONAL
  2135. )
  2136. {
  2137. NTSTATUS Status;
  2138. PVOID Caller = _ReturnAddress();
  2139. if (VfZwShouldCheck (Caller)) {
  2140. VF_ZW_CHECK_ADDRESS (SystemInformation);
  2141. VF_ZW_CHECK_ADDRESS (ReturnLength);
  2142. }
  2143. Status = ZwQuerySystemInformation (SystemInformationClass,
  2144. SystemInformation,
  2145. SystemInformationLength,
  2146. ReturnLength OPTIONAL);
  2147. return Status;
  2148. }
  2149. //NTSYSAPI
  2150. NTSTATUS
  2151. NTAPI
  2152. VfZwQueryValueKey(
  2153. IN HANDLE KeyHandle,
  2154. IN PUNICODE_STRING ValueName,
  2155. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  2156. OUT PVOID KeyValueInformation,
  2157. IN ULONG Length,
  2158. OUT PULONG ResultLength
  2159. )
  2160. {
  2161. NTSTATUS Status;
  2162. PVOID Caller = _ReturnAddress();
  2163. if (VfZwShouldCheck (Caller)) {
  2164. VF_ZW_CHECK_HANDLE (KeyHandle);
  2165. VF_ZW_CHECK_UNICODE_STRING (ValueName);
  2166. VF_ZW_CHECK_ADDRESS (KeyValueInformation);
  2167. VF_ZW_CHECK_ADDRESS (ResultLength);
  2168. }
  2169. Status = ZwQueryValueKey(KeyHandle,
  2170. ValueName,
  2171. KeyValueInformationClass,
  2172. KeyValueInformation,
  2173. Length,
  2174. ResultLength);
  2175. return Status;
  2176. }
  2177. //NTSYSAPI
  2178. NTSTATUS
  2179. NTAPI
  2180. VfZwQueryVolumeInformationFile(
  2181. IN HANDLE FileHandle,
  2182. OUT PIO_STATUS_BLOCK IoStatusBlock,
  2183. OUT PVOID FsInformation,
  2184. IN ULONG Length,
  2185. IN FS_INFORMATION_CLASS FsInformationClass
  2186. )
  2187. {
  2188. NTSTATUS Status;
  2189. PVOID Caller = _ReturnAddress();
  2190. if (VfZwShouldCheck (Caller)) {
  2191. VF_ZW_CHECK_HANDLE (FileHandle);
  2192. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  2193. VF_ZW_CHECK_ADDRESS (FsInformation);
  2194. }
  2195. Status = ZwQueryVolumeInformationFile(FileHandle,
  2196. IoStatusBlock,
  2197. FsInformation,
  2198. Length,
  2199. FsInformationClass);
  2200. return Status;
  2201. }
  2202. //NTSYSAPI
  2203. NTSTATUS
  2204. NTAPI
  2205. VfZwReadFile(
  2206. IN HANDLE FileHandle,
  2207. IN HANDLE Event OPTIONAL,
  2208. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  2209. IN PVOID ApcContext OPTIONAL,
  2210. OUT PIO_STATUS_BLOCK IoStatusBlock,
  2211. OUT PVOID Buffer,
  2212. IN ULONG Length,
  2213. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  2214. IN PULONG Key OPTIONAL
  2215. )
  2216. {
  2217. NTSTATUS Status;
  2218. PVOID Caller = _ReturnAddress();
  2219. if (VfZwShouldCheck (Caller)) {
  2220. VF_ZW_CHECK_HANDLE (FileHandle);
  2221. VF_ZW_CHECK_HANDLE (Event);
  2222. VF_ZW_CHECK_ADDRESS ((PVOID)ApcRoutine);
  2223. VF_ZW_CHECK_ADDRESS (ApcContext);
  2224. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  2225. VF_ZW_CHECK_ADDRESS (Buffer);
  2226. VF_ZW_CHECK_ADDRESS (ByteOffset);
  2227. VF_ZW_CHECK_ADDRESS (Key);
  2228. }
  2229. Status = ZwReadFile(FileHandle,
  2230. Event OPTIONAL,
  2231. ApcRoutine OPTIONAL,
  2232. ApcContext OPTIONAL,
  2233. IoStatusBlock,
  2234. Buffer,
  2235. Length,
  2236. ByteOffset OPTIONAL,
  2237. Key OPTIONAL);
  2238. return Status;
  2239. }
  2240. //NTSYSAPI
  2241. NTSTATUS
  2242. NTAPI
  2243. VfZwReplaceKey(
  2244. IN POBJECT_ATTRIBUTES NewFile,
  2245. IN HANDLE TargetHandle,
  2246. IN POBJECT_ATTRIBUTES OldFile
  2247. )
  2248. {
  2249. NTSTATUS Status;
  2250. PVOID Caller = _ReturnAddress();
  2251. if (VfZwShouldCheck (Caller)) {
  2252. VF_ZW_CHECK_OBJECT_ATTRIBUTES (NewFile);
  2253. VF_ZW_CHECK_HANDLE (TargetHandle);
  2254. VF_ZW_CHECK_OBJECT_ATTRIBUTES (OldFile);
  2255. }
  2256. Status = ZwReplaceKey(NewFile,
  2257. TargetHandle,
  2258. OldFile);
  2259. return Status;
  2260. }
  2261. //NTSYSAPI
  2262. NTSTATUS
  2263. NTAPI
  2264. VfZwRequestWaitReplyPort(
  2265. IN HANDLE PortHandle,
  2266. IN PPORT_MESSAGE RequestMessage,
  2267. OUT PPORT_MESSAGE ReplyMessage
  2268. )
  2269. {
  2270. NTSTATUS Status;
  2271. PVOID Caller = _ReturnAddress();
  2272. if (VfZwShouldCheck (Caller)) {
  2273. VF_ZW_CHECK_HANDLE (PortHandle);
  2274. VF_ZW_CHECK_ADDRESS (RequestMessage);
  2275. VF_ZW_CHECK_ADDRESS (ReplyMessage);
  2276. }
  2277. Status = ZwRequestWaitReplyPort(PortHandle,
  2278. RequestMessage,
  2279. ReplyMessage);
  2280. return Status;
  2281. }
  2282. //NTSYSAPI
  2283. NTSTATUS
  2284. NTAPI
  2285. VfZwResetEvent (
  2286. IN HANDLE EventHandle,
  2287. OUT PLONG PreviousState OPTIONAL
  2288. )
  2289. {
  2290. NTSTATUS Status;
  2291. PVOID Caller = _ReturnAddress();
  2292. if (VfZwShouldCheck (Caller)) {
  2293. VF_ZW_CHECK_HANDLE (EventHandle);
  2294. VF_ZW_CHECK_ADDRESS (PreviousState);
  2295. }
  2296. Status = ZwResetEvent (EventHandle,
  2297. PreviousState OPTIONAL);
  2298. return Status;
  2299. }
  2300. //NTSYSAPI
  2301. NTSTATUS
  2302. NTAPI
  2303. VfZwRestoreKey(
  2304. IN HANDLE KeyHandle,
  2305. IN HANDLE FileHandle,
  2306. IN ULONG Flags
  2307. )
  2308. {
  2309. NTSTATUS Status;
  2310. PVOID Caller = _ReturnAddress();
  2311. if (VfZwShouldCheck (Caller)) {
  2312. VF_ZW_CHECK_HANDLE (KeyHandle);
  2313. VF_ZW_CHECK_HANDLE (FileHandle);
  2314. }
  2315. Status = ZwRestoreKey(KeyHandle,
  2316. FileHandle,
  2317. Flags);
  2318. return Status;
  2319. }
  2320. //NTSYSAPI
  2321. NTSTATUS
  2322. NTAPI
  2323. VfZwSaveKey(
  2324. IN HANDLE KeyHandle,
  2325. IN HANDLE FileHandle
  2326. )
  2327. {
  2328. NTSTATUS Status;
  2329. PVOID Caller = _ReturnAddress();
  2330. if (VfZwShouldCheck (Caller)) {
  2331. VF_ZW_CHECK_HANDLE (KeyHandle);
  2332. VF_ZW_CHECK_HANDLE (FileHandle);
  2333. }
  2334. Status = ZwSaveKey(KeyHandle,
  2335. FileHandle);
  2336. return Status;
  2337. }
  2338. //NTSYSAPI
  2339. NTSTATUS
  2340. NTAPI
  2341. VfZwSaveKeyEx(
  2342. IN HANDLE KeyHandle,
  2343. IN HANDLE FileHandle,
  2344. IN ULONG Format
  2345. )
  2346. {
  2347. NTSTATUS Status;
  2348. PVOID Caller = _ReturnAddress();
  2349. if (VfZwShouldCheck (Caller)) {
  2350. VF_ZW_CHECK_HANDLE (KeyHandle);
  2351. VF_ZW_CHECK_HANDLE (FileHandle);
  2352. }
  2353. Status = ZwSaveKeyEx(KeyHandle,
  2354. FileHandle,
  2355. Format);
  2356. return Status;
  2357. }
  2358. //NTSYSAPI
  2359. NTSTATUS
  2360. NTAPI
  2361. VfZwSetBootEntryOrder (
  2362. IN PULONG Ids,
  2363. IN ULONG Count
  2364. )
  2365. {
  2366. NTSTATUS Status;
  2367. PVOID Caller = _ReturnAddress();
  2368. if (VfZwShouldCheck (Caller)) {
  2369. VF_ZW_CHECK_ADDRESS (Ids);
  2370. }
  2371. Status = ZwSetBootEntryOrder (Ids,
  2372. Count);
  2373. return Status;
  2374. }
  2375. //NTSYSAPI
  2376. NTSTATUS
  2377. NTAPI
  2378. VfZwSetBootOptions (
  2379. IN PBOOT_OPTIONS BootOptions,
  2380. IN ULONG FieldsToChange
  2381. )
  2382. {
  2383. NTSTATUS Status;
  2384. PVOID Caller = _ReturnAddress();
  2385. if (VfZwShouldCheck (Caller)) {
  2386. VF_ZW_CHECK_ADDRESS (BootOptions);
  2387. }
  2388. Status = ZwSetBootOptions (BootOptions,
  2389. FieldsToChange);
  2390. return Status;
  2391. }
  2392. //NTSYSAPI
  2393. NTSTATUS
  2394. NTAPI
  2395. VfZwSetDefaultLocale(
  2396. IN BOOLEAN UserProfile,
  2397. IN LCID DefaultLocaleId
  2398. )
  2399. {
  2400. NTSTATUS Status;
  2401. PVOID Caller = _ReturnAddress();
  2402. if (VfZwShouldCheck (Caller)) {
  2403. // no-op check to avoid warning for `Caller'.
  2404. VF_ZW_CHECK_ADDRESS (NULL);
  2405. }
  2406. Status = ZwSetDefaultLocale(UserProfile,
  2407. DefaultLocaleId);
  2408. return Status;
  2409. }
  2410. //NTSYSAPI
  2411. NTSTATUS
  2412. NTAPI
  2413. VfZwSetDefaultUILanguage(
  2414. IN LANGID DefaultUILanguageId
  2415. )
  2416. {
  2417. NTSTATUS Status;
  2418. PVOID Caller = _ReturnAddress();
  2419. if (VfZwShouldCheck (Caller)) {
  2420. // no-op check to avoid warning for `Caller'.
  2421. VF_ZW_CHECK_ADDRESS (NULL);
  2422. }
  2423. Status = ZwSetDefaultUILanguage(DefaultUILanguageId);
  2424. return Status;
  2425. }
  2426. //NTSYSAPI
  2427. NTSTATUS
  2428. NTAPI
  2429. VfZwSetDriverEntryOrder (
  2430. IN PULONG Ids,
  2431. IN ULONG Count
  2432. )
  2433. {
  2434. NTSTATUS Status;
  2435. PVOID Caller = _ReturnAddress();
  2436. if (VfZwShouldCheck (Caller)) {
  2437. VF_ZW_CHECK_ADDRESS (Ids);
  2438. }
  2439. Status = ZwSetDriverEntryOrder (Ids,
  2440. Count);
  2441. return Status;
  2442. }
  2443. //NTSYSAPI
  2444. NTSTATUS
  2445. NTAPI
  2446. VfZwSetEaFile(
  2447. IN HANDLE FileHandle,
  2448. OUT PIO_STATUS_BLOCK IoStatusBlock,
  2449. IN PVOID Buffer,
  2450. IN ULONG Length
  2451. )
  2452. {
  2453. NTSTATUS Status;
  2454. PVOID Caller = _ReturnAddress();
  2455. if (VfZwShouldCheck (Caller)) {
  2456. VF_ZW_CHECK_HANDLE (FileHandle);
  2457. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  2458. VF_ZW_CHECK_ADDRESS (Buffer);
  2459. }
  2460. Status = ZwSetEaFile(FileHandle,
  2461. IoStatusBlock,
  2462. Buffer,
  2463. Length);
  2464. return Status;
  2465. }
  2466. //NTSYSAPI
  2467. NTSTATUS
  2468. NTAPI
  2469. VfZwSetEvent (
  2470. IN HANDLE EventHandle,
  2471. OUT PLONG PreviousState OPTIONAL
  2472. )
  2473. {
  2474. NTSTATUS Status;
  2475. PVOID Caller = _ReturnAddress();
  2476. if (VfZwShouldCheck (Caller)) {
  2477. VF_ZW_CHECK_HANDLE (EventHandle);
  2478. VF_ZW_CHECK_ADDRESS (PreviousState);
  2479. }
  2480. Status = ZwSetEvent (EventHandle,
  2481. PreviousState OPTIONAL);
  2482. return Status;
  2483. }
  2484. //NTSYSAPI
  2485. NTSTATUS
  2486. NTAPI
  2487. VfZwSetInformationFile(
  2488. IN HANDLE FileHandle,
  2489. OUT PIO_STATUS_BLOCK IoStatusBlock,
  2490. IN PVOID FileInformation,
  2491. IN ULONG Length,
  2492. IN FILE_INFORMATION_CLASS FileInformationClass
  2493. )
  2494. {
  2495. NTSTATUS Status;
  2496. PVOID Caller = _ReturnAddress();
  2497. if (VfZwShouldCheck (Caller)) {
  2498. VF_ZW_CHECK_HANDLE (FileHandle);
  2499. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  2500. VF_ZW_CHECK_ADDRESS (FileInformation);
  2501. }
  2502. Status = ZwSetInformationFile(FileHandle,
  2503. IoStatusBlock,
  2504. FileInformation,
  2505. Length,
  2506. FileInformationClass);
  2507. return Status;
  2508. }
  2509. //NTSYSAPI
  2510. NTSTATUS
  2511. NTAPI
  2512. VfZwSetInformationJobObject(
  2513. IN HANDLE JobHandle,
  2514. IN JOBOBJECTINFOCLASS JobObjectInformationClass,
  2515. IN PVOID JobObjectInformation,
  2516. IN ULONG JobObjectInformationLength
  2517. )
  2518. {
  2519. NTSTATUS Status;
  2520. PVOID Caller = _ReturnAddress();
  2521. if (VfZwShouldCheck (Caller)) {
  2522. VF_ZW_CHECK_HANDLE (JobHandle);
  2523. VF_ZW_CHECK_ADDRESS (JobObjectInformation);
  2524. }
  2525. Status = ZwSetInformationJobObject(JobHandle,
  2526. JobObjectInformationClass,
  2527. JobObjectInformation,
  2528. JobObjectInformationLength);
  2529. return Status;
  2530. }
  2531. //NTSYSAPI
  2532. NTSTATUS
  2533. NTAPI
  2534. VfZwSetInformationObject(
  2535. IN HANDLE Handle,
  2536. IN OBJECT_INFORMATION_CLASS ObjectInformationClass,
  2537. IN PVOID ObjectInformation,
  2538. IN ULONG ObjectInformationLength
  2539. )
  2540. {
  2541. NTSTATUS Status;
  2542. PVOID Caller = _ReturnAddress();
  2543. if (VfZwShouldCheck (Caller)) {
  2544. VF_ZW_CHECK_HANDLE (Handle);
  2545. VF_ZW_CHECK_ADDRESS (ObjectInformation);
  2546. }
  2547. Status = ZwSetInformationObject(Handle,
  2548. ObjectInformationClass,
  2549. ObjectInformation,
  2550. ObjectInformationLength);
  2551. return Status;
  2552. }
  2553. //NTSYSAPI
  2554. NTSTATUS
  2555. NTAPI
  2556. VfZwSetInformationProcess(
  2557. IN HANDLE ProcessHandle,
  2558. IN PROCESSINFOCLASS ProcessInformationClass,
  2559. IN PVOID ProcessInformation,
  2560. IN ULONG ProcessInformationLength
  2561. )
  2562. {
  2563. NTSTATUS Status;
  2564. PVOID Caller = _ReturnAddress();
  2565. if (VfZwShouldCheck (Caller)) {
  2566. VF_ZW_CHECK_HANDLE (ProcessHandle);
  2567. VF_ZW_CHECK_ADDRESS (ProcessInformation);
  2568. }
  2569. Status = ZwSetInformationProcess(ProcessHandle,
  2570. ProcessInformationClass,
  2571. ProcessInformation,
  2572. ProcessInformationLength);
  2573. return Status;
  2574. }
  2575. //NTSYSAPI
  2576. NTSTATUS
  2577. NTAPI
  2578. VfZwSetInformationThread(
  2579. IN HANDLE ThreadHandle,
  2580. IN THREADINFOCLASS ThreadInformationClass,
  2581. IN PVOID ThreadInformation,
  2582. IN ULONG ThreadInformationLength
  2583. )
  2584. {
  2585. NTSTATUS Status;
  2586. PVOID Caller = _ReturnAddress();
  2587. if (VfZwShouldCheck (Caller)) {
  2588. VF_ZW_CHECK_HANDLE (ThreadHandle);
  2589. VF_ZW_CHECK_ADDRESS (ThreadInformation);
  2590. }
  2591. Status = ZwSetInformationThread(ThreadHandle,
  2592. ThreadInformationClass,
  2593. ThreadInformation,
  2594. ThreadInformationLength);
  2595. return Status;
  2596. }
  2597. //NTSYSAPI
  2598. NTSTATUS
  2599. NTAPI
  2600. VfZwSetSecurityObject(
  2601. IN HANDLE Handle,
  2602. IN SECURITY_INFORMATION SecurityInformation,
  2603. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  2604. )
  2605. {
  2606. NTSTATUS Status;
  2607. PVOID Caller = _ReturnAddress();
  2608. if (VfZwShouldCheck (Caller)) {
  2609. VF_ZW_CHECK_HANDLE (Handle);
  2610. VF_ZW_CHECK_ADDRESS (SecurityDescriptor);
  2611. }
  2612. Status = ZwSetSecurityObject(Handle,
  2613. SecurityInformation,
  2614. SecurityDescriptor);
  2615. return Status;
  2616. }
  2617. //NTSYSAPI
  2618. NTSTATUS
  2619. NTAPI
  2620. VfZwSetSystemInformation (
  2621. IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
  2622. IN PVOID SystemInformation,
  2623. IN ULONG SystemInformationLength
  2624. )
  2625. {
  2626. NTSTATUS Status;
  2627. PVOID Caller = _ReturnAddress();
  2628. if (VfZwShouldCheck (Caller)) {
  2629. VF_ZW_CHECK_ADDRESS (SystemInformation);
  2630. }
  2631. Status = ZwSetSystemInformation (SystemInformationClass,
  2632. SystemInformation,
  2633. SystemInformationLength);
  2634. return Status;
  2635. }
  2636. //NTSYSAPI
  2637. NTSTATUS
  2638. NTAPI
  2639. VfZwSetSystemTime (
  2640. IN PLARGE_INTEGER SystemTime,
  2641. OUT PLARGE_INTEGER PreviousTime OPTIONAL
  2642. )
  2643. {
  2644. NTSTATUS Status;
  2645. PVOID Caller = _ReturnAddress();
  2646. if (VfZwShouldCheck (Caller)) {
  2647. VF_ZW_CHECK_ADDRESS (SystemTime);
  2648. VF_ZW_CHECK_ADDRESS (PreviousTime);
  2649. }
  2650. Status = ZwSetSystemTime (SystemTime,
  2651. PreviousTime OPTIONAL);
  2652. return Status;
  2653. }
  2654. //NTSYSAPI
  2655. NTSTATUS
  2656. NTAPI
  2657. VfZwSetTimer (
  2658. IN HANDLE TimerHandle,
  2659. IN PLARGE_INTEGER DueTime,
  2660. IN PTIMER_APC_ROUTINE TimerApcRoutine OPTIONAL,
  2661. IN PVOID TimerContext OPTIONAL,
  2662. IN BOOLEAN ResumeTimer,
  2663. IN LONG Period OPTIONAL,
  2664. OUT PBOOLEAN PreviousState OPTIONAL
  2665. )
  2666. {
  2667. NTSTATUS Status;
  2668. PVOID Caller = _ReturnAddress();
  2669. if (VfZwShouldCheck (Caller)) {
  2670. VF_ZW_CHECK_HANDLE (TimerHandle);
  2671. VF_ZW_CHECK_ADDRESS (DueTime);
  2672. VF_ZW_CHECK_ADDRESS ((PVOID)TimerApcRoutine);
  2673. VF_ZW_CHECK_ADDRESS (TimerContext);
  2674. VF_ZW_CHECK_ADDRESS (PreviousState);
  2675. }
  2676. Status = ZwSetTimer (TimerHandle,
  2677. DueTime,
  2678. TimerApcRoutine OPTIONAL,
  2679. TimerContext OPTIONAL,
  2680. ResumeTimer,
  2681. Period OPTIONAL,
  2682. PreviousState OPTIONAL);
  2683. return Status;
  2684. }
  2685. //NTSYSAPI
  2686. NTSTATUS
  2687. NTAPI
  2688. VfZwSetValueKey(
  2689. IN HANDLE KeyHandle,
  2690. IN PUNICODE_STRING ValueName,
  2691. IN ULONG TitleIndex OPTIONAL,
  2692. IN ULONG Type,
  2693. IN PVOID Data,
  2694. IN ULONG DataSize
  2695. )
  2696. {
  2697. NTSTATUS Status;
  2698. PVOID Caller = _ReturnAddress();
  2699. if (VfZwShouldCheck (Caller)) {
  2700. VF_ZW_CHECK_HANDLE (KeyHandle);
  2701. VF_ZW_CHECK_UNICODE_STRING (ValueName);
  2702. VF_ZW_CHECK_ADDRESS (Data);
  2703. }
  2704. Status = ZwSetValueKey(KeyHandle,
  2705. ValueName,
  2706. TitleIndex OPTIONAL,
  2707. Type,
  2708. Data,
  2709. DataSize);
  2710. return Status;
  2711. }
  2712. //NTSYSAPI
  2713. NTSTATUS
  2714. NTAPI
  2715. VfZwSetVolumeInformationFile(
  2716. IN HANDLE FileHandle,
  2717. OUT PIO_STATUS_BLOCK IoStatusBlock,
  2718. IN PVOID FsInformation,
  2719. IN ULONG Length,
  2720. IN FS_INFORMATION_CLASS FsInformationClass
  2721. )
  2722. {
  2723. NTSTATUS Status;
  2724. PVOID Caller = _ReturnAddress();
  2725. if (VfZwShouldCheck (Caller)) {
  2726. VF_ZW_CHECK_HANDLE (FileHandle);
  2727. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  2728. VF_ZW_CHECK_ADDRESS (FsInformation);
  2729. }
  2730. Status = ZwSetVolumeInformationFile(FileHandle,
  2731. IoStatusBlock,
  2732. FsInformation,
  2733. Length,
  2734. FsInformationClass);
  2735. return Status;
  2736. }
  2737. //NTSYSAPI
  2738. NTSTATUS
  2739. NTAPI
  2740. VfZwTerminateJobObject(
  2741. IN HANDLE JobHandle,
  2742. IN NTSTATUS ExitStatus
  2743. )
  2744. {
  2745. NTSTATUS Status;
  2746. PVOID Caller = _ReturnAddress();
  2747. if (VfZwShouldCheck (Caller)) {
  2748. VF_ZW_CHECK_HANDLE (JobHandle);
  2749. }
  2750. Status = ZwTerminateJobObject(JobHandle,
  2751. ExitStatus);
  2752. return Status;
  2753. }
  2754. //NTSYSAPI
  2755. NTSTATUS
  2756. NTAPI
  2757. VfZwTerminateProcess(
  2758. IN HANDLE ProcessHandle OPTIONAL,
  2759. IN NTSTATUS ExitStatus
  2760. )
  2761. {
  2762. NTSTATUS Status;
  2763. PVOID Caller = _ReturnAddress();
  2764. if (VfZwShouldCheck (Caller)) {
  2765. VF_ZW_CHECK_HANDLE (ProcessHandle);
  2766. }
  2767. Status = ZwTerminateProcess(ProcessHandle OPTIONAL,
  2768. ExitStatus);
  2769. return Status;
  2770. }
  2771. //NTSYSAPI
  2772. NTSTATUS
  2773. NTAPI
  2774. VfZwTranslateFilePath (
  2775. IN PFILE_PATH InputFilePath,
  2776. IN ULONG OutputType,
  2777. OUT PFILE_PATH OutputFilePath,
  2778. IN OUT PULONG OutputFilePathLength
  2779. )
  2780. {
  2781. NTSTATUS Status;
  2782. PVOID Caller = _ReturnAddress();
  2783. if (VfZwShouldCheck (Caller)) {
  2784. VF_ZW_CHECK_ADDRESS (InputFilePath);
  2785. VF_ZW_CHECK_ADDRESS (OutputFilePath);
  2786. VF_ZW_CHECK_ADDRESS (OutputFilePathLength);
  2787. }
  2788. Status = ZwTranslateFilePath (InputFilePath,
  2789. OutputType,
  2790. OutputFilePath,
  2791. OutputFilePathLength);
  2792. return Status;
  2793. }
  2794. //NTSYSAPI
  2795. NTSTATUS
  2796. NTAPI
  2797. VfZwUnloadDriver(
  2798. IN PUNICODE_STRING DriverServiceName
  2799. )
  2800. {
  2801. NTSTATUS Status;
  2802. PVOID Caller = _ReturnAddress();
  2803. if (VfZwShouldCheck (Caller)) {
  2804. VF_ZW_CHECK_UNICODE_STRING (DriverServiceName);
  2805. }
  2806. Status = ZwUnloadDriver(DriverServiceName);
  2807. return Status;
  2808. }
  2809. //NTSYSAPI
  2810. NTSTATUS
  2811. NTAPI
  2812. VfZwUnloadKey(
  2813. IN POBJECT_ATTRIBUTES TargetKey
  2814. )
  2815. {
  2816. NTSTATUS Status;
  2817. PVOID Caller = _ReturnAddress();
  2818. if (VfZwShouldCheck (Caller)) {
  2819. VF_ZW_CHECK_OBJECT_ATTRIBUTES (TargetKey);
  2820. }
  2821. Status = ZwUnloadKey(TargetKey);
  2822. return Status;
  2823. }
  2824. //NTSYSAPI
  2825. NTSTATUS
  2826. NTAPI
  2827. VfZwUnmapViewOfSection(
  2828. IN HANDLE ProcessHandle,
  2829. IN PVOID BaseAddress
  2830. )
  2831. {
  2832. NTSTATUS Status;
  2833. PVOID Caller = _ReturnAddress();
  2834. if (VfZwShouldCheck (Caller)) {
  2835. VF_ZW_CHECK_HANDLE (ProcessHandle);
  2836. VF_ZW_CHECK_ADDRESS (BaseAddress);
  2837. }
  2838. Status = ZwUnmapViewOfSection(ProcessHandle,
  2839. BaseAddress);
  2840. return Status;
  2841. }
  2842. //NTSYSAPI
  2843. NTSTATUS
  2844. NTAPI
  2845. VfZwWaitForMultipleObjects(
  2846. IN ULONG Count,
  2847. IN HANDLE Handles[],
  2848. IN WAIT_TYPE WaitType,
  2849. IN BOOLEAN Alertable,
  2850. IN PLARGE_INTEGER Timeout OPTIONAL
  2851. )
  2852. {
  2853. NTSTATUS Status;
  2854. PVOID Caller = _ReturnAddress();
  2855. ULONG Index;
  2856. if (VfZwShouldCheck (Caller)) {
  2857. VF_ZW_CHECK_ADDRESS (Handles);
  2858. VF_ZW_CHECK_ADDRESS (Timeout);
  2859. for (Index = 0; Index < Count; Index += 1) {
  2860. VF_ZW_CHECK_HANDLE (Handles[Index]);
  2861. }
  2862. }
  2863. Status = ZwWaitForMultipleObjects(Count,
  2864. Handles,
  2865. WaitType,
  2866. Alertable,
  2867. Timeout OPTIONAL);
  2868. return Status;
  2869. }
  2870. //NTSYSAPI
  2871. NTSTATUS
  2872. NTAPI
  2873. VfZwWaitForSingleObject(
  2874. IN HANDLE Handle,
  2875. IN BOOLEAN Alertable,
  2876. IN PLARGE_INTEGER Timeout OPTIONAL
  2877. )
  2878. {
  2879. NTSTATUS Status;
  2880. PVOID Caller = _ReturnAddress();
  2881. if (VfZwShouldCheck (Caller)) {
  2882. VF_ZW_CHECK_HANDLE (Handle);
  2883. VF_ZW_CHECK_ADDRESS (Timeout);
  2884. }
  2885. Status = ZwWaitForSingleObject(Handle,
  2886. Alertable,
  2887. Timeout);
  2888. return Status;
  2889. }
  2890. //NTSYSAPI
  2891. NTSTATUS
  2892. NTAPI
  2893. VfZwWriteFile(
  2894. IN HANDLE FileHandle,
  2895. IN HANDLE Event OPTIONAL,
  2896. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  2897. IN PVOID ApcContext OPTIONAL,
  2898. OUT PIO_STATUS_BLOCK IoStatusBlock,
  2899. IN PVOID Buffer,
  2900. IN ULONG Length,
  2901. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  2902. IN PULONG Key OPTIONAL
  2903. )
  2904. {
  2905. NTSTATUS Status;
  2906. PVOID Caller = _ReturnAddress();
  2907. if (VfZwShouldCheck (Caller)) {
  2908. VF_ZW_CHECK_HANDLE (FileHandle);
  2909. VF_ZW_CHECK_HANDLE (Event);
  2910. VF_ZW_CHECK_ADDRESS ((PVOID)ApcRoutine);
  2911. VF_ZW_CHECK_ADDRESS (ApcContext);
  2912. VF_ZW_CHECK_ADDRESS (IoStatusBlock);
  2913. VF_ZW_CHECK_ADDRESS (Buffer);
  2914. VF_ZW_CHECK_ADDRESS (ByteOffset);
  2915. VF_ZW_CHECK_ADDRESS (Key);
  2916. }
  2917. Status = ZwWriteFile(FileHandle,
  2918. Event OPTIONAL,
  2919. ApcRoutine OPTIONAL,
  2920. ApcContext OPTIONAL,
  2921. IoStatusBlock,
  2922. Buffer,
  2923. Length,
  2924. ByteOffset OPTIONAL,
  2925. Key OPTIONAL);
  2926. return Status;
  2927. }
  2928. //NTSYSAPI
  2929. NTSTATUS
  2930. NTAPI
  2931. VfZwYieldExecution (
  2932. VOID
  2933. )
  2934. {
  2935. NTSTATUS Status;
  2936. PVOID Caller = _ReturnAddress();
  2937. if (VfZwShouldCheck (Caller)) {
  2938. // no-op check to avoid warning for `Caller' local.
  2939. VF_ZW_CHECK_ADDRESS (NULL);
  2940. }
  2941. Status = ZwYieldExecution();
  2942. return Status;
  2943. }
  2944. /////////////////////////////////////////////////////////////////////
  2945. /////////////////////////////////////////////////////////////////////
  2946. /////////////////////////////////////////////////////////////////////
  2947. //
  2948. // Turns on and off the entire Zw verifier code.
  2949. //
  2950. LOGICAL VfZwVerifierEnabled = FALSE;
  2951. //
  2952. // If Zw verifier is on, controls if sessions space drivers are checked.
  2953. //
  2954. LOGICAL VfZwVerifierSessionEnabled = TRUE;
  2955. //
  2956. // Do we break for issues?
  2957. //
  2958. LOGICAL VfZwBreakForIssues = FALSE;
  2959. //
  2960. // Break for virtual space allocations (alloc/map)?
  2961. //
  2962. LOGICAL VfZwBreakForVspaceOps = FALSE;
  2963. //
  2964. // Enable decommitted memory attacks on ZwAlloc/ZwMap users.
  2965. //
  2966. LOGICAL VfZwEnableSimulatedAttacks = FALSE;
  2967. LOGICAL VfZwSystemSufficientlyBooted;
  2968. #define VF_ZW_TIME_ONE_SECOND ((LONGLONG)(1000 * 1000 * 10))
  2969. LONGLONG VfZwRequiredTimeSinceBoot = 5 * 60 * VF_ZW_TIME_ONE_SECOND;
  2970. PVOID VfZwLastCall;
  2971. #define MAX_NO_OF_ISSUES 256
  2972. ULONG VfZwReportedIssuesIndex;
  2973. PVOID VfZwReportedIssues[MAX_NO_OF_ISSUES];
  2974. #define VF_ZW_USER_MODE_ADDRESS_USED 1
  2975. #define VF_ZW_USER_MODE_HANDLE_USED 2
  2976. LOGICAL
  2977. VfZwShouldCheck (
  2978. PVOID Caller
  2979. )
  2980. {
  2981. PEPROCESS CurrentProcess;
  2982. if (VfZwVerifierEnabled == FALSE) {
  2983. return FALSE;
  2984. }
  2985. //
  2986. // Skip system process.
  2987. //
  2988. CurrentProcess = PsGetCurrentProcess();
  2989. if (CurrentProcess == PsInitialSystemProcess) {
  2990. return FALSE;
  2991. }
  2992. //
  2993. // Check if we want to skip session space drivers (e.g. win32k.sys).
  2994. //
  2995. if (MmIsSessionAddress(Caller)) {
  2996. if (VfZwVerifierSessionEnabled == FALSE) {
  2997. return FALSE;
  2998. }
  2999. }
  3000. //
  3001. // Skip exempt (trusted) processes (e.g. lsass, csrss, etc.).
  3002. //
  3003. if (_stricmp ((PCHAR)CurrentProcess->ImageFileName, "lsass.exe") == 0) {
  3004. return FALSE;
  3005. }
  3006. if (_stricmp ((PCHAR)CurrentProcess->ImageFileName, "csrss.exe") == 0) {
  3007. return FALSE;
  3008. }
  3009. if (_stricmp ((PCHAR)CurrentProcess->ImageFileName, "smss.exe") == 0) {
  3010. return FALSE;
  3011. }
  3012. return TRUE;
  3013. }
  3014. VOID
  3015. VfZwReportIssue (
  3016. ULONG IssueType,
  3017. PVOID Information,
  3018. PVOID Caller
  3019. )
  3020. {
  3021. switch (IssueType) {
  3022. case VF_ZW_USER_MODE_HANDLE_USED:
  3023. DbgPrint ("DVRF:ZW: Using user mode handle %p in Zw call from %p \n",
  3024. Information, Caller);
  3025. break;
  3026. case VF_ZW_USER_MODE_ADDRESS_USED:
  3027. DbgPrint ("DVRF:ZW: Using user mode address %p in Zw call from %p \n",
  3028. Information, Caller);
  3029. break;
  3030. default:
  3031. return;
  3032. }
  3033. if (VfZwBreakForIssues) {
  3034. DbgBreakPoint ();
  3035. }
  3036. }
  3037. LOGICAL
  3038. VfZwShouldReportIssue (
  3039. PVOID Caller
  3040. )
  3041. {
  3042. ULONG Index;
  3043. for (Index = 0; Index < VfZwReportedIssuesIndex; Index += 1) {
  3044. if (VfZwReportedIssues[Index] == Caller) {
  3045. return FALSE;
  3046. }
  3047. }
  3048. Index = (ULONG)InterlockedIncrement((PLONG)(&VfZwReportedIssuesIndex));
  3049. if (Index >= MAX_NO_OF_ISSUES) {
  3050. DbgPrint ("DVRF:ZW: reported issues buffer has been maxed out. \n");
  3051. return FALSE;
  3052. }
  3053. VfZwReportedIssues[Index] = Caller;
  3054. return TRUE;
  3055. }
  3056. VOID
  3057. VfZwReportUserModeVirtualSpaceOperation (
  3058. PVOID Caller
  3059. )
  3060. {
  3061. if (VfZwBreakForVspaceOps) {
  3062. DbgPrint ("DVRF:ZW: user-mode virtual space allocation made by %p \n", Caller);
  3063. DbgBreakPoint();
  3064. }
  3065. }
  3066. LOGICAL
  3067. VfZwShouldSimulateDecommitAttack (
  3068. VOID
  3069. )
  3070. {
  3071. LARGE_INTEGER CurrentTime;
  3072. if (VfZwEnableSimulatedAttacks == FALSE) {
  3073. return FALSE;
  3074. }
  3075. if (VfZwSystemSufficientlyBooted == FALSE) {
  3076. KeQuerySystemTime (&CurrentTime);
  3077. if (CurrentTime.QuadPart > KeBootTime.QuadPart + VfZwRequiredTimeSinceBoot) {
  3078. VfZwSystemSufficientlyBooted = TRUE;
  3079. }
  3080. }
  3081. else {
  3082. KeQueryTickCount(&CurrentTime);
  3083. if ((CurrentTime.LowPart & 0xF) == 0) {
  3084. return TRUE;
  3085. }
  3086. }
  3087. return FALSE;
  3088. }
  3089. ULONG
  3090. VfZwExceptionFilter (
  3091. PVOID ExceptionInfo
  3092. )
  3093. {
  3094. DbgPrint("DVRF:ZW: exception raised! (info: %X) \n", ExceptionInfo);
  3095. DbgBreakPoint();
  3096. return EXCEPTION_EXECUTE_HANDLER;
  3097. }
  3098. VOID
  3099. VfZwCheckAddress (
  3100. PVOID Address,
  3101. PVOID Caller
  3102. )
  3103. {
  3104. if (Address == NULL) {
  3105. return;
  3106. }
  3107. VfZwLastCall = _ReturnAddress();
  3108. if ((ULONG_PTR)Address < (ULONG_PTR)(MM_HIGHEST_USER_ADDRESS)) {
  3109. if (VfZwShouldReportIssue (Caller)) {
  3110. VfZwReportIssue (VF_ZW_USER_MODE_ADDRESS_USED,
  3111. Address,
  3112. Caller);
  3113. }
  3114. }
  3115. }
  3116. VOID
  3117. VfZwCheckHandle (
  3118. PVOID Handle,
  3119. PVOID Caller
  3120. )
  3121. {
  3122. if (Handle == NULL) {
  3123. return;
  3124. }
  3125. VfZwLastCall = _ReturnAddress();
  3126. //
  3127. // Macro inspired from ntos\ob\obp.h
  3128. // A kernel handle is just a regular handle with its sign
  3129. // bit set. But must exclude -1 and -2 values which are the current
  3130. // process and current thread constants.
  3131. //
  3132. #define KERNEL_HANDLE_MASK ((ULONG_PTR)((LONG)0x80000000))
  3133. if ((KERNEL_HANDLE_MASK & (ULONG_PTR)(Handle)) != KERNEL_HANDLE_MASK) {
  3134. if (Handle != NtCurrentThread() &&
  3135. Handle != NtCurrentProcess()) {
  3136. if (VfZwShouldReportIssue (Caller)) {
  3137. VfZwReportIssue (VF_ZW_USER_MODE_HANDLE_USED,
  3138. Handle,
  3139. Caller);
  3140. }
  3141. }
  3142. }
  3143. }
  3144. VOID
  3145. VfZwCheckObjectAttributes (
  3146. POBJECT_ATTRIBUTES ObjectAttributes,
  3147. PVOID Caller
  3148. )
  3149. {
  3150. if (ObjectAttributes == NULL) {
  3151. return;
  3152. }
  3153. VfZwLastCall = _ReturnAddress();
  3154. VfZwCheckAddress (ObjectAttributes, Caller);
  3155. VfZwCheckHandle (ObjectAttributes->RootDirectory, Caller);
  3156. VfZwCheckUnicodeString (ObjectAttributes->ObjectName, Caller);
  3157. VfZwCheckAddress (ObjectAttributes->SecurityDescriptor, Caller);
  3158. VfZwCheckAddress (ObjectAttributes->SecurityQualityOfService, Caller);
  3159. }
  3160. VOID
  3161. VfZwCheckUnicodeString (
  3162. PUNICODE_STRING String,
  3163. PVOID Caller
  3164. )
  3165. {
  3166. if (String == NULL) {
  3167. return;
  3168. }
  3169. VfZwLastCall = _ReturnAddress();
  3170. VfZwCheckAddress (String, Caller);
  3171. VfZwCheckAddress (String->Buffer, Caller);
  3172. }
  3173. #ifdef ALLOC_DATA_PRAGMA
  3174. #pragma data_seg("PAGEVRFD")
  3175. #endif