(byte[] data, PatchEntry[] patches)
| 902 | } |
| 903 | |
| 904 | static (byte[] data, int applied, int skipped, List<string> errors) ApplyPatches(byte[] data, PatchEntry[] patches) |
| 905 | { |
| 906 | var buf = (byte[])data.Clone(); |
| 907 | int applied = 0, skipped = 0; |
| 908 | var errors = new List<string>(); |
| 909 | |
| 910 | foreach (var p in patches) |
| 911 | { |
| 912 | if (BytesMatch(buf, p.Offset, p.Replacement, 0, p.Replacement.Length)) |
| 913 | { |
| 914 | skipped++; |
| 915 | } |
| 916 | else if (BytesMatch(buf, p.Offset, p.Original, 0, p.Original.Length)) |
| 917 | { |
| 918 | Buffer.BlockCopy(p.Replacement, 0, buf, p.Offset, p.Replacement.Length); |
| 919 | applied++; |
| 920 | } |
| 921 | else |
| 922 | { |
| 923 | errors.Add($" Mismatch at 0x{p.Offset:X}: expected {BitConverter.ToString(p.Original)}, got {SafeHexDump(buf, p.Offset, p.Original.Length)}"); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | return (buf, applied, skipped, errors); |
| 928 | } |
| 929 | |
| 930 | static (byte[] data, int reverted, int skipped, List<string> errors) UnapplyPatches(byte[] data, PatchEntry[] patches) |
| 931 | { |
nothing calls this directly
no outgoing calls
no test coverage detected