/Misc/Backups/Memory/First/PeLib/NtHeaders.hpp

http://hadesmem.googlecode.com/ · C++ Header · 335 lines · 131 code · 93 blank · 111 comment · 0 complexity · e99db68cbb80632b605be58fa35c7798 MD5 · raw file

  1. /*
  2. This file is part of HadesMem.
  3. Copyright (C) 2011 Joshua Boyce (a.k.a. RaptorFactor).
  4. <http://www.raptorfactor.com/> <raptorfactor@raptorfactor.com>
  5. HadesMem is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. HadesMem is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with HadesMem. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. // Windows
  18. #include <Windows.h>
  19. // Hades
  20. #include <HadesMemory/Fwd.hpp>
  21. #include <HadesMemory/Error.hpp>
  22. #include <HadesMemory/MemoryMgr.hpp>
  23. #include <HadesMemory/PeLib/PeFile.hpp>
  24. namespace Hades
  25. {
  26. namespace Memory
  27. {
  28. // PE file NT headers
  29. class NtHeaders
  30. {
  31. public:
  32. // NT headers error class
  33. class Error : public virtual HadesMemError
  34. { };
  35. // Data directory entries
  36. enum DataDir
  37. {
  38. DataDir_Export,
  39. DataDir_Import,
  40. DataDir_Resource,
  41. DataDir_Exception,
  42. DataDir_Security,
  43. DataDir_BaseReloc,
  44. DataDir_Debug,
  45. DataDir_Architecture,
  46. DataDir_GlobalPTR,
  47. DataDir_TLS,
  48. DataDir_LoadConfig,
  49. DataDir_BoundImport,
  50. DataDir_IAT,
  51. DataDir_DelayImport,
  52. DataDir_COMDescriptor
  53. };
  54. // Constructor
  55. explicit NtHeaders(PeFile const& MyPeFile);
  56. // Get base of NT headers
  57. PVOID GetBase() const;
  58. // Whether signature is valid
  59. bool IsSignatureValid() const;
  60. // Ensure signature is valid
  61. void EnsureSignatureValid() const;
  62. // Get signature
  63. DWORD GetSignature() const;
  64. // Set signature
  65. void SetSignature(DWORD Signature) const;
  66. // Get machine
  67. WORD GetMachine() const;
  68. // Set machine
  69. void SetMachine(WORD Machine) const;
  70. // Get number of sections
  71. WORD GetNumberOfSections() const;
  72. // Set number of sections
  73. void SetNumberOfSections(WORD NumberOfSections) const;
  74. // Get time date stamp
  75. DWORD GetTimeDateStamp() const;
  76. // Set time date stamp
  77. void SetTimeDateStamp(DWORD TimeDateStamp) const;
  78. // Get pointer to symbol table
  79. DWORD GetPointerToSymbolTable() const;
  80. // Set pointer to symbol table
  81. void SetPointerToSymbolTable(DWORD PointerToSymbolTable) const;
  82. // Get number of symbols
  83. DWORD GetNumberOfSymbols() const;
  84. // Set number of symbols
  85. void SetNumberOfSymbols(DWORD NumberOfSymbols) const;
  86. // Get size of optional header
  87. WORD GetSizeOfOptionalHeader() const;
  88. // Set size of optional header
  89. void SetSizeOfOptionalHeader(WORD SizeOfOptionalHeader) const;
  90. // Get characteristics
  91. WORD GetCharacteristics() const;
  92. // Set characteristics
  93. void SetCharacteristics(WORD Characteristics) const;
  94. // Get magic
  95. WORD GetMagic() const;
  96. // Set magic
  97. void SetMagic(WORD Magic) const;
  98. // Get major linker version
  99. BYTE GetMajorLinkerVersion() const;
  100. // Set major linker version
  101. void SetMajorLinkerVersion(BYTE MajorLinkerVersion) const;
  102. // Get minor linker version
  103. BYTE GetMinorLinkerVersion() const;
  104. // Set major linker version
  105. void SetMinorLinkerVersion(BYTE MinorLinkerVersion) const;
  106. // Get minor linker version
  107. DWORD GetSizeOfCode() const;
  108. // Set major linker version
  109. void SetSizeOfCode(DWORD SizeOfCode) const;
  110. // Get minor linker version
  111. DWORD GetSizeOfInitializedData() const;
  112. // Set major linker version
  113. void SetSizeOfInitializedData(DWORD SizeOfInitializedData) const;
  114. // Get minor linker version
  115. DWORD GetSizeOfUninitializedData() const;
  116. // Set major linker version
  117. void SetSizeOfUninitializedData(DWORD SizeOfUninitializedData) const;
  118. // Get minor linker version
  119. DWORD GetAddressOfEntryPoint() const;
  120. // Set major linker version
  121. void SetAddressOfEntryPoint(DWORD AddressOfEntryPoint) const;
  122. // Get base of code
  123. DWORD GetBaseOfCode() const;
  124. // Set base of code
  125. void SetBaseOfCode(DWORD BaseOfCode) const;
  126. #if defined(_M_IX86)
  127. // Get base of data
  128. DWORD GetBaseOfData() const;
  129. // Set base of data
  130. void SetBaseOfData(DWORD BaseOfData) const;
  131. #endif
  132. // Get base of code
  133. ULONG_PTR GetImageBase() const;
  134. // Set base of code
  135. void SetImageBase(ULONG_PTR ImageBase) const;
  136. // Get base of code
  137. DWORD GetSectionAlignment() const;
  138. // Set base of code
  139. void SetSectionAlignment(DWORD SectionAlignment) const;
  140. // Get base of code
  141. DWORD GetFileAlignment() const;
  142. // Set base of code
  143. void SetFileAlignment(DWORD FileAlignment) const;
  144. // Get base of code
  145. WORD GetMajorOperatingSystemVersion() const;
  146. // Set base of code
  147. void SetMajorOperatingSystemVersion(
  148. WORD MajorOperatingSystemVersion) const;
  149. // Get base of code
  150. WORD GetMinorOperatingSystemVersion() const;
  151. // Set base of code
  152. void SetMinorOperatingSystemVersion(
  153. WORD MinorOperatingSystemVersion) const;
  154. // Get base of code
  155. WORD GetMajorImageVersion() const;
  156. // Set base of code
  157. void SetMajorImageVersion(WORD MajorImageVersion) const;
  158. // Get base of code
  159. WORD GetMinorImageVersion() const;
  160. // Set base of code
  161. void SetMinorImageVersion(WORD MinorImageVersion) const;
  162. // Get base of code
  163. WORD GetMajorSubsystemVersion() const;
  164. // Set base of code
  165. void SetMajorSubsystemVersion(WORD MajorSubsystemVersion) const;
  166. // Get base of code
  167. WORD GetMinorSubsystemVersion() const;
  168. // Set base of code
  169. void SetMinorSubsystemVersion(WORD MinorSubsystemVersion) const;
  170. // Get base of code
  171. DWORD GetWin32VersionValue() const;
  172. // Set base of code
  173. void SetWin32VersionValue(DWORD Win32VersionValue) const;
  174. // Get size of image
  175. DWORD GetSizeOfImage() const;
  176. // Set size of image
  177. void SetSizeOfImage(DWORD SizeOfImage) const;
  178. // Get base of code
  179. DWORD GetSizeOfHeaders() const;
  180. // Set base of code
  181. void SetSizeOfHeaders(DWORD SizeOfHeaders) const;
  182. // Get base of code
  183. DWORD GetCheckSum() const;
  184. // Set base of code
  185. void SetCheckSum(DWORD CheckSum) const;
  186. // Get base of code
  187. WORD GetSubsystem() const;
  188. // Set base of code
  189. void SetSubsystem(WORD Subsystem) const;
  190. // Get base of code
  191. WORD GetDllCharacteristics() const;
  192. // Set base of code
  193. void SetDllCharacteristics(WORD DllCharacteristics) const;
  194. // Get base of code
  195. ULONG_PTR GetSizeOfStackReserve() const;
  196. // Set base of code
  197. void SetSizeOfStackReserve(ULONG_PTR SizeOfStackReserve) const;
  198. // Get base of code
  199. ULONG_PTR GetSizeOfStackCommit() const;
  200. // Set base of code
  201. void SetSizeOfStackCommit(ULONG_PTR SizeOfStackCommit) const;
  202. // Get base of code
  203. ULONG_PTR GetSizeOfHeapReserve() const;
  204. // Set base of code
  205. void SetSizeOfHeapReserve(ULONG_PTR SizeOfHeapReserve) const;
  206. // Get base of code
  207. ULONG_PTR GetSizeOfHeapCommit() const;
  208. // Set base of code
  209. void SetSizeOfHeapCommit(ULONG_PTR SizeOfHeapCommit) const;
  210. // Get base of code
  211. DWORD GetLoaderFlags() const;
  212. // Set base of code
  213. void SetLoaderFlags(DWORD LoaderFlags) const;
  214. // Get base of code
  215. DWORD GetNumberOfRvaAndSizes() const;
  216. // Set base of code
  217. void SetNumberOfRvaAndSizes(DWORD NumberOfRvaAndSizes) const;
  218. // Get base of code
  219. DWORD GetDataDirectoryVirtualAddress(DataDir MyDataDir) const;
  220. // Set base of code
  221. void SetDataDirectoryVirtualAddress(DataDir MyDataDir,
  222. DWORD DataDirectoryVirtualAddress) const;
  223. // Get base of code
  224. DWORD GetDataDirectorySize(DataDir MyDataDir) const;
  225. // Set base of code
  226. void SetDataDirectorySize(DataDir MyDataDir,
  227. DWORD DataDirectorySize) const;
  228. // Get raw NT headers
  229. IMAGE_NT_HEADERS GetHeadersRaw() const;
  230. private:
  231. // PE file
  232. PeFile m_PeFile;
  233. // Memory instance
  234. MemoryMgr m_Memory;
  235. // Base address
  236. PBYTE m_pBase;
  237. };
  238. }
  239. }