Better support for read-only ELF access

This commit is contained in:
Vašek Potoček 2017-09-24 13:13:06 +02:00 committed by Serge Lamikhov-Center
parent ced83b14be
commit 972f89e022
6 changed files with 63 additions and 23 deletions

View File

@ -852,6 +852,16 @@ class elfio
return parent->sections_.end();
}
//------------------------------------------------------------------------------
std::vector<section*>::const_iterator begin() const {
return parent->sections_.cbegin();
}
//------------------------------------------------------------------------------
std::vector<section*>::const_iterator end() const {
return parent->sections_.cend();
}
//------------------------------------------------------------------------------
private:
elfio* parent;
@ -897,6 +907,16 @@ class elfio
return parent->segments_.end();
}
//------------------------------------------------------------------------------
std::vector<segment*>::const_iterator begin() const {
return parent->segments_.cbegin();
}
//------------------------------------------------------------------------------
std::vector<segment*>::const_iterator end() const {
return parent->segments_.cend();
}
//------------------------------------------------------------------------------
private:
elfio* parent;

View File

@ -26,13 +26,14 @@ THE SOFTWARE.
namespace ELFIO {
//------------------------------------------------------------------------------
class dynamic_section_accessor
template< class S >
class dynamic_section_accessor_template
{
public:
//------------------------------------------------------------------------------
dynamic_section_accessor( const elfio& elf_file_, section* section_ ) :
elf_file( elf_file_ ),
dynamic_section( section_ )
dynamic_section_accessor_template( const elfio& elf_file_, S* section_ ) :
elf_file( elf_file_ ),
dynamic_section( section_ )
{
}
@ -245,9 +246,12 @@ class dynamic_section_accessor
//------------------------------------------------------------------------------
private:
const elfio& elf_file;
section* dynamic_section;
S* dynamic_section;
};
using dynamic_section_accessor = dynamic_section_accessor_template<section>;
using const_dynamic_section_accessor = dynamic_section_accessor_template<const section>;
} // namespace ELFIO
#endif // ELFIO_DYNAMIC_HPP

View File

@ -38,12 +38,13 @@ namespace ELFIO {
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
class note_section_accessor
template< class S >
class note_section_accessor_template
{
public:
//------------------------------------------------------------------------------
note_section_accessor( const elfio& elf_file_, section* section_ ) :
elf_file( elf_file_ ), note_section( section_ )
note_section_accessor_template( const elfio& elf_file_, S* section_ ) :
elf_file( elf_file_ ), note_section( section_ )
{
process_section();
}
@ -157,10 +158,13 @@ class note_section_accessor
//------------------------------------------------------------------------------
private:
const elfio& elf_file;
section* note_section;
S* note_section;
std::vector<Elf_Xword> note_start_positions;
};
using note_section_accessor = note_section_accessor_template<section>;
using const_note_section_accessor = note_section_accessor_template<const section>;
} // namespace ELFIO
#endif // ELFIO_NOTE_HPP

View File

@ -73,13 +73,14 @@ template<> struct get_sym_and_type< Elf64_Rela >
//------------------------------------------------------------------------------
class relocation_section_accessor
template< class S >
class relocation_section_accessor_template
{
public:
//------------------------------------------------------------------------------
relocation_section_accessor( const elfio& elf_file_, section* section_ ) :
elf_file( elf_file_ ),
relocation_section( section_ )
relocation_section_accessor_template( const elfio& elf_file_, S* section_ ) :
elf_file( elf_file_ ),
relocation_section( section_ )
{
}
@ -361,9 +362,12 @@ class relocation_section_accessor
//------------------------------------------------------------------------------
private:
const elfio& elf_file;
section* relocation_section;
S* relocation_section;
};
using relocation_section_accessor = relocation_section_accessor_template<section>;
using const_relocation_section_accessor = relocation_section_accessor_template<const section>;
} // namespace ELFIO
#endif // ELFIO_RELOCATION_HPP

View File

@ -30,12 +30,13 @@ THE SOFTWARE.
namespace ELFIO {
//------------------------------------------------------------------------------
class string_section_accessor
template< class S >
class string_section_accessor_template
{
public:
//------------------------------------------------------------------------------
string_section_accessor( section* section_ ) :
string_section( section_ )
string_section_accessor_template( S* section_ ) :
string_section( section_ )
{
}
@ -88,9 +89,12 @@ class string_section_accessor
//------------------------------------------------------------------------------
private:
section* string_section;
S* string_section;
};
using string_section_accessor = string_section_accessor_template<section>;
using const_string_section_accessor = string_section_accessor_template<const section>;
} // namespace ELFIO
#endif // ELFIO_STRINGS_HPP

View File

@ -26,13 +26,14 @@ THE SOFTWARE.
namespace ELFIO {
//------------------------------------------------------------------------------
class symbol_section_accessor
template< class S >
class symbol_section_accessor_template
{
public:
//------------------------------------------------------------------------------
symbol_section_accessor( const elfio& elf_file_, section* symbol_section_ ) :
elf_file( elf_file_ ),
symbol_section( symbol_section_ )
symbol_section_accessor_template( const elfio& elf_file_, S* symbol_section_ ) :
elf_file( elf_file_ ),
symbol_section( symbol_section_ )
{
find_hash_section();
}
@ -268,11 +269,14 @@ class symbol_section_accessor
//------------------------------------------------------------------------------
private:
const elfio& elf_file;
section* symbol_section;
S* symbol_section;
Elf_Half hash_section_index;
const section* hash_section;
};
using symbol_section_accessor = symbol_section_accessor_template<section>;
using const_symbol_section_accessor = symbol_section_accessor_template<const section>;
} // namespace ELFIO
#endif // ELFIO_SYMBOLS_HPP