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

Method ReEncryptAndWrite

ui/Services/Patching/Patcher.cs:830–848  ·  view source on GitHub ↗
(string cachePath, byte[] patchedPayload, byte[] iv)

Source from the content-addressed store, hash-verified

828 }
829
830 void ReEncryptAndWrite(string cachePath, byte[] patchedPayload, byte[] iv)
831 {
832 // Reuse original IV: SteamTools does the same; new IV would break cache validation.
833 Log(" Re-encrypting..");
834 using var compMs = new MemoryStream();
835 using (var zOut = new ZLibStream(compMs, CompressionLevel.Optimal, leaveOpen: true))
836 zOut.Write(patchedPayload, 0, patchedPayload.Length);
837
838 var blob = new byte[4 + compMs.Length];
839 BitConverter.TryWriteBytes(blob.AsSpan(0, 4), patchedPayload.Length);
840 compMs.GetBuffer().AsSpan(0, (int)compMs.Length).CopyTo(blob.AsSpan(4));
841
842 var newCt = PayloadCrypto.AesCbcEncrypt(blob, AesKey, iv);
843 var output = new byte[16 + newCt.Length];
844 iv.CopyTo(output, 0);
845 newCt.CopyTo(output, 16);
846 FileUtils.AtomicWriteAllBytes(cachePath, output);
847 _cachedPayload = null;
848 }
849
850 // Build the cave with caller-relative displacements.
851 static byte[] BuildDynamicCloudRedirectCave(int caveRva, int sendPktRva,

Callers

nothing calls this directly

Calls 3

AesCbcEncryptMethod · 0.80
AtomicWriteAllBytesMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected