Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Delphi] SetWindowsHookEx InjectLIB

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
h4c0r-BG
Master Cheater
Reputation: 0

Joined: 29 Nov 2006
Posts: 449
Location: The yogurt country

PostPosted: Wed Mar 25, 2009 5:49 pm    Post subject: [Delphi] SetWindowsHookEx InjectLIB Reply with quote

Well i started browsing the net for tutorials and found this web:

http://www.edgeofnowhere.cc/viewtopic.php?p=2483118

In there they explain a way to inject a dll via SetWindowsHookEx

So far so good, i started translating it from C++ to Delphi

Here is what i have:

Code:
var
  Form1: TForm1;
  dllhandle:thandle;

implementation

{$R *.dfm}


function CBTProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): dword; stdcall;
begin
dllhandle:=LoadLibrary('C:\injected.dll');
result:=CallNextHookEx(0,nCode,WPARAM,LPARAM);
end;

procedure InjectDLL({dllname:pchar;}windowname:pchar);
var
cb_proc_offset,pid:dword;
begin
pointer(cb_proc_offset):=@CBTProc;
SetWindowsHookEx(WH_CBT,@cb_proc_offset,dllhandle,getwindowthreadprocessid(findwindow(nil,pchar(windowname)),@pid));
showmessage(inttohex(dllhandle,1));
end;



Return value of dllhandle is 0 and no dll is injected at all, how can i fix that?

_________________

Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25813
Location: The netherlands

PostPosted: Wed Mar 25, 2009 7:10 pm    Post subject: Reply with quote

Try re-reading the code examples.

first:
dllhandle:=LoadLibrary('C:\injected.dll'); should be in injectdll, not CBTProc

Also, instead of pointer(cb_proc_offset):=@CBTProc; just do:
SetWindowsHookEx(WH_CBT,@CBTProc, dllhandle,getwindowthreadprocessid(findwindow(nil,pchar(windowname)),@pid));

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Wed Mar 25, 2009 7:10 pm    Post subject: Reply with quote

This line of code:

Code:

dllhandle:=LoadLibrary('C:\injected.dll');


Shouldn't be in the CBTProc function. Also, the CBTProc function is in your DLL, not your injector. Second off, the handle should be obtained in the InjectDLL function. Third, getwindowthreadprocessid returns the pid into a DWORD type variable, in this case pid, not as a return value. So you have to call it before you call SetWindowsHookEx and then use the variable pid as the last parameter.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites