Agreement plug-in production

xiaoxiao2021-03-06  114

Agreement plug-in production

BY RIX

The last time we said the startup of the target program, and the pretreatment of the target program. In this section, it is possible to show the plug-in window. Can you say so much, you can only look at it.

Because I decided to use the most popular way hook to inject the thread (sometimes I feel that I have to do this, because Debug's way is also good), for the more universal and faster transplant, and simple, I Decide or use HOOK. Here, let's talk about it, if you don't understand the compilation and program debugging, it is best to make a lesson, which is used in the future.

Let's write the hook.dll section, the launch part of the program is temporarily unreasonable (I will call it in the same part of WG.exe), yesterday, I was very forgiving, I let the data address in the WriteProcessMemory in the mask is big. 9.16 The last version of the update, you need to take the program before 9.16 update, this part I will say later, so let everyone block the two write memory.

For hook.dll, we are ready to use the F12 key to activate the plug-in, write a DLL in the CB very simple, create a DLL project project, and then add code. When establishing an engineering, I remember to select the use of C , using VCL, Multi Thread, the reason:

1. Use C to make me save you water (I put the APIHOOK into a class).

2, use VCL because I am too lazy, don't want to write interface code.

3. Use multithreading because the program must.

Since the external main form is in the DLL, the generated DLL will be larger than the general DLL. The form can be placed anywhere, but it is more convenient to put it in the DLL, and it can be better separated when it is.

The following is the code of hook.cpp:

/ / -------------------------------------------------------------------------------------------- ---------------------------

#include

#include

#include "hookapi.h"

#include "hookform.h"

#pragma HDRSTOP

#pragma argsused

HHOOK G_HHHOOK = NULL; // hook handle

Hinstance dllhinst = NULL; // DLL handle

HWnd GamehWnd; // Game handle

Handle hthread = NULL; // thread handle

HWND WGHANDLE = NULL; // plug-in window handle

Handle gamehandle; // Game window handle, forgot to use

Hinstance GameInstance; // Game, I don't know if I use it.

DWORD THREADID; // Thread ID

LResult Callback KeyboardHook (int Ncode, WParam WParam, LParam Lparam); / / Keyboard HOOK

Extern "C" __declspec (dllexport) BOOL ENABLEHOK (DWORD DWTHREADID); // Start the Hook function

Extern "C" __DECLSPEC (DLLEXPORT) BOOL Disablehook (); // Uninstall the Hook function, and the above function can be controlled externally

DWORD WINAPI THREAD1 (PVOID PARAM); // Thread function, in this function, the plug-in window Int WinAPI DLLENTRYPOINT (Hinstance Hinst, Unsigned Long Reason, Void * LPreserved)

{

Dllhinst = hinst; // Load DLL

Return 1;

}

Extern "C" __DECLSPEC (DLLEXPORT) BOOL ENABLEHOOK (DWORD DWTHREADID)

// Export function enablehook ()

{

IF (g_hhook == null)

/ / Install a new hook

{

g_hook = setwindowshookex (wh_keyboard, (hookproc) Keyboardhook, Dllhinst,

DWTHREADID; / * Remember the parameters in CreateProcess? The parameters we pass are the main thread ID of the target program, indicating that we started the thread hook, not a global hook, which will not have any impact on other programs * /

}

IF (g_hhook)

{

Return True;

}

Return False;

}

Extern "C" __DECLSPEC (DLLEXPORT) BOOL Disablehook () // Export Function Disablehook ()

{

/ * Uninstall hook, now temporarily first this, in fact, if you want to do it, you need to do a lot. If you close the client directly, this is enough, this function does not use anything, Here is just to explain that the outside can actively control plug-in start and shutdown.

IF (g_hhook! = NULL)

{

UnHookWindowsHookex (g_hhook);

g_hook = null; // Remove the new hook

Return True;

}

Return False;

}

LResult Callback KeyboardHook (int Ncode, WPARAM WPARAM, LPARAM LPARAM)

{

IF (ncode> = 0)

{

If (wparam == 123) // 123 is the key code of F12, you can view the MSDN or Windows API reference book, you can write a small program test.

{

IF (hthread == null) // This makes sure the thread starts once, not multiple times, every startup is back to the plug-in window

{

hthread = CreateThread (NULL, 0, Thread1, Null, Null, & ThreadID); // Start thread, the thread is quickly executed

}

}

}

Return (CallNexthooKex (G_HHHHOOK, NCODE, WPARAM, LPARAM)); // The rest of the target program

}

The function in the DLL is the core of the plug-in. After the thread starts successfully, you can uninstall hook, here is just for easy, so keep hook remains.

When programming in CB, it is best to save the file name of the program to the name you want, don't use the default name, the default name is Unit digit, not the class name, this is I don't like CB One reason, the other reason is that there is no full-screen expert interface. When writing code, the third reason is that the code can be written in any place, my code has no specific style, often cause inexplicable mistakes. . It is very fast because it is very fast because it develops it with it, and it is convenient, more convenient than in VC. After the nonsense, you can add a view of the plug-in window. Select New Form in the New menu. If you want new other words, I don't object, can I get the right result I don't know.

There are many people on the Internet to ask how to play out the window in the game, I have answered a bit impatient. It is the most convenient thing to do in CB, but you have to set the properties of the control, because I am not familiar with the use of VCs, more, I am directly using the API to write (I don't learn MFC ), So I can only say sorry for friends who like VC.

The property setting for the new form is the most important, otherwise inexplicably errors and results make people become nerve. Here is some summary of my formality in the DLL. If you have other things that you don't understand, you can give me E-mail or MSN or QQ.

1. The Visible property must be false, otherwise the form has no way to move

2, the FormStyle property is best for fsnormal, but must not be fsmdichild or fsmdiform, which will cause inexplicably errors.

3. If you can't play it, let's change the BorderStyle property to BSDIALOG. I have to overload the TForm function in the tutorial, so this is not very clear for BSDIALOG, after all, I have a very early code.

Other attention seems to have nothing. The following is the Thread1 function implementation in the CreateThread call:

DWORD WINAPI THREAD1 (PVOID param)

{

TWGHOKFORM * WGHOOKFORM;

WGHOOKFORM = New TWGHOKFORM (NULL);

WGHANDLE = WGHOKFORM-> HANDLE;

/ * Temporarily put the following send message, I need a form to make a part of the necessary actions after the form is created, so the mechanism for sending messages is coming, it is not necessary to do this, when I start writing, The content in the APIHOK is made through the MersSage. Here is to make it through Message, it is a historical reason. * /

SendMessage (WGHANDLE, WM_USER 2, NULL, NULL);

WGHOOKFORM-> ShowModal ();

Delete WGHOOKFORM;

Return 1;

}

In the game, you should be able to play out the window in the game. Our first step is done, the platform of the plug-in program is complete, and the rest is the preparation of the tool's production and the necessary code. In the next section I am going to talk about the APIHOK method.

转载请注明原文地址:https://www.9cbs.com/read-100876.html

New Post(0)