private unsafe IList<IntPtr> FindOutOfProcess(IntPtr begin, IntPtr end, IBotProcessContext context, int maxMatchCount, IPatternAlgorithm algorithm) { byte* b = (byte*)begin; byte* e = (byte*)end; IList<IntPtr> matches = new List<IntPtr>(maxMatchCount); int byteCount = (int)(e - b); byte[] buffer = context.Memory.ReadBytes(begin, byteCount); fixed (byte* buf = buffer) { byte* bufEnd = buf + buffer.Length; byte* cur = buf; while (matches.Count < maxMatchCount && cur < bufEnd) { IntPtr match = algorithm.Apply(_pattern, _mask, cur, bufEnd); if (match == IntPtr.Zero) { break; } int delta = (int)((byte*)match - buf); matches.Add(begin + delta); cur = (byte*)match + 1; } } return matches; }
private unsafe IList<IntPtr> FindInProcess(IntPtr begin, IntPtr end, int maxMatchCount, IPatternAlgorithm algorithm) { byte* b = (byte*)begin + _trimmedWildcardsOffset; byte* e = (byte*)end; IList<IntPtr> matches = new List<IntPtr>(maxMatchCount); while (matches.Count < maxMatchCount && b < e) { IntPtr match = algorithm.Apply(_pattern, _mask, b, e); if (match == IntPtr.Zero) { break; } match -= _trimmedWildcardsOffset; matches.Add(match); b = (byte*)match + 1; } return matches; }