2#ifndef ROSE_SgAsmPEFileHeader_H
3#define ROSE_SgAsmPEFileHeader_H
5#include <Cxx_GrammarDeclarations.h>
6#include <SgAsmGenericHeader.h>
27#include <Rose/BinaryAnalysis/RelativeVirtualAddress.h>
29#ifdef ROSE_SgAsmPEFileHeader_IMPL
30#include <SgAsmCoffSymbolTable.h>
31#include <SgAsmPERVASizePairList.h>
32#include <SgAsmPESectionTable.h>
40#if !defined(DOCUMENTATION)
55#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
57 friend class boost::serialization::access;
63 s & BOOST_SERIALIZATION_NVP(p_e_cpu_type);
64 s & BOOST_SERIALIZATION_NVP(p_e_nsections);
65 s & BOOST_SERIALIZATION_NVP(p_e_time);
66 s & BOOST_SERIALIZATION_NVP(p_e_coff_symtab);
67 s & BOOST_SERIALIZATION_NVP(p_e_nt_hdr_size);
68 s & BOOST_SERIALIZATION_NVP(p_e_coff_nsyms);
69 s & BOOST_SERIALIZATION_NVP(p_e_flags);
70 s & BOOST_SERIALIZATION_NVP(p_e_opt_magic);
71 s & BOOST_SERIALIZATION_NVP(p_e_lmajor);
72 s & BOOST_SERIALIZATION_NVP(p_e_lminor);
73 s & BOOST_SERIALIZATION_NVP(p_e_code_size);
74 s & BOOST_SERIALIZATION_NVP(p_e_data_size);
75 s & BOOST_SERIALIZATION_NVP(p_e_bss_size);
76 s & BOOST_SERIALIZATION_NVP(p_e_code_rva);
77 s & BOOST_SERIALIZATION_NVP(p_e_data_rva);
78 s & BOOST_SERIALIZATION_NVP(p_e_section_align);
79 s & BOOST_SERIALIZATION_NVP(p_e_file_align);
80 s & BOOST_SERIALIZATION_NVP(p_e_os_major);
81 s & BOOST_SERIALIZATION_NVP(p_e_os_minor);
82 s & BOOST_SERIALIZATION_NVP(p_e_user_major);
83 s & BOOST_SERIALIZATION_NVP(p_e_user_minor);
84 s & BOOST_SERIALIZATION_NVP(p_e_subsys_major);
85 s & BOOST_SERIALIZATION_NVP(p_e_subsys_minor);
86 s & BOOST_SERIALIZATION_NVP(p_e_reserved9);
87 s & BOOST_SERIALIZATION_NVP(p_e_image_size);
88 s & BOOST_SERIALIZATION_NVP(p_e_header_size);
89 s & BOOST_SERIALIZATION_NVP(p_e_file_checksum);
90 s & BOOST_SERIALIZATION_NVP(p_e_subsystem);
91 s & BOOST_SERIALIZATION_NVP(p_e_dll_flags);
92 s & BOOST_SERIALIZATION_NVP(p_e_stack_reserve_size);
93 s & BOOST_SERIALIZATION_NVP(p_e_stack_commit_size);
94 s & BOOST_SERIALIZATION_NVP(p_e_heap_reserve_size);
95 s & BOOST_SERIALIZATION_NVP(p_e_heap_commit_size);
96 s & BOOST_SERIALIZATION_NVP(p_e_loader_flags);
97 s & BOOST_SERIALIZATION_NVP(p_e_num_rvasize_pairs);
98 s & BOOST_SERIALIZATION_NVP(p_rvaSizePairs);
99 s & BOOST_SERIALIZATION_NVP(p_sectionTable);
100 s & BOOST_SERIALIZATION_NVP(p_coffSymbolTable);
112 struct PEFileHeader_disk {
113 unsigned char e_magic[4];
115 uint16_t e_nsections;
117 uint32_t e_coff_symtab;
118 uint32_t e_coff_nsyms;
119 uint16_t e_nt_hdr_size;
122#if !defined(SWIG) && !defined(_MSC_VER)
123 __attribute__((packed))
127 struct PE32OptHeader_disk {
128 uint16_t e_opt_magic;
131 uint16_t e_code_size;
132 uint32_t e_data_size;
134 uint32_t e_entrypoint_rva;
137 uint32_t e_image_base;
138 uint32_t e_section_align;
139 uint32_t e_file_align;
142 uint16_t e_user_major;
143 uint16_t e_user_minor;
144 uint16_t e_subsys_major;
145 uint16_t e_subsys_minor;
146 uint32_t e_reserved9;
147 uint32_t e_image_size;
148 uint32_t e_header_size;
149 uint32_t e_file_checksum;
150 uint16_t e_subsystem;
151 uint16_t e_dll_flags;
152 uint32_t e_stack_reserve_size;
153 uint32_t e_stack_commit_size;
154 uint32_t e_heap_reserve_size;
155 uint32_t e_heap_commit_size;
156 uint32_t e_loader_flags;
157 uint32_t e_num_rvasize_pairs;
159#if !defined(SWIG) && !defined(_MSC_VER)
160 __attribute__((packed))
164 struct PE64OptHeader_disk {
165 uint16_t e_opt_magic;
168 uint16_t e_code_size;
169 uint32_t e_data_size;
171 uint32_t e_entrypoint_rva;
174 uint64_t e_image_base;
175 uint32_t e_section_align;
176 uint32_t e_file_align;
179 uint16_t e_user_major;
180 uint16_t e_user_minor;
181 uint16_t e_subsys_major;
182 uint16_t e_subsys_minor;
183 uint32_t e_reserved9;
184 uint32_t e_image_size;
185 uint32_t e_header_size;
186 uint32_t e_file_checksum;
187 uint16_t e_subsystem;
188 uint16_t e_dll_flags;
189 uint64_t e_stack_reserve_size;
190 uint64_t e_stack_commit_size;
191 uint64_t e_heap_reserve_size;
192 uint64_t e_heap_commit_size;
193 uint32_t e_loader_flags;
194 uint32_t e_num_rvasize_pairs;
196#if !defined(SWIG) && !defined(_MSC_VER)
197 __attribute__((packed))
207 HF_EXECUTABLE = 0x0002,
210 HF_RESERVED_MASK = 0xddfd
215 HF_SPEC_UNKNOWN = 0x0000,
225 DLL_PROC_INIT = 0x0001,
226 DLL_PROC_TERM = 0x0002,
227 DLL_THRD_INIT = 0x0004,
228 DLL_THRD_TERM = 0x0008,
229 DLL_RESERVED_MASK = 0xfff0
238 PAIR_CERTIFICATES = 4,
241 PAIR_ARCHITECTURE = 7,
244 PAIR_LOADCONFIG = 10,
245 PAIR_BOUNDIMPORT = 11,
247 PAIR_DELAYIMPORT = 13,
248 PAIR_CLRRUNTIME = 14,
262 unsigned const& get_e_cpu_type()
const;
263 void set_e_cpu_type(
unsigned const&);
272 unsigned const& get_e_nsections()
const;
273 void set_e_nsections(
unsigned const&);
282 unsigned const& get_e_time()
const;
283 void set_e_time(
unsigned const&);
292 rose_addr_t
const& get_e_coff_symtab()
const;
293 void set_e_coff_symtab(rose_addr_t
const&);
302 rose_addr_t
const& get_e_nt_hdr_size()
const;
303 void set_e_nt_hdr_size(rose_addr_t
const&);
312 unsigned const& get_e_coff_nsyms()
const;
313 void set_e_coff_nsyms(
unsigned const&);
322 unsigned const& get_e_flags()
const;
323 void set_e_flags(
unsigned const&);
332 unsigned const& get_e_opt_magic()
const;
333 void set_e_opt_magic(
unsigned const&);
342 unsigned const& get_e_lmajor()
const;
343 void set_e_lmajor(
unsigned const&);
352 unsigned const& get_e_lminor()
const;
353 void set_e_lminor(
unsigned const&);
362 unsigned const& get_e_code_size()
const;
363 void set_e_code_size(
unsigned const&);
372 unsigned const& get_e_data_size()
const;
373 void set_e_data_size(
unsigned const&);
382 unsigned const& get_e_bss_size()
const;
383 void set_e_bss_size(
unsigned const&);
414 unsigned const& get_e_section_align()
const;
415 void set_e_section_align(
unsigned const&);
424 unsigned const& get_e_file_align()
const;
425 void set_e_file_align(
unsigned const&);
434 unsigned const& get_e_os_major()
const;
435 void set_e_os_major(
unsigned const&);
444 unsigned const& get_e_os_minor()
const;
445 void set_e_os_minor(
unsigned const&);
454 unsigned const& get_e_user_major()
const;
455 void set_e_user_major(
unsigned const&);
464 unsigned const& get_e_user_minor()
const;
465 void set_e_user_minor(
unsigned const&);
474 unsigned const& get_e_subsys_major()
const;
475 void set_e_subsys_major(
unsigned const&);
484 unsigned const& get_e_subsys_minor()
const;
485 void set_e_subsys_minor(
unsigned const&);
494 unsigned const& get_e_reserved9()
const;
495 void set_e_reserved9(
unsigned const&);
504 unsigned const& get_e_image_size()
const;
505 void set_e_image_size(
unsigned const&);
514 unsigned const& get_e_header_size()
const;
515 void set_e_header_size(
unsigned const&);
524 unsigned const& get_e_file_checksum()
const;
525 void set_e_file_checksum(
unsigned const&);
534 unsigned const& get_e_subsystem()
const;
535 void set_e_subsystem(
unsigned const&);
544 unsigned const& get_e_dll_flags()
const;
545 void set_e_dll_flags(
unsigned const&);
554 unsigned const& get_e_stack_reserve_size()
const;
555 void set_e_stack_reserve_size(
unsigned const&);
564 unsigned const& get_e_stack_commit_size()
const;
565 void set_e_stack_commit_size(
unsigned const&);
574 unsigned const& get_e_heap_reserve_size()
const;
575 void set_e_heap_reserve_size(
unsigned const&);
584 unsigned const& get_e_heap_commit_size()
const;
585 void set_e_heap_commit_size(
unsigned const&);
594 unsigned const& get_e_loader_flags()
const;
595 void set_e_loader_flags(
unsigned const&);
604 unsigned const& get_e_num_rvasize_pairs()
const;
605 void set_e_num_rvasize_pairs(
unsigned const&);
643 virtual const char*
formatName()
const override;
658 std::string rvaSizePairName(PairPurpose,
const char **short_name);
664 void updateRvaSizePairs();
666 void addRvaSizePairs();
670 virtual void unparse(std::ostream&)
const override;
671 virtual void dump(FILE*,
const char *prefix, ssize_t idx)
const override;
672 void createTableSections();
694 virtual const
char *format_name() const override ROSE_DEPRECATED("use formatName");
696 std::
string rvasize_pair_name(PairPurpose, const
char**) ROSE_DEPRECATED("use rvaSizePairName");
697 void set_rvasize_pair(PairPurpose,
SgAsmPESection*) ROSE_DEPRECATED("use set_rvaSizePair");
698 void update_rvasize_pairs() ROSE_DEPRECATED("use updateRvaSizePairs");
699 void add_rvasize_pairs() ROSE_DEPRECATED("use addRvaSizePairs");
700 void create_table_sections() ROSE_DEPRECATED("use createTableSections");
701 Rose::BinaryAnalysis::MemoryMap::Ptr get_loader_map() const ROSE_DEPRECATED("use get_loaderMap");
702 void set_loader_map(const
Rose::BinaryAnalysis::MemoryMap::Ptr&) ROSE_DEPRECATED("use set_loaderMap");
718 void initializeProperties();
737 virtual std::
string class_name() const override;
740 virtual VariantT variantT() const override;
745 enum { static_variant = V_SgAsmPEFileHeader };
760 static const unsigned pool_size;
762 static std::vector<unsigned char *> pools;
767 static unsigned long initializeStorageClassArray(SgAsmPEFileHeaderStorageClass *);
770 static void clearMemoryPool();
771 static void deleteMemoryPool();
774 static void extendMemoryPoolForFileIO();
779 static SgAsmPEFileHeader * getPointerFromGlobalIndex(AstSpecificDataManagingClass *,
unsigned long);
782 static unsigned long getNumberOfValidNodesAndSetGlobalIndexInFreepointer(
unsigned long);
784 static void resetValidFreepointers();
786 static unsigned long getNumberOfLastValidPointer();
789#if defined(INLINE_FUNCTIONS)
791 inline void *
operator new (
size_t size);
794 void *
operator new (
size_t size);
797 void operator delete (
void* pointer,
size_t size);
800 void operator delete (
void* pointer)
846#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
849 virtual RTIReturnType
roseRTI()
override;
863 virtual const char*
sage_class_name() const override ROSE_DEPRECATED_FUNCTION;
869 virtual int variant() const ROSE_DEPRECATED_FUNCTION;
1051 friend class SgAsmPEFileHeaderStorageClass;
1054 friend class AstSpecificDataManagingClass;
1057 friend class AstSpecificDataManagingClassStorageClass;
1089#define BUILD_ATERM_SUPPORT 0
1090 #if BUILD_ATERM_SUPPORT
1091 #ifdef ROSE_USE_ROSE_ATERM_SUPPORT
1103 virtual ATerm generate_ATerm()
override;
1106 virtual void generate_ATerm_Annotation(ATerm & term)
override;
1169unsigned p_e_cpu_type;
1173unsigned p_e_nsections;
1181rose_addr_t p_e_coff_symtab;
1185rose_addr_t p_e_nt_hdr_size;
1189unsigned p_e_coff_nsyms;
1197unsigned p_e_opt_magic;
1209unsigned p_e_code_size;
1213unsigned p_e_data_size;
1217unsigned p_e_bss_size;
1229unsigned p_e_section_align;
1233unsigned p_e_file_align;
1237unsigned p_e_os_major;
1241unsigned p_e_os_minor;
1245unsigned p_e_user_major;
1249unsigned p_e_user_minor;
1253unsigned p_e_subsys_major;
1257unsigned p_e_subsys_minor;
1261unsigned p_e_reserved9;
1265unsigned p_e_image_size;
1269unsigned p_e_header_size;
1273unsigned p_e_file_checksum;
1277unsigned p_e_subsystem;
1281unsigned p_e_dll_flags;
1285unsigned p_e_stack_reserve_size;
1289unsigned p_e_stack_commit_size;
1293unsigned p_e_heap_reserve_size;
1297unsigned p_e_heap_commit_size;
1301unsigned p_e_loader_flags;
1305unsigned 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 size_t get_numberOfTraversalSuccessors()
return number of children in the traversal successor list
virtual RTIReturnType roseRTI()
return C++ Runtime-Time-Information
virtual std::vector< std::string > get_traversalSuccessorNamesContainer()
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 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 size_t get_childIndex(SgNode *child)
index-based access to traversal successors by child node
virtual void debugSerializationBegin(const char *className)
Called by generated serializers.
virtual std::vector< SgNode * > get_traversalSuccessorContainer()
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
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
virtual SgNode * get_traversalSuccessorByIndex(size_t idx)
index-based access to traversal successors by index number
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.
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.