return nullptr;
return reinterpret_cast<const dos_header *>(base());
}
- std::error_code getCOFFHeader(const coff_file_header *&Res) const;
- std::error_code
- getCOFFBigObjHeader(const coff_bigobj_file_header *&Res) const;
- std::error_code getPE32Header(const pe32_header *&Res) const;
- std::error_code getPE32PlusHeader(const pe32plus_header *&Res) const;
+
+ const coff_file_header *getCOFFHeader() const { return COFFHeader; }
+ const coff_bigobj_file_header *getCOFFBigObjHeader() const {
+ return COFFBigObjHeader;
+ }
+ const pe32_header *getPE32Header() const { return PE32Header; }
+ const pe32plus_header *getPE32PlusHeader() const { return PE32PlusHeader; }
+
std::error_code getDataDirectory(uint32_t index,
const data_directory *&Res) const;
std::error_code getSection(int32_t index, const coff_section *&Res) const;
return make_range(base_reloc_begin(), base_reloc_end());
}
-std::error_code
-COFFObjectFile::getCOFFHeader(const coff_file_header *&Res) const {
- Res = COFFHeader;
- return std::error_code();
-}
-
-std::error_code
-COFFObjectFile::getCOFFBigObjHeader(const coff_bigobj_file_header *&Res) const {
- Res = COFFBigObjHeader;
- return std::error_code();
-}
-
-std::error_code COFFObjectFile::getPE32Header(const pe32_header *&Res) const {
- Res = PE32Header;
- return std::error_code();
-}
-
-std::error_code
-COFFObjectFile::getPE32PlusHeader(const pe32plus_header *&Res) const {
- Res = PE32PlusHeader;
- return std::error_code();
-}
-
std::error_code
COFFObjectFile::getDataDirectory(uint32_t Index,
const data_directory *&Res) const {
DH->AddressOfNewExeHeader - sizeof(*DH));
if (COFFObj.is64()) {
- const pe32plus_header *PE32Plus = nullptr;
- if (auto EC = COFFObj.getPE32PlusHeader(PE32Plus))
- return errorCodeToError(EC);
- Obj.PeHeader = *PE32Plus;
+ Obj.PeHeader = *COFFObj.getPE32PlusHeader();
} else {
- const pe32_header *PE32 = nullptr;
- if (auto EC = COFFObj.getPE32Header(PE32))
- return errorCodeToError(EC);
+ const pe32_header *PE32 = COFFObj.getPE32Header();
copyPeHeader(Obj.PeHeader, *PE32);
// The pe32plus_header (stored in Object) lacks the BaseOfData field.
Obj.BaseOfData = PE32->BaseOfData;
Expected<std::unique_ptr<Object>> COFFReader::create() const {
auto Obj = std::make_unique<Object>();
- const coff_file_header *CFH = nullptr;
- const coff_bigobj_file_header *CBFH = nullptr;
- COFFObj.getCOFFHeader(CFH);
- COFFObj.getCOFFBigObjHeader(CBFH);
bool IsBigObj = false;
- if (CFH) {
+ if (const coff_file_header *CFH = COFFObj.getCOFFHeader()) {
Obj->CoffFileHeader = *CFH;
} else {
+ const coff_bigobj_file_header *CBFH = COFFObj.getCOFFBigObjHeader();
if (!CBFH)
return createStringError(object_error::parse_failed,
"no COFF file header returned");
if (Count == 0)
return;
- const pe32_header *PE32Header;
- error(Obj->getPE32Header(PE32Header));
- uint32_t ImageBase = PE32Header->ImageBase;
+ uint32_t ImageBase = Obj->getPE32Header()->ImageBase;
uintptr_t IntPtr = 0;
error(Obj->getVaPtr(TableVA, IntPtr));
const support::ulittle32_t *P = (const support::ulittle32_t *)IntPtr;
}
static void printTLSDirectory(const COFFObjectFile *Obj) {
- const pe32_header *PE32Header;
- error(Obj->getPE32Header(PE32Header));
-
- const pe32plus_header *PE32PlusHeader;
- error(Obj->getPE32PlusHeader(PE32PlusHeader));
+ const pe32_header *PE32Header = Obj->getPE32Header();
+ const pe32plus_header *PE32PlusHeader = Obj->getPE32PlusHeader();
// Skip if it's not executable.
if (!PE32Header && !PE32PlusHeader)
}
static void printLoadConfiguration(const COFFObjectFile *Obj) {
- // Skip if it's not executable.
- const pe32_header *PE32Header;
- error(Obj->getPE32Header(PE32Header));
- if (!PE32Header)
+ if (!Obj->getPE32Header())
return;
// Currently only x86 is supported
}
FunctionAddress = *FunctionAddressOrErr;
} else {
- const pe32_header *PEHeader;
- if (COFF.getPE32Header(PEHeader))
- return false;
- FunctionAddress = PEHeader->ImageBase + RF.BeginAddress;
+ FunctionAddress = COFF.getPE32Header()->ImageBase + RF.BeginAddress;
}
SW.printString("Function", formatSymbol(FunctionName, FunctionAddress));
// Print PE header. This header does not exist if this is an object file and
// not an executable.
- const pe32_header *PEHeader = nullptr;
- if (std::error_code EC = Obj->getPE32Header(PEHeader))
- reportError(EC, Obj->getFileName());
- if (PEHeader)
+ if (const pe32_header *PEHeader = Obj->getPE32Header())
printPEHeader<pe32_header>(PEHeader);
- const pe32plus_header *PEPlusHeader = nullptr;
- if (std::error_code EC = Obj->getPE32PlusHeader(PEPlusHeader))
- reportError(EC, Obj->getFileName());
- if (PEPlusHeader)
+ if (const pe32plus_header *PEPlusHeader = Obj->getPE32PlusHeader())
printPEHeader<pe32plus_header>(PEPlusHeader);
if (const dos_header *DH = Obj->getDOSHeader())
}
COFFDumper::COFFDumper(const object::COFFObjectFile &Obj) : Obj(Obj) {
- const object::pe32_header *PE32Header = nullptr;
- Obj.getPE32Header(PE32Header);
- if (PE32Header) {
+ if (const object::pe32_header *PE32Header = Obj.getPE32Header())
dumpOptionalHeader(PE32Header);
- } else {
- const object::pe32plus_header *PE32PlusHeader = nullptr;
- Obj.getPE32PlusHeader(PE32PlusHeader);
- if (PE32PlusHeader) {
- dumpOptionalHeader(PE32PlusHeader);
- }
- }
+ else if (const object::pe32plus_header *PE32PlusHeader =
+ Obj.getPE32PlusHeader())
+ dumpOptionalHeader(PE32PlusHeader);
+
dumpHeader();
dumpSections(Obj.getNumberOfSections());
dumpSymbols(Obj.getNumberOfSymbols());