Loader: Fix bugs ldr:ro, Loader now works fully on hardware.

This commit is contained in:
Michael Scire 2018-05-02 01:39:24 -06:00
parent 361e9607a9
commit 9e03852703
6 changed files with 13 additions and 6 deletions

View file

@ -202,6 +202,7 @@ T GetValueFromIpcParsedCommand(IpcParsedCommand& r, IpcCommand& out_c, u8 *point
} else if constexpr (is_ipc_handle<T>::value) { } else if constexpr (is_ipc_handle<T>::value) {
return r.Handles[h_index++]; return r.Handles[h_index++];
} else if constexpr (std::is_same<T, PidDescriptor>::value) { } else if constexpr (std::is_same<T, PidDescriptor>::value) {
cur_rawdata_index += sizeof(u64) / sizeof(u32);
return PidDescriptor(r.Pid); return PidDescriptor(r.Pid);
} else { } else {
cur_rawdata_index += size_in_raw_data<T>::value / sizeof(u32); cur_rawdata_index += size_in_raw_data<T>::value / sizeof(u32);

View file

@ -59,6 +59,8 @@
"svcSetProcessMemoryPermission" : "0x73", "svcSetProcessMemoryPermission" : "0x73",
"svcMapProcessMemory" : "0x74", "svcMapProcessMemory" : "0x74",
"svcUnmapProcessMemory" : "0x75", "svcUnmapProcessMemory" : "0x75",
"svcMapProcessCodeMemory" : "0x77",
"svcUnmapProcessCodeMemory" : "0x78",
"svcCreateProcess" : "0x79" "svcCreateProcess" : "0x79"
} }
} }

View file

@ -1,4 +1,5 @@
#include <switch.h> #include <switch.h>
#include <cstdio>
#include "ldr_map.hpp" #include "ldr_map.hpp"
#include "ldr_random.hpp" #include "ldr_random.hpp"
@ -159,7 +160,7 @@ Result MapUtils::MapCodeMemoryForProcessDeprecated(Handle process_h, bool is_64_
if (size > addspace_size) { if (size > addspace_size) {
return 0x6609; return 0x6609;
} }
u64 try_address; u64 try_address;
for (unsigned int i = 0; i < 0x200; i++) { for (unsigned int i = 0; i < 0x200; i++) {
try_address = addspace_base + (RandomUtils::GetRandomU64((u64)(addspace_size - size) >> 12) << 12); try_address = addspace_base + (RandomUtils::GetRandomU64((u64)(addspace_size - size) >> 12) << 12);

View file

@ -30,8 +30,8 @@ Result NroUtils::ValidateNrrHeader(NrrHeader *header, u64 size, u64 title_id_min
Result NroUtils::LoadNro(Registration::Process *target_proc, Handle process_h, u64 nro_heap_address, u64 nro_heap_size, u64 bss_heap_address, u64 bss_heap_size, u64 *out_address) { Result NroUtils::LoadNro(Registration::Process *target_proc, Handle process_h, u64 nro_heap_address, u64 nro_heap_size, u64 bss_heap_address, u64 bss_heap_size, u64 *out_address) {
NroHeader *nro; NroHeader *nro;
MappedCodeMemory mcm_nro; MappedCodeMemory mcm_nro = {0};
MappedCodeMemory mcm_bss; MappedCodeMemory mcm_bss = {0};
unsigned int i; unsigned int i;
Result rc; Result rc;
u8 nro_hash[0x20]; u8 nro_hash[0x20];
@ -47,7 +47,7 @@ Result NroUtils::LoadNro(Registration::Process *target_proc, Handle process_h, u
} }
for (i = 0; i < 0x200; i++) { for (i = 0; i < 0x200; i++) {
if (R_SUCCEEDED(mcm_nro.Open(process_h, target_proc->is_64_bit_addspace, nro_heap_address, nro_heap_size))) { if (R_SUCCEEDED(mcm_nro.Open(process_h, target_proc->is_64_bit_addspace, nro_heap_address, nro_heap_size))) {
if (R_SUCCEEDED(mcm_bss.OpenAtAddress(process_h, bss_heap_address, bss_heap_size, nro_heap_address + nro_heap_size))) { if (R_SUCCEEDED(mcm_bss.OpenAtAddress(process_h, bss_heap_address, bss_heap_size, mcm_nro.code_memory_address + nro_heap_size))) {
break; break;
} else { } else {
mcm_nro.Close(); mcm_nro.Close();

View file

@ -219,6 +219,7 @@ void Registration::AddNroToProcess(u64 index, MappedCodeMemory *nro, MappedCodeM
target_process->nro_infos[i].rw_size = rw_size; target_process->nro_infos[i].rw_size = rw_size;
std::copy(build_id, build_id + sizeof(target_process->nro_infos[i].build_id), target_process->nro_infos[i].build_id); std::copy(build_id, build_id + sizeof(target_process->nro_infos[i].build_id), target_process->nro_infos[i].build_id);
target_process->nro_infos[i].in_use = true; target_process->nro_infos[i].in_use = true;
break;
} }
} }
} }

View file

@ -9,7 +9,7 @@
Result RelocatableObjectsService::dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size) { Result RelocatableObjectsService::dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size) {
Result rc = 0xF601; Result rc = 0xF601;
switch ((RoServiceCmd)cmd_id) { switch ((RoServiceCmd)cmd_id) {
case Ro_Cmd_LoadNro: case Ro_Cmd_LoadNro:
rc = WrapIpcCommandImpl<&RelocatableObjectsService::load_nro>(this, r, out_c, pointer_buffer, pointer_buffer_size); rc = WrapIpcCommandImpl<&RelocatableObjectsService::load_nro>(this, r, out_c, pointer_buffer, pointer_buffer_size);
@ -29,6 +29,7 @@ Result RelocatableObjectsService::dispatch(IpcParsedCommand &r, IpcCommand &out_
default: default:
break; break;
} }
return rc; return rc;
} }
@ -92,6 +93,7 @@ std::tuple<Result> RelocatableObjectsService::load_nrr(PidDescriptor pid_desc, u
Result rc; Result rc;
Registration::Process *target_proc = NULL; Registration::Process *target_proc = NULL;
MappedCodeMemory nrr_info = {0}; MappedCodeMemory nrr_info = {0};
if (!this->has_initialized || this->process_id != pid_desc.pid) { if (!this->has_initialized || this->process_id != pid_desc.pid) {
rc = 0xAE09; rc = 0xAE09;
goto LOAD_NRR_END; goto LOAD_NRR_END;
@ -115,7 +117,7 @@ std::tuple<Result> RelocatableObjectsService::load_nrr(PidDescriptor pid_desc, u
if (R_FAILED((rc = nrr_info.Open(this->process_handle, target_proc->is_64_bit_addspace, nrr_address, nrr_size)))) { if (R_FAILED((rc = nrr_info.Open(this->process_handle, target_proc->is_64_bit_addspace, nrr_address, nrr_size)))) {
goto LOAD_NRR_END; goto LOAD_NRR_END;
} }
if (R_FAILED((rc = nrr_info.Map()))) { if (R_FAILED((rc = nrr_info.Map()))) {
goto LOAD_NRR_END; goto LOAD_NRR_END;
} }