Continue Formatting/Recommenting

This commit is contained in:
Michael 2021-02-06 21:19:03 -06:00
parent fc1abe4c4c
commit ff33cd3254
16 changed files with 1903 additions and 1535 deletions

View file

@ -1,18 +1,30 @@
// Decompiled with JetBrains decompiler
// Type: libWiiSharp.CommonKey
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll
/* This file is part of libWiiSharp
* Copyright (C) 2009 Leathl
* Copyright (C) 2020 Github Contributors
*
* libWiiSharp is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libWiiSharp is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace libWiiSharp
{
public class CommonKey
{
private static string standardKey = "ebe42a225e8593e448d9c5457381aaf7";
private static string koreanKey = "63b82bb4f4614e2e13f2fefbba4c9b7e";
public class CommonKey
{
private static string standardKey = "ebe42a225e8593e448d9c5457381aaf7";
private static string koreanKey = "63b82bb4f4614e2e13f2fefbba4c9b7e";
public static byte[] GetStandardKey() => Shared.HexStringToByteArray(CommonKey.standardKey);
public static byte[] GetStandardKey() => Shared.HexStringToByteArray(CommonKey.standardKey);
public static byte[] GetKoreanKey() => Shared.HexStringToByteArray(CommonKey.koreanKey);
}
public static byte[] GetKoreanKey() => Shared.HexStringToByteArray(CommonKey.koreanKey);
}
}

View file

@ -1,14 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: libWiiSharp.CommonKeyType
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll
namespace libWiiSharp
{
public enum CommonKeyType : byte
{
Standard,
Korean,
}
}

View file

@ -1,8 +1,20 @@
// Decompiled with JetBrains decompiler
// Type: libWiiSharp.ContentIndices
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll
/* This file is part of libWiiSharp
* Copyright (C) 2009 Leathl
* Copyright (C) 2020 Github Contributors
*
* libWiiSharp is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libWiiSharp is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;

View file

@ -1,301 +1,415 @@
// Decompiled with JetBrains decompiler
// Type: libWiiSharp.HbcTransmitter
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll
/* This file is part of libWiiSharp
* Copyright (C) 2009 Leathl
* Copyright (C) 2020 Github Contributors
*
* libWiiSharp is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libWiiSharp is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.ComponentModel;
using System.IO;
using System.Net.Sockets;
using System.Runtime.InteropServices;
namespace libWiiSharp
{
public class HbcTransmitter : IDisposable
{
private int blocksize = 4096;
private int wiiloadMayor;
private int wiiloadMinor = 5;
private bool compress;
private string ipAddress;
private int port = 4299;
private string lastErrorMessage = string.Empty;
private Protocol protocol;
private TcpClient tcpClient;
private NetworkStream nwStream;
private string lastError = string.Empty;
private int transmittedLength;
private int compressionRatio;
private bool isDisposed;
public int Blocksize
public enum Protocol
{
get => this.blocksize;
set => this.blocksize = value;
/// <summary>
/// Will preconfigure all settings for HBC to 1.0.5 (HAXX).
/// </summary>
HAXX = 0,
/// <summary>
/// Will preconfigure all settings for HBC from 1.0.5 (JODI).
/// </summary>
JODI = 1,
/// <summary>
/// Remember to define your custom settings.
/// </summary>
Custom = 2,
}
public int WiiloadVersionMayor
/// <summary>
/// The HbcTransmitter can easily transmit files to the Homebrew Channel.
/// In order to use compression, you need zlib1.dll in the application directory.
/// </summary>
public class HbcTransmitter : IDisposable
{
get => this.wiiloadMayor;
set => this.wiiloadMayor = value;
}
private int blocksize = 4096;
private int wiiloadMayor;
private int wiiloadMinor = 5;
private bool compress;
private string ipAddress;
private int port = 4299;
private string lastErrorMessage = string.Empty;
private Protocol protocol;
private TcpClient tcpClient;
private NetworkStream nwStream;
private string lastError = string.Empty;
private int transmittedLength;
private int compressionRatio;
private bool isDisposed;
public int WiiloadVersionMinor
{
get => this.wiiloadMinor;
set => this.wiiloadMinor = value;
}
public bool Compress
{
get => this.compress;
set
{
if (this.protocol == Protocol.HAXX)
return;
this.compress = value;
}
}
public string IpAddress
{
get => this.ipAddress;
set => this.ipAddress = value;
}
public int Port
{
get => this.port;
set => this.port = value;
}
public int TransmittedLength => this.transmittedLength;
public int CompressionRatio => this.compressionRatio;
public string LastError => this.lastError;
public event EventHandler<ProgressChangedEventArgs> Progress;
public event EventHandler<MessageEventArgs> Debug;
public HbcTransmitter(Protocol protocol, string ipAddress)
{
this.protocol = protocol;
this.ipAddress = ipAddress;
this.wiiloadMinor = protocol == Protocol.HAXX ? 4 : 5;
this.compress = protocol == Protocol.JODI;
}
~HbcTransmitter() => this.Dispose(false);
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize((object) this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing && !this.isDisposed)
{
this.ipAddress = (string) null;
this.lastErrorMessage = (string) null;
this.lastError = (string) null;
if (this.nwStream != null)
/// <summary>
/// The size of the buffer that is used to transmit the data.
/// Default is 4 * 1024. If you're facing problems (freezes while transmitting), try a higher size.
/// </summary>
public int Blocksize
{
this.nwStream.Close();
this.nwStream = (NetworkStream) null;
get => this.blocksize;
set => this.blocksize = value;
}
if (this.tcpClient != null)
/// <summary>
/// The mayor version of wiiload. You might need to change it for upcoming releases of the HBC.
/// </summary>
public int WiiloadVersionMayor
{
this.tcpClient.Close();
this.tcpClient = (TcpClient) null;
get => this.wiiloadMayor;
set => this.wiiloadMayor = value;
}
}
this.isDisposed = true;
/// <summary>
/// The minor version of wiiload. You might need to change it for upcoming releases of the HBC.
/// </summary>
public int WiiloadVersionMinor
{
get => this.wiiloadMinor;
set => this.wiiloadMinor = value;
}
/// <summary>
/// If true, the data will be compressed before being transmitted. NOT available for Protocol.HAXX!
/// Also, compression will only work if zlib1.dll is in the application folder.
/// </summary>
public bool Compress
{
get => this.compress;
set
{
if (this.protocol == Protocol.HAXX)
return;
this.compress = value;
}
}
/// <summary>
/// The IP address of the Wii.
/// </summary>
public string IpAddress
{
get => this.ipAddress;
set => this.ipAddress = value;
}
/// The port used for the transmission.
/// You don't need to touch this unless the port changes in future releases of the HBC.
/// </summary>
public int Port
{
get => this.port;
set => this.port = value;
}
/// <summary>
/// After a successfully completed transmission, this value holds the number of transmitted bytes.
/// </summary>
public int TransmittedLength => this.transmittedLength;
/// <summary>
/// After a successfully completed transmission, this value holds the compression ratio.
/// Will be 0 if the data wasn't compressed.
/// </summary>
public int CompressionRatio => this.compressionRatio;
/// <summary>
/// Holds the last occured error message.
/// </summary>
public string LastError => this.lastError;
public HbcTransmitter(Protocol protocol, string ipAddress)
{
this.protocol = protocol;
this.ipAddress = ipAddress;
this.wiiloadMinor = protocol == Protocol.HAXX ? 4 : 5;
this.compress = protocol == Protocol.JODI;
}
#region IDisposable Members
~HbcTransmitter() => this.Dispose(false);
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize((object) this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing && !this.isDisposed)
{
this.ipAddress = (string) null;
this.lastErrorMessage = (string) null;
this.lastError = (string) null;
if (this.nwStream != null)
{
this.nwStream.Close();
this.nwStream = (NetworkStream) null;
}
if (this.tcpClient != null)
{
this.tcpClient.Close();
this.tcpClient = (TcpClient) null;
}
}
this.isDisposed = true;
}
#endregion
#region Public Functions
public bool TransmitFile(string pathToFile) => this.transmit(Path.GetFileName(pathToFile), File.ReadAllBytes(pathToFile));
public bool TransmitFile(string fileName, byte[] fileData) => this.transmit(fileName, fileData);
#endregion
#region Private Functions
private bool transmit(string fileName, byte[] fileData)
{
this.fireDebug("Transmitting {0} to {1}:{2}...", (object) fileName, (object) this.ipAddress, (object) this.port);
if (!Environment.OSVersion.ToString().ToLower().Contains("windows"))
this.compress = false;
if (fileName.ToLower().EndsWith(".zip"))
this.compress = false;
this.tcpClient = new TcpClient();
byte[] buffer1 = new byte[4];
this.fireDebug(" Connecting...");
try
{
this.tcpClient.Connect(this.ipAddress, 4299);
}
catch (Exception ex)
{
this.fireDebug(" -> Connection Failed:\n" + ex.Message);
this.lastError = "Connection Failed:\n" + ex.Message;
this.tcpClient.Close();
return false;
}
this.nwStream = this.tcpClient.GetStream();
this.fireDebug(" Sending Magic...");
buffer1[0] = (byte) 72;
buffer1[1] = (byte) 65;
buffer1[2] = (byte) 88;
buffer1[3] = (byte) 88;
try
{
this.nwStream.Write(buffer1, 0, 4);
}
catch (Exception ex)
{
this.fireDebug(" -> Error sending Magic:\n" + ex.Message);
this.lastError = "Error sending Magic:\n" + ex.Message;
this.nwStream.Close();
this.tcpClient.Close();
return false;
}
this.fireDebug(" Sending Version Info...");
buffer1[0] = (byte) this.wiiloadMayor;
buffer1[1] = (byte) this.wiiloadMinor;
buffer1[2] = (byte) (fileName.Length + 2 >> 8 & (int) byte.MaxValue);
buffer1[3] = (byte) (fileName.Length + 2 & (int) byte.MaxValue);
try
{
this.nwStream.Write(buffer1, 0, 4);
}
catch (Exception ex)
{
this.fireDebug(" -> Error sending Version Info:\n" + ex.Message);
this.lastError = "Error sending Version Info:\n" + ex.Message;
this.nwStream.Close();
this.tcpClient.Close();
return false;
}
byte[] buffer2;
if (this.compress)
{
this.fireDebug(" Compressing File...");
try
{
buffer2 = zlibWrapper.Compress(fileData);
}
catch
{
this.fireDebug(" -> Compression failed, continuing without compression...");
this.compress = false;
buffer2 = fileData;
fileData = new byte[0];
}
}
else
{
buffer2 = fileData;
fileData = new byte[0];
}
this.fireDebug(" Sending Filesize...");
buffer1[0] = (byte) (buffer2.Length >> 24 & (int) byte.MaxValue);
buffer1[1] = (byte) (buffer2.Length >> 16 & (int) byte.MaxValue);
buffer1[2] = (byte) (buffer2.Length >> 8 & (int) byte.MaxValue);
buffer1[3] = (byte) (buffer2.Length & (int) byte.MaxValue);
try
{
this.nwStream.Write(buffer1, 0, 4);
}
catch (Exception ex)
{
this.fireDebug(" -> Error sending Filesize:\n" + ex.Message);
this.lastError = "Error sending Filesize:\n" + ex.Message;
this.nwStream.Close();
this.tcpClient.Close();
return false;
}
if (this.protocol != Protocol.HAXX)
{
buffer1[0] = (byte) (fileData.Length >> 24 & (int) byte.MaxValue);
buffer1[1] = (byte) (fileData.Length >> 16 & (int) byte.MaxValue);
buffer1[2] = (byte) (fileData.Length >> 8 & (int) byte.MaxValue);
buffer1[3] = (byte) (fileData.Length & (int) byte.MaxValue);
try
{
this.nwStream.Write(buffer1, 0, 4);
}
catch (Exception ex)
{
this.fireDebug(" -> Error sending Filesize:\n" + ex.Message);
this.lastError = "Error sending Filesize:\n" + ex.Message;
this.nwStream.Close();
this.tcpClient.Close();
return false;
}
}
this.fireDebug(" Sending File...");
int offset = 0;
int num1 = 0;
int num2 = buffer2.Length / this.Blocksize;
int num3 = buffer2.Length % this.Blocksize;
try
{
do
{
this.fireProgress(++num1 * 100 / num2);
this.nwStream.Write(buffer2, offset, this.Blocksize);
offset += this.Blocksize;
}
while (num1 < num2);
if (num3 > 0)
this.nwStream.Write(buffer2, offset, buffer2.Length - offset);
}
catch (Exception ex)
{
this.fireDebug(" -> Error sending File:\n" + ex.Message);
this.lastError = "Error sending File:\n" + ex.Message;
this.nwStream.Close();
this.tcpClient.Close();
return false;
}
this.fireDebug(" Sending Arguments...");
byte[] buffer3 = new byte[fileName.Length + 2];
for (int index = 0; index < fileName.Length; ++index)
buffer3[index] = (byte) fileName.ToCharArray()[index];
try
{
this.nwStream.Write(buffer3, 0, buffer3.Length);
}
catch (Exception ex)
{
this.fireDebug(" -> Error sending Arguments:\n" + ex.Message);
this.lastError = "Error sending Arguments:\n" + ex.Message;
this.nwStream.Close();
this.tcpClient.Close();
return false;
}
this.nwStream.Close();
this.tcpClient.Close();
this.transmittedLength = buffer2.Length;
this.compressionRatio = !this.compress || fileData.Length == 0 ? 0 : buffer2.Length * 100 / fileData.Length;
this.fireDebug("Transmitting {0} to {1}:{2} Finished...", (object) fileName, (object) this.ipAddress, (object) this.port);
return true;
}
#endregion
#region Events
/// <summary>
/// Fires the Progress of various operations
/// </summary>
public event EventHandler<ProgressChangedEventArgs> Progress;
/// <summary>
/// Fires debugging messages. You may write them into a log file or log textbox.
/// </summary>
public event EventHandler<MessageEventArgs> Debug;
private void fireDebug(string debugMessage, params object[] args)
{
EventHandler<MessageEventArgs> debug = this.Debug;
if (debug == null)
return;
debug(new object(), new MessageEventArgs(string.Format(debugMessage, args)));
}
private void fireProgress(int progressPercentage)
{
EventHandler<ProgressChangedEventArgs> progress = this.Progress;
if (progress == null)
return;
progress(new object(), new ProgressChangedEventArgs(progressPercentage, (object) string.Empty));
}
#endregion
}
public bool TransmitFile(string pathToFile) => this.transmit(Path.GetFileName(pathToFile), File.ReadAllBytes(pathToFile));
public bool TransmitFile(string fileName, byte[] fileData) => this.transmit(fileName, fileData);
private bool transmit(string fileName, byte[] fileData)
internal class zlibWrapper
{
this.fireDebug("Transmitting {0} to {1}:{2}...", (object) fileName, (object) this.ipAddress, (object) this.port);
if (!Environment.OSVersion.ToString().ToLower().Contains("windows"))
this.compress = false;
if (fileName.ToLower().EndsWith(".zip"))
this.compress = false;
this.tcpClient = new TcpClient();
byte[] buffer1 = new byte[4];
this.fireDebug(" Connecting...");
try
{
this.tcpClient.Connect(this.ipAddress, 4299);
}
catch (Exception ex)
{
this.fireDebug(" -> Connection Failed:\n" + ex.Message);
this.lastError = "Connection Failed:\n" + ex.Message;
this.tcpClient.Close();
return false;
}
this.nwStream = this.tcpClient.GetStream();
this.fireDebug(" Sending Magic...");
buffer1[0] = (byte) 72;
buffer1[1] = (byte) 65;
buffer1[2] = (byte) 88;
buffer1[3] = (byte) 88;
try
{
this.nwStream.Write(buffer1, 0, 4);
}
catch (Exception ex)
{
this.fireDebug(" -> Error sending Magic:\n" + ex.Message);
this.lastError = "Error sending Magic:\n" + ex.Message;
this.nwStream.Close();
this.tcpClient.Close();
return false;
}
this.fireDebug(" Sending Version Info...");
buffer1[0] = (byte) this.wiiloadMayor;
buffer1[1] = (byte) this.wiiloadMinor;
buffer1[2] = (byte) (fileName.Length + 2 >> 8 & (int) byte.MaxValue);
buffer1[3] = (byte) (fileName.Length + 2 & (int) byte.MaxValue);
try
{
this.nwStream.Write(buffer1, 0, 4);
}
catch (Exception ex)
{
this.fireDebug(" -> Error sending Version Info:\n" + ex.Message);
this.lastError = "Error sending Version Info:\n" + ex.Message;
this.nwStream.Close();
this.tcpClient.Close();
return false;
}
byte[] buffer2;
if (this.compress)
{
this.fireDebug(" Compressing File...");
try
[DllImport("zlib1.dll")]
private static extern zlibWrapper.ZLibError compress2(
byte[] dest,
ref int destLength,
byte[] source,
int sourceLength,
int level);
public static byte[] Compress(byte[] inFile)
{
buffer2 = zlibWrapper.Compress(fileData);
byte[] array = new byte[inFile.Length + 64];
int destLength = -1;
zlibWrapper.ZLibError zlibError = zlibWrapper.compress2(array, ref destLength, inFile, inFile.Length, 6);
if (zlibError != zlibWrapper.ZLibError.Z_OK || destLength <= -1 || destLength >= inFile.Length)
throw new Exception("An error occured while compressing! Code: " + zlibError.ToString());
Array.Resize<byte>(ref array, destLength);
return array;
}
catch
public enum ZLibError
{
this.fireDebug(" -> Compression failed, continuing without compression...");
this.compress = false;
buffer2 = fileData;
fileData = new byte[0];
Z_VERSION_ERROR = -6, // 0xFFFFFFFA
Z_BUF_ERROR = -5, // 0xFFFFFFFB
Z_MEM_ERROR = -4, // 0xFFFFFFFC
Z_DATA_ERROR = -3, // 0xFFFFFFFD
Z_STREAM_ERROR = -2, // 0xFFFFFFFE
Z_ERRNO = -1, // 0xFFFFFFFF
Z_OK = 0,
Z_STREAM_END = 1,
Z_NEED_DICT = 2,
}
}
else
{
buffer2 = fileData;
fileData = new byte[0];
}
this.fireDebug(" Sending Filesize...");
buffer1[0] = (byte) (buffer2.Length >> 24 & (int) byte.MaxValue);
buffer1[1] = (byte) (buffer2.Length >> 16 & (int) byte.MaxValue);
buffer1[2] = (byte) (buffer2.Length >> 8 & (int) byte.MaxValue);
buffer1[3] = (byte) (buffer2.Length & (int) byte.MaxValue);
try
{
this.nwStream.Write(buffer1, 0, 4);
}
catch (Exception ex)
{
this.fireDebug(" -> Error sending Filesize:\n" + ex.Message);
this.lastError = "Error sending Filesize:\n" + ex.Message;
this.nwStream.Close();
this.tcpClient.Close();
return false;
}
if (this.protocol != Protocol.HAXX)
{
buffer1[0] = (byte) (fileData.Length >> 24 & (int) byte.MaxValue);
buffer1[1] = (byte) (fileData.Length >> 16 & (int) byte.MaxValue);
buffer1[2] = (byte) (fileData.Length >> 8 & (int) byte.MaxValue);
buffer1[3] = (byte) (fileData.Length & (int) byte.MaxValue);
try
{
this.nwStream.Write(buffer1, 0, 4);
}
catch (Exception ex)
{
this.fireDebug(" -> Error sending Filesize:\n" + ex.Message);
this.lastError = "Error sending Filesize:\n" + ex.Message;
this.nwStream.Close();
this.tcpClient.Close();
return false;
}
}
this.fireDebug(" Sending File...");
int offset = 0;
int num1 = 0;
int num2 = buffer2.Length / this.Blocksize;
int num3 = buffer2.Length % this.Blocksize;
try
{
do
{
this.fireProgress(++num1 * 100 / num2);
this.nwStream.Write(buffer2, offset, this.Blocksize);
offset += this.Blocksize;
}
while (num1 < num2);
if (num3 > 0)
this.nwStream.Write(buffer2, offset, buffer2.Length - offset);
}
catch (Exception ex)
{
this.fireDebug(" -> Error sending File:\n" + ex.Message);
this.lastError = "Error sending File:\n" + ex.Message;
this.nwStream.Close();
this.tcpClient.Close();
return false;
}
this.fireDebug(" Sending Arguments...");
byte[] buffer3 = new byte[fileName.Length + 2];
for (int index = 0; index < fileName.Length; ++index)
buffer3[index] = (byte) fileName.ToCharArray()[index];
try
{
this.nwStream.Write(buffer3, 0, buffer3.Length);
}
catch (Exception ex)
{
this.fireDebug(" -> Error sending Arguments:\n" + ex.Message);
this.lastError = "Error sending Arguments:\n" + ex.Message;
this.nwStream.Close();
this.tcpClient.Close();
return false;
}
this.nwStream.Close();
this.tcpClient.Close();
this.transmittedLength = buffer2.Length;
this.compressionRatio = !this.compress || fileData.Length == 0 ? 0 : buffer2.Length * 100 / fileData.Length;
this.fireDebug("Transmitting {0} to {1}:{2} Finished...", (object) fileName, (object) this.ipAddress, (object) this.port);
return true;
}
private void fireDebug(string debugMessage, params object[] args)
{
EventHandler<MessageEventArgs> debug = this.Debug;
if (debug == null)
return;
debug(new object(), new MessageEventArgs(string.Format(debugMessage, args)));
}
private void fireProgress(int progressPercentage)
{
EventHandler<ProgressChangedEventArgs> progress = this.Progress;
if (progress == null)
return;
progress(new object(), new ProgressChangedEventArgs(progressPercentage, (object) string.Empty));
}
}
}

1330
Headers.cs

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,20 @@
// Decompiled with JetBrains decompiler
// Type: libWiiSharp.HexView
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll
/* This file is part of libWiiSharp
* Copyright (C) 2009 Leathl
* Copyright (C) 2020 Github Contributors
*
* libWiiSharp is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libWiiSharp is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
@ -12,249 +24,319 @@ using System.Windows.Forms;
namespace libWiiSharp
{
public static class HexView
{
private static string savedValue;
public static void DumpToListView(byte[] data, ListView listView) => HexView.dumpToListView(data, listView);
public static void DumpToDataGridView(byte[] data, DataGridView dataGridView) => HexView.dumpToDataGridView(data, dataGridView);
public static byte[] DumpFromDataGridView(DataGridView dataGridView) => HexView.dumpFromDataGridView(dataGridView);
public static void DumpToRichTextBox(byte[] data, RichTextBox richTextBox)
/// <summary>
/// A static class that provides functions to dump a byte array to view it like in a hex-editor.
/// In combination with a DataGridView, it's even able to act like a hex-editor.
/// Big files (25kB ++) will take quite a long time, so don't use this for big files.
/// </summary>
public static class HexView
{
richTextBox.Clear();
richTextBox.Font = new Font("Courier New", 9f);
richTextBox.ReadOnly = true;
richTextBox.Text = HexView.DumpAsString(data);
private static string savedValue;
#region Public Functions
/// <summary>
/// Displays the byte array like a hex editor in a ListView.
/// Columns will be created, estimated width is ~685 px.
/// Big files (25kB ++) will take quite a long time, so don't use this for big files.
/// </summary>
/// <param name="data"></param>
/// <param name="listView"></param>
public static void DumpToListView(byte[] data, ListView listView) => HexView.dumpToListView(data, listView);
/// <summary>
/// Displays the byte array like a hex editor in a DataGridView.
/// Columns will be created, estimated width is ~685 px.
/// Big files (25kB ++) will take quite a long time, so don't use this for big files.
/// </summary>
/// <param name="data"></param>
/// <param name="dataGridView"></param>
public static void DumpToDataGridView(byte[] data, DataGridView dataGridView) => HexView.dumpToDataGridView(data, dataGridView);
/// <summary>
/// Dumps a DataGridView back to a byte array.
/// The DataGridView must have the right format.
/// Big files (25kB ++) will take quite a long time, so don't use this for big files.
/// </summary>
/// <param name="dataGridView"></param>
/// <returns></returns>
public static byte[] DumpFromDataGridView(DataGridView dataGridView) => HexView.dumpFromDataGridView(dataGridView);
/// <summary>
/// Displays the byte array like a hex editor in a RichTextBox.
/// Big files (25kB ++) will take quite a long time, so don't use this for big files.
/// </summary>
/// <param name="data"></param>
/// <param name="richTextBox"></param>
public static void DumpToRichTextBox(byte[] data, RichTextBox richTextBox)
{
richTextBox.Clear();
richTextBox.Font = new Font("Courier New", 9f);
richTextBox.ReadOnly = true;
richTextBox.Text = HexView.DumpAsString(data);
}
/// <summary>
/// Displays the byte array like a hex editor in a TextBox.
/// Big files (25kB ++) will take quite a long time, so don't use this for big files.
/// </summary>
/// <param name="data"></param>
/// <param name="textBox"></param>
public static void DumpToTextBox(byte[] data, TextBox textBox)
{
textBox.Multiline = true;
textBox.Font = new Font("Courier New", 9f);
textBox.ReadOnly = true;
textBox.Text = HexView.DumpAsString(data).Replace("\n", "\r\n");
}
/// <summary>
/// Displays the byte array like a hex editor as a string array.
/// Be sure to use "Courier New" as a font, so every char has the same width.
/// Big files (25kB ++) will take quite a long time, so don't use this for big files.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string[] DumpAsStringArray(byte[] data) => HexView.dumpAsStringArray(data);
/// <summary>
/// Displays the byte array like a hex editor as a string.
/// Be sure to use "Courier New" as a font, so every char has the same width.
/// Big files (25kB ++) will take quite a long time, so don't use this for big files.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string DumpAsString(byte[] data) => string.Join("\n", HexView.dumpAsStringArray(data));
/// <summary>
/// Link your DataGridView's CellEndEdit event with this function.
/// The dump and byte values will be synchronized.
/// Don't forget to also link the CellBeginEdit event.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static void DataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
try
{
DataGridView dataGridView = sender as DataGridView;
if (dataGridView.Columns[e.ColumnIndex].HeaderText.ToLower() == "dump")
{
string str = (string) dataGridView.Rows[e.RowIndex].Cells[17].Value;
if (!(str != HexView.savedValue))
return;
if (str.Length != 16)
throw new Exception();
for (int index = 0; index < 16; ++index)
{
if ((int) HexView.toAscii(byte.Parse((string) dataGridView.Rows[e.RowIndex].Cells[index + 1].Value, NumberStyles.HexNumber)) != (int) str[index])
dataGridView.Rows[e.RowIndex].Cells[index + 1].Value = (object) HexView.fromAscii(str[index]).ToString("x2");
}
}
else
{
if (((string) dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).Length == 1)
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = (object) ("0" + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value?.ToString());
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, HexView.toAscii(byte.Parse((string) dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, NumberStyles.HexNumber)).ToString());
dataGridView.Rows[e.RowIndex].Cells[17].Value = (object) str;
if (((string) dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).Length <= 2)
return;
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = (object) ((string) dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).Remove(0, ((string) dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).Length - 2);
}
}
catch
{
((DataGridView) sender).Rows[e.RowIndex].Cells[e.ColumnIndex].Value = (object) HexView.savedValue;
}
}
/// <summary>
/// Link your DataGridView's CellBeginEdit event with this function.
/// The dump and byte values will be synchronized.
/// Don't forget to also link the CellEndEdit event.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static void DataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) => HexView.savedValue = (string) ((DataGridView) sender).Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
#endregion
#region Private Functions
private static string[] dumpAsStringArray(byte[] data)
{
List<string> stringList = new List<string>();
string empty = string.Empty;
int num;
char ascii;
for (num = 0; (double) (data.Length - num) / 16.0 >= 1.0; num += 16)
{
string str1 = string.Empty + num.ToString("x8") + " ";
string str2 = string.Empty;
for (int index = 0; index < 16; ++index)
{
str1 = str1 + data[num + index].ToString("x2") + " ";
string str3 = str2;
ascii = HexView.toAscii(data[num + index]);
string str4 = ascii.ToString();
str2 = str3 + str4;
}
string str5 = str1 + " " + str2;
stringList.Add(str5);
}
if (data.Length > num)
{
string str1 = string.Empty + num.ToString("x8") + " ";
string str2 = string.Empty;
for (int index = 0; index < 16; ++index)
{
if (index < data.Length - num)
{
str1 = str1 + data[num + index].ToString("x2") + " ";
string str3 = str2;
ascii = HexView.toAscii(data[num + index]);
string str4 = ascii.ToString();
str2 = str3 + str4;
}
else
str1 += " ";
}
string str5 = str1 + " " + str2;
stringList.Add(str5);
}
return stringList.ToArray();
}
private static byte[] dumpFromDataGridView(DataGridView dataGridView)
{
try
{
List<byte> byteList = new List<byte>();
for (int index1 = 0; !string.IsNullOrEmpty((string) dataGridView.Rows[index1].Cells[1].Value); ++index1)
{
for (int index2 = 0; index2 < 16; ++index2)
{
if (!string.IsNullOrEmpty((string) dataGridView.Rows[index1].Cells[index2 + 1].Value))
byteList.Add(byte.Parse((string) dataGridView.Rows[index1].Cells[index2 + 1].Value, NumberStyles.HexNumber));
}
if (index1 == dataGridView.Rows.Count - 1)
break;
}
return byteList.ToArray();
}
catch
{
throw new Exception("An error occured. The DataGridView might have the wrong format!");
}
}
private static void dumpToDataGridView(byte[] data, DataGridView dataGridView)
{
dataGridView.Columns.Clear();
dataGridView.Rows.Clear();
dataGridView.Font = new Font("Courier New", 9f);
dataGridView.Columns.Add(new DataGridViewColumn()
{
HeaderText = "Offset",
Width = 80,
CellTemplate = (DataGridViewCell) new DataGridViewTextBoxCell()
});
for (int index = 0; index < 16; ++index)
dataGridView.Columns.Add(new DataGridViewColumn()
{
HeaderText = index.ToString("x1"),
Width = 30,
CellTemplate = (DataGridViewCell) new DataGridViewTextBoxCell()
});
dataGridView.Columns.Add(new DataGridViewColumn()
{
HeaderText = "Dump",
Width = 125,
CellTemplate = (DataGridViewCell) new DataGridViewTextBoxCell()
});
int num;
for (num = 0; (double) (data.Length - num) / 16.0 >= 1.0; num += 16)
{
DataGridViewRow dataGridViewRow = new DataGridViewRow();
int index1 = dataGridViewRow.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
dataGridViewRow.Cells[index1].Value = (object) num.ToString("x8");
dataGridViewRow.Cells[index1].ReadOnly = true;
string empty = string.Empty;
for (int index2 = 0; index2 < 16; ++index2)
{
int index3 = dataGridViewRow.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
dataGridViewRow.Cells[index3].Value = (object) data[num + index2].ToString("x2");
empty += HexView.toAscii(data[num + index2]).ToString();
}
int index4 = dataGridViewRow.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
dataGridViewRow.Cells[index4].Value = (object) empty;
dataGridView.Rows.Add(dataGridViewRow);
}
if (data.Length <= num)
return;
DataGridViewRow dataGridViewRow1 = new DataGridViewRow();
int index5 = dataGridViewRow1.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
dataGridViewRow1.Cells[index5].Value = (object) num.ToString("x8");
dataGridViewRow1.Cells[index5].ReadOnly = true;
string empty1 = string.Empty;
for (int index1 = 0; index1 < 16; ++index1)
{
if (index1 < data.Length - num)
{
int index2 = dataGridViewRow1.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
dataGridViewRow1.Cells[index2].Value = (object) data[num + index1].ToString("x2");
empty1 += HexView.toAscii(data[num + index1]).ToString();
}
else
dataGridViewRow1.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
}
int index6 = dataGridViewRow1.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
dataGridViewRow1.Cells[index6].Value = (object) empty1;
dataGridView.Rows.Add(dataGridViewRow1);
}
private static void dumpToListView(byte[] data, ListView listView)
{
listView.Columns.Clear();
listView.Items.Clear();
listView.View = View.Details;
listView.Font = new Font("Courier New", 9f);
listView.Columns.Add("Offset", "Offset", 80, HorizontalAlignment.Left, string.Empty);
for (int index = 0; index < 16; ++index)
listView.Columns.Add(index.ToString("x1"), index.ToString("x1"), 30, HorizontalAlignment.Left, string.Empty);
listView.Columns.Add("Dump", "Dump", 125, HorizontalAlignment.Left, string.Empty);
int num;
for (num = 0; (double) (data.Length - num) / 16.0 >= 1.0; num += 16)
{
ListViewItem listViewItem = new ListViewItem(num.ToString("x8"));
string empty = string.Empty;
for (int index = 0; index < 16; ++index)
{
listViewItem.SubItems.Add(data[num + index].ToString("x2"));
empty += HexView.toAscii(data[num + index]).ToString();
}
listViewItem.SubItems.Add(empty);
listView.Items.Add(listViewItem);
}
if (data.Length <= num)
return;
ListViewItem listViewItem1 = new ListViewItem(num.ToString("x8"));
string empty1 = string.Empty;
for (int index = 0; index < 16; ++index)
{
if (index < data.Length - num)
{
listViewItem1.SubItems.Add(data[num + index].ToString("x2"));
empty1 += HexView.toAscii(data[num + index]).ToString();
}
else
listViewItem1.SubItems.Add(string.Empty);
}
listViewItem1.SubItems.Add(empty1);
listView.Items.Add(listViewItem1);
}
private static char toAscii(byte value) => value >= (byte) 32 && value <= (byte) 126 ? (char) value : '.';
private static byte fromAscii(char value) => (byte) value;
#endregion
}
public static void DumpToTextBox(byte[] data, TextBox textBox)
{
textBox.Multiline = true;
textBox.Font = new Font("Courier New", 9f);
textBox.ReadOnly = true;
textBox.Text = HexView.DumpAsString(data).Replace("\n", "\r\n");
}
public static string[] DumpAsStringArray(byte[] data) => HexView.dumpAsStringArray(data);
public static string DumpAsString(byte[] data) => string.Join("\n", HexView.dumpAsStringArray(data));
public static void DataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
try
{
DataGridView dataGridView = sender as DataGridView;
if (dataGridView.Columns[e.ColumnIndex].HeaderText.ToLower() == "dump")
{
string str = (string) dataGridView.Rows[e.RowIndex].Cells[17].Value;
if (!(str != HexView.savedValue))
return;
if (str.Length != 16)
throw new Exception();
for (int index = 0; index < 16; ++index)
{
if ((int) HexView.toAscii(byte.Parse((string) dataGridView.Rows[e.RowIndex].Cells[index + 1].Value, NumberStyles.HexNumber)) != (int) str[index])
dataGridView.Rows[e.RowIndex].Cells[index + 1].Value = (object) HexView.fromAscii(str[index]).ToString("x2");
}
}
else
{
if (((string) dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).Length == 1)
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = (object) ("0" + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value?.ToString());
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, HexView.toAscii(byte.Parse((string) dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, NumberStyles.HexNumber)).ToString());
dataGridView.Rows[e.RowIndex].Cells[17].Value = (object) str;
if (((string) dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).Length <= 2)
return;
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = (object) ((string) dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).Remove(0, ((string) dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).Length - 2);
}
}
catch
{
((DataGridView) sender).Rows[e.RowIndex].Cells[e.ColumnIndex].Value = (object) HexView.savedValue;
}
}
public static void DataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) => HexView.savedValue = (string) ((DataGridView) sender).Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
private static string[] dumpAsStringArray(byte[] data)
{
List<string> stringList = new List<string>();
string empty = string.Empty;
int num;
char ascii;
for (num = 0; (double) (data.Length - num) / 16.0 >= 1.0; num += 16)
{
string str1 = string.Empty + num.ToString("x8") + " ";
string str2 = string.Empty;
for (int index = 0; index < 16; ++index)
{
str1 = str1 + data[num + index].ToString("x2") + " ";
string str3 = str2;
ascii = HexView.toAscii(data[num + index]);
string str4 = ascii.ToString();
str2 = str3 + str4;
}
string str5 = str1 + " " + str2;
stringList.Add(str5);
}
if (data.Length > num)
{
string str1 = string.Empty + num.ToString("x8") + " ";
string str2 = string.Empty;
for (int index = 0; index < 16; ++index)
{
if (index < data.Length - num)
{
str1 = str1 + data[num + index].ToString("x2") + " ";
string str3 = str2;
ascii = HexView.toAscii(data[num + index]);
string str4 = ascii.ToString();
str2 = str3 + str4;
}
else
str1 += " ";
}
string str5 = str1 + " " + str2;
stringList.Add(str5);
}
return stringList.ToArray();
}
private static byte[] dumpFromDataGridView(DataGridView dataGridView)
{
try
{
List<byte> byteList = new List<byte>();
for (int index1 = 0; !string.IsNullOrEmpty((string) dataGridView.Rows[index1].Cells[1].Value); ++index1)
{
for (int index2 = 0; index2 < 16; ++index2)
{
if (!string.IsNullOrEmpty((string) dataGridView.Rows[index1].Cells[index2 + 1].Value))
byteList.Add(byte.Parse((string) dataGridView.Rows[index1].Cells[index2 + 1].Value, NumberStyles.HexNumber));
}
if (index1 == dataGridView.Rows.Count - 1)
break;
}
return byteList.ToArray();
}
catch
{
throw new Exception("An error occured. The DataGridView might have the wrong format!");
}
}
private static void dumpToDataGridView(byte[] data, DataGridView dataGridView)
{
dataGridView.Columns.Clear();
dataGridView.Rows.Clear();
dataGridView.Font = new Font("Courier New", 9f);
dataGridView.Columns.Add(new DataGridViewColumn()
{
HeaderText = "Offset",
Width = 80,
CellTemplate = (DataGridViewCell) new DataGridViewTextBoxCell()
});
for (int index = 0; index < 16; ++index)
dataGridView.Columns.Add(new DataGridViewColumn()
{
HeaderText = index.ToString("x1"),
Width = 30,
CellTemplate = (DataGridViewCell) new DataGridViewTextBoxCell()
});
dataGridView.Columns.Add(new DataGridViewColumn()
{
HeaderText = "Dump",
Width = 125,
CellTemplate = (DataGridViewCell) new DataGridViewTextBoxCell()
});
int num;
for (num = 0; (double) (data.Length - num) / 16.0 >= 1.0; num += 16)
{
DataGridViewRow dataGridViewRow = new DataGridViewRow();
int index1 = dataGridViewRow.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
dataGridViewRow.Cells[index1].Value = (object) num.ToString("x8");
dataGridViewRow.Cells[index1].ReadOnly = true;
string empty = string.Empty;
for (int index2 = 0; index2 < 16; ++index2)
{
int index3 = dataGridViewRow.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
dataGridViewRow.Cells[index3].Value = (object) data[num + index2].ToString("x2");
empty += HexView.toAscii(data[num + index2]).ToString();
}
int index4 = dataGridViewRow.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
dataGridViewRow.Cells[index4].Value = (object) empty;
dataGridView.Rows.Add(dataGridViewRow);
}
if (data.Length <= num)
return;
DataGridViewRow dataGridViewRow1 = new DataGridViewRow();
int index5 = dataGridViewRow1.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
dataGridViewRow1.Cells[index5].Value = (object) num.ToString("x8");
dataGridViewRow1.Cells[index5].ReadOnly = true;
string empty1 = string.Empty;
for (int index1 = 0; index1 < 16; ++index1)
{
if (index1 < data.Length - num)
{
int index2 = dataGridViewRow1.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
dataGridViewRow1.Cells[index2].Value = (object) data[num + index1].ToString("x2");
empty1 += HexView.toAscii(data[num + index1]).ToString();
}
else
dataGridViewRow1.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
}
int index6 = dataGridViewRow1.Cells.Add((DataGridViewCell) new DataGridViewTextBoxCell());
dataGridViewRow1.Cells[index6].Value = (object) empty1;
dataGridView.Rows.Add(dataGridViewRow1);
}
private static void dumpToListView(byte[] data, ListView listView)
{
listView.Columns.Clear();
listView.Items.Clear();
listView.View = View.Details;
listView.Font = new Font("Courier New", 9f);
listView.Columns.Add("Offset", "Offset", 80, HorizontalAlignment.Left, string.Empty);
for (int index = 0; index < 16; ++index)
listView.Columns.Add(index.ToString("x1"), index.ToString("x1"), 30, HorizontalAlignment.Left, string.Empty);
listView.Columns.Add("Dump", "Dump", 125, HorizontalAlignment.Left, string.Empty);
int num;
for (num = 0; (double) (data.Length - num) / 16.0 >= 1.0; num += 16)
{
ListViewItem listViewItem = new ListViewItem(num.ToString("x8"));
string empty = string.Empty;
for (int index = 0; index < 16; ++index)
{
listViewItem.SubItems.Add(data[num + index].ToString("x2"));
empty += HexView.toAscii(data[num + index]).ToString();
}
listViewItem.SubItems.Add(empty);
listView.Items.Add(listViewItem);
}
if (data.Length <= num)
return;
ListViewItem listViewItem1 = new ListViewItem(num.ToString("x8"));
string empty1 = string.Empty;
for (int index = 0; index < 16; ++index)
{
if (index < data.Length - num)
{
listViewItem1.SubItems.Add(data[num + index].ToString("x2"));
empty1 += HexView.toAscii(data[num + index]).ToString();
}
else
listViewItem1.SubItems.Add(string.Empty);
}
listViewItem1.SubItems.Add(empty1);
listView.Items.Add(listViewItem1);
}
private static char toAscii(byte value) => value >= (byte) 32 && value <= (byte) 126 ? (char) value : '.';
private static byte fromAscii(char value) => (byte) value;
}
}

View file

@ -1,8 +1,20 @@
// Decompiled with JetBrains decompiler
// Type: libWiiSharp.IosPatcher
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll
/* This file is part of libWiiSharp
* Copyright (C) 2009 Leathl
* Copyright (C) 2020 Github Contributors
*
* libWiiSharp is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libWiiSharp is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.ComponentModel;
@ -10,277 +22,314 @@ using System.Text;
namespace libWiiSharp
{
public class IosPatcher
{
private WAD wadFile;
private int esIndex = -1;
public event EventHandler<ProgressChangedEventArgs> Progress;
public event EventHandler<MessageEventArgs> Debug;
public void LoadIOS(ref WAD iosWad)
/// <summary>
/// An IOS patcher which can patch fakesigning, es_identify and nand permissions.
/// </summary>
public class IosPatcher
{
this.wadFile = iosWad;
this.getEsIndex();
}
private WAD wadFile;
private int esIndex = -1;
public int PatchFakeSigning() => this.esIndex < 0 ? -1 : this.patchFakeSigning(ref this.wadFile.Contents[this.esIndex]);
public int PatchEsIdentify() => this.esIndex < 0 ? -1 : this.patchEsIdentify(ref this.wadFile.Contents[this.esIndex]);
public int PatchNandPermissions() => this.esIndex < 0 ? -1 : this.patchNandPermissions(ref this.wadFile.Contents[this.esIndex]);
public int PatchVP() => this.esIndex < 0 ? -1 : this.patchVP(ref this.wadFile.Contents[this.esIndex]);
public int PatchAll() => this.esIndex < 0 ? -1 : this.patchAll(ref this.wadFile.Contents[this.esIndex]);
public int PatchFakeSigning(ref byte[] esModule) => this.patchFakeSigning(ref esModule);
public int PatchEsIdentify(ref byte[] esModule) => this.patchEsIdentify(ref esModule);
public int PatchNandPermissions(ref byte[] esModule) => this.patchNandPermissions(ref esModule);
public int PatchVP(ref byte[] esModule) => this.patchVP(ref esModule);
public int PatchAll(ref byte[] esModule) => this.patchAll(ref esModule);
private int patchFakeSigning(ref byte[] esModule)
{
this.fireDebug("Patching Fakesigning...");
int num = 0;
byte[] second1 = new byte[4]
{
(byte) 32,
(byte) 7,
(byte) 35,
(byte) 162
};
byte[] second2 = new byte[4]
{
(byte) 32,
(byte) 7,
(byte) 75,
(byte) 11
};
for (int firstIndex = 0; firstIndex < esModule.Length - 4; ++firstIndex)
{
this.fireProgress((firstIndex + 1) * 100 / esModule.Length);
if (Shared.CompareByteArrays(esModule, firstIndex, second1, 0, 4) || Shared.CompareByteArrays(esModule, firstIndex, second2, 0, 4))
#region Public Functions
/// <summary>
/// Loads an IOS wad to patch the es module.
/// </summary>
/// <param name="iosWad"></param>
public void LoadIOS(ref WAD iosWad)
{
this.fireDebug(" Patching at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex + 1] = (byte) 0;
firstIndex += 4;
++num;
this.wadFile = iosWad;
this.getEsIndex();
}
}
this.fireDebug("Patching Fakesigning Finished... (Patches applied: {0})", (object) num);
return num;
}
private int patchEsIdentify(ref byte[] esModule)
{
this.fireDebug("Patching ES_Identify...");
int num = 0;
byte[] second = new byte[4]
{
(byte) 40,
(byte) 3,
(byte) 209,
(byte) 35
};
for (int firstIndex = 0; firstIndex < esModule.Length - 4; ++firstIndex)
{
this.fireProgress((firstIndex + 1) * 100 / esModule.Length);
if (Shared.CompareByteArrays(esModule, firstIndex, second, 0, 4))
{
this.fireDebug(" Patching at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex + 2] = (byte) 0;
esModule[firstIndex + 3] = (byte) 0;
firstIndex += 4;
++num;
}
}
this.fireDebug("Patching ES_Identify Finished... (Patches applied: {0})", (object) num);
return num;
}
/// <summary>
/// Patches fakesigning.
/// Returns the number of applied patches.
/// </summary>
/// <returns></returns>
public int PatchFakeSigning() => this.esIndex < 0 ? -1 : this.patchFakeSigning(ref this.wadFile.Contents[this.esIndex]);
private int patchNandPermissions(ref byte[] esModule)
{
this.fireDebug("Patching NAND Permissions...");
int num = 0;
byte[] second = new byte[6]
{
(byte) 66,
(byte) 139,
(byte) 208,
(byte) 1,
(byte) 37,
(byte) 102
};
for (int firstIndex = 0; firstIndex < esModule.Length - 6; ++firstIndex)
{
this.fireProgress((firstIndex + 1) * 100 / esModule.Length);
if (Shared.CompareByteArrays(esModule, firstIndex, second, 0, 6))
{
this.fireDebug(" Patching at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex + 2] = (byte) 224;
firstIndex += 6;
++num;
}
}
this.fireDebug("Patching NAND Permissions Finished... (Patches applied: {0})", (object) num);
return num;
}
/// <summary>
/// Patches es_identify.
/// Returns the number of applied patches.
/// </summary>
/// <returns></returns>
public int PatchEsIdentify() => this.esIndex < 0 ? -1 : this.patchEsIdentify(ref this.wadFile.Contents[this.esIndex]);
private int patchVP(ref byte[] esModule)
{
this.fireDebug("Patching VP...");
int num = 0;
byte[] second = new byte[4]
{
(byte) 210,
(byte) 1,
(byte) 78,
(byte) 86
};
for (int firstIndex = 0; firstIndex < esModule.Length - 4; ++firstIndex)
{
this.fireProgress((firstIndex + 1) * 100 / esModule.Length);
if (Shared.CompareByteArrays(esModule, firstIndex, second, 0, 4))
{
this.fireDebug(" Patching for VP at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex] = (byte) 224;
firstIndex += 4;
++num;
}
}
this.fireDebug("Patching VP Finished... (Patches applied: {0})", (object) num);
return num;
}
/// <summary>
/// Patches nand permissions.
/// Returns the number of applied patches.
/// </summary>
/// <returns></returns>
public int PatchNandPermissions() => this.esIndex < 0 ? -1 : this.patchNandPermissions(ref this.wadFile.Contents[this.esIndex]);
private int patchAll(ref byte[] esModule)
{
this.fireDebug("Patching Fakesigning, ES_Identify, NAND Permissions and VP ...");
int num = 0;
byte[] second1 = new byte[4]
{
(byte) 32,
(byte) 7,
(byte) 35,
(byte) 162
};
byte[] second2 = new byte[4]
{
(byte) 32,
(byte) 7,
(byte) 75,
(byte) 11
};
byte[] second3 = new byte[4]
{
(byte) 40,
(byte) 3,
(byte) 209,
(byte) 35
};
byte[] second4 = new byte[6]
{
(byte) 66,
(byte) 139,
(byte) 208,
(byte) 1,
(byte) 37,
(byte) 102
};
byte[] second5 = new byte[4]
{
(byte) 210,
(byte) 1,
(byte) 78,
(byte) 86
};
for (int firstIndex = 0; firstIndex < esModule.Length - 6; ++firstIndex)
{
this.fireProgress((firstIndex + 1) * 100 / esModule.Length);
if (Shared.CompareByteArrays(esModule, firstIndex, second1, 0, 4) || Shared.CompareByteArrays(esModule, firstIndex, second2, 0, 4))
{
this.fireDebug(" Patching Fakesigning at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex + 1] = (byte) 0;
firstIndex += 4;
++num;
}
else if (Shared.CompareByteArrays(esModule, firstIndex, second3, 0, 4))
{
this.fireDebug(" Patching ES_Identify at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex + 2] = (byte) 0;
esModule[firstIndex + 3] = (byte) 0;
firstIndex += 4;
++num;
}
else if (Shared.CompareByteArrays(esModule, firstIndex, second4, 0, 6))
{
this.fireDebug(" Patching NAND Permissions at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex + 2] = (byte) 224;
firstIndex += 6;
++num;
}
else if (Shared.CompareByteArrays(esModule, firstIndex, second5, 0, 4))
{
this.fireDebug(" Patching VP at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex] = (byte) 224;
firstIndex += 4;
++num;
}
}
this.fireDebug("Patching Fakesigning, ES_Identify, NAND Permissions and VP Finished... (Patches applied: {0})", (object) num);
return num;
}
public int PatchVP() => this.esIndex < 0 ? -1 : this.patchVP(ref this.wadFile.Contents[this.esIndex]);
private void getEsIndex()
{
this.fireDebug("Scanning for ES Module...");
string str = "$IOSVersion:";
for (int index1 = this.wadFile.NumOfContents - 1; index1 >= 0; --index1)
{
this.fireDebug(" Scanning Content #{0} of {1}...", (object) (index1 + 1), (object) this.wadFile.NumOfContents);
this.fireProgress((index1 + 1) * 100 / this.wadFile.NumOfContents);
for (int index2 = 0; index2 < this.wadFile.Contents[index1].Length - 64; ++index2)
/// <summary>
/// Patches fakesigning, es_identify and nand permissions.
/// Returns the number of applied patches.
/// </summary>
/// <returns></returns>
public int PatchAll() => this.esIndex < 0 ? -1 : this.patchAll(ref this.wadFile.Contents[this.esIndex]);
public int PatchFakeSigning(ref byte[] esModule) => this.patchFakeSigning(ref esModule);
public int PatchEsIdentify(ref byte[] esModule) => this.patchEsIdentify(ref esModule);
public int PatchNandPermissions(ref byte[] esModule) => this.patchNandPermissions(ref esModule);
public int PatchVP(ref byte[] esModule) => this.patchVP(ref esModule);
public int PatchAll(ref byte[] esModule) => this.patchAll(ref esModule);
#endregion
#region Private Functions
private int patchFakeSigning(ref byte[] esModule)
{
if (Encoding.ASCII.GetString(this.wadFile.Contents[index1], index2, 12) == str)
{
int index3 = index2 + 12;
while (this.wadFile.Contents[index1][index3] == (byte) 32)
++index3;
if (Encoding.ASCII.GetString(this.wadFile.Contents[index1], index3, 3) == "ES:")
this.fireDebug("Patching Fakesigning...");
int num = 0;
byte[] second1 = new byte[4]
{
this.fireDebug(" -> ES Module found!");
this.fireDebug("Scanning for ES Module Finished...");
this.esIndex = index1;
this.fireProgress(100);
return;
(byte) 32,
(byte) 7,
(byte) 35,
(byte) 162
};
byte[] second2 = new byte[4]
{
(byte) 32,
(byte) 7,
(byte) 75,
(byte) 11
};
for (int firstIndex = 0; firstIndex < esModule.Length - 4; ++firstIndex)
{
this.fireProgress((firstIndex + 1) * 100 / esModule.Length);
if (Shared.CompareByteArrays(esModule, firstIndex, second1, 0, 4) || Shared.CompareByteArrays(esModule, firstIndex, second2, 0, 4))
{
this.fireDebug(" Patching at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex + 1] = (byte) 0;
firstIndex += 4;
++num;
}
}
}
this.fireDebug("Patching Fakesigning Finished... (Patches applied: {0})", (object) num);
return num;
}
}
this.fireDebug("/!\\/!\\/!\\ ES Module wasn't found! /!\\/!\\/!\\");
throw new Exception("ES module wasn't found!");
}
private void fireDebug(string debugMessage, params object[] args)
{
EventHandler<MessageEventArgs> debug = this.Debug;
if (debug == null)
return;
debug(new object(), new MessageEventArgs(string.Format(debugMessage, args)));
}
private int patchEsIdentify(ref byte[] esModule)
{
this.fireDebug("Patching ES_Identify...");
int num = 0;
byte[] second = new byte[4]
{
(byte) 40,
(byte) 3,
(byte) 209,
(byte) 35
};
for (int firstIndex = 0; firstIndex < esModule.Length - 4; ++firstIndex)
{
this.fireProgress((firstIndex + 1) * 100 / esModule.Length);
if (Shared.CompareByteArrays(esModule, firstIndex, second, 0, 4))
{
this.fireDebug(" Patching at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex + 2] = (byte) 0;
esModule[firstIndex + 3] = (byte) 0;
firstIndex += 4;
++num;
}
}
this.fireDebug("Patching ES_Identify Finished... (Patches applied: {0})", (object) num);
return num;
}
private void fireProgress(int progressPercentage)
{
EventHandler<ProgressChangedEventArgs> progress = this.Progress;
if (progress == null)
return;
progress(new object(), new ProgressChangedEventArgs(progressPercentage, (object) string.Empty));
private int patchNandPermissions(ref byte[] esModule)
{
this.fireDebug("Patching NAND Permissions...");
int num = 0;
byte[] second = new byte[6]
{
(byte) 66,
(byte) 139,
(byte) 208,
(byte) 1,
(byte) 37,
(byte) 102
};
for (int firstIndex = 0; firstIndex < esModule.Length - 6; ++firstIndex)
{
this.fireProgress((firstIndex + 1) * 100 / esModule.Length);
if (Shared.CompareByteArrays(esModule, firstIndex, second, 0, 6))
{
this.fireDebug(" Patching at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex + 2] = (byte) 224;
firstIndex += 6;
++num;
}
}
this.fireDebug("Patching NAND Permissions Finished... (Patches applied: {0})", (object) num);
return num;
}
private int patchVP(ref byte[] esModule)
{
this.fireDebug("Patching VP...");
int num = 0;
byte[] second = new byte[4]
{
(byte) 210,
(byte) 1,
(byte) 78,
(byte) 86
};
for (int firstIndex = 0; firstIndex < esModule.Length - 4; ++firstIndex)
{
this.fireProgress((firstIndex + 1) * 100 / esModule.Length);
if (Shared.CompareByteArrays(esModule, firstIndex, second, 0, 4))
{
this.fireDebug(" Patching for VP at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex] = (byte) 224;
firstIndex += 4;
++num;
}
}
this.fireDebug("Patching VP Finished... (Patches applied: {0})", (object) num);
return num;
}
private int patchAll(ref byte[] esModule)
{
this.fireDebug("Patching Fakesigning, ES_Identify, NAND Permissions and VP ...");
int num = 0;
byte[] second1 = new byte[4]
{
(byte) 32,
(byte) 7,
(byte) 35,
(byte) 162
};
byte[] second2 = new byte[4]
{
(byte) 32,
(byte) 7,
(byte) 75,
(byte) 11
};
byte[] second3 = new byte[4]
{
(byte) 40,
(byte) 3,
(byte) 209,
(byte) 35
};
byte[] second4 = new byte[6]
{
(byte) 66,
(byte) 139,
(byte) 208,
(byte) 1,
(byte) 37,
(byte) 102
};
byte[] second5 = new byte[4]
{
(byte) 210,
(byte) 1,
(byte) 78,
(byte) 86
};
for (int firstIndex = 0; firstIndex < esModule.Length - 6; ++firstIndex)
{
this.fireProgress((firstIndex + 1) * 100 / esModule.Length);
if (Shared.CompareByteArrays(esModule, firstIndex, second1, 0, 4) || Shared.CompareByteArrays(esModule, firstIndex, second2, 0, 4))
{
this.fireDebug(" Patching Fakesigning at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex + 1] = (byte) 0;
firstIndex += 4;
++num;
}
else if (Shared.CompareByteArrays(esModule, firstIndex, second3, 0, 4))
{
this.fireDebug(" Patching ES_Identify at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex + 2] = (byte) 0;
esModule[firstIndex + 3] = (byte) 0;
firstIndex += 4;
++num;
}
else if (Shared.CompareByteArrays(esModule, firstIndex, second4, 0, 6))
{
this.fireDebug(" Patching NAND Permissions at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex + 2] = (byte) 224;
firstIndex += 6;
++num;
}
else if (Shared.CompareByteArrays(esModule, firstIndex, second5, 0, 4))
{
this.fireDebug(" Patching VP at Offset: 0x{0}", (object) firstIndex.ToString("x8").ToUpper());
esModule[firstIndex] = (byte) 224;
firstIndex += 4;
++num;
}
}
this.fireDebug("Patching Fakesigning, ES_Identify, NAND Permissions and VP Finished... (Patches applied: {0})", (object) num);
return num;
}
private void getEsIndex()
{
this.fireDebug("Scanning for ES Module...");
string str = "$IOSVersion:";
for (int index1 = this.wadFile.NumOfContents - 1; index1 >= 0; --index1)
{
this.fireDebug(" Scanning Content #{0} of {1}...", (object) (index1 + 1), (object) this.wadFile.NumOfContents);
this.fireProgress((index1 + 1) * 100 / this.wadFile.NumOfContents);
for (int index2 = 0; index2 < this.wadFile.Contents[index1].Length - 64; ++index2)
{
if (Encoding.ASCII.GetString(this.wadFile.Contents[index1], index2, 12) == str)
{
int index3 = index2 + 12;
while (this.wadFile.Contents[index1][index3] == (byte) 32)
++index3;
if (Encoding.ASCII.GetString(this.wadFile.Contents[index1], index3, 3) == "ES:")
{
this.fireDebug(" -> ES Module found!");
this.fireDebug("Scanning for ES Module Finished...");
this.esIndex = index1;
this.fireProgress(100);
return;
}
}
}
}
this.fireDebug("/!\\/!\\/!\\ ES Module wasn't found! /!\\/!\\/!\\");
throw new Exception("ES module wasn't found!");
}
#endregion
#region Events
/// <summary>
/// Fires the Progress of various operations
/// </summary>
public event EventHandler<ProgressChangedEventArgs> Progress;
/// <summary>
/// Fires debugging messages. You may write them into a log file or log textbox.
/// </summary>
public event EventHandler<MessageEventArgs> Debug;
private void fireDebug(string debugMessage, params object[] args)
{
EventHandler<MessageEventArgs> debug = this.Debug;
if (debug == null)
return;
debug(new object(), new MessageEventArgs(string.Format(debugMessage, args)));
}
private void fireProgress(int progressPercentage)
{
EventHandler<ProgressChangedEventArgs> progress = this.Progress;
if (progress == null)
return;
progress(new object(), new ProgressChangedEventArgs(progressPercentage, (object) string.Empty));
}
#endregion
}
}
}

View file

@ -1,18 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: libWiiSharp.LowerTitleID
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll
namespace libWiiSharp
{
public enum LowerTitleID : uint
{
SystemTitles = 1,
Channel = 65537, // 0x00010001
SystemChannels = 65538, // 0x00010002
GameChannel = 65540, // 0x00010004
DLC = 65541, // 0x00010005
HiddenChannels = 65544, // 0x00010008
}
}

View file

@ -1,15 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: libWiiSharp.Protocol
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll
namespace libWiiSharp
{
public enum Protocol
{
HAXX,
JODI,
Custom,
}
}

8
TMD.cs
View file

@ -11,7 +11,13 @@ using System.Security.Cryptography;
namespace libWiiSharp
{
public class TMD : IDisposable
public enum ContentType : ushort
{
Normal = 1,
DLC = 16385, // 0x4001
Shared = 32769, // 0x8001
}
public class TMD : IDisposable
{
private bool fakeSign;
private bool sortContents;

View file

@ -10,8 +10,15 @@ using System.Security.Cryptography;
namespace libWiiSharp
{
public class Ticket : IDisposable
{
public enum CommonKeyType : byte
{
Standard = 0x00,
Korean = 0x01,
}
public class Ticket : IDisposable
{
private byte newKeyIndex;
private byte[] decryptedTitleKey = new byte[16];
private bool fakeSign;

45
WAD.cs
View file

@ -13,7 +13,16 @@ using System.Text;
namespace libWiiSharp
{
public class WAD : IDisposable
public enum LowerTitleID : uint
{
SystemTitles = 0x00000001,
SystemChannels = 0x00010002,
Channel = 0x00010001,
GameChannel = 0x00010004,
DLC = 0x00010005,
HiddenChannels = 0x00010008,
}
public class WAD : IDisposable
{
private SHA1 sha = SHA1.Create();
private DateTime creationTimeUTC = new DateTime(1970, 1, 1);
@ -999,4 +1008,38 @@ namespace libWiiSharp
private void bannerApp_Warning(object sender, MessageEventArgs e) => this.fireWarning(e.Message);
}
public class WAD_Header
{
private uint headerSize = 0x20;
private uint wadType = 0x49730000;
private uint certSize = 0xA00;
private uint reserved = 0x00;
private uint tikSize = 0x2A4;
private uint tmdSize;
private uint contentSize;
private uint footerSize = 0x00;
public uint HeaderSize { get { return headerSize; } }
public uint WadType { get { return wadType; } set { wadType = value; } }
public uint CertSize { get { return certSize; } }
public uint Reserved { get { return reserved; } }
public uint TicketSize { get { return tikSize; } }
public uint TmdSize { get { return tmdSize; } set { tmdSize = value; } }
public uint ContentSize { get { return contentSize; } set { contentSize = value; } }
public uint FooterSize { get { return footerSize; } set { footerSize = value; } }
public void Write(Stream writeStream)
{
writeStream.Seek(0, SeekOrigin.Begin);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(headerSize)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(wadType)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(certSize)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(reserved)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(tikSize)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(tmdSize)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(contentSize)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(footerSize)), 0, 4);
}
}
}

View file

@ -1,68 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: libWiiSharp.WAD_Header
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll
using System;
using System.IO;
namespace libWiiSharp
{
public class WAD_Header
{
private uint headerSize = 32;
private uint wadType = 1232273408;
private uint certSize = 2560;
private uint reserved;
private uint tikSize = 676;
private uint tmdSize;
private uint contentSize;
private uint footerSize;
public uint HeaderSize => this.headerSize;
public uint WadType
{
get => this.wadType;
set => this.wadType = value;
}
public uint CertSize => this.certSize;
public uint Reserved => this.reserved;
public uint TicketSize => this.tikSize;
public uint TmdSize
{
get => this.tmdSize;
set => this.tmdSize = value;
}
public uint ContentSize
{
get => this.contentSize;
set => this.contentSize = value;
}
public uint FooterSize
{
get => this.footerSize;
set => this.footerSize = value;
}
public void Write(Stream writeStream)
{
writeStream.Seek(0L, SeekOrigin.Begin);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(this.headerSize)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(this.wadType)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(this.certSize)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(this.reserved)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(this.tikSize)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(this.tmdSize)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(this.contentSize)), 0, 4);
writeStream.Write(BitConverter.GetBytes(Shared.Swap(this.footerSize)), 0, 4);
}
}
}

View file

@ -55,18 +55,14 @@
<Compile Include="CertificateChain.cs" />
<Compile Include="ColorIndexConverter.cs" />
<Compile Include="CommonKey.cs" />
<Compile Include="CommonKeyType.cs" />
<Compile Include="ContentIndices.cs" />
<Compile Include="ContentType.cs" />
<Compile Include="HbcTransmitter.cs" />
<Compile Include="Headers.cs" />
<Compile Include="HexView.cs" />
<Compile Include="IosPatcher.cs" />
<Compile Include="LowerTitleID.cs" />
<Compile Include="Lz77.cs" />
<Compile Include="MessageEventArgs.cs" />
<Compile Include="NusClient.cs" />
<Compile Include="Protocol.cs" />
<Compile Include="Region.cs" />
<Compile Include="Shared.cs" />
<Compile Include="StoreType.cs" />
@ -85,14 +81,12 @@
<Compile Include="U8_Node.cs" />
<Compile Include="U8_NodeType.cs" />
<Compile Include="WAD.cs" />
<Compile Include="WAD_Header.cs" />
<Compile Include="Wave.cs" />
<Compile Include="WaveDataChunk.cs" />
<Compile Include="WaveFmtChunk.cs" />
<Compile Include="WaveHeader.cs" />
<Compile Include="WaveSmplChunk.cs" />
<Compile Include="WaveSmplLoop.cs" />
<Compile Include="zlibWrapper.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

6
libWiiSharp.csproj.user Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>

View file

@ -1,46 +0,0 @@
// Decompiled with JetBrains decompiler
// Type: libWiiSharp.zlibWrapper
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll
using System;
using System.Runtime.InteropServices;
namespace libWiiSharp
{
internal class zlibWrapper
{
[DllImport("zlib1.dll")]
private static extern zlibWrapper.ZLibError compress2(
byte[] dest,
ref int destLength,
byte[] source,
int sourceLength,
int level);
public static byte[] Compress(byte[] inFile)
{
byte[] array = new byte[inFile.Length + 64];
int destLength = -1;
zlibWrapper.ZLibError zlibError = zlibWrapper.compress2(array, ref destLength, inFile, inFile.Length, 6);
if (zlibError != zlibWrapper.ZLibError.Z_OK || destLength <= -1 || destLength >= inFile.Length)
throw new Exception("An error occured while compressing! Code: " + zlibError.ToString());
Array.Resize<byte>(ref array, destLength);
return array;
}
public enum ZLibError
{
Z_VERSION_ERROR = -6, // 0xFFFFFFFA
Z_BUF_ERROR = -5, // 0xFFFFFFFB
Z_MEM_ERROR = -4, // 0xFFFFFFFC
Z_DATA_ERROR = -3, // 0xFFFFFFFD
Z_STREAM_ERROR = -2, // 0xFFFFFFFE
Z_ERRNO = -1, // 0xFFFFFFFF
Z_OK = 0,
Z_STREAM_END = 1,
Z_NEED_DICT = 2,
}
}
}