Finished fixing up some things

This commit is contained in:
Michael 2021-02-10 13:32:35 -06:00
parent 894dbce4ab
commit 7bb002918e
6 changed files with 85 additions and 87 deletions

View file

@ -702,7 +702,7 @@ namespace libWiiSharp
MemoryStream memoryStream = new MemoryStream(fileOrHeader); MemoryStream memoryStream = new MemoryStream(fileOrHeader);
try try
{ {
imD5.ParseHeader(memoryStream); imD5.PrivParseHeader(memoryStream);
} }
catch catch
{ {
@ -726,7 +726,7 @@ namespace libWiiSharp
} }
Headers.IMD5 imD5 = new Headers.IMD5(); Headers.IMD5 imD5 = new Headers.IMD5();
imD5.ParseHeader(fileOrHeader); imD5.PrivParseHeader(fileOrHeader);
return imD5; return imD5;
} }
@ -741,7 +741,7 @@ namespace libWiiSharp
{ {
fileSize = (uint)file.Length fileSize = (uint)file.Length
}; };
imD5.ComputeHash(file); imD5.PrivComputeHash(file);
return imD5; return imD5;
} }
@ -767,7 +767,7 @@ namespace libWiiSharp
Headers.IMD5 imD5 = Create(file); Headers.IMD5 imD5 = Create(file);
MemoryStream memoryStream1 = new MemoryStream(); MemoryStream memoryStream1 = new MemoryStream();
MemoryStream memoryStream2 = memoryStream1; MemoryStream memoryStream2 = memoryStream1;
imD5.WriteToStream(memoryStream2); imD5.PrivWriteToStream(memoryStream2);
memoryStream1.Write(file, 0, file.Length); memoryStream1.Write(file, 0, file.Length);
byte[] array = memoryStream1.ToArray(); byte[] array = memoryStream1.ToArray();
memoryStream1.Dispose(); memoryStream1.Dispose();
@ -809,7 +809,7 @@ namespace libWiiSharp
MemoryStream memoryStream = new MemoryStream(); MemoryStream memoryStream = new MemoryStream();
try try
{ {
WriteToStream(memoryStream); PrivWriteToStream(memoryStream);
return memoryStream; return memoryStream;
} }
catch catch
@ -834,12 +834,12 @@ namespace libWiiSharp
/// <param name="writeStream"></param> /// <param name="writeStream"></param>
public void Write(Stream writeStream) public void Write(Stream writeStream)
{ {
WriteToStream(writeStream); PrivWriteToStream(writeStream);
} }
#endregion #endregion
#region Private Functions #region Private Functions
private void WriteToStream(Stream writeStream) private void PrivWriteToStream(Stream writeStream)
{ {
writeStream.Seek(0L, SeekOrigin.Begin); writeStream.Seek(0L, SeekOrigin.Begin);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(imd5Magic)), 0, 4); writeStream.Write(BitConverter.GetBytes(Shared.Swap(imd5Magic)), 0, 4);
@ -848,14 +848,14 @@ namespace libWiiSharp
writeStream.Write(hash, 0, hash.Length); writeStream.Write(hash, 0, hash.Length);
} }
private void ComputeHash(byte[] bytesToHash) private void PrivComputeHash(byte[] bytesToHash)
{ {
MD5 md5 = MD5.Create(); MD5 md5 = MD5.Create();
hash = md5.ComputeHash(bytesToHash); hash = md5.ComputeHash(bytesToHash);
md5.Clear(); md5.Clear();
} }
private void ParseHeader(Stream headerStream) private void PrivParseHeader(Stream headerStream)
{ {
headerStream.Seek(0L, SeekOrigin.Begin); headerStream.Seek(0L, SeekOrigin.Begin);
byte[] buffer = new byte[4]; byte[] buffer = new byte[4];

View file

@ -71,7 +71,7 @@ namespace libWiiSharp
/// <returns></returns> /// <returns></returns>
public static string DumpAsString(byte[] data) public static string DumpAsString(byte[] data)
{ {
return string.Join("\n", DumpAsStringArray(data)); return string.Join("\n", PrivDumpAsStringArray(data));
} }
/// <summary> /// <summary>
@ -101,9 +101,9 @@ namespace libWiiSharp
for (int index = 0; index < 16; ++index) for (int index = 0; index < 16; ++index)
{ {
if (ToAscii(byte.Parse((string)dataGridView.Rows[e.RowIndex].Cells[index + 1].Value, NumberStyles.HexNumber)) != str[index]) if (PrivToAscii(byte.Parse((string)dataGridView.Rows[e.RowIndex].Cells[index + 1].Value, NumberStyles.HexNumber)) != str[index])
{ {
dataGridView.Rows[e.RowIndex].Cells[index + 1].Value = FromAscii(str[index]).ToString("x2"); dataGridView.Rows[e.RowIndex].Cells[index + 1].Value = PrivFromAscii(str[index]).ToString("x2");
} }
} }
} }
@ -115,7 +115,7 @@ namespace libWiiSharp
} }
int startIndex = int.Parse(dataGridView.Columns[e.ColumnIndex].HeaderText, NumberStyles.HexNumber); int startIndex = int.Parse(dataGridView.Columns[e.ColumnIndex].HeaderText, NumberStyles.HexNumber);
string str = ((string)dataGridView.Rows[e.RowIndex].Cells[17].Value).Remove(startIndex, 1).Insert(startIndex, ToAscii(byte.Parse((string)dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, NumberStyles.HexNumber)).ToString()); string str = ((string)dataGridView.Rows[e.RowIndex].Cells[17].Value).Remove(startIndex, 1).Insert(startIndex, PrivToAscii(byte.Parse((string)dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, NumberStyles.HexNumber)).ToString());
dataGridView.Rows[e.RowIndex].Cells[17].Value = str; dataGridView.Rows[e.RowIndex].Cells[17].Value = str;
if (((string)dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).Length <= 2) if (((string)dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).Length <= 2)
{ {
@ -152,7 +152,7 @@ namespace libWiiSharp
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
/// <returns></returns> /// <returns></returns>
private static string[] DumpAsStringArray(byte[] data) private static string[] PrivDumpAsStringArray(byte[] data)
{ {
List<string> stringList = new List<string>(); List<string> stringList = new List<string>();
int num; int num;
@ -165,7 +165,7 @@ namespace libWiiSharp
{ {
str1 = str1 + data[num + index].ToString("x2") + " "; str1 = str1 + data[num + index].ToString("x2") + " ";
string str3 = str2; string str3 = str2;
ascii = ToAscii(data[num + index]); ascii = PrivToAscii(data[num + index]);
string str4 = ascii.ToString(); string str4 = ascii.ToString();
str2 = str3 + str4; str2 = str3 + str4;
} }
@ -182,7 +182,7 @@ namespace libWiiSharp
{ {
str1 = str1 + data[num + index].ToString("x2") + " "; str1 = str1 + data[num + index].ToString("x2") + " ";
string str3 = str2; string str3 = str2;
ascii = ToAscii(data[num + index]); ascii = PrivToAscii(data[num + index]);
string str4 = ascii.ToString(); string str4 = ascii.ToString();
str2 = str3 + str4; str2 = str3 + str4;
} }
@ -196,8 +196,7 @@ namespace libWiiSharp
} }
return stringList.ToArray(); return stringList.ToArray();
} }
// Unused
/*
/// <summary> /// <summary>
/// Dumps a DataGridView back to a byte array. /// Dumps a DataGridView back to a byte array.
/// The DataGridView must have the right format. /// The DataGridView must have the right format.
@ -205,7 +204,7 @@ namespace libWiiSharp
/// </summary> /// </summary>
/// <param name="dataGridView"></param> /// <param name="dataGridView"></param>
/// <returns></returns> /// <returns></returns>
private static byte[] DumpFromDataGridView(DataGridView dataGridView) private static byte[] PrivDumpFromDataGridView(DataGridView dataGridView)
{ {
try try
{ {
@ -235,7 +234,7 @@ namespace libWiiSharp
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
/// <param name="dataGridView"></param> /// <param name="dataGridView"></param>
private static void DumpToDataGridView(byte[] data, DataGridView dataGridView) private static void PrivDumpToDataGridView(byte[] data, DataGridView dataGridView)
{ {
dataGridView.Columns.Clear(); dataGridView.Columns.Clear();
dataGridView.Rows.Clear(); dataGridView.Rows.Clear();
@ -244,59 +243,59 @@ namespace libWiiSharp
{ {
HeaderText = "Offset", HeaderText = "Offset",
Width = 80, Width = 80,
CellTemplate = (DataGridViewCell)new DataGridViewTextBoxCell() CellTemplate = new DataGridViewTextBoxCell()
}); });
for (int index = 0; index < 16; ++index) for (int index = 0; index < 16; ++index)
dataGridView.Columns.Add(new DataGridViewColumn() dataGridView.Columns.Add(new DataGridViewColumn()
{ {
HeaderText = index.ToString("x1"), HeaderText = index.ToString("x1"),
Width = 30, Width = 30,
CellTemplate = (DataGridViewCell)new DataGridViewTextBoxCell() CellTemplate = new DataGridViewTextBoxCell()
}); });
dataGridView.Columns.Add(new DataGridViewColumn() dataGridView.Columns.Add(new DataGridViewColumn()
{ {
HeaderText = "Dump", HeaderText = "Dump",
Width = 125, Width = 125,
CellTemplate = (DataGridViewCell)new DataGridViewTextBoxCell() CellTemplate = new DataGridViewTextBoxCell()
}); });
int num; int num;
for (num = 0; (double)(data.Length - num) / 16.0 >= 1.0; num += 16) for (num = 0; (data.Length - num) / 16.0 >= 1.0; num += 16)
{ {
DataGridViewRow dataGridViewRow = new DataGridViewRow(); DataGridViewRow dataGridViewRow = new DataGridViewRow();
int index1 = dataGridViewRow.Cells.Add((DataGridViewCell)new DataGridViewTextBoxCell()); int index1 = dataGridViewRow.Cells.Add(new DataGridViewTextBoxCell());
dataGridViewRow.Cells[index1].Value = (object)num.ToString("x8"); dataGridViewRow.Cells[index1].Value = num.ToString("x8");
dataGridViewRow.Cells[index1].ReadOnly = true; dataGridViewRow.Cells[index1].ReadOnly = true;
string empty = string.Empty; string empty = string.Empty;
for (int index2 = 0; index2 < 16; ++index2) for (int index2 = 0; index2 < 16; ++index2)
{ {
int index3 = dataGridViewRow.Cells.Add((DataGridViewCell)new DataGridViewTextBoxCell()); int index3 = dataGridViewRow.Cells.Add(new DataGridViewTextBoxCell());
dataGridViewRow.Cells[index3].Value = (object)data[num + index2].ToString("x2"); dataGridViewRow.Cells[index3].Value = data[num + index2].ToString("x2");
empty += HexView.ToAscii(data[num + index2]).ToString(); empty += PrivToAscii(data[num + index2]).ToString();
} }
int index4 = dataGridViewRow.Cells.Add((DataGridViewCell)new DataGridViewTextBoxCell()); int index4 = dataGridViewRow.Cells.Add(new DataGridViewTextBoxCell());
dataGridViewRow.Cells[index4].Value = (object)empty; dataGridViewRow.Cells[index4].Value = empty;
dataGridView.Rows.Add(dataGridViewRow); dataGridView.Rows.Add(dataGridViewRow);
} }
if (data.Length <= num) if (data.Length <= num)
return; return;
DataGridViewRow dataGridViewRow1 = new DataGridViewRow(); DataGridViewRow dataGridViewRow1 = new DataGridViewRow();
int index5 = dataGridViewRow1.Cells.Add((DataGridViewCell)new DataGridViewTextBoxCell()); int index5 = dataGridViewRow1.Cells.Add(new DataGridViewTextBoxCell());
dataGridViewRow1.Cells[index5].Value = (object)num.ToString("x8"); dataGridViewRow1.Cells[index5].Value = num.ToString("x8");
dataGridViewRow1.Cells[index5].ReadOnly = true; dataGridViewRow1.Cells[index5].ReadOnly = true;
string empty1 = string.Empty; string empty1 = string.Empty;
for (int index1 = 0; index1 < 16; ++index1) for (int index1 = 0; index1 < 16; ++index1)
{ {
if (index1 < data.Length - num) if (index1 < data.Length - num)
{ {
int index2 = dataGridViewRow1.Cells.Add((DataGridViewCell)new DataGridViewTextBoxCell()); int index2 = dataGridViewRow1.Cells.Add(new DataGridViewTextBoxCell());
dataGridViewRow1.Cells[index2].Value = (object)data[num + index1].ToString("x2"); dataGridViewRow1.Cells[index2].Value = data[num + index1].ToString("x2");
empty1 += HexView.ToAscii(data[num + index1]).ToString(); empty1 += PrivToAscii(data[num + index1]).ToString();
} }
else else
dataGridViewRow1.Cells.Add((DataGridViewCell)new DataGridViewTextBoxCell()); dataGridViewRow1.Cells.Add(new DataGridViewTextBoxCell());
} }
int index6 = dataGridViewRow1.Cells.Add((DataGridViewCell)new DataGridViewTextBoxCell()); int index6 = dataGridViewRow1.Cells.Add(new DataGridViewTextBoxCell());
dataGridViewRow1.Cells[index6].Value = (object)empty1; dataGridViewRow1.Cells[index6].Value = empty1;
dataGridView.Rows.Add(dataGridViewRow1); dataGridView.Rows.Add(dataGridViewRow1);
} }
@ -307,7 +306,7 @@ namespace libWiiSharp
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
/// <param name="listView"></param> /// <param name="listView"></param>
private static void DumpToListView(byte[] data, ListView listView) private static void PrivDumpToListView(byte[] data, ListView listView)
{ {
listView.Columns.Clear(); listView.Columns.Clear();
listView.Items.Clear(); listView.Items.Clear();
@ -318,14 +317,14 @@ namespace libWiiSharp
listView.Columns.Add(index.ToString("x1"), index.ToString("x1"), 30, HorizontalAlignment.Left, string.Empty); listView.Columns.Add(index.ToString("x1"), index.ToString("x1"), 30, HorizontalAlignment.Left, string.Empty);
listView.Columns.Add("Dump", "Dump", 125, HorizontalAlignment.Left, string.Empty); listView.Columns.Add("Dump", "Dump", 125, HorizontalAlignment.Left, string.Empty);
int num; int num;
for (num = 0; (double)(data.Length - num) / 16.0 >= 1.0; num += 16) for (num = 0; (data.Length - num) / 16.0 >= 1.0; num += 16)
{ {
ListViewItem listViewItem = new ListViewItem(num.ToString("x8")); ListViewItem listViewItem = new ListViewItem(num.ToString("x8"));
string empty = string.Empty; string empty = string.Empty;
for (int index = 0; index < 16; ++index) for (int index = 0; index < 16; ++index)
{ {
listViewItem.SubItems.Add(data[num + index].ToString("x2")); listViewItem.SubItems.Add(data[num + index].ToString("x2"));
empty += HexView.ToAscii(data[num + index]).ToString(); empty += PrivToAscii(data[num + index]).ToString();
} }
listViewItem.SubItems.Add(empty); listViewItem.SubItems.Add(empty);
listView.Items.Add(listViewItem); listView.Items.Add(listViewItem);
@ -339,7 +338,7 @@ namespace libWiiSharp
if (index < data.Length - num) if (index < data.Length - num)
{ {
listViewItem1.SubItems.Add(data[num + index].ToString("x2")); listViewItem1.SubItems.Add(data[num + index].ToString("x2"));
empty1 += HexView.ToAscii(data[num + index]).ToString(); empty1 += PrivToAscii(data[num + index]).ToString();
} }
else else
listViewItem1.SubItems.Add(string.Empty); listViewItem1.SubItems.Add(string.Empty);
@ -347,15 +346,14 @@ namespace libWiiSharp
listViewItem1.SubItems.Add(empty1); listViewItem1.SubItems.Add(empty1);
listView.Items.Add(listViewItem1); listView.Items.Add(listViewItem1);
} }
*/
private static char ToAscii(byte value) private static char PrivToAscii(byte value)
{ {
return value >= 32 && value <= 126 ? (char)value : '.'; return value >= 32 && value <= 126 ? (char)value : '.';
} }
private static byte FromAscii(char value) private static byte PrivFromAscii(char value)
{ {
return (byte)value; return (byte)value;
} }

View file

@ -38,7 +38,7 @@ namespace libWiiSharp
public void LoadIOS(ref WAD iosWad) public void LoadIOS(ref WAD iosWad)
{ {
wadFile = iosWad; wadFile = iosWad;
GetEsIndex(); PrivGetEsIndex();
} }
/// <summary> /// <summary>
@ -88,12 +88,12 @@ namespace libWiiSharp
public int PatchFakeSigning(ref byte[] esModule) public int PatchFakeSigning(ref byte[] esModule)
{ {
return PatchFakeSigning(ref esModule); return PrivPatchFakeSigning(ref esModule);
} }
public int PatchEsIdentify(ref byte[] esModule) public int PatchEsIdentify(ref byte[] esModule)
{ {
return PatchEsIdentify(ref esModule); return PrivPatchEsIdentify(ref esModule);
} }
public int PatchNandPermissions(ref byte[] esModule) public int PatchNandPermissions(ref byte[] esModule)
@ -305,7 +305,7 @@ namespace libWiiSharp
return num; return num;
} }
private void GetEsIndex() private void PrivGetEsIndex()
{ {
FireDebug("Scanning for ES Module..."); FireDebug("Scanning for ES Module...");
string str = "$IOSVersion:"; string str = "$IOSVersion:";

18
Lz77.cs
View file

@ -273,14 +273,14 @@ namespace libWiiSharp
private Stream PrivCompress(Stream inFile) private Stream PrivCompress(Stream inFile)
{ {
if (Lz77.IsLz77Compressed(inFile)) if (IsLz77Compressed(inFile))
return inFile; return inFile;
inFile.Seek(0L, SeekOrigin.Begin); inFile.Seek(0L, SeekOrigin.Begin);
int num1 = 0; int num1 = 0;
int[] numArray1 = new int[17]; int[] numArray1 = new int[17];
uint num2 = (uint)(((int)Convert.ToUInt32(inFile.Length) << 8) + 16); uint num2 = (uint)(((int)Convert.ToUInt32(inFile.Length) << 8) + 16);
MemoryStream memoryStream = new MemoryStream(); MemoryStream memoryStream = new MemoryStream();
memoryStream.Write(BitConverter.GetBytes(Shared.Swap(Lz77.lz77Magic)), 0, 4); memoryStream.Write(BitConverter.GetBytes(Shared.Swap(lz77Magic)), 0, 4);
memoryStream.Write(BitConverter.GetBytes(num2), 0, 4); memoryStream.Write(BitConverter.GetBytes(num2), 0, 4);
this.InitTree(); this.InitTree();
numArray1[0] = 0; numArray1[0] = 0;
@ -306,7 +306,7 @@ namespace libWiiSharp
if (this.matchLength <= 2) if (this.matchLength <= 2)
{ {
this.matchLength = 1; this.matchLength = 1;
numArray1[num3++] = (int)this.textBuffer[r]; numArray1[num3++] = this.textBuffer[r];
} }
else else
{ {
@ -314,12 +314,12 @@ namespace libWiiSharp
int[] numArray2 = numArray1; int[] numArray2 = numArray1;
int index1 = num3; int index1 = num3;
int num7 = index1 + 1; int num7 = index1 + 1;
int num8 = (int)(ushort)(r - this.matchPosition - 1 >> 8 & 15) | this.matchLength - 3 << 4; int num8 = (ushort)(r - this.matchPosition - 1 >> 8 & 15) | this.matchLength - 3 << 4;
numArray2[index1] = num8; numArray2[index1] = num8;
int[] numArray3 = numArray1; int[] numArray3 = numArray1;
int index2 = num7; int index2 = num7;
num3 = index2 + 1; num3 = index2 + 1;
int num9 = (int)(ushort)(r - this.matchPosition - 1 & (int)byte.MaxValue); int num9 = (ushort)(r - this.matchPosition - 1 & byte.MaxValue);
numArray3[index2] = num9; numArray3[index2] = num9;
} }
if ((num4 >>= 1) == 0) if ((num4 >>= 1) == 0)
@ -363,9 +363,9 @@ namespace libWiiSharp
if (num1 % 4 != 0) if (num1 % 4 != 0)
{ {
for (int index = 0; index < 4 - num1 % 4; ++index) for (int index = 0; index < 4 - num1 % 4; ++index)
memoryStream.WriteByte((byte)0); memoryStream.WriteByte(0);
} }
return (Stream)memoryStream; return memoryStream;
} }
private void InitTree() private void InitTree()
@ -378,7 +378,7 @@ namespace libWiiSharp
private void InsertNode(int r) private void InsertNode(int r)
{ {
int num1 = 1; int num1 = 1;
int index = 4097 + (this.textBuffer[r] != ushort.MaxValue ? (int)this.textBuffer[r] : 0); int index = 4097 + (this.textBuffer[r] != ushort.MaxValue ? this.textBuffer[r] : 0);
this.rightSon[r] = this.leftSon[r] = 4096; this.rightSon[r] = this.leftSon[r] = 4096;
this.matchLength = 0; this.matchLength = 0;
int num2; int num2;
@ -407,7 +407,7 @@ namespace libWiiSharp
index = this.leftSon[index]; index = this.leftSon[index];
} }
num2 = 1; num2 = 1;
while (num2 < 18 && (num1 = (int)this.textBuffer[r + num2] - (int)this.textBuffer[index + num2]) == 0) while (num2 < 18 && (num1 = this.textBuffer[r + num2] - this.textBuffer[index + num2]) == 0)
++num2; ++num2;
} }
while (num2 <= this.matchLength); while (num2 <= this.matchLength);

View file

@ -97,7 +97,7 @@ namespace libWiiSharp
public TMD DownloadTMD(string titleId, string titleVersion) public TMD DownloadTMD(string titleId, string titleVersion)
{ {
return titleId.Length == 16 ? DownloadTmd(titleId, titleVersion) : throw new Exception("Title ID must be 16 characters long!"); return titleId.Length == 16 ? PrivDownloadTmd(titleId, titleVersion) : throw new Exception("Title ID must be 16 characters long!");
} }
public Ticket DownloadTicket(string titleId) public Ticket DownloadTicket(string titleId)
@ -146,7 +146,7 @@ namespace libWiiSharp
contentId = num.ToString("x8"); contentId = num.ToString("x8");
FireDebug("Downloading Content (Content ID: {0}) of Title {1} v{2}...", contentId, titleId, string.IsNullOrEmpty(titleVersion) ? "[Latest]" : titleVersion); FireDebug("Downloading Content (Content ID: {0}) of Title {1} v{2}...", contentId, titleId, string.IsNullOrEmpty(titleVersion) ? "[Latest]" : titleVersion);
FireDebug(" Checking for Internet connection..."); FireDebug(" Checking for Internet connection...");
if (!CheckInet()) if (!PrivCheckInet())
{ {
FireDebug(" Connection not found..."); FireDebug(" Connection not found...");
throw new Exception("You're not connected to the internet!"); throw new Exception("You're not connected to the internet!");
@ -201,7 +201,7 @@ namespace libWiiSharp
byte[] content = wcNus.DownloadData(str2 + empty); byte[] content = wcNus.DownloadData(str2 + empty);
FireProgress(80); FireProgress(80);
FireDebug(" Decrypting Content..."); FireDebug(" Decrypting Content...");
byte[] array = DecryptContent(content, contentIndex, tik, tmd); byte[] array = PrivDecryptContent(content, contentIndex, tik, tmd);
Array.Resize<byte>(ref array, (int)tmd.Contents[contentIndex].Size); Array.Resize<byte>(ref array, (int)tmd.Contents[contentIndex].Size);
if (!Shared.CompareByteArrays(SHA1.Create().ComputeHash(array), tmd.Contents[contentIndex].Hash)) if (!Shared.CompareByteArrays(SHA1.Create().ComputeHash(array), tmd.Contents[contentIndex].Hash))
{ {
@ -215,7 +215,7 @@ namespace libWiiSharp
private Ticket PrivDownloadTicket(string titleId) private Ticket PrivDownloadTicket(string titleId)
{ {
if (!CheckInet()) if (!PrivCheckInet())
{ {
throw new Exception("You're not connected to the internet!"); throw new Exception("You're not connected to the internet!");
} }
@ -226,9 +226,9 @@ namespace libWiiSharp
return Ticket.Load(tikArray); return Ticket.Load(tikArray);
} }
private TMD DownloadTmd(string titleId, string titleVersion) private TMD PrivDownloadTmd(string titleId, string titleVersion)
{ {
if (!CheckInet()) if (!PrivCheckInet())
{ {
throw new Exception("You're not connected to the internet!"); throw new Exception("You're not connected to the internet!");
} }
@ -286,7 +286,7 @@ namespace libWiiSharp
flag3 = false; flag3 = false;
} }
FireDebug(" Checking for Internet connection..."); FireDebug(" Checking for Internet connection...");
if (!CheckInet()) if (!PrivCheckInet())
{ {
FireDebug(" Connection not found..."); FireDebug(" Connection not found...");
throw new Exception("You're not connected to the internet!"); throw new Exception("You're not connected to the internet!");
@ -398,7 +398,7 @@ namespace libWiiSharp
string str3 = outputDir; string str3 = outputDir;
contentId = tmd.Contents[contentIndex].ContentID; contentId = tmd.Contents[contentIndex].ContentID;
string str4 = contentId.ToString("x8"); string str4 = contentId.ToString("x8");
byte[] array = DecryptContent(File.ReadAllBytes(str3 + str4), contentIndex, tik, tmd); byte[] array = PrivDecryptContent(File.ReadAllBytes(str3 + str4), contentIndex, tik, tmd);
Array.Resize<byte>(ref array, (int)tmd.Contents[contentIndex].Size); Array.Resize<byte>(ref array, (int)tmd.Contents[contentIndex].Size);
if (!Shared.CompareByteArrays(shA1.ComputeHash(array), tmd.Contents[contentIndex].Hash)) if (!Shared.CompareByteArrays(shA1.ComputeHash(array), tmd.Contents[contentIndex].Hash))
{ {
@ -465,7 +465,7 @@ namespace libWiiSharp
FireProgress(100); FireProgress(100);
} }
private byte[] DecryptContent(byte[] content, int contentIndex, Ticket tik, TMD tmd) private byte[] PrivDecryptContent(byte[] content, int contentIndex, Ticket tik, TMD tmd)
{ {
Array.Resize<byte>(ref content, Shared.AddPadding(content.Length, 16)); Array.Resize<byte>(ref content, Shared.AddPadding(content.Length, 16));
byte[] titleKey = tik.TitleKey; byte[] titleKey = tik.TitleKey;
@ -492,7 +492,7 @@ namespace libWiiSharp
return buffer; return buffer;
} }
private bool CheckInet() private bool PrivCheckInet()
{ {
try try
{ {

View file

@ -100,7 +100,7 @@ namespace libWiiSharp
return; return;
} }
ReDecryptTitleKey(); PrivReDecryptTitleKey();
} }
} }
@ -157,7 +157,7 @@ namespace libWiiSharp
MemoryStream memoryStream = new MemoryStream(ticket); MemoryStream memoryStream = new MemoryStream(ticket);
try try
{ {
ticket1.ParseTicket(memoryStream); ticket1.PrivParseTicket(memoryStream);
} }
catch catch
{ {
@ -171,7 +171,7 @@ namespace libWiiSharp
public static Ticket Load(Stream ticket) public static Ticket Load(Stream ticket)
{ {
Ticket ticket1 = new Ticket(); Ticket ticket1 = new Ticket();
ticket1.ParseTicket(ticket); ticket1.PrivParseTicket(ticket);
return ticket1; return ticket1;
} }
@ -185,7 +185,7 @@ namespace libWiiSharp
MemoryStream memoryStream = new MemoryStream(ticket); MemoryStream memoryStream = new MemoryStream(ticket);
try try
{ {
ParseTicket(memoryStream); PrivParseTicket(memoryStream);
} }
catch catch
{ {
@ -197,7 +197,7 @@ namespace libWiiSharp
public void LoadFile(Stream ticket) public void LoadFile(Stream ticket)
{ {
ParseTicket(ticket); PrivParseTicket(ticket);
} }
public void Save(string savePath) public void Save(string savePath)
@ -218,7 +218,7 @@ namespace libWiiSharp
} }
using FileStream fileStream = new FileStream(savePath, FileMode.Create); using FileStream fileStream = new FileStream(savePath, FileMode.Create);
WriteToStream(fileStream); PrivWriteToStream(fileStream);
} }
public MemoryStream ToMemoryStream() public MemoryStream ToMemoryStream()
@ -236,7 +236,7 @@ namespace libWiiSharp
MemoryStream memoryStream = new MemoryStream(); MemoryStream memoryStream = new MemoryStream();
try try
{ {
WriteToStream(memoryStream); PrivWriteToStream(memoryStream);
return memoryStream; return memoryStream;
} }
catch catch
@ -261,7 +261,7 @@ namespace libWiiSharp
MemoryStream memoryStream = new MemoryStream(); MemoryStream memoryStream = new MemoryStream();
try try
{ {
WriteToStream(memoryStream); PrivWriteToStream(memoryStream);
} }
catch catch
{ {
@ -290,7 +290,7 @@ namespace libWiiSharp
encryptedTitleKey[index] = (byte)newTitleKey[index]; encryptedTitleKey[index] = (byte)newTitleKey[index];
} }
DecryptTitleKey(); PrivDecryptTitleKey();
titleKeyChanged = true; titleKeyChanged = true;
reDecrypt = true; reDecrypt = true;
newEncryptedTitleKey = encryptedTitleKey; newEncryptedTitleKey = encryptedTitleKey;
@ -299,7 +299,7 @@ namespace libWiiSharp
public void SetTitleKey(byte[] newTitleKey) public void SetTitleKey(byte[] newTitleKey)
{ {
encryptedTitleKey = newTitleKey.Length == 16 ? newTitleKey : throw new Exception("The title key must be 16 characters long!"); encryptedTitleKey = newTitleKey.Length == 16 ? newTitleKey : throw new Exception("The title key must be 16 characters long!");
DecryptTitleKey(); PrivDecryptTitleKey();
titleKeyChanged = true; titleKeyChanged = true;
reDecrypt = true; reDecrypt = true;
newEncryptedTitleKey = newTitleKey; newEncryptedTitleKey = newTitleKey;
@ -317,11 +317,11 @@ namespace libWiiSharp
}); });
} }
private void WriteToStream(Stream writeStream) private void PrivWriteToStream(Stream writeStream)
{ {
FireDebug("Writing Ticket..."); FireDebug("Writing Ticket...");
FireDebug(" Encrypting Title Key..."); FireDebug(" Encrypting Title Key...");
EncryptTitleKey(); PrivEncryptTitleKey();
FireDebug(" -> Decrypted Title Key: {0}", (object)Shared.ByteArrayToString(decryptedTitleKey)); FireDebug(" -> Decrypted Title Key: {0}", (object)Shared.ByteArrayToString(decryptedTitleKey));
FireDebug(" -> Encrypted Title Key: {0}", (object)Shared.ByteArrayToString(encryptedTitleKey)); FireDebug(" -> Encrypted Title Key: {0}", (object)Shared.ByteArrayToString(encryptedTitleKey));
if (fakeSign) if (fakeSign)
@ -421,7 +421,7 @@ namespace libWiiSharp
FireDebug("Writing Ticket Finished..."); FireDebug("Writing Ticket Finished...");
} }
private void ParseTicket(Stream ticketFile) private void PrivParseTicket(Stream ticketFile)
{ {
FireDebug("Parsing Ticket..."); FireDebug("Parsing Ticket...");
ticketFile.Seek(0L, SeekOrigin.Begin); ticketFile.Seek(0L, SeekOrigin.Begin);
@ -478,13 +478,13 @@ namespace libWiiSharp
FireDebug(" Reading Padding4... (Offset: 0x{0})", (object)ticketFile.Position.ToString("x8").ToUpper()); FireDebug(" Reading Padding4... (Offset: 0x{0})", (object)ticketFile.Position.ToString("x8").ToUpper());
ticketFile.Read(padding4, 0, padding4.Length); ticketFile.Read(padding4, 0, padding4.Length);
FireDebug(" Decrypting Title Key..."); FireDebug(" Decrypting Title Key...");
DecryptTitleKey(); PrivDecryptTitleKey();
FireDebug(" -> Encrypted Title Key: {0}", (object)Shared.ByteArrayToString(encryptedTitleKey)); FireDebug(" -> Encrypted Title Key: {0}", (object)Shared.ByteArrayToString(encryptedTitleKey));
FireDebug(" -> Decrypted Title Key: {0}", (object)Shared.ByteArrayToString(decryptedTitleKey)); FireDebug(" -> Decrypted Title Key: {0}", (object)Shared.ByteArrayToString(decryptedTitleKey));
FireDebug("Parsing Ticket Finished..."); FireDebug("Parsing Ticket Finished...");
} }
private void DecryptTitleKey() private void PrivDecryptTitleKey()
{ {
byte[] numArray = commonKeyIndex == 1 ? CommonKey.GetKoreanKey() : CommonKey.GetStandardKey(); byte[] numArray = commonKeyIndex == 1 ? CommonKey.GetKoreanKey() : CommonKey.GetStandardKey();
byte[] bytes = BitConverter.GetBytes(Shared.Swap(titleId)); byte[] bytes = BitConverter.GetBytes(Shared.Swap(titleId));
@ -508,7 +508,7 @@ namespace libWiiSharp
rijndaelManaged.Clear(); rijndaelManaged.Clear();
} }
private void EncryptTitleKey() private void PrivEncryptTitleKey()
{ {
commonKeyIndex = newKeyIndex; commonKeyIndex = newKeyIndex;
byte[] numArray = commonKeyIndex == 1 ? CommonKey.GetKoreanKey() : CommonKey.GetStandardKey(); byte[] numArray = commonKeyIndex == 1 ? CommonKey.GetKoreanKey() : CommonKey.GetStandardKey();
@ -533,10 +533,10 @@ namespace libWiiSharp
rijndaelManaged.Clear(); rijndaelManaged.Clear();
} }
private void ReDecryptTitleKey() private void PrivReDecryptTitleKey()
{ {
encryptedTitleKey = newEncryptedTitleKey; encryptedTitleKey = newEncryptedTitleKey;
DecryptTitleKey(); PrivDecryptTitleKey();
} }
private void FireDebug(string debugMessage, params object[] args) private void FireDebug(string debugMessage, params object[] args)