using namespace llvm;
using namespace object;
-namespace {
using support::ulittle8_t;
using support::ulittle16_t;
using support::ulittle32_t;
using support::little16_t;
-}
-namespace {
// Returns false if size is greater than the buffer size. And sets ec.
-bool checkSize(const MemoryBuffer *M, error_code &EC, uint64_t Size) {
+static bool checkSize(const MemoryBuffer *M, error_code &EC, uint64_t Size) {
if (M->getBufferSize() < Size) {
EC = object_error::unexpected_eof;
return false;
// Sets Obj unless any bytes in [addr, addr + size) fall outsize of m.
// Returns unexpected_eof if error.
template<typename T>
-error_code getObject(const T *&Obj, const MemoryBuffer *M, const uint8_t *Ptr,
- const size_t Size = sizeof(T)) {
+static error_code getObject(const T *&Obj, const MemoryBuffer *M,
+ const uint8_t *Ptr, const size_t Size = sizeof(T)) {
uintptr_t Addr = uintptr_t(Ptr);
if (Addr + Size < Addr ||
Addr + Size < Size ||
Obj = reinterpret_cast<const T *>(Addr);
return object_error::success;
}
-}
const coff_symbol *COFFObjectFile::toSymb(DataRefImpl Ref) const {
const coff_symbol *Addr = reinterpret_cast<const coff_symbol*>(Ref.p);
if (Symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL &&
Symb->SectionNumber == COFF::IMAGE_SYM_UNDEFINED) {
Result = SymbolRef::ST_Unknown;
+ } else if (Symb->getComplexType() == COFF::IMAGE_SYM_DTYPE_FUNCTION) {
+ Result = SymbolRef::ST_Function;
} else {
- if (Symb->getComplexType() == COFF::IMAGE_SYM_DTYPE_FUNCTION) {
- Result = SymbolRef::ST_Function;
- } else {
- uint32_t Characteristics = 0;
- if (Symb->SectionNumber > 0) {
- const coff_section *Section = NULL;
- if (error_code EC = getSection(Symb->SectionNumber, Section))
- return EC;
- Characteristics = Section->Characteristics;
- }
- if (Characteristics & COFF::IMAGE_SCN_MEM_READ &&
- ~Characteristics & COFF::IMAGE_SCN_MEM_WRITE) // Read only.
- Result = SymbolRef::ST_Data;
+ uint32_t Characteristics = 0;
+ if (Symb->SectionNumber > 0) {
+ const coff_section *Section = NULL;
+ if (error_code EC = getSection(Symb->SectionNumber, Section))
+ return EC;
+ Characteristics = Section->Characteristics;
}
+ if (Characteristics & COFF::IMAGE_SCN_MEM_READ &&
+ ~Characteristics & COFF::IMAGE_SCN_MEM_WRITE) // Read only.
+ Result = SymbolRef::ST_Data;
}
return object_error::success;
}
uintptr_t IntPtr = 0;
if (error_code EC = getRvaPtr(ExportTableRva, IntPtr))
return EC;
- ExportDirectory = reinterpret_cast<const export_directory_table_entry *>(IntPtr);
+ ExportDirectory =
+ reinterpret_cast<const export_directory_table_entry *>(IntPtr);
return object_error::success;
}
== 0 && "Aux Symbol data did not point to the beginning of a symbol");
# endif
}
- return ArrayRef<uint8_t>(Aux, Symbol->NumberOfAuxSymbols * sizeof(coff_symbol));
+ return ArrayRef<uint8_t>(Aux,
+ Symbol->NumberOfAuxSymbols * sizeof(coff_symbol));
}
error_code COFFObjectFile::getSectionName(const coff_section *Sec,
return object_error::success;
}
+// Returns the name of the current export symbol. If the symbol is exported only
+// by ordinal, the empty string is set as a result.
+error_code ExportDirectoryEntryRef::getDllName(StringRef &Result) const {
+ uintptr_t IntPtr = 0;
+ if (error_code EC = OwningObject->getRvaPtr(ExportTable->NameRVA, IntPtr))
+ return EC;
+ Result = StringRef(reinterpret_cast<const char *>(IntPtr));
+ return object_error::success;
+}
+
+// Returns the starting ordinal number.
+error_code ExportDirectoryEntryRef::getOrdinalBase(uint32_t &Result) const {
+ Result = ExportTable->OrdinalBase;
+ return object_error::success;
+}
+
// Returns the export ordinal of the current export symbol.
error_code ExportDirectoryEntryRef::getOrdinal(uint32_t &Result) const {
Result = ExportTable->OrdinalBase + Index;
if (error_code EC = OwningObject->getRvaPtr(
ExportTable->ExportAddressTableRVA, IntPtr))
return EC;
- const export_address_table_entry *entry = reinterpret_cast<const export_address_table_entry *>(IntPtr);
+ const export_address_table_entry *entry =
+ reinterpret_cast<const export_address_table_entry *>(IntPtr);
Result = entry[Index].ExportRVA;
return object_error::success;
}
// Returns the name of the current export symbol. If the symbol is exported only
// by ordinal, the empty string is set as a result.
-error_code ExportDirectoryEntryRef::getName(StringRef &Result) const {
+error_code ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const {
uintptr_t IntPtr = 0;
if (error_code EC = OwningObject->getRvaPtr(
ExportTable->OrdinalTableRVA, IntPtr))
error_code EC;
return new COFFObjectFile(Object, EC);
}
-} // end namespace llvm
+}