2020-06-16 20:28:02 +02:00
|
|
|
using ARMeilleure.Translation.PTC;
|
2018-11-28 23:18:09 +01:00
|
|
|
using Ryujinx.Common;
|
|
|
|
using Ryujinx.Common.Logging;
|
2020-05-04 05:41:29 +02:00
|
|
|
using Ryujinx.HLE.HOS.Kernel;
|
2018-12-18 06:33:36 +01:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Memory;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
2018-11-28 23:18:09 +01:00
|
|
|
using Ryujinx.HLE.Loaders.Executables;
|
|
|
|
using Ryujinx.HLE.Loaders.Npdm;
|
2021-03-27 15:12:05 +01:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS
|
|
|
|
{
|
2020-06-16 20:28:02 +02:00
|
|
|
static class ProgramLoader
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
|
|
|
private const bool AslrEnabled = true;
|
|
|
|
|
|
|
|
private const int ArgsHeaderSize = 8;
|
|
|
|
private const int ArgsDataSize = 0x9000;
|
|
|
|
private const int ArgsTotalSize = ArgsHeaderSize + ArgsDataSize;
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
public static bool LoadKip(KernelContext context, KipExecutable kip)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-12-13 08:30:27 +01:00
|
|
|
uint endOffset = kip.DataOffset + (uint)kip.Data.Length;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (kip.BssSize != 0)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
endOffset = kip.BssOffset + kip.BssSize;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2020-12-13 08:30:27 +01:00
|
|
|
uint codeSize = BitUtils.AlignUp(kip.TextOffset + endOffset, KMemoryManager.PageSize);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-12-13 08:30:27 +01:00
|
|
|
int codePagesCount = (int)(codeSize / KMemoryManager.PageSize);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-07-04 01:58:01 +02:00
|
|
|
ulong codeBaseAddress = kip.Is64BitAddressSpace ? 0x8000000UL : 0x200000UL;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
ulong codeAddress = codeBaseAddress + (ulong)kip.TextOffset;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
ProcessCreationFlags flags = 0;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
if (AslrEnabled)
|
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// TODO: Randomization.
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
flags |= ProcessCreationFlags.EnableAslr;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2020-07-04 01:58:01 +02:00
|
|
|
if (kip.Is64BitAddressSpace)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-12-02 00:23:43 +01:00
|
|
|
flags |= ProcessCreationFlags.AddressSpace64Bit;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2020-07-04 01:58:01 +02:00
|
|
|
if (kip.Is64Bit)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-12-02 00:23:43 +01:00
|
|
|
flags |= ProcessCreationFlags.Is64Bit;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
ProcessCreationInfo creationInfo = new ProcessCreationInfo(
|
2020-07-04 01:58:01 +02:00
|
|
|
kip.Name,
|
|
|
|
kip.Version,
|
|
|
|
kip.ProgramId,
|
2018-12-06 12:16:24 +01:00
|
|
|
codeAddress,
|
|
|
|
codePagesCount,
|
2020-12-02 00:23:43 +01:00
|
|
|
flags,
|
2018-11-28 23:18:09 +01:00
|
|
|
0,
|
|
|
|
0);
|
|
|
|
|
2020-07-04 01:58:01 +02:00
|
|
|
MemoryRegion memoryRegion = kip.UsesSecureMemory
|
2018-11-28 23:18:09 +01:00
|
|
|
? MemoryRegion.Service
|
|
|
|
: MemoryRegion.Application;
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KMemoryRegionManager region = context.MemoryRegions[(int)memoryRegion];
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
KernelResult result = region.AllocatePages((ulong)codePagesCount, false, out KPageList pageList);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (result != KernelResult.Success)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
Logger.Error?.Print(LogClass.Loader, $"Process initialization returned error \"{result}\".");
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KProcess process = new KProcess(context);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
var processContextFactory = new ArmProcessContextFactory();
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
result = process.InitializeKip(
|
|
|
|
creationInfo,
|
|
|
|
kip.Capabilities,
|
|
|
|
pageList,
|
2020-05-04 05:41:29 +02:00
|
|
|
context.ResourceLimit,
|
2020-12-02 00:23:43 +01:00
|
|
|
memoryRegion,
|
|
|
|
processContextFactory);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (result != KernelResult.Success)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
Logger.Error?.Print(LogClass.Loader, $"Process initialization returned error \"{result}\".");
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
result = LoadIntoMemory(process, kip, codeBaseAddress);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (result != KernelResult.Success)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
Logger.Error?.Print(LogClass.Loader, $"Process initialization returned error \"{result}\".");
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-04 01:58:01 +02:00
|
|
|
process.DefaultCpuCore = kip.IdealCoreId;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
2020-07-04 01:58:01 +02:00
|
|
|
result = process.Start(kip.Priority, (ulong)kip.StackSize);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (result != KernelResult.Success)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
Logger.Error?.Print(LogClass.Loader, $"Process start returned error \"{result}\".");
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
context.Processes.TryAdd(process.Pid, process);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-27 15:12:05 +01:00
|
|
|
public static bool LoadNsos(KernelContext context, out ProcessTamperInfo tamperInfo, Npdm metaData, byte[] arguments = null, params IExecutable[] executables)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
ulong argsStart = 0;
|
2020-12-13 08:30:27 +01:00
|
|
|
uint argsSize = 0;
|
2020-04-12 23:02:37 +02:00
|
|
|
ulong codeStart = metaData.Is64Bit ? 0x8000000UL : 0x200000UL;
|
2020-12-13 08:30:27 +01:00
|
|
|
uint codeSize = 0;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2021-03-27 15:12:05 +01:00
|
|
|
var buildIds = executables.Select(e => (e switch
|
|
|
|
{
|
|
|
|
NsoExecutable nso => BitConverter.ToString(nso.BuildId.Bytes.ToArray()),
|
|
|
|
NroExecutable nro => BitConverter.ToString(nro.Header.BuildId),
|
|
|
|
_ => ""
|
|
|
|
}).Replace("-", "").ToUpper());
|
|
|
|
|
2020-05-15 08:16:46 +02:00
|
|
|
ulong[] nsoBase = new ulong[executables.Length];
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-05-15 08:16:46 +02:00
|
|
|
for (int index = 0; index < executables.Length; index++)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-12-13 08:30:27 +01:00
|
|
|
IExecutable nso = executables[index];
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-12-13 08:30:27 +01:00
|
|
|
uint textEnd = nso.TextOffset + (uint)nso.Text.Length;
|
|
|
|
uint roEnd = nso.RoOffset + (uint)nso.Ro.Length;
|
|
|
|
uint dataEnd = nso.DataOffset + (uint)nso.Data.Length + nso.BssSize;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-12-13 08:30:27 +01:00
|
|
|
uint nsoSize = textEnd;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-12-13 08:30:27 +01:00
|
|
|
if (nsoSize < roEnd)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
nsoSize = roEnd;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2020-12-13 08:30:27 +01:00
|
|
|
if (nsoSize < dataEnd)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
nsoSize = dataEnd;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
nsoSize = BitUtils.AlignUp(nsoSize, KMemoryManager.PageSize);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
nsoBase[index] = codeStart + (ulong)codeSize;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
codeSize += nsoSize;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (arguments != null && argsSize == 0)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
argsStart = (ulong)codeSize;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-12-13 08:30:27 +01:00
|
|
|
argsSize = (uint)BitUtils.AlignDown(arguments.Length * 2 + ArgsTotalSize - 1, KMemoryManager.PageSize);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
codeSize += argsSize;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-16 20:28:02 +02:00
|
|
|
PtcProfiler.StaticCodeStart = codeStart;
|
2020-12-17 20:32:09 +01:00
|
|
|
PtcProfiler.StaticCodeSize = (ulong)codeSize;
|
2020-06-16 20:28:02 +02:00
|
|
|
|
2020-12-13 08:30:27 +01:00
|
|
|
int codePagesCount = (int)(codeSize / KMemoryManager.PageSize);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
int personalMmHeapPagesCount = metaData.PersonalMmHeapSize / KMemoryManager.PageSize;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
ProcessCreationInfo creationInfo = new ProcessCreationInfo(
|
|
|
|
metaData.TitleName,
|
2020-07-09 06:31:15 +02:00
|
|
|
metaData.Version,
|
2018-12-06 12:16:24 +01:00
|
|
|
metaData.Aci0.TitleId,
|
|
|
|
codeStart,
|
|
|
|
codePagesCount,
|
2020-12-02 00:23:43 +01:00
|
|
|
(ProcessCreationFlags)metaData.ProcessFlags | ProcessCreationFlags.IsApplication,
|
2018-11-28 23:18:09 +01:00
|
|
|
0,
|
2018-12-06 12:16:24 +01:00
|
|
|
personalMmHeapPagesCount);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
KernelResult result;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KResourceLimit resourceLimit = new KResourceLimit(context);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
long applicationRgSize = (long)context.MemoryRegions[(int)MemoryRegion.Application].Size;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
result = resourceLimit.SetLimitValue(LimitableResource.Memory, applicationRgSize);
|
|
|
|
result |= resourceLimit.SetLimitValue(LimitableResource.Thread, 608);
|
|
|
|
result |= resourceLimit.SetLimitValue(LimitableResource.Event, 700);
|
|
|
|
result |= resourceLimit.SetLimitValue(LimitableResource.TransferMemory, 128);
|
|
|
|
result |= resourceLimit.SetLimitValue(LimitableResource.Session, 894);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (result != KernelResult.Success)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
Logger.Error?.Print(LogClass.Loader, $"Process initialization failed setting resource limit values.");
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2021-03-27 15:12:05 +01:00
|
|
|
tamperInfo = null;
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KProcess process = new KProcess(context);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
MemoryRegion memoryRegion = (MemoryRegion)((metaData.Acid.Flags >> 2) & 0xf);
|
|
|
|
|
|
|
|
if (memoryRegion > MemoryRegion.NvServices)
|
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
Logger.Error?.Print(LogClass.Loader, $"Process initialization failed due to invalid ACID flags.");
|
2019-01-18 23:26:39 +01:00
|
|
|
|
2021-03-27 15:12:05 +01:00
|
|
|
tamperInfo = null;
|
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
var processContextFactory = new ArmProcessContextFactory();
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
result = process.Initialize(
|
|
|
|
creationInfo,
|
|
|
|
metaData.Aci0.KernelAccessControl.Capabilities,
|
|
|
|
resourceLimit,
|
2020-12-02 00:23:43 +01:00
|
|
|
memoryRegion,
|
|
|
|
processContextFactory);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (result != KernelResult.Success)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
Logger.Error?.Print(LogClass.Loader, $"Process initialization returned error \"{result}\".");
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2021-03-27 15:12:05 +01:00
|
|
|
tamperInfo = null;
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-15 08:16:46 +02:00
|
|
|
for (int index = 0; index < executables.Length; index++)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
Logger.Info?.Print(LogClass.Loader, $"Loading image {index} at 0x{nsoBase[index]:x16}...");
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-05-15 08:16:46 +02:00
|
|
|
result = LoadIntoMemory(process, executables[index], nsoBase[index]);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (result != KernelResult.Success)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
Logger.Error?.Print(LogClass.Loader, $"Process initialization returned error \"{result}\".");
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2021-03-27 15:12:05 +01:00
|
|
|
tamperInfo = null;
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
process.DefaultCpuCore = metaData.DefaultCpuId;
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
result = process.Start(metaData.MainThreadPriority, (ulong)metaData.MainThreadStackSize);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (result != KernelResult.Success)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
Logger.Error?.Print(LogClass.Loader, $"Process start returned error \"{result}\".");
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2021-03-27 15:12:05 +01:00
|
|
|
tamperInfo = null;
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
context.Processes.TryAdd(process.Pid, process);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2021-03-27 15:12:05 +01:00
|
|
|
// Keep the build ids because the tamper machine uses them to know which process to associate a
|
|
|
|
// tamper to and also keep the starting address of each executable inside a process because some
|
|
|
|
// memory modifications are relative to this address.
|
|
|
|
tamperInfo = new ProcessTamperInfo(process, buildIds, nsoBase, process.MemoryManager.HeapRegionStart);
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private static KernelResult LoadIntoMemory(KProcess process, IExecutable image, ulong baseAddress)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
ulong textStart = baseAddress + (ulong)image.TextOffset;
|
|
|
|
ulong roStart = baseAddress + (ulong)image.RoOffset;
|
|
|
|
ulong dataStart = baseAddress + (ulong)image.DataOffset;
|
|
|
|
ulong bssStart = baseAddress + (ulong)image.BssOffset;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
ulong end = dataStart + (ulong)image.Data.Length;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (image.BssSize != 0)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
end = bssStart + (ulong)image.BssSize;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
process.CpuMemory.Write(textStart, image.Text);
|
|
|
|
process.CpuMemory.Write(roStart, image.Ro);
|
|
|
|
process.CpuMemory.Write(dataStart, image.Data);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-12-13 08:30:27 +01:00
|
|
|
process.CpuMemory.Fill(bssStart, image.BssSize, 0);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
KernelResult SetProcessMemoryPermission(ulong address, ulong size, KMemoryPermission permission)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (size == 0)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
|
|
|
return KernelResult.Success;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
size = BitUtils.AlignUp(size, KMemoryManager.PageSize);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return process.MemoryManager.SetProcessMemoryPermission(address, size, permission);
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
KernelResult result = SetProcessMemoryPermission(textStart, (ulong)image.Text.Length, KMemoryPermission.ReadAndExecute);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (result != KernelResult.Success)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
return result;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
result = SetProcessMemoryPermission(roStart, (ulong)image.Ro.Length, KMemoryPermission.Read);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (result != KernelResult.Success)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
return result;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
return SetProcessMemoryPermission(dataStart, end - dataStart, KMemoryPermission.ReadAndWrite);
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
}
|
2020-04-08 00:41:02 +02:00
|
|
|
}
|