public static int Read(ProcessStream pc, int bytes) { byte[] buffer = new byte[bytes]; pc.Read(buffer, 0, bytes); switch (bytes) { case 1: return((sbyte)buffer[0]); case 2: return((short)(buffer[0] | (buffer[1] << 8))); case 4: return((int)(buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24))); } int val = 0; int bits = 0; for (int i = 0; i < buffer.Length; ++i) { val |= buffer[i] << bits; bits += 8; } return(val); }
public static int Read(ProcessStream pc, int bytes) { byte[] buffer = new byte[bytes]; pc.Read(buffer, 0, bytes); switch (bytes) { case 1: return((int)(sbyte)buffer[0]); case 2: return((int)(short)((int)buffer[0] | (int)buffer[1] << 8)); case 4: return((int)buffer[0] | (int)buffer[1] << 8 | (int)buffer[2] << 16 | (int)buffer[3] << 24); default: int num1 = 0; int num2 = 0; for (int index = 0; index < buffer.Length; ++index) { num1 |= (int)buffer[index] << num2; num2 += 8; } return(num1); } }
public static int Search(ProcessStream pc, byte[] mask, byte[] values) { if (mask.Length != values.Length) { // TODO: maybe we need better exception here? throw new Exception(); } const int chunkSize = 4096; int readSize = chunkSize + mask.Length; pc.BeginAccess(); var read = new byte[readSize]; for (int i = 0; ; ++i) { pc.Seek(0x400000 + (i * chunkSize), SeekOrigin.Begin); int count = pc.Read(read, 0, readSize); if (count != readSize) { break; } for (int j = 0; j < chunkSize; ++j) { bool ok = true; for (int k = 0; ok && k < mask.Length; ++k) { ok = ((read[j + k] & mask[k]) == values[k]); } if (ok) { pc.EndAccess(); return(0x400000 + (i * chunkSize) + j); } } } pc.EndAccess(); return(0); }
public static int Search(ProcessStream pc, byte[] mask, byte[] vals) { if (mask.Length != vals.Length) { throw new Exception(); } int count = 4096 + mask.Length; pc.BeginAccess(); byte[] buffer = new byte[count]; int num = 0; while (true) { pc.Seek((long)(4194304 + num * 4096), SeekOrigin.Begin); if (pc.Read(buffer, 0, count) == count) { for (int index1 = 0; index1 < 4096; ++index1) { bool flag = true; for (int index2 = 0; flag && index2 < mask.Length; ++index2) { flag = ((int)buffer[index1 + index2] & (int)mask[index2]) == (int)vals[index2]; } if (flag) { pc.EndAccess(); return(4194304 + num * 4096 + index1); } } ++num; } else { break; } } pc.EndAccess(); return(0); }
public static int Search(ProcessStream pc, byte[] buffer) { const int chunkSize = 4096; int readSize = chunkSize + buffer.Length; pc.BeginAccess(); byte[] read = new byte[readSize]; for (int i = 0;; ++i) { pc.Seek(0x400000 + (i * chunkSize), SeekOrigin.Begin); int count = pc.Read(read, 0, readSize); if (count != readSize) { break; } for (int j = 0; j < chunkSize; ++j) { bool ok = true; for (int k = 0; ok && k < buffer.Length; ++k) { ok = (buffer[k] == read[j + k]); } if (ok) { pc.EndAccess(); return(0x400000 + (i * chunkSize) + j); } } } pc.EndAccess(); return(0); }
public static int Search(ProcessStream pc, byte[] buffer) { int count = 4096 + buffer.Length; pc.BeginAccess(); byte[] buffer1 = new byte[count]; int num = 0; while (true) { pc.Seek((long)(4194304 + num * 4096), SeekOrigin.Begin); if (pc.Read(buffer1, 0, count) == count) { for (int index1 = 0; index1 < 4096; ++index1) { bool flag = true; for (int index2 = 0; flag && index2 < buffer.Length; ++index2) { flag = (int)buffer[index2] == (int)buffer1[index1 + index2]; } if (flag) { pc.EndAccess(); return(4194304 + num * 4096 + index1); } } ++num; } else { break; } } pc.EndAccess(); return(0); }