Advertisement
HoLLy_HaCKeR

C# Sigscanning

Jun 15th, 2015
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using System.Diagnostics;
  8. using System.Runtime.InteropServices;
  9.  
  10. namespace Helpers
  11. {
  12.     class MemoryHelper
  13.     {
  14.         [DllImport("kernel32.dll", SetLastError = true)]
  15.         static extern bool ReadProcessMemory(
  16.             IntPtr hProcess,
  17.             IntPtr lpBaseAddress,
  18.             [Out] byte[] lpBuffer,
  19.             int dwSize,
  20.             out IntPtr lpNumberOfBytesRead);
  21.  
  22.         public static int findPattern(byte[] source, byte[] pattern)
  23.         {
  24.             bool found = false;
  25.             for (int i = 0; i < source.Length - pattern.Length; i++)
  26.             {
  27.                 //see if it has pattern
  28.                 found = true;
  29.                 for (int j = 0; j < pattern.Length; j++)
  30.                 {
  31.                     if (source[i + j] != pattern[j])
  32.                     {
  33.                         found = false;
  34.                         break;
  35.                     }
  36.                 }
  37.                 if (found)
  38.                     return i;
  39.             }
  40.  
  41.             return -1;
  42.         }
  43.  
  44.         public static int sigscan(byte[] toFind, Process p)
  45.         {
  46.             return sigscan(toFind, p, 0x1000, 0x10000000);
  47.         }
  48.  
  49.         public static int sigscan(byte[] toFind, Process osup, int regionSize, int scanSize)
  50.         {
  51.             int startAddress = (int)osup.MainModule.BaseAddress;
  52.             int endAddress = startAddress + scanSize;
  53.  
  54.             int currentAddress = startAddress;
  55.             int region = regionSize;
  56.  
  57.             byte[] buffer = new byte[region];
  58.  
  59.             while (currentAddress < endAddress)
  60.             {
  61.                 buffer = MemoryHelper.readBytes(osup, currentAddress, region + toFind.Length);
  62.                 int index = findPattern(buffer, toFind);
  63.                 if (index != -1)
  64.                     return currentAddress + index;
  65.                 currentAddress += region;
  66.             }
  67.  
  68.             return -1;
  69.         }
  70.  
  71.         public static byte[] readBytes(Process p, int address, int size)
  72.         {
  73.             byte[] ret = new byte[size];
  74.             IntPtr read;
  75.             ReadProcessMemory(p.Handle, (IntPtr)address, ret, size, out read);
  76.             return ret;
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement