Skip to content

Commit e6466e6

Browse files
authored
Adds Assembly Variable Type to Watchlist and Memory Scanner by ModSault (#246)
Solves #245. Allows for users to see and edit memory as Power PC assembly instructions. It also has support for the memory scanner. * Add Disassembler * Add PowerPC type * PowerPC support for Scanner
1 parent 924ba3b commit e6466e6

19 files changed

+3982
-43
lines changed

Source/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ endif(APPLE)
4646
set(SRCS ${DolphinProcessSrc}
4747
DolphinProcess/DolphinAccessor.cpp
4848
Common/MemoryCommon.cpp
49+
Common/PPC/PowerPCAssembler.cpp
50+
Common/PPC/PowerPCDisassembler.cpp
4951
MemoryWatch/MemWatchEntry.cpp
5052
MemoryWatch/MemWatchTreeNode.cpp
5153
CheatEngineParser/CheatEngineParser.cpp

Source/Common/MemoryCommon.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include "../Common/CommonTypes.h"
1111
#include "../Common/CommonUtils.h"
12+
#include "../Common/PPC/PowerPCAssembler.h"
13+
#include "../Common/PPC/PowerPCDisassembler.h"
1214
#include "../GUI/Settings/SConfig.h"
1315

1416
namespace Common
@@ -75,6 +77,8 @@ size_t getSizeForType(const MemType type, const size_t length)
7577
return length;
7678
case MemType::type_struct:
7779
return length;
80+
case MemType::type_ppc:
81+
return sizeof(u32);
7882
default:
7983
return 0;
8084
}
@@ -100,6 +104,8 @@ bool shouldBeBSwappedForType(const MemType type)
100104
return false;
101105
case MemType::type_struct:
102106
return false;
107+
case MemType::type_ppc:
108+
return true;
103109
default:
104110
return false;
105111
}
@@ -125,14 +131,16 @@ int getNbrBytesAlignmentForType(const MemType type)
125131
return 1;
126132
case MemType::type_struct:
127133
return 1;
134+
case MemType::type_ppc:
135+
return 4;
128136
default:
129137
return 1;
130138
}
131139
}
132140

133141
char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLength,
134142
const std::string_view inputString, const MemBase base,
135-
const MemType type, const size_t length)
143+
const MemType type, const size_t length, u32 ppcBranchOrigin)
136144
{
137145
if (inputString.empty())
138146
{
@@ -463,6 +471,13 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen
463471
actualLength = bytes.size();
464472
break;
465473
}
474+
case Common::MemType::type_ppc:
475+
{
476+
u32 result = Common::PowerPCAssembler::PPCAssemble(inputString.data(), ppcBranchOrigin);
477+
memcpy(buffer, &result, size);
478+
actualLength = size;
479+
break;
480+
}
466481

467482
default:
468483
{
@@ -472,8 +487,10 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen
472487
return buffer;
473488
}
474489

490+
// ppcBranchOrigin = 0 means relative branch, non-zero means absolute branch will be shown
475491
std::string formatMemoryToString(const char* memory, const MemType type, const size_t length,
476-
const MemBase base, const bool isUnsigned, const bool withBSwap)
492+
const MemBase base, const bool isUnsigned, const bool withBSwap,
493+
const u32 ppcBranchOrigin)
477494
{
478495
std::stringstream ss;
479496
switch (base)
@@ -698,6 +715,20 @@ std::string formatMemoryToString(const char* memory, const MemType type, const s
698715
str.pop_back();
699716
return str;
700717
}
718+
case Common::MemType::type_ppc:
719+
{
720+
u32 binary = 0;
721+
for (size_t i{0}; i < 4; ++i)
722+
{
723+
if (!withBSwap)
724+
binary |= (static_cast<u8>(memory[i])) << (i * 8);
725+
else
726+
binary |= (static_cast<u8>(memory[i])) << ((3 - i) * 8);
727+
}
728+
// returns binary (big endian mode).
729+
// Branch is relative if ppcBranchOrigin == 0, absolute otherwise
730+
return Common::PowerPCDisassembler::PPCDisassemble(binary, ppcBranchOrigin);
731+
}
701732
default:
702733
return "";
703734
break;

Source/Common/MemoryCommon.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ enum class MemType
3535
type_string,
3636
type_byteArray,
3737
type_struct,
38+
type_ppc,
3839
type_none // Placeholder for the entry of a child node of a collapsed container
3940
};
4041

@@ -53,14 +54,17 @@ enum class MemOperationReturnCode
5354
operationFailed,
5455
inputTooLong,
5556
invalidPointer,
56-
OK
57+
OK,
58+
noAbsoluteBranchForPPC
5759
};
5860

5961
size_t getSizeForType(MemType type, size_t length);
6062
bool shouldBeBSwappedForType(MemType type);
6163
int getNbrBytesAlignmentForType(MemType type);
6264
char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLength,
63-
std::string_view inputString, MemBase base, MemType type, size_t length);
65+
std::string_view inputString, MemBase base, MemType type, size_t length,
66+
const u32 ppcBranchOrigin = 0);
6467
std::string formatMemoryToString(const char* memory, MemType type, size_t length, MemBase base,
65-
bool isUnsigned, bool withBSwap = false);
68+
bool isUnsigned, bool withBSwap = false,
69+
const u32 ppcBranchOrigin = 0);
6670
} // namespace Common

0 commit comments

Comments
 (0)