mirror of
https://github.com/TheShadowEevee/libWiiSharp.git
synced 2025-01-11 15:38:51 -06:00
Begin Commenting and organizing again, automatic call simplifications
This commit is contained in:
parent
169d251817
commit
25a7878313
17 changed files with 223 additions and 103 deletions
2
BNS.cs
2
BNS.cs
|
@ -731,6 +731,7 @@ namespace libWiiSharp
|
|||
}
|
||||
internal class BNS_Header
|
||||
{
|
||||
//Private Variables
|
||||
private readonly byte[] magic = new byte[4]
|
||||
{
|
||||
66,
|
||||
|
@ -747,6 +748,7 @@ namespace libWiiSharp
|
|||
private uint dataOffset = 192;
|
||||
private uint dataLength = 315392;
|
||||
|
||||
//Public Variables
|
||||
public uint DataOffset
|
||||
{
|
||||
get => dataOffset;
|
||||
|
|
28
Brlan.cs
28
Brlan.cs
|
@ -24,16 +24,33 @@ namespace libWiiSharp
|
|||
{
|
||||
public class Brlan
|
||||
{
|
||||
#region Public Functions
|
||||
/// <summary>
|
||||
/// Gets all TPLs that are required by the brlan (Frame Animation).
|
||||
/// </summary>
|
||||
/// <param name="pathTobrlan"></param>
|
||||
/// <returns></returns>
|
||||
public static string[] GetBrlanTpls(string pathTobrlan)
|
||||
{
|
||||
return Brlan.PrivGetBrlanTpls(File.ReadAllBytes(pathTobrlan));
|
||||
return PrivGetBrlanTpls(File.ReadAllBytes(pathTobrlan));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all TPLs that are required by the brlan (Frame Animation).
|
||||
/// </summary>
|
||||
/// <param name="brlanFile"></param>
|
||||
/// <returns></returns>
|
||||
public static string[] GetBrlanTpls(byte[] brlanFile)
|
||||
{
|
||||
return Brlan.PrivGetBrlanTpls(brlanFile);
|
||||
return PrivGetBrlanTpls(brlanFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all TPLs that are required by the brlan (Frame Animation).
|
||||
/// </summary>
|
||||
/// <param name="wad"></param>
|
||||
/// <param name="banner"></param>
|
||||
/// <returns></returns>
|
||||
public static string[] GetBrlanTpls(WAD wad, bool banner)
|
||||
{
|
||||
if (!wad.HasBanner)
|
||||
|
@ -57,7 +74,7 @@ namespace libWiiSharp
|
|||
{
|
||||
if (u8.StringTable[index2].ToLower() == str + "_start.brlan" || u8.StringTable[index2].ToLower() == str + "_loop.brlan" || u8.StringTable[index2].ToLower() == str + ".brlan")
|
||||
{
|
||||
a = Shared.MergeStringArrays(a, Brlan.GetBrlanTpls(u8.Data[index2]));
|
||||
a = Shared.MergeStringArrays(a, GetBrlanTpls(u8.Data[index2]));
|
||||
}
|
||||
}
|
||||
return a;
|
||||
|
@ -65,11 +82,13 @@ namespace libWiiSharp
|
|||
}
|
||||
return new string[0];
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Functions
|
||||
private static string[] PrivGetBrlanTpls(byte[] brlanFile)
|
||||
{
|
||||
List<string> stringList = new List<string>();
|
||||
int numOfTpls = Brlan.GetNumOfTpls(brlanFile);
|
||||
int numOfTpls = GetNumOfTpls(brlanFile);
|
||||
int index1 = 36 + numOfTpls * 4;
|
||||
for (int index2 = 0; index2 < numOfTpls; ++index2)
|
||||
{
|
||||
|
@ -96,5 +115,6 @@ namespace libWiiSharp
|
|||
{
|
||||
return Shared.Swap(BitConverter.ToUInt16(brlanFile, 28));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
24
Brlyt.cs
24
Brlyt.cs
|
@ -24,16 +24,33 @@ namespace libWiiSharp
|
|||
{
|
||||
public class Brlyt
|
||||
{
|
||||
#region Public Functions
|
||||
/// <summary>
|
||||
/// Gets all TPLs that are required by the brlyt.
|
||||
/// </summary>
|
||||
/// <param name="pathToBrlyt"></param>
|
||||
/// <returns></returns>
|
||||
public static string[] GetBrlytTpls(string pathToBrlyt)
|
||||
{
|
||||
return PrivGetBrlytTpls(File.ReadAllBytes(pathToBrlyt));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all TPLs that are required by the brlyt.
|
||||
/// </summary>
|
||||
/// <param name="brlytFile"></param>
|
||||
/// <returns></returns>
|
||||
public static string[] GetBrlytTpls(byte[] brlytFile)
|
||||
{
|
||||
return PrivGetBrlytTpls(brlytFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all TPLs that are required by the brlyt.
|
||||
/// </summary>
|
||||
/// <param name="wad"></param>
|
||||
/// <param name="banner"></param>
|
||||
/// <returns></returns>
|
||||
public static string[] GetBrlytTpls(WAD wad, bool banner)
|
||||
{
|
||||
if (!wad.HasBanner)
|
||||
|
@ -57,7 +74,7 @@ namespace libWiiSharp
|
|||
{
|
||||
if (u8.StringTable[index2].ToLower() == str + ".brlyt")
|
||||
{
|
||||
a = Shared.MergeStringArrays(a, Brlyt.GetBrlytTpls(u8.Data[index2]));
|
||||
a = Shared.MergeStringArrays(a, GetBrlytTpls(u8.Data[index2]));
|
||||
}
|
||||
}
|
||||
return a;
|
||||
|
@ -65,11 +82,13 @@ namespace libWiiSharp
|
|||
}
|
||||
return new string[0];
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Functions
|
||||
private static string[] PrivGetBrlytTpls(byte[] brlytFile)
|
||||
{
|
||||
List<string> stringList = new List<string>();
|
||||
int numOfTpls = Brlyt.GetNumOfTpls(brlytFile);
|
||||
int numOfTpls = GetNumOfTpls(brlytFile);
|
||||
int index1 = 48 + numOfTpls * 8;
|
||||
for (int index2 = 0; index2 < numOfTpls; ++index2)
|
||||
{
|
||||
|
@ -96,5 +115,6 @@ namespace libWiiSharp
|
|||
{
|
||||
return Shared.Swap(BitConverter.ToUInt16(brlytFile, 44));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,10 +34,12 @@ namespace libWiiSharp
|
|||
private byte[] certXs = new byte[768];
|
||||
private bool isDisposed;
|
||||
|
||||
/// <summary>
|
||||
/// If false, the Certificate Chain is not complete (i.e. at least one certificate is missing).
|
||||
/// </summary>
|
||||
public bool CertsComplete => certsComplete[0] && certsComplete[1] && certsComplete[2];
|
||||
|
||||
public event EventHandler<MessageEventArgs> Debug;
|
||||
|
||||
#region IDisposable Members
|
||||
~CertificateChain() => Dispose(false);
|
||||
|
||||
public void Dispose()
|
||||
|
@ -59,12 +61,24 @@ namespace libWiiSharp
|
|||
}
|
||||
isDisposed = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Functions
|
||||
/// <summary>
|
||||
/// Loads a cert file.
|
||||
/// </summary>
|
||||
/// <param name="pathToCert"></param>
|
||||
/// <returns></returns>
|
||||
public static CertificateChain Load(string pathToCert)
|
||||
{
|
||||
return CertificateChain.Load(File.ReadAllBytes(pathToCert));
|
||||
return Load(File.ReadAllBytes(pathToCert));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a cert file.
|
||||
/// </summary>
|
||||
/// <param name="certFile"></param>
|
||||
/// <returns></returns>
|
||||
public static CertificateChain Load(byte[] certFile)
|
||||
{
|
||||
CertificateChain certificateChain = new CertificateChain();
|
||||
|
@ -82,6 +96,11 @@ namespace libWiiSharp
|
|||
return certificateChain;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a cert file.
|
||||
/// </summary>
|
||||
/// <param name="cert"></param>
|
||||
/// <returns></returns>
|
||||
public static CertificateChain Load(Stream cert)
|
||||
{
|
||||
CertificateChain certificateChain = new CertificateChain();
|
||||
|
@ -89,11 +108,25 @@ namespace libWiiSharp
|
|||
return certificateChain;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs certificates from Ticket and Tmd.
|
||||
/// Ticket and Tmd must contain certs! (They do when they're downloaded from NUS!)
|
||||
/// </summary>
|
||||
/// <param name="pathToTik"></param>
|
||||
/// <param name="pathToTmd"></param>
|
||||
/// <returns></returns>
|
||||
public static CertificateChain FromTikTmd(string pathToTik, string pathToTmd)
|
||||
{
|
||||
return CertificateChain.FromTikTmd(File.ReadAllBytes(pathToTik), File.ReadAllBytes(pathToTmd));
|
||||
return FromTikTmd(File.ReadAllBytes(pathToTik), File.ReadAllBytes(pathToTmd));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs certificates from Ticket and Tmd.
|
||||
/// Ticket and Tmd must contain certs! (They do when they're downloaded from NUS!)
|
||||
/// </summary>
|
||||
/// <param name="tikFile"></param>
|
||||
/// <param name="tmdFile"></param>
|
||||
/// <returns></returns>
|
||||
public static CertificateChain FromTikTmd(byte[] tikFile, byte[] tmdFile)
|
||||
{
|
||||
CertificateChain certificateChain = new CertificateChain();
|
||||
|
@ -121,6 +154,13 @@ namespace libWiiSharp
|
|||
return certificateChain.CertsComplete ? certificateChain : throw new Exception("Couldn't locate all certs!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs certificates from Ticket and Tmd.
|
||||
/// Ticket and Tmd must contain certs! (They do when they're downloaded from NUS!)
|
||||
/// </summary>
|
||||
/// <param name="tik"></param>
|
||||
/// <param name="tmd"></param>
|
||||
/// <returns></returns>
|
||||
public static CertificateChain FromTikTmd(Stream tik, Stream tmd)
|
||||
{
|
||||
CertificateChain certificateChain = new CertificateChain();
|
||||
|
@ -129,11 +169,19 @@ namespace libWiiSharp
|
|||
return certificateChain;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a cert file.
|
||||
/// </summary>
|
||||
/// <param name="pathToCert"></param>
|
||||
public void LoadFile(string pathToCert)
|
||||
{
|
||||
LoadFile(File.ReadAllBytes(pathToCert));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a cert file.
|
||||
/// </summary>
|
||||
/// <param name="certFile"></param>
|
||||
public void LoadFile(byte[] certFile)
|
||||
{
|
||||
MemoryStream memoryStream = new MemoryStream(certFile);
|
||||
|
@ -149,16 +197,33 @@ namespace libWiiSharp
|
|||
memoryStream.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a cert file.
|
||||
/// </summary>
|
||||
/// <param name="cert"></param>
|
||||
public void LoadFile(Stream cert)
|
||||
{
|
||||
ParseCert(cert);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs certificates from Ticket and Tmd.
|
||||
/// Ticket and Tmd must contain certs! (They do when they're downloaded from NUS!)
|
||||
/// </summary>
|
||||
/// <param name="pathToTik"></param>
|
||||
/// <param name="pathToTmd"></param>
|
||||
/// <returns></returns>
|
||||
public void LoadFromTikTmd(string pathToTik, string pathToTmd)
|
||||
{
|
||||
LoadFromTikTmd(File.ReadAllBytes(pathToTik), File.ReadAllBytes(pathToTmd));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs certificates from Ticket and Tmd.
|
||||
/// Ticket and Tmd must contain certs! (They do when they're downloaded from NUS!)
|
||||
/// </summary>
|
||||
/// <param name="tikFile"></param>
|
||||
/// <param name="tmdFile"></param>
|
||||
public void LoadFromTikTmd(byte[] tikFile, byte[] tmdFile)
|
||||
{
|
||||
MemoryStream memoryStream1 = new MemoryStream(tikFile);
|
||||
|
@ -188,12 +253,22 @@ namespace libWiiSharp
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs certificates from Ticket and Tmd.
|
||||
/// Ticket and Tmd must contain certs! (They do when they're downloaded from NUS!)
|
||||
/// </summary>
|
||||
/// <param name="tik"></param>
|
||||
/// <param name="tmd"></param>
|
||||
public void LoadFromTikTmd(Stream tik, Stream tmd)
|
||||
{
|
||||
GrabFromTik(tik);
|
||||
GrabFromTmd(tmd);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the Certificate Chain.
|
||||
/// </summary>
|
||||
/// <param name="savePath"></param>
|
||||
public void Save(string savePath)
|
||||
{
|
||||
if (File.Exists(savePath))
|
||||
|
@ -205,6 +280,10 @@ namespace libWiiSharp
|
|||
WriteToStream(fileStream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Certificate Chain as a memory stream.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public MemoryStream ToMemoryStream()
|
||||
{
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
|
@ -220,6 +299,10 @@ namespace libWiiSharp
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Certificate Chain as a byte array.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public byte[] ToByteArray()
|
||||
{
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
|
@ -236,7 +319,9 @@ namespace libWiiSharp
|
|||
memoryStream.Dispose();
|
||||
return array;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Functions
|
||||
private void WriteToStream(Stream writeStream)
|
||||
{
|
||||
FireDebug("Writing Certificate Chain...");
|
||||
|
@ -476,6 +561,13 @@ namespace libWiiSharp
|
|||
|
||||
return part[388] == 67 && part[389] == 80 && Shared.CompareByteArrays(sha.ComputeHash(part), Shared.HexStringToByteArray("6824D6DA4C25184F0D6DAF6EDB9C0FC57522A41C"));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
/// <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)
|
||||
{
|
||||
|
@ -487,5 +579,6 @@ namespace libWiiSharp
|
|||
|
||||
debug(new object(), new MessageEventArgs(string.Format(debugMessage, args)));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,12 @@ namespace libWiiSharp
|
|||
|
||||
public static byte[] GetStandardKey()
|
||||
{
|
||||
return Shared.HexStringToByteArray(CommonKey.standardKey);
|
||||
return Shared.HexStringToByteArray(standardKey);
|
||||
}
|
||||
|
||||
public static byte[] GetKoreanKey()
|
||||
{
|
||||
return Shared.HexStringToByteArray(CommonKey.koreanKey);
|
||||
return Shared.HexStringToByteArray(koreanKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: libWiiSharp.ContentType
|
||||
// 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 ContentType : ushort
|
||||
{
|
||||
Normal = 1,
|
||||
DLC = 16385, // 0x4001
|
||||
Shared = 32769, // 0x8001
|
||||
}
|
||||
}
|
|
@ -417,8 +417,8 @@ namespace libWiiSharp
|
|||
{
|
||||
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)
|
||||
ZlibWrapper.ZLibError zlibError = Compress2(array, ref destLength, inFile, inFile.Length, 6);
|
||||
if (zlibError != ZLibError.Z_OK || destLength <= -1 || destLength >= inFile.Length)
|
||||
{
|
||||
throw new Exception("An error occured while compressing! Code: " + zlibError.ToString());
|
||||
}
|
||||
|
|
64
Headers.cs
64
Headers.cs
|
@ -55,7 +55,7 @@ namespace libWiiSharp
|
|||
/// <returns></returns>
|
||||
public static Headers.HeaderType DetectHeader(string pathToFile)
|
||||
{
|
||||
return Headers.DetectHeader(File.ReadAllBytes(pathToFile));
|
||||
return DetectHeader(File.ReadAllBytes(pathToFile));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -65,17 +65,17 @@ namespace libWiiSharp
|
|||
/// <returns></returns>
|
||||
public static Headers.HeaderType DetectHeader(byte[] file)
|
||||
{
|
||||
if (file.Length > 68 && (int)Shared.Swap(BitConverter.ToUInt32(file, 64)) == (int)Headers.imetMagic)
|
||||
if (file.Length > 68 && (int)Shared.Swap(BitConverter.ToUInt32(file, 64)) == (int)imetMagic)
|
||||
{
|
||||
return Headers.HeaderType.ShortIMET;
|
||||
return HeaderType.ShortIMET;
|
||||
}
|
||||
|
||||
if (file.Length > 132 && (int)Shared.Swap(BitConverter.ToUInt32(file, 128)) == (int)Headers.imetMagic)
|
||||
if (file.Length > 132 && (int)Shared.Swap(BitConverter.ToUInt32(file, 128)) == (int)imetMagic)
|
||||
{
|
||||
return Headers.HeaderType.IMET;
|
||||
return HeaderType.IMET;
|
||||
}
|
||||
|
||||
return file.Length > 4 && (int)Shared.Swap(BitConverter.ToUInt32(file, 0)) == (int)Headers.imd5Magic ? Headers.HeaderType.IMD5 : Headers.HeaderType.None;
|
||||
return file.Length > 4 && (int)Shared.Swap(BitConverter.ToUInt32(file, 0)) == (int)imd5Magic ? HeaderType.IMD5 : HeaderType.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -90,30 +90,30 @@ namespace libWiiSharp
|
|||
{
|
||||
file.Seek(64L, SeekOrigin.Begin);
|
||||
file.Read(buffer, 0, buffer.Length);
|
||||
if ((int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)Headers.imetMagic)
|
||||
if ((int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)imetMagic)
|
||||
{
|
||||
return Headers.HeaderType.ShortIMET;
|
||||
return HeaderType.ShortIMET;
|
||||
}
|
||||
}
|
||||
if (file.Length > 132L)
|
||||
{
|
||||
file.Seek(128L, SeekOrigin.Begin);
|
||||
file.Read(buffer, 0, buffer.Length);
|
||||
if ((int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)Headers.imetMagic)
|
||||
if ((int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)imetMagic)
|
||||
{
|
||||
return Headers.HeaderType.IMET;
|
||||
return HeaderType.IMET;
|
||||
}
|
||||
}
|
||||
if (file.Length > 4L)
|
||||
{
|
||||
file.Seek(0L, SeekOrigin.Begin);
|
||||
file.Read(buffer, 0, buffer.Length);
|
||||
if ((int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)Headers.imd5Magic)
|
||||
if ((int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)imd5Magic)
|
||||
{
|
||||
return Headers.HeaderType.IMD5;
|
||||
return HeaderType.IMD5;
|
||||
}
|
||||
}
|
||||
return Headers.HeaderType.None;
|
||||
return HeaderType.None;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -279,7 +279,7 @@ namespace libWiiSharp
|
|||
/// <returns></returns>
|
||||
public static Headers.IMET Load(string pathToFile)
|
||||
{
|
||||
return Headers.IMET.Load(File.ReadAllBytes(pathToFile));
|
||||
return Load(File.ReadAllBytes(pathToFile));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -289,13 +289,13 @@ namespace libWiiSharp
|
|||
/// <returns></returns>
|
||||
public static Headers.IMET Load(byte[] fileOrHeader)
|
||||
{
|
||||
Headers.HeaderType headerType = Headers.DetectHeader(fileOrHeader);
|
||||
Headers.HeaderType headerType = DetectHeader(fileOrHeader);
|
||||
switch (headerType)
|
||||
{
|
||||
case Headers.HeaderType.ShortIMET:
|
||||
case Headers.HeaderType.IMET:
|
||||
case HeaderType.ShortIMET:
|
||||
case HeaderType.IMET:
|
||||
Headers.IMET imet = new Headers.IMET();
|
||||
if (headerType == Headers.HeaderType.ShortIMET)
|
||||
if (headerType == HeaderType.ShortIMET)
|
||||
{
|
||||
imet.isShortImet = true;
|
||||
}
|
||||
|
@ -324,13 +324,13 @@ namespace libWiiSharp
|
|||
/// <returns></returns>
|
||||
public static Headers.IMET Load(Stream fileOrHeader)
|
||||
{
|
||||
Headers.HeaderType headerType = Headers.DetectHeader(fileOrHeader);
|
||||
Headers.HeaderType headerType = DetectHeader(fileOrHeader);
|
||||
switch (headerType)
|
||||
{
|
||||
case Headers.HeaderType.ShortIMET:
|
||||
case Headers.HeaderType.IMET:
|
||||
case HeaderType.ShortIMET:
|
||||
case HeaderType.IMET:
|
||||
Headers.IMET imet = new Headers.IMET();
|
||||
if (headerType == Headers.HeaderType.ShortIMET)
|
||||
if (headerType == HeaderType.ShortIMET)
|
||||
{
|
||||
imet.isShortImet = true;
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ namespace libWiiSharp
|
|||
/// <param name="pathToFile"></param>
|
||||
public static void RemoveHeader(string pathToFile)
|
||||
{
|
||||
byte[] bytes = Headers.IMET.RemoveHeader(File.ReadAllBytes(pathToFile));
|
||||
byte[] bytes = RemoveHeader(File.ReadAllBytes(pathToFile));
|
||||
File.Delete(pathToFile);
|
||||
File.WriteAllBytes(pathToFile, bytes);
|
||||
}
|
||||
|
@ -396,11 +396,11 @@ namespace libWiiSharp
|
|||
/// <returns></returns>
|
||||
public static byte[] RemoveHeader(byte[] file)
|
||||
{
|
||||
Headers.HeaderType headerType = Headers.DetectHeader(file);
|
||||
Headers.HeaderType headerType = DetectHeader(file);
|
||||
switch (headerType)
|
||||
{
|
||||
case Headers.HeaderType.ShortIMET:
|
||||
case Headers.HeaderType.IMET:
|
||||
case HeaderType.ShortIMET:
|
||||
case HeaderType.IMET:
|
||||
byte[] numArray = new byte[(int)(file.Length - headerType)];
|
||||
Array.Copy(file, (int)headerType, numArray, 0, numArray.Length);
|
||||
return numArray;
|
||||
|
@ -683,7 +683,7 @@ namespace libWiiSharp
|
|||
/// <returns></returns>
|
||||
public static Headers.IMD5 Load(string pathToFile)
|
||||
{
|
||||
return Headers.IMD5.Load(File.ReadAllBytes(pathToFile));
|
||||
return Load(File.ReadAllBytes(pathToFile));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -693,7 +693,7 @@ namespace libWiiSharp
|
|||
/// <returns></returns>
|
||||
public static Headers.IMD5 Load(byte[] fileOrHeader)
|
||||
{
|
||||
if (Headers.DetectHeader(fileOrHeader) != Headers.HeaderType.IMD5)
|
||||
if (DetectHeader(fileOrHeader) != HeaderType.IMD5)
|
||||
{
|
||||
throw new Exception("No IMD5 Header found!");
|
||||
}
|
||||
|
@ -720,7 +720,7 @@ namespace libWiiSharp
|
|||
/// <returns></returns>
|
||||
public static Headers.IMD5 Load(Stream fileOrHeader)
|
||||
{
|
||||
if (Headers.DetectHeader(fileOrHeader) != Headers.HeaderType.IMD5)
|
||||
if (DetectHeader(fileOrHeader) != HeaderType.IMD5)
|
||||
{
|
||||
throw new Exception("No IMD5 Header found!");
|
||||
}
|
||||
|
@ -751,7 +751,7 @@ namespace libWiiSharp
|
|||
/// <param name="pathToFile"></param>
|
||||
public static void AddHeader(string pathToFile)
|
||||
{
|
||||
byte[] buffer = Headers.IMD5.AddHeader(File.ReadAllBytes(pathToFile));
|
||||
byte[] buffer = AddHeader(File.ReadAllBytes(pathToFile));
|
||||
File.Delete(pathToFile);
|
||||
using FileStream fileStream = new FileStream(pathToFile, FileMode.Create);
|
||||
fileStream.Write(buffer, 0, buffer.Length);
|
||||
|
@ -764,7 +764,7 @@ namespace libWiiSharp
|
|||
/// <returns></returns>
|
||||
public static byte[] AddHeader(byte[] file)
|
||||
{
|
||||
Headers.IMD5 imD5 = Headers.IMD5.Create(file);
|
||||
Headers.IMD5 imD5 = Create(file);
|
||||
MemoryStream memoryStream1 = new MemoryStream();
|
||||
MemoryStream memoryStream2 = memoryStream1;
|
||||
imD5.WriteToStream(memoryStream2);
|
||||
|
@ -780,7 +780,7 @@ namespace libWiiSharp
|
|||
/// <param name="pathToFile"></param>
|
||||
public static void RemoveHeader(string pathToFile)
|
||||
{
|
||||
byte[] buffer = Headers.IMD5.RemoveHeader(File.ReadAllBytes(pathToFile));
|
||||
byte[] buffer = RemoveHeader(File.ReadAllBytes(pathToFile));
|
||||
File.Delete(pathToFile);
|
||||
using FileStream fileStream = new FileStream(pathToFile, FileMode.Create);
|
||||
fileStream.Write(buffer, 0, buffer.Length);
|
||||
|
|
20
HexView.cs
20
HexView.cs
|
@ -45,7 +45,7 @@ namespace libWiiSharp
|
|||
richTextBox.Clear();
|
||||
richTextBox.Font = new Font("Courier New", 9f);
|
||||
richTextBox.ReadOnly = true;
|
||||
richTextBox.Text = HexView.DumpAsString(data);
|
||||
richTextBox.Text = DumpAsString(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -59,7 +59,7 @@ namespace libWiiSharp
|
|||
textBox.Multiline = true;
|
||||
textBox.Font = new Font("Courier New", 9f);
|
||||
textBox.ReadOnly = true;
|
||||
textBox.Text = HexView.DumpAsString(data).Replace("\n", "\r\n");
|
||||
textBox.Text = DumpAsString(data).Replace("\n", "\r\n");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -71,7 +71,7 @@ namespace libWiiSharp
|
|||
/// <returns></returns>
|
||||
public static string DumpAsString(byte[] data)
|
||||
{
|
||||
return string.Join("\n", HexView.DumpAsStringArray(data));
|
||||
return string.Join("\n", DumpAsStringArray(data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -89,7 +89,7 @@ namespace libWiiSharp
|
|||
if (dataGridView.Columns[e.ColumnIndex].HeaderText.ToLower() == "dump")
|
||||
{
|
||||
string str = (string)dataGridView.Rows[e.RowIndex].Cells[17].Value;
|
||||
if (!(str != HexView.savedValue))
|
||||
if (!(str != savedValue))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -101,9 +101,9 @@ namespace libWiiSharp
|
|||
|
||||
for (int index = 0; index < 16; ++index)
|
||||
{
|
||||
if (HexView.ToAscii(byte.Parse((string)dataGridView.Rows[e.RowIndex].Cells[index + 1].Value, NumberStyles.HexNumber)) != str[index])
|
||||
if (ToAscii(byte.Parse((string)dataGridView.Rows[e.RowIndex].Cells[index + 1].Value, NumberStyles.HexNumber)) != str[index])
|
||||
{
|
||||
dataGridView.Rows[e.RowIndex].Cells[index + 1].Value = HexView.FromAscii(str[index]).ToString("x2");
|
||||
dataGridView.Rows[e.RowIndex].Cells[index + 1].Value = FromAscii(str[index]).ToString("x2");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ namespace libWiiSharp
|
|||
}
|
||||
|
||||
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());
|
||||
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());
|
||||
dataGridView.Rows[e.RowIndex].Cells[17].Value = str;
|
||||
if (((string)dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).Length <= 2)
|
||||
{
|
||||
|
@ -140,7 +140,7 @@ namespace libWiiSharp
|
|||
/// <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;
|
||||
savedValue = (string)((DataGridView)sender).Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -165,7 +165,7 @@ namespace libWiiSharp
|
|||
{
|
||||
str1 = str1 + data[num + index].ToString("x2") + " ";
|
||||
string str3 = str2;
|
||||
ascii = HexView.ToAscii(data[num + index]);
|
||||
ascii = ToAscii(data[num + index]);
|
||||
string str4 = ascii.ToString();
|
||||
str2 = str3 + str4;
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ namespace libWiiSharp
|
|||
{
|
||||
str1 = str1 + data[num + index].ToString("x2") + " ";
|
||||
string str3 = str2;
|
||||
ascii = HexView.ToAscii(data[num + index]);
|
||||
ascii = ToAscii(data[num + index]);
|
||||
string str4 = ascii.ToString();
|
||||
str2 = str3 + str4;
|
||||
}
|
||||
|
|
12
Lz77.cs
12
Lz77.cs
|
@ -34,17 +34,17 @@ namespace libWiiSharp
|
|||
//private int matchPosition;
|
||||
//private int matchLength;
|
||||
|
||||
public static uint Lz77Magic => Lz77.lz77Magic;
|
||||
public static uint Lz77Magic => lz77Magic;
|
||||
|
||||
public static bool IsLz77Compressed(string file)
|
||||
{
|
||||
return Lz77.IsLz77Compressed(File.ReadAllBytes(file));
|
||||
return IsLz77Compressed(File.ReadAllBytes(file));
|
||||
}
|
||||
|
||||
public static bool IsLz77Compressed(byte[] file)
|
||||
{
|
||||
Headers.HeaderType headerType = Headers.DetectHeader(file);
|
||||
return (int)Shared.Swap(BitConverter.ToUInt32(file, (int)headerType)) == (int)Lz77.lz77Magic;
|
||||
return (int)Shared.Swap(BitConverter.ToUInt32(file, (int)headerType)) == (int)lz77Magic;
|
||||
}
|
||||
|
||||
public static bool IsLz77Compressed(Stream file)
|
||||
|
@ -53,7 +53,7 @@ namespace libWiiSharp
|
|||
byte[] buffer = new byte[4];
|
||||
file.Seek((long)headerType, SeekOrigin.Begin);
|
||||
file.Read(buffer, 0, buffer.Length);
|
||||
return (int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)Lz77.lz77Magic;
|
||||
return (int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)lz77Magic;
|
||||
}
|
||||
|
||||
public void Compress(string inFile, string outFile)
|
||||
|
@ -120,7 +120,7 @@ namespace libWiiSharp
|
|||
|
||||
private Stream PrivDecompress(Stream inFile)
|
||||
{
|
||||
if (!Lz77.IsLz77Compressed(inFile))
|
||||
if (!IsLz77Compressed(inFile))
|
||||
{
|
||||
return inFile;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ namespace libWiiSharp
|
|||
byte[] buffer = new byte[8];
|
||||
inFile.Seek((long)headerType, SeekOrigin.Begin);
|
||||
inFile.Read(buffer, 0, 8);
|
||||
if ((int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) != (int)Lz77.lz77Magic)
|
||||
if ((int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) != (int)lz77Magic)
|
||||
{
|
||||
inFile.Dispose();
|
||||
throw new Exception("Invaild Magic!");
|
||||
|
|
26
NusClient.cs
26
NusClient.cs
|
@ -117,13 +117,13 @@ namespace libWiiSharp
|
|||
Directory.CreateDirectory(Path.GetDirectoryName(savePath));
|
||||
}
|
||||
|
||||
if (System.IO.File.Exists(savePath))
|
||||
if (File.Exists(savePath))
|
||||
{
|
||||
System.IO.File.Delete(savePath);
|
||||
File.Delete(savePath);
|
||||
}
|
||||
|
||||
byte[] bytes = PrivDownloadSingleContent(titleId, titleVersion, contentId);
|
||||
System.IO.File.WriteAllBytes(savePath, bytes);
|
||||
File.WriteAllBytes(savePath, bytes);
|
||||
}
|
||||
|
||||
private byte[] PrivDownloadSingleContent(string titleId, string titleVersion, string contentId)
|
||||
|
@ -329,7 +329,7 @@ namespace libWiiSharp
|
|||
string str3 = outputDir;
|
||||
contentId = tmd.Contents[index1].ContentID;
|
||||
string str4 = contentId.ToString("x8");
|
||||
if (System.IO.File.Exists(str3 + str4))
|
||||
if (File.Exists(str3 + str4))
|
||||
{
|
||||
FireDebug(" Using Local File, Skipping...");
|
||||
continue;
|
||||
|
@ -369,7 +369,7 @@ namespace libWiiSharp
|
|||
string str3 = outputDir;
|
||||
contentId = tmd.Contents[contentIndex].ContentID;
|
||||
string str4 = contentId.ToString("x8");
|
||||
byte[] array = DecryptContent(System.IO.File.ReadAllBytes(str3 + str4), contentIndex, tik, tmd);
|
||||
byte[] array = DecryptContent(File.ReadAllBytes(str3 + str4), contentIndex, tik, tmd);
|
||||
Array.Resize<byte>(ref array, (int)tmd.Contents[contentIndex].Size);
|
||||
if (!Shared.CompareByteArrays(shA1.ComputeHash(array), tmd.Contents[contentIndex].Hash))
|
||||
{
|
||||
|
@ -379,7 +379,7 @@ namespace libWiiSharp
|
|||
string str5 = outputDir;
|
||||
contentId = tmd.Contents[contentIndex].ContentID;
|
||||
string str6 = contentId.ToString("x8");
|
||||
System.IO.File.WriteAllBytes(str5 + str6 + ".app", array);
|
||||
File.WriteAllBytes(str5 + str6 + ".app", array);
|
||||
}
|
||||
shA1.Clear();
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ namespace libWiiSharp
|
|||
string str3 = outputDir;
|
||||
contentId = tmd.Contents[index1].ContentID;
|
||||
string str4 = contentId.ToString("x8");
|
||||
byte[] numArray2 = System.IO.File.ReadAllBytes(str3 + str4 + ".app");
|
||||
byte[] numArray2 = File.ReadAllBytes(str3 + str4 + ".app");
|
||||
numArray1[index2] = numArray2;
|
||||
}
|
||||
FireDebug(" Creating WAD...");
|
||||
|
@ -406,9 +406,9 @@ namespace libWiiSharp
|
|||
FireDebug(" Deleting Encrypted Contents...");
|
||||
for (int index = 0; index < strArray1.Length; ++index)
|
||||
{
|
||||
if (System.IO.File.Exists(outputDir + strArray1[index]))
|
||||
if (File.Exists(outputDir + strArray1[index]))
|
||||
{
|
||||
System.IO.File.Delete(outputDir + strArray1[index]);
|
||||
File.Delete(outputDir + strArray1[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -417,17 +417,17 @@ namespace libWiiSharp
|
|||
FireDebug(" Deleting Decrypted Contents...");
|
||||
for (int index = 0; index < strArray1.Length; ++index)
|
||||
{
|
||||
if (System.IO.File.Exists(outputDir + strArray1[index] + ".app"))
|
||||
if (File.Exists(outputDir + strArray1[index] + ".app"))
|
||||
{
|
||||
System.IO.File.Delete(outputDir + strArray1[index] + ".app");
|
||||
File.Delete(outputDir + strArray1[index] + ".app");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!flag2 && !flag1)
|
||||
{
|
||||
FireDebug(" Deleting TMD and Ticket...");
|
||||
System.IO.File.Delete(outputDir + str2);
|
||||
System.IO.File.Delete(outputDir + "cetk");
|
||||
File.Delete(outputDir + str2);
|
||||
File.Delete(outputDir + "cetk");
|
||||
}
|
||||
FireDebug("Downloading Title {0} v{1} Finished...", titleId, string.IsNullOrEmpty(titleVersion) ? "[Latest]" : titleVersion);
|
||||
FireProgress(100);
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace libWiiSharp
|
|||
|
||||
public static long AddPadding(long value)
|
||||
{
|
||||
return Shared.AddPadding(value, 64);
|
||||
return AddPadding(value, 64);
|
||||
}
|
||||
|
||||
public static long AddPadding(long value, int padding)
|
||||
|
@ -130,7 +130,7 @@ namespace libWiiSharp
|
|||
|
||||
public static int AddPadding(int value)
|
||||
{
|
||||
return Shared.AddPadding(value, 64);
|
||||
return AddPadding(value, 64);
|
||||
}
|
||||
|
||||
public static int AddPadding(int value, int padding)
|
||||
|
|
2
TMD.cs
2
TMD.cs
|
@ -153,7 +153,7 @@ namespace libWiiSharp
|
|||
|
||||
public static TMD Load(string pathToTmd)
|
||||
{
|
||||
return TMD.Load(File.ReadAllBytes(pathToTmd));
|
||||
return Load(File.ReadAllBytes(pathToTmd));
|
||||
}
|
||||
|
||||
public static TMD Load(byte[] tmdFile)
|
||||
|
|
4
TPL.cs
4
TPL.cs
|
@ -140,7 +140,7 @@ namespace libWiiSharp
|
|||
TPL_TextureFormat tplFormat,
|
||||
TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
|
||||
{
|
||||
return TPL.FromImages(new string[1] { pathToImage }, new TPL_TextureFormat[1]
|
||||
return FromImages(new string[1] { pathToImage }, new TPL_TextureFormat[1]
|
||||
{
|
||||
tplFormat
|
||||
}, new TPL_PaletteFormat[1] { paletteFormat });
|
||||
|
@ -151,7 +151,7 @@ namespace libWiiSharp
|
|||
TPL_TextureFormat tplFormat,
|
||||
TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
|
||||
{
|
||||
return TPL.FromImages(new Image[1] { img }, new TPL_TextureFormat[1]
|
||||
return FromImages(new Image[1] { img }, new TPL_TextureFormat[1]
|
||||
{
|
||||
tplFormat
|
||||
}, new TPL_PaletteFormat[1] { paletteFormat });
|
||||
|
|
|
@ -148,7 +148,7 @@ namespace libWiiSharp
|
|||
|
||||
public static Ticket Load(string pathToTicket)
|
||||
{
|
||||
return Ticket.Load(File.ReadAllBytes(pathToTicket));
|
||||
return Load(File.ReadAllBytes(pathToTicket));
|
||||
}
|
||||
|
||||
public static Ticket Load(byte[] ticket)
|
||||
|
|
6
U8.cs
6
U8.cs
|
@ -111,7 +111,7 @@ namespace libWiiSharp
|
|||
|
||||
public static bool IsU8(string pathToFile)
|
||||
{
|
||||
return U8.IsU8(File.ReadAllBytes(pathToFile));
|
||||
return IsU8(File.ReadAllBytes(pathToFile));
|
||||
}
|
||||
|
||||
public static bool IsU8(byte[] file)
|
||||
|
@ -124,7 +124,7 @@ namespace libWiiSharp
|
|||
file1[index] = file[index];
|
||||
}
|
||||
|
||||
return U8.IsU8(new Lz77().Decompress(file1));
|
||||
return IsU8(new Lz77().Decompress(file1));
|
||||
}
|
||||
Headers.HeaderType headerType = Headers.DetectHeader(file);
|
||||
return Shared.Swap(BitConverter.ToUInt32(file, (int)headerType)) == 1437218861U;
|
||||
|
@ -132,7 +132,7 @@ namespace libWiiSharp
|
|||
|
||||
public static U8 Load(string pathToU8)
|
||||
{
|
||||
return U8.Load(File.ReadAllBytes(pathToU8));
|
||||
return Load(File.ReadAllBytes(pathToU8));
|
||||
}
|
||||
|
||||
public static U8 Load(byte[] u8File)
|
||||
|
|
8
WAD.cs
8
WAD.cs
|
@ -212,7 +212,7 @@ namespace libWiiSharp
|
|||
|
||||
public static WAD Load(string pathToWad)
|
||||
{
|
||||
return WAD.Load(File.ReadAllBytes(pathToWad));
|
||||
return Load(File.ReadAllBytes(pathToWad));
|
||||
}
|
||||
|
||||
public static WAD Load(byte[] wadFile)
|
||||
|
@ -272,7 +272,7 @@ namespace libWiiSharp
|
|||
string path = contentDir + Path.DirectorySeparatorChar.ToString() + (flag ? tmd.Contents[index].ContentID.ToString("x8") : tmd.Contents[index].Index.ToString("x8")) + ".app";
|
||||
contents[index] = File.ReadAllBytes(path);
|
||||
}
|
||||
return WAD.Create(cert, tik, tmd, contents);
|
||||
return Create(cert, tik, tmd, contents);
|
||||
}
|
||||
|
||||
public static WAD Create(
|
||||
|
@ -309,7 +309,7 @@ namespace libWiiSharp
|
|||
string path = contentDir + Path.DirectorySeparatorChar.ToString() + (flag ? tmd.Contents[index].ContentID.ToString("x8") : tmd.Contents[index].Index.ToString("x8")) + ".app";
|
||||
contents[index] = File.ReadAllBytes(path);
|
||||
}
|
||||
return WAD.Create(cert, tik, tmd, contents);
|
||||
return Create(cert, tik, tmd, contents);
|
||||
}
|
||||
|
||||
public static WAD Create(byte[] cert, byte[] tik, byte[] tmd, byte[][] contents)
|
||||
|
@ -320,7 +320,7 @@ namespace libWiiSharp
|
|||
Ticket tik1 = ticket;
|
||||
TMD tmd2 = tmd1;
|
||||
byte[][] contents1 = contents;
|
||||
return WAD.Create(cert1, tik1, tmd2, contents1);
|
||||
return Create(cert1, tik1, tmd2, contents1);
|
||||
}
|
||||
|
||||
public static WAD Create(CertificateChain cert, Ticket tik, TMD tmd, byte[][] contents)
|
||||
|
|
Loading…
Reference in a new issue