Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C#

How to write a Memory Scanner using C#

Rate me:
Please Sign up or sign in to vote.
4.86/5 (67 votes)
23 Sep 2006CPOL8 min read 347.7K   16K   164  
Search a process' memory to find specified 16, 32 or 64 bit data values.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

namespace MemoryScanner
{
    public partial class SplashWindow : Form
    {
        public SplashWindow()
        {
            InitializeComponent();
            #region User Interface
            Bitmap bitmap = new Bitmap(this.Width, this.Height);
            Graphics graphic = Graphics.FromImage(bitmap);
            graphic.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle rectangle = new Rectangle(0, 0, this.Width, this.Height);
            LinearGradientBrush brush = new LinearGradientBrush(rectangle, Color.LightSteelBlue, Color.SteelBlue, 90, true);
            graphic.FillRectangle(brush, rectangle);
            Bitmap terminalBitmap = global::MemoryScanner.Properties.Resources.Splash;
            int distance = (this.Height - terminalBitmap.Height) / 2;
            Rectangle imageRectangel = new Rectangle((distance / 2), distance, terminalBitmap.Width, terminalBitmap.Height);
            graphic.DrawImage(terminalBitmap, imageRectangel);
            int textRectangleWidth = this.Width - (imageRectangel.Width + distance + (distance / 2));
            Rectangle textsRectangle = new Rectangle(imageRectangel.Right + (distance / 2), distance, textRectangleWidth, imageRectangel.Height);
            Rectangle sojanerRectangle = new Rectangle(textsRectangle.Left, textsRectangle.Top, textsRectangle.Width, (textsRectangle.Height / 2));
            Rectangle scannerRectangle = new Rectangle(textsRectangle.Left, sojanerRectangle.Bottom, textsRectangle.Width, (textsRectangle.Height / 2));
            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;
            graphic.DrawString("Sojaner", new Font("Verdana", 40f), Brushes.White, (RectangleF)sojanerRectangle, format);
            SizeF lineSize = graphic.MeasureString("Sojaner", new Font("Verdana", 40f));
            int firstPoint = ((sojanerRectangle.Width - (int)lineSize.Width) / 2) + sojanerRectangle.Left;
            int secondPoint = firstPoint + (int)lineSize.Width;
            Pen linePen = new Pen(Brushes.Orange, 3);
            graphic.DrawLine(linePen, firstPoint, sojanerRectangle.Bottom, secondPoint, sojanerRectangle.Bottom);
            graphic.DrawString("Memory Scanner", new Font("Verdana", 18f), Brushes.White, (RectangleF)scannerRectangle, format);
            Pen pen = new Pen(Brushes.White, 4);
            graphic.DrawRectangle(pen, rectangle);
            this.BackgroundImage = (Image)bitmap; 
            #endregion
        }

        private void closeButton_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void nextButton_Click(object sender, EventArgs e)
        {
            ProcessWindow process = new ProcessWindow();
            process.Show();
            this.Hide();
        }
    }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Sojaner AB
Sweden Sweden
UX designer and full stack developer mainly focused on .NET technologies.
Currently loving .NET Core 2.0.

Comments and Discussions