mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-02 23:59:49 -04:00
strat: use m_ for member variables
This commit is contained in:
parent
ce28591ab2
commit
a595c232b9
425 changed files with 8531 additions and 8484 deletions
|
@ -83,28 +83,28 @@ namespace ams::dmnt::cheat::impl {
|
|||
private:
|
||||
static constexpr size_t ThreadStackSize = 0x4000;
|
||||
private:
|
||||
os::SdkMutex cheat_lock;
|
||||
os::Event unsafe_break_event;
|
||||
os::Event debug_events_event; /* Autoclear. */
|
||||
os::ThreadType detect_thread, debug_events_thread;
|
||||
os::SystemEvent cheat_process_event;
|
||||
os::NativeHandle cheat_process_debug_handle = os::InvalidNativeHandle;
|
||||
CheatProcessMetadata cheat_process_metadata = {};
|
||||
os::SdkMutex m_cheat_lock;
|
||||
os::Event m_unsafe_break_event;
|
||||
os::Event m_debug_events_event; /* Autoclear. */
|
||||
os::ThreadType m_detect_thread, m_debug_events_thread;
|
||||
os::SystemEvent m_cheat_process_event;
|
||||
os::NativeHandle m_cheat_process_debug_handle = os::InvalidNativeHandle;
|
||||
CheatProcessMetadata m_cheat_process_metadata = {};
|
||||
|
||||
os::ThreadType vm_thread;
|
||||
bool broken_unsafe = false;
|
||||
bool needs_reload_vm = false;
|
||||
CheatVirtualMachine cheat_vm;
|
||||
os::ThreadType m_vm_thread;
|
||||
bool m_broken_unsafe = false;
|
||||
bool m_needs_reload_vm = false;
|
||||
CheatVirtualMachine m_cheat_vm;
|
||||
|
||||
bool enable_cheats_by_default = true;
|
||||
bool always_save_cheat_toggles = false;
|
||||
bool should_save_cheat_toggles = false;
|
||||
CheatEntry cheat_entries[MaxCheatCount] = {};
|
||||
FrozenAddressMap frozen_addresses_map = {};
|
||||
bool m_enable_cheats_by_default = true;
|
||||
bool m_always_save_cheat_toggles = false;
|
||||
bool m_should_save_cheat_toggles = false;
|
||||
CheatEntry m_cheat_entries[MaxCheatCount] = {};
|
||||
FrozenAddressMap m_frozen_addresses_map = {};
|
||||
|
||||
alignas(os::MemoryPageSize) u8 detect_thread_stack[ThreadStackSize] = {};
|
||||
alignas(os::MemoryPageSize) u8 debug_events_thread_stack[ThreadStackSize] = {};
|
||||
alignas(os::MemoryPageSize) u8 vm_thread_stack[ThreadStackSize] = {};
|
||||
alignas(os::MemoryPageSize) u8 m_detect_thread_stack[ThreadStackSize] = {};
|
||||
alignas(os::MemoryPageSize) u8 m_debug_events_thread_stack[ThreadStackSize] = {};
|
||||
alignas(os::MemoryPageSize) u8 m_vm_thread_stack[ThreadStackSize] = {};
|
||||
private:
|
||||
static void DetectLaunchThread(void *_this);
|
||||
static void VirtualMachineThread(void *_this);
|
||||
|
@ -119,18 +119,18 @@ namespace ams::dmnt::cheat::impl {
|
|||
void SaveCheatToggles(const ncm::ProgramId program_id);
|
||||
|
||||
bool GetNeedsReloadVm() const {
|
||||
return this->needs_reload_vm;
|
||||
return m_needs_reload_vm;
|
||||
}
|
||||
|
||||
void SetNeedsReloadVm(bool reload) {
|
||||
this->needs_reload_vm = reload;
|
||||
m_needs_reload_vm = reload;
|
||||
}
|
||||
|
||||
|
||||
void ResetCheatEntry(size_t i) {
|
||||
if (i < MaxCheatCount) {
|
||||
std::memset(this->cheat_entries + i, 0, sizeof(this->cheat_entries[i]));
|
||||
this->cheat_entries[i].cheat_id = i;
|
||||
std::memset(m_cheat_entries + i, 0, sizeof(m_cheat_entries[i]));
|
||||
m_cheat_entries[i].cheat_id = i;
|
||||
|
||||
this->SetNeedsReloadVm(true);
|
||||
}
|
||||
|
@ -141,12 +141,12 @@ namespace ams::dmnt::cheat::impl {
|
|||
this->ResetCheatEntry(i);
|
||||
}
|
||||
|
||||
this->cheat_vm.ResetStaticRegisters();
|
||||
m_cheat_vm.ResetStaticRegisters();
|
||||
}
|
||||
|
||||
CheatEntry *GetCheatEntryById(size_t i) {
|
||||
if (i < MaxCheatCount) {
|
||||
return this->cheat_entries + i;
|
||||
return m_cheat_entries + i;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
@ -155,8 +155,8 @@ namespace ams::dmnt::cheat::impl {
|
|||
CheatEntry *GetCheatEntryByReadableName(const char *readable_name) {
|
||||
/* Check all non-master cheats for match. */
|
||||
for (size_t i = 1; i < MaxCheatCount; i++) {
|
||||
if (std::strncmp(this->cheat_entries[i].definition.readable_name, readable_name, sizeof(this->cheat_entries[i].definition.readable_name)) == 0) {
|
||||
return this->cheat_entries + i;
|
||||
if (std::strncmp(m_cheat_entries[i].definition.readable_name, readable_name, sizeof(m_cheat_entries[i].definition.readable_name)) == 0) {
|
||||
return m_cheat_entries + i;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,8 +166,8 @@ namespace ams::dmnt::cheat::impl {
|
|||
CheatEntry *GetFreeCheatEntry() {
|
||||
/* Check all non-master cheats for availability. */
|
||||
for (size_t i = 1; i < MaxCheatCount; i++) {
|
||||
if (this->cheat_entries[i].definition.num_opcodes == 0) {
|
||||
return this->cheat_entries + i;
|
||||
if (m_cheat_entries[i].definition.num_opcodes == 0) {
|
||||
return m_cheat_entries + i;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,53 +175,53 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
void CloseActiveCheatProcess() {
|
||||
if (this->cheat_process_debug_handle != os::InvalidNativeHandle) {
|
||||
if (m_cheat_process_debug_handle != os::InvalidNativeHandle) {
|
||||
/* We don't need to do any unsafe brekaing. */
|
||||
this->broken_unsafe = false;
|
||||
this->unsafe_break_event.Signal();
|
||||
m_broken_unsafe = false;
|
||||
m_unsafe_break_event.Signal();
|
||||
|
||||
/* Knock out the debug events thread. */
|
||||
os::CancelThreadSynchronization(std::addressof(this->debug_events_thread));
|
||||
os::CancelThreadSynchronization(std::addressof(m_debug_events_thread));
|
||||
|
||||
/* Close resources. */
|
||||
R_ABORT_UNLESS(svc::CloseHandle(this->cheat_process_debug_handle));
|
||||
this->cheat_process_debug_handle = os::InvalidNativeHandle;
|
||||
R_ABORT_UNLESS(svc::CloseHandle(m_cheat_process_debug_handle));
|
||||
m_cheat_process_debug_handle = os::InvalidNativeHandle;
|
||||
|
||||
/* Save cheat toggles. */
|
||||
if (this->always_save_cheat_toggles || this->should_save_cheat_toggles) {
|
||||
this->SaveCheatToggles(this->cheat_process_metadata.program_id);
|
||||
this->should_save_cheat_toggles = false;
|
||||
if (m_always_save_cheat_toggles || m_should_save_cheat_toggles) {
|
||||
this->SaveCheatToggles(m_cheat_process_metadata.program_id);
|
||||
m_should_save_cheat_toggles = false;
|
||||
}
|
||||
|
||||
/* Clear metadata. */
|
||||
static_assert(util::is_pod<decltype(this->cheat_process_metadata)>::value, "CheatProcessMetadata definition!");
|
||||
std::memset(std::addressof(this->cheat_process_metadata), 0, sizeof(this->cheat_process_metadata));
|
||||
static_assert(util::is_pod<decltype(m_cheat_process_metadata)>::value, "CheatProcessMetadata definition!");
|
||||
std::memset(std::addressof(m_cheat_process_metadata), 0, sizeof(m_cheat_process_metadata));
|
||||
|
||||
/* Clear cheat list. */
|
||||
this->ResetAllCheatEntries();
|
||||
|
||||
/* Clear frozen addresses. */
|
||||
{
|
||||
auto it = this->frozen_addresses_map.begin();
|
||||
while (it != this->frozen_addresses_map.end()) {
|
||||
auto it = m_frozen_addresses_map.begin();
|
||||
while (it != m_frozen_addresses_map.end()) {
|
||||
FrozenAddressMapEntry *entry = std::addressof(*it);
|
||||
it = this->frozen_addresses_map.erase(it);
|
||||
it = m_frozen_addresses_map.erase(it);
|
||||
DeallocateFrozenAddress(entry);
|
||||
}
|
||||
}
|
||||
|
||||
/* Signal to our fans. */
|
||||
this->cheat_process_event.Signal();
|
||||
m_cheat_process_event.Signal();
|
||||
}
|
||||
}
|
||||
|
||||
bool HasActiveCheatProcess() {
|
||||
/* Note: This function *MUST* be called only with the cheat lock held. */
|
||||
os::ProcessId pid;
|
||||
bool has_cheat_process = this->cheat_process_debug_handle != os::InvalidNativeHandle;
|
||||
has_cheat_process &= R_SUCCEEDED(os::GetProcessId(std::addressof(pid), this->cheat_process_debug_handle));
|
||||
bool has_cheat_process = m_cheat_process_debug_handle != os::InvalidNativeHandle;
|
||||
has_cheat_process &= R_SUCCEEDED(os::GetProcessId(std::addressof(pid), m_cheat_process_debug_handle));
|
||||
has_cheat_process &= R_SUCCEEDED(pm::dmnt::GetApplicationProcessId(std::addressof(pid)));
|
||||
has_cheat_process &= (pid == this->cheat_process_metadata.process_id);
|
||||
has_cheat_process &= (pid == m_cheat_process_metadata.process_id);
|
||||
|
||||
if (!has_cheat_process) {
|
||||
this->CloseActiveCheatProcess();
|
||||
|
@ -236,7 +236,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
os::NativeHandle GetCheatProcessHandle() const {
|
||||
return this->cheat_process_debug_handle;
|
||||
return m_cheat_process_debug_handle;
|
||||
}
|
||||
|
||||
os::NativeHandle HookToCreateApplicationProcess() const {
|
||||
|
@ -250,50 +250,50 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
public:
|
||||
CheatProcessManager() : cheat_lock(), unsafe_break_event(os::EventClearMode_ManualClear), debug_events_event(os::EventClearMode_AutoClear), cheat_process_event(os::EventClearMode_AutoClear, true) {
|
||||
CheatProcessManager() : m_cheat_lock(), m_unsafe_break_event(os::EventClearMode_ManualClear), m_debug_events_event(os::EventClearMode_AutoClear), m_cheat_process_event(os::EventClearMode_AutoClear, true) {
|
||||
/* Learn whether we should enable cheats by default. */
|
||||
{
|
||||
u8 en = 0;
|
||||
if (settings::fwdbg::GetSettingsItemValue(std::addressof(en), sizeof(en), "atmosphere", "dmnt_cheats_enabled_by_default") == sizeof(en)) {
|
||||
this->enable_cheats_by_default = (en != 0);
|
||||
m_enable_cheats_by_default = (en != 0);
|
||||
}
|
||||
|
||||
en = 0;
|
||||
if (settings::fwdbg::GetSettingsItemValue( std::addressof(en), sizeof(en), "atmosphere", "dmnt_always_save_cheat_toggles") == sizeof(en)) {
|
||||
this->always_save_cheat_toggles = (en != 0);
|
||||
m_always_save_cheat_toggles = (en != 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Spawn application detection thread, spawn cheat vm thread. */
|
||||
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->detect_thread), DetectLaunchThread, this, this->detect_thread_stack, ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, CheatDetect)));
|
||||
os::SetThreadNamePointer(std::addressof(this->detect_thread), AMS_GET_SYSTEM_THREAD_NAME(dmnt, CheatDetect));
|
||||
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->vm_thread), VirtualMachineThread, this, this->vm_thread_stack, ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, CheatVirtualMachine)));
|
||||
os::SetThreadNamePointer(std::addressof(this->vm_thread), AMS_GET_SYSTEM_THREAD_NAME(dmnt, CheatVirtualMachine));
|
||||
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->debug_events_thread), DebugEventsThread, this, this->debug_events_thread_stack, ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, CheatDebugEvents)));
|
||||
os::SetThreadNamePointer(std::addressof(this->debug_events_thread), AMS_GET_SYSTEM_THREAD_NAME(dmnt, CheatDebugEvents));
|
||||
R_ABORT_UNLESS(os::CreateThread(std::addressof(m_detect_thread), DetectLaunchThread, this, m_detect_thread_stack, ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, CheatDetect)));
|
||||
os::SetThreadNamePointer(std::addressof(m_detect_thread), AMS_GET_SYSTEM_THREAD_NAME(dmnt, CheatDetect));
|
||||
R_ABORT_UNLESS(os::CreateThread(std::addressof(m_vm_thread), VirtualMachineThread, this, m_vm_thread_stack, ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, CheatVirtualMachine)));
|
||||
os::SetThreadNamePointer(std::addressof(m_vm_thread), AMS_GET_SYSTEM_THREAD_NAME(dmnt, CheatVirtualMachine));
|
||||
R_ABORT_UNLESS(os::CreateThread(std::addressof(m_debug_events_thread), DebugEventsThread, this, m_debug_events_thread_stack, ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, CheatDebugEvents)));
|
||||
os::SetThreadNamePointer(std::addressof(m_debug_events_thread), AMS_GET_SYSTEM_THREAD_NAME(dmnt, CheatDebugEvents));
|
||||
|
||||
/* Start threads. */
|
||||
os::StartThread(std::addressof(this->detect_thread));
|
||||
os::StartThread(std::addressof(this->vm_thread));
|
||||
os::StartThread(std::addressof(this->debug_events_thread));
|
||||
os::StartThread(std::addressof(m_detect_thread));
|
||||
os::StartThread(std::addressof(m_vm_thread));
|
||||
os::StartThread(std::addressof(m_debug_events_thread));
|
||||
}
|
||||
|
||||
bool GetHasActiveCheatProcess() {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
return this->HasActiveCheatProcess();
|
||||
}
|
||||
|
||||
os::NativeHandle GetCheatProcessEventHandle() const {
|
||||
return this->cheat_process_event.GetReadableHandle();
|
||||
return m_cheat_process_event.GetReadableHandle();
|
||||
}
|
||||
|
||||
Result GetCheatProcessMetadata(CheatProcessMetadata *out) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
std::memcpy(out, std::addressof(this->cheat_process_metadata), sizeof(*out));
|
||||
std::memcpy(out, std::addressof(m_cheat_process_metadata), sizeof(*out));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
|
@ -313,7 +313,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
Result WriteCheatProcessMemoryUnsafe(u64 proc_addr, const void *data, size_t size) {
|
||||
R_TRY(svc::WriteDebugProcessMemory(this->GetCheatProcessHandle(), reinterpret_cast<uintptr_t>(data), proc_addr, size));
|
||||
|
||||
for (auto &entry : this->frozen_addresses_map) {
|
||||
for (auto &entry : m_frozen_addresses_map) {
|
||||
/* Get address/value. */
|
||||
const u64 address = entry.GetAddress();
|
||||
auto &value = entry.GetValue();
|
||||
|
@ -335,20 +335,20 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result PauseCheatProcessUnsafe() {
|
||||
this->broken_unsafe = true;
|
||||
this->unsafe_break_event.Clear();
|
||||
m_broken_unsafe = true;
|
||||
m_unsafe_break_event.Clear();
|
||||
return svc::BreakDebugProcess(this->GetCheatProcessHandle());
|
||||
}
|
||||
|
||||
Result ResumeCheatProcessUnsafe() {
|
||||
this->broken_unsafe = false;
|
||||
this->unsafe_break_event.Signal();
|
||||
m_broken_unsafe = false;
|
||||
m_unsafe_break_event.Signal();
|
||||
dmnt::cheat::impl::ContinueCheatProcess(this->GetCheatProcessHandle());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetCheatProcessMappingCount(u64 *out_count) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
|
@ -372,7 +372,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result GetCheatProcessMappings(svc::MemoryInfo *mappings, size_t max_count, u64 *out_count, u64 offset) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
|
@ -399,7 +399,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result ReadCheatProcessMemory(u64 proc_addr, void *out_data, size_t size) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
|
@ -407,7 +407,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result WriteCheatProcessMemory(u64 proc_addr, const void *data, size_t size) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
|
@ -415,7 +415,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result QueryCheatProcessMemory(svc::MemoryInfo *mapping, u64 address) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
|
@ -424,7 +424,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result PauseCheatProcess() {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
|
@ -432,7 +432,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result ResumeCheatProcess() {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
|
@ -440,13 +440,13 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result GetCheatCount(u64 *out_count) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
size_t count = 0;
|
||||
for (size_t i = 0; i < MaxCheatCount; i++) {
|
||||
if (this->cheat_entries[i].definition.num_opcodes) {
|
||||
if (m_cheat_entries[i].definition.num_opcodes) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
@ -456,16 +456,16 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result GetCheats(CheatEntry *out_cheats, size_t max_count, u64 *out_count, u64 offset) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
size_t count = 0, total_count = 0;
|
||||
for (size_t i = 0; i < MaxCheatCount && count < max_count; i++) {
|
||||
if (this->cheat_entries[i].definition.num_opcodes) {
|
||||
if (m_cheat_entries[i].definition.num_opcodes) {
|
||||
total_count++;
|
||||
if (total_count > offset) {
|
||||
out_cheats[count++] = this->cheat_entries[i];
|
||||
out_cheats[count++] = m_cheat_entries[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -475,7 +475,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result GetCheatById(CheatEntry *out_cheat, u32 cheat_id) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
|
@ -488,7 +488,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result ToggleCheat(u32 cheat_id) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
|
@ -507,7 +507,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result AddCheat(u32 *out_id, const CheatDefinition &def, bool enabled) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
|
@ -530,7 +530,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result RemoveCheat(u32 cheat_id) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
R_UNLESS(cheat_id < MaxCheatCount, dmnt::cheat::ResultCheatUnknownId());
|
||||
|
@ -544,14 +544,14 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result SetMasterCheat(const CheatDefinition &def) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
R_UNLESS(def.num_opcodes != 0, dmnt::cheat::ResultCheatInvalid());
|
||||
R_UNLESS(def.num_opcodes <= util::size(def.opcodes), dmnt::cheat::ResultCheatInvalid());
|
||||
|
||||
CheatEntry *master_entry = this->cheat_entries + 0;
|
||||
CheatEntry *master_entry = m_cheat_entries + 0;
|
||||
|
||||
master_entry->enabled = true;
|
||||
master_entry->definition = def;
|
||||
|
@ -563,50 +563,50 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result ReadStaticRegister(u64 *out, size_t which) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
R_UNLESS(which < CheatVirtualMachine::NumStaticRegisters, dmnt::cheat::ResultCheatInvalid());
|
||||
|
||||
*out = this->cheat_vm.GetStaticRegister(which);
|
||||
*out = m_cheat_vm.GetStaticRegister(which);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result WriteStaticRegister(size_t which, u64 value) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
R_UNLESS(which < CheatVirtualMachine::NumStaticRegisters, dmnt::cheat::ResultCheatInvalid());
|
||||
|
||||
this->cheat_vm.SetStaticRegister(which, value);
|
||||
m_cheat_vm.SetStaticRegister(which, value);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ResetStaticRegisters() {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
this->cheat_vm.ResetStaticRegisters();
|
||||
m_cheat_vm.ResetStaticRegisters();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetFrozenAddressCount(u64 *out_count) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
*out_count = std::distance(this->frozen_addresses_map.begin(), this->frozen_addresses_map.end());
|
||||
*out_count = std::distance(m_frozen_addresses_map.begin(), m_frozen_addresses_map.end());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetFrozenAddresses(FrozenAddressEntry *frz_addrs, size_t max_count, u64 *out_count, u64 offset) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
u64 total_count = 0, written_count = 0;
|
||||
for (const auto &entry : this->frozen_addresses_map) {
|
||||
for (const auto &entry : m_frozen_addresses_map) {
|
||||
if (written_count >= max_count) {
|
||||
break;
|
||||
}
|
||||
|
@ -624,12 +624,12 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result GetFrozenAddress(FrozenAddressEntry *frz_addr, u64 address) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
const auto it = this->frozen_addresses_map.find_key(address);
|
||||
R_UNLESS(it != this->frozen_addresses_map.end(), dmnt::cheat::ResultFrozenAddressNotFound());
|
||||
const auto it = m_frozen_addresses_map.find_key(address);
|
||||
R_UNLESS(it != m_frozen_addresses_map.end(), dmnt::cheat::ResultFrozenAddressNotFound());
|
||||
|
||||
frz_addr->address = it->GetAddress();
|
||||
frz_addr->value = it->GetValue();
|
||||
|
@ -637,12 +637,12 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result EnableFrozenAddress(u64 *out_value, u64 address, u64 width) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
const auto it = this->frozen_addresses_map.find_key(address);
|
||||
R_UNLESS(it == this->frozen_addresses_map.end(), dmnt::cheat::ResultFrozenAddressAlreadyExists());
|
||||
const auto it = m_frozen_addresses_map.find_key(address);
|
||||
R_UNLESS(it == m_frozen_addresses_map.end(), dmnt::cheat::ResultFrozenAddressAlreadyExists());
|
||||
|
||||
FrozenAddressValue value = {};
|
||||
value.width = width;
|
||||
|
@ -651,21 +651,21 @@ namespace ams::dmnt::cheat::impl {
|
|||
FrozenAddressMapEntry *entry = AllocateFrozenAddress(address, value);
|
||||
R_UNLESS(entry != nullptr, dmnt::cheat::ResultFrozenAddressOutOfResource());
|
||||
|
||||
this->frozen_addresses_map.insert(*entry);
|
||||
m_frozen_addresses_map.insert(*entry);
|
||||
*out_value = value.value;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result DisableFrozenAddress(u64 address) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
const auto it = this->frozen_addresses_map.find_key(address);
|
||||
R_UNLESS(it != this->frozen_addresses_map.end(), dmnt::cheat::ResultFrozenAddressNotFound());
|
||||
const auto it = m_frozen_addresses_map.find_key(address);
|
||||
R_UNLESS(it != m_frozen_addresses_map.end(), dmnt::cheat::ResultFrozenAddressNotFound());
|
||||
|
||||
FrozenAddressMapEntry *entry = std::addressof(*it);
|
||||
this->frozen_addresses_map.erase(it);
|
||||
m_frozen_addresses_map.erase(it);
|
||||
DeallocateFrozenAddress(entry);
|
||||
|
||||
return ResultSuccess();
|
||||
|
@ -674,37 +674,37 @@ namespace ams::dmnt::cheat::impl {
|
|||
};
|
||||
|
||||
void CheatProcessManager::DetectLaunchThread(void *_this) {
|
||||
CheatProcessManager *this_ptr = reinterpret_cast<CheatProcessManager *>(_this);
|
||||
CheatProcessManager *manager = reinterpret_cast<CheatProcessManager *>(_this);
|
||||
Event hook;
|
||||
while (true) {
|
||||
eventLoadRemote(std::addressof(hook), this_ptr->HookToCreateApplicationProcess(), true);
|
||||
eventLoadRemote(std::addressof(hook), manager->HookToCreateApplicationProcess(), true);
|
||||
if (R_SUCCEEDED(eventWait(std::addressof(hook), std::numeric_limits<u64>::max()))) {
|
||||
this_ptr->AttachToApplicationProcess(true);
|
||||
manager->AttachToApplicationProcess(true);
|
||||
}
|
||||
eventClose(std::addressof(hook));
|
||||
}
|
||||
}
|
||||
|
||||
void CheatProcessManager::DebugEventsThread(void *_this) {
|
||||
CheatProcessManager *this_ptr = reinterpret_cast<CheatProcessManager *>(_this);
|
||||
CheatProcessManager *manager = reinterpret_cast<CheatProcessManager *>(_this);
|
||||
while (true) {
|
||||
/* Atomically wait (and clear) signal for new process. */
|
||||
this_ptr->debug_events_event.Wait();
|
||||
manager->m_debug_events_event.Wait();
|
||||
while (true) {
|
||||
os::NativeHandle cheat_process_handle = this_ptr->GetCheatProcessHandle();
|
||||
os::NativeHandle cheat_process_handle = manager->GetCheatProcessHandle();
|
||||
s32 dummy;
|
||||
while (cheat_process_handle != os::InvalidNativeHandle && R_SUCCEEDED(svc::WaitSynchronization(std::addressof(dummy), std::addressof(cheat_process_handle), 1, std::numeric_limits<u64>::max()))) {
|
||||
this_ptr->cheat_lock.Lock();
|
||||
ON_SCOPE_EXIT { this_ptr->cheat_lock.Unlock(); };
|
||||
manager->m_cheat_lock.Lock();
|
||||
ON_SCOPE_EXIT { manager->m_cheat_lock.Unlock(); };
|
||||
{
|
||||
ON_SCOPE_EXIT { cheat_process_handle = this_ptr->GetCheatProcessHandle(); };
|
||||
ON_SCOPE_EXIT { cheat_process_handle = manager->GetCheatProcessHandle(); };
|
||||
|
||||
/* If we did an unsafe break, wait until we're not broken. */
|
||||
if (this_ptr->broken_unsafe) {
|
||||
this_ptr->cheat_lock.Unlock();
|
||||
this_ptr->unsafe_break_event.Wait();
|
||||
this_ptr->cheat_lock.Lock();
|
||||
if (this_ptr->GetCheatProcessHandle() != os::InvalidNativeHandle) {
|
||||
if (manager->m_broken_unsafe) {
|
||||
manager->m_cheat_lock.Unlock();
|
||||
manager->m_unsafe_break_event.Wait();
|
||||
manager->m_cheat_lock.Lock();
|
||||
if (manager->GetCheatProcessHandle() != os::InvalidNativeHandle) {
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
|
@ -712,10 +712,10 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
/* Handle any pending debug events. */
|
||||
if (this_ptr->HasActiveCheatProcess()) {
|
||||
R_TRY_CATCH(dmnt::cheat::impl::ContinueCheatProcess(this_ptr->GetCheatProcessHandle())) {
|
||||
if (manager->HasActiveCheatProcess()) {
|
||||
R_TRY_CATCH(dmnt::cheat::impl::ContinueCheatProcess(manager->GetCheatProcessHandle())) {
|
||||
R_CATCH(svc::ResultProcessTerminated) {
|
||||
this_ptr->CloseActiveCheatProcess();
|
||||
manager->CloseActiveCheatProcess();
|
||||
break;
|
||||
}
|
||||
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
|
||||
|
@ -725,8 +725,8 @@ namespace ams::dmnt::cheat::impl {
|
|||
|
||||
/* WaitSynchronization failed. This means someone canceled our synchronization, possibly us. */
|
||||
/* Let's check if we should quit! */
|
||||
std::scoped_lock lk(this_ptr->cheat_lock);
|
||||
if (!this_ptr->HasActiveCheatProcess()) {
|
||||
std::scoped_lock lk(manager->m_cheat_lock);
|
||||
if (!manager->HasActiveCheatProcess()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -734,30 +734,30 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
void CheatProcessManager::VirtualMachineThread(void *_this) {
|
||||
CheatProcessManager *this_ptr = reinterpret_cast<CheatProcessManager *>(_this);
|
||||
CheatProcessManager *manager = reinterpret_cast<CheatProcessManager *>(_this);
|
||||
while (true) {
|
||||
/* Apply cheats. */
|
||||
{
|
||||
std::scoped_lock lk(this_ptr->cheat_lock);
|
||||
std::scoped_lock lk(manager->m_cheat_lock);
|
||||
|
||||
if (this_ptr->HasActiveCheatProcess()) {
|
||||
if (manager->HasActiveCheatProcess()) {
|
||||
/* Execute VM. */
|
||||
if (!this_ptr->GetNeedsReloadVm() || this_ptr->cheat_vm.LoadProgram(this_ptr->cheat_entries, util::size(this_ptr->cheat_entries))) {
|
||||
this_ptr->SetNeedsReloadVm(false);
|
||||
if (!manager->GetNeedsReloadVm() || manager->m_cheat_vm.LoadProgram(manager->m_cheat_entries, util::size(manager->m_cheat_entries))) {
|
||||
manager->SetNeedsReloadVm(false);
|
||||
|
||||
/* Execute program only if it has opcodes. */
|
||||
if (this_ptr->cheat_vm.GetProgramSize()) {
|
||||
this_ptr->cheat_vm.Execute(std::addressof(this_ptr->cheat_process_metadata));
|
||||
if (manager->m_cheat_vm.GetProgramSize()) {
|
||||
manager->m_cheat_vm.Execute(std::addressof(manager->m_cheat_process_metadata));
|
||||
}
|
||||
}
|
||||
|
||||
/* Apply frozen addresses. */
|
||||
for (const auto &entry : this_ptr->frozen_addresses_map) {
|
||||
for (const auto &entry : manager->m_frozen_addresses_map) {
|
||||
const auto address = entry.GetAddress();
|
||||
const auto &value = entry.GetValue();
|
||||
|
||||
/* Use Write SVC directly, to avoid the usual frozen address update logic. */
|
||||
svc::WriteDebugProcessMemory(this_ptr->GetCheatProcessHandle(), reinterpret_cast<uintptr_t>(std::addressof(value.value)), address, value.width);
|
||||
svc::WriteDebugProcessMemory(manager->GetCheatProcessHandle(), reinterpret_cast<uintptr_t>(std::addressof(value.value)), address, value.width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -778,7 +778,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
Result CheatProcessManager::AttachToApplicationProcess(bool on_process_launch) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
std::scoped_lock lk(m_cheat_lock);
|
||||
|
||||
/* Close the active process, if needed. */
|
||||
{
|
||||
|
@ -792,12 +792,12 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
/* Get the application process's ID. */
|
||||
R_ABORT_UNLESS_IF_NEW_PROCESS(pm::dmnt::GetApplicationProcessId(std::addressof(this->cheat_process_metadata.process_id)));
|
||||
R_ABORT_UNLESS_IF_NEW_PROCESS(pm::dmnt::GetApplicationProcessId(std::addressof(m_cheat_process_metadata.process_id)));
|
||||
auto proc_guard = SCOPE_GUARD {
|
||||
if (on_process_launch) {
|
||||
this->StartProcess(this->cheat_process_metadata.process_id);
|
||||
this->StartProcess(m_cheat_process_metadata.process_id);
|
||||
}
|
||||
this->cheat_process_metadata.process_id = os::ProcessId{};
|
||||
m_cheat_process_metadata.process_id = os::ProcessId{};
|
||||
};
|
||||
|
||||
/* Get process handle, use it to learn memory extents. */
|
||||
|
@ -806,17 +806,17 @@ namespace ams::dmnt::cheat::impl {
|
|||
ncm::ProgramLocation loc = {};
|
||||
cfg::OverrideStatus status = {};
|
||||
|
||||
R_ABORT_UNLESS_IF_NEW_PROCESS(pm::dmnt::AtmosphereGetProcessInfo(std::addressof(proc_h), std::addressof(loc), std::addressof(status), this->cheat_process_metadata.process_id));
|
||||
R_ABORT_UNLESS_IF_NEW_PROCESS(pm::dmnt::AtmosphereGetProcessInfo(std::addressof(proc_h), std::addressof(loc), std::addressof(status), m_cheat_process_metadata.process_id));
|
||||
ON_SCOPE_EXIT { os::CloseNativeHandle(proc_h); };
|
||||
|
||||
this->cheat_process_metadata.program_id = loc.program_id;
|
||||
m_cheat_process_metadata.program_id = loc.program_id;
|
||||
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(this->cheat_process_metadata.heap_extents.base), svc::InfoType_HeapRegionAddress, proc_h, 0));
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(this->cheat_process_metadata.heap_extents.size), svc::InfoType_HeapRegionSize, proc_h, 0));
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(this->cheat_process_metadata.alias_extents.base), svc::InfoType_AliasRegionAddress, proc_h, 0));
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(this->cheat_process_metadata.alias_extents.size), svc::InfoType_AliasRegionSize, proc_h, 0));
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(this->cheat_process_metadata.aslr_extents.base), svc::InfoType_AslrRegionAddress, proc_h, 0));
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(this->cheat_process_metadata.aslr_extents.size), svc::InfoType_AslrRegionSize, proc_h, 0));
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(m_cheat_process_metadata.heap_extents.base), svc::InfoType_HeapRegionAddress, proc_h, 0));
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(m_cheat_process_metadata.heap_extents.size), svc::InfoType_HeapRegionSize, proc_h, 0));
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(m_cheat_process_metadata.alias_extents.base), svc::InfoType_AliasRegionAddress, proc_h, 0));
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(m_cheat_process_metadata.alias_extents.size), svc::InfoType_AliasRegionSize, proc_h, 0));
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(m_cheat_process_metadata.aslr_extents.base), svc::InfoType_AslrRegionAddress, proc_h, 0));
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(m_cheat_process_metadata.aslr_extents.size), svc::InfoType_AslrRegionSize, proc_h, 0));
|
||||
|
||||
/* If new process launch, we may not want to actually attach. */
|
||||
if (on_process_launch) {
|
||||
|
@ -830,7 +830,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
s32 num_modules;
|
||||
|
||||
/* TODO: ldr::dmnt:: */
|
||||
R_ABORT_UNLESS_IF_NEW_PROCESS(ldrDmntGetProcessModuleInfo(static_cast<u64>(this->cheat_process_metadata.process_id), proc_modules, util::size(proc_modules), std::addressof(num_modules)));
|
||||
R_ABORT_UNLESS_IF_NEW_PROCESS(ldrDmntGetProcessModuleInfo(static_cast<u64>(m_cheat_process_metadata.process_id), proc_modules, util::size(proc_modules), std::addressof(num_modules)));
|
||||
|
||||
/* All applications must have two modules. */
|
||||
/* Only accept one (which means we're attaching to HBL) */
|
||||
|
@ -844,42 +844,42 @@ namespace ams::dmnt::cheat::impl {
|
|||
return dmnt::cheat::ResultCheatNotAttached();
|
||||
}
|
||||
|
||||
this->cheat_process_metadata.main_nso_extents.base = proc_module->base_address;
|
||||
this->cheat_process_metadata.main_nso_extents.size = proc_module->size;
|
||||
std::memcpy(this->cheat_process_metadata.main_nso_build_id, proc_module->build_id, sizeof(this->cheat_process_metadata.main_nso_build_id));
|
||||
m_cheat_process_metadata.main_nso_extents.base = proc_module->base_address;
|
||||
m_cheat_process_metadata.main_nso_extents.size = proc_module->size;
|
||||
std::memcpy(m_cheat_process_metadata.main_nso_build_id, proc_module->build_id, sizeof(m_cheat_process_metadata.main_nso_build_id));
|
||||
}
|
||||
|
||||
/* Read cheats off the SD. */
|
||||
if (!this->LoadCheats(this->cheat_process_metadata.program_id, this->cheat_process_metadata.main_nso_build_id) ||
|
||||
!this->LoadCheatToggles(this->cheat_process_metadata.program_id)) {
|
||||
if (!this->LoadCheats(m_cheat_process_metadata.program_id, m_cheat_process_metadata.main_nso_build_id) ||
|
||||
!this->LoadCheatToggles(m_cheat_process_metadata.program_id)) {
|
||||
/* If new process launch, require success. */
|
||||
R_UNLESS(!on_process_launch, dmnt::cheat::ResultCheatNotAttached());
|
||||
}
|
||||
|
||||
/* Open a debug handle. */
|
||||
svc::Handle debug_handle = svc::InvalidHandle;
|
||||
R_ABORT_UNLESS_IF_NEW_PROCESS(svc::DebugActiveProcess(std::addressof(debug_handle), this->cheat_process_metadata.process_id.value));
|
||||
R_ABORT_UNLESS_IF_NEW_PROCESS(svc::DebugActiveProcess(std::addressof(debug_handle), m_cheat_process_metadata.process_id.value));
|
||||
|
||||
/* Set our debug handle. */
|
||||
this->cheat_process_debug_handle = debug_handle;
|
||||
m_cheat_process_debug_handle = debug_handle;
|
||||
|
||||
/* Cancel process guard. */
|
||||
proc_guard.Cancel();
|
||||
|
||||
/* Reset broken state. */
|
||||
this->broken_unsafe = false;
|
||||
this->unsafe_break_event.Signal();
|
||||
m_broken_unsafe = false;
|
||||
m_unsafe_break_event.Signal();
|
||||
|
||||
/* If new process, start the process. */
|
||||
if (on_process_launch) {
|
||||
this->StartProcess(this->cheat_process_metadata.process_id);
|
||||
this->StartProcess(m_cheat_process_metadata.process_id);
|
||||
}
|
||||
|
||||
/* Signal to the debug events thread. */
|
||||
this->debug_events_event.Signal();
|
||||
m_debug_events_event.Signal();
|
||||
|
||||
/* Signal to our fans. */
|
||||
this->cheat_process_event.Signal();
|
||||
m_cheat_process_event.Signal();
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
@ -922,7 +922,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
i = j + 1;
|
||||
} else if (s[i] == '{') {
|
||||
/* We're parsing a master cheat. */
|
||||
cur_entry = std::addressof(this->cheat_entries[0]);
|
||||
cur_entry = std::addressof(m_cheat_entries[0]);
|
||||
|
||||
/* There can only be one master cheat. */
|
||||
if (cur_entry->definition.num_opcodes > 0) {
|
||||
|
@ -978,14 +978,14 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
/* Master cheat can't be disabled. */
|
||||
if (this->cheat_entries[0].definition.num_opcodes > 0) {
|
||||
this->cheat_entries[0].enabled = true;
|
||||
if (m_cheat_entries[0].definition.num_opcodes > 0) {
|
||||
m_cheat_entries[0].enabled = true;
|
||||
}
|
||||
|
||||
/* Enable all entries we parsed. */
|
||||
for (size_t i = 1; i < MaxCheatCount; i++) {
|
||||
if (this->cheat_entries[i].definition.num_opcodes > 0) {
|
||||
this->cheat_entries[i].enabled = this->enable_cheats_by_default;
|
||||
if (m_cheat_entries[i].definition.num_opcodes > 0) {
|
||||
m_cheat_entries[i].enabled = m_enable_cheats_by_default;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1098,7 +1098,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
|
||||
bool CheatProcessManager::LoadCheatToggles(const ncm::ProgramId program_id) {
|
||||
/* Unless we successfully parse, don't save toggles on close. */
|
||||
this->should_save_cheat_toggles = false;
|
||||
m_should_save_cheat_toggles = false;
|
||||
|
||||
/* Open the file for program_id. */
|
||||
fs::FileHandle file;
|
||||
|
@ -1130,8 +1130,8 @@ namespace ams::dmnt::cheat::impl {
|
|||
g_text_file_buffer[file_size] = '\x00';
|
||||
|
||||
/* Parse toggle buffer. */
|
||||
this->should_save_cheat_toggles = this->ParseCheatToggles(g_text_file_buffer, std::strlen(g_text_file_buffer));
|
||||
return this->should_save_cheat_toggles;
|
||||
m_should_save_cheat_toggles = this->ParseCheatToggles(g_text_file_buffer, std::strlen(g_text_file_buffer));
|
||||
return m_should_save_cheat_toggles;
|
||||
}
|
||||
|
||||
void CheatProcessManager::SaveCheatToggles(const ncm::ProgramId program_id) {
|
||||
|
@ -1153,14 +1153,14 @@ namespace ams::dmnt::cheat::impl {
|
|||
|
||||
/* Save all non-master cheats. */
|
||||
for (size_t i = 1; i < MaxCheatCount; i++) {
|
||||
if (this->cheat_entries[i].definition.num_opcodes != 0) {
|
||||
util::SNPrintf(buf, sizeof(buf), "[%s]\n", this->cheat_entries[i].definition.readable_name);
|
||||
if (m_cheat_entries[i].definition.num_opcodes != 0) {
|
||||
util::SNPrintf(buf, sizeof(buf), "[%s]\n", m_cheat_entries[i].definition.readable_name);
|
||||
const size_t name_len = std::strlen(buf);
|
||||
if (R_SUCCEEDED(fs::WriteFile(file, offset, buf, name_len, fs::WriteOption::Flush))) {
|
||||
offset += name_len;
|
||||
}
|
||||
|
||||
const char *entry = this->cheat_entries[i].enabled ? "true\n" : "false\n";
|
||||
const char *entry = m_cheat_entries[i].enabled ? "true\n" : "false\n";
|
||||
const size_t entry_len = std::strlen(entry);
|
||||
if (R_SUCCEEDED(fs::WriteFile(file, offset, entry, entry_len, fs::WriteOption::Flush))) {
|
||||
offset += entry_len;
|
||||
|
|
|
@ -27,13 +27,13 @@ namespace ams::dmnt::cheat::impl {
|
|||
static constexpr size_t NumCores = 4;
|
||||
static constexpr size_t ThreadStackSize = os::MemoryPageSize;
|
||||
private:
|
||||
std::array<uintptr_t, NumCores> handle_message_queue_buffers;
|
||||
std::array<uintptr_t, NumCores> result_message_queue_buffers;
|
||||
std::array<os::MessageQueue, NumCores> handle_message_queues;
|
||||
std::array<os::MessageQueue, NumCores> result_message_queues;
|
||||
std::array<os::ThreadType, NumCores> threads;
|
||||
std::array<uintptr_t, NumCores> m_handle_message_queue_buffers;
|
||||
std::array<uintptr_t, NumCores> m_result_message_queue_buffers;
|
||||
std::array<os::MessageQueue, NumCores> m_handle_message_queues;
|
||||
std::array<os::MessageQueue, NumCores> m_result_message_queues;
|
||||
std::array<os::ThreadType, NumCores> m_threads;
|
||||
|
||||
alignas(os::MemoryPageSize) u8 thread_stacks[NumCores][ThreadStackSize];
|
||||
alignas(os::MemoryPageSize) u8 m_thread_stacks[NumCores][ThreadStackSize];
|
||||
private:
|
||||
static void PerCoreThreadFunction(void *_this) {
|
||||
/* This thread will wait on the appropriate message queue. */
|
||||
|
@ -73,12 +73,12 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
void SendHandle(size_t target_core, os::NativeHandle debug_handle) {
|
||||
this->handle_message_queues[target_core].Send(static_cast<uintptr_t>(debug_handle));
|
||||
m_handle_message_queues[target_core].Send(static_cast<uintptr_t>(debug_handle));
|
||||
}
|
||||
|
||||
os::NativeHandle WaitReceiveHandle(size_t core_id) {
|
||||
uintptr_t x = 0;
|
||||
this->handle_message_queues[core_id].Receive(&x);
|
||||
m_handle_message_queues[core_id].Receive(&x);
|
||||
return static_cast<os::NativeHandle>(x);
|
||||
}
|
||||
|
||||
|
@ -91,38 +91,38 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
void SendContinueResult(size_t target_core, Result result) {
|
||||
this->result_message_queues[target_core].Send(static_cast<uintptr_t>(result.GetValue()));
|
||||
m_result_message_queues[target_core].Send(static_cast<uintptr_t>(result.GetValue()));
|
||||
}
|
||||
|
||||
Result GetContinueResult(size_t core_id) {
|
||||
uintptr_t x = 0;
|
||||
this->result_message_queues[core_id].Receive(&x);
|
||||
m_result_message_queues[core_id].Receive(&x);
|
||||
return static_cast<Result>(x);
|
||||
}
|
||||
public:
|
||||
DebugEventsManager()
|
||||
: handle_message_queues{
|
||||
os::MessageQueue(std::addressof(handle_message_queue_buffers[0]), 1),
|
||||
os::MessageQueue(std::addressof(handle_message_queue_buffers[1]), 1),
|
||||
os::MessageQueue(std::addressof(handle_message_queue_buffers[2]), 1),
|
||||
os::MessageQueue(std::addressof(handle_message_queue_buffers[3]), 1)},
|
||||
result_message_queues{
|
||||
os::MessageQueue(std::addressof(result_message_queue_buffers[0]), 1),
|
||||
os::MessageQueue(std::addressof(result_message_queue_buffers[1]), 1),
|
||||
os::MessageQueue(std::addressof(result_message_queue_buffers[2]), 1),
|
||||
os::MessageQueue(std::addressof(result_message_queue_buffers[3]), 1)},
|
||||
thread_stacks{}
|
||||
: m_handle_message_queues{
|
||||
os::MessageQueue(std::addressof(m_handle_message_queue_buffers[0]), 1),
|
||||
os::MessageQueue(std::addressof(m_handle_message_queue_buffers[1]), 1),
|
||||
os::MessageQueue(std::addressof(m_handle_message_queue_buffers[2]), 1),
|
||||
os::MessageQueue(std::addressof(m_handle_message_queue_buffers[3]), 1)},
|
||||
m_result_message_queues{
|
||||
os::MessageQueue(std::addressof(m_result_message_queue_buffers[0]), 1),
|
||||
os::MessageQueue(std::addressof(m_result_message_queue_buffers[1]), 1),
|
||||
os::MessageQueue(std::addressof(m_result_message_queue_buffers[2]), 1),
|
||||
os::MessageQueue(std::addressof(m_result_message_queue_buffers[3]), 1)},
|
||||
m_thread_stacks{}
|
||||
{
|
||||
for (size_t i = 0; i < NumCores; i++) {
|
||||
/* Create thread. */
|
||||
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->threads[i]), PerCoreThreadFunction, this, this->thread_stacks[i], ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, MultiCoreEventManager), i));
|
||||
os::SetThreadNamePointer(std::addressof(this->threads[i]), AMS_GET_SYSTEM_THREAD_NAME(dmnt, MultiCoreEventManager));
|
||||
R_ABORT_UNLESS(os::CreateThread(std::addressof(m_threads[i]), PerCoreThreadFunction, this, m_thread_stacks[i], ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, MultiCoreEventManager), i));
|
||||
os::SetThreadNamePointer(std::addressof(m_threads[i]), AMS_GET_SYSTEM_THREAD_NAME(dmnt, MultiCoreEventManager));
|
||||
|
||||
/* Set core mask. */
|
||||
os::SetThreadCoreMask(std::addressof(this->threads[i]), i, (1u << i));
|
||||
os::SetThreadCoreMask(std::addressof(m_threads[i]), i, (1u << i));
|
||||
|
||||
/* Start thread. */
|
||||
os::StartThread(std::addressof(this->threads[i]));
|
||||
os::StartThread(std::addressof(m_threads[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,41 +46,41 @@ namespace ams::dmnt::cheat::impl {
|
|||
void CheatVirtualMachine::OpenDebugLogFile() {
|
||||
#ifdef DMNT_CHEAT_VM_DEBUG_LOG
|
||||
CloseDebugLogFile();
|
||||
R_ABORT_UNLESS(fs::OpenFile(std::addressof(this->debug_log_file), "sdmc:/atmosphere/cheat_vm_logs/debug_log.txt"));
|
||||
this->debug_log_file_offset = 0;
|
||||
R_ABORT_UNLESS(fs::OpenFile(std::addressof(m_debug_log_file), "sdmc:/atmosphere/cheat_vm_logs/debug_log.txt"));
|
||||
m_debug_log_file_offset = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CheatVirtualMachine::CloseDebugLogFile() {
|
||||
#ifdef DMNT_CHEAT_VM_DEBUG_LOG
|
||||
if (this->has_debug_log_file) {
|
||||
fs::CloseFile(this->debug_log_file);
|
||||
if (m_has_debug_log_file) {
|
||||
fs::CloseFile(m_debug_log_file);
|
||||
}
|
||||
this->has_debug_log_file = false;
|
||||
m_has_debug_log_file = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CheatVirtualMachine::LogToDebugFile(const char *format, ...) {
|
||||
#ifdef DMNT_CHEAT_VM_DEBUG_LOG
|
||||
if (!this->has_debug_log_file) {
|
||||
if (!m_has_debug_log_file) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
std::va_list vl;
|
||||
va_start(vl, format);
|
||||
util::VSNPrintf(this->debug_log_format_buf, sizeof(this->debug_log_format_buf) - 1, format, vl);
|
||||
util::VSNPrintf(m_debug_log_format_buf, sizeof(m_debug_log_format_buf) - 1, format, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
size_t fmt_len = std::strlen(this->debug_log_format_buf);
|
||||
if (this->debug_log_format_buf[fmt_len - 1] != '\n') {
|
||||
this->debug_log_format_buf[fmt_len + 0] = '\n';
|
||||
this->debug_log_format_buf[fmt_len + 1] = '\x00';
|
||||
size_t fmt_len = std::strlen(m_debug_log_format_buf);
|
||||
if (m_debug_log_format_buf[fmt_len - 1] != '\n') {
|
||||
m_debug_log_format_buf[fmt_len + 0] = '\n';
|
||||
m_debug_log_format_buf[fmt_len + 1] = '\x00';
|
||||
fmt_len += 1;
|
||||
}
|
||||
|
||||
fs::WriteFile(this->debug_log_file, this->debug_log_offset, this->debug_log_format_buf, fmt_len, fs::WriteOption::Flush);
|
||||
fs::WriteFile(m_debug_log_file, m_debug_log_offset, m_debug_log_format_buf, fmt_len, fs::WriteOption::Flush);
|
||||
#else
|
||||
AMS_UNUSED(format);
|
||||
#endif
|
||||
|
@ -295,10 +295,10 @@ namespace ams::dmnt::cheat::impl {
|
|||
|
||||
bool CheatVirtualMachine::DecodeNextOpcode(CheatVmOpcode *out) {
|
||||
/* If we've ever seen a decode failure, return false. */
|
||||
bool valid = this->decode_success;
|
||||
bool valid = m_decode_success;
|
||||
CheatVmOpcode opcode = {};
|
||||
ON_SCOPE_EXIT {
|
||||
this->decode_success &= valid;
|
||||
m_decode_success &= valid;
|
||||
if (valid) {
|
||||
*out = opcode;
|
||||
}
|
||||
|
@ -306,11 +306,11 @@ namespace ams::dmnt::cheat::impl {
|
|||
|
||||
/* Helper function for getting instruction dwords. */
|
||||
auto GetNextDword = [&]() {
|
||||
if (this->instruction_ptr >= this->num_opcodes) {
|
||||
if (m_instruction_ptr >= m_num_opcodes) {
|
||||
valid = false;
|
||||
return static_cast<u32>(0);
|
||||
}
|
||||
return this->program[this->instruction_ptr++];
|
||||
return m_program[m_instruction_ptr++];
|
||||
};
|
||||
|
||||
/* Helper function for parsing a VmInt. */
|
||||
|
@ -671,12 +671,12 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
void CheatVirtualMachine::SkipConditionalBlock(bool is_if) {
|
||||
if (this->condition_depth > 0) {
|
||||
if (m_condition_depth > 0) {
|
||||
/* We want to continue until we're out of the current block. */
|
||||
const size_t desired_depth = this->condition_depth - 1;
|
||||
const size_t desired_depth = m_condition_depth - 1;
|
||||
|
||||
CheatVmOpcode skip_opcode;
|
||||
while (this->condition_depth > desired_depth && this->DecodeNextOpcode(std::addressof(skip_opcode))) {
|
||||
while (m_condition_depth > desired_depth && this->DecodeNextOpcode(std::addressof(skip_opcode))) {
|
||||
/* Decode instructions until we see end of the current conditional block. */
|
||||
/* NOTE: This is broken in gateway's implementation. */
|
||||
/* Gateway currently checks for "0x2" instead of "0x20000000" */
|
||||
|
@ -685,18 +685,18 @@ namespace ams::dmnt::cheat::impl {
|
|||
|
||||
/* We also support nesting of conditional blocks, and Gateway does not. */
|
||||
if (skip_opcode.begin_conditional_block) {
|
||||
this->condition_depth++;
|
||||
m_condition_depth++;
|
||||
} else if (skip_opcode.opcode == CheatVmOpcodeType_EndConditionalBlock) {
|
||||
if (!skip_opcode.end_cond.is_else) {
|
||||
this->condition_depth--;
|
||||
} else if (is_if && this->condition_depth - 1 == desired_depth) {
|
||||
m_condition_depth--;
|
||||
} else if (is_if && m_condition_depth - 1 == desired_depth) {
|
||||
/* An if will continue to an else at the same depth. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Skipping, but this->condition_depth = 0. */
|
||||
/* Skipping, but m_condition_depth = 0. */
|
||||
/* This is an error condition. */
|
||||
/* This could occur with a mismatched "else" opcode, for example. */
|
||||
R_ABORT_UNLESS(ResultVirtualMachineInvalidConditionDepth());
|
||||
|
@ -735,29 +735,29 @@ namespace ams::dmnt::cheat::impl {
|
|||
|
||||
void CheatVirtualMachine::ResetState() {
|
||||
for (size_t i = 0; i < CheatVirtualMachine::NumRegisters; i++) {
|
||||
this->registers[i] = 0;
|
||||
this->saved_values[i] = 0;
|
||||
this->loop_tops[i] = 0;
|
||||
m_registers[i] = 0;
|
||||
m_saved_values[i] = 0;
|
||||
m_loop_tops[i] = 0;
|
||||
}
|
||||
this->instruction_ptr = 0;
|
||||
this->condition_depth = 0;
|
||||
this->decode_success = true;
|
||||
m_instruction_ptr = 0;
|
||||
m_condition_depth = 0;
|
||||
m_decode_success = true;
|
||||
}
|
||||
|
||||
bool CheatVirtualMachine::LoadProgram(const CheatEntry *cheats, size_t num_cheats) {
|
||||
/* Reset opcode count. */
|
||||
this->num_opcodes = 0;
|
||||
m_num_opcodes = 0;
|
||||
|
||||
for (size_t i = 0; i < num_cheats; i++) {
|
||||
if (cheats[i].enabled) {
|
||||
/* Bounds check. */
|
||||
if (cheats[i].definition.num_opcodes + this->num_opcodes > MaximumProgramOpcodeCount) {
|
||||
this->num_opcodes = 0;
|
||||
if (cheats[i].definition.num_opcodes + m_num_opcodes > MaximumProgramOpcodeCount) {
|
||||
m_num_opcodes = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t n = 0; n < cheats[i].definition.num_opcodes; n++) {
|
||||
this->program[this->num_opcodes++] = cheats[i].definition.opcodes[n];
|
||||
m_program[m_num_opcodes++] = cheats[i].definition.opcodes[n];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -785,27 +785,27 @@ namespace ams::dmnt::cheat::impl {
|
|||
|
||||
/* Loop until program finishes. */
|
||||
while (this->DecodeNextOpcode(std::addressof(cur_opcode))) {
|
||||
this->LogToDebugFile("Instruction Ptr: %04x\n", (u32)this->instruction_ptr);
|
||||
this->LogToDebugFile("Instruction Ptr: %04x\n", (u32)m_instruction_ptr);
|
||||
|
||||
for (size_t i = 0; i < NumRegisters; i++) {
|
||||
this->LogToDebugFile("Registers[%02x]: %016lx\n", i, this->registers[i]);
|
||||
this->LogToDebugFile("Registers[%02x]: %016lx\n", i, m_registers[i]);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < NumRegisters; i++) {
|
||||
this->LogToDebugFile("SavedRegs[%02x]: %016lx\n", i, this->saved_values[i]);
|
||||
this->LogToDebugFile("SavedRegs[%02x]: %016lx\n", i, m_saved_values[i]);
|
||||
}
|
||||
this->LogOpcode(std::addressof(cur_opcode));
|
||||
|
||||
/* Increment conditional depth, if relevant. */
|
||||
if (cur_opcode.begin_conditional_block) {
|
||||
this->condition_depth++;
|
||||
m_condition_depth++;
|
||||
}
|
||||
|
||||
switch (cur_opcode.opcode) {
|
||||
case CheatVmOpcodeType_StoreStatic:
|
||||
{
|
||||
/* Calculate address, write value to memory. */
|
||||
u64 dst_address = GetCheatProcessAddress(metadata, cur_opcode.store_static.mem_type, cur_opcode.store_static.rel_address + this->registers[cur_opcode.store_static.offset_register]);
|
||||
u64 dst_address = GetCheatProcessAddress(metadata, cur_opcode.store_static.mem_type, cur_opcode.store_static.rel_address + m_registers[cur_opcode.store_static.offset_register]);
|
||||
u64 dst_value = GetVmInt(cur_opcode.store_static.value, cur_opcode.store_static.bit_width);
|
||||
switch (cur_opcode.store_static.bit_width) {
|
||||
case 1:
|
||||
|
@ -866,34 +866,34 @@ namespace ams::dmnt::cheat::impl {
|
|||
} else {
|
||||
/* Decrement the condition depth. */
|
||||
/* We will assume, graciously, that mismatched conditional block ends are a nop. */
|
||||
if (this->condition_depth > 0) {
|
||||
this->condition_depth--;
|
||||
if (m_condition_depth > 0) {
|
||||
m_condition_depth--;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CheatVmOpcodeType_ControlLoop:
|
||||
if (cur_opcode.ctrl_loop.start_loop) {
|
||||
/* Start a loop. */
|
||||
this->registers[cur_opcode.ctrl_loop.reg_index] = cur_opcode.ctrl_loop.num_iters;
|
||||
this->loop_tops[cur_opcode.ctrl_loop.reg_index] = this->instruction_ptr;
|
||||
m_registers[cur_opcode.ctrl_loop.reg_index] = cur_opcode.ctrl_loop.num_iters;
|
||||
m_loop_tops[cur_opcode.ctrl_loop.reg_index] = m_instruction_ptr;
|
||||
} else {
|
||||
/* End a loop. */
|
||||
this->registers[cur_opcode.ctrl_loop.reg_index]--;
|
||||
if (this->registers[cur_opcode.ctrl_loop.reg_index] != 0) {
|
||||
this->instruction_ptr = this->loop_tops[cur_opcode.ctrl_loop.reg_index];
|
||||
m_registers[cur_opcode.ctrl_loop.reg_index]--;
|
||||
if (m_registers[cur_opcode.ctrl_loop.reg_index] != 0) {
|
||||
m_instruction_ptr = m_loop_tops[cur_opcode.ctrl_loop.reg_index];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CheatVmOpcodeType_LoadRegisterStatic:
|
||||
/* Set a register to a static value. */
|
||||
this->registers[cur_opcode.ldr_static.reg_index] = cur_opcode.ldr_static.value;
|
||||
m_registers[cur_opcode.ldr_static.reg_index] = cur_opcode.ldr_static.value;
|
||||
break;
|
||||
case CheatVmOpcodeType_LoadRegisterMemory:
|
||||
{
|
||||
/* Choose source address. */
|
||||
u64 src_address;
|
||||
if (cur_opcode.ldr_memory.load_from_reg) {
|
||||
src_address = this->registers[cur_opcode.ldr_memory.reg_index] + cur_opcode.ldr_memory.rel_address;
|
||||
src_address = m_registers[cur_opcode.ldr_memory.reg_index] + cur_opcode.ldr_memory.rel_address;
|
||||
} else {
|
||||
src_address = GetCheatProcessAddress(metadata, cur_opcode.ldr_memory.mem_type, cur_opcode.ldr_memory.rel_address);
|
||||
}
|
||||
|
@ -903,7 +903,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
case 2:
|
||||
case 4:
|
||||
case 8:
|
||||
dmnt::cheat::impl::ReadCheatProcessMemoryUnsafe(src_address, std::addressof(this->registers[cur_opcode.ldr_memory.reg_index]), cur_opcode.ldr_memory.bit_width);
|
||||
dmnt::cheat::impl::ReadCheatProcessMemoryUnsafe(src_address, std::addressof(m_registers[cur_opcode.ldr_memory.reg_index]), cur_opcode.ldr_memory.bit_width);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -911,10 +911,10 @@ namespace ams::dmnt::cheat::impl {
|
|||
case CheatVmOpcodeType_StoreStaticToAddress:
|
||||
{
|
||||
/* Calculate address. */
|
||||
u64 dst_address = this->registers[cur_opcode.str_static.reg_index];
|
||||
u64 dst_address = m_registers[cur_opcode.str_static.reg_index];
|
||||
u64 dst_value = cur_opcode.str_static.value;
|
||||
if (cur_opcode.str_static.add_offset_reg) {
|
||||
dst_address += this->registers[cur_opcode.str_static.offset_reg_index];
|
||||
dst_address += m_registers[cur_opcode.str_static.offset_reg_index];
|
||||
}
|
||||
/* Write value to memory. Gateway only writes on valid bitwidth. */
|
||||
switch (cur_opcode.str_static.bit_width) {
|
||||
|
@ -927,7 +927,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
/* Increment register if relevant. */
|
||||
if (cur_opcode.str_static.increment_reg) {
|
||||
this->registers[cur_opcode.str_static.reg_index] += cur_opcode.str_static.bit_width;
|
||||
m_registers[cur_opcode.str_static.reg_index] += cur_opcode.str_static.bit_width;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -936,19 +936,19 @@ namespace ams::dmnt::cheat::impl {
|
|||
/* Do requested math. */
|
||||
switch (cur_opcode.perform_math_static.math_type) {
|
||||
case RegisterArithmeticType_Addition:
|
||||
this->registers[cur_opcode.perform_math_static.reg_index] += (u64)cur_opcode.perform_math_static.value;
|
||||
m_registers[cur_opcode.perform_math_static.reg_index] += (u64)cur_opcode.perform_math_static.value;
|
||||
break;
|
||||
case RegisterArithmeticType_Subtraction:
|
||||
this->registers[cur_opcode.perform_math_static.reg_index] -= (u64)cur_opcode.perform_math_static.value;
|
||||
m_registers[cur_opcode.perform_math_static.reg_index] -= (u64)cur_opcode.perform_math_static.value;
|
||||
break;
|
||||
case RegisterArithmeticType_Multiplication:
|
||||
this->registers[cur_opcode.perform_math_static.reg_index] *= (u64)cur_opcode.perform_math_static.value;
|
||||
m_registers[cur_opcode.perform_math_static.reg_index] *= (u64)cur_opcode.perform_math_static.value;
|
||||
break;
|
||||
case RegisterArithmeticType_LeftShift:
|
||||
this->registers[cur_opcode.perform_math_static.reg_index] <<= (u64)cur_opcode.perform_math_static.value;
|
||||
m_registers[cur_opcode.perform_math_static.reg_index] <<= (u64)cur_opcode.perform_math_static.value;
|
||||
break;
|
||||
case RegisterArithmeticType_RightShift:
|
||||
this->registers[cur_opcode.perform_math_static.reg_index] >>= (u64)cur_opcode.perform_math_static.value;
|
||||
m_registers[cur_opcode.perform_math_static.reg_index] >>= (u64)cur_opcode.perform_math_static.value;
|
||||
break;
|
||||
default:
|
||||
/* Do not handle extensions here. */
|
||||
|
@ -957,16 +957,16 @@ namespace ams::dmnt::cheat::impl {
|
|||
/* Apply bit width. */
|
||||
switch (cur_opcode.perform_math_static.bit_width) {
|
||||
case 1:
|
||||
this->registers[cur_opcode.perform_math_static.reg_index] = static_cast<u8>(this->registers[cur_opcode.perform_math_static.reg_index]);
|
||||
m_registers[cur_opcode.perform_math_static.reg_index] = static_cast<u8>(m_registers[cur_opcode.perform_math_static.reg_index]);
|
||||
break;
|
||||
case 2:
|
||||
this->registers[cur_opcode.perform_math_static.reg_index] = static_cast<u16>(this->registers[cur_opcode.perform_math_static.reg_index]);
|
||||
m_registers[cur_opcode.perform_math_static.reg_index] = static_cast<u16>(m_registers[cur_opcode.perform_math_static.reg_index]);
|
||||
break;
|
||||
case 4:
|
||||
this->registers[cur_opcode.perform_math_static.reg_index] = static_cast<u32>(this->registers[cur_opcode.perform_math_static.reg_index]);
|
||||
m_registers[cur_opcode.perform_math_static.reg_index] = static_cast<u32>(m_registers[cur_opcode.perform_math_static.reg_index]);
|
||||
break;
|
||||
case 8:
|
||||
this->registers[cur_opcode.perform_math_static.reg_index] = static_cast<u64>(this->registers[cur_opcode.perform_math_static.reg_index]);
|
||||
m_registers[cur_opcode.perform_math_static.reg_index] = static_cast<u64>(m_registers[cur_opcode.perform_math_static.reg_index]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -980,10 +980,10 @@ namespace ams::dmnt::cheat::impl {
|
|||
break;
|
||||
case CheatVmOpcodeType_PerformArithmeticRegister:
|
||||
{
|
||||
const u64 operand_1_value = this->registers[cur_opcode.perform_math_reg.src_reg_1_index];
|
||||
const u64 operand_1_value = m_registers[cur_opcode.perform_math_reg.src_reg_1_index];
|
||||
const u64 operand_2_value = cur_opcode.perform_math_reg.has_immediate ?
|
||||
GetVmInt(cur_opcode.perform_math_reg.value, cur_opcode.perform_math_reg.bit_width) :
|
||||
this->registers[cur_opcode.perform_math_reg.src_reg_2_index];
|
||||
m_registers[cur_opcode.perform_math_reg.src_reg_2_index];
|
||||
|
||||
u64 res_val = 0;
|
||||
/* Do requested math. */
|
||||
|
@ -1038,32 +1038,32 @@ namespace ams::dmnt::cheat::impl {
|
|||
}
|
||||
|
||||
/* Save to register. */
|
||||
this->registers[cur_opcode.perform_math_reg.dst_reg_index] = res_val;
|
||||
m_registers[cur_opcode.perform_math_reg.dst_reg_index] = res_val;
|
||||
}
|
||||
break;
|
||||
case CheatVmOpcodeType_StoreRegisterToAddress:
|
||||
{
|
||||
/* Calculate address. */
|
||||
u64 dst_value = this->registers[cur_opcode.str_register.str_reg_index];
|
||||
u64 dst_address = this->registers[cur_opcode.str_register.addr_reg_index];
|
||||
u64 dst_value = m_registers[cur_opcode.str_register.str_reg_index];
|
||||
u64 dst_address = m_registers[cur_opcode.str_register.addr_reg_index];
|
||||
switch (cur_opcode.str_register.ofs_type) {
|
||||
case StoreRegisterOffsetType_None:
|
||||
/* Nothing more to do */
|
||||
break;
|
||||
case StoreRegisterOffsetType_Reg:
|
||||
dst_address += this->registers[cur_opcode.str_register.ofs_reg_index];
|
||||
dst_address += m_registers[cur_opcode.str_register.ofs_reg_index];
|
||||
break;
|
||||
case StoreRegisterOffsetType_Imm:
|
||||
dst_address += cur_opcode.str_register.rel_address;
|
||||
break;
|
||||
case StoreRegisterOffsetType_MemReg:
|
||||
dst_address = GetCheatProcessAddress(metadata, cur_opcode.str_register.mem_type, this->registers[cur_opcode.str_register.addr_reg_index]);
|
||||
dst_address = GetCheatProcessAddress(metadata, cur_opcode.str_register.mem_type, m_registers[cur_opcode.str_register.addr_reg_index]);
|
||||
break;
|
||||
case StoreRegisterOffsetType_MemImm:
|
||||
dst_address = GetCheatProcessAddress(metadata, cur_opcode.str_register.mem_type, cur_opcode.str_register.rel_address);
|
||||
break;
|
||||
case StoreRegisterOffsetType_MemImmReg:
|
||||
dst_address = GetCheatProcessAddress(metadata, cur_opcode.str_register.mem_type, this->registers[cur_opcode.str_register.addr_reg_index] + cur_opcode.str_register.rel_address);
|
||||
dst_address = GetCheatProcessAddress(metadata, cur_opcode.str_register.mem_type, m_registers[cur_opcode.str_register.addr_reg_index] + cur_opcode.str_register.rel_address);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1079,7 +1079,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
|
||||
/* Increment register if relevant. */
|
||||
if (cur_opcode.str_register.increment_reg) {
|
||||
this->registers[cur_opcode.str_register.addr_reg_index] += cur_opcode.str_register.bit_width;
|
||||
m_registers[cur_opcode.str_register.addr_reg_index] += cur_opcode.str_register.bit_width;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -1089,16 +1089,16 @@ namespace ams::dmnt::cheat::impl {
|
|||
u64 src_value = 0;
|
||||
switch (cur_opcode.begin_reg_cond.bit_width) {
|
||||
case 1:
|
||||
src_value = static_cast<u8>(this->registers[cur_opcode.begin_reg_cond.val_reg_index] & 0xFFul);
|
||||
src_value = static_cast<u8>(m_registers[cur_opcode.begin_reg_cond.val_reg_index] & 0xFFul);
|
||||
break;
|
||||
case 2:
|
||||
src_value = static_cast<u16>(this->registers[cur_opcode.begin_reg_cond.val_reg_index] & 0xFFFFul);
|
||||
src_value = static_cast<u16>(m_registers[cur_opcode.begin_reg_cond.val_reg_index] & 0xFFFFul);
|
||||
break;
|
||||
case 4:
|
||||
src_value = static_cast<u32>(this->registers[cur_opcode.begin_reg_cond.val_reg_index] & 0xFFFFFFFFul);
|
||||
src_value = static_cast<u32>(m_registers[cur_opcode.begin_reg_cond.val_reg_index] & 0xFFFFFFFFul);
|
||||
break;
|
||||
case 8:
|
||||
src_value = static_cast<u64>(this->registers[cur_opcode.begin_reg_cond.val_reg_index] & 0xFFFFFFFFFFFFFFFFul);
|
||||
src_value = static_cast<u64>(m_registers[cur_opcode.begin_reg_cond.val_reg_index] & 0xFFFFFFFFFFFFFFFFul);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1109,16 +1109,16 @@ namespace ams::dmnt::cheat::impl {
|
|||
} else if (cur_opcode.begin_reg_cond.comp_type == CompareRegisterValueType_OtherRegister) {
|
||||
switch (cur_opcode.begin_reg_cond.bit_width) {
|
||||
case 1:
|
||||
cond_value = static_cast<u8>(this->registers[cur_opcode.begin_reg_cond.other_reg_index] & 0xFFul);
|
||||
cond_value = static_cast<u8>(m_registers[cur_opcode.begin_reg_cond.other_reg_index] & 0xFFul);
|
||||
break;
|
||||
case 2:
|
||||
cond_value = static_cast<u16>(this->registers[cur_opcode.begin_reg_cond.other_reg_index] & 0xFFFFul);
|
||||
cond_value = static_cast<u16>(m_registers[cur_opcode.begin_reg_cond.other_reg_index] & 0xFFFFul);
|
||||
break;
|
||||
case 4:
|
||||
cond_value = static_cast<u32>(this->registers[cur_opcode.begin_reg_cond.other_reg_index] & 0xFFFFFFFFul);
|
||||
cond_value = static_cast<u32>(m_registers[cur_opcode.begin_reg_cond.other_reg_index] & 0xFFFFFFFFul);
|
||||
break;
|
||||
case 8:
|
||||
cond_value = static_cast<u64>(this->registers[cur_opcode.begin_reg_cond.other_reg_index] & 0xFFFFFFFFFFFFFFFFul);
|
||||
cond_value = static_cast<u64>(m_registers[cur_opcode.begin_reg_cond.other_reg_index] & 0xFFFFFFFFFFFFFFFFul);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -1128,13 +1128,13 @@ namespace ams::dmnt::cheat::impl {
|
|||
cond_address = GetCheatProcessAddress(metadata, cur_opcode.begin_reg_cond.mem_type, cur_opcode.begin_reg_cond.rel_address);
|
||||
break;
|
||||
case CompareRegisterValueType_MemoryOfsReg:
|
||||
cond_address = GetCheatProcessAddress(metadata, cur_opcode.begin_reg_cond.mem_type, this->registers[cur_opcode.begin_reg_cond.ofs_reg_index]);
|
||||
cond_address = GetCheatProcessAddress(metadata, cur_opcode.begin_reg_cond.mem_type, m_registers[cur_opcode.begin_reg_cond.ofs_reg_index]);
|
||||
break;
|
||||
case CompareRegisterValueType_RegisterRelAddr:
|
||||
cond_address = this->registers[cur_opcode.begin_reg_cond.addr_reg_index] + cur_opcode.begin_reg_cond.rel_address;
|
||||
cond_address = m_registers[cur_opcode.begin_reg_cond.addr_reg_index] + cur_opcode.begin_reg_cond.rel_address;
|
||||
break;
|
||||
case CompareRegisterValueType_RegisterOfsReg:
|
||||
cond_address = this->registers[cur_opcode.begin_reg_cond.addr_reg_index] + this->registers[cur_opcode.begin_reg_cond.ofs_reg_index];
|
||||
cond_address = m_registers[cur_opcode.begin_reg_cond.addr_reg_index] + m_registers[cur_opcode.begin_reg_cond.ofs_reg_index];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1182,17 +1182,17 @@ namespace ams::dmnt::cheat::impl {
|
|||
/* Save or restore a register. */
|
||||
switch (cur_opcode.save_restore_reg.op_type) {
|
||||
case SaveRestoreRegisterOpType_ClearRegs:
|
||||
this->registers[cur_opcode.save_restore_reg.dst_index] = 0ul;
|
||||
m_registers[cur_opcode.save_restore_reg.dst_index] = 0ul;
|
||||
break;
|
||||
case SaveRestoreRegisterOpType_ClearSaved:
|
||||
this->saved_values[cur_opcode.save_restore_reg.dst_index] = 0ul;
|
||||
m_saved_values[cur_opcode.save_restore_reg.dst_index] = 0ul;
|
||||
break;
|
||||
case SaveRestoreRegisterOpType_Save:
|
||||
this->saved_values[cur_opcode.save_restore_reg.dst_index] = this->registers[cur_opcode.save_restore_reg.src_index];
|
||||
m_saved_values[cur_opcode.save_restore_reg.dst_index] = m_registers[cur_opcode.save_restore_reg.src_index];
|
||||
break;
|
||||
case SaveRestoreRegisterOpType_Restore:
|
||||
default:
|
||||
this->registers[cur_opcode.save_restore_reg.dst_index] = this->saved_values[cur_opcode.save_restore_reg.src_index];
|
||||
m_registers[cur_opcode.save_restore_reg.dst_index] = m_saved_values[cur_opcode.save_restore_reg.src_index];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1203,14 +1203,14 @@ namespace ams::dmnt::cheat::impl {
|
|||
switch (cur_opcode.save_restore_regmask.op_type) {
|
||||
case SaveRestoreRegisterOpType_ClearSaved:
|
||||
case SaveRestoreRegisterOpType_Save:
|
||||
src = this->registers;
|
||||
dst = this->saved_values;
|
||||
src = m_registers;
|
||||
dst = m_saved_values;
|
||||
break;
|
||||
case SaveRestoreRegisterOpType_ClearRegs:
|
||||
case SaveRestoreRegisterOpType_Restore:
|
||||
default:
|
||||
src = this->saved_values;
|
||||
dst = this->registers;
|
||||
src = m_saved_values;
|
||||
dst = m_registers;
|
||||
break;
|
||||
}
|
||||
for (size_t i = 0; i < NumRegisters; i++) {
|
||||
|
@ -1232,10 +1232,10 @@ namespace ams::dmnt::cheat::impl {
|
|||
case CheatVmOpcodeType_ReadWriteStaticRegister:
|
||||
if (cur_opcode.rw_static_reg.static_idx < NumReadableStaticRegisters) {
|
||||
/* Load a register with a static register. */
|
||||
this->registers[cur_opcode.rw_static_reg.idx] = this->static_registers[cur_opcode.rw_static_reg.static_idx];
|
||||
m_registers[cur_opcode.rw_static_reg.idx] = m_static_registers[cur_opcode.rw_static_reg.static_idx];
|
||||
} else {
|
||||
/* Store a register to a static register. */
|
||||
this->static_registers[cur_opcode.rw_static_reg.static_idx] = this->registers[cur_opcode.rw_static_reg.idx];
|
||||
m_static_registers[cur_opcode.rw_static_reg.static_idx] = m_registers[cur_opcode.rw_static_reg.idx];
|
||||
}
|
||||
break;
|
||||
case CheatVmOpcodeType_PauseProcess:
|
||||
|
@ -1251,16 +1251,16 @@ namespace ams::dmnt::cheat::impl {
|
|||
if (cur_opcode.debug_log.val_type == DebugLogValueType_RegisterValue) {
|
||||
switch (cur_opcode.debug_log.bit_width) {
|
||||
case 1:
|
||||
log_value = static_cast<u8>(this->registers[cur_opcode.debug_log.val_reg_index] & 0xFFul);
|
||||
log_value = static_cast<u8>(m_registers[cur_opcode.debug_log.val_reg_index] & 0xFFul);
|
||||
break;
|
||||
case 2:
|
||||
log_value = static_cast<u16>(this->registers[cur_opcode.debug_log.val_reg_index] & 0xFFFFul);
|
||||
log_value = static_cast<u16>(m_registers[cur_opcode.debug_log.val_reg_index] & 0xFFFFul);
|
||||
break;
|
||||
case 4:
|
||||
log_value = static_cast<u32>(this->registers[cur_opcode.debug_log.val_reg_index] & 0xFFFFFFFFul);
|
||||
log_value = static_cast<u32>(m_registers[cur_opcode.debug_log.val_reg_index] & 0xFFFFFFFFul);
|
||||
break;
|
||||
case 8:
|
||||
log_value = static_cast<u64>(this->registers[cur_opcode.debug_log.val_reg_index] & 0xFFFFFFFFFFFFFFFFul);
|
||||
log_value = static_cast<u64>(m_registers[cur_opcode.debug_log.val_reg_index] & 0xFFFFFFFFFFFFFFFFul);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -1270,13 +1270,13 @@ namespace ams::dmnt::cheat::impl {
|
|||
val_address = GetCheatProcessAddress(metadata, cur_opcode.debug_log.mem_type, cur_opcode.debug_log.rel_address);
|
||||
break;
|
||||
case DebugLogValueType_MemoryOfsReg:
|
||||
val_address = GetCheatProcessAddress(metadata, cur_opcode.debug_log.mem_type, this->registers[cur_opcode.debug_log.ofs_reg_index]);
|
||||
val_address = GetCheatProcessAddress(metadata, cur_opcode.debug_log.mem_type, m_registers[cur_opcode.debug_log.ofs_reg_index]);
|
||||
break;
|
||||
case DebugLogValueType_RegisterRelAddr:
|
||||
val_address = this->registers[cur_opcode.debug_log.addr_reg_index] + cur_opcode.debug_log.rel_address;
|
||||
val_address = m_registers[cur_opcode.debug_log.addr_reg_index] + cur_opcode.debug_log.rel_address;
|
||||
break;
|
||||
case DebugLogValueType_RegisterOfsReg:
|
||||
val_address = this->registers[cur_opcode.debug_log.addr_reg_index] + this->registers[cur_opcode.debug_log.ofs_reg_index];
|
||||
val_address = m_registers[cur_opcode.debug_log.addr_reg_index] + m_registers[cur_opcode.debug_log.ofs_reg_index];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -277,15 +277,15 @@ namespace ams::dmnt::cheat::impl {
|
|||
constexpr static size_t NumWritableStaticRegisters = 0x80;
|
||||
constexpr static size_t NumStaticRegisters = NumReadableStaticRegisters + NumWritableStaticRegisters;
|
||||
private:
|
||||
size_t num_opcodes = 0;
|
||||
size_t instruction_ptr = 0;
|
||||
size_t condition_depth = 0;
|
||||
bool decode_success = false;
|
||||
u32 program[MaximumProgramOpcodeCount] = {0};
|
||||
u64 registers[NumRegisters] = {0};
|
||||
u64 saved_values[NumRegisters] = {0};
|
||||
u64 static_registers[NumStaticRegisters] = {0};
|
||||
size_t loop_tops[NumRegisters] = {0};
|
||||
size_t m_num_opcodes = 0;
|
||||
size_t m_instruction_ptr = 0;
|
||||
size_t m_condition_depth = 0;
|
||||
bool m_decode_success = false;
|
||||
u32 m_program[MaximumProgramOpcodeCount] = {0};
|
||||
u64 m_registers[NumRegisters] = {0};
|
||||
u64 m_saved_values[NumRegisters] = {0};
|
||||
u64 m_static_registers[NumStaticRegisters] = {0};
|
||||
size_t m_loop_tops[NumRegisters] = {0};
|
||||
private:
|
||||
bool DecodeNextOpcode(CheatVmOpcode *out);
|
||||
void SkipConditionalBlock(bool is_if);
|
||||
|
@ -303,32 +303,32 @@ namespace ams::dmnt::cheat::impl {
|
|||
static u64 GetVmInt(VmInt value, u32 bit_width);
|
||||
static u64 GetCheatProcessAddress(const CheatProcessMetadata* metadata, MemoryAccessType mem_type, u64 rel_address);
|
||||
public:
|
||||
CheatVirtualMachine() { }
|
||||
constexpr CheatVirtualMachine() = default;
|
||||
|
||||
size_t GetProgramSize() {
|
||||
return this->num_opcodes;
|
||||
return m_num_opcodes;
|
||||
}
|
||||
|
||||
bool LoadProgram(const CheatEntry *cheats, size_t num_cheats);
|
||||
void Execute(const CheatProcessMetadata *metadata);
|
||||
|
||||
u64 GetStaticRegister(size_t which) const {
|
||||
return this->static_registers[which];
|
||||
return m_static_registers[which];
|
||||
}
|
||||
|
||||
void SetStaticRegister(size_t which, u64 value) {
|
||||
this->static_registers[which] = value;
|
||||
m_static_registers[which] = value;
|
||||
}
|
||||
|
||||
void ResetStaticRegisters() {
|
||||
std::memset(this->static_registers, 0, sizeof(this->static_registers));
|
||||
std::memset(m_static_registers, 0, sizeof(m_static_registers));
|
||||
}
|
||||
#ifdef DMNT_CHEAT_VM_DEBUG_LOG
|
||||
private:
|
||||
fs::FileHandle debug_log_file;
|
||||
s64 debug_log_file_offset;
|
||||
bool has_debug_log_file;
|
||||
char debug_log_format_buf[0x100];
|
||||
fs::FileHandle m_debug_log_file = {};
|
||||
s64 m_debug_log_file_offset = 0;
|
||||
bool m_has_debug_log_file = false;
|
||||
char m_debug_log_format_buf[0x100] = {0};
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue