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) {
return r.Handles[h_index++];
} else if constexpr (std::is_same<T, PidDescriptor>::value) {
cur_rawdata_index += sizeof(u64) / sizeof(u32);
return PidDescriptor(r.Pid);
} else {
cur_rawdata_index += size_in_raw_data<T>::value / sizeof(u32);

View file

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

View file

@ -1,4 +1,5 @@
#include <switch.h>
#include <cstdio>
#include "ldr_map.hpp"
#include "ldr_random.hpp"

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) {
NroHeader *nro;
MappedCodeMemory mcm_nro;
MappedCodeMemory mcm_bss;
MappedCodeMemory mcm_nro = {0};
MappedCodeMemory mcm_bss = {0};
unsigned int i;
Result rc;
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++) {
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;
} else {
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;
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;
break;
}
}
}

View file

@ -29,6 +29,7 @@ Result RelocatableObjectsService::dispatch(IpcParsedCommand &r, IpcCommand &out_
default:
break;
}
return rc;
}
@ -92,6 +93,7 @@ std::tuple<Result> RelocatableObjectsService::load_nrr(PidDescriptor pid_desc, u
Result rc;
Registration::Process *target_proc = NULL;
MappedCodeMemory nrr_info = {0};
if (!this->has_initialized || this->process_id != pid_desc.pid) {
rc = 0xAE09;
goto LOAD_NRR_END;