🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #13962

How to spy on a console's screen buffer?

#13962
From: Sean McCune
Date: Sun, 31 Aug 2003 19:08
56 lines
2634 bytes
Hi folks,

I'm trying to write an application that accesses the screen buffers of
console apps to read what is currently visible in the console app's window.
The pseudo-code is below.  I know it doesn't have error checking.  The real
code does.  I ripped out all of the extraneous stuff.

At any rate, the code below works when run in the debugger.

   hwnd = FindWindow( className, title );
   GetWindowThreadProcessId( hwnd, &pid );
   AttachConsole( pid );
   out = GetStdHandle( STD_OUTPUT_HANDLE );
   result = ReadConsoleOutputCharacter( out, internalBuf, length, c,
nRead );

When run in the debugger, the buffer internalBuf gets filled with the text
from the console app's window.  When run outside the debugger, result is
always false and the error is ERROR_INVALID_HANDLE.  I figured it was a
security issue on the handle so I wrote a console app that I "think"
should've allowed access to the handle by everybody.  But I'm a newbie at
messing with the security API on windows.  The code I used to do this in my
console app is below.  But it didn't work.  Does anybody have any ideas?
Thanks in advance!

   HANDLE out;
   PACL pDacl;
   PSECURITY_DESCRIPTOR sd;

   out = GetStdHandle( STD_OUTPUT_HANDLE );

   GetSecurityInfo(
      out,
      SE_KERNEL_OBJECT,
      DACL_SECURITY_INFORMATION,
      NULL,
      NULL,
      &pDacl,
      NULL,
      &sd
   );

   SetSecurityInfo(
      out,
      SE_KERNEL_OBJECT,
      DACL_SECURITY_INFORMATION,
      NULL,
      NULL,
      NULL,
      NULL
   );


Thanks in advance!
Sean McCune
sean@redhandsoftware.com
Technical Details
Message-ID: <3f5247ae@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!news.osn.de!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,e59457b0353e4c0f,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-31 12:09:35 PST
From: "Sean McCune" <sean@redhandsoftware.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: How to spy on a console's screen buffer?
Date: Sun, 31 Aug 2003 15:08:15 -0400
Lines: 58
Organization: Red Hand Software, Inc.
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 65.199.19.189
Message-ID: <3f5247ae@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1062356910 65.199.19.189 (31 Aug 2003 12:08:30 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!news.osn.de!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail