2019-07-12 12:31:00 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2019-07-12 12:31:00 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
2020-03-08 09:45:12 +00:00
|
|
|
#include "creport_scoped_file.hpp"
|
2019-07-12 12:31:00 +00:00
|
|
|
#include "creport_threads.hpp"
|
|
|
|
|
2019-10-24 09:30:10 +00:00
|
|
|
namespace ams::creport {
|
2019-07-12 12:31:00 +00:00
|
|
|
|
|
|
|
class ModuleList {
|
|
|
|
private:
|
|
|
|
static constexpr size_t ModuleCountMax = 0x60;
|
|
|
|
static constexpr size_t ModuleNameLengthMax = 0x20;
|
2021-10-11 01:22:32 +00:00
|
|
|
static constexpr size_t ModuleIdSize = 0x20;
|
2019-07-12 12:31:00 +00:00
|
|
|
|
|
|
|
struct ModuleInfo {
|
|
|
|
char name[ModuleNameLengthMax];
|
2021-10-11 01:22:32 +00:00
|
|
|
u8 module_id[ModuleIdSize];
|
2019-07-12 12:31:00 +00:00
|
|
|
u64 start_address;
|
|
|
|
u64 end_address;
|
|
|
|
};
|
|
|
|
private:
|
2021-10-10 07:14:06 +00:00
|
|
|
os::NativeHandle m_debug_handle;
|
|
|
|
size_t m_num_modules;
|
|
|
|
ModuleInfo m_modules[ModuleCountMax];
|
2019-07-12 12:31:00 +00:00
|
|
|
|
|
|
|
/* For pretty-printing. */
|
2021-10-10 07:14:06 +00:00
|
|
|
char m_address_str_buf[0x280];
|
2019-07-12 12:31:00 +00:00
|
|
|
public:
|
2021-10-10 07:14:06 +00:00
|
|
|
ModuleList() : m_debug_handle(os::InvalidNativeHandle), m_num_modules(0) {
|
|
|
|
std::memset(m_modules, 0, sizeof(m_modules));
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetModuleCount() const {
|
2021-10-10 07:14:06 +00:00
|
|
|
return m_num_modules;
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 GetModuleStartAddress(size_t i) const {
|
2021-10-10 07:14:06 +00:00
|
|
|
return m_modules[i].start_address;
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
|
|
|
|
2021-10-04 21:54:13 +00:00
|
|
|
void FindModulesFromThreadInfo(os::NativeHandle debug_handle, const ThreadInfo &thread);
|
2019-07-12 12:31:00 +00:00
|
|
|
const char *GetFormattedAddressString(uintptr_t address);
|
2020-03-08 09:45:12 +00:00
|
|
|
void SaveToFile(ScopedFile &file);
|
2019-07-12 12:31:00 +00:00
|
|
|
private:
|
|
|
|
bool TryFindModule(uintptr_t *out_address, uintptr_t guess);
|
|
|
|
void TryAddModule(uintptr_t guess);
|
|
|
|
void GetModuleName(char *out_name, uintptr_t text_start, uintptr_t ro_start);
|
2021-10-11 01:22:32 +00:00
|
|
|
void GetModuleId(u8 *out, uintptr_t ro_start);
|
2019-07-12 12:31:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|