[*] Linux: replace the initial map scanners aggressive filtering to not dismiss potential hits. Also parses file offsets for these section maps.

This commit is contained in:
Reece Wilson 2023-09-15 23:50:00 +01:00
parent e3a493bf9c
commit 9bfd895fc4

View File

@ -22,12 +22,12 @@ namespace Aurora::Process
{
void InitProcessMapLinux()
{
//puts("InitProcessMapLinux");
}
void DeinitProcessMapLinux()
{
//puts("DeinitProcessMapLinux");
}
static AuHashMap<AuUInt, AuTuple<AuString, AuList<AuTuple<AuUInt, AuUInt, AuUInt, AuUInt>>>> gModuleMap;
@ -44,7 +44,6 @@ namespace Aurora::Process
if (!AuIOFS::FileExists(fileName))
{
//printf("drop: %s\n", fileName.c_str());
return 0;
}
@ -76,6 +75,7 @@ namespace Aurora::Process
Sections sections;
AuParse::SplitNewlines(map, [&](const AuString &line)
{
bool bIsSpecialFile {};
char *endPtr;
auto base = strtoll(line.c_str(), &endPtr, 16);
if (errno == ERANGE) return;
@ -90,6 +90,10 @@ namespace Aurora::Process
auto A = line.find_first_of(':');
if (A == AuString::npos) return;
auto offsetStart = perms + 5;
auto uFileOffset = strtoll(offsetStart, &endPtr, 16);
if (errno == ERANGE) uFileOffset = 0;
A += 4;
auto gross = line.substr(A);
@ -119,10 +123,26 @@ namespace Aurora::Process
if (name.size())
{
bool bIsFile = AuIOFS::FileExists(name);
if (bIsFile)
bIsSpecialFile = AuIOFS::FileExists(name);
if (bIsSpecialFile)
{
return;
for (const auto &[uBaseAddress, pathSectionPair] : gModuleMap)
{
if (uBaseAddress == base)
{
return;
}
for (auto &[a, b, c, d] : AuGet<1>(pathSectionPair))
{
if ((uBaseAddress + a) <= base &&
(uBaseAddress + a + c) > base)
{
return;
}
}
}
}
}
@ -131,13 +151,53 @@ namespace Aurora::Process
sect.origVa = 0;
sect.baseVa = base;
sect.size = end - base;
sect.fsOff = 0;
sect.fsOff = uFileOffset;
sect.pt.readable = perms[0] == 'r';
sect.pt.writable = perms[1] == 'w';
sect.pt.NX = perms[2] != 'x';
sect.name = AuMove(name);
if (bIsSpecialFile)
{
// edge case: these are like windows nt section views
// insert these as their own modules
// (we cant present Sections of weakly owned files )
static AuMutex gLock;
static AuHashMap<AuString, AuSPtr<PublicModule>> gMap;
sect.name = kSectionNameFile;
AU_LOCK_GUARD(gLock);
auto &refMod = gMap[name];
if (refMod)
{
// already cached
}
else
{
refMod = AuMakeShared<PublicModule>();
if (!refMod) return;
refMod->moduleMeta = AuMakeShared<ModuleMeta>();
if (!refMod->moduleMeta) return;
AuString fileName;
AuIOFS::GetFileFromPath(fileName, name);
refMod->moduleMeta->moduleBase = base;
refMod->moduleMeta->moduleName = fileName;
refMod->moduleMeta->modulePath = name;
refMod->moduleMeta->origVa = 0;
}
sect.moduleMeta = refMod;
}
else
{
// most likely
sect.name = AuMove(name);
}
AuTryInsert(sections, sect);
}, false);