-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1398 / win / cmdline: call NtQueryInformationProcess twice, the firs…
…t time to get the right buf size (ProcessHacker does this)
- Loading branch information
Showing
1 changed file
with
22 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59e3c5e
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.
hmm, I think you have to choose :
either you call
NtQueryInformationProcess
twice like this, but you have to allocate the necessary memory between the 2 calls using the size inret_length
or you keep the simple first version which had a 4096 bytes buffer and call
NtQueryInformationProcess
once and hope 4096 is enoughAs is, you have a 4096 bytes buffer (enough for 2048 bytes minus a few of command line, might not be enough for edge cases), ask for the correct length, but don't do anything with the information (
cmdline_buffer
is already allocated at the beginning)The first choice is, IMHO, the best one.
The version I provided was indeed crude and should have requested the correct length
59e3c5e
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.
You are right. I misread ProcessHacker code which indeed it allocates memory:
https://github.com/processhacker/processhacker/blob/master/phlib/native.c#L495
It uses RtlAllocateHeap though, which is kinda painful to implement. Unless you have other ideas to proper allocate memory I'd rather go back to your original implementation using a fixed size.
59e3c5e
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.
it's a really tiny fix actually (move the
calloc
after the firstNtQueryInformationProcess
call, setret_length
initially to 0 to be sure):59e3c5e
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.
Done in #1446. Thanks @EccoTheFlintstone.