Beispiel #1
0
 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));
     }
 }
Beispiel #2
0
        private void ComparePdExistence()
        {
            CheckLocation checkLocation = new CheckLocation(268u, 4u, byte.MaxValue, Sections.ArcParams, TbtStatus.SDK_IMAGE_VALIDATION_ERROR, null);
            bool          num           = Utilities.ValidPointer(BitConverter.ToUInt32(ReadFromFw(checkLocation), 0), (int)checkLocation.Length);
            bool          flag          = Utilities.ValidPointer(BitConverter.ToUInt32(ReadFromFile(checkLocation), 0), (int)checkLocation.Length);

            if (num != flag)
            {
                throw new TbtException(TbtStatus.SDK_PD_MISMATCH);
            }
        }
Beispiel #3
0
        private void ValidateChipSize()
        {
            CheckLocation checkLocation = new CheckLocation(69u, 1u, Convert.ToByte("00000111", 2), Sections.Digital, TbtStatus.SDK_CHIP_SIZE_ERROR, null);
            byte          num           = ReadFromFw(checkLocation)[0];
            byte          b             = ReadFromFile(checkLocation)[0];

            if (num < b)
            {
                throw new TbtException(checkLocation.ErrorCode);
            }
        }
Beispiel #4
0
        private void CheckMultipleController()
        {
            CheckLocation loc = new CheckLocation(14u, 2u, byte.MaxValue, Sections.DROM, TbtStatus.SDK_IMAGE_VALIDATION_ERROR, null);

            byte[] lengthBytes  = ReadFromFile(loc);
            byte[] lengthBytes2 = ReadFromFw(loc);
            uint   length       = ExtractLength(lengthBytes);
            uint   length2      = ExtractLength(lengthBytes2);

            byte[] drom  = ReadFromFile(new CheckLocation(0u, length, byte.MaxValue, Sections.DROM, TbtStatus.SDK_IMAGE_VALIDATION_ERROR, null));
            byte[] drom2 = ReadFromFw(new CheckLocation(0u, length2, byte.MaxValue, Sections.DROM, TbtStatus.SDK_IMAGE_VALIDATION_ERROR, null));
            if (GetMcData(drom) != GetMcData(drom2))
            {
                throw new TbtException(TbtStatus.SDK_IMAGE_VALIDATION_ERROR, Resources.ValidationFailedPart1 + "X of N\n" + Resources.ValidationFailedPart2);
            }
        }
Beispiel #5
0
        protected override IEnumerable <CheckLocation> GetCheckLocations(HwGeneration generation)
        {
            CheckLocation isHostCheckLocation = ImageValidator.GetIsHostCheckLocation();

            isHostCheckLocation.ErrorCode = TbtStatus.SDK_IMAGE_FOR_DEVICE_ERROR;
            List <CheckLocation> list = new List <CheckLocation>();

            list.Add(isHostCheckLocation);
            list.AddRange(GetHostCheckLocations(generation).Where(delegate(HostCheckLocation val)
            {
                if (val.Type != HwType._1Port)
                {
                    return(val.Type == base.HwInfo.Type);
                }
                return(true);
            }));
            return(list);
        }
Beispiel #6
0
        protected override IEnumerable <CheckLocation> GetCheckLocations(HwGeneration generation)
        {
            CheckLocation isHostCheckLocation = ImageValidator.GetIsHostCheckLocation();

            isHostCheckLocation.ErrorCode = TbtStatus.SDK_IMAGE_FOR_HOST_ERROR;
            if ((uint)(generation - 3) <= 2u)
            {
                return(new CheckLocation[2]
                {
                    isHostCheckLocation,
                    new CheckLocation(292u, 1u, byte.MaxValue, Sections.ArcParams, TbtStatus.SDK_IMAGE_VALIDATION_ERROR, "X of N")
                });
            }
            if (generation == HwGeneration.JHL7540_7440_7340)
            {
                return(new CheckLocation[1]
                {
                    isHostCheckLocation
                });
            }
            throw new TbtException(TbtStatus.SDK_UNKNOWN_CHIP);
        }
Beispiel #7
0
 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)
         });
     }
 }
Beispiel #8
0
 protected byte[] ReadFromFw(CheckLocation loc)
 {
     return(ApplyMask(_controller.ReadFirmware(_controllerSections[loc.Section].Offset + loc.Offset, loc.Length), loc.Mask));
 }
Beispiel #9
0
 protected byte[] ReadFromFile(CheckLocation loc)
 {
     return(ApplyMask(_image.Skip((int)(_fileSections[loc.Section].Offset + loc.Offset)).Take((int)loc.Length).ToArray(), loc.Mask));
 }