protected override PatchEntry OnMatch(Byte[] data, Int32 i, SearchCriteria criteria) { PatchEntry entry = new PatchEntry(); entry.Status = PatchCurrentStatus.Unknown; if (data[i + criteria.MagicIndex] == 0x48 && data[i + criteria.MagicIndex + 1] == 0x31) { entry.Status = PatchCurrentStatus.Yes; } else if (data[i + criteria.MagicIndex] == 0x48 && data[i + criteria.MagicIndex + 1] == 0x81) { entry.Status = PatchCurrentStatus.No; } if (entry.Status != PatchCurrentStatus.Unknown) { entry.Offset = criteria.SearchBegin + i + criteria.MagicIndex; entry.Bytes = criteria.PatchBytes; } return(entry); }
protected Patch Search(SearchCriteria criteria) { if (criteria.SearchEnd >= File.Length) { criteria.SearchEnd = File.Length; } Byte[] data; using (FileStream fs = new FileStream(File.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, 0x400)) using (BinaryReader rdr = new BinaryReader(fs)) { fs.Seek(criteria.SearchBegin, SeekOrigin.Begin); int length = (int)(criteria.SearchEnd - criteria.SearchBegin); data = rdr.ReadBytes(length); } Patch ret = new Patch(File); List <PatchEntry> entries = new List <PatchEntry>(); ///////////////////////////////// // Do the search for (int i = 0; i < data.Length - 64; i++) { if ( data[i] == criteria.SignBytes[0] && data[i + criteria.SignIndexen[1]] == criteria.SignBytes[1]) { /////////////////////////////////////////////////////////////// // if the first 2 match, try the rest Boolean matched = true; for (int j = 2; j < criteria.SignBytes.Length; j++) { if (data[i + criteria.SignIndexen[j]] != criteria.SignBytes[j]) { matched = false; break; } } if (matched) { // let the subclasses take it from here PatchEntry entry = OnMatch(data, i, criteria); if (entry != null) { entries.Add(entry); } } } //if } //for ret.Entries = entries.ToArray(); return(ret); }
protected override PatchEntry OnMatch(Byte[] data, Int32 i, SearchCriteria criteria) { PatchEntry entry = new PatchEntry(); entry.Status = PatchCurrentStatus.Unknown; // Pre-Win7 M1 if (data[i + 33] == 0xF6 && data[i + 34] == 0xD8) { if (data[i + criteria.MagicIndex] == 0x33 && data[i + criteria.MagicIndex + 1] == 0xC0) { entry.Status = PatchCurrentStatus.Yes; } else if (data[i + criteria.MagicIndex] == 0x81 && data[i + criteria.MagicIndex + 1] == 0xEC) { entry.Status = PatchCurrentStatus.No; } } else if (data[i + 33] == 0x0F && data[i + 36] == 0xF7) { if (data[i + criteria.MagicIndex] == 0x33 && data[i + criteria.MagicIndex + 1] == 0xC0) { entry.Status = PatchCurrentStatus.Yes; } else if (data[i + criteria.MagicIndex] == 0x81 && data[i + criteria.MagicIndex + 1] == 0xEC) { entry.Status = PatchCurrentStatus.No; } } if (entry.Status != PatchCurrentStatus.Unknown) { entry.Offset = criteria.SearchBegin + i + criteria.MagicIndex; entry.Bytes = criteria.PatchBytes; } return(entry); }
private void ApplyPatch(PatchEntry entry) { // sanity checking if (entry.Offset >= File.Length) { throw new InvalidDataException("offset out of range"); } if (entry.Offset == -1) { throw new InvalidDataException("offset undefined"); } _fs.Seek(entry.Offset, SeekOrigin.Begin); _fs.Write(entry.Bytes, 0, entry.Bytes.Length); }
protected override PatchEntry OnMatch(Byte[] data, Int32 i, SearchCriteria criteria) { PatchEntry entry = new PatchEntry(); entry.Status = PatchCurrentStatus.Unknown; if (data[i + criteria.MagicIndex] == 0x33 && data[i + 15] == 0xC3) { // this file is patched entry.Status = PatchCurrentStatus.Yes; } else if (data[i + criteria.MagicIndex] == 0x48 && data[i + criteria.MagicIndex + 1] == 0x81 && data[i + 15] == 0x48) { // then it isn't patch entry.Status = PatchCurrentStatus.No; } else if (data[i + criteria.MagicIndex] == 0x33) { entry.Status = PatchCurrentStatus.Unsure; } if (entry.Status != PatchCurrentStatus.Unknown) { entry.Offset = criteria.SearchBegin + i + criteria.MagicIndex; entry.Bytes = criteria.PatchBytes; } return(entry); }