mirror of
https://github.com/serge1/ELFIO.git
synced 2025-01-29 21:32:44 +00:00
Refactoring
This commit is contained in:
parent
ecc45ede27
commit
8e7a29e128
@ -74,7 +74,8 @@ class elfio
|
||||
//------------------------------------------------------------------------------
|
||||
elfio() : sections( this ), segments( this )
|
||||
{
|
||||
header = 0;
|
||||
header = 0;
|
||||
current_file_pos = 0;
|
||||
create( ELFCLASS32, ELFDATA2LSB );
|
||||
}
|
||||
|
||||
@ -573,7 +574,6 @@ class elfio
|
||||
{
|
||||
std::vector<segment*> worklist;
|
||||
std::vector<bool> section_generated(sections.size(),false);
|
||||
std::vector<Elf_Xword> section_alignment(sections.size(),0);
|
||||
|
||||
// Get segments in a order in where segments which contain a
|
||||
// sub sequence of other segments are located at the end
|
||||
|
@ -74,7 +74,12 @@ class dynamic_section_accessor
|
||||
tag == DT_RUNPATH ) {
|
||||
string_section_accessor strsec =
|
||||
elf_file.sections[ get_string_table_index() ];
|
||||
str = strsec.get_string( value );
|
||||
const char* result = strsec.get_string( value );
|
||||
if ( 0 == result ) {
|
||||
str.clear();
|
||||
return false;
|
||||
}
|
||||
str = result;
|
||||
}
|
||||
else {
|
||||
str.clear();
|
||||
|
@ -154,8 +154,8 @@ class relocation_section_accessor
|
||||
unsigned char other;
|
||||
|
||||
symbol_section_accessor symbols( elf_file, elf_file.sections[get_symbol_table_index()] );
|
||||
ret = symbols.get_symbol( symbol, symbolName, symbolValue,
|
||||
size, bind, symbolType, section, other );
|
||||
ret = ret && symbols.get_symbol( symbol, symbolName, symbolValue,
|
||||
size, bind, symbolType, section, other );
|
||||
|
||||
if ( ret ) { // Was it successful?
|
||||
switch ( type ) {
|
||||
@ -217,10 +217,10 @@ class relocation_section_accessor
|
||||
{
|
||||
Elf_Xword info;
|
||||
if ( elf_file.get_class() == ELFCLASS32 ) {
|
||||
info = ELF32_R_INFO( symbol, type );
|
||||
info = ELF32_R_INFO( (Elf_Xword)symbol, type );
|
||||
}
|
||||
else {
|
||||
info = ELF64_R_INFO( symbol, type );
|
||||
info = ELF64_R_INFO((Elf_Xword)symbol, type );
|
||||
}
|
||||
|
||||
add_entry( offset, info );
|
||||
@ -245,10 +245,10 @@ class relocation_section_accessor
|
||||
{
|
||||
Elf_Xword info;
|
||||
if ( elf_file.get_class() == ELFCLASS32 ) {
|
||||
info = ELF32_R_INFO( symbol, type );
|
||||
info = ELF32_R_INFO( (Elf_Xword)symbol, type );
|
||||
}
|
||||
else {
|
||||
info = ELF64_R_INFO( symbol, type );
|
||||
info = ELF64_R_INFO( (Elf_Xword)symbol, type );
|
||||
}
|
||||
|
||||
add_entry( offset, info, addend );
|
||||
|
@ -150,7 +150,9 @@ class section_impl : public section
|
||||
try {
|
||||
data = new char[size];
|
||||
} catch (const std::bad_alloc&) {
|
||||
data = 0;
|
||||
data_size = 0;
|
||||
size = 0;
|
||||
}
|
||||
if ( 0 != data && 0 != raw_data ) {
|
||||
data_size = size;
|
||||
@ -183,6 +185,7 @@ class section_impl : public section
|
||||
new_data = new char[data_size];
|
||||
} catch (const std::bad_alloc&) {
|
||||
new_data = 0;
|
||||
size = 0;
|
||||
}
|
||||
if ( 0 != new_data ) {
|
||||
std::copy( data, data + get_size(), new_data );
|
||||
@ -228,6 +231,7 @@ class section_impl : public section
|
||||
try {
|
||||
data = new char[size];
|
||||
} catch (const std::bad_alloc&) {
|
||||
data = 0;
|
||||
data_size = 0;
|
||||
}
|
||||
if ( 0 != size ) {
|
||||
|
@ -109,9 +109,9 @@ class segment_impl : public segment
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Half
|
||||
add_section_index( Elf_Half index, Elf_Xword addr_align )
|
||||
add_section_index( Elf_Half sec_index, Elf_Xword addr_align )
|
||||
{
|
||||
sections.push_back( index );
|
||||
sections.push_back( sec_index );
|
||||
if ( addr_align > get_align() ) {
|
||||
set_align( addr_align );
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class string_section_accessor
|
||||
return data + index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -61,15 +61,19 @@ class string_section_accessor
|
||||
Elf_Word
|
||||
add_string( const char* str )
|
||||
{
|
||||
// Strings are addeded to the end of the current section data
|
||||
Elf_Word current_position = (Elf_Word)string_section->get_size();
|
||||
Elf_Word current_position = 0;
|
||||
|
||||
if (string_section) {
|
||||
// Strings are addeded to the end of the current section data
|
||||
current_position = (Elf_Word)string_section->get_size();
|
||||
|
||||
if ( current_position == 0 ) {
|
||||
char empty_string = '\0';
|
||||
string_section->append_data( &empty_string, 1 );
|
||||
current_position++;
|
||||
if ( current_position == 0 ) {
|
||||
char empty_string = '\0';
|
||||
string_section->append_data( &empty_string, 1 );
|
||||
current_position++;
|
||||
}
|
||||
string_section->append_data( str, (Elf_Word)std::strlen( str ) + 1 );
|
||||
}
|
||||
string_section->append_data( str, (Elf_Word)std::strlen( str ) + 1 );
|
||||
|
||||
return current_position;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user