MCPcopy Create free account
hub / github.com/BeneficialCode/WinArk / CheckValidity

Method CheckValidity

PEParser/PEParser.cpp:256–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256void 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
280unsigned PEParser::RvaToFileOffset(unsigned rva) const {
281 auto sections = _sections;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected