/// <summary> /// Creates a Checksum from a hex string representation of bytes /// </summary> /// <param name="hashAlgorithmName">The name of the hash algorithm used to calculate the hash bytes.</param> /// <param name="checksumString">Hex String representation of hash bytse. Example: "A0B1C2D3E4F5A6B7C8D9E0F1A2B3C4D5"</param> /// <returns></returns> public static Checksum FromString(MIHashAlgorithmName hashAlgorithmName, string checksumString) { if (checksumString == null) { throw new ArgumentNullException("checksumString"); } Checksum checksum = new Checksum(hashAlgorithmName, StringToBytes(checksumString)); checksum._checksumString = checksumString; return checksum; }
/// <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; }