Writing and reading to and from another process.

How can i write to the stdin and read from the stdout of another process? Please explain and do please add
Code example.
Thanks.
closed account (13bSLyTq)
Hi,

These tend to be more or less difficult aspects of Windows API, involving manual mapping, disassembly and such.

The logic is the key here, normally when a console calls any std:: members, it will mostly result in some type of memory storage of these calls especially the stdin calls.

Therefore you may need to create some level of pattern signature in the process then you need to locate the variable which stores the data of the input, then once located a simple call to ReadProcessMemory or NtReadVirtualMemory would successfully return to you information. As for writing you may simply call WriteProcessMemory or NtWriteVirtualMemory. This would involve creating custom disassemblers and debuggers, which is too much work for these sort of petty programs.

As for Window based UI reading and writing, it is much more simpler as you may need to perform a simple code injection into the process then use SendMessageA to gain the text box values. I would highly recommend you should use Window based UI for these sort of things.


If the following applications are part of YOUR project and NOT 3rd Party, you can use IPCs to communicate with each other. This would be 100x more easier than the above steps suggests.
A simpler way might be just to use "GetStartupInfo()" to retrieve a STARTUPINFO struct which would contain that handles to hStdInput and hStdOutput. You can write to hStdInput using "WriteFile()" and read from hStdOutput using "ReadFile()".

- GetStartupInfo(): http://msdn.microsoft.com/en-us/library/windows/desktop/ms683230(v=vs.85).aspx

- ReadFile(): http://msdn.microsoft.com/en-us/library/windows/desktop/aa365467(v=vs.85).aspx

- WriteFile(): http://msdn.microsoft.com/en-us/library/windows/desktop/aa365747(v=vs.85).aspx

- STARTUPINFO: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v=vs.85).aspx

If the target application doesn't use std::cin or std::cout you may have to use Orion Master's route.
Big time thanks guys.
You have here some example code, no need for hooks and anything like that.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499%28v=vs.85%29.aspx

I know OrionMaster uses "hooks" for everything, I wonder why happens if every application that is running uses hooks ?
closed account (13bSLyTq)
Well, Clearly I never mentioned anything like that anyway you basically said what I said - IPC
Topic archived. No new replies allowed.