Many tiny fixes. This is close to v1.2 final.

This commit is contained in:
givememystuffplease 2009-07-10 00:56:17 +00:00
parent e770c15458
commit dadf1e185f

View File

@ -13,10 +13,11 @@ namespace NUS_Downloader
const string NUSURL = "http://nus.cdn.shop.wii.com/ccs/download/"; const string NUSURL = "http://nus.cdn.shop.wii.com/ccs/download/";
const string DSiNUSURL = "http://nus.cdn.t.shop.nintendowifi.net/ccs/download/"; const string DSiNUSURL = "http://nus.cdn.t.shop.nintendowifi.net/ccs/download/";
// TODO: Always remember to change version! // TODO: Always remember to change version!
string version = "v1.2 Beta"; string version = "v1.2";
WebClient generalWC = new WebClient(); WebClient generalWC = new WebClient();
static RijndaelManaged rijndaelCipher; static RijndaelManaged rijndaelCipher;
static bool dsidecrypt = false; static bool dsidecrypt = false;
const string certs_MD5 = "7677AD47BAA5D6E3E313E72661FBDC16";
// Images do not compare unless globalized... // Images do not compare unless globalized...
Image green = Properties.Resources.bullet_green; Image green = Properties.Resources.bullet_green;
@ -37,31 +38,22 @@ namespace NUS_Downloader
public int FooterSize; public int FooterSize;
}; };
const string certs_MD5 = "7677AD47BAA5D6E3E313E72661FBDC16"; // This is the standard entry to the GUI
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
BootChecks(); BootChecks();
} }
// CLI Mode
public Form1(string[] args) public Form1(string[] args)
{ {
// CLI Mode
InitializeComponent(); InitializeComponent();
// certs.sys / key.bin // certs.sys / key.bin
if (BootChecks() == false) if (BootChecks() == false)
return; return;
// DEBUG
/*
for (int i = 0; i < args.Length; i++)
{
WriteStatus(i + ": " + args[i]);
}
*/
// Vars // Vars
bool startnow = false; bool startnow = false;
bool endafter = false; bool endafter = false;
@ -122,6 +114,11 @@ namespace NUS_Downloader
WriteStatus("Please enter SOME info..."); WriteStatus("Please enter SOME info...");
return; return;
} }
else
{
if (!statusbox.Lines[0].StartsWith(" ---"))
statusbox.Text = " --- " + titleidbox.Text + " ---";
}
// Running Downloads in background so no form freezing // Running Downloads in background so no form freezing
NUSDownloader.RunWorkerAsync(); NUSDownloader.RunWorkerAsync();
@ -132,7 +129,6 @@ namespace NUS_Downloader
{ {
// Do nothing... // Do nothing...
} }
if ((NUSDownloader.IsBusy == false) && (endafter == true)) if ((NUSDownloader.IsBusy == false) && (endafter == true))
{ {
Application.Exit(); Application.Exit();
@ -252,12 +248,10 @@ namespace NUS_Downloader
if (opentmd.ShowDialog() != DialogResult.Cancel) if (opentmd.ShowDialog() != DialogResult.Cancel)
{ {
// Read the tmd as a stream... // Read the tmd as a stream...
FileStream fs = File.OpenRead(opentmd.FileName); byte[] tmd = FileLocationToByteArray(opentmd.FileName);
byte[] tmd = ReadFully(fs, 20);
WriteStatus("TMD Loaded (" + tmd.Length + " bytes)"); WriteStatus("TMD Loaded (" + tmd.Length + " bytes)");
// Read ID... // Read ID...
titleidbox.Text = "";
for (int x = 396; x < 404; x++) for (int x = 396; x < 404; x++)
{ {
titleidbox.Text += MakeProperLength(ConvertToHex(Convert.ToString(tmd[x]))); titleidbox.Text += MakeProperLength(ConvertToHex(Convert.ToString(tmd[x])));
@ -307,7 +301,7 @@ namespace NUS_Downloader
{ {
hash[x] = tmdhashes[(i*20)+x]; hash[x] = tmdhashes[(i*20)+x];
} }
WriteStatus(" - Hash: " + DisplayBytes(hash)); WriteStatus(" - Hash: " + DisplayBytes(hash, ""));
WriteStatus(" - Index: " + tmdindices[i]); WriteStatus(" - Index: " + tmdindices[i]);
} }
@ -316,8 +310,7 @@ namespace NUS_Downloader
private void WriteStatus(string Update) private void WriteStatus(string Update)
{ {
// Small thing for writing text to the statusbox... // Small function for writing text to the statusbox...
if (statusbox.Text == "") if (statusbox.Text == "")
statusbox.Text = Update; statusbox.Text = Update;
else else
@ -391,11 +384,8 @@ namespace NUS_Downloader
private string ConvertToHex(string decval) private string ConvertToHex(string decval)
{ {
// Convert text string to unsigned integer // Convert text string to unsigned integer
int uiDecimal = System.Convert.ToInt32(decval); int uiDecimal = System.Convert.ToInt32(decval);
return String.Format("{0:x2}", uiDecimal);
string hexval;
hexval = String.Format("{0:x2}", uiDecimal);
return hexval;
} }
private void ReadIDType(string ttlid) private void ReadIDType(string ttlid)
@ -528,7 +518,6 @@ namespace NUS_Downloader
} }
startoffset += 36; startoffset += 36;
} }
//WriteStatus(DisplayBytes(contenthashes));
return contenthashes; return contenthashes;
} }
@ -556,7 +545,8 @@ namespace NUS_Downloader
} }
else else
{ {
statusbox.Text = " --- " + titleidbox.Text + " ---"; if (!statusbox.Lines[0].StartsWith(" ---"))
statusbox.Text = " --- " + titleidbox.Text + " ---";
} }
// Running Downloads in background so no form freezing // Running Downloads in background so no form freezing
@ -652,9 +642,7 @@ namespace NUS_Downloader
if (decryptbox.Checked == true) if (decryptbox.Checked == true)
{ {
// Create ticket file holder // Create ticket file holder
FileStream fs1 = File.OpenRead(titledirectory + @"\cetk"); byte[] cetkbuf = FileLocationToByteArray(titledirectory + @"\cetk");
byte[] cetkbuf = ReadFully(fs1, 20);
fs1.Close();
// Load TitleKey into it's byte[] // Load TitleKey into it's byte[]
// It is currently encrypted... // It is currently encrypted...
@ -674,41 +662,30 @@ namespace NUS_Downloader
iv[i+8] = 0x00; iv[i+8] = 0x00;
} }
// Standard/Korea // Standard/Korea Common Key
bool koreankey = false; byte[] keyBytes;
//WriteStatus("0x01F1: " + Convert.ToString(cetkbuf[0x01F1]));
if (cetkbuf[0x01F1] == 0x01) if (cetkbuf[0x01F1] == 0x01)
{ {
WriteStatus("Key Type: Korean"); WriteStatus("Key Type: Korean");
koreankey = true; keyBytes = LoadCommonKey(@"\kkey.bin");
} }
else else
{ {
WriteStatus("Key Type: Standard"); WriteStatus("Key Type: Standard");
} if (wiimode)
// Common Key
byte[] keyBytes;
if (wiimode)
{
if (koreankey)
keyBytes = LoadCommonKey(@"\kkey.bin");
else
keyBytes = LoadCommonKey(@"\key.bin"); keyBytes = LoadCommonKey(@"\key.bin");
else
keyBytes = LoadCommonKey(@"\dsikey.bin");
} }
else
keyBytes = LoadCommonKey(@"\dsikey.bin");
initCrypt(iv, keyBytes); initCrypt(iv, keyBytes);
WriteStatus("Title Key: " + DisplayBytes(Decrypt(titlekey))); WriteStatus("Title Key: " + DisplayBytes(Decrypt(titlekey), ""));
titlekey = Decrypt(titlekey); titlekey = Decrypt(titlekey);
} }
// Read the tmd as a stream... // Read the tmd as a stream...
FileStream fs = File.OpenRead(titledirectory + tmdfull); byte[] tmd = FileLocationToByteArray(titledirectory + tmdfull);
byte[] tmd = ReadFully(fs, 20);
fs.Close();
// Read Title Version... // Read Title Version...
string tmdversion = ""; string tmdversion = "";
@ -794,14 +771,10 @@ namespace NUS_Downloader
if (decryptbox.Checked == true) if (decryptbox.Checked == true)
{ {
// Create content file holder // Create content file holder
FileStream cont = File.OpenRead(titledirectory + @"\" + tmdcontents[i]); byte[] contbuf = FileLocationToByteArray(titledirectory + @"\" + tmdcontents[i]);
byte[] contbuf = ReadFully(cont, 20);
cont.Close();
// Create ticket file holder // Create ticket file holder
FileStream fs1 = File.OpenRead(titledirectory + @"\cetk"); byte[] cetkbuf = FileLocationToByteArray(titledirectory + @"\cetk");
byte[] cetkbuf = ReadFully(fs1, 20);
fs1.Close();
// IV (00+IDX+more000) // IV (00+IDX+more000)
byte[] iv = new byte[16]; byte[] iv = new byte[16];
@ -839,8 +812,8 @@ namespace NUS_Downloader
else else
{ {
WriteStatus(" - Hash Check: Fail"); WriteStatus(" - Hash Check: Fail");
WriteStatus(" - True Hash: " + DisplayBytes(hash)); WriteStatus(" - True Hash: " + DisplayBytes(hash, ""));
WriteStatus(" - You Have: " + DisplayBytes(ComputeSHA(Decrypt(contbuf)))); WriteStatus(" - You Have: " + DisplayBytes(ComputeSHA(Decrypt(contbuf)), ""));
} }
} }
@ -865,9 +838,7 @@ namespace NUS_Downloader
// Read information from TIK into signing GUI... // Read information from TIK into signing GUI...
// Create ticket file holder // Create ticket file holder
FileStream cetkf = File.OpenRead(titledirectory + @"\cetk"); byte[] cetkbuff = FileLocationToByteArray(titledirectory + @"\cetk");
byte[] cetkbuff = ReadFully(cetkf, 20);
cetkf.Close();
// Titlekey // Titlekey
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
@ -887,7 +858,7 @@ namespace NUS_Downloader
{ {
iv[i + 8] = 0x00; iv[i + 8] = 0x00;
} }
titleIDIV.Text = DisplayBytes(iv).Replace(" ", ""); titleIDIV.Text = DisplayBytes(iv, "");
//DLC //DLC
dlcamntbox.Text = Convert.ToString((cetkbuff[0x1E6]*256) + cetkbuff[0x1E7]); dlcamntbox.Text = Convert.ToString((cetkbuff[0x1E6]*256) + cetkbuff[0x1E7]);
@ -1047,19 +1018,13 @@ namespace NUS_Downloader
currentdir += @"\"; currentdir += @"\";
// Create cert file holder // Create cert file holder
FileStream certfs = File.OpenRead(currentdir + @"\cert.sys"); byte[] certsbuf = FileLocationToByteArray(currentdir + @"\cert.sys");
byte[] certsbuf = ReadFully(certfs, 20);
certfs.Close();
// Create ticket file holder // Create ticket file holder
FileStream fs1 = File.OpenRead(totaldirectory + @"\cetk"); byte[] cetkbuf = FileLocationToByteArray(totaldirectory + @"\cetk");
byte[] cetkbuf = ReadFully(fs1, 20);
fs1.Close();
// Create tmd file holder // Create tmd file holder
FileStream fs2 = File.OpenRead(totaldirectory + @"\" + tmdfilename); byte[] tmdbuf = FileLocationToByteArray(totaldirectory + @"\" + tmdfilename);
byte[] tmdbuf = ReadFully(fs2, 20);
fs2.Close();
if (wadnamebox.Text.Contains("[v]") == true) if (wadnamebox.Text.Contains("[v]") == true)
wadnamebox.Text = wadnamebox.Text.Replace("[v]", "v" + titleversion.Text); wadnamebox.Text = wadnamebox.Text.Replace("[v]", "v" + titleversion.Text);
@ -1105,9 +1070,7 @@ namespace NUS_Downloader
wadfs.Seek(ByteBoundary(Convert.ToInt32(wadfs.Length)), SeekOrigin.Begin); wadfs.Seek(ByteBoundary(Convert.ToInt32(wadfs.Length)), SeekOrigin.Begin);
// Create content file holder // Create content file holder
FileStream cont = File.OpenRead(totaldirectory + @"\" + contentnames[i]); byte[] contbuf = FileLocationToByteArray(totaldirectory + @"\" + contentnames[i]);
byte[] contbuf = ReadFully(cont, 20);
cont.Close();
wadfs.Write(contbuf, 0, contbuf.Length); wadfs.Write(contbuf, 0, contbuf.Length);
@ -1301,14 +1264,10 @@ namespace NUS_Downloader
DownloadNUSFile("0000000100000002", "cetk", currentdir + @"\", 0, true); DownloadNUSFile("0000000100000002", "cetk", currentdir + @"\", 0, true);
// Create ticket file holder // Create ticket file holder
FileStream cetk = File.OpenRead(currentdir + "cetk"); byte[] cetkbuf = FileLocationToByteArray(currentdir + "cetk");
byte[] cetkbuf = ReadFully(cetk, 20);
cetk.Close();
// Create tmd file holder // Create tmd file holder
FileStream tmd = File.OpenRead(currentdir + "tmd.289"); byte[] tmdbuf = FileLocationToByteArray(currentdir + "tmd.289");
byte[] tmdbuf = ReadFully(tmd, 20);
tmd.Close();
// Write CA cert... // Write CA cert...
certsfs.Seek(0, SeekOrigin.Begin); certsfs.Seek(0, SeekOrigin.Begin);
@ -1391,20 +1350,7 @@ namespace NUS_Downloader
{ {
wadnamebox.Enabled = true; wadnamebox.Enabled = true;
// Change WAD name if applicable // Change WAD name if applicable
if (packbox.Checked == true) UpdatePackedName();
{
if (titleidbox.Enabled == true)
{
if (titleversion.Text != "")
{
wadnamebox.Text = titleidbox.Text + "-NUS-v" + titleversion.Text + ".wad";
}
else
{
wadnamebox.Text = titleidbox.Text + "-NUS-[v]" + titleversion.Text + ".wad";
}
}
}
} }
else else
{ {
@ -1415,37 +1361,12 @@ namespace NUS_Downloader
private void titleidbox_TextChanged(object sender, EventArgs e) private void titleidbox_TextChanged(object sender, EventArgs e)
{ {
// Change WAD name if applicable UpdatePackedName();
if (packbox.Checked == true)
{
if (titleidbox.Enabled == true)
{
if (titleversion.Text != "")
{
wadnamebox.Text = titleidbox.Text + "-NUS-v" + titleversion.Text + ".wad";
}
else
{
wadnamebox.Text = titleidbox.Text + "-NUS-[v]" + titleversion.Text + ".wad";
}
}
}
} }
private void titleversion_TextChanged(object sender, EventArgs e) private void titleversion_TextChanged(object sender, EventArgs e)
{ {
// Change WAD name if applicable UpdatePackedName();
if ((titleidbox.Enabled == true) && (packbox.Checked == true))
{
if (titleversion.Text != "")
{
wadnamebox.Text = titleidbox.Text + "-NUS-v" + titleversion.Text + ".wad";
}
else
{
wadnamebox.Text = titleidbox.Text + "-NUS-[v]" + titleversion.Text + ".wad";
}
}
} }
public void initCrypt(byte[] iv, byte[] key) public void initCrypt(byte[] iv, byte[] key)
@ -1498,12 +1419,12 @@ namespace NUS_Downloader
} }
} }
public string DisplayBytes(byte[] bytes) public string DisplayBytes(byte[] bytes, string spacer)
{ {
string output = ""; string output = "";
for (int i = 0; i < bytes.Length; ++i) for (int i = 0; i < bytes.Length; ++i)
{ {
output += bytes[i].ToString("X2") + " "; output += bytes[i].ToString("X2") + spacer;
} }
return output; return output;
} }
@ -1524,11 +1445,8 @@ namespace NUS_Downloader
if (File.Exists(currentdir + keyfile) == true) if (File.Exists(currentdir + keyfile) == true)
{ {
// Read common key into array // Read common key byte[]
FileStream ckey = File.OpenRead(currentdir + keyfile); return FileLocationToByteArray(currentdir + keyfile);
byte[] ckeybuf = ReadFully(ckey, 16);
ckey.Close();
return ckeybuf;
} }
else else
return null; return null;
@ -1538,8 +1456,6 @@ namespace NUS_Downloader
{ {
// Open Database button menu... // Open Database button menu...
databaseStrip.Show(databaseButton, 2, 2); databaseStrip.Show(databaseButton, 2, 2);
} }
private void ClearDatabaseStrip() private void ClearDatabaseStrip()
@ -1611,15 +1527,6 @@ namespace NUS_Downloader
} }
break; break;
case "region": case "region":
/* string[] regions = ChildrenOfTheNode[z].InnerText.Split(',');
if (ChildrenOfTheNode[z].InnerText != "")
{
for (int y = 0; y < regions.Length; y++)
{
XMLToolStripItem.DropDownItems.Add(regions[y]);
}
}
break; */
string[] regions = ChildrenOfTheNode[z].InnerText.Split(','); string[] regions = ChildrenOfTheNode[z].InnerText.Split(',');
if (ChildrenOfTheNode[z].InnerText != "") if (ChildrenOfTheNode[z].InnerText != "")
{ {
@ -1633,15 +1540,10 @@ namespace NUS_Downloader
break; break;
case "ticket": case "ticket":
ticket = Convert.ToBoolean(ChildrenOfTheNode[z].InnerText); ticket = Convert.ToBoolean(ChildrenOfTheNode[z].InnerText);
/*if (!ticket)
stticket += "(-)";
else
stticket += "(+)"; */
break; break;
case "danger": case "danger":
dangerous = true; dangerous = true;
string dangertext = ChildrenOfTheNode[z].InnerText; XMLToolStripItem.ToolTipText = ChildrenOfTheNode[z].InnerText;
XMLToolStripItem.ToolTipText = dangertext;
break; break;
} }
XMLToolStripItem.Image = SelectItemImage(ticket, dangerous); XMLToolStripItem.Image = SelectItemImage(ticket, dangerous);
@ -1726,7 +1628,8 @@ namespace NUS_Downloader
titleidbox.Text = titleidbox.Text.Replace("XX", e.ClickedItem.Text.Substring(0, 2)); titleidbox.Text = titleidbox.Text.Replace("XX", e.ClickedItem.Text.Substring(0, 2));
// Prepare StatusBox... // Prepare StatusBox...
statusbox.Text = " --- " + e.ClickedItem.OwnerItem.Text.Substring(19, (e.ClickedItem.OwnerItem.Text.Length - 19)) + " ---"; string titlename = e.ClickedItem.OwnerItem.Text.Substring(19, (e.ClickedItem.OwnerItem.Text.Length - 19));
statusbox.Text = " --- " + titlename + " ---";
// Check if a ticket is present... // Check if a ticket is present...
if ((e.ClickedItem.OwnerItem.Image) == (orange) || (e.ClickedItem.OwnerItem.Image) == (redorange)) if ((e.ClickedItem.OwnerItem.Image) == (orange) || (e.ClickedItem.OwnerItem.Image) == (redorange))
@ -1741,6 +1644,17 @@ namespace NUS_Downloader
ignoreticket.Checked = false; ignoreticket.Checked = false;
} }
// Change WAD name if packed is already checked...
if (packbox.Checked)
{
if (titlename.Contains("IOS"))
wadnamebox.Text = titlename + "-64-[v].wad";
else
wadnamebox.Text = titlename + "-NUS-[v].wad";
if (titleversion.Text != "")
wadnamebox.Text = wadnamebox.Text.Replace("[v]", "v" + titleversion.Text);
}
// Check for danger item // Check for danger item
if ((e.ClickedItem.OwnerItem.Image) == (redgreen) || (e.ClickedItem.OwnerItem.Image) == (redorange)) if ((e.ClickedItem.OwnerItem.Image) == (redgreen) || (e.ClickedItem.OwnerItem.Image) == (redorange))
{ {
@ -1772,7 +1686,8 @@ namespace NUS_Downloader
} }
// Prepare StatusBox... // Prepare StatusBox...
statusbox.Text = " --- " + e.ClickedItem.OwnerItem.Text.Substring(19, (e.ClickedItem.OwnerItem.Text.Length - 19)) + " ---"; string titlename = e.ClickedItem.OwnerItem.Text.Substring(19, (e.ClickedItem.OwnerItem.Text.Length - 19));
statusbox.Text = " --- " + titlename + " ---";
if ((e.ClickedItem.OwnerItem.Image) == (orange) || (e.ClickedItem.OwnerItem.Image) == (redorange)) if ((e.ClickedItem.OwnerItem.Image) == (orange) || (e.ClickedItem.OwnerItem.Image) == (redorange))
{ {
@ -1786,6 +1701,17 @@ namespace NUS_Downloader
ignoreticket.Checked = false; ignoreticket.Checked = false;
} }
// Change WAD name if packed is already checked...
if (packbox.Checked)
{
if (titlename.Contains("IOS"))
wadnamebox.Text = titlename + "-64-[v].wad";
else
wadnamebox.Text = titlename + "-NUS-[v].wad";
if (titleversion.Text != "")
wadnamebox.Text = wadnamebox.Text.Replace("[v]", "v" + titleversion.Text);
}
// Check for danger item // Check for danger item
if ((e.ClickedItem.OwnerItem.Image) == (redgreen) || (e.ClickedItem.OwnerItem.Image) == (redorange)) if ((e.ClickedItem.OwnerItem.Image) == (redgreen) || (e.ClickedItem.OwnerItem.Image) == (redorange))
{ {
@ -1934,9 +1860,7 @@ namespace NUS_Downloader
string[] fileinfo = shamelessvariablelabel.Text.Split(','); string[] fileinfo = shamelessvariablelabel.Text.Split(',');
// Read the tmd as a stream... // Read the tmd as a stream...
FileStream fs = File.OpenRead(fileinfo[0] + fileinfo[1]); byte[] tmd = FileLocationToByteArray(fileinfo[0] + fileinfo[1]);
byte[] tmd = ReadFully(fs, 20);
fs.Close();
// Read information from TMD into signing GUI... // Read information from TMD into signing GUI...
requiredIOSbox.Text = Convert.ToString(tmd[0x18B]); requiredIOSbox.Text = Convert.ToString(tmd[0x18B]);
@ -1949,8 +1873,6 @@ namespace NUS_Downloader
requiredIOSbox.Enabled = false; requiredIOSbox.Enabled = false;
else else
requiredIOSbox.Enabled = true; requiredIOSbox.Enabled = true;
} }
private void button5_Click(object sender, EventArgs e) private void button5_Click(object sender, EventArgs e)
@ -1959,9 +1881,7 @@ namespace NUS_Downloader
string[] fileinfo = shamelessvariablelabel.Text.Split(','); string[] fileinfo = shamelessvariablelabel.Text.Split(',');
// Create ticket file holder // Create ticket file holder
FileStream cetkf = File.OpenRead(fileinfo[0] + @"\cetk"); byte[] cetkbuff = FileLocationToByteArray(fileinfo[0] + @"\cetk");
byte[] cetkbuff = ReadFully(cetkf, 20);
cetkf.Close();
// Titlekey // Titlekey
byte[] titlekey = new byte[16]; byte[] titlekey = new byte[16];
@ -1969,7 +1889,6 @@ namespace NUS_Downloader
{ {
titlekey[i] = cetkbuff[0x1BF + i]; titlekey[i] = cetkbuff[0x1BF + i];
} }
//titlekeybox.Text = DisplayBytes(titlekey).Replace(" ", "");
titlekeybox.Text = System.Text.Encoding.UTF7.GetString(titlekey); titlekeybox.Text = System.Text.Encoding.UTF7.GetString(titlekey);
// IV (TITLEID+00000000s) // IV (TITLEID+00000000s)
@ -1982,7 +1901,7 @@ namespace NUS_Downloader
{ {
iv[i + 8] = 0x00; iv[i + 8] = 0x00;
} }
titleIDIV.Text = DisplayBytes(iv).Replace(" ", ""); titleIDIV.Text = DisplayBytes(iv, "");
//DLC //DLC
dlcamntbox.Text = Convert.ToString((cetkbuff[0x1E6]*256) + cetkbuff[0x1E7]); dlcamntbox.Text = Convert.ToString((cetkbuff[0x1E6]*256) + cetkbuff[0x1E7]);
@ -2021,9 +1940,7 @@ namespace NUS_Downloader
string[] fileinfo = shamelessvariablelabel.Text.Split(','); string[] fileinfo = shamelessvariablelabel.Text.Split(',');
// Read the tmd as a stream... // Read the tmd as a stream...
FileStream fs = File.OpenRead(fileinfo[0] + fileinfo[1]); byte[] tmd = FileLocationToByteArray(fileinfo[0] + fileinfo[1]);
byte[] tmd = ReadFully(fs, 20);
fs.Close();
// Resize to just TMD... // Resize to just TMD...
Array.Resize(ref tmd, 484 + (Convert.ToInt32(fileinfo[2]) * 36)); Array.Resize(ref tmd, 484 + (Convert.ToInt32(fileinfo[2]) * 36));
@ -2067,9 +1984,7 @@ namespace NUS_Downloader
string[] fileinfo = shamelessvariablelabel.Text.Split(','); string[] fileinfo = shamelessvariablelabel.Text.Split(',');
// Create ticket file holder // Create ticket file holder
FileStream cetkf = File.OpenRead(fileinfo[0] + @"\cetk"); byte[] cetkbuff = FileLocationToByteArray(fileinfo[0] + @"\cetk");
byte[] cetkbuff = ReadFully(cetkf, 20);
cetkf.Close();
// Resize Ticket to actual size. // Resize Ticket to actual size.
Array.Resize(ref cetkbuff, 0x2A4); Array.Resize(ref cetkbuff, 0x2A4);
@ -2102,7 +2017,7 @@ namespace NUS_Downloader
byte[] limitseconds = new byte[4]; byte[] limitseconds = new byte[4];
limitseconds = InttoByteArray(Convert.ToInt32(timelimitsecs.Text), 4); limitseconds = InttoByteArray(Convert.ToInt32(timelimitsecs.Text), 4);
//DEBUG //DEBUG
WriteStatus(DisplayBytes(limitseconds)); WriteStatus(DisplayBytes(limitseconds, " "));
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
cetkbuff[0x248 + i] = limitseconds[i]; cetkbuff[0x248 + i] = limitseconds[i];
@ -2191,5 +2106,29 @@ namespace NUS_Downloader
return null; return null;
} }
private byte[] FileLocationToByteArray(string filename)
{
FileStream fs = File.OpenRead(filename);
byte[] filebytearray = ReadFully(fs, 460);
fs.Close();
return filebytearray;
}
private void UpdatePackedName()
{
// Change WAD name if applicable
if ((titleidbox.Enabled == true) && (packbox.Checked == true))
{
if (titleversion.Text != "")
{
wadnamebox.Text = titleidbox.Text + "-NUS-v" + titleversion.Text + ".wad";
}
else
{
wadnamebox.Text = titleidbox.Text + "-NUS-[v]" + titleversion.Text + ".wad";
}
}
}
} }
} }