Click here to Skip to main content
15,896,207 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.5K   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.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.CodeDom.Compiler;

namespace NdisMonitor
{
	/// <summary>
	/// Summary description for ErrorsWindow.
	/// </summary>
	public class ErrorsWindow : System.Windows.Forms.Form
	{
		private System.Windows.Forms.StatusBar ctrlStatusBar;
		private System.Windows.Forms.ListView ctrlList;
		private System.Windows.Forms.ColumnHeader chIsError;
		private System.Windows.Forms.ColumnHeader chPosInSource;
		private System.Windows.Forms.ColumnHeader chMessage;
		private System.Windows.Forms.ImageList ilListViewImages;
		private System.ComponentModel.IContainer components;

		public ErrorsWindow( CompilerResults res, CodeWindow caller )
		{
			_res = res;
			_caller = caller;

			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after 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 );
		}

		#region Windows Form 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.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ErrorsWindow));
			this.ctrlStatusBar = new System.Windows.Forms.StatusBar();
			this.ctrlList = new System.Windows.Forms.ListView();
			this.chIsError = new System.Windows.Forms.ColumnHeader();
			this.chPosInSource = new System.Windows.Forms.ColumnHeader();
			this.chMessage = new System.Windows.Forms.ColumnHeader();
			this.ilListViewImages = new System.Windows.Forms.ImageList(this.components);
			this.SuspendLayout();
			// 
			// ctrlStatusBar
			// 
			this.ctrlStatusBar.Location = new System.Drawing.Point(0, 251);
			this.ctrlStatusBar.Name = "ctrlStatusBar";
			this.ctrlStatusBar.Size = new System.Drawing.Size(488, 22);
			this.ctrlStatusBar.TabIndex = 1;
			// 
			// ctrlList
			// 
			this.ctrlList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																					   this.chIsError,
																					   this.chPosInSource,
																					   this.chMessage});
			this.ctrlList.Dock = System.Windows.Forms.DockStyle.Fill;
			this.ctrlList.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.ctrlList.FullRowSelect = true;
			this.ctrlList.GridLines = true;
			this.ctrlList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
			this.ctrlList.HideSelection = false;
			this.ctrlList.Location = new System.Drawing.Point(0, 0);
			this.ctrlList.MultiSelect = false;
			this.ctrlList.Name = "ctrlList";
			this.ctrlList.Scrollable = false;
			this.ctrlList.Size = new System.Drawing.Size(488, 251);
			this.ctrlList.SmallImageList = this.ilListViewImages;
			this.ctrlList.TabIndex = 2;
			this.ctrlList.View = System.Windows.Forms.View.Details;
			this.ctrlList.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ctrlList_KeyDown);
			this.ctrlList.DoubleClick += new System.EventHandler(this.ctrlList_DoubleClick);
			// 
			// chIsError
			// 
			this.chIsError.Width = 18;
			// 
			// chPosInSource
			// 
			this.chPosInSource.Width = 100;
			// 
			// chMessage
			// 
			this.chMessage.Width = 500;
			// 
			// ilListViewImages
			// 
			this.ilListViewImages.ImageSize = new System.Drawing.Size(16, 16);
			this.ilListViewImages.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilListViewImages.ImageStream")));
			this.ilListViewImages.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// ErrorsWindow
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(488, 273);
			this.Controls.Add(this.ctrlList);
			this.Controls.Add(this.ctrlStatusBar);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "ErrorsWindow";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Compiler Results";
			this.Load += new System.EventHandler(this.ErrorsWindow_Load);
			this.ResumeLayout(false);

		}
		#endregion

		//
		// data.
		//

		CompilerResults			_res = null;
		CodeWindow				_caller = null;

		private void ErrorsWindow_Load(object sender, System.EventArgs e)
		{
			if ( _res != null )
			{
				// calc num of errs and wrns.

				int		errNum = ( _res.Errors == null ) ? 0 : _res.Errors.Count;
				int		wrnNum = 0;

				if ( errNum != 0 )
					foreach( CompilerError err in _res.Errors )
						if ( err.IsWarning )
						{
							errNum --;
							wrnNum ++;
						}

				// set status text.

				ctrlStatusBar.Text = errNum.ToString() + " error(s), " + wrnNum.ToString() + " warning(s). Double-click on error to edit code.";

				// populate list view.

				if ( errNum != 0 )
					foreach( CompilerError err in _res.Errors )
						if ( err.IsWarning == false )
						{
							string[]			items = new string[ 3 ];
							items[ 0 ] = "";
							items[ 1 ] = "Ln " + err.Line.ToString () + ", Col " + err.Column.ToString ();
							items[ 2 ] = err.ErrorText;
							ListViewItem		lvi = new ListViewItem( items, 0 );
							lvi.Tag = err;
							ctrlList.Items.Add( lvi );
						}

				if ( wrnNum != 0 )
					foreach( CompilerError err in _res.Errors )
						if ( err.IsWarning == true )
						{
							string[]			items = new string[ 3 ];
							items[ 0 ] = "";
							items[ 1 ] = "Ln " + err.Line.ToString () + ", Col " + err.Column.ToString ();
							items[ 2 ] = err.ErrorText;
							ListViewItem		lvi = new ListViewItem( items );
							lvi.Tag = err;
							ctrlList.Items.Add( lvi );
						}
			}
		}

		protected void GoToLine ()
		{
			if ( ctrlList.SelectedItems != null && ctrlList.SelectedItems.Count == 1 )
			{
				CompilerError		sel = (CompilerError) ctrlList.SelectedItems[ 0 ].Tag;
				_caller.GoToLine( sel );
				_caller.Activate ();
			}
		}

		private void ctrlList_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if ( e.KeyCode == Keys.Escape )
				_caller.Activate ();
			else if ( e.KeyCode == Keys.Enter )
				GoToLine ();
		}

		private void ctrlList_DoubleClick(object sender, System.EventArgs e)
		{
			GoToLine ();
		}
	}
}

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