- SectionTable =
- reinterpret_cast<const coff_section *>( base()
- + HeaderStart
- + sizeof(coff_file_header)
- + Header->SizeOfOptionalHeader);
- if (!checkAddr(Data, ec, uintptr_t(SectionTable),
- Header->NumberOfSections * sizeof(coff_section)))
+ if (hasPEHeader) {
+ if ((ec = getObject(PE32Header, Data, base() + CurPtr)))
+ return;
+ if (PE32Header->Magic != 0x10b) {
+ // We only support PE32. If this is PE32 (not PE32+), the magic byte
+ // should be 0x10b. If this is not PE32, continue as if there's no PE
+ // header in this file.
+ PE32Header = 0;
+ } else if (PE32Header->NumberOfRvaAndSize > 0) {
+ const uint8_t *addr = base() + CurPtr + sizeof(pe32_header);
+ uint64_t size = sizeof(data_directory) * PE32Header->NumberOfRvaAndSize;
+ if ((ec = getObject(DataDirectory, Data, addr, size)))
+ return;
+ }
+ CurPtr += COFFHeader->SizeOfOptionalHeader;
+ }
+
+ if ((ec = getObject(SectionTable, Data, base() + CurPtr,
+ COFFHeader->NumberOfSections * sizeof(coff_section))))