Exemplo n.º 1
0
            public override void CalculateHashes(byte[] rom, IHashWorkManager worker, float startProgress, float endProgress)
            {
                // Hashes are calculated using the thread pool due to the fact that NDS roms are MASSIVE

                worker.QueueTask((SimpleDelegate) delegate {
                    if (!worker.AbortPending)
                    {
                        worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.SHA256, HashFlags.FileHash, HashFlags.RomHash);
                    }
                });
                worker.QueueTask((SimpleDelegate) delegate {
                    if (!worker.AbortPending)
                    {
                        worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.SHA1, HashFlags.FileHash, HashFlags.RomHash);
                    }
                });
                worker.QueueTask((SimpleDelegate) delegate {
                    if (!worker.AbortPending)
                    {
                        worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.CRC32, HashFlags.FileHash, HashFlags.RomHash);
                    }
                });
                worker.QueueTask((SimpleDelegate) delegate {
                    if (!worker.AbortPending)
                    {
                        worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.MD5, HashFlags.FileHash, HashFlags.RomHash);
                    }
                });

                // Can not return until all hashes are ready
                worker.WaitAll();
            }
Exemplo n.º 2
0
            public override void CalculateHashes(byte[] rom, IHashWorkManager worker, float startProgress, float endProgress)
            {
                iNesHeader header = null;

                if (rom.Length > 0x10)
                {
                    header = new iNesHeader(rom, 0);
                }

                if (header != null && header.MagicNumberIsCorrect)   // Headered
                {
                    worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.FileHash);

                    // Calculate headerless hashes and PRG/CHR hashes
                    int ROMSize = header.PrgRomSize + header.ChrRomSize;
                    ROMSize = Math.Min(ROMSize, rom.Length - 0x10);

                    worker.AddHashes(rom, 0x10, ROMSize, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.RomHash);
                }
                else
                {
                    // Unheadered (file hash IS rom hash)
                    worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.FileHash, HashFlags.RomHash);
                }
            }
Exemplo n.º 3
0
            public override void CalculateHashes(byte[] rom, IHashWorkManager worker, float startProgress, float endProgress)
            {
                iNesHeader header = null;

                if (rom.Length > 0x10)
                {
                    header = new iNesHeader(rom, 0);
                }

                if (SNES.HasExternalHeader(rom))   // Headered
                {
                    worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.FileHash);

                    // Calculate headerless hashes
                    int ROMSize = rom.Length - SNES.ExternalHeaderSize;
                    ROMSize = Math.Min(ROMSize, rom.Length - SNES.ExternalHeaderSize);

                    worker.AddHashes(rom, SNES.ExternalHeaderSize, ROMSize, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.RomHash);
                }
                else
                {
                    // Unheadered (file hash IS rom hash)
                    worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.FileHash, HashFlags.RomHash);
                }
            }
Exemplo n.º 4
0
            public override void CalculateHashes(byte[] rom, IHashWorkManager worker, float startProgress, float endProgress)
            {
                if (HasFdsMagicNumber(rom))   // Headered
                {
                    worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.FileHash);

                    // Calculate headerless hashes and PRG/CHR hashes
                    int ROMSize = rom.Length - 0x10;

                    worker.AddHashes(rom, 0x10, ROMSize, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.RomHash);
                }
                else
                {
                    // Unheadered (file hash IS rom hash)
                    worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.FileHash, HashFlags.RomHash);
                }
            }
Exemplo n.º 5
0
            public override void CalculateHashes(byte[] rom, IHashWorkManager worker, float startProgress, float endProgress)
            {
                bool eHeader, iHeader, interleaved, s32X;

                iHeader = Gen.HasInternalHeader(rom, out interleaved, out eHeader, out s32X);

                byte[] binRomImage = GetBinFormat(rom);
                this.BinRomImage = new WeakReference(binRomImage);


                if (binRomImage == rom)
                {
                    worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.FileHash, HashFlags.RomHash);
                }
                else
                {
                    worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.FileHash);
                    worker.AddHashes(binRomImage, 0, binRomImage.Length, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.RomHash);
                }
            }
Exemplo n.º 6
0
 public override void CalculateHashes(byte[] rom, IHashWorkManager worker, float startProgress, float endProgress)
 {
     worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, RomHash.AllHashAlgorithms, HashFlags.FileHash, HashFlags.RomHash);
 }
Exemplo n.º 7
0
            public override void CalculateHashes(byte[] rom, IHashWorkManager worker, float startProgress, float endProgress)
            {
                // N64 hashes are calculated using the thread pool because the ROMs tend to be large

                bool byteswapped = N64.IsByteswapped(rom) == N64ByteSwap.Swapped;

                byte[] swappedRom = new byte[rom.Length];
                // Watch out for odd # of bytes!
                int len = rom.Length & (~1);

                for (int i = 0; i < len; i += 2)
                {
                    swappedRom[i]     = rom[i + 1];
                    swappedRom[i + 1] = rom[i];
                }

                HashFlags originalType = byteswapped ? HashFlags.RomHash_ByteSwap : HashFlags.RomHash;
                HashFlags swappedType  = byteswapped ? HashFlags.RomHash : HashFlags.RomHash_ByteSwap;

                worker.QueueTask((SimpleDelegate) delegate {
                    if (!worker.AbortPending)
                    {
                        worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.SHA256, originalType, HashFlags.FileHash);
                    }
                });
                worker.QueueTask((SimpleDelegate) delegate {
                    if (!worker.AbortPending)
                    {
                        worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.SHA1, originalType, HashFlags.FileHash);
                    }
                });
                worker.QueueTask((SimpleDelegate) delegate {
                    if (!worker.AbortPending)
                    {
                        worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.CRC32, originalType, HashFlags.FileHash);
                    }
                });
                worker.QueueTask((SimpleDelegate) delegate {
                    if (!worker.AbortPending)
                    {
                        worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.MD5, originalType, HashFlags.FileHash);
                    }
                });

                // We can not byte-swap the ROM while it is being hashed
                worker.WaitAll();


                worker.QueueTask((SimpleDelegate) delegate {
                    if (!worker.AbortPending)
                    {
                        worker.AddHashes(swappedRom, 0, swappedRom.Length, () => worker.AbortPending, HashFlags.SHA256, swappedType);
                    }
                });
                worker.QueueTask((SimpleDelegate) delegate {
                    if (!worker.AbortPending)
                    {
                        worker.AddHashes(swappedRom, 0, swappedRom.Length, () => worker.AbortPending, HashFlags.SHA1, swappedType);
                    }
                });
                worker.QueueTask((SimpleDelegate) delegate {
                    if (!worker.AbortPending)
                    {
                        worker.AddHashes(swappedRom, 0, swappedRom.Length, () => worker.AbortPending, HashFlags.CRC32, swappedType);
                    }
                });
                worker.QueueTask((SimpleDelegate) delegate {
                    if (!worker.AbortPending)
                    {
                        worker.AddHashes(swappedRom, 0, swappedRom.Length, () => worker.AbortPending, HashFlags.MD5, swappedType);
                    }
                });

                // We can not return until all hashes are calculated
                worker.WaitAll();
            }