コード例 #1
0
        internal static NCSD setNCSD(NCCH Content, bool Card2
                                     )
        {
            NCSD Rom = new NCSD {
                NCCH_Array = new List <NCCH>()
            };

            Rom.NCCH_Array.Add(Content);
            Console.WriteLine("Building NCSD Header...");
            Rom.Card2  = Card2;
            Rom.header = new NCSD.Header {
                Signature = new byte[0x100], Magic = 0x4453434E
            };
            ulong Length = 0x80 * 0x100000;                                    // 128 MB

            while (Length <= Content.header.Size * MEDIA_UNIT_SIZE + 0x400000) //Extra 4 MB for potential save data
            {
                Length *= 2;
            }
            Rom.header.MediaSize       = (uint)(Length / MEDIA_UNIT_SIZE);
            Rom.header.TitleId         = Content.exheader.TitleID;
            Rom.header.OffsetSizeTable = new NCSD.NCCH_Meta[8];
            ulong OSOfs = 0x4000;

            for (int i = 0; i < Rom.header.OffsetSizeTable.Length; i++)
            {
                NCSD.NCCH_Meta ncchm = new NCSD.NCCH_Meta();
                if (i < Rom.NCCH_Array.Count)
                {
                    ncchm.Offset = (uint)(OSOfs / MEDIA_UNIT_SIZE);
                    ncchm.Size   = Rom.NCCH_Array[i].header.Size;
                }
                else
                {
                    ncchm.Offset = 0;
                    ncchm.Size   = 0;
                }
                Rom.header.OffsetSizeTable[i] = ncchm;
                OSOfs += ncchm.Size * MEDIA_UNIT_SIZE;
            }
            Rom.header.flags       = new byte[0x8];
            Rom.header.flags[0]    = 0;                         // 0-255 seconds of waiting for save writing.
            Rom.header.flags[3]    = (byte)(Rom.Card2 ? 2 : 1); // Media Card Device: 1 = NOR Flash, 2 = None, 3 = BT
            Rom.header.flags[4]    = 1;                         // Media Platform Index: 1 = CTR
            Rom.header.flags[5]    = (byte)(Rom.Card2 ? 2 : 1); // Media Type Index: 0 = Inner Device, 1 = Card1, 2 = Card2, 3 = Extended Device
            Rom.header.flags[6]    = 0;                         // Media Unit Size. Same as NCCH.
            Rom.header.flags[7]    = 0;                         // Old Media Card Device.
            Rom.header.NCCHIdTable = new ulong[8];
            for (int i = 0; i < Rom.NCCH_Array.Count; i++)
            {
                Rom.header.NCCHIdTable[i] = Rom.NCCH_Array[i].header.TitleId;
            }
            Rom.cardinfoheader = new NCSD.CardInfoHeader
            {
                WritableAddress = (uint)(Rom.GetWritableAddress()),
                CardInfoBitmask = 0,
                CIN             = new NCSD.CardInfoHeader.CardInfoNotes
                {
                    Reserved0        = new byte[0xF8],
                    MediaSizeUsed    = OSOfs,
                    Reserved1        = 0,
                    Unknown          = 0,
                    Reserved2        = new byte[0xC],
                    CVerTitleId      = 0,
                    CVerTitleVersion = 0,
                    Reserved3        = new byte[0xCD6]
                },
                NCCH0TitleId = Rom.NCCH_Array[0].header.TitleId,
                Reserved0    = 0,
                InitialData  = new byte[0x30]
            };
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

            byte[] randbuffer = new byte[0x2C];
            rng.GetBytes(randbuffer);
            Array.Copy(randbuffer, Rom.cardinfoheader.InitialData, randbuffer.Length);
            Rom.cardinfoheader.Reserved1   = new byte[0xC0];
            Rom.cardinfoheader.NCCH0Header = new byte[0x100];
            Array.Copy(Rom.NCCH_Array[0].header.Data, 0x100, Rom.cardinfoheader.NCCH0Header, 0, 0x100);

            Rom.BuildHeader();

            //NCSD is Initialized
            return(Rom);
        }
コード例 #2
0
ファイル: CTR.cs プロジェクト: typhlosion418/pk3DS
        internal static NCSD setNCSD(NCCH NCCH, bool Card2,
                                     ProgressBar PB_Show = null, RichTextBox TB_Progress = null)
        {
            PB_Show     = PB_Show ?? new ProgressBar();
            TB_Progress = TB_Progress ?? new RichTextBox();
            updateTB(TB_Progress, "Building NCSD Header...");
            NCSD NCSD = new NCSD
            {
                NCCH_Array = new List <NCCH> {
                    NCCH
                },
                Card2  = Card2,
                header = new NCSD.Header {
                    Signature = new byte[0x100], Magic = 0x4453434E
                }
            };
            ulong Length = 0x80 * 0x100000;                                 // 128 MB

            while (Length <= NCCH.header.Size * MEDIA_UNIT_SIZE + 0x400000) //Extra 4 MB for potential save data
            {
                Length *= 2;
            }
            NCSD.header.MediaSize       = (uint)(Length / MEDIA_UNIT_SIZE);
            NCSD.header.TitleId         = NCCH.exheader.TitleID;
            NCSD.header.OffsetSizeTable = new NCSD.NCCH_Meta[8];
            ulong OSOfs = 0x4000;

            for (int i = 0; i < NCSD.header.OffsetSizeTable.Length; i++)
            {
                NCSD.NCCH_Meta ncchm = new NCSD.NCCH_Meta();
                if (i < NCSD.NCCH_Array.Count)
                {
                    ncchm.Offset = (uint)(OSOfs / MEDIA_UNIT_SIZE);
                    ncchm.Size   = NCSD.NCCH_Array[i].header.Size;
                }
                else
                {
                    ncchm.Offset = 0;
                    ncchm.Size   = 0;
                }
                NCSD.header.OffsetSizeTable[i] = ncchm;
                OSOfs += ncchm.Size * MEDIA_UNIT_SIZE;
            }
            NCSD.header.flags       = new byte[0x8];
            NCSD.header.flags[0]    = 0;                          // 0-255 seconds of waiting for save writing.
            NCSD.header.flags[3]    = (byte)(NCSD.Card2 ? 2 : 1); // Media Card Device: 1 = NOR Flash, 2 = None, 3 = BT
            NCSD.header.flags[4]    = 1;                          // Media Platform Index: 1 = CTR
            NCSD.header.flags[5]    = (byte)(NCSD.Card2 ? 2 : 1); // Media Type Index: 0 = Inner Device, 1 = Card1, 2 = Card2, 3 = Extended Device
            NCSD.header.flags[6]    = 0;                          // Media Unit Size. Same as NCCH.
            NCSD.header.flags[7]    = 0;                          // Old Media Card Device.
            NCSD.header.NCCHIdTable = new ulong[8];
            for (int i = 0; i < NCSD.NCCH_Array.Count; i++)
            {
                NCSD.header.NCCHIdTable[i] = NCSD.NCCH_Array[i].header.TitleId;
            }
            NCSD.cardinfoheader = new NCSD.CardInfoHeader
            {
                WritableAddress = (uint)NCSD.GetWritableAddress(),
                CardInfoBitmask = 0,
                CIN             = new NCSD.CardInfoHeader.CardInfoNotes
                {
                    Reserved0        = new byte[0xF8],
                    MediaSizeUsed    = OSOfs,
                    Reserved1        = 0,
                    Unknown          = 0,
                    Reserved2        = new byte[0xC],
                    CVerTitleId      = 0,
                    CVerTitleVersion = 0,
                    Reserved3        = new byte[0xCD6]
                },
                NCCH0TitleId = NCSD.NCCH_Array[0].header.TitleId,
                Reserved0    = 0,
                InitialData  = new byte[0x30]
            };
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

            byte[] randbuffer = new byte[0x2C];
            rng.GetBytes(randbuffer);
            Array.Copy(randbuffer, NCSD.cardinfoheader.InitialData, randbuffer.Length);
            NCSD.cardinfoheader.Reserved1   = new byte[0xC0];
            NCSD.cardinfoheader.NCCH0Header = new byte[0x100];
            Array.Copy(NCSD.NCCH_Array[0].header.Data, 0x100, NCSD.cardinfoheader.NCCH0Header, 0, 0x100);

            NCSD.BuildHeader();

            //NCSD is Initialized
            return(NCSD);
        }
コード例 #3
0
ファイル: CTR.cs プロジェクト: FullLifeGames/pk3DS
        internal static NCSD setNCSD(NCCH NCCH, bool Card2,
            ProgressBar PB_Show = null, RichTextBox TB_Progress = null)
        {
            PB_Show = PB_Show ?? new ProgressBar();
            TB_Progress = TB_Progress ?? new RichTextBox();
            updateTB(TB_Progress, "Building NCSD Header...");
            NCSD NCSD = new NCSD
            {
                NCCH_Array = new List<NCCH> {NCCH},
                Card2 = Card2,
                header = new NCSD.Header {Signature = new byte[0x100], Magic = 0x4453434E}
            };
            ulong Length = 0x80 * 0x100000; // 128 MB
            while (Length <= NCCH.header.Size * MEDIA_UNIT_SIZE + 0x400000) //Extra 4 MB for potential save data
            {
                Length *= 2;
            }
            NCSD.header.MediaSize = (uint)(Length / MEDIA_UNIT_SIZE);
            NCSD.header.TitleId = NCCH.exheader.TitleID;
            NCSD.header.OffsetSizeTable = new NCSD.NCCH_Meta[8];
            ulong OSOfs = 0x4000;
            for (int i = 0; i < NCSD.header.OffsetSizeTable.Length; i++)
            {
                NCSD.NCCH_Meta ncchm = new NCSD.NCCH_Meta();
                if (i < NCSD.NCCH_Array.Count)
                {
                    ncchm.Offset = (uint)(OSOfs / MEDIA_UNIT_SIZE);
                    ncchm.Size = NCSD.NCCH_Array[i].header.Size;
                }
                else
                {
                    ncchm.Offset = 0;
                    ncchm.Size = 0;
                }
                NCSD.header.OffsetSizeTable[i] = ncchm;
                OSOfs += ncchm.Size * MEDIA_UNIT_SIZE;
            }
            NCSD.header.flags = new byte[0x8];
            NCSD.header.flags[0] = 0; // 0-255 seconds of waiting for save writing.
            NCSD.header.flags[3] = (byte)(NCSD.Card2 ? 2 : 1); // Media Card Device: 1 = NOR Flash, 2 = None, 3 = BT
            NCSD.header.flags[4] = 1; // Media Platform Index: 1 = CTR
            NCSD.header.flags[5] = (byte)(NCSD.Card2 ? 2 : 1); // Media Type Index: 0 = Inner Device, 1 = Card1, 2 = Card2, 3 = Extended Device
            NCSD.header.flags[6] = 0; // Media Unit Size. Same as NCCH.
            NCSD.header.flags[7] = 0; // Old Media Card Device.
            NCSD.header.NCCHIdTable = new ulong[8];
            for (int i = 0; i < NCSD.NCCH_Array.Count; i++)
            {
                NCSD.header.NCCHIdTable[i] = NCSD.NCCH_Array[i].header.TitleId;
            }
            NCSD.cardinfoheader = new NCSD.CardInfoHeader
            {
                WritableAddress = (uint)NCSD.GetWritableAddress(),
                CardInfoBitmask = 0,
                CIN = new NCSD.CardInfoHeader.CardInfoNotes
                {
                    Reserved0 = new byte[0xF8],
                    MediaSizeUsed = OSOfs,
                    Reserved1 = 0,
                    Unknown = 0,
                    Reserved2 = new byte[0xC],
                    CVerTitleId = 0,
                    CVerTitleVersion = 0,
                    Reserved3 = new byte[0xCD6]
                },
                NCCH0TitleId = NCSD.NCCH_Array[0].header.TitleId,
                Reserved0 = 0,
                InitialData = new byte[0x30]
            };
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            byte[] randbuffer = new byte[0x2C];
            rng.GetBytes(randbuffer);
            Array.Copy(randbuffer, NCSD.cardinfoheader.InitialData, randbuffer.Length);
            NCSD.cardinfoheader.Reserved1 = new byte[0xC0];
            NCSD.cardinfoheader.NCCH0Header = new byte[0x100];
            Array.Copy(NCSD.NCCH_Array[0].header.Data, 0x100, NCSD.cardinfoheader.NCCH0Header, 0, 0x100);

            NCSD.BuildHeader();

            //NCSD is Initialized
            return NCSD;
        }