ibrahim_elsakka

aobscan/patternscan/sigscan

Oct 4th, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Diagnostics;
  8. using System.Globalization;
  9.  
  10. namespace sigscan
  11. {
  12.     internal class Program
  13.     {
  14.         [DllImport("kernel32.dll")]
  15.  
  16.         static extern bool ReadProcessMemory(IntPtr handle, IntPtr addy, byte[] buffer, int size, ref int bytesRead);
  17.  
  18.  
  19.         static void Main(string[] args)
  20.         {
  21.             Process proc = Process.GetProcessesByName("popcapgame1")[0];
  22.  
  23.             byte[] buffer = new byte[proc.MainModule.ModuleMemorySize];
  24.  
  25.             int bytesread = 0;
  26.  
  27.             ReadProcessMemory(proc.Handle, proc.MainModule.BaseAddress, buffer, buffer.Length, ref bytesread); // might require openprocess, idk
  28.  
  29.             string signature = "89 B7 78 55 ?? 00 B0 01";
  30.             var addy = sigscan(signature);
  31.             Console.WriteLine(addy[0].ToString("X"));
  32.             Console.ReadLine();
  33.            
  34.          
  35.            
  36.             int[] transformarray(string sig)
  37.             {
  38.                 var bytes = sig.Split(' ');
  39.                 int[] intlist = new int[bytes.Length];
  40.  
  41.                 for (int i = 0; i < intlist.Length; i++)
  42.                 {
  43.                     if (bytes[i] == "??")
  44.                         intlist[i] = -1;
  45.                     else
  46.                         intlist[i] = int.Parse(bytes[i], NumberStyles.HexNumber);
  47.                 }
  48.                 return intlist;
  49.             }
  50.  
  51.           List<IntPtr> sigscan(string sig)
  52.             {
  53.                 var intlist = transformarray(sig);
  54.                 var results = new List<IntPtr>();
  55.  
  56.                 for (int a = 0; a < buffer.Length; a++)
  57.                 {
  58.                     for (int b = 0; b < intlist.Length; b++)
  59.                     {
  60.                         if (intlist[b] != -1 && intlist[b] != buffer[a + b])
  61.                             break;
  62.                         if (b + 1 == intlist.Length)
  63.                         {
  64.                             var result = new IntPtr(a + (int)proc.MainModule.BaseAddress);
  65.                             results.Add(result);
  66.                         }
  67.                     }
  68.  
  69.  
  70.                 }
  71.  
  72.  
  73.  
  74.  
  75.                 return results;
  76.             }
  77.  
  78.         }
  79.     }
  80. }
Add Comment
Please, Sign In to add comment