| 171 | } |
| 172 | |
| 173 | std::string |
| 174 | CoreFileExtractor::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 | |
| 206 | static auto |
| 207 | read_obj(const char** source, void* dest, size_t size) |
nothing calls this directly
no test coverage detected