public override void ValidateImage(string path) { if (!File.Exists(path)) { throw new TbtException(TbtStatus.SDK_FILE_NOT_FOUND); } if (!Updatable) { throw new TbtException(TbtStatus.SDK_DEVICE_NOT_SUPPORTED); } using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { byte[] image = new BinaryReader(fileStream).ReadBytes((int)fileStream.Length); DeviceFwInfo deviceFwInfo = new DeviceFwInfo(new ControllerFwInfoSource(this)); DeviceFwInfo deviceFwInfo2 = new DeviceFwInfo(new FileFwInfoSource(image)); if (deviceFwInfo.Info.Generation != deviceFwInfo2.Info.Generation) { throw new TbtException(TbtStatus.SDK_HW_GENERATION_MISMATCH); } if (deviceFwInfo.Info.Type != deviceFwInfo2.Info.Type) { throw new TbtException(TbtStatus.SDK_PORT_COUNT_MISMATCH); } new DeviceImageValidator(this, image, deviceFwInfo.GetSectionInfo(), deviceFwInfo2.GetSectionInfo(), deviceFwInfo.Info).Validate(); } }
public static bool GetImageIsHost(string path) { using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { byte[] array = new BinaryReader(fileStream).ReadBytes((int)fileStream.Length); Dictionary <Sections, FwInfo.SectionDetails> sectionInfo = new DeviceFwInfo(new FileFwInfoSource(array)).GetSectionInfo(); CheckLocation isHostCheckLocation = ImageValidator.GetIsHostCheckLocation(); return(Convert.ToBoolean(array.Skip((int)(sectionInfo[isHostCheckLocation.Section].Offset + isHostCheckLocation.Offset)).Take((int)isHostCheckLocation.Length).ToArray()[0] & isHostCheckLocation.Mask)); } }
public static string GetImageFullNvmVersion(string path) { using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { int count = (int)fileStream.Length; byte[] array = new BinaryReader(fileStream).ReadBytes(count); uint offset = new DeviceFwInfo(new FileFwInfoSource(array)).GetSectionInfo()[Sections.Digital].Offset; return($"{array[offset + 10]:X}.{array[offset + 9]:X2}"); } }
public static DeviceInformation GetImageDeviceInformation(string path) { using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { BinaryReader binaryReader = new BinaryReader(fileStream); byte[] imageBuffer = binaryReader.ReadBytes((int)fileStream.Length); DeviceFwInfo deviceFwInfo = new DeviceFwInfo(new FileFwInfoSource(imageBuffer)); Dictionary <Sections, FwInfo.SectionDetails> fileSections = deviceFwInfo.GetSectionInfo(); if (!fileSections.ContainsKey(Sections.DROM)) { throw new TbtException(TbtStatus.SDK_NO_DROM_IN_FILE_ERROR); } CheckLocation arg = new CheckLocation(16u, 2u, byte.MaxValue, Sections.DROM, TbtStatus.SDK_IMAGE_VALIDATION_ERROR, null); CheckLocation arg2 = new CheckLocation(18u, 2u, byte.MaxValue, Sections.DROM, TbtStatus.SDK_IMAGE_VALIDATION_ERROR, null); Func <CheckLocation, byte[]> func = (CheckLocation loc) => imageBuffer.Skip((int)(fileSections[loc.Section].Offset + loc.Offset)).Take((int)loc.Length).ToArray(); return(new DeviceInformation { VendorId = BitConverter.ToUInt16(func(arg), 0), ModelId = BitConverter.ToUInt16(func(arg2), 0) }); } }
public static string GetImageTIPdVersion(string path) { byte[] array = default(byte[]); using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { array = new BinaryReader(fileStream).ReadBytes((int)fileStream.Length); } Dictionary <Sections, FwInfo.SectionDetails> sectionInfo = new DeviceFwInfo(new FileFwInfoSource(array)).GetSectionInfo(); if (!sectionInfo.ContainsKey(Sections.Pd)) { return("N/A"); } string text; if (Encoding.ASCII.GetString(array.Skip((int)(sectionInfo[Sections.Pd].Offset + 48)).Take(4).ToArray()) == "ACE1") { string[] array2 = BitConverter.ToString(array.Skip((int)(sectionInfo[Sections.Pd].Offset + 52)).Take(3).ToArray(), 0).Split('-'); text = $"{array2[1]}.{array2[0]}.{array2[2]}"; } else { string @string = Encoding.ASCII.GetString(array); Match match = Regex.Match(@string, "TPS6598. HW.{5}FW", RegexOptions.Singleline); if (!match.Success) { return("N/A"); } text = @string.Substring(match.Index + match.Length, 10); } text = text.TrimStart('0'); if (text[0] == '.') { text = "0" + text; } return(text); }