I'm working on a windows kernel driver that reports the command-line arguments of started processses. While getting the command-line string is easy, I'm having trouble interpreting it as separate arguments.
I'm using ProcessNotifyExCallback which gives me a PS_CREATE_NOTIFY_INFO for every started process. It contains a PCUNICODE_STRING CommandLine.
However, I'm unsure how this string is split into individual arguments by the windows kernel. Is there a kernel function that can do that for me? Is the splitting done by userland processes themself? Is there a way to query the (already split) arguments?
I'd like to get the arguments exactly the same was as the user-land process would in it's argc/argv parameters. So writing the "split" function myself is a no-go (doing the splitting/escaping is non-trivial).
Another interesting detail that I don't quite understand:
Assume I want to start the executable calc.exe with 2 arguments: a and b c (note the space).
When running the command in cmd.exe, I write calc.exe a "b c". However, inside the ProcessNotifyExCallback callback I receive the string calc.exe a "b c" - there are two spaces between the process name and the argument list. Why is that?
When starting the processes normally (no cmd.exe), there is only one space. So I assume the cmd is doing some magic there?