More Util methods -> extension methods
This commit is contained in:
parent
bf88be8c72
commit
fd80c62cdb
|
@ -2,7 +2,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common.BufferExtensions;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
// IDEA: put filesizes in DB too. then scans can go real quick by only scanning filesizes that match (and then scanning filesizes that dont match, in case of an emergency)
|
// IDEA: put filesizes in DB too. then scans can go real quick by only scanning filesizes that match (and then scanning filesizes that dont match, in case of an emergency)
|
||||||
|
@ -81,7 +81,7 @@ namespace BizHawk.Client.Common
|
||||||
fs.Read(buffer, 0, (int)len);
|
fs.Read(buffer, 0, (int)len);
|
||||||
}
|
}
|
||||||
|
|
||||||
rff.Hash = Util.Hash_SHA1(buffer, 0, (int)len);
|
rff.Hash = buffer.HashSHA1(0, (int)len);
|
||||||
dict[rff.Hash] = rff;
|
dict[rff.Hash] = rff;
|
||||||
_files.Add(rff);
|
_files.Add(rff);
|
||||||
return rff;
|
return rff;
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
|
using BizHawk.Common.BufferExtensions;
|
||||||
using BizHawk.Common.IOExtensions;
|
using BizHawk.Common.IOExtensions;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.GI.Hash = Util.Hash_SHA1(HashStream.GetBuffer(), 0, (int)HashStream.Length);
|
ret.GI.Hash = HashStream.GetBuffer().HashSHA1(0, (int)HashStream.Length);
|
||||||
HashStream.Close();
|
HashStream.Close();
|
||||||
if (OriginalIndex != null)
|
if (OriginalIndex != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,10 +8,13 @@ using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using BizHawk.Client.Common;
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
|
using BizHawk.Common.BufferExtensions;
|
||||||
using BizHawk.Common.IOExtensions;
|
using BizHawk.Common.IOExtensions;
|
||||||
|
|
||||||
|
using BizHawk.Client.Common;
|
||||||
using BizHawk.Bizware.BizwareGL;
|
using BizHawk.Bizware.BizwareGL;
|
||||||
|
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
||||||
using BizHawk.Emulation.Cores.Atari.Atari2600;
|
using BizHawk.Emulation.Cores.Atari.Atari2600;
|
||||||
|
@ -3080,8 +3083,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Global.Emulator.CoreComm.RomStatusDetails = string.Format(
|
Global.Emulator.CoreComm.RomStatusDetails = string.Format(
|
||||||
"{0}\r\nSHA1:{1}\r\nMD5:{2}\r\n",
|
"{0}\r\nSHA1:{1}\r\nMD5:{2}\r\n",
|
||||||
loader.Game.Name,
|
loader.Game.Name,
|
||||||
Util.Hash_SHA1(loader.Rom.RomData),
|
loader.Rom.RomData.HashSHA1(),
|
||||||
Util.Hash_MD5(loader.Rom.RomData));
|
loader.Rom.RomData.HashMD5());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Global.Emulator.BoardName != null)
|
if (Global.Emulator.BoardName != null)
|
||||||
|
|
|
@ -8,9 +8,8 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common.BufferExtensions;
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
using BizHawk.Emulation.Cores.Nintendo.SNES;
|
|
||||||
|
|
||||||
using BizHawk.Emulation.Cores.PCEngine;
|
using BizHawk.Emulation.Cores.PCEngine;
|
||||||
using BizHawk.Emulation.Common.Components;
|
using BizHawk.Emulation.Common.Components;
|
||||||
|
@ -93,7 +92,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
foreach (var s in waveform)
|
foreach (var s in waveform)
|
||||||
bw.Write(s);
|
bw.Write(s);
|
||||||
bw.Flush();
|
bw.Flush();
|
||||||
string md5 = Util.Hash_MD5(waveformTemp);
|
string md5 = waveformTemp.HashMD5();
|
||||||
|
|
||||||
if (!PSGEntryTable.ContainsKey(md5))
|
if (!PSGEntryTable.ContainsKey(md5))
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace BizHawk.Common.BufferExtensions
|
namespace BizHawk.Common.BufferExtensions
|
||||||
{
|
{
|
||||||
|
@ -183,6 +184,34 @@ namespace BizHawk.Common.BufferExtensions
|
||||||
return (result >= pattern.Length - 1);
|
return (result >= pattern.Length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string HashMD5(this byte[] data, int offset, int len)
|
||||||
|
{
|
||||||
|
using (var md5 = MD5.Create())
|
||||||
|
{
|
||||||
|
md5.ComputeHash(data, offset, len);
|
||||||
|
return md5.Hash.BytesToHexString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string HashMD5(this byte[] data)
|
||||||
|
{
|
||||||
|
return HashMD5(data, 0, data.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string HashSHA1(this byte[] data, int offset, int len)
|
||||||
|
{
|
||||||
|
using (var sha1 = SHA1.Create())
|
||||||
|
{
|
||||||
|
sha1.ComputeHash(data, offset, len);
|
||||||
|
return sha1.Hash.BytesToHexString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string HashSHA1(this byte[] data)
|
||||||
|
{
|
||||||
|
return HashSHA1(data, 0, data.Length);
|
||||||
|
}
|
||||||
|
|
||||||
#region Helpers
|
#region Helpers
|
||||||
|
|
||||||
private static int Hex2Int(char c)
|
private static int Hex2Int(char c)
|
||||||
|
|
|
@ -20,34 +20,6 @@ namespace BizHawk.Common
|
||||||
|
|
||||||
public static char* HexConvPtr { get; set; }
|
public static char* HexConvPtr { get; set; }
|
||||||
|
|
||||||
public static string Hash_MD5(byte[] data, int offset, int len)
|
|
||||||
{
|
|
||||||
using (var md5 = System.Security.Cryptography.MD5.Create())
|
|
||||||
{
|
|
||||||
md5.ComputeHash(data, offset, len);
|
|
||||||
return md5.Hash.BytesToHexString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string Hash_MD5(byte[] data)
|
|
||||||
{
|
|
||||||
return Hash_MD5(data, 0, data.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string Hash_SHA1(byte[] data, int offset, int len)
|
|
||||||
{
|
|
||||||
using (var sha1 = System.Security.Cryptography.SHA1.Create())
|
|
||||||
{
|
|
||||||
sha1.ComputeHash(data, offset, len);
|
|
||||||
return sha1.Hash.BytesToHexString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string Hash_SHA1(byte[] data)
|
|
||||||
{
|
|
||||||
return Hash_SHA1(data, 0, data.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsPowerOfTwo(int x)
|
public static bool IsPowerOfTwo(int x)
|
||||||
{
|
{
|
||||||
if (x == 0 || x == 1)
|
if (x == 0 || x == 1)
|
||||||
|
|
|
@ -217,13 +217,13 @@ namespace BizHawk.Emulation.Common
|
||||||
return new GameInfo(cgi);
|
return new GameInfo(cgi);
|
||||||
}
|
}
|
||||||
|
|
||||||
hash = Util.Hash_MD5(romData);
|
hash = romData.HashMD5();
|
||||||
if (db.TryGetValue(hash, out cgi))
|
if (db.TryGetValue(hash, out cgi))
|
||||||
{
|
{
|
||||||
return new GameInfo(cgi);
|
return new GameInfo(cgi);
|
||||||
}
|
}
|
||||||
|
|
||||||
hash = Util.Hash_SHA1(romData);
|
hash = romData.HashSHA1();
|
||||||
if (db.TryGetValue(hash, out cgi))
|
if (db.TryGetValue(hash, out cgi))
|
||||||
{
|
{
|
||||||
return new GameInfo(cgi);
|
return new GameInfo(cgi);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
using BizHawk.Common.NumberExtensions;
|
using BizHawk.Common.NumberExtensions;
|
||||||
|
using BizHawk.Common.BufferExtensions;
|
||||||
|
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
using BizHawk.Emulation.Cores.Components.M6502;
|
using BizHawk.Emulation.Cores.Components.M6502;
|
||||||
|
|
||||||
|
@ -311,8 +313,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
||||||
string.Format(
|
string.Format(
|
||||||
"{0}\r\nSHA1:{1}\r\nMD5:{2}\r\nMapper Impl \"{3}\"",
|
"{0}\r\nSHA1:{1}\r\nMD5:{2}\r\nMapper Impl \"{3}\"",
|
||||||
this._game.Name,
|
this._game.Name,
|
||||||
Util.Hash_SHA1(Rom),
|
Rom.HashSHA1(),
|
||||||
Util.Hash_MD5(Rom),
|
Rom.HashMD5(),
|
||||||
_mapper.GetType());
|
_mapper.GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
|
using BizHawk.Common.BufferExtensions;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
||||||
|
@ -165,7 +166,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
||||||
Name = _game.Name,
|
Name = _game.Name,
|
||||||
System = "A26",
|
System = "A26",
|
||||||
MetaData = "m=" + _mapper.GetType().ToString().Split('.').ToList().Last(),
|
MetaData = "m=" + _mapper.GetType().ToString().Split('.').ToList().Last(),
|
||||||
Hash = Util.Hash_SHA1(Rom),
|
Hash = Rom.HashSHA1(),
|
||||||
Region = _game.Region,
|
Region = _game.Region,
|
||||||
Status = RomStatus.Unknown
|
Status = RomStatus.Unknown
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common.BufferExtensions;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
||||||
{
|
{
|
||||||
|
@ -145,8 +146,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
||||||
|
|
||||||
CoreComm.RomStatusDetails = string.Format("{0}\r\nSHA1:{1}\r\nMD5:{2}\r\n",
|
CoreComm.RomStatusDetails = string.Format("{0}\r\nSHA1:{1}\r\nMD5:{2}\r\n",
|
||||||
game.Name,
|
game.Name,
|
||||||
Util.Hash_SHA1(romdata), Util.Hash_MD5(romdata)
|
romdata.HashSHA1(),
|
||||||
);
|
romdata.HashMD5());
|
||||||
|
|
||||||
{
|
{
|
||||||
byte[] buff = new byte[32];
|
byte[] buff = new byte[32];
|
||||||
|
|
|
@ -4,9 +4,11 @@ using System.IO;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Common.BufferExtensions;
|
||||||
//TODO - redo all timekeeping in terms of master clock
|
|
||||||
|
|
||||||
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
|
//TODO - redo all timekeeping in terms of master clock
|
||||||
namespace BizHawk.Emulation.Cores.Nintendo.NES
|
namespace BizHawk.Emulation.Cores.Nintendo.NES
|
||||||
{
|
{
|
||||||
[CoreAttributes(
|
[CoreAttributes(
|
||||||
|
@ -546,9 +548,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
||||||
|
|
||||||
//now that we know we have an iNES header, we can try to ignore it.
|
//now that we know we have an iNES header, we can try to ignore it.
|
||||||
|
|
||||||
hash_sha1 = "sha1:" + Util.Hash_SHA1(file, 16, file.Length - 16);
|
hash_sha1 = "sha1:" + file.HashSHA1(16, file.Length - 16);
|
||||||
hash_sha1_several.Add(hash_sha1);
|
hash_sha1_several.Add(hash_sha1);
|
||||||
hash_md5 = "md5:" + Util.Hash_MD5(file, 16, file.Length - 16);
|
hash_md5 = "md5:" + file.HashMD5(16, file.Length - 16);
|
||||||
|
|
||||||
LoadWriteLine("Found iNES header:");
|
LoadWriteLine("Found iNES header:");
|
||||||
LoadWriteLine(iNesHeaderInfo.ToString());
|
LoadWriteLine(iNesHeaderInfo.ToString());
|
||||||
|
@ -572,10 +574,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
||||||
msTemp.Write(file, 16 + 16 * 1024, iNesHeaderInfo.chr_size * 1024); //add chr
|
msTemp.Write(file, 16 + 16 * 1024, iNesHeaderInfo.chr_size * 1024); //add chr
|
||||||
msTemp.Flush();
|
msTemp.Flush();
|
||||||
var bytes = msTemp.ToArray();
|
var bytes = msTemp.ToArray();
|
||||||
var hash = "sha1:" + Util.Hash_SHA1(bytes, 0, bytes.Length);
|
var hash = "sha1:" + bytes.HashSHA1(0, bytes.Length);
|
||||||
LoadWriteLine(" PRG (8KB) + CHR hash: {0}", hash);
|
LoadWriteLine(" PRG (8KB) + CHR hash: {0}", hash);
|
||||||
hash_sha1_several.Add(hash);
|
hash_sha1_several.Add(hash);
|
||||||
hash = "md5:" + Util.Hash_MD5(bytes, 0, bytes.Length);
|
hash = "md5:" + bytes.HashMD5(0, bytes.Length);
|
||||||
LoadWriteLine(" PRG (8KB) + CHR hash: {0}", hash);
|
LoadWriteLine(" PRG (8KB) + CHR hash: {0}", hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common.BufferExtensions;
|
||||||
|
|
||||||
namespace BizHawk.Emulation.Cores.Nintendo.NES
|
namespace BizHawk.Emulation.Cores.Nintendo.NES
|
||||||
{
|
{
|
||||||
|
@ -80,13 +80,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chunks.TryGetValue("MAPR", out tmp))
|
if (chunks.TryGetValue("MAPR", out tmp))
|
||||||
|
{
|
||||||
ci.board_type = Encoding.ASCII.GetString(tmp);
|
ci.board_type = Encoding.ASCII.GetString(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
ci.board_type = ci.board_type.TrimEnd('\0');
|
ci.board_type = ci.board_type.TrimEnd('\0');
|
||||||
ci.board_type = "UNIF_" + ci.board_type;
|
ci.board_type = "UNIF_" + ci.board_type;
|
||||||
|
|
||||||
if (chunks.TryGetValue("BATR", out tmp))
|
if (chunks.TryGetValue("BATR", out tmp))
|
||||||
|
{
|
||||||
// apparently, this chunk just existing means battery is yes
|
// apparently, this chunk just existing means battery is yes
|
||||||
ci.wram_battery = true;
|
ci.wram_battery = true;
|
||||||
|
}
|
||||||
|
|
||||||
// is there any way using System.Security.Cryptography.SHA1 to compute the hash of
|
// is there any way using System.Security.Cryptography.SHA1 to compute the hash of
|
||||||
// prg concatentated with chr? i couldn't figure it out, so this implementation is dumb
|
// prg concatentated with chr? i couldn't figure it out, so this implementation is dumb
|
||||||
|
@ -96,7 +101,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
||||||
ms.Write(chrrom, 0, chrrom.Length);
|
ms.Write(chrrom, 0, chrrom.Length);
|
||||||
ms.Close();
|
ms.Close();
|
||||||
byte[] all = ms.ToArray();
|
byte[] all = ms.ToArray();
|
||||||
ci.sha1 = "sha1:" + Util.Hash_SHA1(all, 0, all.Length);
|
ci.sha1 = "sha1:" + all.HashSHA1(0, all.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// other code will expect this
|
// other code will expect this
|
||||||
|
|
|
@ -333,7 +333,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
|
||||||
if (game["SGB"])
|
if (game["SGB"])
|
||||||
{
|
{
|
||||||
sgbRomData = CoreComm.CoreFileProvider.GetFirmware("SNES", "Rom_SGB", true, "SGB Rom is required for SGB emulation.");
|
sgbRomData = CoreComm.CoreFileProvider.GetFirmware("SNES", "Rom_SGB", true, "SGB Rom is required for SGB emulation.");
|
||||||
game.FirmwareHash = Util.Hash_SHA1(sgbRomData);
|
game.FirmwareHash = sgbRomData.HashSHA1();
|
||||||
}
|
}
|
||||||
|
|
||||||
ScanlineHookManager = new MyScanlineHookManager(this);
|
ScanlineHookManager = new MyScanlineHookManager(this);
|
||||||
|
|
|
@ -4,8 +4,11 @@ using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
|
using BizHawk.Common.BufferExtensions;
|
||||||
|
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
using BizHawk.Emulation.Common.Components;
|
using BizHawk.Emulation.Common.Components;
|
||||||
|
|
||||||
using BizHawk.Emulation.Cores.Components.H6280;
|
using BizHawk.Emulation.Cores.Components.H6280;
|
||||||
using BizHawk.Emulation.DiscSystem;
|
using BizHawk.Emulation.DiscSystem;
|
||||||
|
|
||||||
|
@ -131,7 +134,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
game.FirmwareHash = Util.Hash_SHA1(rom);
|
game.FirmwareHash = rom.HashSHA1();
|
||||||
|
|
||||||
Init(game, rom);
|
Init(game, rom);
|
||||||
// the default RomStatusDetails don't do anything with Disc
|
// the default RomStatusDetails don't do anything with Disc
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common.BufferExtensions;
|
||||||
|
|
||||||
//main apis for emulator core routine use
|
//main apis for emulator core routine use
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ namespace BizHawk.Emulation.DiscSystem
|
||||||
for (int s = 0; s < 512 && s < track.length_aba; s++)
|
for (int s = 0; s < 512 && s < track.length_aba; s++)
|
||||||
ReadABA_2352(track.Indexes[1].aba + s, buffer, s * 2352);
|
ReadABA_2352(track.Indexes[1].aba + s, buffer, s * 2352);
|
||||||
|
|
||||||
return Util.Hash_MD5(buffer, 0, lba_len * 2352);
|
return buffer.HashMD5(0, lba_len * 2352);
|
||||||
}
|
}
|
||||||
return "no data track found";
|
return "no data track found";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue