Search the current process to see if any modules contain the address. @param Address - The address to search for. @param StackReturnInfo - The structure to be populated. */
| 12 | @param StackReturnInfo - The structure to be populated. |
| 13 | */ |
| 14 | VOID |
| 15 | StackWalker::ResolveAddressModule ( |
| 16 | _In_ PVOID Address, |
| 17 | _Inout_ PSTACK_RETURN_INFO StackReturnInfo |
| 18 | ) |
| 19 | { |
| 20 | NTSTATUS status; |
| 21 | MEMORY_BASIC_INFORMATION meminfo; |
| 22 | SIZE_T returnLength; |
| 23 | SIZE_T mappedFilenameLength; |
| 24 | PUNICODE_STRING mappedFilename; |
| 25 | |
| 26 | mappedFilenameLength = sizeof(UNICODE_STRING) + MAX_PATH * 2; |
| 27 | |
| 28 | // |
| 29 | // Query the virtual memory to see if it's part of an image. |
| 30 | // |
| 31 | status = ZwQueryVirtualMemory(NtCurrentProcess(), Address, MemoryBasicInformation, &meminfo, sizeof(meminfo), &returnLength); |
| 32 | if (NT_SUCCESS(status) && meminfo.Type == MEM_IMAGE) |
| 33 | { |
| 34 | StackReturnInfo->MemoryInModule = TRUE; |
| 35 | StackReturnInfo->BinaryOffset = RCAST<ULONG64>(Address) - RCAST<ULONG64>(meminfo.AllocationBase); |
| 36 | |
| 37 | // |
| 38 | // Allocate the filename. |
| 39 | // |
| 40 | mappedFilename = RCAST<PUNICODE_STRING>(ExAllocatePoolWithTag(PagedPool, mappedFilenameLength, STACK_WALK_MAPPED_NAME)); |
| 41 | if (mappedFilename == NULL) |
| 42 | { |
| 43 | DBGPRINT("StackWalker!ResolveAddressModule: Failed to allocate module name."); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | // |
| 48 | // Query the filename. |
| 49 | // |
| 50 | status = ZwQueryVirtualMemory(NtCurrentProcess(), Address, SCAST<MEMORY_INFORMATION_CLASS>(MemoryMappedFilenameInformation), mappedFilename, mappedFilenameLength, &mappedFilenameLength); |
| 51 | if (status == STATUS_BUFFER_OVERFLOW) |
| 52 | { |
| 53 | // |
| 54 | // If we don't have a large enough buffer, allocate one! |
| 55 | // |
| 56 | ExFreePoolWithTag(mappedFilename, STACK_WALK_MAPPED_NAME); |
| 57 | mappedFilename = RCAST<PUNICODE_STRING>(ExAllocatePoolWithTag(PagedPool, mappedFilenameLength, STACK_WALK_MAPPED_NAME)); |
| 58 | if (mappedFilename == NULL) |
| 59 | { |
| 60 | DBGPRINT("StackWalker!ResolveAddressModule: Failed to allocate module name."); |
| 61 | return; |
| 62 | } |
| 63 | status = ZwQueryVirtualMemory(NtCurrentProcess(), Address, SCAST<MEMORY_INFORMATION_CLASS>(MemoryMappedFilenameInformation), mappedFilename, mappedFilenameLength, &mappedFilenameLength); |
| 64 | } |
| 65 | |
| 66 | if (NT_SUCCESS(status) == FALSE) |
| 67 | { |
| 68 | DBGPRINT("StackWalker!ResolveAddressModule: Failed to query memory module name with status 0x%X.", status); |
| 69 | return; |
| 70 | } |
| 71 |
no outgoing calls
no test coverage detected