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.

554 lines
14 KiB

  1. /*++
  2. Copyright (b\\c) 2000 Microsoft Corporation
  3. Module Name:
  4. tpath.b\\c
  5. Abstract:
  6. Test program for path stuff in rtl.
  7. Author:
  8. Jay Krell (a-JayK) November 2000
  9. Revision History:
  10. --*/
  11. #include "nt.h"
  12. #include "ntrtl.h"
  13. #include "nturtl.h"
  14. #include "windows.h"
  15. #include <stdio.h>
  16. //__declspec(selectany) int _ldused = 0;
  17. //__declspec(selectany) int _fltused = 0;
  18. #if 1
  19. void __stdcall RtlpInitDeferredCriticalSection(void);
  20. void __stdcall RtlpDphInitializeDelayedFreeQueue(void);
  21. extern RTL_CRITICAL_SECTION RtlpDphHeapListCriticalSection;
  22. VOID __stdcall LdrpInitialize (IN PCONTEXT Context, IN PVOID SystemArgument1, IN PVOID SystemArgument2);
  23. void NtdllMain()
  24. {
  25. PPEB PPeb = NtCurrentPeb();
  26. PTEB PTeb = NtCurrentTeb();
  27. PEB Peb;
  28. TEB Teb;
  29. HANDLE NtdllModuleHandle = GetModuleHandleW(L"ntdll.dll");
  30. HANDLE MyModuleHandle = GetModuleHandleW(NULL);
  31. PIMAGE_NT_HEADERS MyHeaders = RtlImageNtHeader(MyModuleHandle);
  32. /*const*/ static IMAGE_NT_HEADERS ZeroHeaders = { 0 };
  33. SIZE_T RegionSize = 0x10000;
  34. PVOID Base = MyModuleHandle;
  35. ULONG OldProtect = 0;
  36. NTSTATUS Status;
  37. Status = NtProtectVirtualMemory(
  38. NtCurrentProcess(),
  39. &Base,
  40. &RegionSize,
  41. PAGE_EXECUTE_READWRITE,
  42. &OldProtect
  43. );
  44. /*
  45. WriteProcessMemory(
  46. NtCurrentProcess(),
  47. &MyHeaders->OptionalHeader.DataDirectory,
  48. &ZeroHeaders,
  49. sizeof(MyHeaders->OptionalHeader.DataDirectory),
  50. NULL
  51. );
  52. */
  53. RtlZeroMemory(&MyHeaders->OptionalHeader.DataDirectory, sizeof(MyHeaders->OptionalHeader.DataDirectory));
  54. #if 0
  55. NLSTABLEINFO InitTableInfo = {0};
  56. RtlInitNlsTables(
  57. Peb->AnsiCodePageData,
  58. Peb->OemCodePageData,
  59. Peb->UnicodeCaseTableData,
  60. &InitTableInfo
  61. );
  62. RtlResetRtlTranslations(&InitTableInfo);
  63. RtlpInitDeferredCriticalSection();
  64. RtlInitializeCriticalSection( &RtlpDphHeapListCriticalSection );
  65. RtlpDphInitializeDelayedFreeQueue();
  66. #elif 1
  67. Peb = *PPeb;
  68. Teb = *PTeb;
  69. RtlZeroMemory(NtCurrentPeb(), sizeof(*NtCurrentPeb()));
  70. PPeb->ProcessParameters = Peb.ProcessParameters;
  71. PPeb->BeingDebugged = Peb.BeingDebugged;
  72. PPeb->FastPebLock = Peb.FastPebLock;
  73. PPeb->FastPebLockRoutine = Peb.FastPebLockRoutine;
  74. PPeb->FastPebUnlockRoutine = Peb.FastPebUnlockRoutine;
  75. PPeb->ProcessHeap = Peb.ProcessHeap;
  76. PPeb->ImageBaseAddress = Peb.ImageBaseAddress;
  77. PPeb->AnsiCodePageData = Peb.AnsiCodePageData;
  78. PPeb->OemCodePageData = Peb.OemCodePageData;
  79. PPeb->UnicodeCaseTableData = Peb.UnicodeCaseTableData;
  80. PPeb->NtGlobalFlag = Peb.NtGlobalFlag
  81. /*
  82. | FLG_HEAP_ENABLE_TAIL_CHECK |
  83. FLG_HEAP_ENABLE_FREE_CHECK |
  84. FLG_HEAP_VALIDATE_PARAMETERS |
  85. FLG_HEAP_VALIDATE_ALL |
  86. FLG_HEAP_ENABLE_TAGGING
  87. */
  88. ;
  89. __try
  90. {
  91. //LdrpInitialize(0, NtdllModuleHandle, 0);
  92. }
  93. __except(EXCEPTION_EXECUTE_HANDLER)
  94. {
  95. }
  96. PPeb->ProcessParameters = Peb.ProcessParameters;
  97. PPeb->BeingDebugged = Peb.BeingDebugged;
  98. PPeb->NtGlobalFlag = Peb.NtGlobalFlag
  99. /*
  100. | FLG_HEAP_ENABLE_TAIL_CHECK |
  101. FLG_HEAP_ENABLE_FREE_CHECK |
  102. FLG_HEAP_VALIDATE_PARAMETERS |
  103. FLG_HEAP_VALIDATE_ALL |
  104. FLG_HEAP_ENABLE_TAGGING
  105. */
  106. ;
  107. PPeb->FastPebLock = Peb.FastPebLock;
  108. PPeb->FastPebLockRoutine = Peb.FastPebLockRoutine;
  109. PPeb->ProcessHeap = Peb.ProcessHeap;
  110. PPeb->FastPebUnlockRoutine = Peb.FastPebUnlockRoutine;
  111. PPeb->ImageBaseAddress = Peb.ImageBaseAddress;
  112. PPeb->AnsiCodePageData = Peb.AnsiCodePageData;
  113. PPeb->OemCodePageData = Peb.OemCodePageData;
  114. PPeb->UnicodeCaseTableData = Peb.UnicodeCaseTableData;
  115. PPeb->Ldr = Peb.Ldr;
  116. #else
  117. #endif
  118. }
  119. #else
  120. void NtdllMain() { }
  121. #include "curdir.c"
  122. #endif
  123. // WriteProcessMemory(1 + (ULONG_PTR)RtlEnterCriticalSection, GetModuleHandleW(L"ntdll.dll"), "RtlEnterCriticalSection"
  124. static BOOLEAN InMain;
  125. int __cdecl main(int argc, char** argv)
  126. {
  127. UCHAR Buffer[100];
  128. RTL_UNICODE_STRING_BUFFER StringBuffer = {0};
  129. UNICODE_STRING String = {0};
  130. ULONG i = 0;
  131. PCWSTR x = 0;
  132. PCWSTR y = 0;
  133. NTSTATUS Status = 0;
  134. const static WCHAR AppendPathElementTestData[] =
  135. {
  136. // noslash
  137. L"a\0bar\0" // = a\b
  138. // one slash
  139. L"/a\0bar\0" // = /a/b
  140. L"a/\0bar\0" // = /a/b/
  141. L"a\0/b\0" // = a/b
  142. L"a\0bar/\0" // = a/b/
  143. // two slashes
  144. L"/a/\0bar\0" // = /a/b/
  145. L"/a\0/b\0" // = /a/b
  146. L"/a\0bar/\0" // = /a/b/
  147. L"a/\0/b\0" // = a/b/
  148. L"a/\0bar/\0" // = a/b/
  149. L"a\0/b/\0" // = a/b/
  150. // three slashes
  151. L"/a/\0/b\0" // = /a/b/
  152. L"/a/\0bar/\0" // = /a/b/
  153. L"/a\0/b/\0" // = /a/b/
  154. L"a/\0/b/\0" // = a/b
  155. // four slashes
  156. L"/a/\0/b/\0" // = /a/b/
  157. //
  158. // 1 + 4 + 6 + 4 + 1 = 4^2 = 16 posibilities
  159. L"\0"
  160. };
  161. const static WCHAR RemoveLastPathElementTestData[] =
  162. {
  163. //
  164. // move/copy cases to the top to debug them
  165. //
  166. //L"c:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
  167. //L"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
  168. //L"\0"
  169. L"\\\\a\\\\b\\\\c\\\\\0"
  170. L"x:\\\0"
  171. L"c:a\\\\b\\c\\\\\0"
  172. L"\\\\?\\a:\\\0"
  173. L"\\\\?\\unc\\a\\b\0"
  174. L"\\\0"
  175. L"\\\\\0"
  176. L"\\\\?\0"
  177. L"\\\\?\\unc\0"
  178. L"\\\\?\\unc\\a\0"
  179. L"\\\\?\\unc\\a\\b\0"
  180. L"\\\\?\\unc\\a\\b\\c\0"
  181. L"\\\\?\\a\0"
  182. L"\\\\?\\a\\b\0"
  183. L"\\\\?\\a\\b\\c\0"
  184. L"\\\\?\\a:\0"
  185. L"\\\\?\\a:\\\0"
  186. L"\\\\?\\a:\\b\0"
  187. L"\\\\?\\a:\\b\\c\0"
  188. L"\\\\a\\\\b\\c\\\\\0"
  189. L"\\\\a\\\\b\\c\\\0"
  190. L"\\\\a\\\\b\\c/\0"
  191. L"\\\\a\\\\b\\c//\0"
  192. L"\\\\a\\\\b\\c/\\\0"
  193. L"\\\\a\\\\b\\c\\/\0"
  194. L"\\\\a\\\\b\\c\0"
  195. L"\\\\a\\b\\c\\\\\0"
  196. L"\\\\a\\b\\c\\\0"
  197. L"\\\\a\\b\\c/\0"
  198. L"\\\\a\\b\\c//\0"
  199. L"\\\\a\\b\\c/\\\0"
  200. L"\\\\a\\b\\c\\/\0"
  201. L"\\\\a\\b\\c\0"
  202. L"\\\\a/b\\c\\\\\0"
  203. L"\\\\a/b\\c\\\0"
  204. L"\\\\a/b\\c/\0"
  205. L"\\\\a/b\\c//\0"
  206. L"\\\\a/b\\c/\\\0"
  207. L"\\\\a/b\\c\\/\0"
  208. L"\\\\a/b\\c\0"
  209. L"\\\\a//b\\c\\\\\0"
  210. L"\\\\a//b\\c\\\0"
  211. L"\\\\a//b\\c/\0"
  212. L"\\\\a//b\\c//\0"
  213. L"\\\\a//b\\c/\\\0"
  214. L"\\\\a//b\\c\\/\0"
  215. L"\\\\a//b\\c\0"
  216. L"\\\\a/\\b\\c\\\\\0"
  217. L"\\\\a/\\b\\c\\\0"
  218. L"\\\\a/\\b\\c/\0"
  219. L"\\\\a/\\b\\c//\0"
  220. L"\\\\a/\\b\\c/\\\0"
  221. L"\\\\a/\\b\\c\\/\0"
  222. L"\\\\a/\\b\\c\0"
  223. L"\\\\a\\/b\\c\\\\\0"
  224. L"\\\\a\\/b\\c\\\0"
  225. L"\\\\a\\/b\\c/\0"
  226. L"\\\\a\\/b\\c//\0"
  227. L"\\\\a\\/b\\c/\\\0"
  228. L"\\\\a\\/b\\c\\/\0"
  229. L"\\\\a\\/b\\c\0"
  230. L"\\\\\0"
  231. L"//\0"
  232. L"/\\\0"
  233. L"\\/\0"
  234. L"x:\\\\a\\\\b\\c\\\\\0"
  235. L"x:\\\\a\\\\b\\c\\\0"
  236. L"x:\\\\a\\\\b\\c/\0"
  237. L"x:\\\\a\\\\b\\c//\0"
  238. L"x:\\\\a\\\\b\\c/\\\0"
  239. L"x:\\\\a\\\\b\\c\\/\0"
  240. L"x:\\\\a\\\\b\\c\0"
  241. L"x:\\\\a\\b\\c\\\\\0"
  242. L"x:\\\\a\\b\\c\\\0"
  243. L"x:\\\\a\\b\\c/\0"
  244. L"x:\\\\a\\b\\c//\0"
  245. L"x:\\\\a\\b\\c/\\\0"
  246. L"x:\\\\a\\b\\c\\/\0"
  247. L"x:\\\\a\\b\\c\0"
  248. L"x:\\\\a/b\\c\\\\\0"
  249. L"x:\\\\a/b\\c\\\0"
  250. L"x:\\\\a/b\\c/\0"
  251. L"x:\\\\a/b\\c//\0"
  252. L"x:\\\\a/b\\c/\\\0"
  253. L"x:\\\\a/b\\c\\/\0"
  254. L"x:\\\\a/b\\c\0"
  255. L"x:\\\\a//b\\c\\\\\0"
  256. L"x:\\\\a//b\\c\\\0"
  257. L"x:\\\\a//b\\c/\0"
  258. L"x:\\\\a//b\\c//\0"
  259. L"x:\\\\a//b\\c/\\\0"
  260. L"x:\\\\a//b\\c\\/\0"
  261. L"x:\\\\a//b\\c\0"
  262. L"x:\\\\a/\\b\\c\\\\\0"
  263. L"x:\\\\a/\\b\\c\\\0"
  264. L"x:\\\\a/\\b\\c/\0"
  265. L"x:\\\\a/\\b\\c//\0"
  266. L"x:\\\\a/\\b\\c/\\\0"
  267. L"x:\\\\a/\\b\\c\\/\0"
  268. L"x:\\\\a/\\b\\c\0"
  269. L"x:\\\\a\\/b\\c\\\\\0"
  270. L"x:\\\\a\\/b\\c\\\0"
  271. L"x:\\\\a\\/b\\c/\0"
  272. L"x:\\\\a\\/b\\c//\0"
  273. L"x:\\\\a\\/b\\c/\\\0"
  274. L"x:\\\\a\\/b\\c\\/\0"
  275. L"x:\\\\a\\/b\\c\0"
  276. L"x:\\\\a\\\\\0"
  277. L"x:\\\\a\\\0"
  278. L"x:\\\\a/\0"
  279. L"x:\\\\a//\0"
  280. L"x:\\\\a/\\\0"
  281. L"x:\\\\a\\/\0"
  282. L"x:\\\\a\0"
  283. L"x:\\a\\\\\0"
  284. L"x:\\a\\\0"
  285. L"x:\\a/\0"
  286. L"x:\\a//\0"
  287. L"x:\\a/\\\0"
  288. L"x:\\a\\/\0"
  289. L"x:\\a\0"
  290. L"x:/a\\\\\0"
  291. L"x:/a\\\0"
  292. L"x:/a/\0"
  293. L"x:/a//\0"
  294. L"x:/a/\\\0"
  295. L"x:/a\\/\0"
  296. L"x:/a\0"
  297. L"x:\\\0"
  298. L"x:/\0"
  299. L"x:\0"
  300. L"c\0"
  301. //////////////////////////////////////////////////////////////////////////
  302. L"a\\\\b\\c\\\\\0"
  303. L"a\\\\b\\c\\\0"
  304. L"a\\\\b\\c/\0"
  305. L"a\\\\b\\c//\0"
  306. L"a\\\\b\\c/\\\0"
  307. L"a\\\\b\\c\\/\0"
  308. L"a\\\\b\\c\0"
  309. L"a\\b\\c\\\\\0"
  310. L"a\\b\\c\\\0"
  311. L"a\\b\\c/\0"
  312. L"a\\b\\c//\0"
  313. L"a\\b\\c/\\\0"
  314. L"a\\b\\c\\/\0"
  315. L"a\\b\\c\0"
  316. L"a/b\\c\\\\\0"
  317. L"a/b\\c\\\0"
  318. L"a/b\\c/\0"
  319. L"a/b\\c//\0"
  320. L"a/b\\c/\\\0"
  321. L"a/b\\c\\/\0"
  322. L"a/b\\c\0"
  323. L"a//b\\c\\\\\0"
  324. L"a//b\\c\\\0"
  325. L"a//b\\c/\0"
  326. L"a//b\\c//\0"
  327. L"a//b\\c/\\\0"
  328. L"a//b\\c\\/\0"
  329. L"a//b\\c\0"
  330. L"a/\\b\\c\\\\\0"
  331. L"a/\\b\\c\\\0"
  332. L"a/\\b\\c/\0"
  333. L"a/\\b\\c//\0"
  334. L"a/\\b\\c/\\\0"
  335. L"a/\\b\\c\\/\0"
  336. L"a/\\b\\c\0"
  337. L"a\\/b\\c\\\\\0"
  338. L"a\\/b\\c\\\0"
  339. L"a\\/b\\c/\0"
  340. L"a\\/b\\c//\0"
  341. L"a\\/b\\c/\\\0"
  342. L"a\\/b\\c\\/\0"
  343. L"a\\/b\\c\0"
  344. L"x:a\\\\b\\c\\\\\0"
  345. L"x:a\\\\b\\c\\\0"
  346. L"x:a\\\\b\\c/\0"
  347. L"x:a\\\\b\\c//\0"
  348. L"x:a\\\\b\\c/\\\0"
  349. L"x:a\\\\b\\c\\/\0"
  350. L"x:a\\\\b\\c\0"
  351. L"x:a\\b\\c\\\\\0"
  352. L"x:a\\b\\c\\\0"
  353. L"x:a\\b\\c/\0"
  354. L"x:a\\b\\c//\0"
  355. L"x:a\\b\\c/\\\0"
  356. L"x:a\\b\\c\\/\0"
  357. L"x:a\\b\\c\0"
  358. L"x:a/b\\c\\\\\0"
  359. L"x:a/b\\c\\\0"
  360. L"x:a/b\\c/\0"
  361. L"x:a/b\\c//\0"
  362. L"x:a/b\\c/\\\0"
  363. L"x:a/b\\c\\/\0"
  364. L"x:a/b\\c\0"
  365. L"x:a//b\\c\\\\\0"
  366. L"x:a//b\\c\\\0"
  367. L"x:a//b\\c/\0"
  368. L"x:a//b\\c//\0"
  369. L"x:a//b\\c/\\\0"
  370. L"x:a//b\\c\\/\0"
  371. L"x:a//b\\c\0"
  372. L"x:a/\\b\\c\\\\\0"
  373. L"x:a/\\b\\c\\\0"
  374. L"x:a/\\b\\c/\0"
  375. L"x:a/\\b\\c//\0"
  376. L"x:a/\\b\\c/\\\0"
  377. L"x:a/\\b\\c\\/\0"
  378. L"x:a/\\b\\c\0"
  379. L"x:a\\/b\\c\\\\\0"
  380. L"x:a\\/b\\c\\\0"
  381. L"x:a\\/b\\c/\0"
  382. L"x:a\\/b\\c//\0"
  383. L"x:a\\/b\\c/\\\0"
  384. L"x:a\\/b\\c\\/\0"
  385. L"x:a\\/b\\c\0"
  386. L"x:a\\\\\0"
  387. L"x:a\\\0"
  388. L"x:a/\0"
  389. L"x:a//\0"
  390. L"x:a/\\\0"
  391. L"x:a\\/\0"
  392. L"x:a\0"
  393. L"x:a\\\\\0"
  394. L"x:a\\\0"
  395. L"x:a/\0"
  396. L"x:a//\0"
  397. L"x:a/\\\0"
  398. L"x:a\\/\0"
  399. L"x:a\0"
  400. L"x:a\\\\\0"
  401. L"x:a\\\0"
  402. L"x:a/\0"
  403. L"x:a//\0"
  404. L"x:a/\\\0"
  405. L"x:a\\/\0"
  406. L"x:a\0"
  407. L"\\a\\b\\c\\\\\0"
  408. L"\\a\\b\\c\\\0"
  409. L"\\a\\b\\c/\0"
  410. L"\\a\\b\\c//\0"
  411. L"\\a\\b\\c/\\\0"
  412. L"\\a\\b\\c\\/\0"
  413. L"\\a\\b\\c\0"
  414. L"\\a\0"
  415. L"\\a\\\0"
  416. L"\\a\\\0"
  417. L"\\a\\\0"
  418. L"\\a\\\0"
  419. L"\\a\\\0"
  420. L"\\a\\b\\c\0"
  421. L"\0\0"
  422. };
  423. if (InMain)
  424. return;
  425. InMain = TRUE;
  426. NtdllMain();
  427. Status = RtlInitUnicodeStringBuffer(&StringBuffer, Buffer, sizeof(Buffer));
  428. RTL_SOFT_ASSERT(NT_SUCCESS(Status));
  429. #if 1
  430. for ( (x = AppendPathElementTestData, y = x + wcslen(x) + 1) ;
  431. *x && *y ;
  432. (x = y + wcslen(y) + 1, y = x + wcslen(x) + 1)
  433. )
  434. {
  435. RtlInitUnicodeString(&String, x);
  436. RTL_SOFT_VERIFY(NT_SUCCESS(Status = RtlAssignUnicodeStringBuffer(&StringBuffer, &String)));
  437. RtlInitUnicodeString(&String, y);
  438. RTL_SOFT_VERIFY(NT_SUCCESS(Status = RtlAppendPathElement(0, &StringBuffer, &String)));
  439. printf("%ls + %ls = %ls\n", x, y, StringBuffer.String.Buffer);
  440. }
  441. #endif
  442. #if 1
  443. printf("\n\nDosPath<->NtPath conversion\n\n");
  444. for (x = RemoveLastPathElementTestData ; *x || *(x + 1) ; x += + wcslen(x) + 1)
  445. {
  446. UNICODE_STRING DosToNt = {0};
  447. RTL_UNICODE_STRING_BUFFER NtToDos = {0};
  448. BOOLEAN Success;
  449. RtlInitUnicodeStringBuffer(&NtToDos, 0, 0);
  450. //RtlInitUnicodeStringBuffer(&NtToDos, Buffer, sizeof(Buffer));
  451. RTL_SOFT_VERIFY(Success = RtlDosPathNameToNtPathName_U(x, &DosToNt, NULL, NULL));
  452. if (!Success)
  453. printf("%ls failed\n", x);
  454. else if (DosToNt.Length && DosToNt.Buffer)
  455. {
  456. printf("%ls -> %ls\n", x, DosToNt.Buffer);
  457. RTL_SOFT_VERIFY(NT_SUCCESS(Status = RtlAssignUnicodeStringBuffer(&NtToDos, &DosToNt)));
  458. RTL_SOFT_VERIFY(NT_SUCCESS(Status = RtlNtPathNameToDosPathName(0, &NtToDos, NULL, NULL)));
  459. if (Status != STATUS_SUCCESS)
  460. printf("%ls Status = 0x%08lx\n", x, Status);
  461. else if (NtToDos.String.Length && NtToDos.String.Buffer)
  462. printf("%ls -> %ls\n\n", DosToNt.Buffer, NtToDos.String.Buffer);
  463. }
  464. RtlFreeStringRoutine(DosToNt.Buffer);
  465. RtlFreeUnicodeStringBuffer(&NtToDos);
  466. }
  467. #endif
  468. return 0;
  469. }