Changeset 43417 in vbox
- Timestamp:
- Sep 24, 2012 1:46:57 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/testcase/tstNtQueryStuff.cpp
r43386 r43417 29 29 * Header Files * 30 30 *******************************************************************************/ 31 #include <ntstatus.h> 32 #define WIN32_NO_STATUS 31 33 #include <Windows.h> 32 34 #include <winternl.h> … … 54 56 OUT PSIZE_T pcbReturned OPTIONAL); 55 57 58 #define ProcessDebugPort ((PROCESSINFOCLASS)7 ) 59 #define ProcessHandleCount ((PROCESSINFOCLASS)20) 60 #define ProcessWow64Information ((PROCESSINFOCLASS)26) 61 #define ProcessImageFileName ((PROCESSINFOCLASS)27) 62 #define ProcessDebugObjectHandle ((PROCESSINFOCLASS)30) 63 #define ProcessExecuteFlags ((PROCESSINFOCLASS)34) 64 #define ProcessImageFileNameWin32 ((PROCESSINFOCLASS)43) 65 #define ProcessImageFileMapping ((PROCESSINFOCLASS)44) 66 56 67 57 68 #include <iprt/test.h> … … 75 86 *******************************************************************************/ 76 87 static RTTEST g_hTest = NIL_RTTEST; 88 static HANDLE g_hProcess = NULL; 77 89 78 90 … … 188 200 RTTestISub("NtQueryVirtualMemory"); 189 201 190 191 202 uintptr_t cbAdvance = 0; 192 203 uintptr_t uPtrWhere = 0; … … 195 206 SIZE_T cbActual = 0; 196 207 MEMORY_BASIC_INFORMATION MemInfo = { 0, 0, 0, 0, 0, 0, 0 }; 197 NTSTATUS ntRc = NtQueryVirtualMemory(GetCurrentProcess(),208 NTSTATUS rcNt = NtQueryVirtualMemory(g_hProcess, 198 209 (void const *)uPtrWhere, 199 210 MemoryBasicInformation, … … 201 212 sizeof(MemInfo), 202 213 &cbActual); 203 if (!NT_SUCCESS( ntRc))204 { 205 RTTestIPrintf(RTTESTLVL_ALWAYS, "%p: ntRc=%#x\n", uPtrWhere, ntRc);214 if (!NT_SUCCESS(rcNt)) 215 { 216 RTTestIPrintf(RTTESTLVL_ALWAYS, "%p: rcNt=%#x\n", uPtrWhere, rcNt); 206 217 break; 207 218 } … … 211 222 char szMemState[1024]; 212 223 char szMemProt[1024]; 213 214 RTTestIPrintf(RTTESTLVL_ALWAYS, "%p-%p %-8s %-8s %-12s\n", 224 char szAllocProt[1024]; 225 226 if ( MemInfo.AllocationBase != NULL 227 && MemInfo.AllocationBase == MemInfo.BaseAddress 228 && MemInfo.Protect != MemInfo.AllocationProtect) 229 RTTestIPrintf(RTTESTLVL_ALWAYS, "\n"); 230 231 RTTestIPrintf(RTTESTLVL_ALWAYS, "%p-%p %-8s %-8s %-12s", 215 232 MemInfo.BaseAddress, (uintptr_t)MemInfo.BaseAddress + MemInfo.RegionSize - 1, 216 233 stringifyMemType(MemInfo.Type, szMemType, sizeof(szMemType)), … … 218 235 stringifyMemProt(MemInfo.Protect, szMemProt, sizeof(szMemProt)) 219 236 ); 237 if ((uintptr_t)MemInfo.AllocationBase != 0) 238 { 239 if (MemInfo.AllocationBase != MemInfo.BaseAddress) 240 RTTestIPrintf(RTTESTLVL_ALWAYS, " %p", MemInfo.AllocationBase); 241 else 242 RTTestIPrintf(RTTESTLVL_ALWAYS, " %s", stringifyMemProt(MemInfo.AllocationProtect, szAllocProt, sizeof(szAllocProt))); 243 } 244 RTTestIPrintf(RTTESTLVL_ALWAYS, "\n"); 220 245 221 246 if ((uintptr_t)MemInfo.BaseAddress != uPtrWhere) … … 223 248 uPtrWhere, MemInfo.BaseAddress); 224 249 250 /* Image or mapped, then try get a file name. */ 251 if (MemInfo.Type == MEM_IMAGE || MemInfo.Type == MEM_MAPPED) 252 { 253 union 254 { 255 MEMORY_SECTION_NAME Core; 256 WCHAR awcPadding[UNICODE_STRING_MAX_CHARS + (sizeof(UNICODE_STRING_MAX_CHARS) + 1) / sizeof(WCHAR)]; 257 } uBuf; 258 RT_ZERO(uBuf); 259 uBuf.Core.SectionFileName.Length = UNICODE_STRING_MAX_CHARS * 2; 260 uBuf.Core.SectionFileName.MaximumLength = UNICODE_STRING_MAX_CHARS * 2; 261 uBuf.Core.SectionFileName.Buffer = &uBuf.Core.NameBuffer[0]; 262 263 cbActual = 0; 264 rcNt = NtQueryVirtualMemory(g_hProcess, 265 (void const *)uPtrWhere, 266 MemorySectionName, 267 &uBuf, 268 sizeof(uBuf), 269 &cbActual); 270 if (NT_SUCCESS(rcNt)) 271 RTTestIPrintf(RTTESTLVL_ALWAYS, " %.*ls\n", 272 uBuf.Core.SectionFileName.Length / 2, uBuf.Core.SectionFileName.Buffer); 273 else 274 { 275 RTTestIPrintf(RTTESTLVL_ALWAYS, "%p: MemorySectionName - rcNt=%#x\n", uPtrWhere, rcNt); 276 RTTESTI_CHECK(rcNt == STATUS_FILE_INVALID && MemInfo.Type == MEM_MAPPED); 277 } 278 } 279 280 /* Advance. */ 225 281 cbAdvance = MemInfo.RegionSize; 226 282 //cbAdvance = 0; … … 232 288 233 289 234 235 //NtQueryInformationProcess 290 static void tstQueryInformationProcess(void) 291 { 292 RTTestISub("NtQueryInformationProcess"); 293 294 NTSTATUS rcNt; 295 296 /* Basic info */ 297 PROCESS_BASIC_INFORMATION BasicInfo; 298 RT_ZERO(BasicInfo); 299 DWORD cbActual = 0; 300 rcNt = NtQueryInformationProcess(g_hProcess, 301 ProcessBasicInformation, 302 &BasicInfo, sizeof(BasicInfo), &cbActual); 303 RTTESTI_CHECK_MSG(NT_SUCCESS(rcNt), ("rcNt=%#x\n", rcNt)); 304 if (NT_SUCCESS(rcNt)) 305 RTTestIPrintf(RTTESTLVL_ALWAYS, "BasicInfo:\n" 306 " UniqueProcessId = %#x (%6d)\n" 307 " PebBaseAddress = %p\n" 308 " Reserved1 = %p ExitStatus?\n" 309 " Reserved2a = %p AffinityMask?\n" 310 " Reserved2b = %p (%6d) BasePriority?\n" 311 " Reserved3 = %p (%6d) InheritedFromUniqueProcessId?\n" 312 , 313 BasicInfo.UniqueProcessId, BasicInfo.UniqueProcessId, 314 BasicInfo.PebBaseAddress, 315 BasicInfo.Reserved1, 316 BasicInfo.Reserved2[0], 317 BasicInfo.Reserved2[1], BasicInfo.Reserved2[1], 318 BasicInfo.Reserved3, BasicInfo.Reserved3 319 ); 320 321 322 /* Debugger present? */ 323 DWORD_PTR uPtr = ~(DWORD_PTR)0; 324 cbActual = 0; 325 rcNt = NtQueryInformationProcess(g_hProcess, 326 ProcessDebugPort, 327 &uPtr, sizeof(uPtr), &cbActual); 328 RTTESTI_CHECK_MSG(NT_SUCCESS(rcNt), ("rcNt=%#x\n", rcNt)); 329 if (NT_SUCCESS(rcNt)) 330 RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessDebugPort: %p\n", uPtr); 331 332 /* Debug object handle, whatever that is... */ 333 uPtr = ~(DWORD_PTR)0; 334 cbActual = 0; 335 rcNt = NtQueryInformationProcess(g_hProcess, 336 ProcessDebugObjectHandle, 337 &uPtr, sizeof(uPtr), &cbActual); 338 if (NT_SUCCESS(rcNt)) 339 RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessDebugObjectHandle: %p\n", uPtr); 340 else if (rcNt == STATUS_PORT_NOT_SET) 341 RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessDebugObjectHandle: rcNt=%#x (STATUS_PORT_NOT_SET)\n", uPtr); 342 else 343 RTTESTI_CHECK_MSG(NT_SUCCESS(rcNt), ("rcNt=%#x\n", rcNt)); 344 345 /* 32-bit app on 64-bit host? */ 346 uPtr = ~(DWORD_PTR)0; 347 cbActual = 0; 348 rcNt = NtQueryInformationProcess(g_hProcess, 349 ProcessWow64Information, 350 &uPtr, sizeof(uPtr), &cbActual); 351 RTTESTI_CHECK_MSG(NT_SUCCESS(rcNt), ("rcNt=%#x\n", rcNt)); 352 if (NT_SUCCESS(rcNt)) 353 RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessWow64Information: %p\n", uPtr); 354 355 /* Process image name (NT). */ 356 struct 357 { 358 UNICODE_STRING UniStr; 359 WCHAR awBuffer[UNICODE_STRING_MAX_CHARS]; 360 } StrBuf; 361 RT_ZERO(StrBuf); 362 StrBuf.UniStr.Length = UNICODE_STRING_MAX_CHARS * 2; 363 StrBuf.UniStr.MaximumLength = UNICODE_STRING_MAX_CHARS * 2; 364 StrBuf.UniStr.Buffer = &StrBuf.awBuffer[0]; 365 cbActual = 0; 366 rcNt = NtQueryInformationProcess(g_hProcess, 367 ProcessImageFileName, 368 &StrBuf, sizeof(StrBuf), &cbActual); 369 RTTESTI_CHECK_MSG(NT_SUCCESS(rcNt), ("rcNt=%#x\n", rcNt)); 370 if (NT_SUCCESS(rcNt)) 371 RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessImageFileName: len=%u\n %.*ls\n", 372 StrBuf.UniStr.Length, StrBuf.UniStr.Length, StrBuf.UniStr.Buffer); 373 374 /* Process image name (Win32). */ 375 RT_ZERO(StrBuf); 376 StrBuf.UniStr.Length = UNICODE_STRING_MAX_CHARS * 2; 377 StrBuf.UniStr.MaximumLength = UNICODE_STRING_MAX_CHARS * 2; 378 StrBuf.UniStr.Buffer = &StrBuf.awBuffer[0]; 379 cbActual = 0; 380 rcNt = NtQueryInformationProcess(g_hProcess, 381 ProcessImageFileNameWin32, 382 &StrBuf, sizeof(StrBuf), &cbActual); 383 RTTESTI_CHECK_MSG(NT_SUCCESS(rcNt), ("rcNt=%#x\n", rcNt)); 384 if (NT_SUCCESS(rcNt)) 385 RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessImageFileNameWin32: len=%u\n %.*ls\n", 386 StrBuf.UniStr.Length, StrBuf.UniStr.Length, StrBuf.UniStr.Buffer); 387 388 /* Process image mapping. */ 389 uPtr = ~(DWORD_PTR)0; 390 cbActual = 0; 391 rcNt = NtQueryInformationProcess(g_hProcess, 392 ProcessImageFileMapping, 393 &uPtr, sizeof(uPtr), &cbActual); 394 if (NT_SUCCESS(rcNt)) 395 RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessImageFileMapping: %p\n", uPtr); 396 else if (rcNt == STATUS_OBJECT_TYPE_MISMATCH) 397 RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessImageFileMapping: rcNt=%#x (STATUS_OBJECT_TYPE_MISMATCH)\n", rcNt); 398 else 399 RTTestIFailed("ProcessImageFileMapping: rcNt=%#x\n", rcNt); 400 401 402 /* Handles. Broken for 64-bit input. */ 403 uint32_t u32 = UINT32_MAX; 404 cbActual = 0; 405 rcNt = NtQueryInformationProcess(g_hProcess, 406 ProcessHandleCount, 407 &u32, sizeof(u32), &cbActual); 408 if (NT_SUCCESS(rcNt)) 409 RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessHandleCount: %#x (%d)\n", u32, u32); 410 else 411 RTTestIFailed("ProcessHandleCount: rcNt=%#x\n", rcNt); 412 413 /* Execute flags. */ 414 #if 0 /* fails... wrong process handle? */ 415 u32 = ~(DWORD_PTR)0; 416 cbActual = 0; 417 rcNt = NtQueryInformationProcess(g_hProcess, 418 ProcessExecuteFlags, 419 &u32, sizeof(u32), &cbActual); 420 if (NT_SUCCESS(rcNt)) 421 RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessExecuteFlags: %#p\n", u32); 422 else 423 RTTestIFailed("ProcessExecuteFlags: rcNt=%#x\n", rcNt); 424 #endif 425 426 /** @todo ProcessImageInformation */ 427 } 428 236 429 237 430 int main() … … 242 435 RTTestBanner(g_hTest); 243 436 244 tstQueryVirtualMemory(); 437 g_hProcess = GetCurrentProcess(); 438 439 //tstQueryVirtualMemory(); 440 tstQueryInformationProcess(); 245 441 246 442
Note:
See TracChangeset
for help on using the changeset viewer.