Exemplo n.º 1
0
        public void GetProgramIndexForAccessLog_IsMultiProgram_ReturnsCorrectIndex()
        {
            const int count = 7;

            Horizon hos = HorizonFactory.CreateBasicHorizon();

            var programs = new HorizonClient[count];

            programs[0] = hos.CreateHorizonClient(new ProgramId(1), AccessControlBits.Bits.RegisterProgramIndexMapInfo);

            for (int i = 1; i < programs.Length; i++)
            {
                programs[i] = hos.CreateHorizonClient(new ProgramId((ulong)(i + 1)), AccessControlBits.Bits.None);
            }

            var map = new ProgramIndexMapInfo[count];

            for (int i = 0; i < map.Length; i++)
            {
                map[i].MainProgramId = new ProgramId(1);
                map[i].ProgramId     = new ProgramId((ulong)(i + 1));
                map[i].ProgramIndex  = (byte)i;
            }

            Assert.Success(programs[0].Fs.RegisterProgramIndexMapInfo(map));

            for (int i = 0; i < programs.Length; i++)
            {
                Assert.Success(programs[i].Fs.GetFileSystemProxyServiceObject()
                               .GetProgramIndexForAccessLog(out int programIndex, out int programCount));

                Assert.Equal(i, programIndex);
                Assert.Equal(count, programCount);
            }
        }
Exemplo n.º 2
0
        public void OpenFileSystemWithPermissions_ReturnsInvalidNcaMountPoint()
        {
            Horizon hos = HorizonFactory.CreateBasicHorizon();

            HorizonClient regClient = hos.CreatePrivilegedHorizonClient();
            HorizonClient client    = hos.CreateHorizonClient();

            var dataHeader = new AccessControlDataHeader();
            var descriptor = new AccessControlDescriptor();

            descriptor.Version = 123;
            dataHeader.Version = 123;

            descriptor.AccessFlags = (ulong)AccessControlBits.Bits.ApplicationInfo;
            dataHeader.AccessFlags = (ulong)AccessControlBits.Bits.ApplicationInfo;

            Assert.Success(regClient.Fs.RegisterProgram(client.ProcessId.Value, new ProgramId(123),
                                                        StorageId.BuiltInUser, SpanHelpers.AsReadOnlyByteSpan(in dataHeader),
                                                        SpanHelpers.AsReadOnlyByteSpan(in descriptor)));

            // We should get UnexpectedInNcaFileSystemServiceImplA because mounting NCAs from @System isn't allowed
            Result rc = client.Fs.MountContent("test".ToU8Span(), "@System:/fake.nca".ToU8Span(), ContentType.Control);

            Assert.Result(ResultFs.UnexpectedInNcaFileSystemServiceImplA, rc);
        }
Exemplo n.º 3
0
        public void GetProgramIndexForAccessLog_IsMultiProgram_ReturnsCorrectIndex()
        {
            const int count = 7;

            Horizon hos = HorizonFactory.CreateBasicHorizon();

            var programs = new HorizonClient[count];

            programs[0] = hos.CreateHorizonClient(new ProgramLocation(new ProgramId(1), StorageId.BuiltInSystem),
                                                  AccessControlBits.Bits.RegisterProgramIndexMapInfo);

            for (int i = 1; i < programs.Length; i++)
            {
                programs[i] =
                    hos.CreateHorizonClient(new ProgramLocation(new ProgramId((ulong)(i + 1)), StorageId.BuiltInSystem),
                                            AccessControlBits.Bits.None);
            }

            var map = new ProgramIndexMapInfo[count];

            for (int i = 0; i < map.Length; i++)
            {
                map[i].MainProgramId = new ProgramId(1);
                map[i].ProgramId     = new ProgramId((ulong)(i + 1));
                map[i].ProgramIndex  = (byte)i;
            }

            Assert.Success(programs[0].Fs.RegisterProgramIndexMapInfo(map));

            for (int i = 0; i < programs.Length; i++)
            {
                using ReferenceCountedDisposable <LibHac.FsSrv.Sf.IFileSystemProxy> fsProxy =
                          programs[i].Fs.Impl.GetFileSystemProxyServiceObject();
                Assert.Success(fsProxy.Target.GetProgramIndexForAccessLog(out int programIndex, out int programCount));

                Assert.Equal(i, programIndex);
                Assert.Equal(count, programCount);
            }
        }
Exemplo n.º 4
0
        public void OpenFileSystemWithNoPermissions_ReturnsPermissionDenied()
        {
            Horizon hos = HorizonFactory.CreateBasicHorizon();

            HorizonClient regClient = hos.CreatePrivilegedHorizonClient();
            HorizonClient client    = hos.CreateHorizonClient();

            var dataHeader = new AccessControlDataHeader();
            var descriptor = new AccessControlDescriptor();

            descriptor.Version = 123;
            dataHeader.Version = 123;

            descriptor.AccessFlags = (ulong)AccessControlBits.Bits.None;
            dataHeader.AccessFlags = (ulong)AccessControlBits.Bits.None;

            Assert.Success(regClient.Fs.RegisterProgram(client.ProcessId.Value, new ProgramId(123),
                                                        StorageId.BuiltInUser, SpanHelpers.AsReadOnlyByteSpan(in dataHeader),
                                                        SpanHelpers.AsReadOnlyByteSpan(in descriptor)));

            Result rc = client.Fs.MountContent("test".ToU8Span(), "@System:/fake.nca".ToU8Span(), ContentType.Control);

            Assert.Result(ResultFs.PermissionDenied, rc);
        }
Exemplo n.º 5
0
        private static bool Run(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            var ctx = new Context();

            ctx.Options = CliParser.Parse(args);
            if (ctx.Options == null)
            {
                return(false);
            }

            StreamWriter      logWriter    = null;
            ResultLogger      resultLogger = null;
            LogObserverHolder logObserver  = null;

            try
            {
                using (var logger = new ProgressBar())
                {
                    ctx.Logger = logger;
                    OpenKeySet(ctx);

                    Horizon horizon = HorizonFactory.CreateWithDefaultFsConfig(new HorizonConfiguration(),
                                                                               new InMemoryFileSystem(), ctx.KeySet);
                    ctx.Horizon = horizon.CreatePrivilegedHorizonClient();

                    if (ctx.Options.AccessLog != null)
                    {
                        logWriter   = new StreamWriter(ctx.Options.AccessLog);
                        logObserver = new LogObserverHolder();

                        // ReSharper disable once AccessToDisposedClosure
                        // References to logWriter should be gone by the time it's disposed
                        ctx.Horizon.Diag.InitializeLogObserverHolder(ref logObserver,
                                                                     (in LogMetaData data, in LogBody body, object arguments) =>
                                                                     logWriter.Write(body.Message.ToString()), null);

                        ctx.Horizon.Diag.RegisterLogObserver(logObserver);

                        ctx.Horizon.Fs.SetLocalSystemAccessLogForDebug(true);
                        ctx.Horizon.Fs.SetGlobalAccessLogMode(GlobalAccessLogMode.Log).ThrowIfFailure();
                    }

                    if (ctx.Options.ResultLog != null)
                    {
                        resultLogger = new ResultLogger(new StreamWriter(ctx.Options.ResultLog),
                                                        printStackTrace: true, printSourceInfo: true, combineRepeats: true);

                        Result.SetLogger(resultLogger);
                    }

                    if (ctx.Options.RunCustom)
                    {
                        CustomTask(ctx);
                        return(true);
                    }

                    RunTask(ctx);
                }
            }
            finally
            {
                if (logObserver != null)
                {
                    ctx.Horizon.Diag.UnregisterLogObserver(logObserver);
                }

                logWriter?.Dispose();

                if (resultLogger != null)
                {
                    Result.SetLogger(null);
                    resultLogger.Dispose();
                }
            }

            return(true);
        }
Exemplo n.º 6
0
 public static IHorizon Server(this HorizonEnvironment environment)
 {
     return(HorizonFactory.Create(environment));
 }