Advertisement
User12345678910

Memory Reader in C#

Jan 19th, 2018
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using ProcessMemoryReaderAndWriterlib;
  11. using System.Diagnostics;
  12.  
  13. namespace Test_meomry_pointer
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         ProcessMemoryReaderAndWriter api = new ProcessMemoryReaderAndWriter();
  18.         Process GameProcess = null;
  19.         int pointerMemoryAddr = -1;
  20.         int bytesout;
  21.         int bytesWritten;
  22.         public Form1()
  23.         {
  24.             InitializeComponent();
  25.         }
  26.  
  27.         private void comboBox1_Click(object sender, EventArgs e)
  28.         {
  29.             foreach(var proc in Process.GetProcesses())
  30.             {
  31.                 comboBox1.Items.Add(proc.ProcessName + "-" + proc.Id);
  32.             }
  33.         }
  34.  
  35.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  36.         {
  37.             foreach(var proc in Process.GetProcesses())
  38.             {
  39.                 if(comboBox1.Text.Contains(proc.ProcessName) && comboBox1.Text.Contains(proc.Id.ToString()))
  40.                 {
  41.                     GameProcess = proc;
  42.                     timerOfSetup.Start();
  43.                 }
  44.             }
  45.         }
  46.         //base: "programme test.exe"+00001374
  47.         //offset: 0
  48.         private void setup()
  49.         {
  50.             IntPtr pointerAdd = new IntPtr(0x00001374);
  51.             api.ReadProcess = GameProcess;
  52.             api.OpenProcess();
  53.  
  54.             ProcessModule pModule = null;
  55.             foreach (ProcessModule module in GameProcess.Modules)
  56.             {
  57.                 if (module.FileName.Contains("programme test.exe"))
  58.                 {
  59.                     pModule = module;
  60.                 }
  61.             }
  62.  
  63.             pointerMemoryAddr = api.ReadPointerAddress(pointerAdd, 0x0, 4, out bytesout, true, (int)pModule.BaseAddress);
  64.         }
  65.  
  66.         private void timerOfSetup_Tick(object sender, EventArgs e)
  67.         {
  68.             setup();
  69.             timerOfSetup.Stop();
  70.         }
  71.  
  72.         private void button1_Click(object sender, EventArgs e)
  73.         {
  74.             try
  75.             {
  76.                 if (pointerMemoryAddr != -1 && txtAmount.Text != string.Empty)
  77.                 {
  78.                     api.WriteMemory((IntPtr)pointerMemoryAddr, BitConverter.GetBytes(int.Parse(txtAmount.Text)), out bytesWritten);
  79.                 }
  80.             }catch(Exception ex) { MessageBox.Show(ex.Message); }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement