Ie technology bho c # IE Plug-in

Source: Internet
Author: User

There are few such articles, especially those of the IE Plug-in type. Most of them are webbrowser, but some of them are reposted on the Internet! Other connections are provided!

Use C # To create an ie bho hook and obtain the form Password

To authorize csdn, please obtain your consent and repost it. Author: Chen Jia, netsecure Inc, Canada, Software Engineer

Microsoft officially exited Browser Helper Object (BHO) in 1997, enabling programmers to perform further development and operations on IE. after several months of writing the BHO program, I hope to tell some of my experiences to my comrades and avoid detours.

I like C ++ very much. because c ++ can directly operate on the memory, it can save a lot of memory loss and make it faster. however, when developing BHO, I realized that C # is much more powerful than C ++. for example, the foreach loop provided by C # can avoid overflow of the for loop. in addition, the type conversion of C # is obviously stronger than that of C ++. after all, BHO and C # are both from the Microsoft family. Of course, C # is more suitable for BHO development. my first BHO program was written in C ++. for the operations on com, it took me at least a few days to figure out what they were trying to do. however, it takes only a few minutes for my first C # BHO program to build a hook. if you want to engage in BHO development, and you want to start learning. I think this article is helpful to you.

This article was originally written in English. Because of the working environment, Chinese characters are getting increasingly unfamiliar. If there are errors or exceptions, refer to the original English document.

Let's start.

First, we need to create a new DLL project in C. BHO is driven by calling DLL by IE. I use V C # Express. this is enough. v c # professional is not required and memory is wasted.

After creating an empty project, add a folder named BHO and add a file.
 

Please note that this file must be named iobjectwithsite. CS so that IE will know that this is a BHO program. If you want to know more about the iobjectwitesite interface, please query the msdn

Http://msdn2.microsoft.com/en-us/library/Aa768220.aspx

In iobjectwithsite, there must be two methods: getsite and setsite. We mainly call the latter. You can guess what they do by name.

Getsite: gets the last site set with iobjectwithsite: setsite. If there is no known site, the object returns a failure code.

Setsite: Provides the site's iunknown pointer to the object.

Remove the default vs stuido class name because iobjectwithsite is not a class but an interface.

 

Do not forget to add system. runtime. interopservices

Next we will add a main file named BHO. CS.

The newly created class is based on the iobjectwithsite interface. As I mentioned earlier, you use this interface to call IE.

To use Microsoft's BHO library, we must add the following two libraries: shdocvw and mshtml. They are generally under windows \ system32.

Shdocvw is Microsoft shell Doc object and control library

Mshtml is: All interfaces for accessing the dynamic HTML (DHTML) object model are based on idispatch and are the basis of access to the object model that is also used by scripts. http://msdn2.microsoft.com/en-us/library/bb498651.aspx

Light Using shdocvw "is not enough, you need to add

Add shdocvw

MessageBox will be used later, so I have added a Windows form library.

The following two variables are added: webbrowser and htmldocument. They are like their names. One is the IE variable, and the other is the HTML page variable accessed by IE.

The following is a function called ondocumentcomplete in this class. it's okay to get other names. but here we call ondocumentcomplete for code availability. this function is actually corresponding to ondocumentcomplete under cdhtmldialog.

Cdhtmldialog class http://msdn2.microsoft.com/en-us/library/8bed8k60 (vs.80). aspx.

Ondocumentcomplete is triggered after an HTML page is loaded. You can also avoid using navigate () or onbeforenavigate (). They indicate triggering before sending access and access.

Please refer to http://msdn2.microsoft.com/en-us/library/8k5z3ekh (vs.80). aspx to find out what you need exactly.

In iobjectwithsite. CS, you need to spend the guid of IE to facilitate registry modification.

In addition, you need to add a guid to your program. in this way, ie can find your information in the registry. you can use system. guid. newguid () method to obtain a guid. this is much easier than the method for C ++ to get the guid.

We must add content to setsite and getsite. In setsite, we need to add an eventhandler so that IE can trigger our ondocumentcomplete function.

Add one more reference

In BHO. CS, we need to add the Register/unregister function for our DLL.

 

Compile, we have our DLL.

The following uses the regasm/codebase "BHO helloworld. dll" command under DOS to register DLL. Why?

Because we forgot to set our main class to public, no one else can call your class. Naturally, we cannot register it.

And then it succeeds.

Open the registry and find Browser Helper Object under LOCAL_MACHINE-> Software-> Microsoft-> Windows-> explorer to see if there is any change?

After registration, we will write our program to control ie. The following is an example to capture the name of all input elements on the page you are visiting.

In document, all our elements are ihtmlelement. We need to call ihtmlinputelement. therefore, we use the getelementbytagname method to find all input elements. after finding the attribute, you still need to perform type conversion to find the corresponding attribute. otherwise, ihtmlelement does not have name attribute. the attribute provided by ihtmlelement is available to all elements. for example, ID, such as title, such as onclick. some elements have their own unique attributes. For example, if input has onfocus, it must be converted to ihtmlinputelement to be used. ihtmlinputelement corresponding to input, select-> ihtmlselectelement .......

 

There you go, see?

Next we will try another method called beforenavigate (). it is triggered before you start the next page. that is to say, if you want to submit a form and the page changes, it will be triggered. in fact, Ms provides two similar interfaces: beforenavigate and beforenavigate2 (). you can check msdn to see what the difference is. we will not talk about it here.

Similarly, we add a corresponding function prototype (click the image to see the big image ).

Add eventhandler

What we want to do below is to intercept the password on the page.

See, how easily, you can get it.

Through the above process. I hope you have a preliminary understanding of BHO. for more information, visit msdn. it provides a very detailed introduction. this also raises a topic. we can see that it takes almost two minutes for us to intercept any content you entered. Do you think IE is safe? Even if he can encrypt the content of the network card through SSL, it is so weak at the application layer. in addition, if we use IE, we will find the flood of add-on, which is caused by BHO.

 

Connection: http://www.hackpig.cn/post/194.html

Recommended series of articles:

C # develop BHO plug-in urltrack http://www.hackpig.cn/post/195.html

Research on Internet Plug-in Technology of reflux technology Part 1 http://www.hackpig.cn/post/196.html

Research on Internet Plug-in Technology of stream technology Part 2 http://www.hackpig.cn/post/197.html

Featured blogger space: http://www.hackpig.cn/

Related Article

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.