| 254 | } |
| 255 | |
| 256 | void PEParser::CheckValidity() { |
| 257 | if (::strncmp((PCSTR)_address, "!<arch>\n", 8) == 0) { |
| 258 | // LIB import library |
| 259 | _importLib = true; |
| 260 | return; |
| 261 | } |
| 262 | |
| 263 | _dosHeader = reinterpret_cast<IMAGE_DOS_HEADER*>(_address); |
| 264 | if (_dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { |
| 265 | // perhaps object file / static library |
| 266 | _fileHeader = (IMAGE_FILE_HEADER*)_address; |
| 267 | _sections = (PIMAGE_SECTION_HEADER)(_fileHeader + 1); |
| 268 | } |
| 269 | else { |
| 270 | auto ntHeader = (PIMAGE_NT_HEADERS64)(_address + _dosHeader->e_lfanew); |
| 271 | _ntHeader = ntHeader; |
| 272 | _fileHeader = &ntHeader->FileHeader; |
| 273 | _opt64 = &ntHeader->OptionalHeader; |
| 274 | _opt32 = (PIMAGE_OPTIONAL_HEADER32)_opt64; |
| 275 | _sections = (PIMAGE_SECTION_HEADER)((BYTE*)_opt64 + _fileHeader->SizeOfOptionalHeader); |
| 276 | } |
| 277 | _valid = true; |
| 278 | } |
| 279 | |
| 280 | unsigned PEParser::RvaToFileOffset(unsigned rva) const { |
| 281 | auto sections = _sections; |
nothing calls this directly
no outgoing calls
no test coverage detected