-
Notifications
You must be signed in to change notification settings - Fork 13
optimized #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
optimized #4
Changes from all commits
5dc44b3
1ef473c
2dc0ef0
ad6cfc3
bfd637a
dd7b18c
ca36ac7
972f915
f41976c
989778f
a96a80a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,11 +15,17 @@ ProcessReference::~ProcessReference() { | |
|
|
||
| } | ||
|
|
||
| NTSTATUS ProcessReference::init(size_t pid, bool attach) { | ||
| NTSTATUS ProcessReference::init(size_t pid, bool attach) | ||
| { | ||
| CHECK(PsLookupProcessByProcessId(reinterpret_cast<HANDLE>(pid), &m_process)); | ||
| m_attach = attach; | ||
| if (attach) { | ||
| m_apc_state = (KAPC_STATE*)ExAllocatePool(NonPagedPool, sizeof(KAPC_STATE)); | ||
| if (attach) | ||
| { | ||
| m_apc_state = (KAPC_STATE*)ExAllocatePool2(NonPagedPool, sizeof(KAPC_STATE), '2cba'); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ExAllocatePool2 and ExAllocatePoolZero are both functions that are supported from new versions of windows.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's OK in an older version. |
||
| if (NULL == m_apc_state) | ||
| m_apc_state = (KAPC_STATE*)ExAllocatePoolZero(NonPagedPool, sizeof(KAPC_STATE), '2cba'); | ||
| if (NULL == m_apc_state) | ||
| return STATUS_MEMORY_NOT_ALLOCATED; | ||
| KeStackAttachProcess(m_process, m_apc_state); | ||
| } | ||
| return STATUS_SUCCESS; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,21 +5,25 @@ extern "C" NTSTATUS NTAPI ZwQuerySystemInformation(IN size_t SystemInformationCl | |
| IN ULONG SystemInformationLength, | ||
| OUT PULONG ReturnLength OPTIONAL); | ||
|
|
||
| SYSTEM_HANDLE_INFORMATION* get_all_handles() { | ||
| SYSTEM_HANDLE_INFORMATION* get_all_handles() | ||
| { | ||
| size_t handles_allocation_size = 0; | ||
| PVOID handles_pool = nullptr; | ||
|
|
||
| while (true) { | ||
| for (;;) | ||
| { | ||
| handles_allocation_size += 0x10000; | ||
| handles_pool = ExAllocatePool(PagedPool, handles_allocation_size); | ||
| handles_pool = ExAllocatePool2(PagedPool, handles_allocation_size, '1cba'); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain please why this is necessary?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good question. Generally speaking, Microsoft Windows is updating its document all the time. Judging whether it succeeds in allocating pools is always required. Other changes could be ignored if using an old version wdk. According to the Microsoft document, ExAllocatePool is obsolete and has been deprecated in Windows 10, version 2004. It has been replaced by ExAllocatePool2. From then on, Microsoft always encourages developers to have a tag while allocating a pool. The following image prevents me to build it when regarding warnings as errors in kernel mode. After my testing, ExAllocatePool2 is not always successful, but ExAllocatePoolZero on my system could succeed. I have no good ideas on this point. Maybe it is better to judge which one to use first according to the system. The same as the ProcessReference.cpp.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool :)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ExAllocatePoolWithTag is also replaced by ExAllocatePool2.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ExAllocatePool2 and ExAllocatePoolZero are both functions that are supported from new versions of windows. |
||
| if (NULL == handles_pool) | ||
| handles_pool = ExAllocatePoolZero(PagedPool, handles_allocation_size, '1cba'); | ||
| if (NULL == handles_pool) | ||
| break; | ||
|
|
||
| auto status = ZwQuerySystemInformation(SystemHandleInformation, handles_pool, (ULONG)handles_allocation_size, nullptr); | ||
| if (status == STATUS_INFO_LENGTH_MISMATCH) { | ||
| if (status == STATUS_INFO_LENGTH_MISMATCH) | ||
| ExFreePool(handles_pool); | ||
| } | ||
| else { | ||
| else | ||
| break; | ||
| } | ||
| } | ||
| return (SYSTEM_HANDLE_INFORMATION*)handles_pool; | ||
| } | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain please why this is necessary?