Autor Beitrag
SAiBOT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: So 15.01.06 14:54 
hi all,
ich versuche einen API HOOK zu machen der erkennt wenn eine Exe, eine datei importiert!
(auch eigene Dateiformate).

Beispiel:

mspaint.exe > öffnet die datei C:\Hallo.bmp.
Hook erkennt dies und öffnet statt C:\Hallo.bmp, C:\MyHallo.bmp.

Weiß noch nicht ganz genau welche functionen dafür gehookt werden sollen, geschweige denn obs mit delphi überhaupt möglich ist, da es wieder in die richtung Kernel32 geht :).

MfG
-=LE=-
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 15.01.06 16:49 
Ist mit nem Hook auf die CreateFileW-Funktion ohne weiteres möglich. Schau Dir dazu mal die uallCollection an.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
SAiBOT Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: So 15.01.06 21:32 
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
library hook;

uses
  windows,
  uallhook,
  dialogs,
  Controls,
  sysutils;

var
  old_CreateFileW: function(lpszName:LPCTSTR;fdwAccess, fdwShareMode:DWORD; lpsa:PSecurityAttributes; fdwCreate, fdwAttrsAndFlags:DWORD; hTemplateFile:HWND): HWND; stdcall;
  next_CreateFileW: function(lpszName:LPCTSTR;fdwAccess, fdwShareMode:DWORD; lpsa:PSecurityAttributes; fdwCreate, fdwAttrsAndFlags:DWORD; hTemplateFile:HWND): HWND; stdcall;

function my_CreateFileW(lpszName:LPCTSTR;fdwAccess, fdwShareMode:DWORD; lpsa:PSecurityAttributes; fdwCreate, fdwAttrsAndFlags:DWORD; hTemplateFile:HWND): HWND; stdcall;
begin
  Result := next_CreateFileW(lpszName, fdwAccess, fdwShareMode, lpsa, fdwCreate, fdwAttrsAndFlags, hTemplateFile);
end;

procedure injectmain;
var
  p4:pointer;
begin
  p4 := GetProcAddress(GetModuleHandle('kernel32.dll'),'CreateFileW');
  if p4 <> nil then begin
    @old_CreateFileW := p4;
    uallHook.HookCode(@old_CreateFileW,@my_CreateFileW,@next_CreateFileW);
  end;

end;

procedure uninjectmain;
begin
  uallHook.UnhookCode(@next_CreateFileW);
end;

procedure dllmain(dwReason: integer);
begin
  case dwreason of
    DLL_PROCESS_ATTACH:
      injectmain;
    DLL_PROCESS_DETACH:
      uninjectmain;
  end;
end;

begin
  DLLProc := @DLLMain;
  DLLMain(1);
end.


ok hook sitzt, aber wie unterscheide ich jetzt die daten die geladen werden?
ich dachte erst "lpszName" sei der dateiname aber diese variable hat immer den wert "\" oder "C".
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: So 15.01.06 21:45 
das ist nen PChar den kannst du dir z.b. mit

ausblenden Delphi-Quelltext
1:
MessageBoxA(0,lpszName,nil,0)					


anzeigen lassen

oder du machst

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
//...
var s: String;
begin
  s := lpszName;
  if (suppercase(s) = 'C:\bla.txt') then... 
//...

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
SAiBOT Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: So 15.01.06 22:18 
user profile iconuall@ogc hat folgendes geschrieben:
das ist nen PChar den kannst du dir z.b. mit

ausblenden Delphi-Quelltext
1:
MessageBoxA(0,lpszName,nil,0)					


anzeigen lassen

oder du machst

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
//...
var s: String;
begin
  s := lpszName;
  if (suppercase(s) = 'C:\bla.txt') then... 
//...


dachte ich mir auch so, aber versuchs mal das geht nicht!
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 16.01.06 01:09 
Du hookst ne WideChar-Funktion und wunderst dich, dass AnsiChars Probleme machen ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Mo 16.01.06 14:40 
siehste BenBE da hab ich mal wieder net richtig gelesen ;)

ausblenden Delphi-Quelltext
1:
2:
3:
function CreateFileW(lpFileName: PWideChar; dwDesiredAccess, dwShareMode: DWORD;
  lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
  hTemplateFile: THandle): THandle; stdcall;


und

ausblenden Delphi-Quelltext
1:
  WideCharToString					


sollte helfen

Moderiert von user profile iconChristian S.: Delphi-Tags repariert

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
SAiBOT Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: Mo 16.01.06 17:34 
user profile iconBenBE hat folgendes geschrieben:
Du hookst ne WideChar-Funktion und wunderst dich, dass AnsiChars Probleme machen ...


woher soll ich das wissen? in der windows sdk steht bei mir der eine andere typ, naja egal dake auch beiden!
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Mo 16.01.06 17:40 
user profile icon-=LordEvil=- hat folgendes geschrieben:
woher soll ich das wissen?
Alles, was ein W an den Namen angehängt hat, impliziert automatisch Strings aus 16bit breiten Widechars, sowohl für die Eingabe (Parameter), als auch für die Ausgabe (Rückgabewerte).

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert