Create a plug-in for source insight -- discover source insight

Source: Internet
Author: User

Author: Orbit)
E_mail: inte2000@163.com

When it comes to plug-ins, everyone is certainly familiar with it. QQ has many versions of plug-ins for advertising, and many games also have tools for scaling functions or cheating, many of them are provided in other forms. The difference between plug-ins and plug-ins is that plug-ins usually rely on program support. If the program does not support the plug-in mechanism, plug-ins cannot be developed for it, But plug-ins do not, it does not rely on the functions of the program itself. Generally, it is a separate program. The method of "hanging" other programs is to inject cross-Process Code. If all the software in this world is open-source, and there are not so many license restrictions, hackers can freely modify the code to release new features, then there will be no plug-ins. It is very troublesome to plug-in other programs. Not all programs can "tolerate" code injected from outside, especially some programs with internal defects, the function injected according to the normal Windows operating mechanism usually cannot achieve the expected effect, or even cause the program to be unavailable, so if there is no other way, no one will take the initiative to use plug-ins to expand a program.

Although you don't want to, there are still some programs that can only be extended through plug-ins. The program mentioned in this article has to be hung up is the famous source code browser tool: Source insight. Source insight is a... [The number of introductory characters (excluding spaces) is omitted here, which is 1028 for non-Chinese words, 126 for Chinese characters or 819 for Korean Words]. I have been using VC for a long time and may be spoiled by the "tabbar" plug-in of VC. Therefore, I feel very uncomfortable when I use an editor that cannot switch files through file tags, unfortunately, "Source insight" is like this. After using "Source insight" for a while, I began to look for ways to add a file tag bar to it. "Source insight" is powerful and can be expanded through custom commands, it even supports a macro language similar to the C language syntax. However, after some research, I have come to the conclusion that the "source insight" interface can only be expanded through plug-ins, add a tab for file switching.

As mentioned above, not all programs can "tolerate" external injection code. The reason why I think "Source insight" can be hung up, because "Source insight" uses a standard Windows MDI (Multi-Document Interface) window, the message flow before the window is simple and follows the Windows Standard mechanism. So a month later, tabsiplus, the file tag plug-in of "Source insight", was born. It has accumulated some experience in studying "Source insight" and compiling "tabsiplus, if you leave them in your mind, you will only forget them slowly. Now you can organize them into words and share them with everyone.

First, we will introduce "tabsiplus". Its main function is to add a file switch label bar for "Source insight, this switching label bar is of great help to those who use "Source insight" to write code. First, let's take a look at some of the changes it has brought to "Source insight:

In the code window, a file label bar is added, and the menu is also changed. Several icons are added. In fact, the background color and text color of the menu can be changed, the color of the file label bar can also be changed. Let's see:

In addition, the C/C ++ file flip function has been added, which is a common function of VA. I believe everyone is familiar with it, the C/C ++ file flip function inherits the multi-directory and multi-extension search functions of the "tabbar for Visual C ++" plug-in:

From now on, I have introduced how tabsiplus is developed step by step through a series of articles, including the research process of "Source insight, this article describes how to find "Source insight ". This is a very important issue. If you cannot find the running "Source insight" in the system, the plug-in will not be suspended. Find the "source Pipeline" running in the system and obtain the handle of the process. You can also find the main window with the "source insight" flag through window enumeration and obtain the handle of the main window. Of course there are other methods. We will not introduce them here. "tabsiplus" uses the window enumeration method, because the Class Name of the Main Window of "Source insight" is fixed and the title bar text is regular, "Source insight" is available in all circumstances to facilitate matching. The main reason is that the window enumeration method is simple.

Use the spy ++ tool to study the main window of "Source insight" and find that the class name of the window is "si_frame". This is a good sign. If the class name of a window is similar to "afx: 400000: 0: 10011: 10: 0 "is troublesome. This is a typical name of the main framework window class of MFC. The numbers in it are process addresses, window icon handles, the mouse cursor handle is formatted as a string, which is variable. It is a result on a system and may be another result on another system. Let's take a look at the title Text of the "source insight" Main Window and find that there is a "Source insight" substring in whatever situation, this can help us determine whether the window is the "source insight" Main Window. The enumwindows () API is used in the enumeration window. This API uses a callback function. The following is a prototype of the callback function:

Bool callback enumwindowsproc (hwnd, lparam)

The following is the implementation of the enumwindowsproc () callback function in "tabsiplus:
Bool callback enumwindowsproc (hwnd, lparam)
{
Bool bsuccess = true;
If (hwnd! = NULL & issourceinsightframewnd (hwnd ))
{
If (lparam)
{
Hwnd * phwnd = (hwnd *) lparam;
* Phwnd = hwnd;
Bsuccess = false; // a source insight window has been found. Exit enumeration.
}
}

Return bsuccess;
}
This function uses the lparam parameter to pass the window handle. It processes only one "Source insight" window at a time. If multiple "Source insight" windows are running in the system, there will be multiple "Source insight" main windows, which are driven by external mechanisms to enumerate multiple times to ensure that all "Source insight" is processed. You may have already seen the problem that has been found again. Yes, it is. However, "tabsiplus" uses a clever method to solve the problem. "Tabsiplus" adds a "with tabsiplus" sign in the title bar of the window after hook a "Source insight" window, so that you can identify whether the window has been processed. The following is the issourceinsightframewnd () function of the "source insight" window:

Lpctstr lpszsourceinsight = _ T ("Source insight ");
Lpctstr lpszsiframewndclass = _ T ("si_frame ");
Lpctstr lpsztextmark = _ T ("with tabsiplus ");

Bool issourceinsightframewnd (hwnd)
{
Tchar szclassname [128], sztitle [256];
 
Int nrtn = getclassname (hwnd, szclassname, 128 );
If (nrtn = 0)
Return false;

Nrtn = getwindowtext (hwnd, sztitle, 256 );
If (nrtn = 0)
Return false;

// The class name is si_frame, and the window title contains source insight. It can be basically determined to be a source insignt window.
If (lstrcmp (lpszsiframewndclass, szclassname) = 0) & (strstr (sztitle, lpszsourceinsight )! = NULL ))
{
If (strstr (sztitle, lpsztextmark )! = NULL) // if this mark exists, it indicates that it has been hooked. Do not harass the source insignt window any more.
Return false;

Return true;
}

Return false;
}

The following is a scheduling function in the "source insight" window. You can call the scheduling function once each time to find a "Source insight" that has not been hooked up ":
Hwnd findsourceinsightframewindow ()
{
Hwnd hsifrmwnd = NULL;
 
Bool brtn =: enumwindows (enumwindowsproc, (lparam) & hsifrmwnd );
If (! Brtn & hsifrmwnd! = NULL)
Return hsifrmwnd;
Else
Return NULL;
}

Finally, find the "source insight" window and mount the specified dynamic Connection Library to the function in the "source insight" process:
// One attempt to find and hook a source insighe window
Bool findandhooksourceinsightwindow (lpctstr lpszhookdll)
{
Bool bsuccess = false;
If (lpszhookdll)
{
Hwnd hsifrmwnd = findsourceinsightframewindow ();
If (hsifrmwnd! = NULL)
{
Bsuccess = hooksourceinsightwindow (hsifrmwnd, lpszhookdll );
}
}
Return bsuccess;
}
This function calls an important function: hooksourceinsightwindow (), which injects our code into the "source insight" process, which involves many details about remote code injection, the code injection method will be introduced in the next article "Create a plug-in Series 2 for source insight -- inject local code into the source insight process". This article ends here.

Source insignt file tag plug-in: tabsiplus:
Click to download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.