Skip to content

Commit 66b24ec

Browse files
committed
fix: memory patch linux
1 parent 87a56d7 commit 66b24ec

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

smsm/src/Modules/MaterialSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ bool MaterialSystem::Init()
1717
auto offSize = 1;
1818
#else
1919
auto sigSize = "81 C3 00 60 22 00";
20-
auto sigInit = "A1 ? ? ? ? 85 C0 74 ? 83 C0 01";
2120
auto sigTerm = "83 2D ? ? ? ? 01 74 ? C3";
21+
auto sigInit = "A1 ? ? ? ? 85 C0 74 ? 83 C0 01";
2222
auto offSize = 2;
2323
#endif
2424
auto defaultContextSize = Memory::Scan(this->Name(), sigSize, offSize);

smsm/src/Utils/Memory.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,23 @@ bool Memory::TryGetModule(const char* moduleName, Memory::ModuleInfo* info)
5757

5858
#else
5959
dl_iterate_phdr([](struct dl_phdr_info* info, size_t, void*) {
60-
auto module = Memory::ModuleInfo();
61-
6260
std::string temp = std::string(info->dlpi_name);
6361
int index = temp.find_last_of("\\/");
6462
temp = temp.substr(index + 1, temp.length() - index);
65-
snprintf(module.name, sizeof(module.name), "%s", temp.c_str());
6663

67-
module.base = info->dlpi_addr + info->dlpi_phdr[0].p_paddr;
68-
module.size = info->dlpi_phdr[0].p_memsz;
69-
strcpy(module.path, info->dlpi_name);
64+
for (int i = 0; i < info->dlpi_phnum; ++i) {
65+
// FIXME: we really want data segments too! but +x is more important
66+
if (info->dlpi_phdr[i].p_flags & 1) { // execute
67+
Memory::ModuleInfo module;
68+
module.base = info->dlpi_addr + info->dlpi_phdr[i].p_vaddr;
69+
module.size = info->dlpi_phdr[i].p_memsz;
70+
std::strncpy(module.name, temp.c_str(), sizeof(module.name));
71+
std::strncpy(module.path, info->dlpi_name, sizeof(module.path));
72+
Memory::moduleList.push_back(module);
73+
break;
74+
}
75+
}
7076

71-
Memory::moduleList.push_back(module);
7277
return 0;
7378
},
7479
nullptr);

0 commit comments

Comments
 (0)