diff --git a/Adler32Context.cs b/Adler32Context.cs index d320bbf..b2189d0 100644 --- a/Adler32Context.cs +++ b/Adler32Context.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System; using System.IO; using System.Text; using DiscImageChef.CommonTypes.Interfaces; @@ -83,7 +82,6 @@ namespace DiscImageChef.Checksums public byte[] Final() { uint finalSum = (uint)((sum2 << 16) | sum1); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; return BigEndianBitConverter.GetBytes(finalSum); } @@ -95,7 +93,6 @@ namespace DiscImageChef.Checksums uint finalSum = (uint)((sum2 << 16) | sum1); StringBuilder adlerOutput = new StringBuilder(); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++) adlerOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2")); @@ -132,8 +129,7 @@ namespace DiscImageChef.Checksums uint finalSum = (uint)((localSum2 << 16) | localSum1); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - hash = BigEndianBitConverter.GetBytes(finalSum); + hash = BigEndianBitConverter.GetBytes(finalSum); StringBuilder adlerOutput = new StringBuilder(); @@ -163,8 +159,7 @@ namespace DiscImageChef.Checksums uint finalSum = (uint)((localSum2 << 16) | localSum1); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - hash = BigEndianBitConverter.GetBytes(finalSum); + hash = BigEndianBitConverter.GetBytes(finalSum); StringBuilder adlerOutput = new StringBuilder(); diff --git a/CDChecksums.cs b/CDChecksums.cs index d0c2530..93eae78 100644 --- a/CDChecksums.cs +++ b/CDChecksums.cs @@ -100,6 +100,7 @@ namespace DiscImageChef.Checksums return status; } + case 2352: return CheckCdSectorChannel(buffer); default: return null; } @@ -429,8 +430,6 @@ namespace DiscImageChef.Checksums break; } - BigEndianBitConverter.IsLittleEndian = true; - ushort qSubChannelCrc = BigEndianBitConverter.ToUInt16(qSubChannel, 10); byte[] qSubChannelForCrc = new byte[10]; Array.Copy(qSubChannel, 0, qSubChannelForCrc, 0, 10); diff --git a/CRC16Context.cs b/CRC16Context.cs index e07302d..988db22 100644 --- a/CRC16Context.cs +++ b/CRC16Context.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System; using System.IO; using System.Text; using DiscImageChef.CommonTypes.Interfaces; @@ -64,10 +63,8 @@ namespace DiscImageChef.Checksums { ushort entry = (ushort)i; for(int j = 0; j < 8; j++) - if((entry & 1) == 1) - entry = (ushort)((entry >> 1) ^ CRC16_IBM_POLY); - else - entry = (ushort)(entry >> 1); + if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ CRC16_IBM_POLY); + else entry = (ushort)(entry >> 1); table[i] = entry; } @@ -86,10 +83,8 @@ namespace DiscImageChef.Checksums { ushort entry = (ushort)i; for(int j = 0; j < 8; j++) - if((entry & 1) == 1) - entry = (ushort)((entry >> 1) ^ polynomial); - else - entry = (ushort)(entry >> 1); + if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ polynomial); + else entry = (ushort)(entry >> 1); table[i] = entry; } @@ -117,11 +112,7 @@ namespace DiscImageChef.Checksums /// /// Returns a byte array of the hash value. /// - public byte[] Final() - { - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - return BigEndianBitConverter.GetBytes((ushort)(hashInt ^ finalSeed)); - } + public byte[] Final() => BigEndianBitConverter.GetBytes((ushort)(hashInt ^ finalSeed)); /// /// Returns a hexadecimal representation of the hash value. @@ -130,7 +121,6 @@ namespace DiscImageChef.Checksums { StringBuilder crc16Output = new StringBuilder(); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; for(int i = 0; i < BigEndianBitConverter.GetBytes((ushort)(hashInt ^ finalSeed)).Length; i++) crc16Output.Append(BigEndianBitConverter.GetBytes((ushort)(hashInt ^ finalSeed))[i].ToString("x2")); @@ -171,10 +161,8 @@ namespace DiscImageChef.Checksums { ushort entry = (ushort)i; for(int j = 0; j < 8; j++) - if((entry & 1) == 1) - entry = (ushort)((entry >> 1) ^ polynomial); - else - entry = (ushort)(entry >> 1); + if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ polynomial); + else entry = (ushort)(entry >> 1); localTable[i] = entry; } @@ -183,9 +171,8 @@ namespace DiscImageChef.Checksums localhashInt = (ushort)((localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ (localhashInt & 0xff)]); - localhashInt ^= seed; - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - hash = BigEndianBitConverter.GetBytes(localhashInt); + localhashInt ^= seed; + hash = BigEndianBitConverter.GetBytes(localhashInt); StringBuilder crc16Output = new StringBuilder(); @@ -222,10 +209,8 @@ namespace DiscImageChef.Checksums { ushort entry = (ushort)i; for(int j = 0; j < 8; j++) - if((entry & 1) == 1) - entry = (ushort)((entry >> 1) ^ polynomial); - else - entry = (ushort)(entry >> 1); + if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ polynomial); + else entry = (ushort)(entry >> 1); localTable[i] = entry; } @@ -233,9 +218,8 @@ namespace DiscImageChef.Checksums for(int i = 0; i < len; i++) localhashInt = (ushort)((localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)]); - localhashInt ^= seed; - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - hash = BigEndianBitConverter.GetBytes(localhashInt); + localhashInt ^= seed; + hash = BigEndianBitConverter.GetBytes(localhashInt); StringBuilder crc16Output = new StringBuilder(); diff --git a/CRC32Context.cs b/CRC32Context.cs index 898669f..84d1d7f 100644 --- a/CRC32Context.cs +++ b/CRC32Context.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System; using System.IO; using System.Text; using DiscImageChef.CommonTypes.Interfaces; @@ -64,10 +63,8 @@ namespace DiscImageChef.Checksums { uint entry = (uint)i; for(int j = 0; j < 8; j++) - if((entry & 1) == 1) - entry = (entry >> 1) ^ CRC32_ISO_POLY; - else - entry = entry >> 1; + if((entry & 1) == 1) entry = (entry >> 1) ^ CRC32_ISO_POLY; + else entry = entry >> 1; table[i] = entry; } @@ -86,10 +83,8 @@ namespace DiscImageChef.Checksums { uint entry = (uint)i; for(int j = 0; j < 8; j++) - if((entry & 1) == 1) - entry = (entry >> 1) ^ polynomial; - else - entry = entry >> 1; + if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial; + else entry = entry >> 1; table[i] = entry; } @@ -117,11 +112,7 @@ namespace DiscImageChef.Checksums /// /// Returns a byte array of the hash value. /// - public byte[] Final() - { - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - return BigEndianBitConverter.GetBytes(hashInt ^ finalSeed); - } + public byte[] Final() => BigEndianBitConverter.GetBytes(hashInt ^ finalSeed); /// /// Returns a hexadecimal representation of the hash value. @@ -130,7 +121,6 @@ namespace DiscImageChef.Checksums { StringBuilder crc32Output = new StringBuilder(); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt ^ finalSeed).Length; i++) crc32Output.Append(BigEndianBitConverter.GetBytes(hashInt ^ finalSeed)[i].ToString("x2")); @@ -171,10 +161,8 @@ namespace DiscImageChef.Checksums { uint entry = (uint)i; for(int j = 0; j < 8; j++) - if((entry & 1) == 1) - entry = (entry >> 1) ^ polynomial; - else - entry = entry >> 1; + if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial; + else entry = entry >> 1; localTable[i] = entry; } @@ -182,9 +170,8 @@ namespace DiscImageChef.Checksums for(int i = 0; i < fileStream.Length; i++) localhashInt = (localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ (localhashInt & 0xff)]; - localhashInt ^= seed; - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - hash = BigEndianBitConverter.GetBytes(localhashInt); + localhashInt ^= seed; + hash = BigEndianBitConverter.GetBytes(localhashInt); StringBuilder crc32Output = new StringBuilder(); @@ -221,10 +208,8 @@ namespace DiscImageChef.Checksums { uint entry = (uint)i; for(int j = 0; j < 8; j++) - if((entry & 1) == 1) - entry = (entry >> 1) ^ polynomial; - else - entry = entry >> 1; + if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial; + else entry = entry >> 1; localTable[i] = entry; } @@ -232,9 +217,8 @@ namespace DiscImageChef.Checksums for(int i = 0; i < len; i++) localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)]; - localhashInt ^= seed; - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - hash = BigEndianBitConverter.GetBytes(localhashInt); + localhashInt ^= seed; + hash = BigEndianBitConverter.GetBytes(localhashInt); StringBuilder crc32Output = new StringBuilder(); diff --git a/CRC64Context.cs b/CRC64Context.cs index 7882d03..4ce0b96 100644 --- a/CRC64Context.cs +++ b/CRC64Context.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System; using System.IO; using System.Text; using DiscImageChef.CommonTypes.Interfaces; @@ -61,10 +60,8 @@ namespace DiscImageChef.Checksums { ulong entry = (ulong)i; for(int j = 0; j < 8; j++) - if((entry & 1) == 1) - entry = (entry >> 1) ^ CRC64_ECMA_POLY; - else - entry = entry >> 1; + if((entry & 1) == 1) entry = (entry >> 1) ^ CRC64_ECMA_POLY; + else entry = entry >> 1; table[i] = entry; } @@ -84,10 +81,8 @@ namespace DiscImageChef.Checksums { ulong entry = (ulong)i; for(int j = 0; j < 8; j++) - if((entry & 1) == 1) - entry = (entry >> 1) ^ polynomial; - else - entry = entry >> 1; + if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial; + else entry = entry >> 1; table[i] = entry; } @@ -117,11 +112,7 @@ namespace DiscImageChef.Checksums /// /// Returns a byte array of the hash value. /// - public byte[] Final() - { - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - return BigEndianBitConverter.GetBytes(hashInt ^= finalSeed); - } + public byte[] Final() => BigEndianBitConverter.GetBytes(hashInt ^= finalSeed); /// /// Returns a hexadecimal representation of the hash value. @@ -130,7 +121,6 @@ namespace DiscImageChef.Checksums { StringBuilder crc64Output = new StringBuilder(); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt ^= finalSeed).Length; i++) crc64Output.Append(BigEndianBitConverter.GetBytes(hashInt ^= finalSeed)[i].ToString("x2")); @@ -171,10 +161,8 @@ namespace DiscImageChef.Checksums { ulong entry = (ulong)i; for(int j = 0; j < 8; j++) - if((entry & 1) == 1) - entry = (entry >> 1) ^ polynomial; - else - entry = entry >> 1; + if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial; + else entry = entry >> 1; localTable[i] = entry; } @@ -182,9 +170,8 @@ namespace DiscImageChef.Checksums for(int i = 0; i < fileStream.Length; i++) localhashInt = (localhashInt >> 8) ^ localTable[(ulong)fileStream.ReadByte() ^ (localhashInt & 0xffL)]; - localhashInt ^= seed; - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - hash = BigEndianBitConverter.GetBytes(localhashInt); + localhashInt ^= seed; + hash = BigEndianBitConverter.GetBytes(localhashInt); StringBuilder crc64Output = new StringBuilder(); @@ -221,10 +208,8 @@ namespace DiscImageChef.Checksums { ulong entry = (ulong)i; for(int j = 0; j < 8; j++) - if((entry & 1) == 1) - entry = (entry >> 1) ^ polynomial; - else - entry = entry >> 1; + if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial; + else entry = entry >> 1; localTable[i] = entry; } @@ -232,9 +217,8 @@ namespace DiscImageChef.Checksums for(int i = 0; i < len; i++) localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)]; - localhashInt ^= seed; - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - hash = BigEndianBitConverter.GetBytes(localhashInt); + localhashInt ^= seed; + hash = BigEndianBitConverter.GetBytes(localhashInt); StringBuilder crc64Output = new StringBuilder(); diff --git a/FletcherContext.cs b/FletcherContext.cs index 3dcd7ac..d3c102e 100644 --- a/FletcherContext.cs +++ b/FletcherContext.cs @@ -32,7 +32,6 @@ // Disabled because the speed is abnormally slow -using System; using System.IO; using System.Text; using DiscImageChef.CommonTypes.Interfaces; @@ -85,7 +84,6 @@ namespace DiscImageChef.Checksums public byte[] Final() { uint finalSum = (uint)((sum2 << 16) | sum1); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; return BigEndianBitConverter.GetBytes(finalSum); } @@ -97,7 +95,6 @@ namespace DiscImageChef.Checksums uint finalSum = (uint)((sum2 << 16) | sum1); StringBuilder fletcherOutput = new StringBuilder(); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++) fletcherOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2")); @@ -134,8 +131,7 @@ namespace DiscImageChef.Checksums uint finalSum = (uint)((localSum2 << 16) | localSum1); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - hash = BigEndianBitConverter.GetBytes(finalSum); + hash = BigEndianBitConverter.GetBytes(finalSum); StringBuilder fletcherOutput = new StringBuilder(); @@ -165,8 +161,7 @@ namespace DiscImageChef.Checksums uint finalSum = (uint)((localSum2 << 16) | localSum1); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - hash = BigEndianBitConverter.GetBytes(finalSum); + hash = BigEndianBitConverter.GetBytes(finalSum); StringBuilder adlerOutput = new StringBuilder(); @@ -229,7 +224,6 @@ namespace DiscImageChef.Checksums public byte[] Final() { ushort finalSum = (ushort)((sum2 << 8) | sum1); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; return BigEndianBitConverter.GetBytes(finalSum); } @@ -241,7 +235,6 @@ namespace DiscImageChef.Checksums ushort finalSum = (ushort)((sum2 << 8) | sum1); StringBuilder fletcherOutput = new StringBuilder(); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++) fletcherOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2")); @@ -278,8 +271,7 @@ namespace DiscImageChef.Checksums ushort finalSum = (ushort)((localSum2 << 8) | localSum1); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - hash = BigEndianBitConverter.GetBytes(finalSum); + hash = BigEndianBitConverter.GetBytes(finalSum); StringBuilder fletcherOutput = new StringBuilder(); @@ -309,8 +301,7 @@ namespace DiscImageChef.Checksums ushort finalSum = (ushort)((localSum2 << 8) | localSum1); - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - hash = BigEndianBitConverter.GetBytes(finalSum); + hash = BigEndianBitConverter.GetBytes(finalSum); StringBuilder adlerOutput = new StringBuilder();