MCPcopy Create free account
hub / github.com/Selectively11/CloudRedirect / ApplyPatches

Method ApplyPatches

ui/Services/Patching/Patcher.cs:904–928  ·  view source on GitHub ↗
(byte[] data, PatchEntry[] patches)

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected