mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Add AccessLogService
This commit is contained in:
parent
a3220cc8df
commit
9826178fb6
6 changed files with 149 additions and 9 deletions
66
src/LibHac/FsSrv/AccessLogService.cs
Normal file
66
src/LibHac/FsSrv/AccessLogService.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using LibHac.Fs;
|
||||
using LibHac.FsSrv.Impl;
|
||||
using LibHac.Sf;
|
||||
|
||||
namespace LibHac.FsSrv
|
||||
{
|
||||
internal readonly struct AccessLogService
|
||||
{
|
||||
private readonly AccessLogServiceImpl _serviceImpl;
|
||||
private readonly ulong _processId;
|
||||
|
||||
public AccessLogService(AccessLogServiceImpl serviceImpl, ulong processId)
|
||||
{
|
||||
_serviceImpl = serviceImpl;
|
||||
_processId = processId;
|
||||
}
|
||||
|
||||
public Result SetAccessLogMode(GlobalAccessLogMode mode)
|
||||
{
|
||||
Result rc = GetProgramInfo(out ProgramInfo programInfo);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (!programInfo.AccessControl.CanCall(OperationType.SetGlobalAccessLogMode))
|
||||
return ResultFs.PermissionDenied.Log();
|
||||
|
||||
_serviceImpl.SetAccessLogMode(mode);
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result GetAccessLogMode(out GlobalAccessLogMode mode)
|
||||
{
|
||||
mode = _serviceImpl.GetAccessLogMode();
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result OutputAccessLogToSdCard(InBuffer textBuffer)
|
||||
{
|
||||
Result rc = GetProgramInfo(out ProgramInfo programInfo);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
return _serviceImpl.OutputAccessLogToSdCard(textBuffer.Buffer, programInfo.ProgramIdValue, _processId);
|
||||
}
|
||||
|
||||
public Result OutputMultiProgramTagAccessLog()
|
||||
{
|
||||
_serviceImpl.OutputAccessLogToSdCard(MultiProgramTag, _processId).IgnoreResult();
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
private Result GetProgramInfo(out ProgramInfo programInfo)
|
||||
{
|
||||
return _serviceImpl.GetProgramInfo(out programInfo, _processId);
|
||||
}
|
||||
|
||||
private static ReadOnlySpan<byte> MultiProgramTag => // FS_ACCESS: { multi_program_tag: true }\n
|
||||
new[]
|
||||
{
|
||||
(byte) 'F', (byte) 'S', (byte) '_', (byte) 'A', (byte) 'C', (byte) 'C', (byte) 'E', (byte) 'S',
|
||||
(byte) 'S', (byte) ':', (byte) ' ', (byte) '{', (byte) ' ', (byte) 'm', (byte) 'u', (byte) 'l',
|
||||
(byte) 't', (byte) 'i', (byte) '_', (byte) 'p', (byte) 'r', (byte) 'o', (byte) 'g', (byte) 'r',
|
||||
(byte) 'a', (byte) 'm', (byte) '_', (byte) 't', (byte) 'a', (byte) 'g', (byte) ':', (byte) ' ',
|
||||
(byte) 't', (byte) 'r', (byte) 'u', (byte) 'e', (byte) ' ', (byte) '}', (byte) '\n'
|
||||
};
|
||||
}
|
||||
}
|
56
src/LibHac/FsSrv/AccessLogServiceImpl.cs
Normal file
56
src/LibHac/FsSrv/AccessLogServiceImpl.cs
Normal file
|
@ -0,0 +1,56 @@
|
|||
using System;
|
||||
using LibHac.Fs;
|
||||
using LibHac.FsSrv.Impl;
|
||||
|
||||
namespace LibHac.FsSrv
|
||||
{
|
||||
public class AccessLogServiceImpl : IDisposable
|
||||
{
|
||||
private Configuration _config;
|
||||
private GlobalAccessLogMode _accessLogMode;
|
||||
|
||||
public AccessLogServiceImpl(in Configuration configuration)
|
||||
{
|
||||
_config = configuration;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public struct Configuration
|
||||
{
|
||||
public ulong MinimumProgramIdForSdCardLog;
|
||||
|
||||
// LibHac additions
|
||||
public HorizonClient HorizonClient;
|
||||
public ProgramRegistryImpl ProgramRegistry;
|
||||
}
|
||||
|
||||
public void SetAccessLogMode(GlobalAccessLogMode mode)
|
||||
{
|
||||
_accessLogMode = mode;
|
||||
}
|
||||
|
||||
public GlobalAccessLogMode GetAccessLogMode()
|
||||
{
|
||||
return _accessLogMode;
|
||||
}
|
||||
|
||||
public Result OutputAccessLogToSdCard(ReadOnlySpan<byte> text, ulong processId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Result OutputAccessLogToSdCard(ReadOnlySpan<byte> text, ulong programId, ulong processId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal Result GetProgramInfo(out ProgramInfo programInfo, ulong processId)
|
||||
{
|
||||
return _config.ProgramRegistry.GetProgramInfo(out programInfo, processId);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,5 +9,6 @@ namespace LibHac.FsSrv
|
|||
public NcaFileSystemServiceImpl NcaFileSystemService { get; set; }
|
||||
public SaveDataFileSystemServiceImpl SaveDataFileSystemService { get; set; }
|
||||
public ProgramRegistryServiceImpl ProgramRegistryService { get; set; }
|
||||
public AccessLogServiceImpl AccessLogService { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -888,14 +888,13 @@ namespace LibHac.FsSrv
|
|||
|
||||
public Result SetGlobalAccessLogMode(GlobalAccessLogMode mode)
|
||||
{
|
||||
// Missing permission check
|
||||
return GetAccessLogService().SetAccessLogMode(mode);
|
||||
|
||||
return FsProxyCore.SetGlobalAccessLogMode(mode);
|
||||
}
|
||||
|
||||
public Result GetGlobalAccessLogMode(out GlobalAccessLogMode mode)
|
||||
{
|
||||
return FsProxyCore.GetGlobalAccessLogMode(out mode);
|
||||
return GetAccessLogService().GetAccessLogMode(out mode);
|
||||
}
|
||||
|
||||
public Result GetProgramIndexForAccessLog(out int programIndex, out int programCount)
|
||||
|
@ -903,9 +902,14 @@ namespace LibHac.FsSrv
|
|||
return GetProgramIndexRegistryService().GetProgramIndex(out programIndex, out programCount);
|
||||
}
|
||||
|
||||
public Result OutputAccessLogToSdCard(InBuffer logString)
|
||||
public Result OutputAccessLogToSdCard(InBuffer textBuffer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return GetAccessLogService().OutputAccessLogToSdCard(textBuffer);
|
||||
}
|
||||
|
||||
public Result OutputMultiProgramTagAccessLog()
|
||||
{
|
||||
return GetAccessLogService().OutputMultiProgramTagAccessLog();
|
||||
}
|
||||
|
||||
public Result RegisterUpdatePartition()
|
||||
|
@ -928,7 +932,7 @@ namespace LibHac.FsSrv
|
|||
return ncaFsService.OpenRegisteredUpdatePartition(out fileSystem);
|
||||
}
|
||||
|
||||
public Result OverrideSaveDataTransferTokenSignVerificationKey(ReadOnlySpan<byte> key)
|
||||
public Result OverrideSaveDataTransferTokenSignVerificationKey(InBuffer key)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -1000,5 +1004,10 @@ namespace LibHac.FsSrv
|
|||
saveFsService = SaveFsService.Target;
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
private AccessLogService GetAccessLogService()
|
||||
{
|
||||
return new AccessLogService(FsProxyCore.Config.AccessLogService, CurrentProcess);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,13 +136,20 @@ namespace LibHac.FsSrv
|
|||
|
||||
var saveFsService = new SaveDataFileSystemServiceImpl(in saveFsServiceConfig);
|
||||
|
||||
var accessLogServiceConfig = new AccessLogServiceImpl.Configuration();
|
||||
accessLogServiceConfig.MinimumProgramIdForSdCardLog = 0x0100000000003000;
|
||||
accessLogServiceConfig.HorizonClient = Hos;
|
||||
accessLogServiceConfig.ProgramRegistry = programRegistry;
|
||||
var accessLogService = new AccessLogServiceImpl(in accessLogServiceConfig);
|
||||
|
||||
var fspConfig = new FileSystemProxyConfiguration
|
||||
{
|
||||
FsCreatorInterfaces = config.FsCreators,
|
||||
BaseFileSystemService = baseFsService,
|
||||
NcaFileSystemService = ncaFsService,
|
||||
SaveDataFileSystemService = saveFsService,
|
||||
ProgramRegistryService = programRegistryService
|
||||
ProgramRegistryService = programRegistryService,
|
||||
AccessLogService = accessLogService
|
||||
};
|
||||
|
||||
return fspConfig;
|
||||
|
|
|
@ -104,13 +104,14 @@ namespace LibHac.FsSrv
|
|||
Result DisableAutoSaveDataCreation();
|
||||
Result SetGlobalAccessLogMode(GlobalAccessLogMode mode);
|
||||
Result GetGlobalAccessLogMode(out GlobalAccessLogMode mode);
|
||||
Result OutputAccessLogToSdCard(InBuffer logString);
|
||||
Result OutputAccessLogToSdCard(InBuffer textBuffer);
|
||||
Result RegisterUpdatePartition();
|
||||
Result OpenRegisteredUpdatePartition(out ReferenceCountedDisposable<IFileSystemSf> fileSystem);
|
||||
|
||||
Result GetProgramIndexForAccessLog(out int programIndex, out int programCount);
|
||||
Result UnsetSaveDataRootPath();
|
||||
Result OverrideSaveDataTransferTokenSignVerificationKey(ReadOnlySpan<byte> key);
|
||||
Result OutputMultiProgramTagAccessLog();
|
||||
Result OverrideSaveDataTransferTokenSignVerificationKey(InBuffer key);
|
||||
Result CorruptSaveDataFileSystemByOffset(SaveDataSpaceId spaceId, ulong saveDataId, long offset);
|
||||
Result OpenMultiCommitManager(out ReferenceCountedDisposable<IMultiCommitManager> commitManager);
|
||||
Result OpenBisWiper(out ReferenceCountedDisposable<IWiper> bisWiper, NativeHandle transferMemoryHandle, ulong transferMemorySize);
|
||||
|
|
Loading…
Reference in a new issue