Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
7.2 KiB

  1. //===- MachO.h - MachO object file implementation ---------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file declares the MachOObjectFile class, which implement the ObjectFile
  11. // interface for MachO files.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_OBJECT_MACHO_H
  15. #define LLVM_OBJECT_MACHO_H
  16. #include "llvm/ADT/ArrayRef.h"
  17. #include "llvm/ADT/SmallVector.h"
  18. #include "llvm/Object/MachOFormat.h"
  19. #include "llvm/Object/ObjectFile.h"
  20. #include "llvm/Support/MachO.h"
  21. #include "llvm/Support/raw_ostream.h"
  22. namespace llvm {
  23. namespace object {
  24. class MachOObjectFile : public ObjectFile {
  25. public:
  26. struct LoadCommandInfo {
  27. const char *Ptr; // Where in memory the load command is.
  28. macho::LoadCommand C; // The command itself.
  29. };
  30. MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, bool Is64Bits,
  31. error_code &ec);
  32. virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
  33. virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
  34. virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
  35. virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const;
  36. virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
  37. virtual error_code getSymbolType(DataRefImpl Symb,
  38. SymbolRef::Type &Res) const;
  39. virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
  40. virtual error_code getSymbolFlags(DataRefImpl Symb, uint32_t &Res) const;
  41. virtual error_code getSymbolSection(DataRefImpl Symb,
  42. section_iterator &Res) const;
  43. virtual error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const;
  44. virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const;
  45. virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const;
  46. virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const;
  47. virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const;
  48. virtual error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const;
  49. virtual error_code getSectionAlignment(DataRefImpl Sec, uint64_t &Res) const;
  50. virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const;
  51. virtual error_code isSectionData(DataRefImpl Sec, bool &Res) const;
  52. virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const;
  53. virtual error_code isSectionRequiredForExecution(DataRefImpl Sec,
  54. bool &Res) const;
  55. virtual error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const;
  56. virtual error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const;
  57. virtual error_code isSectionReadOnlyData(DataRefImpl Sec, bool &Res) const;
  58. virtual error_code sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb,
  59. bool &Result) const;
  60. virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const;
  61. virtual relocation_iterator getSectionRelEnd(DataRefImpl Sec) const;
  62. virtual error_code getRelocationNext(DataRefImpl Rel,
  63. RelocationRef &Res) const;
  64. virtual error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const;
  65. virtual error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const;
  66. virtual error_code getRelocationSymbol(DataRefImpl Rel, SymbolRef &Res) const;
  67. virtual error_code getRelocationType(DataRefImpl Rel, uint64_t &Res) const;
  68. virtual error_code getRelocationTypeName(DataRefImpl Rel,
  69. SmallVectorImpl<char> &Result) const;
  70. virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
  71. int64_t &Res) const;
  72. virtual error_code getRelocationValueString(DataRefImpl Rel,
  73. SmallVectorImpl<char> &Result) const;
  74. virtual error_code getRelocationHidden(DataRefImpl Rel, bool &Result) const;
  75. virtual error_code getLibraryNext(DataRefImpl LibData, LibraryRef &Res) const;
  76. virtual error_code getLibraryPath(DataRefImpl LibData, StringRef &Res) const;
  77. // TODO: Would be useful to have an iterator based version
  78. // of the load command interface too.
  79. virtual symbol_iterator begin_symbols() const;
  80. virtual symbol_iterator end_symbols() const;
  81. virtual symbol_iterator begin_dynamic_symbols() const;
  82. virtual symbol_iterator end_dynamic_symbols() const;
  83. virtual section_iterator begin_sections() const;
  84. virtual section_iterator end_sections() const;
  85. virtual library_iterator begin_libraries_needed() const;
  86. virtual library_iterator end_libraries_needed() const;
  87. virtual uint8_t getBytesInAddress() const;
  88. virtual StringRef getFileFormatName() const;
  89. virtual unsigned getArch() const;
  90. virtual StringRef getLoadName() const;
  91. // In a MachO file, sections have a segment name. This is used in the .o
  92. // files. They have a single segment, but this field specifies which segment
  93. // a section should be put in in the final object.
  94. StringRef getSectionFinalSegmentName(DataRefImpl Sec) const;
  95. // Names are stored as 16 bytes. These returns the raw 16 bytes without
  96. // interpreting them as a C string.
  97. ArrayRef<char> getSectionRawName(DataRefImpl Sec) const;
  98. ArrayRef<char> getSectionRawFinalSegmentName(DataRefImpl Sec) const;
  99. // MachO specific Info about relocations.
  100. bool isRelocationScattered(const macho::RelocationEntry &RE) const;
  101. unsigned getPlainRelocationSymbolNum(const macho::RelocationEntry &RE) const;
  102. bool getPlainRelocationExternal(const macho::RelocationEntry &RE) const;
  103. bool getScatteredRelocationScattered(const macho::RelocationEntry &RE) const;
  104. uint32_t getScatteredRelocationValue(const macho::RelocationEntry &RE) const;
  105. unsigned getAnyRelocationAddress(const macho::RelocationEntry &RE) const;
  106. unsigned getAnyRelocationPCRel(const macho::RelocationEntry &RE) const;
  107. unsigned getAnyRelocationLength(const macho::RelocationEntry &RE) const;
  108. unsigned getAnyRelocationType(const macho::RelocationEntry &RE) const;
  109. // Walk load commands.
  110. LoadCommandInfo getFirstLoadCommandInfo() const;
  111. LoadCommandInfo getNextLoadCommandInfo(const LoadCommandInfo &L) const;
  112. // MachO specific structures.
  113. macho::Section getSection(DataRefImpl DRI) const;
  114. macho::Section64 getSection64(DataRefImpl DRI) const;
  115. macho::SymbolTableEntry getSymbolTableEntry(DataRefImpl DRI) const;
  116. macho::Symbol64TableEntry getSymbol64TableEntry(DataRefImpl DRI) const;
  117. macho::LinkeditDataLoadCommand
  118. getLinkeditDataLoadCommand(const LoadCommandInfo &L) const;
  119. macho::RelocationEntry getRelocation(DataRefImpl Rel) const;
  120. macho::Header getHeader() const;
  121. macho::SymtabLoadCommand getSymtabLoadCommand() const;
  122. bool is64Bit() const;
  123. void ReadULEB128s(uint64_t Index, SmallVectorImpl<uint64_t> &Out) const;
  124. static bool classof(const Binary *v) {
  125. return v->isMachO();
  126. }
  127. private:
  128. typedef SmallVector<const char*, 1> SectionList;
  129. SectionList Sections;
  130. const char *SymtabLoadCmd;
  131. };
  132. }
  133. }
  134. #endif