-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunixdump.cpp
More file actions
58 lines (46 loc) · 1.22 KB
/
unixdump.cpp
File metadata and controls
58 lines (46 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include "common.h"
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
using namespace std;
uint8_t* emuRAMAddressStart = 0;
void findAndAttachProcess() {
int pid = dolphinPid();
if (pid < 0) {
cerr << "Can't find dolphin! Launch dolphin first!" << endl;
exit(1);
}
cerr << "Dolphin found, PID " << pid << endl;
const string file_name = "/dolphin-emu." + to_string(pid);
int fd = shm_open(file_name.c_str(), O_RDWR, 0600);
if (fd < 0) {
cerr << "Failed to open shared memory" << endl;
exit(2);
}
cerr << "Opened shmem" << endl;
size_t size = 0x2040000;
void *mem = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (mem == MAP_FAILED) {
cerr << "failed to map shared memory" << endl;
close(fd);
exit(3);
}
emuRAMAddressStart = reinterpret_cast<uint8_t *>(mem);
close(fd);
}
uint32_t getRealPtr(uint32_t address) {
uint32_t masked = address & 0x7FFFFFFFu;
if (masked > 0x1800000) {
return 0;
}
return masked;
}
void dolphin_memcpy(void *dest, size_t offset, size_t size) {
if (size > 0x1800000) {
size = 0x1800000;
}
memcpy(dest, emuRAMAddressStart + getRealPtr(offset), size);
}