Home > Back-end >  Can be automatically pop-up window after DLL injection, but the keyboard hook can't breathe out
Can be automatically pop-up window after DLL injection, but the keyboard hook can't breathe out

Time:10-08

Bother everybody to help see, after the DLL injection, can automatically display window, but also causes the keyboard hook, but can't breathe out the window, put a MessageBox (0, 'displayed', 'show', 0). , will be displayed, and the dynamic invocation DLL will tip can't find the function, the static no problem, function with parameters, have a little dizzy
Under the DLL code into the
The library mydll;


USES the
SysUtils,
Windows,
Classes,
Forms,
Myform in 'myform. Pas,



Var
Keyhhk: HHOOK;


{$R *. Res}



The function keyproc (icode, wp, lp: integer) : dwords. Stdcall;
The begin
If (icode=HC_ACTION) then
The begin
If (wp=VK_HOME) and (SHL 31 (1) and lp=0) then
The begin
If form1=nil then
The begin
Form1:=tform1. Create (nil);
//MessageBox (0, PChar (IntToStr (Application. Handle)), PChar (' Test '), MB_OK);
MessageBox (0, 'success', 'show', 0).
end;
Form1. Show;
MessageBox (0, 'show', 'show', 0).
end;
end;
Keyproc:=CallNextHookEx (keyhhk, icode, wp, lp);
end;

Procedure DllEnterProc (reason: DWord);//unloading function form

The begin
Case "reason of
Windows. DLL_PROCESS_ATTACH:
The begin
//hookdlla:=Thookdll. Create (false);
Form1:=tform1. Create (nil);
Form1. Show;
MessageBox (0, 'into the', 'show', 0).
end;
Windows. DLL_PROCESS_DETACH: begin form1. Free; Form1:=nil; end;
end;
end;



Function installKeyProcy (dar: dword) : Boolean; Stdcall;

The begin
Result:=false;
Keyhhk:=setwindowshookex (WH_KEYBOARD @ Keyproc, GetModuleHandle (' 123. DLL), Tid);

If keyhhk> 0 then the Result:=true;
end;

The function uninstallKeyProc () : a Boolean; Stdcall;
The begin
Result:=UnhookWindowsHookEx (keyhhk);
end;



Exports

InstallKeyProcy,
UninstallKeyProc;
The begin
Dllproc:=@ DllEnterProc;
DllEnterProc (DLL_PROCESS_ATTACH);

End.


Exe window using InjectDll (ExtractFilePath (Application. ExeName) + '123. DLL, lsPid);
Will be running Windows. The content of the DLL_PROCESS_ATTACH,
I'll also use
InstallKeyProcy (dar) is to be able to hook procedure, also displays MessageBox (0, 'show', 'show', 0). Content, but the window does not show up, my purpose is to automatically after injection can display window, and I also can pop-up window button, I do not know where I went wrong, please guidance,
And installKeyProcy (dar) using static call no problem, use the

HModule:=LoadLibrary (123. DLL ');
The Pcall:=GetProcAddress call (hModule, installKeyProcy);
InstallKeyProcy:=Pcall;
If (Pcall=nil) then
The begin
Self. Caption:='failed to obtain function address;
exit;
end;
Will pop up 'failed to obtain function address, if it is invoked with no arguments without problems, under the guidance of this also please everybody

CodePudding user response:

Since a MessageBox (0, 'show', 'show', 0)

CodePudding user response:

Upstairs, say what?

CodePudding user response:

The Pcall:=GetProcAddress call (hModule, installKeyProcy);//the second parameter wrong, of course, take less than function addresses, and doesn't compile, you is how to compile successfully??

To:
The Pcall: GetProcAddress call=(hModule, 'installKeyProcy');//the second parameter is a function name

CodePudding user response:

Upstairs good eye, that is when I copied down correction, the program is its', if can not compile successfully, the problem is not here, will first form1:=tform1. Create (nil); Created with two brother form1 form1. The Show is not the same form, but if form1=nil then this sentence is not empty, that is to say, brother 2 times only run the form1. Show, but will not display, struggle

CodePudding user response:

To email me to give you a complete implementation examples

CodePudding user response:

BBS strange, that I long a passage into a # 1, and I want to say: try form1. Show to form1. Showmodal

CodePudding user response:

BBS strange, that I long a passage into a # 1, and I want to say: try form1. Show to form1. Showmodal

CodePudding user response:

BBS strange, that I long a passage into a # 1, and I want to say: try form1. Show to form1. Showmodal

CodePudding user response:


The function keyproc (icode, wp, lp: integer) : dwords. Stdcall;
The begin
If (icode=HC_ACTION) then
The begin
If (wp=VK_HOME) and (SHL 31 (1) and lp=0) then
The begin
If form1=nil then
Form1:=tform1. Create (nil);//button DLL injection immediately after creating the form
The else
Form1. Visible:=not form1. Visible;//if you have created before switching to state
end;
end;
Keyproc:=CallNextHookEx (keyhhk, icode, wp, lp);
end;

CodePudding user response:

Switch the status window should be placed at the top: form1 bringtofront

CodePudding user response:

Keyproc the execution environment should be a thread of execution environment, this is equivalent to in the main thread interface operation, is not thread-safe,
Try to create the form in the main thread, and then using SendMessage keyproc send a custom message to form, forms when the response message Show form, it is the operation interface in the main thread,

CodePudding user response:

To ls, lz seems to do online plugins, but don't want to write the remote code way, using into host (game) process is to use a variety of facilities is its purpose (and a lot of online games are done ban into the remote code processing), now that is just a matter of simple logic, AnXiaoDi the code above can be solved,

CodePudding user response:

Thank you for your guidance, sololie code is the same with me, only keyproc hooks if you press the home button you can run, the problem is that my purpose is to, after injection can create first window, press the home also can show the window instead of waiting to press home again to run to create the code window , the DLL into the program I am using InjectDll (ExtractFilePath (Application. ExeName) + '123. DLL, lsPid); The code into the
The function InjectDll (const DllFullPath: string;
Const dwRemoteProcessId: Cardinal) : Boolean;
Var
HRemoteProcess hRemoteThread: THANDLE;
PszLibFileRemote: Pointer;
PszLibAFilename: PwideChar;
PfnStartAddr: TFNThreadStartRoutine;
WriteSize memSize, lpThreadId: Cardinal;
The begin
Result:=FALSE;
Adjust the permissions//, make the program can access other processes memory space
If EnableDebugPriv then
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related