dmnt: various cheat changes/suggestions that have been cooking a while

This commit is contained in:
Michael Scire
2021-07-21 19:21:58 -07:00
parent 0c596e682f
commit 389c3b6baa
9 changed files with 74 additions and 4 deletions

View File

@@ -48,6 +48,10 @@ namespace ams::dmnt::cheat {
return dmnt::cheat::impl::ResumeCheatProcess();
}
Result CheatService::ForceCloseCheatProcess() {
return dmnt::cheat::impl::ForceCloseCheatProcess();
}
/* ========================================================================================= */
/* =================================== Memory Commands =================================== */
/* ========================================================================================= */
@@ -116,6 +120,10 @@ namespace ams::dmnt::cheat {
return dmnt::cheat::impl::ResetStaticRegisters();
}
Result CheatService::SetMasterCheat(const CheatDefinition &cheat) {
return dmnt::cheat::impl::SetMasterCheat(cheat);
}
/* ========================================================================================= */
/* =================================== Address Commands ================================== */
/* ========================================================================================= */

View File

@@ -24,6 +24,7 @@
AMS_SF_METHOD_INFO(C, H, 65003, Result, ForceOpenCheatProcess, (), ()) \
AMS_SF_METHOD_INFO(C, H, 65004, Result, PauseCheatProcess, (), ()) \
AMS_SF_METHOD_INFO(C, H, 65005, Result, ResumeCheatProcess, (), ()) \
AMS_SF_METHOD_INFO(C, H, 65006, Result, ForceCloseCheatProcess, (), ()) \
AMS_SF_METHOD_INFO(C, H, 65100, Result, GetCheatProcessMappingCount, (sf::Out<u64> out_count), (out_count)) \
AMS_SF_METHOD_INFO(C, H, 65101, Result, GetCheatProcessMappings, (const sf::OutArray<MemoryInfo> &mappings, sf::Out<u64> out_count, u64 offset), (mappings, out_count, offset)) \
AMS_SF_METHOD_INFO(C, H, 65102, Result, ReadCheatProcessMemory, (const sf::OutBuffer &buffer, u64 address, u64 out_size), (buffer, address, out_size)) \
@@ -38,6 +39,7 @@
AMS_SF_METHOD_INFO(C, H, 65206, Result, ReadStaticRegister, (sf::Out<u64> out, u8 which), (out, which)) \
AMS_SF_METHOD_INFO(C, H, 65207, Result, WriteStaticRegister, (u8 which, u64 value), (which, value)) \
AMS_SF_METHOD_INFO(C, H, 65208, Result, ResetStaticRegisters, (), ()) \
AMS_SF_METHOD_INFO(C, H, 65209, Result, SetMasterCheat, (const dmnt::cheat::CheatDefinition &cheat), (cheat)) \
AMS_SF_METHOD_INFO(C, H, 65300, Result, GetFrozenAddressCount, (sf::Out<u64> out_count), (out_count)) \
AMS_SF_METHOD_INFO(C, H, 65301, Result, GetFrozenAddresses, (const sf::OutArray<dmnt::cheat::FrozenAddressEntry> &addresses, sf::Out<u64> out_count, u64 offset), (addresses, out_count, offset)) \
AMS_SF_METHOD_INFO(C, H, 65302, Result, GetFrozenAddress, (sf::Out<dmnt::cheat::FrozenAddressEntry> entry, u64 address), (entry, address)) \
@@ -56,6 +58,7 @@ namespace ams::dmnt::cheat {
Result ForceOpenCheatProcess();
Result PauseCheatProcess();
Result ResumeCheatProcess();
Result ForceCloseCheatProcess();
Result GetCheatProcessMappingCount(sf::Out<u64> out_count);
Result GetCheatProcessMappings(const sf::OutArray<MemoryInfo> &mappings, sf::Out<u64> out_count, u64 offset);
@@ -72,6 +75,7 @@ namespace ams::dmnt::cheat {
Result ReadStaticRegister(sf::Out<u64> out, u8 which);
Result WriteStaticRegister(u8 which, u64 value);
Result ResetStaticRegisters();
Result SetMasterCheat(const CheatDefinition &cheat);
Result GetFrozenAddressCount(sf::Out<u64> out_count);
Result GetFrozenAddresses(const sf::OutArray<FrozenAddressEntry> &addresses, sf::Out<u64> out_count, u64 offset);

View File

@@ -301,6 +301,11 @@ namespace ams::dmnt::cheat::impl {
return this->AttachToApplicationProcess(false);
}
Result ForceCloseCheatProcess() {
this->CloseActiveCheatProcess();
return ResultSuccess();
}
Result ReadCheatProcessMemoryUnsafe(u64 proc_addr, void *out_data, size_t size) {
return svcReadDebugProcessMemory(out_data, this->GetCheatProcessHandle(), proc_addr, size);
}
@@ -520,6 +525,9 @@ namespace ams::dmnt::cheat::impl {
/* Trigger a VM reload. */
this->SetNeedsReloadVm(true);
/* Set output id. */
*out_id = new_entry->cheat_id;
return ResultSuccess();
}
@@ -537,6 +545,25 @@ namespace ams::dmnt::cheat::impl {
return ResultSuccess();
}
Result SetMasterCheat(const CheatDefinition &def) {
std::scoped_lock lk(this->cheat_lock);
R_TRY(this->EnsureCheatProcess());
R_UNLESS(def.num_opcodes != 0, ResultCheatInvalid());
R_UNLESS(def.num_opcodes <= util::size(def.opcodes), ResultCheatInvalid());
CheatEntry *master_entry = this->cheat_entries + 0;
master_entry->enabled = true;
master_entry->definition = def;
/* Trigger a VM reload. */
this->SetNeedsReloadVm(true);
return ResultSuccess();
}
Result ReadStaticRegister(u64 *out, size_t which) {
std::scoped_lock lk(this->cheat_lock);
@@ -1187,6 +1214,10 @@ namespace ams::dmnt::cheat::impl {
return GetReference(g_cheat_process_manager).ResumeCheatProcess();
}
Result ForceCloseCheatProcess() {
return GetReference(g_cheat_process_manager).ForceCloseCheatProcess();
}
Result ReadCheatProcessMemoryUnsafe(u64 process_addr, void *out_data, size_t size) {
return GetReference(g_cheat_process_manager).ReadCheatProcessMemoryUnsafe(process_addr, out_data, size);
}
@@ -1247,6 +1278,10 @@ namespace ams::dmnt::cheat::impl {
return GetReference(g_cheat_process_manager).RemoveCheat(cheat_id);
}
Result SetMasterCheat(const CheatDefinition &def) {
return GetReference(g_cheat_process_manager).SetMasterCheat(def);
}
Result ReadStaticRegister(u64 *out, size_t which) {
return GetReference(g_cheat_process_manager).ReadStaticRegister(out, which);
}

View File

@@ -26,6 +26,7 @@ namespace ams::dmnt::cheat::impl {
Result ForceOpenCheatProcess();
Result PauseCheatProcess();
Result ResumeCheatProcess();
Result ForceCloseCheatProcess();
Result ReadCheatProcessMemoryUnsafe(u64 process_addr, void *out_data, size_t size);
Result WriteCheatProcessMemoryUnsafe(u64 process_addr, void *data, size_t size);
@@ -45,6 +46,7 @@ namespace ams::dmnt::cheat::impl {
Result ToggleCheat(u32 cheat_id);
Result AddCheat(u32 *out_id, const CheatDefinition &def, bool enabled);
Result RemoveCheat(u32 cheat_id);
Result SetMasterCheat(const CheatDefinition &def);
Result ReadStaticRegister(u64 *out, size_t which);
Result WriteStaticRegister(size_t which, u64 value);
Result ResetStaticRegisters();

View File

@@ -721,6 +721,10 @@ namespace ams::dmnt::cheat::impl {
return metadata->main_nso_extents.base + rel_address;
case MemoryAccessType_Heap:
return metadata->heap_extents.base + rel_address;
case MemoryAccessType_Alias:
return metadata->alias_extents.base + rel_address;
case MemoryAccessType_Aslr:
return metadata->aslr_extents.base + rel_address;
}
}

View File

@@ -56,7 +56,9 @@ namespace ams::dmnt::cheat::impl {
enum MemoryAccessType : u32 {
MemoryAccessType_MainNso = 0,
MemoryAccessType_Heap = 1,
MemoryAccessType_Heap = 1,
MemoryAccessType_Alias = 2,
MemoryAccessType_Aslr = 3,
};
enum ConditionalComparisonType : u32 {