Dll-Injection - Notepad

c++ / delphi package - dll injection and api hooking
Post Reply
Crocotronic
Posts: 4
Joined: Sat Aug 18, 2012 1:45 pm

Dll-Injection - Notepad

Post by Crocotronic »

Hello again,
to come into touch with all the brilliant components I tried to inject a simple DLL into Notepad. Here is small code:

Code: Select all

InjectLibrary(FindWindow('notepad',nil),'MsgBox.dll');
It doesn't work (no reaction) :cry: The code is probably to easy, right?
Hope you can help me :)

Greetings,
Crocotronic
iconic
Site Admin
Posts: 1067
Joined: Wed Jun 08, 2005 5:08 am

Re: Dll-Injection - Notepad

Post by iconic »

FindWindow('notepad',nil) returns a window handle, not a process handle. Use OpenProcess() with the process id of notepad. If you want to convert window handles to owner process handles you can do this

Code: Select all

var
  Wnd: HWND;
  dwPID: DWORD;
  hProcess: THandle;
begin
  Wnd := FindWindowW('notepad', nil);
  GetWindowThreadProcessId(Wnd, dwPID);
  hProcess := OpenProcess(MAXIMUM_ALLOWED, False, dwPID);
  if hProcess <> 0 then
  begin
  InjectLibrary(hProcess, 'Inject.dll');
  CloseHandle(hProcess);
  end;
end;
--Iconic
Crocotronic
Posts: 4
Joined: Sat Aug 18, 2012 1:45 pm

Re: Dll-Injection - Notepad

Post by Crocotronic »

Thanks a lot!! Works perfect :)
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Re: Dll-Injection - Notepad

Post by madshi »

iconic doing support for me, nice! :D
Post Reply