Modernize more files

This commit is contained in:
Serge Lamikhov-Center 2022-09-01 18:49:56 +03:00
parent fc4df31fc2
commit dd425d83c6
9 changed files with 43 additions and 58 deletions

View File

@ -630,8 +630,7 @@ constexpr Elf_Word NT_MEMTAG = 0xff000001; // Contains a copy of the memory t
/* ARM-specific NT_MEMTAG types. */
constexpr Elf_Word NT_MEMTAG_TYPE_AARCH_MTE = 0x400; // MTE memory tags for AArch64.
/* Note segment for SystemTap probes. */
#define NT_STAPSDT 3
constexpr Elf_Word NT_STAPSDT = 3; // Note segment for SystemTap probes.
// Note name is "FreeBSD"
constexpr Elf_Word NT_FREEBSD_THRMISC = 7; // Thread miscellaneous info.

View File

@ -78,13 +78,8 @@ template <class T> class elf_header_impl : public elf_header
elf_header_impl( endianess_convertor* convertor,
unsigned char encoding,
const address_translator* translator )
: convertor( convertor ), translator( translator )
{
this->convertor = convertor;
this->translator = translator;
std::fill_n( reinterpret_cast<char*>( &header ), sizeof( header ),
'\0' );
header.e_ident[EI_MAG0] = ELFMAG0;
header.e_ident[EI_MAG1] = ELFMAG1;
header.e_ident[EI_MAG2] = ELFMAG2;
@ -148,9 +143,9 @@ template <class T> class elf_header_impl : public elf_header
ELFIO_GET_SET_ACCESS( Elf64_Off, segments_offset, header.e_phoff );
private:
T header;
endianess_convertor* convertor;
const address_translator* translator;
T header = {};
endianess_convertor* convertor = nullptr;
const address_translator* translator = nullptr;
};
} // namespace ELFIO

View File

@ -33,7 +33,7 @@ template <class S> class modinfo_section_accessor_template
{
public:
//------------------------------------------------------------------------------
modinfo_section_accessor_template( S* section ) : modinfo_section( section )
explicit modinfo_section_accessor_template( S* section ) : modinfo_section( section )
{
process_section();
}
@ -55,9 +55,9 @@ template <class S> class modinfo_section_accessor_template
}
//------------------------------------------------------------------------------
bool get_attribute( const std::string field_name, std::string& value ) const
bool get_attribute( const std::string& field_name, std::string& value ) const
{
for ( auto i : content ) {
for ( auto& i : content ) {
if ( field_name == i.first ) {
value = i.second;
return true;
@ -68,7 +68,7 @@ template <class S> class modinfo_section_accessor_template
}
//------------------------------------------------------------------------------
Elf_Word add_attribute( const std::string field, const std::string value )
Elf_Word add_attribute( const std::string& field, const std::string& value )
{
Elf_Word current_position = 0;

View File

@ -59,7 +59,7 @@ class note_section_accessor_template
bool get_note( Elf_Word index,
Elf_Word& type,
std::string& name,
void*& desc,
char*& desc,
Elf_Word& descSize ) const
{
if ( index >= ( notes->*F_get_size )() ) {
@ -96,7 +96,7 @@ class note_section_accessor_template
//------------------------------------------------------------------------------
void add_note( Elf_Word type,
const std::string& name,
const void* desc,
const char* desc,
Elf_Word descSize )
{
const endianess_convertor& convertor = elf_file.get_convertor();
@ -117,7 +117,7 @@ class note_section_accessor_template
buffer.append( pad, (size_t)align - nameLen % align );
}
if ( desc != nullptr && descSize != 0 ) {
buffer.append( reinterpret_cast<const char*>( desc ), descSize );
buffer.append( desc, descSize );
if ( descSize % align != 0 ) {
buffer.append( pad, (size_t)align - descSize % align );
}

View File

@ -181,14 +181,13 @@ template <class T> class segment_impl : public segment
else {
data.reset( new ( std::nothrow ) char[(size_t)size + 1] );
if ( nullptr != data.get() ) {
stream.read( data.get(), size );
if ( static_cast<Elf_Xword>( stream.gcount() ) != size ) {
data = nullptr;
return false;
}
if ( nullptr != data.get() && stream.read( data.get(), size ) ) {
data.get()[size] = 0;
}
else {
data = nullptr;
return false;
}
}
return true;

View File

@ -43,15 +43,12 @@ template <class S> class string_section_accessor_template
const char* get_string( Elf_Word index ) const
{
if ( string_section ) {
if ( index < string_section->get_size() ) {
const char* data = string_section->get_data();
if ( nullptr != data ) {
size_t string_length = strnlen(
data + index, string_section->get_size() - index );
if ( string_length <
( string_section->get_size() - index ) )
return data + index;
}
const char* data = string_section->get_data();
if ( index < string_section->get_size() && nullptr != data ) {
size_t string_length =
strnlen( data + index, string_section->get_size() - index );
if ( string_length < ( string_section->get_size() - index ) )
return data + index;
}
}

View File

@ -541,8 +541,6 @@ template <class S> class symbol_section_accessor_template
}
}
// Elf_Word nRet = symbol_section->get_size() / sizeof(entry) - 1;
return first_not_local;
}

View File

@ -58,9 +58,6 @@ namespace ELFIO {
class endianess_convertor
{
public:
//------------------------------------------------------------------------------
endianess_convertor() { need_conversion = false; }
//------------------------------------------------------------------------------
void setup( unsigned char elf_file_encoding )
{
@ -73,14 +70,14 @@ class endianess_convertor
if ( !need_conversion ) {
return value;
}
value = ( ( value & 0x00000000000000FFull ) << 56 ) |
( ( value & 0x000000000000FF00ull ) << 40 ) |
( ( value & 0x0000000000FF0000ull ) << 24 ) |
( ( value & 0x00000000FF000000ull ) << 8 ) |
( ( value & 0x000000FF00000000ull ) >> 8 ) |
( ( value & 0x0000FF0000000000ull ) >> 24 ) |
( ( value & 0x00FF000000000000ull ) >> 40 ) |
( ( value & 0xFF00000000000000ull ) >> 56 );
value = ( ( value & 0x00000000000000FFuLL ) << 56 ) |
( ( value & 0x000000000000FF00uLL ) << 40 ) |
( ( value & 0x0000000000FF0000uLL ) << 24 ) |
( ( value & 0x00000000FF000000uLL ) << 8 ) |
( ( value & 0x000000FF00000000uLL ) >> 8 ) |
( ( value & 0x0000FF0000000000uLL ) >> 24 ) |
( ( value & 0x00FF000000000000uLL ) >> 40 ) |
( ( value & 0xFF00000000000000uLL ) >> 56 );
return value;
}
@ -91,7 +88,7 @@ class endianess_convertor
if ( !need_conversion ) {
return value;
}
return (int64_t)(*this)( (uint64_t)value );
return (int64_t)( *this )( (uint64_t)value );
}
//------------------------------------------------------------------------------
@ -113,7 +110,7 @@ class endianess_convertor
if ( !need_conversion ) {
return value;
}
return (int32_t)(*this)( (uint32_t)value );
return (int32_t)( *this )( (uint32_t)value );
}
//------------------------------------------------------------------------------
@ -122,7 +119,8 @@ class endianess_convertor
if ( !need_conversion ) {
return value;
}
value = ( ( value & 0x00FF ) << 8 ) | ( ( value & 0xFF00 ) >> 8 );
value =
(uint16_t)( ( value & 0x00FF ) << 8 ) | ( ( value & 0xFF00 ) >> 8 );
return value;
}
@ -133,7 +131,7 @@ class endianess_convertor
if ( !need_conversion ) {
return value;
}
return (int16_t)(*this)( (uint16_t)value );
return (int16_t)( *this )( (uint16_t)value );
}
//------------------------------------------------------------------------------
@ -157,7 +155,7 @@ class endianess_convertor
}
//------------------------------------------------------------------------------
bool need_conversion;
bool need_conversion = false;
};
//------------------------------------------------------------------------------

View File

@ -187,7 +187,7 @@ void checkNote( const note_section_accessor& notes,
{
Elf_Word type;
std::string name;
void* desc;
char* desc;
Elf_Word descSize;
ASSERT_EQ( notes.get_note( index, type, name, desc, descSize ), true );
@ -224,8 +224,7 @@ TEST( ELFIOTest, load32 )
sec = reader.sections[27];
checkSection( sec, 27, ".strtab", SHT_STRTAB, 0, 0x0, 0x259, 0, 0, 1, 0 );
for ( Elf_Half i = 0; i < reader.sections.size(); ++i )
{
for ( Elf_Half i = 0; i < reader.sections.size(); ++i ) {
sec = reader.sections[i];
EXPECT_EQ( sec->get_index(), i );
}
@ -717,7 +716,7 @@ TEST( ELFIOTest, test_dummy_out_i386_32 )
note_sec->set_addr_align( 4 );
note_section_accessor note_writer( writer, note_sec );
char descr[6] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
note_writer.add_note( 0x77, "Hello", &descr, 6 );
note_writer.add_note( 0x77, "Hello", descr, 6 );
EXPECT_EQ( note_sec->get_index(), 2 );
// Create ELF file
@ -770,7 +769,7 @@ TEST( ELFIOTest, test_dummy_out_ppc_32 )
note_sec->set_addr_align( 4 );
note_section_accessor note_writer( writer, note_sec );
char descr[6] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
note_writer.add_note( 0x77, "Hello", &descr, 6 );
note_writer.add_note( 0x77, "Hello", descr, 6 );
EXPECT_EQ( note_sec->get_index(), 2 );
// Create ELF file
@ -823,7 +822,7 @@ TEST( ELFIOTest, test_dummy_out_i386_64 )
note_sec->set_addr_align( 4 );
note_section_accessor note_writer( writer, note_sec );
char descr[6] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
note_writer.add_note( 0x77, "Hello", &descr, 6 );
note_writer.add_note( 0x77, "Hello", descr, 6 );
EXPECT_EQ( note_sec->get_index(), 2 );
// Create ELF file
@ -876,7 +875,7 @@ TEST( ELFIOTest, test_dummy_out_ppc_64 )
note_sec->set_addr_align( 4 );
note_section_accessor note_writer( writer, note_sec );
char descr[6] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
note_writer.add_note( 0x77, "Hello", &descr, 6 );
note_writer.add_note( 0x77, "Hello", descr, 6 );
EXPECT_EQ( note_sec->get_index(), 2 );
// Create ELF file