public static void DownloadTitle(NintendoTitle currentTitle)
        {
            bool success = true;
            StatusChanged("Starting NUS Download. Please be patient!");
            StatusChanged("Prerequisites: (0/2)");
            // Download TMD before the rest...
            success = DownloadNUSFile(currentTitle, currentTitle.TMDFull);
            if (success)
            {
                StatusChanged("Prerequisites: (1/2)");
                // Download CETK before the rest...
                success = DownloadNUSFile(currentTitle, "cetk");
            }

            // Gather information...
            string[] tmdcontents = currentTitle.GetContentNames();
            string[] tmdsizes = currentTitle.GetContentSizes();
            string[] tmdhashes = currentTitle.GetContentHashes();

            float totalcontentsize = 0;
            float currentcontentlocation = 0;
            for (int i = 0; i < tmdsizes.Length; i++)
            {
                totalcontentsize += int.Parse(tmdsizes[i], System.Globalization.NumberStyles.HexNumber);
            }
            bool continueTrans = true;
            for (int i = 0; i < tmdcontents.Length && continueTrans; i++)
            {
                continueTrans = DownloadNUSFile(currentTitle, tmdcontents[i]);
                currentcontentlocation += int.Parse(tmdsizes[i], System.Globalization.NumberStyles.HexNumber);
            }
            StatusChanged("NUS Download Finished.");
        }
        public static void DownloadTitle(NintendoTitle currentTitle)
        {
            bool success = true;

            StatusChanged("Starting NUS Download. Please be patient!");
            StatusChanged("Prerequisites: (0/2)");
            // Download TMD before the rest...
            success = DownloadNUSFile(currentTitle, currentTitle.TMDFull);
            if (success)
            {
                StatusChanged("Prerequisites: (1/2)");
                // Download CETK before the rest...
                success = DownloadNUSFile(currentTitle, "cetk");
            }

            // Gather information...
            string[] tmdcontents = currentTitle.GetContentNames();
            string[] tmdsizes    = currentTitle.GetContentSizes();
            string[] tmdhashes   = currentTitle.GetContentHashes();

            float totalcontentsize       = 0;
            float currentcontentlocation = 0;

            for (int i = 0; i < tmdsizes.Length; i++)
            {
                totalcontentsize += int.Parse(tmdsizes[i], System.Globalization.NumberStyles.HexNumber);
            }
            bool continueTrans = true;

            for (int i = 0; i < tmdcontents.Length && continueTrans; i++)
            {
                continueTrans           = DownloadNUSFile(currentTitle, tmdcontents[i]);
                currentcontentlocation += int.Parse(tmdsizes[i], System.Globalization.NumberStyles.HexNumber);
            }
            StatusChanged("NUS Download Finished.");
        }
        public static void WriteWad(NintendoTitle currentTitle, string directoryName)
        {
            byte[] cetkbuf = currentTitle.cetk;
            string[] contentnames = currentTitle.GetContentNames();

            // Create tmd file holder
            byte[] tmdbuf = currentTitle.TMD;

            // Create wad file
            if (!Directory.Exists(directoryName + "\\" + currentTitle.TitleId + @"\"))
                Directory.CreateDirectory(directoryName + "\\" + currentTitle.TitleId);
            FileStream wadfs = new FileStream(directoryName + "\\" + currentTitle.TitleId
                + @"\" + currentTitle.TitleId + ".wad", FileMode.Create);

            // Add wad stuffs
            WADHeader wad = new WADHeader();
            wad.HeaderSize = 0x20;
            wad.WadType = 0x49730000;
            wad.CertChainSize = 0xA00;

            // TMDSize is length of buffer.
            wad.TMDSize = tmdbuf.Length;
            // TicketSize is length of cetkbuf.
            wad.TicketSize = cetkbuf.Length;

            // Write cert[] to 0x40.
            wadfs.Seek(0x40, SeekOrigin.Begin);
            wadfs.Write(cert, 0, cert.Length);

            WriteStatus("Cert wrote at 0x40");

            // Need 64 byte boundary...
            wadfs.Seek(2624, SeekOrigin.Begin);

            // Cert is 2560
            // Write ticket at this point...
            wad.TicketSize = 0x2A4;
            wadfs.Write(cetkbuf, 0, wad.TicketSize);

            WriteStatus("Ticket wrote at " + (wadfs.Length - 0x2A4));

            // Need 64 byte boundary...
            wadfs.Seek(ByteBoundary(Convert.ToInt32(wadfs.Length)), SeekOrigin.Begin);

            // Write TMD at this point...
            wadfs.Write(tmdbuf, 0, 484 + ((currentTitle.Contents.Count - 2) * 36));

            WriteStatus("TMD wrote at " + (wadfs.Length - (484 + ((currentTitle.Contents.Count - 2) * 36))));

            // Preliminary data size of wad file.
            wad.DataSize = 0;

            // Loop n Add contents
            for (int i = 0; i < currentTitle.Contents.Count - 2; i++)
            {
                // Need 64 byte boundary...
                wadfs.Seek(ByteBoundary(Convert.ToInt32(wadfs.Length)), SeekOrigin.Begin);
                byte[] contbuf = currentTitle.Contents[contentnames[i]];
                wadfs.Write(contbuf, 0, contbuf.Length);
                WriteStatus(contentnames[i] + " wrote at " + (wadfs.Length - contbuf.Length));
                wad.DataSize += contbuf.Length;
            }

            wadfs.Seek(0, SeekOrigin.Begin);

            // Write initial part of header
            byte[] start = new byte[8] { 0x00, 0x00, 0x00, 0x20, 0x49, 0x73, 0x00, 0x00 };
            wadfs.Write(start, 0, start.Length);

            //WriteStatus("Initial header wrote");

            // Write CertChainLength
            wadfs.Seek(0x08, SeekOrigin.Begin);
            byte[] chainsize = InttoByteArray(wad.CertChainSize);
            wadfs.Write(chainsize, 0, 4);

            // Write res
            byte[] reserved = new byte[4] { 0x00, 0x00, 0x00, 0x00 };
            wadfs.Seek(0x0C, SeekOrigin.Begin);
            wadfs.Write(reserved, 0, 4);

            // Write ticketsize
            byte[] ticketsize = new byte[4] { 0x00, 0x00, 0x02, 0xA4 };
            wadfs.Seek(0x10, SeekOrigin.Begin);
            wadfs.Write(ticketsize, 0, 4);

            // Write tmdsize
            int strippedtmd = 484 + (currentTitle.Contents.Count - 2 * 36);
            byte[] tmdsize = InttoByteArray(strippedtmd);
            wadfs.Seek(0x14, SeekOrigin.Begin);
            wadfs.Write(tmdsize, 0, 4);

            // Write data size
            wadfs.Seek(0x18, SeekOrigin.Begin);
            byte[] datasize = InttoByteArray(wad.DataSize);
            wadfs.Write(datasize, 0, 4);

            WriteStatus("WAD Created: " + currentTitle.TitleId + ".wad");
            wadfs.Close();
        }
示例#4
0
        public static void WriteWad(NintendoTitle currentTitle, string directoryName)
        {
            byte[]   cetkbuf      = currentTitle.cetk;
            string[] contentnames = currentTitle.GetContentNames();

            // Create tmd file holder
            byte[] tmdbuf = currentTitle.TMD;

            // Create wad file
            if (!Directory.Exists(directoryName + "\\" + currentTitle.TitleId + @"\"))
            {
                Directory.CreateDirectory(directoryName + "\\" + currentTitle.TitleId);
            }
            FileStream wadfs = new FileStream(directoryName + "\\" + currentTitle.TitleId
                                              + @"\" + currentTitle.TitleId + ".wad", FileMode.Create);

            // Add wad stuffs
            WADHeader wad = new WADHeader();

            wad.HeaderSize    = 0x20;
            wad.WadType       = 0x49730000;
            wad.CertChainSize = 0xA00;

            // TMDSize is length of buffer.
            wad.TMDSize = tmdbuf.Length;
            // TicketSize is length of cetkbuf.
            wad.TicketSize = cetkbuf.Length;

            // Write cert[] to 0x40.
            wadfs.Seek(0x40, SeekOrigin.Begin);
            wadfs.Write(cert, 0, cert.Length);

            WriteStatus("Cert wrote at 0x40");

            // Need 64 byte boundary...
            wadfs.Seek(2624, SeekOrigin.Begin);

            // Cert is 2560
            // Write ticket at this point...
            wad.TicketSize = 0x2A4;
            wadfs.Write(cetkbuf, 0, wad.TicketSize);

            WriteStatus("Ticket wrote at " + (wadfs.Length - 0x2A4));

            // Need 64 byte boundary...
            wadfs.Seek(ByteBoundary(Convert.ToInt32(wadfs.Length)), SeekOrigin.Begin);

            // Write TMD at this point...
            wadfs.Write(tmdbuf, 0, 484 + ((currentTitle.Contents.Count - 2) * 36));

            WriteStatus("TMD wrote at " + (wadfs.Length - (484 + ((currentTitle.Contents.Count - 2) * 36))));

            // Preliminary data size of wad file.
            wad.DataSize = 0;

            // Loop n Add contents
            for (int i = 0; i < currentTitle.Contents.Count - 2; i++)
            {
                // Need 64 byte boundary...
                wadfs.Seek(ByteBoundary(Convert.ToInt32(wadfs.Length)), SeekOrigin.Begin);
                byte[] contbuf = currentTitle.Contents[contentnames[i]];
                wadfs.Write(contbuf, 0, contbuf.Length);
                WriteStatus(contentnames[i] + " wrote at " + (wadfs.Length - contbuf.Length));
                wad.DataSize += contbuf.Length;
            }

            wadfs.Seek(0, SeekOrigin.Begin);

            // Write initial part of header
            byte[] start = new byte[8] {
                0x00, 0x00, 0x00, 0x20, 0x49, 0x73, 0x00, 0x00
            };
            wadfs.Write(start, 0, start.Length);

            //WriteStatus("Initial header wrote");

            // Write CertChainLength
            wadfs.Seek(0x08, SeekOrigin.Begin);
            byte[] chainsize = InttoByteArray(wad.CertChainSize);
            wadfs.Write(chainsize, 0, 4);

            // Write res
            byte[] reserved = new byte[4] {
                0x00, 0x00, 0x00, 0x00
            };
            wadfs.Seek(0x0C, SeekOrigin.Begin);
            wadfs.Write(reserved, 0, 4);

            // Write ticketsize
            byte[] ticketsize = new byte[4] {
                0x00, 0x00, 0x02, 0xA4
            };
            wadfs.Seek(0x10, SeekOrigin.Begin);
            wadfs.Write(ticketsize, 0, 4);

            // Write tmdsize
            int strippedtmd = 484 + (currentTitle.Contents.Count - 2 * 36);

            byte[] tmdsize = InttoByteArray(strippedtmd);
            wadfs.Seek(0x14, SeekOrigin.Begin);
            wadfs.Write(tmdsize, 0, 4);

            // Write data size
            wadfs.Seek(0x18, SeekOrigin.Begin);
            byte[] datasize = InttoByteArray(wad.DataSize);
            wadfs.Write(datasize, 0, 4);

            WriteStatus("WAD Created: " + currentTitle.TitleId + ".wad");
            wadfs.Close();
        }