public NintendoContentMetaXmlSource(NintendoContentMetaBase contentMetaBase, ISource metaHashSource, long metaSize)
        {
            this.m_contentMetaBase = contentMetaBase;
            this.m_MetaHashSource  = metaHashSource;
            NintendoContentMetaReader contentMetaReader = new NintendoContentMetaReader(contentMetaBase.GetBytes());
            ContentMetaModel          contentMetaModel1 = this.PrepareContentMetaModel(contentMetaBase.GetContentMetaDescryptor());

            contentMetaModel1.Type = contentMetaReader.GetType();
            contentMetaModel1.SetUInt64Id(contentMetaReader.GetId());
            contentMetaModel1.Version       = contentMetaReader.GetVersion();
            contentMetaModel1.AttributeList = ((ContentMetaAttribute)contentMetaReader.GetAttributes()).ToStringList();
            contentMetaModel1.RequiredDownloadSystemVersion = contentMetaReader.GetRequiredDownloadSystemVersion();
            byte[] bytes1 = new byte[NintendoContentMeta.GetDigestSize()];
            contentMetaModel1.SetDigestBytes(bytes1);
            List <NintendoContentInfo> contentInfoList = contentMetaReader.GetContentInfoList();

            if (contentInfoList.Count > 0)
            {
                contentMetaModel1.ContentList = new List <ContentModel>();
                foreach (NintendoContentInfo nintendoContentInfo in contentInfoList)
                {
                    ContentModel contentModel = new ContentModel();
                    contentModel.Type = nintendoContentInfo.Type;
                    contentModel.Size = nintendoContentInfo.Size;
                    byte[] bytes2 = new byte[NintendoContentMeta.GetContentInfoHashSize()];
                    contentModel.SetIdBytes(bytes2);
                    contentModel.SetHashBytes(bytes2);
                    contentMetaModel1.ContentList.Add(contentModel);
                }
            }
            contentMetaModel1.ContentList = contentMetaModel1.ContentList ?? new List <ContentModel>();
            this.m_MetaModel = new ContentModel();
            contentMetaModel1.ContentList.Add(this.m_MetaModel);
            this.m_MetaModel.Type = "Meta";
            this.m_MetaModel.Size = metaSize;
            byte[] bytes3 = new byte[NintendoContentMeta.GetContentInfoHashSize()];
            this.m_MetaModel.SetIdBytes(bytes3);
            this.m_MetaModel.SetHashBytes(bytes3);
            List <NintendoContentMetaInfo> contentMetaInfoList = contentMetaReader.GetContentMetaInfoList();

            if (contentMetaInfoList.Count > 0)
            {
                contentMetaModel1.ContentMetaList = new List <ContentMetaModel>();
                foreach (NintendoContentMetaInfo nintendoContentMetaInfo in contentMetaInfoList)
                {
                    ContentMetaModel contentMetaModel2 = new ContentMetaModel();
                    contentMetaModel2.Type = nintendoContentMetaInfo.Type;
                    contentMetaModel2.SetUInt64Id(nintendoContentMetaInfo.Id);
                    contentMetaModel2.Version       = nintendoContentMetaInfo.Version;
                    contentMetaModel2.AttributeList = ((ContentMetaAttribute)nintendoContentMetaInfo.Attributes).ToStringList();
                    contentMetaModel1.ContentMetaList.Add(contentMetaModel2);
                }
            }
            this.m_model = contentMetaModel1;
            this.Size    = (long)this.GetBytes().Length;
        }
        private ContentMetaModel PrepareContentMetaModel(ContentMetaDescriptor descriptor)
        {
            string           type = descriptor.Type;
            ContentMetaModel contentMetaModel1;

            if (!(type == "Application"))
            {
                if (!(type == "Patch"))
                {
                    if (type == "AddOnContent")
                    {
                        NintendoAddOnContentExtendedHeader extendedHeader    = (NintendoAddOnContentExtendedHeader)descriptor.ExtendedHeader;
                        AddOnContentContentMetaModel       contentMetaModel2 = new AddOnContentContentMetaModel();
                        contentMetaModel2.RequiredApplicationVersion = extendedHeader.RequiredApplicationVersion;
                        contentMetaModel2.SetUInt64ApplicationId(extendedHeader.ApplicationId);
                        contentMetaModel2.Tag   = extendedHeader.Tag;
                        contentMetaModel2.Index = this.GetAddOnContentIndex(descriptor, extendedHeader);
                        contentMetaModel1       = (ContentMetaModel)contentMetaModel2;
                        this.m_ModelType        = typeof(AddOnContentContentMetaModel);
                    }
                    else
                    {
                        contentMetaModel1 = new ContentMetaModel();
                    }
                }
                else
                {
                    NintendoPatchExtendedHeader extendedHeader    = (NintendoPatchExtendedHeader)descriptor.ExtendedHeader;
                    PatchContentMetaModel       contentMetaModel2 = new PatchContentMetaModel();
                    contentMetaModel2.RequiredSystemVersion = extendedHeader.RequiredSystemVersion;
                    contentMetaModel2.SetUInt64ApplicationId(extendedHeader.ApplicationId);
                    contentMetaModel1 = (ContentMetaModel)contentMetaModel2;
                    this.m_ModelType  = typeof(PatchContentMetaModel);
                }
            }
            else
            {
                NintendoApplicationExtendedHeader extendedHeader    = (NintendoApplicationExtendedHeader)descriptor.ExtendedHeader;
                ApplicationContentMetaModel       contentMetaModel2 = new ApplicationContentMetaModel();
                contentMetaModel2.RequiredSystemVersion = extendedHeader.RequiredSystemVersion;
                contentMetaModel2.SetUInt64PatchId(extendedHeader.PatchId);
                contentMetaModel1 = (ContentMetaModel)contentMetaModel2;
                this.m_ModelType  = typeof(ApplicationContentMetaModel);
            }
            return(contentMetaModel1);
        }
Ejemplo n.º 3
0
 public ContentMetaInfo(byte[] data, ContentMetaModel model)
 {
     this.Data  = data;
     this.Model = model;
 }
        private static NintendoSubmissionPackageFileSystemInfo GetNspInfo(NintendoSubmissionPackageReader nspReader, KeyConfiguration keyConfig, ArchiveReconstructionUtils.GetContentInfoDelegate getContentInfoImpl, ArchiveReconstructionUtils.GetContentMetaInfoDelegate getContentMetaInfoImpl)
        {
            NintendoSubmissionPackageFileSystemInfo packageFileSystemInfo = new NintendoSubmissionPackageFileSystemInfo();

            packageFileSystemInfo.Version = (byte)0;
            foreach (Tuple <string, long> tuple in nspReader.ListFileInfo())
            {
                string fileName = tuple.Item1;
                long   fileSize = tuple.Item2;
                if (fileName.EndsWith(".cnmt.xml"))
                {
                    ContentMetaModel model = ArchiveReconstructionUtils.ReadXml <ContentMetaModel>(nspReader, fileName, fileSize);
                    string           type  = model.Type;
                    if (!(type == "Application"))
                    {
                        if (!(type == "Patch"))
                        {
                            if (type == "AddOnContent")
                            {
                                model = (ContentMetaModel)ArchiveReconstructionUtils.ReadXml <AddOnContentContentMetaModel>(nspReader, fileName, fileSize);
                            }
                        }
                        else
                        {
                            model = (ContentMetaModel)ArchiveReconstructionUtils.ReadXml <PatchContentMetaModel>(nspReader, fileName, fileSize);
                        }
                    }
                    else
                    {
                        model = (ContentMetaModel)ArchiveReconstructionUtils.ReadXml <ApplicationContentMetaModel>(nspReader, fileName, fileSize);
                    }
                    NintendoSubmissionPackageFileSystemInfo.EntryInfo entry = new NintendoSubmissionPackageFileSystemInfo.EntryInfo();
                    entry.Contents = new List <NintendoSubmissionPackageFileSystemInfo.ContentInfo>();
                    foreach (ContentModel content in model.ContentList)
                    {
                        if (!(content.Type == "Meta"))
                        {
                            NintendoSubmissionPackageFileSystemInfo.ContentInfo contentInfo = getContentInfoImpl(content);
                            entry.Contents.Add(contentInfo);
                        }
                    }
                    string contentMetaFileName = Path.GetFileNameWithoutExtension(fileName) + ".nca";
                    getContentMetaInfoImpl(ref entry, contentMetaFileName, model);
                    List <NintendoSubmissionPackageExtraData> list = nspReader.ListFileInfo().FindAll((Predicate <Tuple <string, long> >)(x =>
                    {
                        if (x.Item1.StartsWith(fileName.Replace(".cnmt.xml", "")))
                        {
                            return(x.Item1.EndsWith(".jpg"));
                        }
                        return(false);
                    })).Select <Tuple <string, long>, NintendoSubmissionPackageExtraData>((Func <Tuple <string, long>, NintendoSubmissionPackageExtraData>)(x =>
                    {
                        byte[] buffer = nspReader.ReadFile(x.Item1, 0L, x.Item2);
                        return(new NintendoSubmissionPackageExtraData(x.Item1, (ISource) new MemorySource(buffer, 0, buffer.Length)));
                    })).ToList <NintendoSubmissionPackageExtraData>();
                    entry.ExtraData = list;
                    packageFileSystemInfo.Entries.Add(entry);
                }
                if (fileName == "cardspec.xml")
                {
                    CardSpecModel cardSpecModel = ArchiveReconstructionUtils.ReadXml <CardSpecModel>(nspReader, fileName, fileSize);
                    packageFileSystemInfo.CardSize      = Convert.ToInt32(cardSpecModel.Size, 10);
                    packageFileSystemInfo.CardClockRate = Convert.ToInt32(cardSpecModel.ClockRate, 10);
                }
            }
            return(packageFileSystemInfo);
        }
        private static void GetCommonContentMetaInfo(ref NintendoSubmissionPackageFileSystemInfo.EntryInfo entry, string contentMetaFileName, ContentMetaModel model, NintendoSubmissionPackageReader nspReader, KeyConfiguration keyConfig)
        {
            IFileSystemArchiveReader systemArchiveReader = nspReader.OpenNintendoContentArchiveReader(contentMetaFileName, keyConfig.GetKeyAreaEncryptionKeys()).OpenFileSystemArchiveReader(0);
            Tuple <string, long>     tuple = systemArchiveReader.ListFileInfo().Single <Tuple <string, long> >();

            entry.ContentMetaInfo = new NintendoSubmissionPackageFileSystemInfo.ContentMetaInfo(systemArchiveReader.ReadFile(tuple.Item1, 0L, tuple.Item2), model);
            NintendoContentMetaReader contentMetaReader = new NintendoContentMetaReader(entry.ContentMetaInfo.Data);

            entry.MetaType = contentMetaReader.GetType();
        }
Ejemplo n.º 6
0
 public NintendoContentMetaBase(List <Tuple <ISource, NintendoContentInfo> > contentSourceList, byte[] buffer, ContentMetaModel model, bool isProdEncryption)
     : this(contentSourceList, NintendoContentMetaBase.ExtractContentMetaDescriptor(buffer, model, contentSourceList.Select <Tuple <ISource, NintendoContentInfo>, NintendoContentInfo>((Func <Tuple <ISource, NintendoContentInfo>, NintendoContentInfo>)(tuple => tuple.Item2)).ToList <NintendoContentInfo>()), isProdEncryption)
 {
 }
Ejemplo n.º 7
0
        private static ContentMetaDescriptor ExtractContentMetaDescriptor(string type, string metaPath, List <NintendoContentInfo> contentInfoList)
        {
            ulong applicationId = 0;
            byte  attributes    = 0;
            NintendoExtendedHeader         extendedHeader      = (NintendoExtendedHeader)null;
            List <NintendoContentMetaInfo> contentMetaInfoList = new List <NintendoContentMetaInfo>();
            uint  num1 = NintendoContentMetaBase.GetDefaultDownloadSystemVersion();
            ulong id;
            uint  version;

            if (type.Equals("SystemUpdate"))
            {
                ContentMetaModel contentMeta1 = NintendoContentMetaBase.GetDeserializedModel <SystemUpdateModel>(metaPath, false).ContentMeta;
                if (contentMeta1.Type != "SystemUpdate")
                {
                    throw new ArgumentException("The content meta type is not SystemUpdate.");
                }
                id      = contentMeta1.GetUInt64Id();
                version = contentMeta1.Version;
                foreach (ContentMetaModel contentMeta2 in contentMeta1.ContentMetaList)
                {
                    contentMetaInfoList.Add(new NintendoContentMetaInfo(contentMeta2.Type, contentMeta2.GetUInt64Id(), contentMeta2.Version, (byte)ContentMetaAttributeExtension.FromStringList((IEnumerable <string>)contentMeta2.AttributeList)));
                }
            }
            else
            {
                DotMetaReader dotMetaReader = new DotMetaReader(metaPath);
                id         = dotMetaReader.GetContentMetaId();
                version    = dotMetaReader.GetVersion();
                attributes = dotMetaReader.GetContentMetaAttributes();
                num1       = dotMetaReader.GetRequiredDownloadSystemVersion().GetValueOrDefault(num1);
                if (!(type == "Application"))
                {
                    if (!(type == "AddOnContent"))
                    {
                        if (type == "Patch")
                        {
                            applicationId = dotMetaReader.GetApplicationId();
                            uint?requiredSystemVersion1 = dotMetaReader.GetRequiredSystemVersion();
                            uint requiredSystemVersion2 = requiredSystemVersion1.HasValue ? requiredSystemVersion1.Value : NintendoContentMeta.GetRequiredSystemVersion();
                            extendedHeader = (NintendoExtendedHeader) new NintendoPatchExtendedHeader(dotMetaReader.GetApplicationId(), requiredSystemVersion2);
                            version        = NintendoContentMetaBase.ShiftVersion(version, "Patch");
                        }
                    }
                    else
                    {
                        applicationId  = dotMetaReader.GetApplicationId();
                        extendedHeader = (NintendoExtendedHeader) new NintendoAddOnContentExtendedHeader(dotMetaReader.GetApplicationId(), dotMetaReader.GetRequiredApplicationVersion(), dotMetaReader.GetAddOnContentTag());
                        version        = NintendoContentMetaBase.ShiftVersion(version, "AddOnContent");
                    }
                }
                else
                {
                    long num2 = (long)id + 2048L;
                    uint?requiredSystemVersion = dotMetaReader.GetRequiredSystemVersion();
                    int  num3 = requiredSystemVersion.HasValue ? (int)requiredSystemVersion.Value : (int)NintendoContentMeta.GetRequiredSystemVersion();
                    extendedHeader = (NintendoExtendedHeader) new NintendoApplicationExtendedHeader((ulong)num2, (uint)num3);
                    version        = NintendoContentMetaBase.ShiftVersion(version, "Application");
                }
            }
            return(new ContentMetaDescriptor(type, id, version, attributes, applicationId, num1, contentInfoList, contentMetaInfoList, extendedHeader, new byte[NintendoContentMeta.GetDigestSize()]));
        }
Ejemplo n.º 8
0
        private static ContentMetaDescriptor ExtractContentMetaDescriptor(byte[] buffer, ContentMetaModel model, List <NintendoContentInfo> contentInfoList)
        {
            NintendoContentMetaReader contentMetaReader = new NintendoContentMetaReader(buffer);
            NintendoExtendedHeader    extendedHeader    = contentMetaReader.GetExtendedHeader();

            if (contentMetaReader.GetType() == "AddOnContent")
            {
                (extendedHeader as NintendoAddOnContentExtendedHeader).Tag = (model as AddOnContentContentMetaModel).Tag;
            }
            return(new ContentMetaDescriptor(contentMetaReader.GetType(), contentMetaReader.GetId(), contentMetaReader.GetVersion(), contentMetaReader.GetAttributes(), contentMetaReader.GetApplicationId(), contentMetaReader.GetRequiredDownloadSystemVersion(), contentInfoList, contentMetaReader.GetContentMetaInfoList(), extendedHeader, contentMetaReader.GetDigest()));
        }