Click here to Skip to main content
15,894,410 members
Articles / Desktop Programming / Windows Forms

NDIS MONITOR .NET 32-bit v1.00

Rate me:
Please Sign up or sign in to vote.
4.81/5 (36 votes)
27 Apr 20078 min read 176.4K   9.9K   90  
NDIS Monitor allows to catch and log the exchange of packet data between NDIS miniport drivers and network protocol modules that occurs in kernel space.
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using NdisMonitor;

namespace NmExampleExtension
{
	/// <summary>
	/// Summary description for NmExampleExtension.
	/// </summary>
	[ Extension( "User Example" ) ]
	public class NmExampleExtension : System.Windows.Forms.UserControl, INmExtension
	{
		private System.Windows.Forms.TextBox ctrlExample;
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public NmExampleExtension()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitializeComponent call

		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		//
		// ### INmExtension implementation ###
		//

			// called when a new packet arrives.
		public bool ProcessNextPacket( RawPacket rp, NdisHookStubs.NEXT_PACKET np, int ord, DateTime tm )
		{
			ctrlExample.AppendText( "New packet arrived: " + rp._data.Length.ToString() + " byte(s) long.\r\n" );
			ctrlExample.SelectionStart = 0x7fffffff;

			return true; // the extension processed the packet.
		}

			// called when NDIS Monitor is about to display the extension.
		public void Showing ( LogFn logFn, NdisHookStubs.NT_PROTOCOL_LIST protList, MenuItem popupMenu )
		{
			ctrlExample.AppendText( "- showing -\r\n" );
			ctrlExample.SelectionStart = 0x7fffffff;
		}

			// called when NDIS Monitor is hiding this extension.
		public void Hiding ()
		{
			ctrlExample.AppendText( "- hiding -\r\n" );
			ctrlExample.SelectionStart = 0x7fffffff;
		}

			// called when the user requests to delete all the packets.
		public void DeleteAllPackets ()
		{
			ctrlExample.AppendText( "- delete all packets -\r\n" );
			ctrlExample.SelectionStart = 0x7fffffff;
		}

			// called when user presses the STOP button. We should free here ANY resource allocated.
		public new void Disposing ()
		{
			ctrlExample.AppendText( "- disposing -\r\n" );
			ctrlExample.SelectionStart = 0x7fffffff;
		}

			// called when a new command is entered in the OUTPUT window.
		public bool UserCommand( string s )
		{
			ctrlExample.AppendText( "- user command: \"" + s + "\".\r\n" );
			ctrlExample.SelectionStart = 0x7fffffff;

			return false; // the extension refused to process the command.
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.ctrlExample = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// ctrlExample
			// 
			this.ctrlExample.Dock = System.Windows.Forms.DockStyle.Fill;
			this.ctrlExample.Location = new System.Drawing.Point(0, 0);
			this.ctrlExample.Multiline = true;
			this.ctrlExample.Name = "ctrlExample";
			this.ctrlExample.ReadOnly = true;
			this.ctrlExample.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.ctrlExample.Size = new System.Drawing.Size(150, 150);
			this.ctrlExample.TabIndex = 0;
			this.ctrlExample.Text = "";
			// 
			// NmExampleExtension
			// 
			this.Controls.Add(this.ctrlExample);
			this.Name = "NmExampleExtension";
			this.ResumeLayout(false);

		}
		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Italy Italy
Vito is a former videogame programmer. Now, Vito is the founder and CEO of VPC Technologies, a company that specializes in online services. VPC Technologies also provides consulting, developing and training services to several italian companies and government agencies in the field of kernel, component, enterprise and tridimensional software, for the Microsoft Windows platform.

Vito has attended as a speaker several italian conferences and events on development and security, such as the Microsoft Security Roadshow 2006.

Vito is the man behind GoToTerminal, a secure, reliable and innovative web technology to control remote Microsoft Windows, Telnet and VNC servers over the internet. He is also the author of BugChecker, an independent research project to create the only clone of SoftICE to date, NDIS Monitor, MapGen and Image Downloader.

For more information, you can visit Vito Plantamura's technical website at www.VitoPlantamura.com.

Comments and Discussions