Пример #1
0
        /// <summary>
        /// Adds hashes to specified string builder for summary box. SB.
        /// </summary>
        /// <param name="hashes">A list of hashes to add. This list will be destroyed.</param>
        /// <param name="prefix">A string to prefix to hash name, e.g. "Patched" -> "Patched File MD5:..."</param>
        /// <param name="sb"></param>
        private void AddHashesToSB(StringBuilder sb, List <RomHash> hashes, string prefix)
        {
            // Why do I make things more complicated than they need to be?

            if (string.IsNullOrEmpty(prefix))
            {
                prefix = string.Empty;
            }
            else
            {
                prefix += " ";
            }

            while (hashes.Count > 0)
            {
                // Grab last hash
                var hash = hashes[0];
                hashes.RemoveAt(0);

                // For ROM/FILE hashes, if two are the same, we want to report them as one
                // Example: a headerless SNES ROM will have identical file and ROM hashes because the file is a plain ROM image,
                // so we can report it as a "File/ROM SHA-1" rather than as two seprate hashes with identical values

                // Get the desired type of hash we want to check, e.g. for ROM SHA-1, we want to see if File SHA-1 is the same.
                HashFlags altHashType = 0;
                if (hash.Type.GetContents() == HashFlags.FileHash)
                {
                    altHashType = HashFlags.RomHash | hash.Type.GetAlgorithm();
                }
                else if (hash.Type.GetContents() == HashFlags.RomHash)
                {
                    altHashType = HashFlags.FileHash | hash.Type.GetAlgorithm();
                }

                RomHash altHash = null;
                if (altHashType != 0)
                {
                    for (int i = 0; i < hashes.Count; i++)
                    {
                        // Find the right hash, and check its value
                        if (hashes[i].Type == altHashType && CompareByteArrays(hash.Value, hashes[i].Value))
                        {
                            // Match? Cool beans
                            altHash = hashes[i];
                            hashes.RemoveAt(i);
                            break; // for
                        }
                    }
                }

                var hashType = hash.Type;
                if (altHash != null)
                {
                    hashType |= altHash.Type;
                }
                string hashname = RomHash.GetHashName(hashType);
                sb.AppendLine(prefix + hashname + ": " + Hex.FormatHex(hash.Value));
            }
        }
Пример #2
0
        /// <summary>
        /// Adds standard ROM details
        /// </summary>
        /// <param name="builder">Data builder</param>
        /// <param name="rom">ROM image</param>
        /// <param name="data">ROM information</param>
        private void AddStandardData(RomExDataBuilder builder, byte[] rom, RomData data)
        {
            const string general = RomExDataBuilder.GeneralCat;

            builder.AddData(general, "Platform", data.Platform.ID.GetDescription());
            builder.AddData(general, "ROM format", data.FormatName);
            if (data.ExternalHeader != null)
            {
                builder.AddData(general, "External Header", data.ExternalHeader.Value ? "Yes" : "No");
            }
            builder.AddData(general, "File Size", data.FileSize.ToString() + " (" + data.FileSize.ToString("x") + ")");
            builder.AddData(general, "ROM Size", data.RomSize.ToString() + " (" + data.RomSize.ToString("x") + ")");

            // ROM hashes
            var crc32 = data.GetHash(HashFlags.RomHash | HashFlags.CRC32);
            var sha1  = data.GetHash(HashFlags.RomHash | HashFlags.SHA1);

            if (crc32 != null)
            {
                builder.AddData(general, RomHash.GetHashName(HashFlags.RomHash | HashFlags.CRC32), Hex.FormatHex(crc32.Value));
            }
            if (sha1 != null)
            {
                builder.AddData(general, RomHash.GetHashName(HashFlags.RomHash | HashFlags.SHA1), Hex.FormatHex(sha1.Value));
            }

            // File hashes as a last resort when ROM hashes aren't present
            if (crc32 == null)
            {
                crc32 = data.GetHash(HashFlags.FileHash | HashFlags.CRC32);
                if (crc32 != null)
                {
                    builder.AddData(general, RomHash.GetHashName(HashFlags.FileHash | HashFlags.CRC32), Hex.FormatHex(crc32.Value));
                }
            }
            if (sha1 == null)
            {
                sha1 = data.GetHash(HashFlags.FileHash | HashFlags.SHA1);
                if (sha1 != null)
                {
                    builder.AddData(general, RomHash.GetHashName(HashFlags.FileHash | HashFlags.SHA1), Hex.FormatHex(sha1.Value));
                }
            }

            for (int i = 0; i < data.DatabaseMatches.Count; i++)
            {
                var match = data.DatabaseMatches[i];
                builder.AddData(general, match.Database.Name + " entry", match.Entry.name);
            }

            for (int i = 0; i < data.Hashes.Count; i++)
            {
                builder.AddData(
                    RomExDataBuilder.HashesCat,
                    RomHash.GetHashName(data.Hashes[i].Type),
                    Hex.FormatHex(data.Hashes[i].Value));
            }
        }
Пример #3
0
        /// <summary>
        /// Attempts to find the specified hash and append it to the string builder for RHDN-specific output.
        /// </summary>
        /// <param name="hashtype">The hash type (i.e. CRC32/MD5/SHA1). File/ROM/PRG/CHR should NOT be specified.</param>
        /// <returns>True if ANYTHING was appended to the string builder.</returns>
        /// <param name="rom"></param>
        /// <param name="sb"></param>
        private static bool AddHashToSB(StringBuilder sb, RomData rom, HashFlags hashtype)
        {
            string hashname = RomHash.GetHashName(HashFlags.RomHash | hashtype);
            var    hash     = rom.GetHash(HashFlags.RomHash | hashtype);

            if (hash == null)
            {
                hashname = hashname = RomHash.GetHashName(HashFlags.FileHash | hashtype);;
                hash     = rom.GetHash(HashFlags.FileHash | hashtype);
            }

            if (hash == null)
            {
                return(false);
            }

            sb.AppendLine(hashname + ": " + Hex.FormatHex(hash.Value));
            return(true);
        }