Autor Beitrag
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mi 11.05.05 21:57 
ausblenden 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:
library hook_2;

uses
  windows,
  uallhook;


type TCFfunc = function(lppoint:pointer):boolean; stdcall;

var oldCreateFile, nextCreateFile: tcffunc;


function myCreateFile(lpPoint:pointer):boolean; stdcall;
begin
tpoint(lppoint^).x := 123;
tpoint(lppoint^).y := 123;
result := true;
end;

var p:pointer;

begin
  p := GetProcAddress(GetModuleHandle('user32.dll'),'GetCursorPos');
  if p <> nil then begin
    @oldCreateFile := p;
    uallHook.HookCode(@oldCreateFile,@myCreateFile,@nextCreateFile);
  end;
end.

bei mir gehts so, logischerweise aber nur, wenn die anwendung, die den getcursorpos test macht, bereits vor dem start des inject-programmes (exemain) geladen ist

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
uall@ogc Threadstarter
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: Mi 11.05.05 22:06 
ich weiß nicht warum ihr das so kompliziert macht, in der windows pas stehen doch alle header drin:

ausblenden Delphi-Quelltext
1:
function GetCursorPos(var lpPoint: TPoint): BOOL; stdcall;					


das würde dann so etwas aussehen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var oldGetCursorPos, nextGetCursorPos: function(var lpPoint: TPoint): BOOL; stdcall;


function myGetCursorPos(var lpPoint: TPoint): BOOL; stdcall;
begin
  // alter aufruf überhaupt nötig?
  // result := nextGetCursorPos(lpPoint);
  // ansonsten nur:

  result := true;
  lpPoint.x := 123;
  lpPoint.y := 123;  
end;

// und noch hooken

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
uall@ogc Threadstarter
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: Mi 11.05.05 22:16 
so habs hier nochmal getestet:

ausblenden 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:
var oldGetCursorPos, nextGetCursorPos: function(var lpPoint: TPoint): BOOL; stdcall;

function myGetCursorPos(var lpPoint: TPoint): BOOL; stdcall;
begin
  // alter aufruf überhaupt nötig?
  // result := nextGetCursorPos(lpPoint);
  // ansonsten nur:

  result := true;
  lpPoint.x := 123;
  lpPoint.y := 123;
end;


procedure TForm1.FormCreate(Sender: TObject);
var lp: Tpoint;
begin
  @oldGetCursorPos := GetProcAddress(GetModuleHandle('user32.dll'),'GetCursorPos');
  uallHook.HookCode(@oldGetCursorPos,@myGetCursorPos,@nextGetCursorPos);

  GetCursorPos(lp); //alter aufruf
  form1.caption := inttostr(lp.X)+' '+inttostr(lp.Y);
end;



funktioniert einwandfrei
man kann immer die header aus der windows.pas bzw andere vordefinierte header nehmen, es ist egal wie diese aussehen

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
maps
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Mi 11.05.05 22:29 
Eben habe ich noch einen Fehler im Code gefunden,
welcher eigentlich richtige Werte als ungültig (X/Y = 0) darstellte.

Alles funktioniert nun einwandfrei - man darf lediglich das "var" in
function XXXGetCursorPos(var lpPoint: TPoint): BOOL; stdcall;nicht vergessen! :wink:

Vielen Dank, retnyg und uall!
maps
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Sa 14.05.05 01:08 
Hallo,

Ich habe leider ein weiteres Problem:

Ich möchte "SystemParametersInfo" manipulieren.
Das gelingt mir soweit auch, allerdings crasht es beim "Unloaden" jedesmal die Programme.

Ich habe die Funktionen auf ihr Minimum reduziert und zudem nur das "1337 global hook" Beispiel abgeändert, um die möglichen Fehlerquellen zu minimieren.

Jedoch kann ich mir nicht erklären, weshalb es beim "Unloaden" immer zu einem Crash kommt.


Hier ist der Loader:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
program exemain;

uses
  windows,
  uallHook,
  uallUtil;

begin
  if paramcount < 1 then
    MessageBox(0,'No Param, use PARAM -load / -unload.',Nil,0else

  if uppercase(paramstr(1)) = uppercase('-load'then
    GlobalInjectLibrary(pchar(uallUtil.GetExeDirectory+'hook.dll')) else

  if uppercase(paramstr(1)) = uppercase('-unload'then
    GlobalUnloadLibrary(pchar('hook.dll')) else

    MessageBox(0,'Wrong Param, use PARAM -load / -unload.',Nil,0);
end.


Und hier der Hook:
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:
50:
51:
52:
53:
54:
55:
56:
library hook;

uses windows,
     uallHook;

var
  oldSystemParametersInfoA, oldSystemParametersInfoW, nextSystemParametersInfoA,
  nextSystemParametersInfoW: function(uiAction, uiParam: UINT; pvParam: Pointer; fWinIni: UINT): BOOL; stdcall;

function mySystemParametersInfoA(uiAction, uiParam: UINT; pvParam: Pointer; fWinIni: UINT): BOOL; stdcall;
begin
Result := nextSystemParametersInfoA(uiAction, uiParam, pvParam, fWinIni);
end;

function mySystemParametersInfoW(uiAction, uiParam: UINT; pvParam: Pointer; fWinIni: UINT): BOOL; stdcall;
begin
Result := nextSystemParametersInfoW(uiAction, uiParam, pvParam, fWinIni);
end;

procedure injectmain;
var h: integer;
begin
  h :=  GetModuleHandle('user32.dll');
  if h > 0 then
  begin
      @oldSystemParametersInfoA := GetProcAddress(h, 'SystemParametersInfoA');
      If @oldSystemParametersInfoA <> Nil
      then
        uallHook.HookCode(@oldSystemParametersInfoA, @mySystemParametersInfoA, @nextSystemParametersInfoA);
      @oldSystemParametersInfoW := GetProcAddress(h, 'SystemParametersInfoW');
      If @oldSystemParametersInfoW <> Nil
      then
        uallHook.HookCode(@oldSystemParametersInfoW, @mySystemParametersInfoW, @nextSystemParametersInfoW); 
  end;
end;

procedure uninjectmain;
begin
  uallHook.UnhookCode(@nextSystemParametersInfoA);
  uallHook.UnhookCode(@nextSystemParametersInfoW);
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.



Wäre schön, wenn ihr eine Erklärung (besser noch: Lösung) parat habt.


Danke!
uall@ogc Threadstarter
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: Sa 14.05.05 11:00 
ich schau mir das gleich mal an aber du könntest beim unhook schaun ob uallHook.UnhookCode auch funktioniert hat weil wenn die dll entladen wird aber immer noch gehookt ist crashed es natürlich

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
maps
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Sa 14.05.05 11:31 
Nein, "UnhookCode" meldet bei beiden Aufrufen "False".
uall@ogc Threadstarter
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: Sa 14.05.05 11:45 
ausblenden Delphi-Quelltext
1:
2:
3:
var   
  oldSystemParametersInfoA, oldSystemParametersInfoW, nextSystemParametersInfoA,   
  nextSystemParametersInfoW: function(uiAction, uiParam: UINT; pvParam: Pointer; fWinIni: UINT): BOOL stdcall = nil;


ausblenden Delphi-Quelltext
1:
2:
3:
  if @nextSystemParametersInfoA <> nil then
  if uallHook.UnhookCode(@nextSystemParametersInfoA) then
   // MessageBoxA(0,pchar(paramstr(0)),nil,0); <- aber messageboxa dynamisch importieren



kannste das mal so abändern und mir sagen welches programm z.b. crashed damit ich das mal selbst testen kann?

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
maps
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Sa 14.05.05 12:00 
Bei
ausblenden Delphi-Quelltext
1:
2:
3:
var
  oldSystemParametersInfoA, oldSystemParametersInfoW, nextSystemParametersInfoA, 
  nextSystemParametersInfoW: function(uiAction, uiParam: UINT; pvParam: Pointer; fWinIni: UINT): BOOL stdcall = nil;
bekomme ich "Cannot initialize multiple variables", auch nachdem ich ein Semikolon hinter "BOOL" gesetzt habe.

Ansonsten habe ich es nun ein weiteres Mal getestet und trotzdem stürzen die Programme ab.

Es stürzen alle Prozesse mit Fenstern ab, sobald irgendeine Aktion auf ihren Fenstern durchgeführt werden soll.

Ich habe zB. einfach auf "Explorer.exe"'s "Start"-Button geklickt und schon ist der Prozess abgestürzt.

"Winlogon.exe" stürzt zB. beim Herunterfahren ab, also sobald es selber ein Fenster generiert.
uall@ogc Threadstarter
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: Sa 14.05.05 12:15 
das mit dme nil is klar das es net geht ;P mein fehler ich teste mal eben selber

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
maps
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Sa 14.05.05 12:19 
Ich habe soeben den Fehler gefunden.

Ich benutze die "Key Objects Library" und zu der gibt es auch noch Replacements für "SysInit", "System", "SysUtils", "Classes", etc., um die Größe noch weiter zu reduzieren.

Ich habe jetzt einfach mal testweise alle Replacements entfernt, beide Binaries neu kompiliert und schon gab es diese Crashes nicht mehr.

Ich werde nun die Fehlerquelle weiter eindämmen, um genau zu wissen, welche PAS/DCU-Datei für die Crashes verantwortlich ist.


Edit:
Es liegt an dem "SysInit" Replacement.
uall@ogc Threadstarter
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: Sa 14.05.05 12:35 
ja pass auf ich habs auch getestet bei mir gehts.

wichtig ist das du in der dll nur STATISCHE imports von der KERNEL32.DLL hast.
keine anderen! das liegt daran das die dll auch in system prozesse geladen wird die nur die ntdll.dll und kernel32.dll geladen haben. sollte deine dll da irgendwelche komischen dlls statisch laden kanns crashen wenn se beim unloaden oder so nicht auch entladen werden.

ich weiß auch nicht was die keyobject library macht (ich schaus mit mal an) aber in der hookdll nur die windows.pas benutzen alles andere dynamisch einbinden und versuchen kaum neue dlls zu laden

ansonsten mussu das GetDebugPrivilege rausnehmen, dann wird nich in systemprozesse injected.

uallProcess ruft immer GetDebugPrivilege beim start auf. vielleicht sollte ich das mal ändern.
nen veruschs isses wert das mal zu entfernen und schaun obs dann geht.

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
maps
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Sa 14.05.05 12:51 
Auch bei auskommentiertem "GetDebugPrivilege" und KOL's "SysInit" Replacement kommt es zum Crash.

Aber der Fehler ist ja nun eigentlich gelöst - ich benutze einfach nicht mehr das "SysInit" Replacement.


Vielen Dank!
maps
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Sa 14.05.05 21:23 
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Sa 14.05.05 21:38 
maps
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: So 15.05.05 12:00 
Dir ist schon aufgefallen, dass in dem Dateinamen ein Datum vorhanden ist und dein Link folglich zu einer veralteten Version führt?
reepo2k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 138

WIN XP
Borland Delphi 7 Enterprise, Microsoft Visual C++ 6.0 Enterprise, Macromedia Dreamweaver 8
BeitragVerfasst: Mo 16.05.05 21:03 
Wär seht nett, wenn das mit dem Link gefixt wird, würd mich sogar bereiterklären das File zu hosten.

MfG: reepo2k
uall@ogc Threadstarter
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.05.05 21:59 
hatte ich doch heute mittang schon geändert :)

war nur so weil der source in die code sparte bei delphipraxis reinkam und ich da nen fixen link nehmen musste damit ich da immer alles uppen kann
also ohne ein datum isses jetzzt immer,hab das jetzt mal dahinter geschrieben

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mo 16.05.05 23:39 
vielen dank für die unhook funktion ! :D
hast du an der process und protect unit auch was geändert (weil ich da schon einiges geändert habe, noch bei der 27.04er version) ?

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
uall@ogc Threadstarter
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.05.05 23:46 
ausser dass ich die funktionen hinzugefügt habe hab ich sonst nichts verändert im gegensatz zu der verion davor.
hatte in der version davor halt die bugs gefixt.

aber ich schreib das besser nächtes mal dazu

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit