Exemplo n.º 1
0
        internal static List <QualcommPartition> GetPossibleLoadersForRootKeyHash(string Path, byte[] RootKeyHash)
        {
            List <QualcommPartition> Result = new List <QualcommPartition>();

            try
            {
                IEnumerable <string> FilePaths = Directory.EnumerateFiles(Path);
                foreach (string FilePath in FilePaths)
                {
                    try
                    {
                        FileInfo Info = new FileInfo(FilePath);
                        if (Info.Length <= 0x80000)
                        {
                            QualcommPartition Loader;

#if DEBUG
                            System.Diagnostics.Debug.Print("Evaluating loader: " + FilePath);
#endif

                            byte[] Binary = ParseAsHexFile(FilePath);
                            if (Binary == null)
                            {
                                Loader = new QualcommPartition(FilePath);
                            }
                            else
                            {
                                Loader = new QualcommPartition(Binary);
                            }

                            // Make sure the RootKeyHash is not blank
                            // If the RootKeyHash is blank, this is an engineering device, and it will accept any RKH
                            // We expect the user to know what he is doing in such case and we will ignore checks
                            if (!StructuralComparisons.StructuralEqualityComparer.Equals(RootKeyHash, new byte[RootKeyHash.Length]))
                            {
                                if ((StructuralComparisons.StructuralEqualityComparer.Equals(Loader.RootKeyHash, RootKeyHash)) &&
                                    (ByteOperations.FindUnicode(Loader.Binary, "QHSUSB_ARMPRG") != null))    // To detect that this is a loader, and not SBL1 or something. V1 loaders are QHSUSB_ARMPRG. V2 loaders are QHSUSB__BULK. Only V1 supported for now, because V2 only accepts signed payload.
                                {
                                    Result.Add(Loader);
                                }
                            }
                            else
                            {
                                if ((ByteOperations.FindUnicode(Loader.Binary, "QHSUSB_ARMPRG") != null)) // To detect that this is a loader, and not SBL1 or something. V1 loaders are QHSUSB_ARMPRG. V2 loaders are QHSUSB__BULK. Only V1 supported for now, because V2 only accepts signed payload.
                                {
                                    Result.Add(Loader);
                                }
                            }
                        }
                    }
                    catch { }
                }
            }
            catch { }

            return(Result);
        }