Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- namespace Helpers
- {
- class MemoryHelper
- {
- [DllImport("kernel32.dll", SetLastError = true)]
- static extern bool ReadProcessMemory(
- IntPtr hProcess,
- IntPtr lpBaseAddress,
- [Out] byte[] lpBuffer,
- int dwSize,
- out IntPtr lpNumberOfBytesRead);
- public static int findPattern(byte[] source, byte[] pattern)
- {
- bool found = false;
- for (int i = 0; i < source.Length - pattern.Length; i++)
- {
- //see if it has pattern
- found = true;
- for (int j = 0; j < pattern.Length; j++)
- {
- if (source[i + j] != pattern[j])
- {
- found = false;
- break;
- }
- }
- if (found)
- return i;
- }
- return -1;
- }
- public static int sigscan(byte[] toFind, Process p)
- {
- return sigscan(toFind, p, 0x1000, 0x10000000);
- }
- public static int sigscan(byte[] toFind, Process osup, int regionSize, int scanSize)
- {
- int startAddress = (int)osup.MainModule.BaseAddress;
- int endAddress = startAddress + scanSize;
- int currentAddress = startAddress;
- int region = regionSize;
- byte[] buffer = new byte[region];
- while (currentAddress < endAddress)
- {
- buffer = MemoryHelper.readBytes(osup, currentAddress, region + toFind.Length);
- int index = findPattern(buffer, toFind);
- if (index != -1)
- return currentAddress + index;
- currentAddress += region;
- }
- return -1;
- }
- public static byte[] readBytes(Process p, int address, int size)
- {
- byte[] ret = new byte[size];
- IntPtr read;
- ReadProcessMemory(p.Handle, (IntPtr)address, ret, size, out read);
- return ret;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement