home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
lan
/
spy
/
source
/
spy.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1989-10-04
|
11KB
|
340 lines
{$A+,B-,D-,E-,F+,I+,L-,N-,O-,R-,S-,V+}
{$M 16384,0,655360}
Program Spy;
{ SPY Monitor program - Network Remote Opertaions. Communicates with SPYTSR.
This program is:
Copyright (c) 1989 by Edwin T. Floyd
All rights reserved
Noncommercial use encouraged; direct commercial inquires and problem reports
to the author:
Edwin T. Floyd [76067,747]
#9 Adams Park Court
Columbus, GA 31909
404-322-0076 (home)
404-576-3305 (work)
}
Uses Multi, NetBios, SpySup, Screen, Dos;
Const
StopChar = #0; { Alt }
StopScan = 129; { Zero }
Var
InitialScreen : Pointer;
ScreenSave : Pointer;
InitialSaveLen : Word;
ScreenSaveLen : Word;
RapidUpdateCount : Word;
ScreenReq : RequestType;
ScreenInfo : ScreenInfoType;
Regs : Registers;
Adapter : Byte;
SpyLsn : Byte;
StopSpy : Boolean;
Break : Boolean;
SessionUp : Boolean;
ScreenTask : TaskType;
ScreenWaiting : Boolean;
KeyTask : TaskType;
KeyWaiting : Boolean;
MyName : NetNameType;
CallName : NetNameType;
Procedure ScreenUpdateProc(p : Pointer);
Var
ScreenNct : TaskNctType;
Err : Byte;
Begin
WriteLn('Screen update task started');
ScreenTask := MyTaskId;
With ScreenNct Do Begin
NetSetAdapter(Nct, Adapter, NetNoWait, NetTaskPost);
Repeat
ScreenWaiting := False;
If Not Break Then With ScreenReq Do Begin
Req := SendScreen;
Count := 0;
NetSend(Nct, SpyLsn, ScreenReq, SizeOf(ScreenReq) - SizeOf(Key));
Err := NetWaitError(ScreenNct, 2000);
If Err = 0 Then Begin
NetReceive(Nct, SpyLsn, ScreenSave^, ScreenSaveLen);
Err := NetWaitError(ScreenNct, 2000);
If (Err = 0) Or (Err = 6) Then With ScreenSaveHeader(ScreenSave^)
Do Begin
If (Size + SizeOf(ScreenSaveHeader) <= ScreenSaveLen) Then Begin
If Not Break Then RestoreScreenArea(ScreenSave^);
End Else Begin
FreeMem(ScreenSave, ScreenSaveLen);
ScreenSaveLen := Size + SizeOf(ScreenSaveHeader);
GetMem(ScreenSave, ScreenSaveLen);
End;
If Err = 6 Then Begin { Flush }
NetReceive(Nct, SpyLsn, ScreenSave^, ScreenSaveLen);
Err := NetWaitError(ScreenNct, 200);
End;
End;
End;
If (Err <> 0) And (NetReturnAction(Nct) = SessionDead) Then
SessionUp := False;
End;
If Not SessionUp Then Begin
SetCursorPosition($0101);
WriteLn('Calling ', Copy(CallName, 1, 15));
NetCall(Nct, CallName, MyName, CallRto, CallSto);
Err := NetWaitError(ScreenNct, 2000);
If Err <> 0 Then Begin
WriteLn('Unable to connect to ', Copy(CallName, 1, 15));
NetShutdown;
StopAll(5);
End;
SpyLsn := NetLsn(Nct);
SessionUp := True;
End;
Wait(50);
ScreenWaiting := True;
If RapidUpdateCount = 0 Then Wait(150) Else Dec(RapidUpdateCount);
Until StopSpy;
End;
Wake(KeyTask);
Stop;
End;
Procedure NetWaitKey;
Var
i : Word;
KeyReq : RequestType;
KeyNct : TaskNctType;
Err : Byte;
Begin
KeyTask := MyTaskId;
With KeyNct Do Begin
NetSetAdapter(Nct, Adapter, NetNoWait, NetTaskPost);
KeyReq.Count := 0;
Repeat
KeyWaiting := False;
If KeyHead <> KeyTail Then With KeyReq Do Begin
While (Count < MaxReqKeys) And (KeyHead <> KeyTail) Do Begin
With KeyQueue[KeyTail] Do Begin
If Break Then Begin
Case UpCase(KeyChar) Of
'E' : Begin
WriteLn('Spy will end now');
StopSpy := True;
End;
'B' : Begin
Req := Boot;
NetSend(Nct, SpyLsn, KeyReq, SizeOf(KeyReq) - SizeOf(Key));
Err := NetWaitError(KeyNct, 2000);
If Err = 0 Then Begin
WriteLn('Remote system ordered to reboot');
WriteLn('Spy will end now');
Wait(100);
StopSpy := True;
End Else Begin
WriteLn('Unable to send Boot cmd ', Err);
If NetReturnAction(Nct) = SessionDead Then
SessionUp := False;
End;
End;
'S' : Begin
Req := DieQuietly;
NetSend(Nct, SpyLsn, KeyReq, SizeOf(KeyReq) - SizeOf(Key));
Err := NetWaitError(KeyNct, 2000);
If Err = 0 Then Begin
WriteLn('Remote SPYTSR ordered to die quietly');
WriteLn('Spy will end now');
Wait(100);
StopSpy := True;
End Else Begin
WriteLn('Unable to stop remote SPYTSR ', Err);
If NetReturnAction(Nct) = SessionDead Then
SessionUp := False;
End;
End;
^[ : Begin
WriteLn('Returning to remote screen');
Break := False;
If ScreenWaiting Then Wake(ScreenTask);
End;
StopChar : If KeyScan = StopScan Then Begin
WriteLn('Alt-0 sent to remote system');
Break := False;
Inc(Count);
Key[Count] := KeyQueue[KeyTail];
If ScreenWaiting Then Wake(ScreenTask);
End;
End;
End Else Begin
Case KeyChar Of
#0 : If KeyScan = StopScan Then Break := True;
Else If KeyChar = StopChar Then Break := True;
End;
If Break Then Begin
FillWord(ScreenSave^, ScreenCols, 0);
For i := 1 To ScreenRows Do
PutWords(ScreenSave^, Succ(i Shl 8), ScreenCols);
SetCursorPosition($0101);
WriteLn('You are connected to remote system: ',
Copy(CallName, 1, 15));
WriteLn('Break menu:');
WriteLn;
WriteLn(' (E)xit SPY on local system');
WriteLn(' (B)oot remote system');
WriteLn(' (S)top SPYTSR on remote system');
WriteLn(' (Alt-0) Send Alt-0 to remote system');
WriteLn;
WriteLn('Press a key to choose an action or <Esc> to return...');
End Else Begin
Inc(Count);
Key[Count] := KeyQueue[KeyTail];
End;
End;
If KeyTail = MaxTableKeys Then KeyTail := 0 Else Inc(KeyTail);
End;
End;
If (Count > 0) And SessionUp Then Begin
Req := StuffKeyboard;
NetSend(Nct, SpyLsn, KeyReq, SizeOf(KeyReq) - SizeOf(Key)
+ Count * SizeOf(KeyType));
Err := NetWaitError(KeyNct, 2000);
If Err = 0 Then Count := 0 Else Begin
If NetReturnAction(Nct) = SessionDead Then SessionUp := False
Else WriteLn('Unable to send keystrokes: ', Err);
End;
RapidUpdateCount := 10;
If ScreenWaiting Then Wake(ScreenTask);
End;
End;
Wait(20);
KeyWaiting := True;
If KeyHead = KeyTail Then Wait(150);
Until StopSpy;
FreezeTask(ScreenTask);
NetShutdown;
If SessionUp Then Begin
NetHangup(Nct, SpyLsn);
Err := NetWaitError(KeyNct, 500);
End;
End;
NetShutdown;
RestoreScreenArea(InitialScreen^);
WriteLn('Spy Terminated');
StopAll(0);
End;
Procedure SpyIdle(Timeout : LongInt);
Var
i : 0..MaxTableKeys;
Begin
With Regs Do Begin
Ah := $01;
Intr($16, Regs);
If (Flags And FZero) = 0 Then Begin
i := KeyHead;
If i = MaxTableKeys Then i := 0 Else Inc(i);
If i <> KeyTail Then With KeyQueue[KeyHead] Do Begin
Ah := $00;
Intr($16, Regs);
KeyChar := Chr(Al);
KeyScan := Ah;
KeyHead := i;
If KeyWaiting Then Wake(KeyTask);
End;
End;
End;
End;
Procedure InitSpy;
Var
i, j : Integer;
NameNct : TaskNctType;
Status : NetAdapterStatusType;
Err : Byte;
s : String[2];
Begin
RapidUpdateCount := 0;
StopSpy := False;
Break := False;
SessionUp := False;
If (ParamCount < 1) Or (ParamStr(1) = '') Then Begin
WriteLn('Run like this: SPY <name>');
StopAll(1);
End Else Begin
CallName := ParamStr(1);
For i := 1 To Length(CallName) Do CallName[i] := UpCase(CallName[i]);
While Length(CallName) < 16 Do
Insert(' ', CallName, Succ(Length(CallName)));
CallName[16] := #$EF;
End;
If ParamCount > 1 Then Begin
s := ParamStr(2);
Val(s, i, j);
If (i >= 0) And (i < 3) Then Adapter := i Else Begin
WriteLn('Adapter must be 0..3, "', ParamStr(2), '" specified');
StopAll(2);
End;
End Else Adapter := 0;
If Not NetAdapterPresent(Adapter) Then Begin
WriteLn('Adapter ', Adapter, ' not found');
StopAll(3);
End;
With NameNct Do Begin
NetSetAdapter(Nct, Adapter, NetNoWait, NetTaskPost);
WriteLn('Getting Unit Name for adapter ', Adapter);
NetAdapterStatus(Nct, Status, '*');
Err := NetWaitError(NameNct, 2000);
If Err <> 0 Then Begin
WriteLn('Unable to acquire local adapter Unit Name, error ', Err);
StopAll(4);
End Else Begin
MyName[0] := #16;
FillChar(MyName[1], 10, 0);
Move(Status.UnitId, MyName[11], 6);
End;
WriteLn('Calling ', Copy(CallName, 1, 15));
NetCall(Nct, CallName, MyName, CallRto, CallSto);
Err := NetWaitError(NameNct, 2000);
If Err <> 0 Then Begin
WriteLn('Unable to connect to ', Copy(CallName, 1, 15),
', error ', Err);
StopAll(5);
End;
SpyLsn := NetLsn(Nct);
SessionUp := True;
WriteLn('Requesting screen information');
With ScreenReq Do Begin
Req := SendScreenInfo;
Count := 0;
NetSend(Nct, SpyLsn, ScreenReq, SizeOf(ScreenReq) - SizeOf(Key));
Err := NetWaitError(NameNct, 2000);
If Err = 0 Then Begin
NetReceive(Nct, SpyLsn, ScreenInfo, SizeOf(ScreenInfo));
Err := NetWaitError(NameNct, 2000);
If Err = 0 Then Begin
ScreenSaveLen := ScreenInfo.ScreenSaveSize;
WriteLn('ScreenSave area is ', ScreenSaveLen, ' bytes');
GetMem(ScreenSave, ScreenSaveLen);
End;
End;
If Err <> 0 Then Begin
WriteLn('Unable to acquire screen information from ',
Copy(CallName, 1, 15), ', error ', Err);
StopAll(6);
End;
End;
End;
WriteLn('Connection established');
InitialSaveLen := ScreenAreaSize(1, 1, ScreenCols, ScreenRows);
GetMem(InitialScreen, InitialSaveLen);
SaveScreenArea(InitialScreen^, 1, 1, ScreenCols, ScreenRows);
IdleRoutine := SpyIdle;
Spawn(ScreenUpdateProc, Nil, 8192, 'SCREEN');
End;
Begin
WriteLn('SPY Version 1.1 Starting - Press Alt-0 for menu');
InitSpy;
NetWaitKey;
End.