mirror of
https://github.com/LibreSplit/LibreSplit.git
synced 2026-03-10 15:00:25 +00:00
Memory offset such as 0x400000 is found internally
This commit is contained in:
parent
64a4e0c188
commit
2b4417fbfb
2 changed files with 43 additions and 4 deletions
|
|
@ -7,6 +7,8 @@
|
|||
#include <cstring>
|
||||
#include <variant>
|
||||
#include <thread>
|
||||
#include <array>
|
||||
#include <sstream>
|
||||
|
||||
#include "lasprint.h"
|
||||
|
||||
|
|
@ -21,6 +23,8 @@ using std::cerr;
|
|||
using std::exception;
|
||||
using std::this_thread::sleep_for;
|
||||
using std::chrono::microseconds;
|
||||
using std::array;
|
||||
using std::stringstream;
|
||||
|
||||
extern int pid;
|
||||
|
||||
|
|
@ -28,6 +32,6 @@ int processID(lua_State* L);
|
|||
int readAddress(lua_State* L);
|
||||
|
||||
template <typename T>
|
||||
T readMem(int pid, uint64_t memAddress);
|
||||
T readMem(int pid, uintptr_t memAddress);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,12 +1,45 @@
|
|||
#include "readmem.h"
|
||||
|
||||
string processName;
|
||||
string newProcessName;
|
||||
uintptr_t memoryOffset = 0;
|
||||
|
||||
struct iovec memLocal;
|
||||
struct iovec memRemote;
|
||||
|
||||
int pid = 0;
|
||||
|
||||
void setMemoryOffset()
|
||||
{
|
||||
string command = "cat /proc/" + to_string(pid) + "/maps | grep " + newProcessName;
|
||||
array<char, 128> buffer;
|
||||
string result;
|
||||
|
||||
// Open the command for reading
|
||||
FILE* pipe = popen(command.c_str(), "r");
|
||||
if (!pipe)
|
||||
{
|
||||
std::cout << "Error executing command: " << command << std::endl;
|
||||
}
|
||||
|
||||
// Read the command output line by line
|
||||
while (fgets(buffer.data(), buffer.size(), pipe) != nullptr)
|
||||
{
|
||||
result += buffer.data();
|
||||
}
|
||||
|
||||
// Close the pipe
|
||||
pclose(pipe);
|
||||
|
||||
size_t dashPos = result.find_first_of("-");
|
||||
|
||||
if (dashPos != string::npos)
|
||||
{
|
||||
string firstNumber = result.substr(0, dashPos);
|
||||
memoryOffset = stoull(firstNumber, nullptr, 16);
|
||||
}
|
||||
}
|
||||
|
||||
struct StockPid
|
||||
{
|
||||
pid_t pid;
|
||||
|
|
@ -40,7 +73,7 @@ void Func_StockPid(const char *processtarget)
|
|||
int processID(lua_State* L)
|
||||
{
|
||||
processName = lua_tostring(L, 1);
|
||||
string newProcessName = processName.substr(0, 15);
|
||||
newProcessName = processName.substr(0, 15);
|
||||
string command = "pidof " + newProcessName;
|
||||
const char *cCommand = command.c_str();
|
||||
|
||||
|
|
@ -54,11 +87,13 @@ int processID(lua_State* L)
|
|||
}
|
||||
lasPrint("\n");
|
||||
|
||||
setMemoryOffset();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T readMem(int pid, uint64_t memAddress)
|
||||
T readMem(int pid, uintptr_t memAddress)
|
||||
{
|
||||
T value; // Variable to store the read value
|
||||
|
||||
|
|
@ -99,8 +134,8 @@ template string readMem<string>(int pid, uint64_t memAddress);
|
|||
|
||||
int readAddress(lua_State* L)
|
||||
{
|
||||
uintptr_t address = memoryOffset;
|
||||
string valueType = lua_tostring(L, 1);
|
||||
uint64_t address = 0;
|
||||
for (int i = 2; i <= lua_gettop(L); i++)
|
||||
{
|
||||
address += lua_tointeger(L, i); // Calculate the final memory address by summing the Lua arguments.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue