// Warning: the sourceBytes byte[] will get zeroed out. public static unsafe byte[] CreatePatch(byte[] sourceBytes, byte[] targetBytes) { fixed(byte *pSourceBuf = sourceBytes) fixed(byte *pTargetBuf = targetBytes) { DeltaInput ds = new DeltaInput(pSourceBuf, sourceBytes.Length, true); DeltaInput dt = new DeltaInput(pTargetBuf, targetBytes.Length, true); DeltaOutput output; if (!CreateDeltaB(DeltaFileType.Executable, DeltaFlag.None, DeltaFlag.None, // "reset flags" ds, dt, DeltaInput.Empty, DeltaInput.Empty, DeltaInput.Empty, IntPtr.Zero, AlgId.Crc32FromMsdelta, out output)) { throw new Win32Exception(); } byte[] patchBytes = new byte[output.cbBuf.ToInt32()]; Marshal.Copy(output.pBuf, patchBytes, 0, patchBytes.Length); DeltaFree(output.pBuf); return(patchBytes); } } // end CreatePatch()
private static extern bool CreateDeltaB( DeltaFileType fileTypeSet, // File type set. DeltaFlag setFlags, // Set these flags. DeltaFlag resetFlags, // Reset (suppress) these flags. DeltaInput source, // Source memory block. DeltaInput target, // Target memory block. DeltaInput sourceOptions, // Memory block with source-specific options. DeltaInput targetOptions, // Memory block with target-specific options. DeltaInput globalOptions, // Memory block with global options. IntPtr targetFileTime, // Target file time to use, null to use current time. (need this overload because the compiler can't convert from "null" to "ref FILETIME") AlgId hashAlgId, out DeltaOutput delta);
private static extern bool CreateDeltaB( DeltaFileType fileTypeSet, // File type set. DeltaFlag setFlags, // Set these flags. DeltaFlag resetFlags, // Reset (suppress) these flags. DeltaInput source, // Source memory block. DeltaInput target, // Target memory block. DeltaInput sourceOptions, // Memory block with source-specific options. DeltaInput targetOptions, // Memory block with target-specific options. DeltaInput globalOptions, // Memory block with global options. ref System.Runtime.InteropServices.ComTypes.FILETIME targetFileTime, // Target file time to use, null to use current time. AlgId hashAlgId, out DeltaOutput delta);
public static unsafe byte[] ApplyPatch(byte[] sourceBytes, byte[] patchBytes) { fixed(byte *pSourceBuf = sourceBytes) fixed(byte *pPatchBuf = patchBytes) { var ds = new DeltaInput(pSourceBuf, sourceBytes.Length, true); var dp = new DeltaInput(pPatchBuf, patchBytes.Length, true); if (!ApplyDeltaB(DeltaApplyFlag.None, ds, dp, out var output)) { throw new Win32Exception(); } var targetBytes = new byte[output.cbBuf.ToInt32()]; Marshal.Copy(output.pBuf, targetBytes, 0, targetBytes.Length); DeltaFree(output.pBuf); return(targetBytes); } }
public static unsafe byte[] ApplyPatch(byte[] sourceBytes, byte[] patchBytes) { fixed (byte* pSourceBuf = sourceBytes) fixed (byte* pPatchBuf = patchBytes) { DeltaInput ds = new DeltaInput(pSourceBuf, sourceBytes.Length, true); DeltaInput dp = new DeltaInput(pPatchBuf, patchBytes.Length, true); if (!ApplyDeltaB(DeltaApplyFlag.None, ds, dp, out var output)) { throw new Win32Exception(); } byte[] targetBytes = new byte[output.cbBuf.ToInt32()]; Marshal.Copy(output.pBuf, targetBytes, 0, targetBytes.Length); DeltaFree(output.pBuf); return targetBytes; } }
private static extern bool ApplyDeltaB( DeltaApplyFlag applyFlags, DeltaInput source, DeltaInput delta, out DeltaOutput target);
private static extern bool ApplyDeltaB( DeltaApplyFlag applyFlags, DeltaInput source, DeltaInput delta, out DeltaOutput target );