Einzelnen Beitrag anzeigen

Benutzerbild von diabox
diabox

Registriert seit: 13. Sep 2006
61 Beiträge
 
Delphi 2010 Professional
 
#1

madCodeHook: UninjectLibrary verursacht Neustart

  Alt 11. Nov 2006, 16:50
moin allerseits!

Ich verwende die madCodeHook Unit (madshi) für ein kleines Projekt, das "Shell_NotifyIcon" systemweit hooken soll. Prozessweit klappt alles reibungslos. Das Hooken funktioniert zwar auch systemweit, aber sobald ich UninjectLibrary aufrufe, wird mein PC ohne Vorwarnung neugestartet, d.h. Bildschirm wird schwarz und zack isser wieder am booten.

DLL:
Delphi-Quellcode:
library DBXHookDLL;

uses Windows,SysUtils, Classes, ShellApi, madRemote, madCodeHook, madStrings, Dialogs;

var Shell_NotifyIconNext : function (dwMessage: DWord; lpdata: PNOTIFYICONDATA): Boolean; stdcall;

const
 {$EXTERNALSYM NIM_SETFOCUS} 
  NIM_SETFOCUS = $00000003;
  {$EXTERNALSYM NIM_SETVERSION}
  NIM_SETVERSION = $00000004;

function Shell_NotifyIconCallback(dwMessage: DWord; lpdata: PNOTIFYICONDATA): Boolean; stdcall;
var
MyLog: TStringList;
begin
try
MyLog:=TStringList.Create();
if dwMessage = NIM_ADD then MyLog.Add('NIM_ADD');
if dwMessage = NIM_DELETE then MyLog.Add('NIM_DELETE');
if dwMessage = NIM_MODIFY then MyLog.Add('NIM_MODIFY');
if dwMessage = NIM_SETFOCUS then MyLog.Add('NIM_SETFOCUS');
if dwMessage = NIM_SETVERSION then MyLog.Add('NIM_SETVERSION');
MyLog.SaveToFile('C:\DBXHookDLLLog.txt'); //Die Datei wird erstellt und es steht
//je nach Aktion dann auch NIM_ADD usw. drin
MyLog.Destroy();
except on E: Exception do begin end; //Was auch immer für Exceptions
//auftreten - ich will keine sehen :-) (Habs auch ohne getestet:
//bringt mich nicht weiter...)
end;

result := Shell_NotifyIconNext(dwMessage,lpdata);
end;

begin
  HookAPI('shell32.dll', 'Shell_NotifyIcon', @Shell_NotifyIconCallback, @Shell_NotifyIconNext);
end.
MainAPP:
Delphi-Quellcode:
unit uMain;

interface

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

type
  TForm1 = class(TForm)
    Button3: TButton;
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Button3Click(Sender: TObject);
begin
  InjectLibrary(ALL_SESSIONS or SYSTEM_PROCESSES, 'DBXHookDll.dll');
  MessageBox(0, 'Active...', 'Hook is active...', MB_ICONINFORMATION);
  UninjectLibrary(ALL_SESSIONS or SYSTEM_PROCESSES, 'DBXHookDll.dll'); //shutdown
end;

end.
Was mach ich falsch?
Ist mein zweiter Versuch mit Code Hooking, also seid nachsichtig mit mir

Danke im voraus
Wer zweifelt, detoniert nicht!'
Dieter Nuhr
  Mit Zitat antworten Zitat