Exemple #1
0
        public bool HasNca(string ncaId, StorageId storageId)
        {
            lock (_lock)
            {
                if (_contentDictionary.ContainsValue(ncaId))
                {
                    var  content = _contentDictionary.FirstOrDefault(x => x.Value == ncaId);
                    long titleId = (long)content.Key.Item1;

                    NcaContentType contentType = content.Key.type;
                    StorageId      storage     = GetInstalledStorage(titleId, contentType, storageId);

                    return(storage == storageId);
                }
            }

            return(false);
        }
Exemple #2
0
        public NcaFile FindNca(string titleid, NcaContentType type)
        {
            string  titleID = titleid.ToUpper();
            NcaFile file    = files.Find(x => x.titleId == titleID && x.header.ContentType == type);

            if (file == null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"Could not find specified Program Id ({titleID})");
                if (!Config.noExfat)
                {
                    Console.WriteLine("Consider trying out the '--no-exfat' option");
                }
                Console.WriteLine("Is your firmware dump valid?");
                Console.ResetColor();
                Environment.Exit(0);
            }
            return(file);
        }
Exemple #3
0
        public static void MatchupBaseNca(this IEnumerable <SwitchFsNca> ncas)
        {
            PseudoFileSystem ps = ncas.MakeFs();
            SwitchFs         fs = SwitchFs.OpenNcaDirectory(HACGUIKeyset.Keyset, ps);

            foreach (KeyValuePair <ulong, LibHac.Application> kv in fs.Applications)
            {
                ulong tid = kv.Key;
                LibHac.Application app = kv.Value;

                if (app.Patch != null && app.Main != null)
                {
                    foreach (SwitchFsNca nca in app.Patch.Ncas)
                    {
                        NcaContentType type    = nca.Nca.Header.ContentType;
                        SwitchFsNca    baseNca = app.Main.Ncas.Where(n => n.Nca.Header.ContentType == type).FirstOrDefault();
                        if (baseNca != null)
                        {
                            bool hasPatch = false;
                            for (int i = 0; i < 4; i++)
                            {
                                Nca n = nca.Nca;
                                if (n.CanOpenSection(i))
                                {
                                    NcaFsHeader section = n.Header.GetFsHeader(i);
                                    if (section.IsPatchSection())
                                    {
                                        hasPatch = true;
                                        break;
                                    }
                                }
                            }
                            if (hasPatch)
                            {
                                ncas.Where(n => n.Filename == nca.Filename.Replace("/", "")).First().BaseNca = baseNca.Nca; // set original NCA, not new parsed one
                            }
                        }
                    }
                }
            }
        }
        private bool ResolvePath(ServiceCtx context, long titleId, NcaContentType contentType)
        {
            ContentManager contentManager = context.Device.System.ContentManager;
            string         contentPath    = contentManager.GetInstalledContentPath(titleId, _storageId, NcaContentType.Program);

            if (!string.IsNullOrWhiteSpace(contentPath))
            {
                long position = context.Request.RecvListBuff[0].Position;
                long size     = context.Request.RecvListBuff[0].Size;

                byte[] contentPathBuffer = Encoding.UTF8.GetBytes(contentPath);

                context.Memory.Write((ulong)position, contentPathBuffer);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemple #5
0
        private Result OpenNcaStorage(out IStorage ncaStorage, Nca nca, out NcaFormatType fsType,
                                      FileSystemProxyType fsProxyType, bool isGameCard, bool canMountSystemDataPrivate)
        {
            ncaStorage = default;
            fsType     = default;

            NcaContentType contentType = nca.Header.ContentType;

            switch (fsProxyType)
            {
            case FileSystemProxyType.Code:
            case FileSystemProxyType.Rom:
            case FileSystemProxyType.Logo:
            case FileSystemProxyType.RegisteredUpdate:
                if (contentType != NcaContentType.Program)
                {
                    return(ResultFs.PreconditionViolation.Log());
                }

                break;

            case FileSystemProxyType.Control:
                if (contentType != NcaContentType.Control)
                {
                    return(ResultFs.PreconditionViolation.Log());
                }

                break;

            case FileSystemProxyType.Manual:
                if (contentType != NcaContentType.Manual)
                {
                    return(ResultFs.PreconditionViolation.Log());
                }

                break;

            case FileSystemProxyType.Meta:
                if (contentType != NcaContentType.Meta)
                {
                    return(ResultFs.PreconditionViolation.Log());
                }

                break;

            case FileSystemProxyType.Data:
                if (contentType != NcaContentType.Data && contentType != NcaContentType.PublicData)
                {
                    return(ResultFs.PreconditionViolation.Log());
                }

                if (contentType == NcaContentType.Data && !canMountSystemDataPrivate)
                {
                    return(ResultFs.PermissionDenied.Log());
                }

                break;

            default:
                return(ResultFs.InvalidArgument.Log());
            }

            if (nca.Header.DistributionType == DistributionType.GameCard && !isGameCard)
            {
                return(ResultFs.PermissionDenied.Log());
            }

            Result rc = SetNcaExternalKey(nca);

            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = GetNcaSectionIndex(out int sectionIndex, fsProxyType);
            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = FsCreators.StorageOnNcaCreator.Create(out ncaStorage, out NcaFsHeader fsHeader, nca,
                                                       sectionIndex, fsProxyType == FileSystemProxyType.Code);
            if (rc.IsFailure())
            {
                return(rc);
            }

            fsType = fsHeader.FormatType;
            return(Result.Success);
        }
Exemple #6
0
        // OpenDataStorageByDataId(u8 storageId, nn::ApplicationId tid) -> object<nn::fssrv::sf::IStorage> dataStorage
        public ResultCode OpenDataStorageByDataId(ServiceCtx context)
        {
            StorageId storageId = (StorageId)context.RequestData.ReadByte();

            byte[] padding = context.RequestData.ReadBytes(7);
            long   titleId = context.RequestData.ReadInt64();

            // We do a mitm here to find if the request is for an AOC.
            // This is because AOC can be distributed over multiple containers in the emulator.
            if (context.Device.System.ContentManager.GetAocDataStorage((ulong)titleId, out LibHac.Fs.IStorage aocStorage))
            {
                Logger.Info?.Print(LogClass.Loader, $"Opened AddOnContent Data TitleID={titleId:X16}");

                MakeObject(context, new FileSystemProxy.IStorage(aocStorage));

                return(ResultCode.Success);
            }

            NcaContentType contentType = NcaContentType.Data;

            StorageId installedStorage = context.Device.System.ContentManager.GetInstalledStorage(titleId, contentType, storageId);

            if (installedStorage == StorageId.None)
            {
                contentType = NcaContentType.PublicData;

                installedStorage = context.Device.System.ContentManager.GetInstalledStorage(titleId, contentType, storageId);
            }

            if (installedStorage != StorageId.None)
            {
                string contentPath = context.Device.System.ContentManager.GetInstalledContentPath(titleId, storageId, contentType);
                string installPath = context.Device.FileSystem.SwitchPathToSystemPath(contentPath);

                if (!string.IsNullOrWhiteSpace(installPath))
                {
                    string ncaPath = installPath;

                    if (File.Exists(ncaPath))
                    {
                        try
                        {
                            LibHac.Fs.IStorage ncaStorage = new LocalStorage(ncaPath, FileAccess.Read, FileMode.Open);
                            Nca nca = new Nca(context.Device.System.KeySet, ncaStorage);
                            LibHac.Fs.IStorage romfsStorage = nca.OpenStorage(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel);

                            MakeObject(context, new FileSystemProxy.IStorage(romfsStorage));
                        }
                        catch (HorizonResultException ex)
                        {
                            return((ResultCode)ex.ResultValue.Value);
                        }

                        return(ResultCode.Success);
                    }
                    else
                    {
                        throw new FileNotFoundException($"No Nca found in Path `{ncaPath}`.");
                    }
                }
                else
                {
                    throw new DirectoryNotFoundException($"Path for title id {titleId:x16} on Storage {storageId} was not found in Path {installPath}.");
                }
            }

            throw new FileNotFoundException($"System archive with titleid {titleId:x16} was not found on Storage {storageId}. Found in {installedStorage}.");
        }
Exemple #7
0
 public UInt128 GetInstalledNcaId(long titleId, NcaContentType contentType)
 {
     if (_contentDictionary.ContainsKey(((ulong)titleId, contentType)))
     {
         return(new UInt128(_contentDictionary[((ulong)titleId, contentType)]));
Exemple #8
0
 public void ClearEntry(long titleId, NcaContentType contentType, StorageId storageId)
 {
     RemoveLocationEntry(titleId, contentType, storageId);
 }