Click here to Skip to main content
15,888,984 members
Articles / Programming Languages / MSIL

Building Security Awareness in .NET Assemblies : Part 1 - Learn to break a .NET Assembly

Rate me:
Please Sign up or sign in to vote.
4.53/5 (54 votes)
31 Oct 20045 min read 183.8K   2.3K   122  
Building Security Awareness in .NET Assemblies : Part 1 of 3
////////////////////////////////////////////////////////////////////////////
/// Building Security Awareness in .Net Assemblies 
/// Part 1
/// CrackingIL.sln
/// Developed by: Chua Wen Ching
/// Email me: chuawenching@necoders.com
/// Visit us: http://www.necoders.com
////////////////////////////////////////////////////////////////////////////

using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Windows.Forms;

// need this to call the RegistryKey
using Microsoft.Win32;

[assembly: IsolatedStorageFilePermission(SecurityAction.RequestMinimum, UserQuota=1048576)]
namespace CrackingIL
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class FrmSecureApp : Form
	{
		private Label lblHeader;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private Container components = null;

		public FrmSecureApp()
		{
			//
			// 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.lblHeader = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// lblHeader
			// 
			this.lblHeader.Font = new System.Drawing.Font("Arial", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblHeader.Location = new System.Drawing.Point(24, 16);
			this.lblHeader.Name = "lblHeader";
			this.lblHeader.Size = new System.Drawing.Size(216, 136);
			this.lblHeader.TabIndex = 0;
			this.lblHeader.Text = "Welcome To NeCoders";
			// 
			// FrmSecureApp
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 173);
			this.Controls.Add(this.lblHeader);
			this.Name = "FrmSecureApp";
			this.Text = "Secure App v1.0";
			this.Load += new System.EventHandler(this.FrmSecureApp_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new FrmSecureApp());
		}

		/// <summary>
		/// Verifies the registry to make sure the serial number is in there
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void FrmSecureApp_Load(object sender, EventArgs e)
		{
			RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Necoders");

			if (key == null)
			{
				MessageBox.Show("Please acquire a license to run this!");
				this.Dispose(true);				
			}
			else
			{
				string validSerial = "1111-1111-1111-1111";

				if ((string)key.GetValue("serial") == validSerial)
				{
					return;
				}
				else if (key.GetValue("serial") == null)
				{
					MessageBox.Show("Please acquire a license to run this!");
					this.Dispose(true);
				}
				else
				{
					MessageBox.Show("Wrong serial number");
					this.Dispose(true);
				}
			}
		}
	}
}

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
Software Developer
Malaysia Malaysia
I am Chua Wen Ching and it is great to be part of CodeProject network Smile | :)

Comments and Discussions