mirror of
https://github.com/serge1/ELFIO.git
synced 2024-11-19 11:14:46 +00:00
In dynamic section count entries until DT_NULL; Add const for modinfo params
This commit is contained in:
parent
ab41401ab2
commit
49c2de32ec
@ -23,6 +23,8 @@ THE SOFTWARE.
|
||||
#ifndef ELFIO_DYNAMIC_HPP
|
||||
#define ELFIO_DYNAMIC_HPP
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace ELFIO {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -31,21 +33,30 @@ template <class S> class dynamic_section_accessor_template
|
||||
public:
|
||||
//------------------------------------------------------------------------------
|
||||
dynamic_section_accessor_template( const elfio& elf_file_, S* section_ )
|
||||
: elf_file( elf_file_ ), dynamic_section( section_ )
|
||||
: elf_file( elf_file_ ), dynamic_section( section_ ), entries_num( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Xword get_entries_num() const
|
||||
{
|
||||
Elf_Xword nRet = 0;
|
||||
|
||||
if ( 0 != dynamic_section->get_entry_size() ) {
|
||||
nRet =
|
||||
if ( ( 0 == entries_num ) &&
|
||||
( 0 != dynamic_section->get_entry_size() ) ) {
|
||||
entries_num =
|
||||
dynamic_section->get_size() / dynamic_section->get_entry_size();
|
||||
Elf_Xword i;
|
||||
Elf_Xword tag;
|
||||
Elf_Xword value;
|
||||
std::string str;
|
||||
for ( i = 0; i < entries_num; i++ ) {
|
||||
get_entry( i, tag, value, str );
|
||||
if ( tag == DT_NULL )
|
||||
break;
|
||||
}
|
||||
entries_num = std::min( entries_num, i + 1 );
|
||||
}
|
||||
|
||||
return nRet;
|
||||
return entries_num;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -234,8 +245,9 @@ template <class S> class dynamic_section_accessor_template
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
private:
|
||||
const elfio& elf_file;
|
||||
S* dynamic_section;
|
||||
const elfio& elf_file;
|
||||
S* dynamic_section;
|
||||
mutable Elf_Xword entries_num;
|
||||
};
|
||||
|
||||
using dynamic_section_accessor = dynamic_section_accessor_template<section>;
|
||||
|
@ -56,7 +56,7 @@ template <class S> class modinfo_section_accessor_template
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool get_attribute( std::string field_name, std::string& value ) const
|
||||
bool get_attribute( const std::string field_name, std::string& value ) const
|
||||
{
|
||||
for ( auto i = content.begin(); i != content.end(); i++ ) {
|
||||
if ( field_name == i->first ) {
|
||||
@ -69,7 +69,7 @@ template <class S> class modinfo_section_accessor_template
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Word add_attribute( std::string field, std::string value )
|
||||
Elf_Word add_attribute( const std::string field, const std::string value )
|
||||
{
|
||||
Elf_Word current_position = 0;
|
||||
|
||||
|
@ -892,7 +892,7 @@ BOOST_AUTO_TEST_CASE( test_dynamic_64_1 )
|
||||
|
||||
dynamic_section_accessor da( reader, dynsec );
|
||||
|
||||
BOOST_CHECK_EQUAL( da.get_entries_num(), 26 );
|
||||
BOOST_CHECK_EQUAL( da.get_entries_num(), 21 );
|
||||
|
||||
Elf_Xword tag;
|
||||
Elf_Xword value;
|
||||
@ -926,7 +926,7 @@ BOOST_AUTO_TEST_CASE( test_dynamic_64_2 )
|
||||
|
||||
dynamic_section_accessor da( reader, dynsec );
|
||||
|
||||
BOOST_CHECK_EQUAL( da.get_entries_num(), 24 );
|
||||
BOOST_CHECK_EQUAL( da.get_entries_num(), 20 );
|
||||
|
||||
Elf_Xword tag;
|
||||
Elf_Xword value;
|
||||
@ -956,7 +956,7 @@ BOOST_AUTO_TEST_CASE( test_dynamic_64_3 )
|
||||
BOOST_REQUIRE( dynsec != NULL );
|
||||
|
||||
dynamic_section_accessor da( reader, dynsec );
|
||||
BOOST_CHECK_EQUAL( da.get_entries_num(), 26 );
|
||||
BOOST_CHECK_EQUAL( da.get_entries_num(), 21 );
|
||||
|
||||
section* strsec1 = reader.sections.add( ".dynstr" );
|
||||
strsec1->set_type( SHT_STRTAB );
|
||||
|
Loading…
Reference in New Issue
Block a user