loader: refactor ro manager/improve accuracy

This commit is contained in:
Michael Scire 2021-10-10 18:22:32 -07:00
parent d8a36e39f2
commit d9dc04318d
24 changed files with 328 additions and 218 deletions

View file

@ -33,7 +33,7 @@ namespace ams::dmnt::cheat {
MemoryRegionExtents heap_extents;
MemoryRegionExtents alias_extents;
MemoryRegionExtents aslr_extents;
u8 main_nso_build_id[0x20];
u8 main_nso_module_id[0x20];
};
static_assert(util::is_pod<CheatProcessMetadata>::value && sizeof(CheatProcessMetadata) == 0x70, "CheatProcessMetadata definition!");

View file

@ -73,8 +73,12 @@ namespace ams::ldr {
}
static_assert(sizeof(PinId) == sizeof(u64) && util::is_pod<PinId>::value, "PinId definition!");
/* Import ModuleInfo from libnx. */
using ModuleInfo = ::LoaderModuleInfo;
struct ModuleInfo {
u8 module_id[0x20];
u64 address;
u64 size;
};
static_assert(sizeof(ModuleInfo) == 0x30);
/* NSO types. */
struct NsoHeader {
@ -123,7 +127,7 @@ namespace ams::ldr {
};
SegmentInfo segments[Segment_Count];
};
u8 build_id[sizeof(ModuleInfo::build_id)];
u8 module_id[sizeof(ModuleInfo::module_id)];
union {
u32 compressed_sizes[Segment_Count];
struct {

View file

@ -17,9 +17,10 @@
#pragma once
#include <vapours.hpp>
#include <stratosphere/ro/ro_types.hpp>
#include <stratosphere/ldr/ldr_types.hpp>
#include <stratosphere/sf.hpp>
#define AMS_RO_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, GetProcessModuleInfo, (sf::Out<u32> out_count, const sf::OutArray<LoaderModuleInfo> &out_infos, os::ProcessId process_id), (out_count, out_infos, process_id))
AMS_SF_METHOD_INFO(C, H, 0, Result, GetProcessModuleInfo, (sf::Out<u32> out_count, const sf::OutArray<ldr::ModuleInfo> &out_infos, os::ProcessId process_id), (out_count, out_infos, process_id))
AMS_SF_DEFINE_INTERFACE(ams::ro::impl, IDebugMonitorInterface, AMS_RO_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO)

View file

@ -27,10 +27,11 @@ namespace ams::ro {
NrrKind_Count,
};
static constexpr size_t ModuleIdSize = 0x20;
struct ModuleId {
u8 build_id[0x20];
u8 data[ModuleIdSize];
};
static_assert(sizeof(ModuleId) == sizeof(LoaderModuleInfo::build_id), "ModuleId definition!");
static_assert(sizeof(ModuleId) == ModuleIdSize);
struct NrrCertification {
static constexpr size_t RsaKeySize = 0x100;

View file

@ -43,3 +43,16 @@
\
return ::ams::util::GetReference(s_singleton_storage); \
}
#define AMS_CONSTINIT_SINGLETON_TRAITS(_CLASSNAME_) \
private: \
NON_COPYABLE(_CLASSNAME_); \
NON_MOVEABLE(_CLASSNAME_); \
private: \
constexpr _CLASSNAME_ () = default; \
public: \
static _CLASSNAME_ &GetInstance() { \
/* Declare singleton instance variables. */ \
static constinit _CLASSNAME_ s_singleton_instance; \
return s_singleton_instance; \
}

View file

@ -56,8 +56,8 @@ namespace ams::patcher {
/* Read module id from name. */
std::memset(out_module_id, 0, sizeof(*out_module_id));
for (unsigned int name_ofs = 0, id_ofs = 0; name_ofs < name_len - extension_len && id_ofs < sizeof(*out_module_id); id_ofs++) {
out_module_id->build_id[id_ofs] |= ConvertHexNybble(name[name_ofs++]) << 4;
out_module_id->build_id[id_ofs] |= ConvertHexNybble(name[name_ofs++]);
out_module_id->data[id_ofs] |= ConvertHexNybble(name[name_ofs++]) << 4;
out_module_id->data[id_ofs] |= ConvertHexNybble(name[name_ofs++]);
}
return true;
@ -76,7 +76,7 @@ namespace ams::patcher {
bool IsIpsFileForModule(const char *name, const ro::ModuleId *module_id) {
const size_t name_len = std::strlen(name);
/* The path must be correct size for a build id (with trailing zeroes optionally trimmed) + ".ips". */
/* The path must be correct size for a module id (with trailing zeroes optionally trimmed) + ".ips". */
if (!(IpsFileExtensionLength < name_len && name_len <= ModuleIpsPatchLength)) {
return false;
}

View file

@ -330,7 +330,7 @@ namespace ams::scs {
Result PrepareToLaunchProgram(ncm::ProgramId program_id, const void *args, size_t args_size) {
/* Set the arguments. */
R_TRY_CATCH(ldr::SetProgramArgument(program_id, args, args_size)) {
R_CATCH(ldr::ResultTooManyArguments) {
R_CATCH(ldr::ResultArgumentCountOverflow) {
/* There are too many arguments already registered. Flush the arguments queue. */
R_TRY(ldr::FlushArguments());

View file

@ -21,29 +21,30 @@ namespace ams::ldr {
R_DEFINE_NAMESPACE_RESULT_MODULE(9);
R_DEFINE_ERROR_RESULT(TooLongArgument, 1);
R_DEFINE_ERROR_RESULT(TooManyArguments, 2);
R_DEFINE_ERROR_RESULT(TooLargeMeta, 3);
R_DEFINE_ERROR_RESULT(InvalidMeta, 4);
R_DEFINE_ERROR_RESULT(InvalidNso, 5);
R_DEFINE_ERROR_RESULT(InvalidPath, 6);
R_DEFINE_ERROR_RESULT(TooManyProcesses, 7);
R_DEFINE_ERROR_RESULT(NotPinned, 8);
R_DEFINE_ERROR_RESULT(InvalidProgramId, 9);
R_DEFINE_ERROR_RESULT(ArgumentOverflow, 1);
R_DEFINE_ERROR_RESULT(ArgumentCountOverflow, 2);
R_DEFINE_ERROR_RESULT(MetaOverflow, 3);
R_DEFINE_ERROR_RESULT(InvalidMeta, 4);
R_DEFINE_ERROR_RESULT(InvalidNso, 5);
R_DEFINE_ERROR_RESULT(InvalidPath, 6);
R_DEFINE_ERROR_RESULT(MaxProcess, 7);
R_DEFINE_ERROR_RESULT(NotPinned, 8);
R_DEFINE_ERROR_RESULT(InvalidProgramId, 9);
R_DEFINE_ERROR_RESULT(InvalidVersion, 10);
R_DEFINE_ERROR_RESULT(InvalidAcidSignature, 11);
R_DEFINE_ERROR_RESULT(InvalidNcaSignature, 12);
R_DEFINE_ERROR_RESULT(InsufficientAddressSpace, 51);
R_DEFINE_ERROR_RESULT(InvalidNro, 52);
R_DEFINE_ERROR_RESULT(InvalidNrr, 53);
R_DEFINE_ERROR_RESULT(InvalidSignature, 54);
R_DEFINE_ERROR_RESULT(InsufficientNroRegistrations, 55);
R_DEFINE_ERROR_RESULT(InsufficientNrrRegistrations, 56);
R_DEFINE_ERROR_RESULT(OutOfAddressSpace, 51);
R_DEFINE_ERROR_RESULT(InvalidNroImage, 52);
R_DEFINE_ERROR_RESULT(InvalidNrrImage, 53);
R_DEFINE_ERROR_RESULT(NotAuthorized, 54);
R_DEFINE_ERROR_RESULT(MaxModule, 55);
R_DEFINE_ERROR_RESULT(MaxRegistration, 56);
R_DEFINE_ERROR_RESULT(NroAlreadyLoaded, 57);
R_DEFINE_ERROR_RESULT(InvalidAddress, 81);
R_DEFINE_ERROR_RESULT(InvalidSize, 82);
R_DEFINE_ERROR_RESULT(InvalidCurrentMemory, 83);
R_DEFINE_ERROR_RESULT(NotLoaded, 84);
R_DEFINE_ERROR_RESULT(NotRegistered, 85);
R_DEFINE_ERROR_RESULT(InvalidSession, 86);