Re: DOS programs under screen

2009-05-01 Thread Andy Koppe
2009/4/21 Barry Kelly:
 Windows implements console mode as a client-server protocol between the
 executable (ntvdm.exe for DOS apps) and winsrv.dll (hosted in
 csrss.exe), but the protocol isn't easily hookable. I guess one would
 have to hijack the console APIs, perhaps by stepping into the
 application using debugging APIs and overwriting the DLL imports, but it
 would be pretty painful.

Hi Barry, have you got any pointers to documentation or reverse
engineering attempts for that console protocol?


2009/4/21 Christopher Faylor:
 It can be done using the same technique as Console2:

 http://console.sourceforge.net

I don't understand how. 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.

This article has more on this:
http://homepages.tesco.net/~J.deBoynePollard/FGA/capture-console-win32.html

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/



Re: DOS programs under screen

2009-05-01 Thread Christopher Faylor
On Fri, May 01, 2009 at 08:26:31PM +0100, Andy Koppe wrote:
2009/4/21 Barry Kelly:
 Windows implements console mode as a client-server protocol between the
 executable (ntvdm.exe for DOS apps) and winsrv.dll (hosted in
 csrss.exe), but the protocol isn't easily hookable. I guess one would
 have to hijack the console APIs, perhaps by stepping into the
 application using debugging APIs and overwriting the DLL imports, but it
 would be pretty painful.

Hi Barry, have you got any pointers to documentation or reverse
engineering attempts for that console protocol?

2009/4/21 Christopher Faylor:
It can be done using the same technique as Console2:

http://console.sourceforge.net

I don't understand how.  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.

If you can get the character cell contents and attributes and you can
push data into the consoles input buffer then, AFAIK, that's really all
you need to create a pty.  You can see that Console is doing something
like that because of the barely noticeable lag when you type things.
Obviously it's sending things back and forth between a hidden console
and displaying what it receives on the screen.

(You can also see it doing this in the source code if you are so inclined)

What would probably be problematic would be accommodating programs which
try to manipulate console attributes since a pty program would need to
maintain strict control of the hidden console.

cgf

--
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/



Re: DOS programs under screen

2009-05-01 Thread Barry Kelly
Andy Koppe wrote:

 2009/4/21 Barry Kelly:
  Windows implements console mode as a client-server protocol between the
  executable (ntvdm.exe for DOS apps) and winsrv.dll (hosted in
  csrss.exe), but the protocol isn't easily hookable. I guess one would
  have to hijack the console APIs, perhaps by stepping into the
  application using debugging APIs and overwriting the DLL imports, but it
  would be pretty painful.
 
 Hi Barry, have you got any pointers to documentation or reverse
 engineering attempts for that console protocol?

It is not just the console. It's a substantial fraction of the Win32
API. The NT kernel transfers the data (LPCs, local/lightweight procedure
calls) across a bit like a microkernel OS design; at least that's the
theory, in practice it's all pretty monolithic.

You can read a little bit more about it here:

http://en.wikipedia.org/wiki/Local_Procedure_Call

 2009/4/21 Christopher Faylor:
  It can be done using the same technique as Console2:
 
  http://console.sourceforge.net
 
 I don't understand how. 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 your-stub-here, and at
your-stub-here 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.

-- Barry

-- 
http://barrkel.blogspot.com/

--
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/



Re: DOS programs under screen

2009-05-01 Thread Andy Koppe
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 your-stub-here, and at
 your-stub-here 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/



Re: DOS programs under screen

2009-04-21 Thread Andrew Schulman
 I could
 imagine some kind of a DOS-to-Unix terminal wrapper program, but I've never 
 seen
 one and have no idea how it would work.
 
 ...and if one was possible why wouldn't the techniques that it incorporates be
 part of cygwin?

Laziness on your part?

hahahahahaha


--
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/



Re: DOS programs under screen

2009-04-21 Thread Christopher Faylor
On Tue, Apr 21, 2009 at 06:39:27AM -0400, Andrew Schulman wrote:
I could imagine some kind of a DOS-to-Unix terminal wrapper program,
but I've never seen one and have no idea how it would work.

...and if one was possible why wouldn't the techniques that it
incorporates be part of cygwin?

Laziness on your part?

hahahahahaha

You got me.

**cgf hangs head in shame and gets back to his bon bons.

--
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/



Re: DOS programs under screen

2009-04-21 Thread Andy Koppe
 Maybe someone knows a solution to this, but I don't.  Although I maintain 
 screen
 for Cygwin, I know almost nothing of the details of how terminals work.  I 
 could
 imagine some kind of a DOS-to-Unix terminal wrapper program, but I've never
 seen one and have no idea how it would work.

It probably can't be done as long as Microsoft doesn't provide a
pseudo-console interface that would allow a third-party program to
fully take over the role of a console window. In the meantime, the
best that can be done is the lipstick-on-a-pig approach taken by
http://sourceforge.net/projects/console/, which uses Win32 interfaces
for accessing a console's screen contents and paints its own version
of that.

Andy


ps: Actually, would it be possible to invoke a process with all the
Win32 console functions overwritten by custom ones? (That would of
course require an awful lot of work ...)

--
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/



Re: DOS programs under screen

2009-04-21 Thread Barry Kelly
Andrew Schulman wrote:

  In general, non-cygwin programs can't be run reliably inside of an
  application that uses cygwin PTYs, including xterm, rxvt, and screen.
 
 Maybe someone knows a solution to this, but I don't.  Although I maintain 
 screen
 for Cygwin, I know almost nothing of the details of how terminals work.  I 
 could
 imagine some kind of a DOS-to-Unix terminal wrapper program, but I've never 
 seen
 one and have no idea how it would work.

Windows implements console mode as a client-server protocol between the
executable (ntvdm.exe for DOS apps) and winsrv.dll (hosted in
csrss.exe), but the protocol isn't easily hookable. I guess one would
have to hijack the console APIs, perhaps by stepping into the
application using debugging APIs and overwriting the DLL imports, but it
would be pretty painful.

I don't know how DOS programs that use graphics modes (in fullscreen)
are implemented, though these must be rare now given that Vista no
longer has a full-screen mode.

-- Barry

-- 
http://barrkel.blogspot.com/

--
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/



Re: DOS programs under screen

2009-04-21 Thread Christopher Faylor
On Tue, Apr 21, 2009 at 06:46:05PM +0100, Andy Koppe wrote:
Andrew Schulman wrote:
Maybe someone knows a solution to this, but I don't.  ?Although I
maintain screen for Cygwin, I know almost nothing of the details of how
terminals work.  ?I could imagine some kind of a DOS-to-Unix terminal
wrapper program, but I've never seen one and have no idea how it would
work.

It probably can't be done as long as Microsoft doesn't provide a
pseudo-console interface that would allow a third-party program to
fully take over the role of a console window.  In the meantime, the
best that can be done is the lipstick-on-a-pig approach taken by
http://sourceforge.net/projects/console/, which uses Win32 interfaces
for accessing a console's screen contents and paints its own version of
that.

It can be done using the same technique as Console2:

http://console.sourceforge.net

So there is some justification in invoking the too lazy clause.  I've
started down the path of implementing ptys using console functions a
couple of times and have always turned back due to the amount of work it
would end up taking.

cgf

--
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/



Re: DOS programs under screen

2009-04-20 Thread Andrew Schulman
James Calfee jcal...@xxx.xxx wrote on 04/20/2009 02:02:33 PM:

 Hi Andrew.  I have change request for screen.exe under cygwin.  I did
 not get any response from the cygwin mailing list.   I guess the request
 is a bit too specific.  Do you know where I might direct the request?
 
 In case your wondering, we are running a server program that has a DOS
 interface.  It does not work under screen.  This program is very similar
 to the DOS edit program which also does NOT work under screen.  So, my
 question would be, what is required to fix screen so it will work with
 the DOS edit program?
 
 Thanks for your help,
 Jimmy

Jimmy, I saw the thread on the cygwin list.  I didn't answer there because I
didn't have anything to add.  In fact, you did get a response there from Matt
Wozniski, who I thought covered it as well as I could:

 In general, non-cygwin programs can't be run reliably inside of an
 application that uses cygwin PTYs, including xterm, rxvt, and screen.

Maybe someone knows a solution to this, but I don't.  Although I maintain screen
for Cygwin, I know almost nothing of the details of how terminals work.  I could
imagine some kind of a DOS-to-Unix terminal wrapper program, but I've never seen
one and have no idea how it would work.

Please note that http://cygwin.com/problems.html asks you not to send problem
reports to maintainers' personal email addresses.  Such reports should go to the
Cygwin list, so that everyone can contribute to and benefit from the discussion.
If you want to call someone's attention to a thread, you can append e.g. [ping
Andrew Schulman] to the subject.  But at least in my case, it's not necessary:
I have my news client set to automatically flag anything that has screen in
the subject.

Sorry I couldn't help.  Good luck,
Andrew.


--
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/



Re: DOS programs under screen

2009-04-20 Thread Christopher Faylor
On Mon, Apr 20, 2009 at 03:56:16PM -0400, Andrew Schulman wrote:
James Calfee jcal...@xxx.xxx wrote on 04/20/2009 02:02:33 PM:

 Hi Andrew.  I have change request for screen.exe under cygwin.  I did
 not get any response from the cygwin mailing list.   I guess the request
 is a bit too specific.  Do you know where I might direct the request?
 
 In case your wondering, we are running a server program that has a DOS
 interface.  It does not work under screen.  This program is very similar
 to the DOS edit program which also does NOT work under screen.  So, my
 question would be, what is required to fix screen so it will work with
 the DOS edit program?
 
 Thanks for your help,
 Jimmy

Jimmy, I saw the thread on the cygwin list.  I didn't answer there because I
didn't have anything to add.  In fact, you did get a response there from Matt
Wozniski, who I thought covered it as well as I could:

 In general, non-cygwin programs can't be run reliably inside of an
 application that uses cygwin PTYs, including xterm, rxvt, and screen.

Maybe someone knows a solution to this, but I don't.  Although I maintain 
screen
for Cygwin, I know almost nothing of the details of how terminals work.  I 
could
imagine some kind of a DOS-to-Unix terminal wrapper program, but I've never 
seen
one and have no idea how it would work.

...and if one was possible why wouldn't the techniques that it incorporates be
part of cygwin?

cgf

--
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/



Re: DOS programs under screen

2009-04-08 Thread William Sutton
I suppose you could always use the 'clear' command instead of cls.  If you 
need cls specifically, you can alias it to clear.


From the edit point of view, is this something you could accomplish with 

another command-line editor (say vim)?

William Sutton

On Wed, 8 Apr 2009, James Calfee wrote:


We need to run a DOS program as a service.  The program provides
valuable information in the DOS window in an interactive ASCII color
interface but does not provide any method to connect to this interface
if started as a service.

One solution is to run this program under screen.  Unfortunately, this
will not work until I can get these things resolved:

* DOS cls command does not work under screen
* DOS edit program does not work under screen

Does anyone know how to get these things working under Cygwin's screen?

Steps to produce:

Open a DOS window (start, run, cmd) or open Cygwin
Run something like this c:\cygwin\bin\screen cmd
Or just screen cmd
... Dos text and a prompt should come up ..
Type cls

The command is echoed back but the console does not clear.

Running 'edit' does basically the same thing too.  Instead of seeing
edit's blue interface, the command is echoed and the console hangs.
Pressing Ctrl+C will terminate screen's session.

These test do not use ANSI.sys (see absence of this device in
/cygdrive/c/CONFIG.SYS).. The 'edit' program works just fine without it.
Maybe screen can manage without it too.

Any help is appreciated.

Thanks,
jc

Disclaimer: This message (including attachments) is confidential and may be 
privileged. If you have received it by mistake please notify the sender by 
return e-mail and delete this message from your system. Any unauthorized use or 
dissemination of this message in whole or in part is strictly prohibited. 
Please note that e-mails are susceptible to change. RxStrategies, Inc. shall 
not be liable for the improper or incomplete transmission of the information 
contained in this communication or for any delay in its receipt or damage to 
your system. RxStrategies, Inc. does not guarantee that the integrity of this 
communication has been maintained nor that this communication is free from 
viruses, interceptions or interference.



--
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/




--
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/



RE: DOS programs under screen

2009-04-08 Thread James Calfee
Your right, clear does work.  That example is too simple though.
edit is similar to the server.  I'm testing with a copy of the server
now.  It behaves just as edit does, I see my command echoed back to me
but nothing else.  The session is hung and I can not see the interface. 

I don't actually need edit to work.  I'm just trying to provide a
program that can be used to test the DOS graphical interface under
screen.  edit re-sizes the DOS window.   The server does not do this.
You may know of another DOS interface that could be used to test this.

-Original Message-
From: William Sutton [mailto:will...@trilug.org] 
Sent: Wednesday, April 08, 2009 2:29 PM
To: James Calfee
Cc: cygwin@cygwin.com; InformationTechnology
Subject: Re: DOS programs under screen

I suppose you could always use the 'clear' command instead of cls.  If
you 
need cls specifically, you can alias it to clear.

From the edit point of view, is this something you could accomplish with

another command-line editor (say vim)?

William Sutton

On Wed, 8 Apr 2009, James Calfee wrote:

 We need to run a DOS program as a service.  The program provides
 valuable information in the DOS window in an interactive ASCII color
 interface but does not provide any method to connect to this interface
 if started as a service.

 One solution is to run this program under screen.  Unfortunately, this
 will not work until I can get these things resolved:

 * DOS cls command does not work under screen
 * DOS edit program does not work under screen

 Does anyone know how to get these things working under Cygwin's
screen?

 Steps to produce:

 Open a DOS window (start, run, cmd) or open Cygwin
 Run something like this c:\cygwin\bin\screen cmd
 Or just screen cmd
 ... Dos text and a prompt should come up ..
 Type cls

 The command is echoed back but the console does not clear.

 Running 'edit' does basically the same thing too.  Instead of seeing
 edit's blue interface, the command is echoed and the console hangs.
 Pressing Ctrl+C will terminate screen's session.

 These test do not use ANSI.sys (see absence of this device in
 /cygdrive/c/CONFIG.SYS).. The 'edit' program works just fine without
it.
 Maybe screen can manage without it too.

 Any help is appreciated.

 Thanks,
 jc


Disclaimer: This message (including attachments) is confidential and may be 
privileged. If you have received it by mistake please notify the sender by 
return e-mail and delete this message from your system. Any unauthorized use or 
dissemination of this message in whole or in part is strictly prohibited. 
Please note that e-mails are susceptible to change. RxStrategies, Inc. shall 
not be liable for the improper or incomplete transmission of the information 
contained in this communication or for any delay in its receipt or damage to 
your system. RxStrategies, Inc. does not guarantee that the integrity of this 
communication has been maintained nor that this communication is free from 
viruses, interceptions or interference. 



--
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/



Re: DOS programs under screen

2009-04-08 Thread Matt Wozniski
On Wed, Apr 8, 2009 at 5:11 PM, James Calfee jcal...@accessrxs.com wrote:
 Your right, clear does work.  That example is too simple though.
 edit is similar to the server.  I'm testing with a copy of the server
 now.  It behaves just as edit does, I see my command echoed back to me
 but nothing else.  The session is hung and I can not see the interface.

 I don't actually need edit to work.  I'm just trying to provide a
 program that can be used to test the DOS graphical interface under
 screen.  edit re-sizes the DOS window.   The server does not do this.
 You may know of another DOS interface that could be used to test this.

In general, non-cygwin programs can't be run reliably inside of an
application that uses cygwin PTYs, including xterm, rxvt, and screen.


Don't quote these headers.  We already know them.

 -Original Message-
 From: William Sutton [mailto:x...@xxx.xxx]

http://www.cygwin.com/acronyms/#PCYMTNQREAIYR

 Sent: Wednesday, April 08, 2009 2:29 PM
 To: James Calfee
 Cc: x...@xxx.xxx; InformationTechnology
 Subject: Re: DOS programs under screen

[ snip http://www.cygwin.com/acronyms/#TOFU ]

 Disclaimer: This message (including attachments) is confidential and may be 
 privileged...

And don't do this.  Such disclaimers are against unenforcible when
sent to a public mailing list, and you will likely be banned from the
mailing list if you continue posting them.  If you need to, send
emails from a private address so this doesn't happen.

~Matt

--
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/