From a66fb2c5107487287fd6a7c2223efd92c63813f8 Mon Sep 17 00:00:00 2001 From: J Reece Wilson Date: Thu, 21 Apr 2022 13:29:47 +0100 Subject: [PATCH] [+] Insert anon/other pages into process map of linux processes --- Source/Process/ProcessMap.Linux.cpp | 38 +++++++++++++++++++---------- Source/Process/ProcessMap.cpp | 8 ++++-- Source/Process/ProcessMap.hpp | 2 +- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Source/Process/ProcessMap.Linux.cpp b/Source/Process/ProcessMap.Linux.cpp index aa57fd8c..92a868ee 100644 --- a/Source/Process/ProcessMap.Linux.cpp +++ b/Source/Process/ProcessMap.Linux.cpp @@ -36,14 +36,6 @@ namespace Aurora::Process size_t size, void *data) { - #if 0 - auto index = file.find_last_of(".so"); - if (index != AuString::npos) - { - file = file.substr(0, index); - } - #endif - AuString fileName = info->dlpi_name[0] ? info->dlpi_name : AuString{}; if (fileName.empty()) { @@ -81,6 +73,7 @@ namespace Aurora::Process return; } + Sections sections; AuParse::SplitNewlines(map, [&](const AuString &line) { char *endPtr; @@ -92,6 +85,8 @@ namespace Aurora::Process if (errno == ERANGE) return; if (*endPtr != ' ') return; + auto perms = endPtr + 1; + auto A = line.find_first_of(':'); if (A == AuString::npos) return; @@ -131,10 +126,26 @@ namespace Aurora::Process } } - // TODO: - //printf("%llx %llx %s\n", base, end, name.c_str()); + Section sect {}; + sect.origVa = 0; + sect.baseVa = base; + sect.size = end - base; + sect.fsOff = 0; + + sect.pt.readable = perms[0] == 'r'; + sect.pt.writable = perms[1] == 'w'; + sect.pt.NX = perms[2] != 'x'; + + sect.name = AuMove(name); + AuTryInsert(sections, sect); }, false); + + BorrowOtherSectionArray([&](AuList
&out) + { + out.clear(); + out.insert(out.end(), sections.begin(), sections.end()); + }); } static void PassThreeGatherMissingProgNames() @@ -205,9 +216,7 @@ namespace Aurora::Process AuUInt fileOffset = section.sh_offset; AuUInt programOffset = section.sh_addr; - Section sect {}; - sect.origVa = section.sh_addr; sect.baseVa = 0; @@ -238,7 +247,10 @@ namespace Aurora::Process sect.name = sectionName; - AuTryInsert(modSections, sect); + if (sect.fsOff || sect.size) + { + AuTryInsert(modSections, sect); + } } auto pub = AuMakeShared(); diff --git a/Source/Process/ProcessMap.cpp b/Source/Process/ProcessMap.cpp index e0af4359..3b0ae776 100644 --- a/Source/Process/ProcessMap.cpp +++ b/Source/Process/ProcessMap.cpp @@ -131,6 +131,11 @@ namespace Aurora::Process for (const auto §ion : mod->sections) { + if (!section.baseVa) + { + continue; + } + for (AuUInt i = section.baseVa; i < section.baseVa + section.size; i += (kMinPageAlignment * kPageBufferPad)) { auto itr = gModulePtrMap.find(ToLowestPageAlignment(i)); @@ -155,7 +160,6 @@ namespace Aurora::Process static AuOptional
FindInCache(AuUInt pointer) { auto curPtr = ToLowestPageAlignment(pointer); - auto temp = GetSectionCache(curPtr); if (temp.has_value()) return temp; @@ -209,7 +213,7 @@ namespace Aurora::Process #endif } - void BorrowOtherSectionArray(const AuConsumer> &callback) + void BorrowOtherSectionArray(const AuConsumer&> &callback) { AU_LOCK_GUARD(gMutexUnique); callback(gOtherSections); diff --git a/Source/Process/ProcessMap.hpp b/Source/Process/ProcessMap.hpp index e2974758..9e11872b 100644 --- a/Source/Process/ProcessMap.hpp +++ b/Source/Process/ProcessMap.hpp @@ -15,7 +15,7 @@ namespace Aurora::Process AuUInt modBase; }; - void BorrowOtherSectionArray(const AuConsumer> &callback); + void BorrowOtherSectionArray(const AuConsumer&> &callback); PublicModule GetFromModuleCache(AuUInt handle); void InsertModuleCache(const ModuleBasePair &pair, const AuSPtr &mod);