2018-09-07 17:00:13 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Atmosphère-NX
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-04-19 07:00:10 +02:00
|
|
|
#pragma once
|
|
|
|
#include <switch.h>
|
2018-06-19 20:07:31 +02:00
|
|
|
#include <array>
|
2018-04-19 07:00:10 +02:00
|
|
|
|
2018-04-27 04:27:52 +02:00
|
|
|
#include "ldr_map.hpp"
|
|
|
|
|
2018-04-19 07:00:10 +02:00
|
|
|
#define REGISTRATION_LIST_MAX (0x40)
|
|
|
|
|
|
|
|
#define NSO_INFO_MAX (0x20)
|
2018-04-27 01:03:10 +02:00
|
|
|
#define NRR_INFO_MAX (0x40)
|
2018-04-27 11:17:07 +02:00
|
|
|
#define NRO_INFO_MAX (0x40)
|
2018-04-19 07:00:10 +02:00
|
|
|
|
|
|
|
class Registration {
|
|
|
|
public:
|
|
|
|
struct NsoInfo {
|
|
|
|
u64 base_address;
|
|
|
|
u64 size;
|
|
|
|
unsigned char build_id[0x20];
|
|
|
|
};
|
|
|
|
|
2018-04-20 00:14:48 +02:00
|
|
|
struct NsoInfoHolder {
|
|
|
|
bool in_use;
|
|
|
|
NsoInfo info;
|
|
|
|
};
|
|
|
|
|
2018-04-27 11:17:07 +02:00
|
|
|
struct NroInfo {
|
|
|
|
bool in_use;
|
|
|
|
u64 base_address;
|
|
|
|
u64 total_mapped_size;
|
|
|
|
u64 nro_heap_address;
|
|
|
|
u64 nro_heap_size;
|
|
|
|
u64 bss_heap_address;
|
|
|
|
u64 bss_heap_size;
|
|
|
|
u64 text_size;
|
|
|
|
u64 ro_size;
|
|
|
|
u64 rw_size;
|
|
|
|
unsigned char build_id[0x20];
|
|
|
|
};
|
|
|
|
|
2018-04-19 07:00:10 +02:00
|
|
|
struct TidSid {
|
|
|
|
u64 title_id;
|
|
|
|
FsStorageId storage_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Process {
|
|
|
|
bool in_use;
|
2018-04-26 22:53:33 +02:00
|
|
|
bool is_64_bit_addspace;
|
2018-04-19 07:00:10 +02:00
|
|
|
u64 index;
|
|
|
|
u64 process_id;
|
2018-05-02 00:49:20 +02:00
|
|
|
u64 title_id;
|
2018-04-19 07:00:10 +02:00
|
|
|
Registration::TidSid tid_sid;
|
2018-06-19 20:07:31 +02:00
|
|
|
std::array<Registration::NsoInfoHolder, NSO_INFO_MAX> nso_infos;
|
|
|
|
std::array<Registration::NroInfo, NRO_INFO_MAX> nro_infos;
|
|
|
|
std::array<MappedCodeMemory, NRR_INFO_MAX> nrr_infos;
|
2018-04-27 03:13:55 +02:00
|
|
|
void *owner_ro_service;
|
2018-04-19 07:00:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct List {
|
2018-06-19 20:07:31 +02:00
|
|
|
std::array<Registration::Process, REGISTRATION_LIST_MAX> processes;
|
2018-04-19 07:00:10 +02:00
|
|
|
u64 num_processes;
|
|
|
|
};
|
|
|
|
|
2018-04-27 01:03:10 +02:00
|
|
|
static Registration::Process *GetFreeProcess();
|
|
|
|
static Registration::Process *GetProcess(u64 index);
|
|
|
|
static Registration::Process *GetProcessByProcessId(u64 pid);
|
2018-04-27 04:50:27 +02:00
|
|
|
static Registration::Process *GetProcessByRoService(void *service);
|
2018-04-27 01:03:10 +02:00
|
|
|
static Result GetRegisteredTidSid(u64 index, Registration::TidSid *out);
|
|
|
|
static bool RegisterTidSid(const TidSid *tid_sid, u64 *out_index);
|
|
|
|
static bool UnregisterIndex(u64 index);
|
2018-05-02 00:49:20 +02:00
|
|
|
static void SetProcessIdTidAndIs64BitAddressSpace(u64 index, u64 process_id, u64 tid, bool is_64_bit_addspace);
|
2018-04-27 01:03:10 +02:00
|
|
|
static void AddNsoInfo(u64 index, u64 base_address, u64 size, const unsigned char *build_id);
|
2018-04-27 04:50:27 +02:00
|
|
|
static void CloseRoService(void *service, Handle process_h);
|
2018-04-27 04:27:52 +02:00
|
|
|
static Result AddNrrInfo(u64 index, MappedCodeMemory *nrr_info);
|
2018-04-27 04:37:38 +02:00
|
|
|
static Result RemoveNrrInfo(u64 index, u64 base_address);
|
2018-04-27 11:17:07 +02:00
|
|
|
static bool IsNroHashPresent(u64 index, u8 *nro_hash);
|
|
|
|
static bool IsNroAlreadyLoaded(u64 index, u8 *build_id);
|
|
|
|
static void AddNroToProcess(u64 index, MappedCodeMemory *nro, MappedCodeMemory *bss, u32 text_size, u32 ro_size, u32 rw_size, u8 *build_id);
|
2018-04-27 11:33:44 +02:00
|
|
|
static Result RemoveNroInfo(u64 index, Handle process_h, u64 base_address);
|
2018-04-27 01:03:10 +02:00
|
|
|
static Result GetNsoInfosForProcessId(NsoInfo *out, u32 max_out, u64 process_id, u32 *num_written);
|
2018-06-15 01:50:01 +02:00
|
|
|
|
|
|
|
/* Atmosphere MitM Extension. */
|
|
|
|
static void AssociatePidTidForMitM(u64 index);
|
2018-04-19 07:00:10 +02:00
|
|
|
};
|