File tree 3 files changed +59
-1
lines changed
api/python/Abstract/objects
3 files changed +59
-1
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ using setter_t = void (Binary::*)(T);
30
30
template <class T >
31
31
using it_t = T (Binary::*)(void );
32
32
33
+ template <class T , class P >
34
+ using no_const_func = T (Binary::*)(P);
35
+
33
36
void init_LIEF_Binary_class (py::module& m) {
34
37
py::class_<Binary>(m, " Binary" )
35
38
@@ -80,6 +83,17 @@ void init_LIEF_Binary_class(py::module& m) {
80
83
" Return a list in **read only** of binary's abstract " RST_CLASS_REF (lief.Symbol ) " " ,
81
84
py::return_value_policy::reference_internal)
82
85
86
+ .def (" has_symbol" ,
87
+ &Binary::has_symbol,
88
+ " Check if a " RST_CLASS_REF (lief.Symbol ) " with the given name exists" ,
89
+ " symbol_name" _a)
90
+
91
+ .def (" get_symbol" ,
92
+ static_cast <no_const_func<Symbol&, const std::string&>>(&Binary::get_symbol),
93
+ " Return the " RST_CLASS_REF (lief.Symbol ) " with the given ``name``" ,
94
+ " symbol_name" _a,
95
+ py::return_value_policy::reference)
96
+
83
97
.def (" get_function_address" ,
84
98
&Binary::get_function_address,
85
99
" Return the address of the given function name" ,
Original file line number Diff line number Diff line change @@ -48,11 +48,19 @@ class DLL_PUBLIC Binary : public Visitable {
48
48
Header get_header (void ) const ;
49
49
50
50
// ! @brief Return list of symbols whose elements **can** be modified
51
- it_symbols get_symbols (void );
51
+ it_symbols get_symbols (void );
52
52
53
53
// ! @brief Return list of symbols whose elements **can't** be modified
54
54
it_const_symbols get_symbols (void ) const ;
55
55
56
+ // ! @brief Check if a Symbol with the given name exists
57
+ bool has_symbol (const std::string& name) const ;
58
+
59
+ // ! @brief Return the Symbol with the given name
60
+ const Symbol& get_symbol (const std::string& name) const ;
61
+
62
+ Symbol& get_symbol (const std::string& name);
63
+
56
64
// ! @brief Returns binary's sections
57
65
it_sections get_sections (void );
58
66
it_const_sections get_sections (void ) const ;
@@ -82,6 +90,8 @@ class DLL_PUBLIC Binary : public Visitable {
82
90
virtual void accept (Visitor& visitor) const override ;
83
91
84
92
93
+
94
+
85
95
// ! @brief Patch the content at virtual address @p address with @p patch_value
86
96
// !
87
97
// ! @param[in] address Address to patch
Original file line number Diff line number Diff line change @@ -58,6 +58,40 @@ it_const_symbols Binary::get_symbols(void) const {
58
58
return it_const_symbols{const_cast <Binary*>(this )->get_abstract_symbols ()};
59
59
}
60
60
61
+
62
+ bool Binary::has_symbol (const std::string& name) const {
63
+ symbols_t symbols = const_cast <Binary*>(this )->get_abstract_symbols ();
64
+ auto && it_symbol = std::find_if (
65
+ std::begin (symbols),
66
+ std::end (symbols),
67
+ [&name] (const Symbol* s) {
68
+ return s->name () == name;
69
+ });
70
+
71
+ return it_symbol != std::end (symbols);
72
+ }
73
+
74
+ const Symbol& Binary::get_symbol (const std::string& name) const {
75
+ if (not this ->has_symbol (name)) {
76
+ throw not_found (" Symbol '" + name + " ' not found!" );
77
+ }
78
+
79
+ symbols_t symbols = const_cast <Binary*>(this )->get_abstract_symbols ();
80
+
81
+ auto && it_symbol = std::find_if (
82
+ std::begin (symbols),
83
+ std::end (symbols),
84
+ [&name] (const Symbol* s) {
85
+ return s->name () == name;
86
+ });
87
+
88
+ return **it_symbol;
89
+ }
90
+
91
+ Symbol& Binary::get_symbol (const std::string& name) {
92
+ return const_cast <Symbol&>(static_cast <const Binary*>(this )->get_symbol (name));
93
+ }
94
+
61
95
it_sections Binary::get_sections (void ) {
62
96
return it_sections{this ->get_abstract_sections ()};
63
97
}
You can’t perform that action at this time.
0 commit comments