Use a different notation for the address translation

This commit is contained in:
Serge Lamikhov-Center 2021-09-20 00:03:21 +03:00
parent 6da283b3f4
commit dad4b434c8
6 changed files with 18 additions and 18 deletions

View File

@ -148,7 +148,7 @@ class elfio
unsigned char e_ident[EI_NIDENT];
// Read ELF file signature
stream.seekg( addr_translator( 0 ) );
stream.seekg( addr_translator[0] );
stream.read( reinterpret_cast<char*>( &e_ident ), sizeof( e_ident ) );
// Is it ELF file?

View File

@ -107,7 +107,7 @@ template <class T> class elf_header_impl : public elf_header
//------------------------------------------------------------------------------
bool load( std::istream& stream ) override
{
stream.seekg( ( *translator )( 0 ) );
stream.seekg( ( *translator )[0] );
stream.read( reinterpret_cast<char*>( &header ), sizeof( header ) );
return ( stream.gcount() == sizeof( header ) );
@ -116,7 +116,7 @@ template <class T> class elf_header_impl : public elf_header
//------------------------------------------------------------------------------
bool save( std::ostream& stream ) const override
{
stream.seekp( ( *translator )( 0 ) );
stream.seekp( ( *translator )[0] );
stream.write( reinterpret_cast<const char*>( &header ),
sizeof( header ) );

View File

@ -201,7 +201,7 @@ template <class T> class section_impl : public section
set_stream_size( 0xFFFFFFFFFFFFFFFF );
}
stream.seekg( ( *translator )( header_offset ) );
stream.seekg( ( *translator )[ header_offset ] );
stream.read( reinterpret_cast<char*>( &header ), sizeof( header ) );
Elf_Xword size = get_size();
@ -211,7 +211,7 @@ template <class T> class section_impl : public section
if ( ( 0 != size ) && ( nullptr != data ) ) {
stream.seekg(
( *translator )( ( *convertor )( header.sh_offset ) ) );
( *translator )[ ( *convertor )( header.sh_offset ) ] );
stream.read( data, size );
data[size] = 0; // Ensure data is ended with 0 to avoid oob read
data_size = size;

View File

@ -176,12 +176,12 @@ template <class T> class segment_impl : public segment
set_stream_size( 0xFFFFFFFFFFFFFFFF );
}
stream.seekg( ( *translator )( header_offset ) );
stream.seekg( ( *translator )[header_offset] );
stream.read( reinterpret_cast<char*>( &ph ), sizeof( ph ) );
is_offset_set = true;
if ( PT_NULL != get_type() && 0 != get_file_size() ) {
stream.seekg( ( *translator )( ( *convertor )( ph.p_offset ) ) );
stream.seekg( ( *translator )[( *convertor )( ph.p_offset )] );
Elf_Xword size = get_file_size();
if ( size > get_stream_size() ) {

View File

@ -181,7 +181,7 @@ class address_translator
}
//------------------------------------------------------------------------------
std::streampos operator()( std::streampos value ) const
std::streampos operator[]( std::streampos value ) const
{
if ( translation.empty() ) {
return value;

View File

@ -440,18 +440,18 @@ BOOST_AUTO_TEST_CASE( address_translation_test )
address_translator tr;
tr.set_address_translation( ranges );
BOOST_CHECK_EQUAL( tr( 0 ), 500 );
BOOST_CHECK_EQUAL( tr( 510 ), 1010 );
BOOST_CHECK_EQUAL( tr( 1710 ), 1710 );
BOOST_CHECK_EQUAL( tr( 2710 ), 3710 );
BOOST_CHECK_EQUAL( tr( 3710 ), 3710 );
BOOST_CHECK_EQUAL( tr[0], 500 );
BOOST_CHECK_EQUAL( tr[510], 1010 );
BOOST_CHECK_EQUAL( tr[1710], 1710 );
BOOST_CHECK_EQUAL( tr[2710], 3710 );
BOOST_CHECK_EQUAL( tr[3710], 3710 );
ranges.clear();
tr.set_address_translation( ranges );
BOOST_CHECK_EQUAL( tr( 0 ), 0 );
BOOST_CHECK_EQUAL( tr( 510 ), 510 );
BOOST_CHECK_EQUAL( tr( 1710 ), 1710 );
BOOST_CHECK_EQUAL( tr( 2710 ), 2710 );
BOOST_CHECK_EQUAL( tr( 3710 ), 3710 );
BOOST_CHECK_EQUAL( tr[0], 0 );
BOOST_CHECK_EQUAL( tr[510], 510 );
BOOST_CHECK_EQUAL( tr[1710], 1710 );
BOOST_CHECK_EQUAL( tr[2710], 2710 );
BOOST_CHECK_EQUAL( tr[3710], 3710 );
}