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

Strips telnet commands from Spy output.

parent 8b1b5d9f
Branches
Tags
No related merge requests found
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "MainFormUnit.h" #include "MainFormUnit.h"
#include "SpyFormUnit.h" #include "SpyFormUnit.h"
#include "telnet.h"
#define SPYBUF_LEN 10000 #define SPYBUF_LEN 10000
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
...@@ -60,9 +61,37 @@ __fastcall TSpyForm::TSpyForm(TComponent* Owner) ...@@ -60,9 +61,37 @@ __fastcall TSpyForm::TSpyForm(TComponent* Owner)
ActiveControl=Terminal; ActiveControl=Terminal;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
int strip_telnet(uchar *buf, int len)
{
int i;
int telnet_cmd=0;
int newlen=0;
for(i=0;i<len;i++) {
if(buf[i]==TELNET_IAC || telnet_cmd) {
if(telnet_cmd==1 && buf[i]==TELNET_IAC) {
telnet_cmd=0; /* escape IAC */
continue;
}
if(telnet_cmd==1 && buf[i]<TELNET_WILL) {
telnet_cmd=0; /* single byte command */
continue;
}
if(telnet_cmd>=2) {
telnet_cmd=0; /* two byte command */
continue;
}
telnet_cmd++;
continue;
}
buf[newlen++]=buf[i];
}
return(newlen);
}
//---------------------------------------------------------------------------
void __fastcall TSpyForm::SpyTimerTick(TObject *Sender) void __fastcall TSpyForm::SpyTimerTick(TObject *Sender)
{ {
char buf[1024]; uchar buf[1024];
int rd; int rd;
if(*outbuf==NULL) if(*outbuf==NULL)
...@@ -70,6 +99,7 @@ void __fastcall TSpyForm::SpyTimerTick(TObject *Sender) ...@@ -70,6 +99,7 @@ void __fastcall TSpyForm::SpyTimerTick(TObject *Sender)
rd=RingBufRead(*outbuf,buf,sizeof(buf)-1); rd=RingBufRead(*outbuf,buf,sizeof(buf)-1);
if(rd) { if(rd) {
rd=strip_telnet(buf,rd);
Terminal->WriteBuffer(buf,rd); Terminal->WriteBuffer(buf,rd);
Timer->Interval=1; Timer->Interval=1;
} else } else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment