Are any of your "x failed" if branches hit? (lines 31, 34, 37, 41)?
If so, you should be able to use GetLastError() to see what the specific error code is.
One possible issue I see that according to MSDN, UNICODE_STRING.Length does not account for the null-terminator, and that
the strings returned by the various LSA functions might not be null-terminated. |
So it might be dangerous to assume that your cmd will be null-terminated.
When I run your program (and change the process id to be a valid process on my machine), the error code I get after line 36 is 299, which means
ERROR_PARTIAL_COPY
299 (0x12B)
Only part of a ReadProcessMemory or WriteProcessMemory request was completed. |
Some other things,
1. exit is a function, it should be called like a function e.g.
exit(1);
However, I do not suggest using exit, it's a very kludgy way to kill the process, and does 0 clean-up. Use
return 1;
instead (1 is some arbitrary non-zero code to mean "failure").
2. I needed to
#include <Ntdef.h>
to get your code to compile, so I suggest adding that in there to make your code more portable.
3. If you're printing a wide-char array, you should use std::wcout.