Myspy development

zhaozj2021-02-16  54

Write -Aweay

Recently, the author wrote a small software in 20 days, published in the 9CBS BCB Forum and ChinaBCB, got everyone's support, and many friends asked if the source code can be disclosed, the author is not a conservative person, which is open before. Your own game source code, but later this game was stolen by others, but also when he shared software charges, I was very angry, I also had lessons, this author will not open source code in the short term, but facing So many netizens support, the author believes that there is a responsibility to write some things to help the majority of BCBER enthusiasts will make progress together, so they have written this development, I hope to have a certain help for beginners. If you are a master, when I am going to the ax. .

If you haven't seen MySpy yet, you can download from http://www.chinabcb.com/bbs/viewtopic.php?t=6445, this address needs you to register to log in to see the download address, otherwise only introduction.

The author does not intend to introduce the entire development process, and ask the most questions to ask questions:

1. How do I save the icon as a true color icon?

In fact, this is a problem, but it is a problem that is very difficult in BCB and Delphi. I don't know if you know that BCB and Delphi's Ticon class saved only 16 colors, so that it is 256 colors. Or the true colorful icon can only display 16 colors, such a save result is not, the author once wanted to give up the function of saving the icon, but finally did not do this, how did the author solves?

First, the author thought of the Internet, since I have such a problem, then there are certain people in the world who have encountered such problems. Google should find other people to solve the problem, the author spent an afternoon time, in each Big Delphi site, FAQ, the control area did not find the right solution, and finally found a Ticonex in a Japanese web battle. From a few known Chinese, I guess this thing is just what I want, I immediately The express train was opened, and it was a pity that there was no source code. The Japanese truth TMD hate, with an unlimited anger of the Japanese, I threw that Ticonex into the trash.

It seems that the stone of his mountain can't be used, then the author has to find a solution from the bottom layer, from this address http://www.9cbs.net/dev/format/, the author found Icon's file format and one The example code written by Microsoft Engineer, the author used this ICON format and engineer's code in the evening. After understanding, the author decided to pack him with BCB, because the original code is written in C language, and the author is an OO hobby So the author decides to type him then adds the code from HiCon to save the file (originally only saved from the module).

The code is finished, but it is really not easy to use the BCB, but this is not a technical problem. If you are interested, try it, right, the article introduces the ICON format is English, if the author Have time, it will translate him into Chinese, the article writes quite good.

2. How to hook?

Hook is using the most technique in MySPY. From the message to the interception system, the message is hook technology. It can be said that this technology is no technical. Online casual program sites can find relevant introduction information, but intercept system messages It is still more trouble, the author introduces it.

Intercept system message is nothing more than installing system hooks wh_callwndproc, wh_callwndprocret and wh_getMallWndProcret and wh_getMallWndProcret, why do you have so much installation, because system messages have many different types, SEND, POST also handles messages return, of course, if you also have the system menu Interested, you also need to install the Wh_sysmsgfilter hook, because this is a system-wide hook, so you must write a DLL, and the core code is just: LResult Callback MsghookProc1 (int Ncode, WParam WParam, LParam Lparam)

{

IF (ncode> = 0)

{

CWPSTRUCT * mm = (cwpstruct *) lparam;

Msgdata Data;

Data.msg = mm-> message;

Data.wparam = (int) mm-> wparam;

Data.lparam = (int) mm-> lparam;

Data.Type = 1;

Data.Result = 0;

CopyDataStruct CopyData;

CopyData.dwdata = 0;

CopyData.cbdata = sizeof (msgdata);

CopyData.lpdata = & data;

IF (mm-> hwnd == hookstruct-> hootedwnd)

{

SendMessage (Hookstruct-> PARENTWND, WM_COPYDATA, 0, (LPARAM) & CopyData);

}

}

Return (CallNexThookex (Hookstruct-> Msghook1, Ncode, WPARAM, LPARAM);

}

It can be seen that the author uses WM_COPYDATA to send a notification message to MySPY, which is one of the HOOK callback functions, and other similar. After myspy receives the WM_CopyData message, the LPARAM parameter will be converted into MSGData, and this structure encapsulates that all useful information about the message is waiting for MySPY processing. Hook is actually very simple, it is to debug trouble, during the debugging process, at least 10 more times, if you use the Win9x system, you may be able to die.

At this point you may think that the ability to write a intercept message is completed, if you pay attention to MySPY, and you will know about Win32API, you will find that the message we get is an integer ID, and we can't show only ID, we need WM_XXX's friendly representation, but there is no function to convert an integer ID into a friendly string, how can I solve? The author finally used a record file, the file format is as follows:

0x0000 WM_NULL

0x0001 WM_CREATE

0x0002 WM_DESTROY

0x0003 WM_MOVE

0x0005 WM_SIZE

0x0006 WM_Activate

......

With this file, look up the corresponding friendly string is simple, and the extended record file is very easy, you can join the corresponding string of your known ID. The key is to find efficiency, this is not difficult, and quickly find it quickly after sorting. To now, the author doesn't know if my solution is the best, please advise?

3. How do I get the element on the webpage and achieve his information?

This problem is still difficult, especially for people who don't understand COM, this problem is even more difficult. Want to operate HTML first to get the IHTMLDocument2 interface, this interface is IE4.0 to provide a COM object that is used to specifically interact with HTML. If we use ASP or JavaScript to operate HTML, it is very simple, of course, it is also possible to get the elements in the web page Very simple, and use BCB development tools to operate HTML, no Microsoft's help I am not good (at least the author doesn't know), and Microsoft does provide this support. This support is Oleacc.dll.

This DLL has a lot of functions, one is to get the interface of the COM object from HWND, what is the code?

CComptr spaccess;

HR = AccessibleObjectFromWindow (hwnd, 0, iid_iaccessible, (void **) & spaccess);

En (ac))

{

CComptr spserviceProv;

HR = spaccess-> queryinterface (IID_IServiceProvider, (void **) & spserviceProv);

IF (hr == s_ok)

{

CComptr spwin;

HR = SPSERVICEPROV-> QueryService (IID_IHTMLWindow2, IID_IHTMLWindow2, (void **) & spwin);

IF (hr == s_ok)

Spwin-> get_document (& PDOC2);

}

}

The above is the core code of the IHTMLDocument2 interface from HWND. Of course, you need to join the Oleacc.h and Oleacc.lib files. After getting the IHTMLDocument2 interface, we use the same power to make HTML with the same ASP, about how to operate HTML. Don't talk, friends with ASP know, I want to understand it.

The key function here is the AccessibleObjectFromWindow exported by oleacc.dll. This function will look at the name, and the description of MSDN is as follows:

Retrieves The Address of the specified interface to the object associated with the given window.

So this function can get the IHTMLDocument2 interface, you can also get an Office and other interfaces. Interested can try it.

4. How to write plugins?

MySPY supports plugin, and it is easy for MySPY development plugins. Of course, this is mainly based on reasonable design and complete development documents (everyone don't smash me :)), write plugins should not be Myspy's feature, or something is absolutely nothing Core technology, but since myspy wrote, someone asked, I will introduce how to develop plugins.

When starting the design of the plug-in structure, the author is inserting the intersection of the COM plug or the ordinary DLL, using COM will easily write code, which is easy to understand, and most software now use COM as a plugin, but The biggest problem with COM is to greatly increase the body bloatingness of MySPY and increase the development time of MySPY because the author needs to write a DLL to encapsulate the entire myspy, then expose the interface, so that there will be nearly 1 times extra fat, This is the author's unacceptable, and it is to write the COM plug-in to the developer's requirements too high; there are many ways to use the DLL to do plug-ins, it is to deport several functions to be responsible for several functions or deport 1-2 functions to generalize design ? Also, do you want to plug-in with mySPY interaction? Is there two-way data access? Several messages give the plugin to notify the plugin to do something, the plugin can also send a message to myspy to control myspy, and developers only need to handle the corresponding message and return the necessary value, the rest is completed by MySpy, such a solution does not need Additional DLL, sends an appropriate message to the plugin in the appropriate location within the MySPY code, and then processes the return value. Let's take a look at the format of the export function:

Extern "c" __declspec (dllexport)

INT MMPLUGIN (MMSG MSG, MParam WParam, MParam Lparam)

{

Switch (msg)

{

Case mm_init:

// Place Your Init Code Here

Break;

Case MM_DESTROY:

// Place Your Destroy Code Here

Break;

...

}

}

You can see this export function, very like WndProc functions, inspiration in the author is completely stem from the smarter of the Windows message mechanism, and a integer MPARAM parameter can pass any type, any size data, the author really admires Windows news Mechanism, I don't know what kind of good ways, everyone will discuss it.

The key technologies to this myspy have been all described. You may also see that the author is not a point for all the technical introduction, and it is not discussed very detailed. This is not the author is not willing to give the source code, but there is no need. In the author's way to solve the problem, if everyone is interested, try itself, like a three-20 days like the author, definitely gain.

The author is very welcome to let me let me discuss Siney@yeah.net.

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

New Post(0)