Click here to Skip to main content
12,073,325 members (77,876 online)
Click here to Skip to main content
Articles » Languages » C# » Memory Management » Downloads

Stats

221K views
12K downloads
154 bookmarked
Posted

How to write a Memory Scanner using C#

, 23 Sep 2006 CPOL
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;
using System.Diagnostics;

namespace MemoryScanner
{
    public partial class ProcessWindow : Form
    {
        public ProcessWindow()
        {
            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.ProcessImage;
            int distance = (this.Height - terminalBitmap.Height) / 2;
            Rectangle imageRectangel = new Rectangle((distance / 2), distance, terminalBitmap.Width, terminalBitmap.Height);
            graphic.DrawImage(terminalBitmap, imageRectangel);
            Pen pen = new Pen(Brushes.White, 4);
            graphic.DrawRectangle(pen, rectangle);
            this.BackgroundImage = (Image)bitmap;
            #endregion
        }

        Process[] tempProcesses;
        int[] IDsList;

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

        private void WriteTheList()
        {
            listBox.Items.Clear();
            tempProcesses = Process.GetProcesses();
            IDsList = new int[tempProcesses.Length];
            int i = 0;
            foreach (Process pro in tempProcesses)
            {
                if (pro.MainWindowTitle != "")
                {
                    listBox.Items.Add(pro.ProcessName + " - (" + pro.MainWindowTitle + ")");
                    IDsList[i] = pro.Id;
                    i++;
                }
                else
                {
                    listBox.Items.Add(pro.ProcessName);
                    IDsList[i] = pro.Id;
                    i++;
                }
            }
        }

        private void refreshButton_Click(object sender, EventArgs e)
        {
            WriteTheList();
        }

        private void ProcessWindow_Load(object sender, EventArgs e)
        {
            WriteTheList();
        }

        private void nextButton_Click(object sender, EventArgs e)
        {
            if (listBox.SelectedIndex != -1)
            {
                WholeMemoryScan whole = new WholeMemoryScan();
                whole.process = Process.GetProcessById(IDsList[listBox.SelectedIndex]);
                whole.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("No process is selected.", "Selection error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
    }
}

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)

Share

About the Author

Rojan Gh.
CEO
Sweden Sweden
MVC/SPA designer and programmer.
C# programmer on .net/mono/monomac/monotouch/monodroid frameworks.
jQuery/Knockout/Angular programmer.
And has been working since 2002.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160208.1 | Last Updated 23 Sep 2006
Article Copyright 2006 by Rojan Gh.
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid