X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org MIME-Version: 1.0 In-Reply-To: References: <416096c60905011226j27e942bcrf7661fb1693b5df1 AT mail DOT gmail DOT com> Date: Sat, 2 May 2009 06:47:27 +0100 Message-ID: <416096c60905012247i79dda0fna27b739a178cd29a@mail.gmail.com> Subject: Re: DOS programs under "screen" From: Andy Koppe To: cygwin AT cygwin DOT com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 2009/5/1 Barry Kelly: >> ReadConsoleOutput() on the hidden console only >> gives you the cooked output in terms of character cell contents and >> attributes, whereas the raw output as it came from the console app >> would need to be sent to the pty to be displayed by the likes of >> screen. As far as I can see, recreating the raw output from the cooked >> one isn't possible in general. > > You could intercept the calls to the console APIs by finding out where > the imports resolve to using GetProcAddress etc. (i.e. somewhere inside > where kernel32.dll is mapped to in the process), then adjusting the page > permissions (VirtualProtect etc.) and rewriting the entrypoint code > (save original 5 bytes of code, insert JMP , and at > save the parameters, update your stuff, execute the > missing code (the code you skipped - may need adjustment owing to > code-relative addressing modes in e.g. Jcc instructions), then JMP back. > > That's all assuming you have access to the innards of the process, most > likely with debugging APIs like CreateRemoteThread, DebugActiveProcess / > CreateProcess w/ debug, and WaitForDebugEvent / ContinueDebugEvent > debugging loop. > > Doing all this could be fun, but I reckon it would amount to a stack of > hacks. It also requires overbearing privileges. Thanks very much Barry, that's valuable info. I get the feeling this would best be attempted as a separate utility to be invoked as a wrapper around Win32 console programs. This would translate the console API calls into reads and writes on stdin and stdout. It could be used with all pty-based terminal emulators while keeping the hackery out of the Cygwin DLL. On the last point, do you really need special privileges to access the innards of your own processes? Assuming the hooking could be made to work, translating the low-level console I/O functions that reach directly into the console screen buffer would still be rather a big challenge. Perhaps the wrapper would need to be limited to high-level console I/O only. Oh, and ReadFile() and WriteFile() would need to be hooked too, to see whether they're accessing the console in question. I think I'll stick with difficulty rating "Insane" for this issue on the MinTTY issue tracker. Andy -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/