2#ifndef ROSE_SgAsmPEFileHeader_H
3#define ROSE_SgAsmPEFileHeader_H
5#include <Cxx_GrammarDeclarations.h>
6#include <SgAsmGenericHeader.h>
27#include <Rose/BinaryAnalysis/Address.h>
28#include <Rose/BinaryAnalysis/RelativeVirtualAddress.h>
30#ifdef ROSE_SgAsmPEFileHeader_IMPL
31#include <SgAsmCoffSymbolTable.h>
32#include <SgAsmPERVASizePairList.h>
33#include <SgAsmPESectionTable.h>
41#if !defined(DOCUMENTATION)
56#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
58 friend class boost::serialization::access;
64 s & BOOST_SERIALIZATION_NVP(p_e_cpu_type);
65 s & BOOST_SERIALIZATION_NVP(p_e_nsections);
66 s & BOOST_SERIALIZATION_NVP(p_e_time);
67 s & BOOST_SERIALIZATION_NVP(p_e_coff_symtab);
68 s & BOOST_SERIALIZATION_NVP(p_e_nt_hdr_size);
69 s & BOOST_SERIALIZATION_NVP(p_e_coff_nsyms);
70 s & BOOST_SERIALIZATION_NVP(p_e_flags);
71 s & BOOST_SERIALIZATION_NVP(p_e_opt_magic);
72 s & BOOST_SERIALIZATION_NVP(p_e_lmajor);
73 s & BOOST_SERIALIZATION_NVP(p_e_lminor);
74 s & BOOST_SERIALIZATION_NVP(p_e_code_size);
75 s & BOOST_SERIALIZATION_NVP(p_e_data_size);
76 s & BOOST_SERIALIZATION_NVP(p_e_bss_size);
77 s & BOOST_SERIALIZATION_NVP(p_e_code_rva);
78 s & BOOST_SERIALIZATION_NVP(p_e_data_rva);
79 s & BOOST_SERIALIZATION_NVP(p_e_section_align);
80 s & BOOST_SERIALIZATION_NVP(p_e_file_align);
81 s & BOOST_SERIALIZATION_NVP(p_e_os_major);
82 s & BOOST_SERIALIZATION_NVP(p_e_os_minor);
83 s & BOOST_SERIALIZATION_NVP(p_e_user_major);
84 s & BOOST_SERIALIZATION_NVP(p_e_user_minor);
85 s & BOOST_SERIALIZATION_NVP(p_e_subsys_major);
86 s & BOOST_SERIALIZATION_NVP(p_e_subsys_minor);
87 s & BOOST_SERIALIZATION_NVP(p_e_reserved9);
88 s & BOOST_SERIALIZATION_NVP(p_e_image_size);
89 s & BOOST_SERIALIZATION_NVP(p_e_header_size);
90 s & BOOST_SERIALIZATION_NVP(p_e_file_checksum);
91 s & BOOST_SERIALIZATION_NVP(p_e_subsystem);
92 s & BOOST_SERIALIZATION_NVP(p_e_dll_flags);
93 s & BOOST_SERIALIZATION_NVP(p_e_stack_reserve_size);
94 s & BOOST_SERIALIZATION_NVP(p_e_stack_commit_size);
95 s & BOOST_SERIALIZATION_NVP(p_e_heap_reserve_size);
96 s & BOOST_SERIALIZATION_NVP(p_e_heap_commit_size);
97 s & BOOST_SERIALIZATION_NVP(p_e_loader_flags);
98 s & BOOST_SERIALIZATION_NVP(p_e_num_rvasize_pairs);
99 s & BOOST_SERIALIZATION_NVP(p_rvaSizePairs);
100 s & BOOST_SERIALIZATION_NVP(p_sectionTable);
101 s & BOOST_SERIALIZATION_NVP(p_coffSymbolTable);
113 struct PEFileHeader_disk {
114 unsigned char e_magic[4];
116 uint16_t e_nsections;
118 uint32_t e_coff_symtab;
119 uint32_t e_coff_nsyms;
120 uint16_t e_nt_hdr_size;
123#if !defined(SWIG) && !defined(_MSC_VER)
124 __attribute__((packed))
128 struct PE32OptHeader_disk {
129 uint16_t e_opt_magic;
132 uint16_t e_code_size;
133 uint32_t e_data_size;
135 uint32_t e_entrypoint_rva;
138 uint32_t e_image_base;
139 uint32_t e_section_align;
140 uint32_t e_file_align;
143 uint16_t e_user_major;
144 uint16_t e_user_minor;
145 uint16_t e_subsys_major;
146 uint16_t e_subsys_minor;
147 uint32_t e_reserved9;
148 uint32_t e_image_size;
149 uint32_t e_header_size;
150 uint32_t e_file_checksum;
151 uint16_t e_subsystem;
152 uint16_t e_dll_flags;
153 uint32_t e_stack_reserve_size;
154 uint32_t e_stack_commit_size;
155 uint32_t e_heap_reserve_size;
156 uint32_t e_heap_commit_size;
157 uint32_t e_loader_flags;
158 uint32_t e_num_rvasize_pairs;
160#if !defined(SWIG) && !defined(_MSC_VER)
161 __attribute__((packed))
165 struct PE64OptHeader_disk {
166 uint16_t e_opt_magic;
169 uint16_t e_code_size;
170 uint32_t e_data_size;
172 uint32_t e_entrypoint_rva;
175 uint64_t e_image_base;
176 uint32_t e_section_align;
177 uint32_t e_file_align;
180 uint16_t e_user_major;
181 uint16_t e_user_minor;
182 uint16_t e_subsys_major;
183 uint16_t e_subsys_minor;
184 uint32_t e_reserved9;
185 uint32_t e_image_size;
186 uint32_t e_header_size;
187 uint32_t e_file_checksum;
188 uint16_t e_subsystem;
189 uint16_t e_dll_flags;
190 uint64_t e_stack_reserve_size;
191 uint64_t e_stack_commit_size;
192 uint64_t e_heap_reserve_size;
193 uint64_t e_heap_commit_size;
194 uint32_t e_loader_flags;
195 uint32_t e_num_rvasize_pairs;
197#if !defined(SWIG) && !defined(_MSC_VER)
198 __attribute__((packed))
208 HF_EXECUTABLE = 0x0002,
211 HF_RESERVED_MASK = 0xddfd
216 HF_SPEC_UNKNOWN = 0x0000,
226 DLL_PROC_INIT = 0x0001,
227 DLL_PROC_TERM = 0x0002,
228 DLL_THRD_INIT = 0x0004,
229 DLL_THRD_TERM = 0x0008,
230 DLL_RESERVED_MASK = 0xfff0
239 PAIR_CERTIFICATES = 4,
242 PAIR_ARCHITECTURE = 7,
245 PAIR_LOADCONFIG = 10,
246 PAIR_BOUNDIMPORT = 11,
248 PAIR_DELAYIMPORT = 13,
249 PAIR_CLRRUNTIME = 14,
263 unsigned const& get_e_cpu_type()
const;
264 void set_e_cpu_type(
unsigned const&);
273 unsigned const& get_e_nsections()
const;
274 void set_e_nsections(
unsigned const&);
283 unsigned const& get_e_time()
const;
284 void set_e_time(
unsigned const&);
313 unsigned const& get_e_coff_nsyms()
const;
314 void set_e_coff_nsyms(
unsigned const&);
323 unsigned const& get_e_flags()
const;
324 void set_e_flags(
unsigned const&);
333 unsigned const& get_e_opt_magic()
const;
334 void set_e_opt_magic(
unsigned const&);
343 unsigned const& get_e_lmajor()
const;
344 void set_e_lmajor(
unsigned const&);
353 unsigned const& get_e_lminor()
const;
354 void set_e_lminor(
unsigned const&);
363 unsigned const& get_e_code_size()
const;
364 void set_e_code_size(
unsigned const&);
373 unsigned const& get_e_data_size()
const;
374 void set_e_data_size(
unsigned const&);
383 unsigned const& get_e_bss_size()
const;
384 void set_e_bss_size(
unsigned const&);
415 unsigned const& get_e_section_align()
const;
416 void set_e_section_align(
unsigned const&);
425 unsigned const& get_e_file_align()
const;
426 void set_e_file_align(
unsigned const&);
435 unsigned const& get_e_os_major()
const;
436 void set_e_os_major(
unsigned const&);
445 unsigned const& get_e_os_minor()
const;
446 void set_e_os_minor(
unsigned const&);
455 unsigned const& get_e_user_major()
const;
456 void set_e_user_major(
unsigned const&);
465 unsigned const& get_e_user_minor()
const;
466 void set_e_user_minor(
unsigned const&);
475 unsigned const& get_e_subsys_major()
const;
476 void set_e_subsys_major(
unsigned const&);
485 unsigned const& get_e_subsys_minor()
const;
486 void set_e_subsys_minor(
unsigned const&);
495 unsigned const& get_e_reserved9()
const;
496 void set_e_reserved9(
unsigned const&);
505 unsigned const& get_e_image_size()
const;
506 void set_e_image_size(
unsigned const&);
515 unsigned const& get_e_header_size()
const;
516 void set_e_header_size(
unsigned const&);
525 unsigned const& get_e_file_checksum()
const;
526 void set_e_file_checksum(
unsigned const&);
535 unsigned const& get_e_subsystem()
const;
536 void set_e_subsystem(
unsigned const&);
545 unsigned const& get_e_dll_flags()
const;
546 void set_e_dll_flags(
unsigned const&);
555 unsigned const& get_e_stack_reserve_size()
const;
556 void set_e_stack_reserve_size(
unsigned const&);
565 unsigned const& get_e_stack_commit_size()
const;
566 void set_e_stack_commit_size(
unsigned const&);
575 unsigned const& get_e_heap_reserve_size()
const;
576 void set_e_heap_reserve_size(
unsigned const&);
585 unsigned const& get_e_heap_commit_size()
const;
586 void set_e_heap_commit_size(
unsigned const&);
595 unsigned const& get_e_loader_flags()
const;
596 void set_e_loader_flags(
unsigned const&);
605 unsigned const& get_e_num_rvasize_pairs()
const;
606 void set_e_num_rvasize_pairs(
unsigned const&);
644 virtual const char*
formatName()
const override;
659 std::string rvaSizePairName(PairPurpose,
const char **short_name);
665 void updateRvaSizePairs();
667 void addRvaSizePairs();
671 virtual void unparse(std::ostream&)
const override;
672 virtual void dump(FILE*,
const char *prefix, ssize_t idx)
const override;
673 void createTableSections();
695 virtual const
char *format_name() const override ROSE_DEPRECATED("use formatName");
697 std::
string rvasize_pair_name(PairPurpose, const
char**) ROSE_DEPRECATED("use rvaSizePairName");
698 void set_rvasize_pair(PairPurpose,
SgAsmPESection*) ROSE_DEPRECATED("use set_rvaSizePair");
699 void update_rvasize_pairs() ROSE_DEPRECATED("use updateRvaSizePairs");
700 void add_rvasize_pairs() ROSE_DEPRECATED("use addRvaSizePairs");
701 void create_table_sections() ROSE_DEPRECATED("use createTableSections");
702 Rose::BinaryAnalysis::MemoryMap::Ptr get_loader_map() const ROSE_DEPRECATED("use get_loaderMap");
703 void set_loader_map(const
Rose::BinaryAnalysis::MemoryMap::Ptr&) ROSE_DEPRECATED("use set_loaderMap");
719 void initializeProperties();
738 virtual std::
string class_name() const override;
741 virtual VariantT variantT() const override;
746 enum { static_variant = V_SgAsmPEFileHeader };
761 static const unsigned pool_size;
763 static std::vector<unsigned char *> pools;
768 static unsigned long initializeStorageClassArray(SgAsmPEFileHeaderStorageClass *);
771 static void clearMemoryPool();
772 static void deleteMemoryPool();
775 static void extendMemoryPoolForFileIO();
780 static SgAsmPEFileHeader * getPointerFromGlobalIndex(AstSpecificDataManagingClass *,
unsigned long);
783 static unsigned long getNumberOfValidNodesAndSetGlobalIndexInFreepointer(
unsigned long);
785 static void resetValidFreepointers();
787 static unsigned long getNumberOfLastValidPointer();
790#if defined(INLINE_FUNCTIONS)
792 inline void *
operator new (
size_t size);
795 void *
operator new (
size_t size);
798 void operator delete (
void* pointer,
size_t size);
801 void operator delete (
void* pointer)
847#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
850 virtual RTIReturnType
roseRTI()
override;
864 virtual const char*
sage_class_name() const override ROSE_DEPRECATED_FUNCTION;
870 virtual int variant() const ROSE_DEPRECATED_FUNCTION;
1052 friend class SgAsmPEFileHeaderStorageClass;
1055 friend class AstSpecificDataManagingClass;
1058 friend class AstSpecificDataManagingClassStorageClass;
1090#define BUILD_ATERM_SUPPORT 0
1091 #if BUILD_ATERM_SUPPORT
1092 #ifdef ROSE_USE_ROSE_ATERM_SUPPORT
1104 virtual ATerm generate_ATerm()
override;
1107 virtual void generate_ATerm_Annotation(ATerm & term)
override;
1170unsigned p_e_cpu_type;
1174unsigned p_e_nsections;
1190unsigned p_e_coff_nsyms;
1198unsigned p_e_opt_magic;
1210unsigned p_e_code_size;
1214unsigned p_e_data_size;
1218unsigned p_e_bss_size;
1230unsigned p_e_section_align;
1234unsigned p_e_file_align;
1238unsigned p_e_os_major;
1242unsigned p_e_os_minor;
1246unsigned p_e_user_major;
1250unsigned p_e_user_minor;
1254unsigned p_e_subsys_major;
1258unsigned p_e_subsys_minor;
1262unsigned p_e_reserved9;
1266unsigned p_e_image_size;
1270unsigned p_e_header_size;
1274unsigned p_e_file_checksum;
1278unsigned p_e_subsystem;
1282unsigned p_e_dll_flags;
1286unsigned p_e_stack_reserve_size;
1290unsigned p_e_stack_commit_size;
1294unsigned p_e_heap_reserve_size;
1298unsigned p_e_heap_commit_size;
1302unsigned p_e_loader_flags;
1306unsigned p_e_num_rvasize_pairs;
Class holding static data and functions supporting File I/O.
Attribute containing a regex expression as a string.
Optionally bound relative virtual address.
Base class for binary files.
virtual SgAsmGenericSection * parse()
Parse contents of the section.
List of SgAsmPERVASizePair AST nodes.
Base class for PE sections.
Supporting class from copy mechanism within ROSE.
This class represents the base class for all IR nodes within Sage III.
virtual RTIReturnType roseRTI()
return C++ Runtime-Time-Information
virtual size_t get_numberOfTraversalSuccessors() const
return number of children in the traversal successor list
virtual std::vector< std::string > get_traversalSuccessorNamesContainer() const
container of names of variables or container indices used used in the traversal to access AST success...
virtual void debugSerializationEnd(const char *className)
Called by generated serializers.
static std::string getNodeIdString(SgNode *sgnode)
compute the NodeId for a particular SgNode*.
virtual bool isInMemoryPool()
FOR INTERNAL USE This is used in internal tests to verify that all IR nodes are allocated from the he...
int variant() const
Older version function returns enum value "NODE".
virtual void processDataMemberReferenceToPointers(ReferenceToPointerHandler *)
FOR INTERNAL USE Processes pairs of references to SgNode* and strings for use in AST tools
virtual size_t get_childIndex(SgNode *child) const
index-based access to traversal successors by child node
virtual std::vector< SgNode * > get_traversalSuccessorContainer() const
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
virtual long getChildIndex(SgNode *childNode) const
FOR INTERNAL USE Returns a unique index value for the childNode in the list of children at this IR no...
virtual void debugSerializationBegin(const char *className)
Called by generated serializers.
virtual SgNode * get_traversalSuccessorByIndex(size_t idx) const
index-based access to traversal successors by index number
static void visitRepresentativeNode(ROSE_VisitTraversal &visit)
FOR INTERNAL USE Support for type-based traversal.
virtual void checkDataMemberPointersIfInMemoryPool()
FOR INTERNAL USE This is used in internal tests to verify that all IR nodes are allocated from the he...
static size_t numberOfNodes()
Returns the total number of IR nodes of this type.
virtual void accept(ROSE_VisitorPattern &visitor)
support for the classic visitor pattern done in GoF
static void traverseMemoryPoolVisitorPattern(ROSE_VisitorPattern &visitor)
FOR INTERNAL USE Support for visitor pattern.
void executeVisitorMemberFunction(ROSE_VisitorPattern &visitor)
FOR INTERNAL USE Support for visitor pattern.
static SgNode * getNodeByNodeId(VariantT variantT, size_t poolIdx, size_t itemIdx)
Find a node by its variant type, pool index, and item index.
static size_t memoryUsage()
Returns the size in bytes of the total memory allocated for all IR nodes of this type.
static void traverseMemoryPoolNodes(ROSE_VisitTraversal &visit)
FOR INTERNAL USE Support for visitor pattern over all IR nodes by type of IR node.
virtual const char * sage_class_name() const
generates string representing the class name: (e.g. for SgNode returns "SgNode").
virtual std::vector< std::pair< SgNode *, std::string > > returnDataMemberPointers() const
FOR INTERNAL USE Returns STL vector of pairs of SgNode* and strings for use in AST tools
static SgNode * getNodeByNodeIdInternal(size_t poolIdx, size_t itemIdx)
FOR INTERNAL USE Find an SgNode from its memory pool and location therin.
SgNode * addRegExpAttribute(std::string s, AstRegExAttribute *a)
Support for AST matching using regular expression.
std::uint64_t Address
Address.
void serialize(std::ostream &output, Graph &graph)
Serialize a graph into a stream of bytes.
void copy(const Word *src, const BitRange &srcRange, Word *dst, const BitRange &dstRange)
Copy some bits.