@@ -37,123 +37,128 @@ class LIEF_API Binary : public Object {
3737
3838 public:
3939
40- // ! Type of a virtual address
41- enum class VA_TYPES {
42- AUTO = 0 , // /< Guess if it's relative or not
43- RVA = 1 , // /< Relative
44- VA = 2 , // /< Absolute
45- };
40+ // ! Type of a virtual address
41+ enum class VA_TYPES {
42+ AUTO = 0 , // /< Guess if it's relative or not
43+ RVA = 1 , // /< Relative
44+ VA = 2 , // /< Absolute
45+ };
46+
47+ using ctor_t = std::vector<uint64_t >;
4648
4749 public:
48- Binary (void );
49- virtual ~Binary (void );
50+ Binary (void );
51+ virtual ~Binary (void );
52+
53+ Binary& operator =(const Binary&);
54+ Binary (const Binary&);
5055
51- Binary& operator =( const Binary&);
52- Binary ( const Binary&) ;
56+ // ! @brief Executable format (ELF, PE, Mach-O) of the underlying binary
57+ EXE_FORMATS format ( void ) const ;
5358
54- // ! @brief Executable format (ELF, PE, Mach-O) of the underlying binary
55- EXE_FORMATS format (void ) const ;
59+ // ! @brief Return the abstract header of the binary
60+ Header header (void ) const ;
5661
57- // ! @brief Return the abstract header of the binary
58- Header header (void ) const ;
62+ // ! @brief Return list of symbols whose elements **can** be modified
63+ it_symbols symbols (void );
5964
60- // ! @brief Return list of symbols whose elements **can** be modified
61- it_symbols symbols (void );
65+ // ! @brief Return list of symbols whose elements **can't ** be modified
66+ it_const_symbols symbols (void ) const ;
6267
63- // ! @brief Return list of symbols whose elements **can't** be modified
64- it_const_symbols symbols ( void ) const ;
68+ // ! @brief Check if a Symbol with the given name exists
69+ bool has_symbol ( const std::string& name ) const ;
6570
66- // ! @brief Check if a Symbol with the given name exists
67- bool has_symbol (const std::string& name) const ;
71+ // ! @brief Return the Symbol with the given name
72+ const Symbol& get_symbol (const std::string& name) const ;
6873
69- // ! @brief Return the Symbol with the given name
70- const Symbol& get_symbol (const std::string& name) const ;
74+ Symbol& get_symbol (const std::string& name);
7175
72- Symbol& get_symbol (const std::string& name);
76+ // ! @brief Returns binary's sections
77+ it_sections sections (void );
78+ it_const_sections sections (void ) const ;
7379
74- // ! @brief Returns binary's sections
75- it_sections sections (void );
76- it_const_sections sections (void ) const ;
80+ // ! @brief Returns binary's relocations
81+ it_relocations relocations (void );
82+ it_const_relocations relocations (void ) const ;
7783
78- // ! @brief Returns binary's relocations
79- it_relocations relocations (void );
80- it_const_relocations relocations (void ) const ;
84+ // ! @brief Binary's entrypoint (if any)
85+ virtual uint64_t entrypoint (void ) const = 0;
8186
82- // ! @brief Binary's entrypoint (if any)
83- virtual uint64_t entrypoint (void ) const = 0 ;
87+ // ! @brief Binary's name
88+ const std::string& name (void ) const ;
8489
85- // ! @brief Binary's name
86- const std::string& name (void ) const ;
90+ // ! @brief Binary's original size
91+ uint64_t original_size (void ) const ;
8792
88- // ! @brief Binary 's original size
89- uint64_t original_size (void ) const ;
93+ // ! @brief Return functions 's name exported by the binary
94+ std::vector<std::string> exported_functions (void ) const ;
9095
91- // ! @brief Return functions's name exported by the binary
92- std::vector<std::string> exported_functions (void ) const ;
96+ // ! @brief Return libraries which are imported by the binary
97+ std::vector<std::string> imported_libraries (void ) const ;
9398
94- // ! @brief Return libraries which are imported by the binary
95- std::vector<std::string> imported_libraries (void ) const ;
99+ // ! @brief Return functions's name imported by the binary
100+ std::vector<std::string> imported_functions (void ) const ;
96101
97- // ! @brief Return functions's name imported by the binary
98- std::vector<std:: string> imported_functions ( void ) const ;
102+ // ! @brief Return the address of the given function name
103+ virtual uint64_t get_function_address ( const std::string& func_name ) const ;
99104
100- // ! @brief Return the address of the given function name
101- virtual uint64_t get_function_address ( const std::string& func_name ) const ;
105+ // ! @brief Method so that a ``visitor`` can visit us
106+ virtual void accept (Visitor& visitor ) const override ;
102107
103- // ! @brief Method so that a ``visitor`` can visit us
104- virtual void accept (Visitor& visitor) const override ;
108+ std::vector<uint64_t > xref (uint64_t address) const ;
105109
106- std::vector<uint64_t > xref (uint64_t address) const ;
110+ // ! @brief Patch the content at virtual address @p address with @p patch_value
111+ // !
112+ // ! @param[in] address Address to patch
113+ // ! @param[in] patch_value Patch to apply
114+ virtual void patch_address (uint64_t address, const std::vector<uint8_t >& patch_value, VA_TYPES addr_type = VA_TYPES::AUTO) = 0;
107115
108- // ! @brief Patch the content at virtual address @p address with @p patch_value
109- // !
110- // ! @param[in] address Address to patch
111- // ! @param[in] patch_value Patch to apply
112- virtual void patch_address (uint64_t address, const std::vector<uint8_t >& patch_value, VA_TYPES addr_type = VA_TYPES::AUTO) = 0;
116+ // ! @brief Patch the address with the given value
117+ // !
118+ // ! @param[in] address Address to patch
119+ // ! @param[in] patch_value Patch to apply
120+ // ! @param[in] size Size of the value in **bytes** (1, 2, ... 8)
121+ virtual void patch_address (uint64_t address, uint64_t patch_value, size_t size = sizeof (uint64_t ), VA_TYPES addr_type = VA_TYPES::AUTO) = 0;
113122
114- // ! @brief Patch the address with the given value
115- // !
116- // ! @param[in] address Address to patch
117- // ! @param[in] patch_value Patch to apply
118- // ! @param[in] size Size of the value in **bytes** (1, 2, ... 8)
119- virtual void patch_address (uint64_t address, uint64_t patch_value, size_t size = sizeof (uint64_t ), VA_TYPES addr_type = VA_TYPES::AUTO) = 0;
123+ // ! @brief Return the content located at virtual address
124+ virtual std::vector<uint8_t > get_content_from_virtual_address (uint64_t virtual_address, uint64_t size, VA_TYPES addr_type = VA_TYPES::AUTO) const = 0;
120125
121- // ! @brief Return the content located at virtual address
122- virtual std::vector< uint8_t > get_content_from_virtual_address ( uint64_t virtual_address, uint64_t size, VA_TYPES addr_type = VA_TYPES::AUTO) const = 0 ;
126+ // ! @brief Change binary's name
127+ void name ( const std::string& name) ;
123128
124- // ! @brief Change binary's name
125- void name (const std::string& name);
129+ // ! @brief Change binary's original size.
130+ // !
131+ // ! @warning
132+ // ! Should be used carefully because some optimizations can be
133+ // ! done with this value
134+ void original_size (uint64_t size);
126135
127- // ! @brief Change binary's original size.
128- // !
129- // ! @warning
130- // ! Should be used carefully because some optimizations can be
131- // ! done with this value
132- void original_size (uint64_t size);
136+ // ! @brief Check if the binary is position independent
137+ virtual bool is_pie (void ) const = 0;
133138
134- // ! @brief Check if the binary is position independent
135- virtual bool is_pie (void ) const = 0;
139+ // ! @brief Check if the binary uses ``NX`` protection
140+ virtual bool has_nx (void ) const = 0;
136141
137- // ! @brief Check if the binary uses ``NX`` protection
138- virtual bool has_nx (void ) const = 0;
142+ // ! Constructor functions that are called prior any other functions
143+ virtual LIEF::Binary:: ctor_t ctor_functions (void ) const = 0;
139144
140- virtual std::ostream& print (std::ostream& os) const ;
145+ virtual std::ostream& print (std::ostream& os) const ;
141146
142- LIEF_API friend std::ostream& operator <<(std::ostream& os, const Binary& binary);
147+ LIEF_API friend std::ostream& operator <<(std::ostream& os, const Binary& binary);
143148
144149 protected:
145- std::string name_;
150+ std::string name_;
146151
147- uint64_t original_size_;
152+ uint64_t original_size_;
148153
149- virtual Header get_abstract_header (void ) const = 0;
150- virtual symbols_t get_abstract_symbols (void ) = 0;
151- virtual sections_t get_abstract_sections (void ) = 0;
152- virtual relocations_t get_abstract_relocations (void ) = 0;
154+ virtual Header get_abstract_header (void ) const = 0;
155+ virtual symbols_t get_abstract_symbols (void ) = 0;
156+ virtual sections_t get_abstract_sections (void ) = 0;
157+ virtual relocations_t get_abstract_relocations (void ) = 0;
153158
154- virtual std::vector<std::string> get_abstract_exported_functions (void ) const = 0;
155- virtual std::vector<std::string> get_abstract_imported_functions (void ) const = 0;
156- virtual std::vector<std::string> get_abstract_imported_libraries (void ) const = 0;
159+ virtual std::vector<std::string> get_abstract_exported_functions (void ) const = 0;
160+ virtual std::vector<std::string> get_abstract_imported_functions (void ) const = 0;
161+ virtual std::vector<std::string> get_abstract_imported_libraries (void ) const = 0;
157162
158163
159164};
0 commit comments