MCPcopy Create free account
hub / github.com/bloomberg/pystack / extractExecutable

Method extractExecutable

src/pystack/_pystack/corefile.cpp:173–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173std::string
174CoreFileExtractor::extractExecutable() const
175{
176 uintptr_t addr = findExecFn();
177
178 LOG(DEBUG) << std::hex << std::showbase << "Found exec_fn attribute at address: " << std::hex
179 << std::showbase << addr;
180
181 if (!addr) {
182 throw ElfAnalyzerError("Failed to locate the address of the executable string in the core file");
183 }
184
185 auto it = std::find_if(d_maps.cbegin(), d_maps.cend(), [&](auto& map) {
186 return map.start <= addr && addr <= map.end;
187 });
188
189 if (it == d_maps.cend()) {
190 throw ElfAnalyzerError(
191 "Failed to locate the map where the executable string resides in the core file");
192 }
193
194 unsigned long location = addr - it->start + it->offset;
195 std::ifstream is(d_analyzer->d_filename, std::ifstream::binary);
196 if (!is) {
197 throw ElfAnalyzerError("Failed to open the core file for analysis");
198 }
199 is.seekg(location);
200 std::string executable_string;
201 std::getline(is, executable_string, '\0');
202 LOG(DEBUG) << "Executable string (exec_fn) extracted from core file: " << executable_string;
203 return executable_string;
204}
205
206static auto
207read_obj(const char** source, void* dest, size_t size)

Callers

nothing calls this directly

Calls 2

LOGClass · 0.85
ElfAnalyzerErrorClass · 0.85

Tested by

no test coverage detected