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.

133 lines
3.7 KiB

  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <memory.h>
  5. #include <nt.h>
  6. #include <ntrtl.h>
  7. #include <nturtl.h>
  8. #include <windows.h>
  9. #define DbgPrint printf
  10. #define NtTerminateProcess(a,b) ExitProcess((ULONG)(b))
  11. __cdecl
  12. main(
  13. )
  14. {
  15. LONG i, j;
  16. PULONG p4, p3, p2, p1, oldp1;
  17. SIZE_T Size1;
  18. NTSTATUS status;
  19. HANDLE CurrentProcessHandle;
  20. HANDLE GiantSection;
  21. MEMORY_BASIC_INFORMATION MemInfo;
  22. ULONG OldProtect;
  23. STRING Name3;
  24. HANDLE Section1;
  25. OBJECT_ATTRIBUTES ObjectAttributes;
  26. ULONG ViewSize;
  27. ULONG NumberOfAllocs = 0;
  28. TIME DelayTime = {-15 * 1000 * 1000 * 10, -1};
  29. OBJECT_ATTRIBUTES Object1Attributes;
  30. LARGE_INTEGER SectionSize;
  31. BOOL PrintedOnce = FALSE;
  32. CurrentProcessHandle = NtCurrentProcess();
  33. for(i = 0; i < 3; i += 1){
  34. DbgPrint("Hello World...\n\n");
  35. }
  36. DbgPrint("allocating virtual memory\n");
  37. for (;;) {
  38. p1 = NULL;
  39. Size1 = 800;
  40. status = NtAllocateVirtualMemory(CurrentProcessHandle,
  41. (PVOID *)&p1,
  42. 0,
  43. &Size1,
  44. MEM_RESERVE,
  45. PAGE_READWRITE);
  46. if (!NT_SUCCESS(status)) {
  47. break;
  48. }
  49. if ((PrintedOnce == FALSE) &&
  50. ((ULONG_PTR)p1 >= 0x80000000)) {
  51. printf("allocate high %p\n", p1);
  52. PrintedOnce = TRUE;
  53. }
  54. NumberOfAllocs += 1;
  55. }
  56. DbgPrint("allocVM failed after %ld allocs of 800 bytes\n", NumberOfAllocs);
  57. DbgPrint("created vm status %X start %p size %d\n",
  58. status,
  59. p1,
  60. Size1);
  61. for (i = 0; i < 4; i += 1) {
  62. p1 = NULL;
  63. Size1 = 800;
  64. status = NtAllocateVirtualMemory(CurrentProcessHandle,
  65. (PVOID *)&p1,
  66. 0,
  67. &Size1,
  68. MEM_RESERVE,
  69. PAGE_READWRITE);
  70. DbgPrint("created vm status %X start %p size %d\n",
  71. status,
  72. p1,
  73. Size1);
  74. }
  75. DbgPrint("delaying for 15 seconds\n");
  76. NtDelayExecution(FALSE, &DelayTime);
  77. DbgPrint ("end of delay\n");
  78. DbgPrint ("paged pool allocations\n");
  79. NumberOfAllocs = 0;
  80. for (;;) {
  81. //
  82. // Create a giant section (100mb)
  83. //
  84. InitializeObjectAttributes(&Object1Attributes,
  85. NULL,
  86. 0,
  87. NULL,
  88. NULL);
  89. SectionSize.QuadPart = (100 * 1024 * 1024);
  90. status = NtCreateSection(&GiantSection,
  91. SECTION_MAP_READ | SECTION_MAP_WRITE,
  92. &Object1Attributes,
  93. &SectionSize,
  94. PAGE_READWRITE,
  95. SEC_RESERVE,
  96. NULL);
  97. if (!NT_SUCCESS(status)) {
  98. break;
  99. }
  100. NumberOfAllocs += 1;
  101. }
  102. DbgPrint("Create section failed after %ld creates of 2GB\n", NumberOfAllocs);
  103. DbgPrint("create section status %X\n", status);
  104. DbgPrint("delaying for 15 seconds\n");
  105. NtDelayExecution(FALSE, &DelayTime);
  106. DbgPrint("end of delay\n");
  107. DbgPrint("that's all\n");
  108. NtTerminateProcess(NtCurrentProcess(), STATUS_SUCCESS);
  109. return 0;
  110. }