Allow MemoryWatcher to follow pointers

This commit is contained in:
spxtr
2015-12-30 19:10:31 -08:00
parent afde6ae72c
commit 525fc4fe8a
2 changed files with 52 additions and 16 deletions

View File

@ -7,16 +7,18 @@
#include <atomic>
#include <map>
#include <thread>
#include <vector>
#include <sys/socket.h>
#include <sys/un.h>
// MemoryWatcher reads a file containing in-game memory addresses and outputs
// changes to those memory addresses to a unix domain socket as the game runs.
//
// The input file is a newline-separated list of hex memory addresses
// (without the "0x"). The output to the socket is two words long, the first
// containing the address, and the second containing the data as stored in
// game memory.
// The input file is a newline-separated list of hex memory addresses, without
// the "0x". To follow pointers, separate addresses with a space. For example,
// "ABCD EF" will watch the address at (*0xABCD) + 0xEF.
// The output to the socket is two lines. The first is the address from the
// input file, and the second is the new value in hex.
class MemoryWatcher final
{
public:
@ -26,6 +28,11 @@ public:
private:
bool LoadAddresses(const std::string& path);
bool OpenSocket(const std::string& path);
void ParseLine(const std::string& line);
u32 ChasePointer(const std::string& line);
std::string ComposeMessage(const std::string& line, u32 value);
void WatcherThread();
std::thread m_watcher_thread;
@ -34,6 +41,8 @@ private:
int m_fd;
sockaddr_un m_addr;
// Address -> last value
std::map<u32, u32> m_values;
// Address as stored in the file -> list of offsets to follow
std::map<std::string, std::vector<u32>> m_addresses;
// Address as stored in the file -> current value
std::map<std::string, u32> m_values;
};