#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/Error.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/WindowsMachineFlag.h"
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBufferRef.h"
#include <algorithm>
#include <cassert>
#include <cinttypes>
#include <cstddef>
#include <cstring>
#include <limits>
#include <memory>
#include <system_error>
usingnamespacellvm;
usingnamespaceobject;
ulittle16_t;
ulittle32_t;
ulittle64_t;
little16_t;
static bool checkSize(MemoryBufferRef M, std::error_code &EC, uint64_t Size) { … }
template <typename T>
static Error getObject(const T *&Obj, MemoryBufferRef M, const void *Ptr,
const uint64_t Size = sizeof(T)) { … }
static bool decodeBase64StringEntry(StringRef Str, uint32_t &Result) { … }
template <typename coff_symbol_type>
const coff_symbol_type *COFFObjectFile::toSymb(DataRefImpl Ref) const { … }
const coff_section *COFFObjectFile::toSec(DataRefImpl Ref) const { … }
void COFFObjectFile::moveSymbolNext(DataRefImpl &Ref) const { … }
Expected<StringRef> COFFObjectFile::getSymbolName(DataRefImpl Ref) const { … }
uint64_t COFFObjectFile::getSymbolValueImpl(DataRefImpl Ref) const { … }
uint32_t COFFObjectFile::getSymbolAlignment(DataRefImpl Ref) const { … }
Expected<uint64_t> COFFObjectFile::getSymbolAddress(DataRefImpl Ref) const { … }
Expected<SymbolRef::Type> COFFObjectFile::getSymbolType(DataRefImpl Ref) const { … }
Expected<uint32_t> COFFObjectFile::getSymbolFlags(DataRefImpl Ref) const { … }
uint64_t COFFObjectFile::getCommonSymbolSizeImpl(DataRefImpl Ref) const { … }
Expected<section_iterator>
COFFObjectFile::getSymbolSection(DataRefImpl Ref) const { … }
unsigned COFFObjectFile::getSymbolSectionID(SymbolRef Sym) const { … }
void COFFObjectFile::moveSectionNext(DataRefImpl &Ref) const { … }
Expected<StringRef> COFFObjectFile::getSectionName(DataRefImpl Ref) const { … }
uint64_t COFFObjectFile::getSectionAddress(DataRefImpl Ref) const { … }
uint64_t COFFObjectFile::getSectionIndex(DataRefImpl Sec) const { … }
uint64_t COFFObjectFile::getSectionSize(DataRefImpl Ref) const { … }
Expected<ArrayRef<uint8_t>>
COFFObjectFile::getSectionContents(DataRefImpl Ref) const { … }
uint64_t COFFObjectFile::getSectionAlignment(DataRefImpl Ref) const { … }
bool COFFObjectFile::isSectionCompressed(DataRefImpl Sec) const { … }
bool COFFObjectFile::isSectionText(DataRefImpl Ref) const { … }
bool COFFObjectFile::isSectionData(DataRefImpl Ref) const { … }
bool COFFObjectFile::isSectionBSS(DataRefImpl Ref) const { … }
bool COFFObjectFile::isDebugSection(DataRefImpl Ref) const { … }
unsigned COFFObjectFile::getSectionID(SectionRef Sec) const { … }
bool COFFObjectFile::isSectionVirtual(DataRefImpl Ref) const { … }
static uint32_t getNumberOfRelocations(const coff_section *Sec,
MemoryBufferRef M, const uint8_t *base) { … }
static const coff_relocation *
getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base) { … }
relocation_iterator COFFObjectFile::section_rel_begin(DataRefImpl Ref) const { … }
relocation_iterator COFFObjectFile::section_rel_end(DataRefImpl Ref) const { … }
Error COFFObjectFile::initSymbolTablePtr() { … }
uint64_t COFFObjectFile::getImageBase() const { … }
Error COFFObjectFile::getVaPtr(uint64_t Addr, uintptr_t &Res) const { … }
Error COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res,
const char *ErrorContext) const { … }
Error COFFObjectFile::getRvaAndSizeAsBytes(uint32_t RVA, uint32_t Size,
ArrayRef<uint8_t> &Contents,
const char *ErrorContext) const { … }
Error COFFObjectFile::getHintName(uint32_t Rva, uint16_t &Hint,
StringRef &Name) const { … }
Error COFFObjectFile::getDebugPDBInfo(const debug_directory *DebugDir,
const codeview::DebugInfo *&PDBInfo,
StringRef &PDBFileName) const { … }
Error COFFObjectFile::getDebugPDBInfo(const codeview::DebugInfo *&PDBInfo,
StringRef &PDBFileName) const { … }
Error COFFObjectFile::initImportTablePtr() { … }
Error COFFObjectFile::initDelayImportTablePtr() { … }
Error COFFObjectFile::initExportTablePtr() { … }
Error COFFObjectFile::initBaseRelocPtr() { … }
Error COFFObjectFile::initDebugDirectoryPtr() { … }
Error COFFObjectFile::initTLSDirectoryPtr() { … }
Error COFFObjectFile::initLoadConfigPtr() { … }
Error COFFObjectFile::initDynamicRelocPtr(uint32_t SectionIndex,
uint32_t SectionOffset) { … }
Expected<std::unique_ptr<COFFObjectFile>>
COFFObjectFile::create(MemoryBufferRef Object) { … }
COFFObjectFile::COFFObjectFile(MemoryBufferRef Object)
: … { … }
static Error ignoreStrippedErrors(Error E) { … }
Error COFFObjectFile::initialize() { … }
basic_symbol_iterator COFFObjectFile::symbol_begin() const { … }
basic_symbol_iterator COFFObjectFile::symbol_end() const { … }
import_directory_iterator COFFObjectFile::import_directory_begin() const { … }
import_directory_iterator COFFObjectFile::import_directory_end() const { … }
delay_import_directory_iterator
COFFObjectFile::delay_import_directory_begin() const { … }
delay_import_directory_iterator
COFFObjectFile::delay_import_directory_end() const { … }
export_directory_iterator COFFObjectFile::export_directory_begin() const { … }
export_directory_iterator COFFObjectFile::export_directory_end() const { … }
section_iterator COFFObjectFile::section_begin() const { … }
section_iterator COFFObjectFile::section_end() const { … }
base_reloc_iterator COFFObjectFile::base_reloc_begin() const { … }
base_reloc_iterator COFFObjectFile::base_reloc_end() const { … }
dynamic_reloc_iterator COFFObjectFile::dynamic_reloc_begin() const { … }
dynamic_reloc_iterator COFFObjectFile::dynamic_reloc_end() const { … }
uint8_t COFFObjectFile::getBytesInAddress() const { … }
StringRef COFFObjectFile::getFileFormatName() const { … }
Triple::ArchType COFFObjectFile::getArch() const { … }
Expected<uint64_t> COFFObjectFile::getStartAddress() const { … }
iterator_range<import_directory_iterator>
COFFObjectFile::import_directories() const { … }
iterator_range<delay_import_directory_iterator>
COFFObjectFile::delay_import_directories() const { … }
iterator_range<export_directory_iterator>
COFFObjectFile::export_directories() const { … }
iterator_range<base_reloc_iterator> COFFObjectFile::base_relocs() const { … }
iterator_range<dynamic_reloc_iterator> COFFObjectFile::dynamic_relocs() const { … }
const data_directory *COFFObjectFile::getDataDirectory(uint32_t Index) const { … }
Expected<const coff_section *> COFFObjectFile::getSection(int32_t Index) const { … }
Expected<StringRef> COFFObjectFile::getString(uint32_t Offset) const { … }
Expected<StringRef> COFFObjectFile::getSymbolName(COFFSymbolRef Symbol) const { … }
Expected<StringRef>
COFFObjectFile::getSymbolName(const coff_symbol_generic *Symbol) const { … }
ArrayRef<uint8_t>
COFFObjectFile::getSymbolAuxData(COFFSymbolRef Symbol) const { … }
uint32_t COFFObjectFile::getSymbolIndex(COFFSymbolRef Symbol) const { … }
Expected<StringRef>
COFFObjectFile::getSectionName(const coff_section *Sec) const { … }
uint64_t COFFObjectFile::getSectionSize(const coff_section *Sec) const { … }
Error COFFObjectFile::getSectionContents(const coff_section *Sec,
ArrayRef<uint8_t> &Res) const { … }
const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const { … }
void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const { … }
uint64_t COFFObjectFile::getRelocationOffset(DataRefImpl Rel) const { … }
symbol_iterator COFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const { … }
uint64_t COFFObjectFile::getRelocationType(DataRefImpl Rel) const { … }
const coff_section *
COFFObjectFile::getCOFFSection(const SectionRef &Section) const { … }
COFFSymbolRef COFFObjectFile::getCOFFSymbol(const DataRefImpl &Ref) const { … }
COFFSymbolRef COFFObjectFile::getCOFFSymbol(const SymbolRef &Symbol) const { … }
const coff_relocation *
COFFObjectFile::getCOFFRelocation(const RelocationRef &Reloc) const { … }
ArrayRef<coff_relocation>
COFFObjectFile::getRelocations(const coff_section *Sec) const { … }
#define LLVM_COFF_SWITCH_RELOC_TYPE_NAME …
StringRef COFFObjectFile::getRelocationTypeName(uint16_t Type) const { … }
#undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
void COFFObjectFile::getRelocationTypeName(
DataRefImpl Rel, SmallVectorImpl<char> &Result) const { … }
bool COFFObjectFile::isRelocatableObject() const { … }
StringRef COFFObjectFile::mapDebugSectionName(StringRef Name) const { … }
std::unique_ptr<MemoryBuffer> COFFObjectFile::getHybridObjectView() const { … }
bool ImportDirectoryEntryRef::
operator==(const ImportDirectoryEntryRef &Other) const { … }
void ImportDirectoryEntryRef::moveNext() { … }
Error ImportDirectoryEntryRef::getImportTableEntry(
const coff_import_directory_table_entry *&Result) const { … }
static imported_symbol_iterator
makeImportedSymbolIterator(const COFFObjectFile *Object,
uintptr_t Ptr, int Index) { … }
static imported_symbol_iterator
importedSymbolBegin(uint32_t RVA, const COFFObjectFile *Object) { … }
static imported_symbol_iterator
importedSymbolEnd(uint32_t RVA, const COFFObjectFile *Object) { … }
imported_symbol_iterator
ImportDirectoryEntryRef::imported_symbol_begin() const { … }
imported_symbol_iterator
ImportDirectoryEntryRef::imported_symbol_end() const { … }
iterator_range<imported_symbol_iterator>
ImportDirectoryEntryRef::imported_symbols() const { … }
imported_symbol_iterator ImportDirectoryEntryRef::lookup_table_begin() const { … }
imported_symbol_iterator ImportDirectoryEntryRef::lookup_table_end() const { … }
iterator_range<imported_symbol_iterator>
ImportDirectoryEntryRef::lookup_table_symbols() const { … }
Error ImportDirectoryEntryRef::getName(StringRef &Result) const { … }
Error
ImportDirectoryEntryRef::getImportLookupTableRVA(uint32_t &Result) const { … }
Error ImportDirectoryEntryRef::getImportAddressTableRVA(
uint32_t &Result) const { … }
bool DelayImportDirectoryEntryRef::
operator==(const DelayImportDirectoryEntryRef &Other) const { … }
void DelayImportDirectoryEntryRef::moveNext() { … }
imported_symbol_iterator
DelayImportDirectoryEntryRef::imported_symbol_begin() const { … }
imported_symbol_iterator
DelayImportDirectoryEntryRef::imported_symbol_end() const { … }
iterator_range<imported_symbol_iterator>
DelayImportDirectoryEntryRef::imported_symbols() const { … }
Error DelayImportDirectoryEntryRef::getName(StringRef &Result) const { … }
Error DelayImportDirectoryEntryRef::getDelayImportTable(
const delay_import_directory_table_entry *&Result) const { … }
Error DelayImportDirectoryEntryRef::getImportAddress(int AddrIndex,
uint64_t &Result) const { … }
bool ExportDirectoryEntryRef::
operator==(const ExportDirectoryEntryRef &Other) const { … }
void ExportDirectoryEntryRef::moveNext() { … }
Error ExportDirectoryEntryRef::getDllName(StringRef &Result) const { … }
Error ExportDirectoryEntryRef::getOrdinalBase(uint32_t &Result) const { … }
Error ExportDirectoryEntryRef::getOrdinal(uint32_t &Result) const { … }
Error ExportDirectoryEntryRef::getExportRVA(uint32_t &Result) const { … }
Error
ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const { … }
Error ExportDirectoryEntryRef::isForwarder(bool &Result) const { … }
Error ExportDirectoryEntryRef::getForwardTo(StringRef &Result) const { … }
bool ImportedSymbolRef::
operator==(const ImportedSymbolRef &Other) const { … }
void ImportedSymbolRef::moveNext() { … }
Error ImportedSymbolRef::getSymbolName(StringRef &Result) const { … }
Error ImportedSymbolRef::isOrdinal(bool &Result) const { … }
Error ImportedSymbolRef::getHintNameRVA(uint32_t &Result) const { … }
Error ImportedSymbolRef::getOrdinal(uint16_t &Result) const { … }
Expected<std::unique_ptr<COFFObjectFile>>
ObjectFile::createCOFFObjectFile(MemoryBufferRef Object) { … }
bool BaseRelocRef::operator==(const BaseRelocRef &Other) const { … }
void BaseRelocRef::moveNext() { … }
Error BaseRelocRef::getType(uint8_t &Type) const { … }
Error BaseRelocRef::getRVA(uint32_t &Result) const { … }
bool DynamicRelocRef::operator==(const DynamicRelocRef &Other) const { … }
void DynamicRelocRef::moveNext() { … }
uint32_t DynamicRelocRef::getType() const { … }
void DynamicRelocRef::getContents(ArrayRef<uint8_t> &Ref) const { … }
Error DynamicRelocRef::validate() const { … }
arm64x_reloc_iterator DynamicRelocRef::arm64x_reloc_begin() const { … }
arm64x_reloc_iterator DynamicRelocRef::arm64x_reloc_end() const { … }
iterator_range<arm64x_reloc_iterator> DynamicRelocRef::arm64x_relocs() const { … }
bool Arm64XRelocRef::operator==(const Arm64XRelocRef &Other) const { … }
uint8_t Arm64XRelocRef::getEntrySize() const { … }
void Arm64XRelocRef::moveNext() { … }
uint8_t Arm64XRelocRef::getSize() const { … }
uint64_t Arm64XRelocRef::getValue() const { … }
Error Arm64XRelocRef::validate(const COFFObjectFile *Obj) const { … }
#define RETURN_IF_ERROR(Expr) …
Expected<ArrayRef<UTF16>>
ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) { … }
Expected<ArrayRef<UTF16>>
ResourceSectionRef::getEntryNameString(const coff_resource_dir_entry &Entry) { … }
Expected<const coff_resource_dir_table &>
ResourceSectionRef::getTableAtOffset(uint32_t Offset) { … }
Expected<const coff_resource_dir_entry &>
ResourceSectionRef::getTableEntryAtOffset(uint32_t Offset) { … }
Expected<const coff_resource_data_entry &>
ResourceSectionRef::getDataEntryAtOffset(uint32_t Offset) { … }
Expected<const coff_resource_dir_table &>
ResourceSectionRef::getEntrySubDir(const coff_resource_dir_entry &Entry) { … }
Expected<const coff_resource_data_entry &>
ResourceSectionRef::getEntryData(const coff_resource_dir_entry &Entry) { … }
Expected<const coff_resource_dir_table &> ResourceSectionRef::getBaseTable() { … }
Expected<const coff_resource_dir_entry &>
ResourceSectionRef::getTableEntry(const coff_resource_dir_table &Table,
uint32_t Index) { … }
Error ResourceSectionRef::load(const COFFObjectFile *O) { … }
Error ResourceSectionRef::load(const COFFObjectFile *O, const SectionRef &S) { … }
Expected<StringRef>
ResourceSectionRef::getContents(const coff_resource_data_entry &Entry) { … }