MCPcopy Create free account
hub / github.com/MJx0/KittyMemoryEx / getAllELFs

Method getAllELFs

KittyMemoryEx/KittyScanner.cpp:1078–1217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1076std::vector<ElfScanner> ElfScannerMgr::getAllELFs(EScanElfType type, EScanElfFilter filter)
1077#else
1078std::vector<ElfScanner> ElfScannerMgr::getAllELFs()
1079#endif
1080{
1081 std::vector<ElfScanner> elfs;
1082
1083 if (!_pMem)
1084 return elfs;
1085
1086#ifdef __ANDROID__
1087 const auto progMachine = getProgramElf().header().e_machine;
1088 static auto eMachineCheck = [](EScanElfType type, int a, int b) -> bool {
1089 return a == 0 || b == 0 || type == EScanElfType::Any || (type == EScanElfType::Native && a == b) ||
1090 (type == EScanElfType::Emulated && a != b);
1091 };
1092
1093 const bool isAppFilter = filter == EScanElfFilter::App;
1094 const bool isSysFilter = filter == EScanElfFilter::System;
1095#endif
1096
1097 auto maps = KittyMemoryEx::getAllMaps(_pMem->processID());
1098 if (maps.empty())
1099 {
1100 KITTY_LOGD("GetAllELFs: Failed to get process maps.");
1101 return elfs;
1102 }
1103
1104 unsigned long lastElfNode = 0;
1105
1106 for (auto &it : maps)
1107 {
1108#ifdef __LP64__
1109 if (it.startAddress >= (0x7fffffffffff - 0x1000))
1110 continue;
1111#else
1112 if (it.startAddress >= (0xffffffff - 0x1000))
1113 continue;
1114#endif
1115
1116 if (!it.isValid() || !it.readable || it.writeable || it.is_shared || (it.inode != 0 && it.inode == lastElfNode))
1117 continue;
1118
1119#ifdef __ANDROID__
1120 if (isAppFilter)
1121 {
1122 if (it.inode == 0 || (!KittyUtils::String::startsWith(it.pathname, "/data/") &&
1123 !KittyUtils::String::startsWith(it.pathname, "/proc/") &&
1124 !KittyUtils::String::startsWith(it.pathname, "/memfd:")))
1125 continue;
1126 }
1127 else if (isSysFilter)
1128 {
1129 if ((it.inode == 0 && it.pathname != "[vdso]") ||
1130 (!KittyUtils::String::startsWith(it.pathname, "/system/") &&
1131 !KittyUtils::String::startsWith(it.pathname, "/apex/")))
1132 continue;
1133 }
1134#endif
1135

Callers 3

initMethod · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 8

getAllMapsFunction · 0.85
ElfScannerClass · 0.85
getAddressMapFunction · 0.85
headerMethod · 0.80
filePathMethod · 0.80
baseSegmentMethod · 0.80
processIDMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected