Skip to content
Snippets Groups Projects
Commit c62a5a01 authored by rswindell's avatar rswindell
Browse files

Now strips ANSI, handle clear screens, carriage-returns, and bell chars.

parent f716d4d1
Branches
Tags
No related merge requests found
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#pragma hdrstop #pragma hdrstop
#include "SpyFormUnit.h" #include "SpyFormUnit.h"
#include "sbbsdefs.h"
#define SPYBUF_LEN 10000
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#pragma package(smart_init) #pragma package(smart_init)
#pragma resource "*.dfm" #pragma resource "*.dfm"
...@@ -13,6 +16,60 @@ __fastcall TSpyForm::TSpyForm(TComponent* Owner) ...@@ -13,6 +16,60 @@ __fastcall TSpyForm::TSpyForm(TComponent* Owner)
: TForm(Owner) : TForm(Owner)
{ {
} }
bool strip_ansi(char* str)
{
char* p=str;
char newstr[SPYBUF_LEN];
int newlen=0;
bool ff=false;
for(p=str;*p && newlen<(sizeof(newstr)-1);) {
switch(*p) {
case BEL: /* bell */
Beep();
break;
case BS: /* backspace */
if(newlen)
newlen--;
break;
case FF: /* form feed */
newlen=0;
ff=true;
break;
case ESC:
if(*(p+1)=='[') { /* ANSI */
p+=2;
if(!strncmp(p,"2J",2)) {
newlen=0;
ff=true;
}
while(*p && !isalpha(*p)) p++;
}
break;
case CR:
if(*(p+1)!=LF) {
while(newlen) {
newlen--;
if(newstr[newlen]==LF) {
newlen++;
break;
}
}
break;
} /* Fall through */
default:
newstr[newlen++]=*p;
break;
}
if(*p==0)
break;
p++;
}
newstr[newlen]=0;
strcpy(str,newstr);
return(ff);
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void __fastcall TSpyForm::SpyTimerTick(TObject *Sender) void __fastcall TSpyForm::SpyTimerTick(TObject *Sender)
{ {
...@@ -25,6 +82,10 @@ void __fastcall TSpyForm::SpyTimerTick(TObject *Sender) ...@@ -25,6 +82,10 @@ void __fastcall TSpyForm::SpyTimerTick(TObject *Sender)
rd=RingBufRead(*spybuf,buf,sizeof(buf)-1); rd=RingBufRead(*spybuf,buf,sizeof(buf)-1);
if(rd) { if(rd) {
buf[rd]=0; buf[rd]=0;
if(strip_ansi(buf))
Log->Lines->Clear();
Log->SelLength=0;
Log->SelStart=Log->Lines->Text.Length();
Log->SelText=AnsiString(buf); Log->SelText=AnsiString(buf);
Timer->Interval=100; Timer->Interval=100;
} else } else
...@@ -47,8 +108,7 @@ void __fastcall TSpyForm::FormShow(TObject *Sender) ...@@ -47,8 +108,7 @@ void __fastcall TSpyForm::FormShow(TObject *Sender)
Log->Lines->Add("Malloc failure!"); Log->Lines->Add("Malloc failure!");
return; return;
} }
RingBufInit(*spybuf,10000); RingBufInit(*spybuf,SPYBUF_LEN);
Log->Lines->Add("Spying...");
Timer->Enabled=true; Timer->Enabled=true;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment