mirror of
https://github.com/par274/sharpemu.git
synced 2026-07-18 00:30:56 +00:00
[libs] Add NP entitlement validation
This commit is contained in:
51
src/SharpEmu.Libs/Np/NpEntitlementAccessExports.cs
Normal file
51
src/SharpEmu.Libs/Np/NpEntitlementAccessExports.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
// Copyright (C) 2026 SharpEmu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
using SharpEmu.HLE;
|
||||||
|
|
||||||
|
namespace SharpEmu.Libs.Np;
|
||||||
|
|
||||||
|
public static class NpEntitlementAccessExports
|
||||||
|
{
|
||||||
|
private const int BootParamClearSize = 0x20;
|
||||||
|
|
||||||
|
[SysAbiExport(
|
||||||
|
Nid = "jO8DM8oyego",
|
||||||
|
ExportName = "sceNpEntitlementAccessInitialize",
|
||||||
|
Target = Generation.Gen4 | Generation.Gen5,
|
||||||
|
LibraryName = "libSceNpEntitlementAccess")]
|
||||||
|
public static int NpEntitlementAccessInitialize(CpuContext ctx)
|
||||||
|
{
|
||||||
|
var initParam = ctx[CpuRegister.Rdi];
|
||||||
|
var bootParam = ctx[CpuRegister.Rsi];
|
||||||
|
|
||||||
|
if (bootParam != 0)
|
||||||
|
{
|
||||||
|
Span<byte> clear = stackalloc byte[BootParamClearSize];
|
||||||
|
clear.Clear();
|
||||||
|
if (!ctx.Memory.TryWrite(bootParam, clear))
|
||||||
|
{
|
||||||
|
return SetReturn(ctx, OrbisGen2Result.ORBIS_GEN2_ERROR_MEMORY_FAULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TraceNpEntitlementAccess($"initialize init=0x{initParam:X16} boot=0x{bootParam:X16}");
|
||||||
|
return SetReturn(ctx, OrbisGen2Result.ORBIS_GEN2_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int SetReturn(CpuContext ctx, OrbisGen2Result result)
|
||||||
|
{
|
||||||
|
ctx[CpuRegister.Rax] = unchecked((ulong)(int)result);
|
||||||
|
return (int)result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TraceNpEntitlementAccess(string message)
|
||||||
|
{
|
||||||
|
if (!string.Equals(Environment.GetEnvironmentVariable("SHARPEMU_LOG_NP"), "1", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Error.WriteLine($"[LOADER][TRACE] np.entitlement.{message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user