initial commit

This commit is contained in:
what 2021-07-26 13:04:16 -07:00
commit 1b60743303
274 changed files with 25866 additions and 0 deletions

View file

@ -0,0 +1,607 @@
// Decompiled with JetBrains decompiler
// Type: SEGATools.HashAlgorithm.ECC
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
// MVID: D631183F-57B1-40A1-B502-5364D288307A
// Assembly location: SEGATools.dll
using ImageReader.DiscSectors;
using System;
namespace SEGATools.HashAlgorithm
{
public static class ECC
{
private static readonly byte[] ECC_F_LOOKUP_TABLE = new byte[256]
{
(byte) 0,
(byte) 2,
(byte) 4,
(byte) 6,
(byte) 8,
(byte) 10,
(byte) 12,
(byte) 14,
(byte) 16,
(byte) 18,
(byte) 20,
(byte) 22,
(byte) 24,
(byte) 26,
(byte) 28,
(byte) 30,
(byte) 32,
(byte) 34,
(byte) 36,
(byte) 38,
(byte) 40,
(byte) 42,
(byte) 44,
(byte) 46,
(byte) 48,
(byte) 50,
(byte) 52,
(byte) 54,
(byte) 56,
(byte) 58,
(byte) 60,
(byte) 62,
(byte) 64,
(byte) 66,
(byte) 68,
(byte) 70,
(byte) 72,
(byte) 74,
(byte) 76,
(byte) 78,
(byte) 80,
(byte) 82,
(byte) 84,
(byte) 86,
(byte) 88,
(byte) 90,
(byte) 92,
(byte) 94,
(byte) 96,
(byte) 98,
(byte) 100,
(byte) 102,
(byte) 104,
(byte) 106,
(byte) 108,
(byte) 110,
(byte) 112,
(byte) 114,
(byte) 116,
(byte) 118,
(byte) 120,
(byte) 122,
(byte) 124,
(byte) 126,
(byte) 128,
(byte) 130,
(byte) 132,
(byte) 134,
(byte) 136,
(byte) 138,
(byte) 140,
(byte) 142,
(byte) 144,
(byte) 146,
(byte) 148,
(byte) 150,
(byte) 152,
(byte) 154,
(byte) 156,
(byte) 158,
(byte) 160,
(byte) 162,
(byte) 164,
(byte) 166,
(byte) 168,
(byte) 170,
(byte) 172,
(byte) 174,
(byte) 176,
(byte) 178,
(byte) 180,
(byte) 182,
(byte) 184,
(byte) 186,
(byte) 188,
(byte) 190,
(byte) 192,
(byte) 194,
(byte) 196,
(byte) 198,
(byte) 200,
(byte) 202,
(byte) 204,
(byte) 206,
(byte) 208,
(byte) 210,
(byte) 212,
(byte) 214,
(byte) 216,
(byte) 218,
(byte) 220,
(byte) 222,
(byte) 224,
(byte) 226,
(byte) 228,
(byte) 230,
(byte) 232,
(byte) 234,
(byte) 236,
(byte) 238,
(byte) 240,
(byte) 242,
(byte) 244,
(byte) 246,
(byte) 248,
(byte) 250,
(byte) 252,
(byte) 254,
(byte) 29,
(byte) 31,
(byte) 25,
(byte) 27,
(byte) 21,
(byte) 23,
(byte) 17,
(byte) 19,
(byte) 13,
(byte) 15,
(byte) 9,
(byte) 11,
(byte) 5,
(byte) 7,
(byte) 1,
(byte) 3,
(byte) 61,
(byte) 63,
(byte) 57,
(byte) 59,
(byte) 53,
(byte) 55,
(byte) 49,
(byte) 51,
(byte) 45,
(byte) 47,
(byte) 41,
(byte) 43,
(byte) 37,
(byte) 39,
(byte) 33,
(byte) 35,
(byte) 93,
(byte) 95,
(byte) 89,
(byte) 91,
(byte) 85,
(byte) 87,
(byte) 81,
(byte) 83,
(byte) 77,
(byte) 79,
(byte) 73,
(byte) 75,
(byte) 69,
(byte) 71,
(byte) 65,
(byte) 67,
(byte) 125,
(byte) 127,
(byte) 121,
(byte) 123,
(byte) 117,
(byte) 119,
(byte) 113,
(byte) 115,
(byte) 109,
(byte) 111,
(byte) 105,
(byte) 107,
(byte) 101,
(byte) 103,
(byte) 97,
(byte) 99,
(byte) 157,
(byte) 159,
(byte) 153,
(byte) 155,
(byte) 149,
(byte) 151,
(byte) 145,
(byte) 147,
(byte) 141,
(byte) 143,
(byte) 137,
(byte) 139,
(byte) 133,
(byte) 135,
(byte) 129,
(byte) 131,
(byte) 189,
(byte) 191,
(byte) 185,
(byte) 187,
(byte) 181,
(byte) 183,
(byte) 177,
(byte) 179,
(byte) 173,
(byte) 175,
(byte) 169,
(byte) 171,
(byte) 165,
(byte) 167,
(byte) 161,
(byte) 163,
(byte) 221,
(byte) 223,
(byte) 217,
(byte) 219,
(byte) 213,
(byte) 215,
(byte) 209,
(byte) 211,
(byte) 205,
(byte) 207,
(byte) 201,
(byte) 203,
(byte) 197,
(byte) 199,
(byte) 193,
(byte) 195,
(byte) 253,
byte.MaxValue,
(byte) 249,
(byte) 251,
(byte) 245,
(byte) 247,
(byte) 241,
(byte) 243,
(byte) 237,
(byte) 239,
(byte) 233,
(byte) 235,
(byte) 229,
(byte) 231,
(byte) 225,
(byte) 227
};
private static readonly byte[] ECC_B_LOOKUP_TABLE = new byte[256]
{
(byte) 0,
(byte) 244,
(byte) 245,
(byte) 1,
(byte) 247,
(byte) 3,
(byte) 2,
(byte) 246,
(byte) 243,
(byte) 7,
(byte) 6,
(byte) 242,
(byte) 4,
(byte) 240,
(byte) 241,
(byte) 5,
(byte) 251,
(byte) 15,
(byte) 14,
(byte) 250,
(byte) 12,
(byte) 248,
(byte) 249,
(byte) 13,
(byte) 8,
(byte) 252,
(byte) 253,
(byte) 9,
byte.MaxValue,
(byte) 11,
(byte) 10,
(byte) 254,
(byte) 235,
(byte) 31,
(byte) 30,
(byte) 234,
(byte) 28,
(byte) 232,
(byte) 233,
(byte) 29,
(byte) 24,
(byte) 236,
(byte) 237,
(byte) 25,
(byte) 239,
(byte) 27,
(byte) 26,
(byte) 238,
(byte) 16,
(byte) 228,
(byte) 229,
(byte) 17,
(byte) 231,
(byte) 19,
(byte) 18,
(byte) 230,
(byte) 227,
(byte) 23,
(byte) 22,
(byte) 226,
(byte) 20,
(byte) 224,
(byte) 225,
(byte) 21,
(byte) 203,
(byte) 63,
(byte) 62,
(byte) 202,
(byte) 60,
(byte) 200,
(byte) 201,
(byte) 61,
(byte) 56,
(byte) 204,
(byte) 205,
(byte) 57,
(byte) 207,
(byte) 59,
(byte) 58,
(byte) 206,
(byte) 48,
(byte) 196,
(byte) 197,
(byte) 49,
(byte) 199,
(byte) 51,
(byte) 50,
(byte) 198,
(byte) 195,
(byte) 55,
(byte) 54,
(byte) 194,
(byte) 52,
(byte) 192,
(byte) 193,
(byte) 53,
(byte) 32,
(byte) 212,
(byte) 213,
(byte) 33,
(byte) 215,
(byte) 35,
(byte) 34,
(byte) 214,
(byte) 211,
(byte) 39,
(byte) 38,
(byte) 210,
(byte) 36,
(byte) 208,
(byte) 209,
(byte) 37,
(byte) 219,
(byte) 47,
(byte) 46,
(byte) 218,
(byte) 44,
(byte) 216,
(byte) 217,
(byte) 45,
(byte) 40,
(byte) 220,
(byte) 221,
(byte) 41,
(byte) 223,
(byte) 43,
(byte) 42,
(byte) 222,
(byte) 139,
(byte) 127,
(byte) 126,
(byte) 138,
(byte) 124,
(byte) 136,
(byte) 137,
(byte) 125,
(byte) 120,
(byte) 140,
(byte) 141,
(byte) 121,
(byte) 143,
(byte) 123,
(byte) 122,
(byte) 142,
(byte) 112,
(byte) 132,
(byte) 133,
(byte) 113,
(byte) 135,
(byte) 115,
(byte) 114,
(byte) 134,
(byte) 131,
(byte) 119,
(byte) 118,
(byte) 130,
(byte) 116,
(byte) 128,
(byte) 129,
(byte) 117,
(byte) 96,
(byte) 148,
(byte) 149,
(byte) 97,
(byte) 151,
(byte) 99,
(byte) 98,
(byte) 150,
(byte) 147,
(byte) 103,
(byte) 102,
(byte) 146,
(byte) 100,
(byte) 144,
(byte) 145,
(byte) 101,
(byte) 155,
(byte) 111,
(byte) 110,
(byte) 154,
(byte) 108,
(byte) 152,
(byte) 153,
(byte) 109,
(byte) 104,
(byte) 156,
(byte) 157,
(byte) 105,
(byte) 159,
(byte) 107,
(byte) 106,
(byte) 158,
(byte) 64,
(byte) 180,
(byte) 181,
(byte) 65,
(byte) 183,
(byte) 67,
(byte) 66,
(byte) 182,
(byte) 179,
(byte) 71,
(byte) 70,
(byte) 178,
(byte) 68,
(byte) 176,
(byte) 177,
(byte) 69,
(byte) 187,
(byte) 79,
(byte) 78,
(byte) 186,
(byte) 76,
(byte) 184,
(byte) 185,
(byte) 77,
(byte) 72,
(byte) 188,
(byte) 189,
(byte) 73,
(byte) 191,
(byte) 75,
(byte) 74,
(byte) 190,
(byte) 171,
(byte) 95,
(byte) 94,
(byte) 170,
(byte) 92,
(byte) 168,
(byte) 169,
(byte) 93,
(byte) 88,
(byte) 172,
(byte) 173,
(byte) 89,
(byte) 175,
(byte) 91,
(byte) 90,
(byte) 174,
(byte) 80,
(byte) 164,
(byte) 165,
(byte) 81,
(byte) 167,
(byte) 83,
(byte) 82,
(byte) 166,
(byte) 163,
(byte) 87,
(byte) 86,
(byte) 162,
(byte) 84,
(byte) 160,
(byte) 161,
(byte) 85
};
internal static int ComputeECCBlock(
byte[] src,
int srcOffset,
byte[] dest,
int destOffset,
uint majorCount,
uint minorCount,
uint majorMult,
uint minorInc)
{
uint num1 = majorCount * minorCount;
for (uint index1 = 0; index1 < majorCount; ++index1)
{
uint num2 = (uint) ((int) (index1 >> 1) * (int) majorMult + ((int) index1 & 1));
byte num3 = 0;
byte num4 = 0;
for (uint index2 = 0; index2 < minorCount; ++index2)
{
byte num5 = src[(long) srcOffset + (long) num2];
num2 += minorInc;
if (num2 >= num1)
num2 -= num1;
byte num6 = (byte) ((uint) num3 ^ (uint) num5);
num4 ^= num5;
num3 = ECC.ECC_F_LOOKUP_TABLE[(int) num6];
}
byte num7 = ECC.ECC_B_LOOKUP_TABLE[(int) ECC.ECC_F_LOOKUP_TABLE[(int) num3] ^ (int) num4];
dest[(long) destOffset + (long) index1] = num7;
dest[(long) destOffset + (long) index1 + (long) majorCount] = (byte) ((uint) num7 ^ (uint) num4);
}
return (int) majorCount * 2;
}
internal static void CheckBufferSize(byte[] buffer)
{
if (buffer == null)
throw new ArgumentNullException(nameof (buffer));
if (buffer.Length != DiscSectorCommon.RawSectorSize)
throw new ArgumentException(string.Format("length must be {0} bytes", (object) DiscSectorCommon.RawSectorSize), nameof (buffer));
}
public interface ECCParityVectorAlgorithm
{
void ComputeVectors(byte[] buffer);
}
public class PParity : ECC.ECCParityVectorAlgorithm
{
public static readonly int P_PARITY_VECTOR_LENGTH = ECC.PParity.P_PARITY_VECTORS * 2 * 2;
public static readonly int P_PARITY_VECTOR_OFFSET = 2076;
private static readonly int P_PARITY_VECTORS = 43;
private static readonly int P_PARITY_DATA_OFFSET = 12;
public void ComputeVectors(byte[] buffer)
{
ECC.CheckBufferSize(buffer);
ECC.ComputeECCBlock(buffer, ECC.PParity.P_PARITY_DATA_OFFSET, buffer, ECC.PParity.P_PARITY_VECTOR_OFFSET, (uint) (ECC.PParity.P_PARITY_VECTORS * 2), 24U, 2U, 86U);
}
}
public class QParity : ECC.ECCParityVectorAlgorithm
{
public static readonly int Q_PARITY_VECTOR_LENGTH = ECC.QParity.Q_PARITY_VECTORS * 2 * 2;
public static readonly int Q_PARITY_VECTOR_OFFSET = 2248;
private static readonly int Q_PARITY_VECTORS = 26;
private static readonly int Q_PARITY_DATA_OFFSET = 12;
public void ComputeVectors(byte[] buffer)
{
ECC.CheckBufferSize(buffer);
ECC.ComputeECCBlock(buffer, ECC.QParity.Q_PARITY_DATA_OFFSET, buffer, ECC.QParity.Q_PARITY_VECTOR_OFFSET, (uint) (ECC.QParity.Q_PARITY_VECTORS * 2), 43U, 86U, 88U);
}
}
}
}

View file

@ -0,0 +1,322 @@
// Decompiled with JetBrains decompiler
// Type: SEGATools.HashAlgorithm.EDC
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
// MVID: D631183F-57B1-40A1-B502-5364D288307A
// Assembly location: SEGATools.dll
using System;
namespace SEGATools.HashAlgorithm
{
public class EDC : System.Security.Cryptography.HashAlgorithm
{
public static readonly int SECTOR_DATA_LENGTH_FOR_EDC_COMPUTATION = 2064;
public static readonly int EDC_DATA_OFFSET = EDC.SECTOR_DATA_LENGTH_FOR_EDC_COMPUTATION;
public static readonly int EDC_DATA_LENGTH = 4;
private static readonly uint EDC_POLYNOMIAL = 3623976961;
private static readonly uint[] EDC_CRC_LOOKUP_TABLE = new uint[256]
{
0U,
2425422081U,
2434859521U,
28312320U,
2453734401U,
47187200U,
56624640U,
2482046721U,
2491484161U,
68159744U,
94374400U,
2503019265U,
113249280U,
2521894145U,
2548108801U,
124784384U,
2566983681U,
160436480U,
136319488U,
2561741569U,
188748800U,
2614170881U,
2590053889U,
183506688U,
226498560U,
2635143425U,
2627803649U,
204479232U,
2680232961U,
256908544U,
249568768U,
2658213633U,
2181111809U,
311435520U,
320872960U,
2209424129U,
272638976U,
2161190145U,
2170627585U,
300951296U,
377497600U,
2249271553U,
2275486209U,
389032704U,
2227252225U,
340798720U,
367013376U,
2238787329U,
452997120U,
2341548289U,
2317431297U,
447755008U,
2302751745U,
433075456U,
408958464U,
2297509633U,
2407610369U,
521156864U,
513817088U,
2385591041U,
499137536U,
2370911489U,
2363571713U,
477118208U,
3019980801U,
613433600U,
622871040U,
3048293121U,
641745920U,
3067168001U,
3076605441U,
670058240U,
545277952U,
2953922817U,
2980137473U,
556813056U,
2999012353U,
575687936U,
601902592U,
3010547457U,
754995200U,
3180417281U,
3156300289U,
749753088U,
3208729601U,
802182400U,
778065408U,
3203487489U,
3112261633U,
688937216U,
681597440U,
3090242305U,
734026752U,
3142671617U,
3135331841U,
712007424U,
905994240U,
2794545409U,
2803982849U,
934306560U,
2755748865U,
886072576U,
895510016U,
2784061185U,
2726389761U,
839936256U,
866150912U,
2737924865U,
817916928U,
2689690881U,
2715905537U,
829452032U,
2936107009U,
1066430720U,
1042313728U,
2930864897U,
1027634176U,
2916185345U,
2892068353U,
1022392064U,
998275072U,
2870049025U,
2862709249U,
976255744U,
2848029697U,
961576192U,
954236416U,
2826010369U,
3623976961U,
1217429760U,
1226867200U,
3652289281U,
1245742080U,
3671164161U,
3680601601U,
1274054400U,
1283491840U,
3692136705U,
3718351361U,
1295026944U,
3737226241U,
1313901824U,
1340116480U,
3748761345U,
1090555904U,
3515977985U,
3491860993U,
1085313792U,
3544290305U,
1137743104U,
1113626112U,
3539048193U,
3582040065U,
1158715648U,
1151375872U,
3560020737U,
1203805184U,
3612450049U,
3605110273U,
1181785856U,
1509990400U,
3398541569U,
3407979009U,
1538302720U,
3359745025U,
1490068736U,
1499506176U,
3388057345U,
3464603649U,
1578150144U,
1604364800U,
3476138753U,
1556130816U,
3427904769U,
3454119425U,
1567665920U,
3271667713U,
1401991424U,
1377874432U,
3266425601U,
1363194880U,
3251746049U,
3227629057U,
1357952768U,
1468053504U,
3339827457U,
3332487681U,
1446034176U,
3317808129U,
1431354624U,
1424014848U,
3295788801U,
1811988480U,
4237410561U,
4246848001U,
1840300800U,
4265722881U,
1859175680U,
1868613120U,
4294035201U,
4169254913U,
1745930496U,
1772145152U,
4180790017U,
1791020032U,
4199664897U,
4225879553U,
1802555136U,
4110536705U,
1703989504U,
1679872512U,
4105294593U,
1732301824U,
4157723905U,
4133606913U,
1727059712U,
1635833856U,
4044478721U,
4037138945U,
1613814528U,
4089568257U,
1666243840U,
1658904064U,
4067548929U,
3993100289U,
2123424000U,
2132861440U,
4021412609U,
2084627456U,
3973178625U,
3982616065U,
2112939776U,
2055268352U,
3927042305U,
3953256961U,
2066803456U,
3905022977U,
2018569472U,
2044784128U,
3916558081U,
1996550144U,
3885101313U,
3860984321U,
1991308032U,
3846304769U,
1976628480U,
1952511488U,
3841062657U,
3816945665U,
1930492160U,
1923152384U,
3794926337U,
1908472832U,
3780246785U,
3772907009U,
1886453504U
};
private uint hash;
protected override void HashCore(byte[] array, int ibStart, int cbSize)
{
EDC.CheckBufferSize(array, ibStart, cbSize);
uint num1 = 0;
for (int index = ibStart; index < ibStart + cbSize; ++index)
{
uint num2 = (uint) (((int) num1 ^ (int) array[ibStart + index]) & (int) byte.MaxValue);
num1 = EDC.EDC_CRC_LOOKUP_TABLE[(int) num2] ^ num1 >> 8;
}
this.hash = num1;
}
protected override byte[] HashFinal() => BitConverter.GetBytes(this.hash);
public override void Initialize()
{
}
private static uint[] GenerateCRCLookUpTable()
{
uint[] numArray = new uint[256];
for (uint index1 = 0; (long) index1 < (long) numArray.Length; ++index1)
{
uint num = index1;
for (int index2 = 8; index2 > 0; --index2)
{
if (((int) num & 1) != 0)
num = num >> 1 ^ EDC.EDC_POLYNOMIAL;
else
num >>= 1;
}
numArray[(int) index1] = num;
}
return numArray;
}
private static void CheckBufferSize(byte[] buffer, int ibStart, int cbSize)
{
if (buffer == null)
throw new ArgumentNullException(nameof (buffer));
if (buffer.Length - ibStart < cbSize)
throw new ArgumentException("buffer too small");
}
}
}