/// <summary> /// Get the checksums associated with this pending breakpoint in order to verify the source file /// </summary> /// <param name="hashAlgorithmId">The HashAlgorithmId to use to calculate checksums</param> /// <param name="checksums">Enumerable of the checksums obtained from the UI</param> /// <returns> /// S_OK on Success, Error Codes on failure /// </returns> private int GetChecksum(HashAlgorithmId hashAlgorithmId, out IEnumerable <Checksum> checksums) { checksums = Enumerable.Empty <Checksum>(); IDebugBreakpointChecksumRequest2 checksumRequest = _pBPRequest as IDebugBreakpointChecksumRequest2; if (checksumRequest == null) { return(Constants.E_NOTIMPL); } int hr = Constants.S_OK; int checksumEnabled; hr = checksumRequest.IsChecksumEnabled(out checksumEnabled); if (hr != Constants.S_OK || checksumEnabled == 0) { return(Constants.E_NOTIMPL); } Guid guidAlgorithm = hashAlgorithmId.AD7GuidHashAlgorithm; uint checksumSize = hashAlgorithmId.HashSize; CHECKSUM_DATA[] checksumDataArr = new CHECKSUM_DATA[1]; hr = checksumRequest.GetChecksum(ref guidAlgorithm, checksumDataArr); if (hr != Constants.S_OK) { return(hr); } CHECKSUM_DATA checksumData = checksumDataArr[0]; Debug.Assert(checksumData.ByteCount % checksumSize == 0); uint countChecksums = checksumData.ByteCount / checksumSize; if (countChecksums == 0) { return(Constants.S_OK); } byte[] allChecksumBytes = new byte[checksumData.ByteCount]; System.Runtime.InteropServices.Marshal.Copy(checksumData.pBytes, allChecksumBytes, 0, allChecksumBytes.Length); System.Runtime.InteropServices.Marshal.FreeCoTaskMem(checksumData.pBytes); Checksum[] checksumArray = new Checksum[countChecksums]; for (uint i = 0; i < countChecksums; i++) { checksumArray[i] = Checksum.FromBytes(hashAlgorithmId.MIHashAlgorithmName, allChecksumBytes.Skip((int)(i * checksumSize)).Take((int)checksumSize).ToArray()); } checksums = checksumArray; return(Constants.S_OK); }
/// <summary> /// Get the checksums associated with this pending breakpoint in order to verify the source file /// </summary> /// <param name="hashAlgorithmId">The HashAlgorithmId to use to calculate checksums</param> /// <param name="checksums">Enumerable of the checksums obtained from the UI</param> /// <returns> /// S_OK on Success, Error Codes on failure /// </returns> private int GetChecksum(HashAlgorithmId hashAlgorithmId, out IEnumerable<Checksum> checksums) { checksums = Enumerable.Empty<Checksum>(); IDebugBreakpointChecksumRequest2 checksumRequest = _pBPRequest as IDebugBreakpointChecksumRequest2; if (checksumRequest == null) { return Constants.E_NOTIMPL; } int hr = Constants.S_OK; int checksumEnabled; hr = checksumRequest.IsChecksumEnabled(out checksumEnabled); if (hr != Constants.S_OK || checksumEnabled == 0) { return Constants.E_NOTIMPL; } Guid guidAlgorithm = hashAlgorithmId.AD7GuidHashAlgorithm; uint checksumSize = hashAlgorithmId.HashSize; CHECKSUM_DATA[] checksumDataArr = new CHECKSUM_DATA[1]; hr = checksumRequest.GetChecksum(ref guidAlgorithm, checksumDataArr); if (hr != Constants.S_OK) { return hr; } CHECKSUM_DATA checksumData = checksumDataArr[0]; Debug.Assert(checksumData.ByteCount % checksumSize == 0); uint countChecksums = checksumData.ByteCount / checksumSize; if (countChecksums == 0) { return Constants.S_OK; } byte[] allChecksumBytes = new byte[checksumData.ByteCount]; System.Runtime.InteropServices.Marshal.Copy(checksumData.pBytes, allChecksumBytes, 0, allChecksumBytes.Length); System.Runtime.InteropServices.Marshal.FreeCoTaskMem(checksumData.pBytes); Checksum[] checksumArray = new Checksum[countChecksums]; for (uint i = 0; i < countChecksums; i++) { checksumArray[i] = Checksum.FromBytes(hashAlgorithmId.MIHashAlgorithmName, allChecksumBytes.Skip((int)(i * checksumSize)).Take((int)checksumSize).ToArray()); } checksums = checksumArray; return Constants.S_OK; }