REFACTOR: Reformat code.

This commit is contained in:
2017-12-19 20:33:03 +00:00
parent 77edc7c91c
commit e6f6ace80b
704 changed files with 82627 additions and 83641 deletions

View File

@@ -39,44 +39,30 @@ namespace DiscImageChef.Decoders.Xbox
{
public static bool IsXbox(byte[] dmi)
{
if(dmi == null)
return false;
if(dmi.Length != 2052)
return false;
if(dmi == null) return false;
if(dmi.Length != 2052) return false;
// Version is 1
if(BitConverter.ToUInt32(dmi, 4) != 1)
return false;
if(BitConverter.ToUInt32(dmi, 4) != 1) return false;
// Catalogue number is two letters, five numbers, one letter
for(int i = 12; i < 14; i++)
{
if(dmi[i] < 0x41 || dmi[i] > 0x5A)
return false;
}
for(int i = 14; i < 19; i++)
{
if(dmi[i] < 0x30 || dmi[i] > 0x39)
return false;
}
if(dmi[19] < 0x41 || dmi[19] > 0x5A)
return false;
for(int i = 12; i < 14; i++) { if(dmi[i] < 0x41 || dmi[i] > 0x5A) return false; }
for(int i = 14; i < 19; i++) { if(dmi[i] < 0x30 || dmi[i] > 0x39) return false; }
if(dmi[19] < 0x41 || dmi[19] > 0x5A) return false;
long timestamp = BitConverter.ToInt64(dmi, 20);
// Game cannot exist before the Xbox
if(timestamp < 0x1BD164833DFC000)
return false;
if(timestamp < 0x1BD164833DFC000) return false;
return true;
}
public static bool IsXbox360(byte[] dmi)
{
if(dmi == null)
return false;
if(dmi.Length != 2052)
return false;
if(dmi == null) return false;
if(dmi.Length != 2052) return false;
uint signature = BitConverter.ToUInt32(dmi, 0x7EC);
@@ -167,8 +153,7 @@ namespace DiscImageChef.Decoders.Xbox
public static XboxDMI? DecodeXbox(byte[] response)
{
bool isXbox = IsXbox(response);
if(!isXbox)
return null;
if(!isXbox) return null;
XboxDMI dmi = new XboxDMI();
@@ -188,8 +173,7 @@ namespace DiscImageChef.Decoders.Xbox
public static Xbox360DMI? DecodeXbox360(byte[] response)
{
bool isX360 = IsXbox360(response);
if(!isX360)
return null;
if(!isX360) return null;
Xbox360DMI dmi = new Xbox360DMI();
@@ -205,26 +189,24 @@ namespace DiscImageChef.Decoders.Xbox
Array.Copy(response, 68, tmp, 0, 16);
dmi.CatalogNumber = StringHandlers.CToString(tmp);
if(dmi.CatalogNumber == null || dmi.CatalogNumber.Length < 13)
return null;
if(dmi.CatalogNumber == null || dmi.CatalogNumber.Length < 13) return null;
return dmi;
}
public static string PrettifyXbox(XboxDMI? dmi)
{
if(dmi == null)
return null;
if(dmi == null) return null;
XboxDMI decoded = dmi.Value;
StringBuilder sb = new StringBuilder();
sb.Append("Catalogue number: ");
for(int i = 0; i < 2; i++)
sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
for(int i = 0; i < 2; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
sb.Append("-");
for(int i = 2; i < 7; i++)
sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
for(int i = 2; i < 7; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
sb.Append("-");
sb.AppendFormat("{0}", decoded.CatalogNumber[7]);
sb.AppendLine();
@@ -236,55 +218,54 @@ namespace DiscImageChef.Decoders.Xbox
public static string PrettifyXbox360(Xbox360DMI? dmi)
{
if(dmi == null)
return null;
if(dmi == null) return null;
Xbox360DMI decoded = dmi.Value;
StringBuilder sb = new StringBuilder();
sb.Append("Catalogue number: ");
for(int i = 0; i < 2; i++)
sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
for(int i = 0; i < 2; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
sb.Append("-");
for(int i = 2; i < 6; i++)
sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
for(int i = 2; i < 6; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
sb.Append("-");
for(int i = 6; i < 8; i++)
sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
for(int i = 6; i < 8; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
sb.Append("-");
if(decoded.CatalogNumber.Length == 13)
{
for(int i = 8; i < 10; i++)
sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
for(int i = 8; i < 10; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
sb.Append("-");
for(int i = 10; i < 13; i++)
sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
for(int i = 10; i < 13; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
}
else if(decoded.CatalogNumber.Length == 14)
{
for(int i = 8; i < 11; i++)
sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
for(int i = 8; i < 11; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
sb.Append("-");
for(int i = 11; i < 14; i++)
sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
for(int i = 11; i < 14; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
}
else
{
for(int i = 8; i < decoded.CatalogNumber.Length - 3; i++)
sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
sb.Append("-");
for(int i = decoded.CatalogNumber.Length - 3; i < decoded.CatalogNumber.Length; i++)
sb.AppendFormat("{0}", decoded.CatalogNumber[i]);
}
sb.AppendLine();
sb.Append("Media ID: ");
for(int i = 0; i < 12; i++)
sb.AppendFormat("{0:X2}", decoded.MediaID[i]);
for(int i = 0; i < 12; i++) sb.AppendFormat("{0:X2}", decoded.MediaID[i]);
sb.Append("-");
for(int i = 12; i < 16; i++)
sb.AppendFormat("{0:X2}", decoded.MediaID[i]);
for(int i = 12; i < 16; i++) sb.AppendFormat("{0:X2}", decoded.MediaID[i]);
sb.AppendLine();
sb.AppendFormat("Timestamp: {0}", DateTime.FromFileTimeUtc(decoded.Timestamp)).AppendLine();
@@ -302,5 +283,4 @@ namespace DiscImageChef.Decoders.Xbox
return PrettifyXbox360(DecodeXbox360(response));
}
}
}
}

View File

@@ -217,11 +217,9 @@ namespace DiscImageChef.Decoders.Xbox
public static SecuritySector? Decode(byte[] response)
{
if(response == null)
return null;
if(response == null) return null;
if(response.Length < 2048)
return null;
if(response.Length < 2048) return null;
SecuritySector ss = new SecuritySector();
@@ -257,10 +255,15 @@ namespace DiscImageChef.Decoders.Xbox
ss.ChallengeEntries[i] = new ChallengeEntry();
ss.ChallengeEntries[i].Level = response[770 + i * 11 + 0];
ss.ChallengeEntries[i].ChallengeId = response[770 + i * 11 + 1];
ss.ChallengeEntries[i].ChallengeValue = (uint)((response[770 + i * 11 + 2] << 24) + (response[770 + i * 11 + 3] << 16) + (response[770 + i * 11 + 4] << 8) + response[770 + i * 11 + 5]);
ss.ChallengeEntries[i].ChallengeValue =
(uint)((response[770 + i * 11 + 2] << 24) + (response[770 + i * 11 + 3] << 16) +
(response[770 + i * 11 + 4] << 8) + response[770 + i * 11 + 5]);
ss.ChallengeEntries[i].ResponseModifier = response[770 + i * 11 + 6];
ss.ChallengeEntries[i].ResponseValue = (uint)((response[770 + i * 11 + 7] << 24) + (response[770 + i * 11 + 8] << 16) + (response[770 + i * 11 + 9] << 8) + response[770 + i * 11 + 10]);
ss.ChallengeEntries[i].ResponseValue =
(uint)((response[770 + i * 11 + 7] << 24) + (response[770 + i * 11 + 8] << 16) +
(response[770 + i * 11 + 9] << 8) + response[770 + i * 11 + 10]);
}
ss.Unknown6 = response[1023];
ss.Unknown7 = new byte[48];
Array.Copy(response, 1052, ss.Unknown7, 0, 48);
@@ -276,25 +279,32 @@ namespace DiscImageChef.Decoders.Xbox
for(int i = 0; i < 23; i++)
{
ss.Extents[i] = new SecuritySectorExtent();
ss.Extents[i].Unknown = (uint)((response[1633 + i * 9 + 0] << 16) + (response[1633 + i * 9 + 1] << 8) + response[1633 + i * 9 + 2]);
ss.Extents[i].StartPSN = (uint)((response[1633 + i * 9 + 3] << 16) + (response[1633 + i * 9 + 4] << 8) + response[1633 + i * 9 + 5]);
ss.Extents[i].EndPSN = (uint)((response[1633 + i * 9 + 6] << 16) + (response[1633 + i * 9 + 7] << 8) + response[1633 + i * 9 + 8]);
ss.Extents[i].Unknown = (uint)((response[1633 + i * 9 + 0] << 16) + (response[1633 + i * 9 + 1] << 8) +
response[1633 + i * 9 + 2]);
ss.Extents[i].StartPSN = (uint)((response[1633 + i * 9 + 3] << 16) + (response[1633 + i * 9 + 4] << 8) +
response[1633 + i * 9 + 5]);
ss.Extents[i].EndPSN = (uint)((response[1633 + i * 9 + 6] << 16) + (response[1633 + i * 9 + 7] << 8) +
response[1633 + i * 9 + 8]);
}
ss.ExtentsCopy = new SecuritySectorExtent[23];
for(int i = 0; i < 23; i++)
{
ss.ExtentsCopy[i] = new SecuritySectorExtent();
ss.ExtentsCopy[i].Unknown = (uint)((response[1840 + i * 9 + 0] << 16) + (response[1840 + i * 9 + 1] << 8) + response[1840 + i * 9 + 2]);
ss.ExtentsCopy[i].StartPSN = (uint)((response[1840 + i * 9 + 3] << 16) + (response[1840 + i * 9 + 4] << 8) + response[1840 + i * 9 + 5]);
ss.ExtentsCopy[i].EndPSN = (uint)((response[1840 + i * 9 + 6] << 16) + (response[1840 + i * 9 + 7] << 8) + response[1840 + i * 9 + 8]);
ss.ExtentsCopy[i].Unknown = (uint)((response[1840 + i * 9 + 0] << 16) +
(response[1840 + i * 9 + 1] << 8) + response[1840 + i * 9 + 2]);
ss.ExtentsCopy[i].StartPSN = (uint)((response[1840 + i * 9 + 3] << 16) +
(response[1840 + i * 9 + 4] << 8) + response[1840 + i * 9 + 5]);
ss.ExtentsCopy[i].EndPSN = (uint)((response[1840 + i * 9 + 6] << 16) +
(response[1840 + i * 9 + 7] << 8) + response[1840 + i * 9 + 8]);
}
return ss;
}
public static string Prettify(SecuritySector? ss)
{
if(ss == null)
return null;
if(ss == null) return null;
SecuritySector decoded = ss.Value;
StringBuilder sb = new StringBuilder();
@@ -321,10 +331,12 @@ namespace DiscImageChef.Decoders.Xbox
sb.AppendFormat(categorySentence, sizeString, "Xbox Game Disc", decoded.PartVersion).AppendLine();
break;
case DiskCategory.DVDPRDL:
sb.AppendFormat(categorySentence, sizeString, "Xbox 360 Game Disc", decoded.PartVersion).AppendLine();
sb.AppendFormat(categorySentence, sizeString, "Xbox 360 Game Disc", decoded.PartVersion)
.AppendLine();
break;
default:
sb.AppendFormat(categorySentence, sizeString, "unknown disc type", decoded.PartVersion).AppendLine();
sb.AppendFormat(categorySentence, sizeString, "unknown disc type", decoded.PartVersion)
.AppendLine();
break;
}
@@ -349,15 +361,14 @@ namespace DiscImageChef.Decoders.Xbox
sb.AppendLine("Disc maximum transfer rate is unspecified.");
break;
default:
sb.AppendFormat("Disc maximum transfer rate is specified by unknown key {0}", decoded.MaximumRate).AppendLine();
sb.AppendFormat("Disc maximum transfer rate is specified by unknown key {0}", decoded.MaximumRate)
.AppendLine();
break;
}
sb.AppendFormat("Disc has {0} layers", decoded.Layers + 1).AppendLine();
if(decoded.TrackPath && decoded.Layers == 1)
sb.AppendLine("Layers are in parallel track path");
else if(!decoded.TrackPath && decoded.Layers == 1)
sb.AppendLine("Layers are in opposite track path");
if(decoded.TrackPath && decoded.Layers == 1) sb.AppendLine("Layers are in parallel track path");
else if(!decoded.TrackPath && decoded.Layers == 1) sb.AppendLine("Layers are in opposite track path");
switch(decoded.LinearDensity)
{
@@ -418,11 +429,9 @@ namespace DiscImageChef.Decoders.Xbox
if(decoded.Layers == 1 && !decoded.TrackPath)
sb.AppendFormat("Layer 0 ends at PSN {0:X}h", decoded.Layer0EndPSN).AppendLine();
}
else
sb.AppendLine("Disc is empty");
else sb.AppendLine("Disc is empty");
}
else
sb.AppendLine("Disc is empty");
else sb.AppendLine("Disc is empty");
sb.AppendLine("Challenges:");
foreach(ChallengeEntry entry in decoded.ChallengeEntries)
@@ -435,7 +444,8 @@ namespace DiscImageChef.Decoders.Xbox
}
for(int i = 0; i < 16; i++)
sb.AppendFormat("Extent starts at PSN {0:X6}h and ends at PSN {1:X6}h", decoded.Extents[i].StartPSN, decoded.Extents[i].EndPSN).AppendLine();
sb.AppendFormat("Extent starts at PSN {0:X6}h and ends at PSN {1:X6}h", decoded.Extents[i].StartPSN,
decoded.Extents[i].EndPSN).AppendLine();
return sb.ToString();
}
@@ -445,4 +455,4 @@ namespace DiscImageChef.Decoders.Xbox
return Prettify(Decode(response));
}
}
}
}