mirror of
https://github.com/serge1/ELFIO.git
synced 2025-01-29 21:32:44 +00:00
Trim trailing space and remove tabs
This commit is contained in:
parent
2cddbab258
commit
e1d554978d
@ -206,11 +206,11 @@ typedef uint64_t Elf64_Off;
|
||||
#define ELFOSABI_TRU64 10 // Compaq TRU64 UNIX
|
||||
#define ELFOSABI_MODESTO 11 // Novell Modesto
|
||||
#define ELFOSABI_OPENBSD 12 // Open BSD
|
||||
#define ELFOSABI_OPENVMS 13 // Open VMS
|
||||
#define ELFOSABI_NSK 14 // Hewlett-Packard Non-Stop Kernel
|
||||
#define ELFOSABI_AROS 15 // Amiga Research OS
|
||||
#define ELFOSABI_FENIXOS 16 // The FenixOS highly scalable multi-core OS
|
||||
// 64-255 Architecture-specific value range
|
||||
#define ELFOSABI_OPENVMS 13 // Open VMS
|
||||
#define ELFOSABI_NSK 14 // Hewlett-Packard Non-Stop Kernel
|
||||
#define ELFOSABI_AROS 15 // Amiga Research OS
|
||||
#define ELFOSABI_FENIXOS 16 // The FenixOS highly scalable multi-core OS
|
||||
// 64-255 Architecture-specific value range
|
||||
|
||||
|
||||
|
||||
|
@ -33,7 +33,7 @@ ELFIDynamicReader::getEntriesNum() const
|
||||
if ( 0 != m_pSection->get_entry_size() ) {
|
||||
nRet = m_pSection->get_size() / m_pSection->get_entry_size();
|
||||
}
|
||||
|
||||
|
||||
return nRet;
|
||||
}
|
||||
|
||||
@ -46,12 +46,12 @@ ELFIDynamicReader::get_entry( Elf_Xword index,
|
||||
if ( index >= getEntriesNum() ) { // Is index valid
|
||||
return ERR_ELFIO_INDEX_ERROR;
|
||||
}
|
||||
|
||||
|
||||
const Elf64_Dyn* pEntry = reinterpret_cast<const Elf64_Dyn*>(
|
||||
m_pSection->get_data() + index * m_pSection->get_entry_size() );
|
||||
tag = convert2host( pEntry->d_tag, m_pIELFI->get_encoding() );
|
||||
value = convert2host( pEntry->d_un.d_val, m_pIELFI->get_encoding() );
|
||||
|
||||
|
||||
return ERR_ELFIO_NO_ERROR;
|
||||
}
|
||||
|
||||
|
@ -90,13 +90,13 @@ class elfio
|
||||
header = create_header( file_class, encoding );
|
||||
create_mandatory_sections();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool load( const std::string& file_name )
|
||||
{
|
||||
clean();
|
||||
|
||||
std::ifstream stream;
|
||||
|
||||
std::ifstream stream;
|
||||
stream.open( file_name.c_str(), std::ios::in | std::ios::binary );
|
||||
if ( !stream ) {
|
||||
return false;
|
||||
@ -154,12 +154,12 @@ class elfio
|
||||
is_still_good = is_still_good && save_header( f );
|
||||
is_still_good = is_still_good && save_sections_without_segments( f );
|
||||
is_still_good = is_still_good && save_segments_and_their_sections( f );
|
||||
|
||||
|
||||
f.close();
|
||||
|
||||
|
||||
return is_still_good;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ELF header access functions
|
||||
ELFIO_HEADER_ACCESS_GET( unsigned char, class );
|
||||
@ -179,7 +179,7 @@ class elfio
|
||||
ELFIO_HEADER_ACCESS_GET_SET( Elf64_Off, sections_offset );
|
||||
ELFIO_HEADER_ACCESS_GET_SET( Elf64_Off, segments_offset );
|
||||
ELFIO_HEADER_ACCESS_GET_SET( Elf_Half, section_name_str_index );
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
const endianess_convertor& get_convertor() const
|
||||
{
|
||||
@ -237,7 +237,7 @@ class elfio
|
||||
delete *it;
|
||||
}
|
||||
sections_.clear();
|
||||
|
||||
|
||||
std::vector<segment*>::const_iterator it1;
|
||||
for ( it1 = segments_.begin(); it1 != segments_.end(); ++it1 ) {
|
||||
delete *it1;
|
||||
@ -249,7 +249,7 @@ class elfio
|
||||
elf_header* create_header( unsigned char file_class, unsigned char encoding )
|
||||
{
|
||||
elf_header* new_header = 0;
|
||||
|
||||
|
||||
if ( file_class == ELFCLASS64 ) {
|
||||
new_header = new elf_header_impl< Elf64_Ehdr >( &convertor,
|
||||
encoding );
|
||||
@ -261,10 +261,10 @@ class elfio
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return new_header;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
section* create_section()
|
||||
{
|
||||
@ -280,20 +280,20 @@ class elfio
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
new_section->set_index( sections_.size() );
|
||||
sections_.push_back( new_section );
|
||||
|
||||
|
||||
return new_section;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
segment* create_segment()
|
||||
{
|
||||
segment* new_segment;
|
||||
unsigned char file_class = header->get_class();
|
||||
|
||||
|
||||
if ( file_class == ELFCLASS64 ) {
|
||||
new_segment = new segment_impl<Elf64_Phdr>( &convertor );
|
||||
}
|
||||
@ -303,9 +303,9 @@ class elfio
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
segments_.push_back( new_segment );
|
||||
|
||||
|
||||
return new_segment;
|
||||
}
|
||||
|
||||
@ -318,12 +318,12 @@ class elfio
|
||||
sec0->set_index( 0 );
|
||||
sec0->set_name( "" );
|
||||
sec0->set_name_string_offset( 0 );
|
||||
|
||||
|
||||
set_section_name_str_index( 1 );
|
||||
section* shstrtab = sections.add( ".shstrtab" );
|
||||
shstrtab->set_type( SHT_STRTAB );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Half load_sections( std::ifstream& stream )
|
||||
{
|
||||
@ -336,7 +336,7 @@ class elfio
|
||||
sec->load( stream, (std::streamoff)offset + i * entry_size );
|
||||
sec->set_index( i );
|
||||
}
|
||||
|
||||
|
||||
Elf_Half shstrndx = get_section_name_str_index();
|
||||
|
||||
if ( SHN_UNDEF != shstrndx ) {
|
||||
@ -356,7 +356,7 @@ class elfio
|
||||
Elf_Half entry_size = header->get_segment_entry_size();
|
||||
Elf_Half num = header->get_segments_num();
|
||||
Elf64_Off offset = header->get_segments_offset();
|
||||
|
||||
|
||||
for ( Elf_Half i = 0; i < num; ++i ) {
|
||||
segment* seg;
|
||||
unsigned char file_class = header->get_class();
|
||||
@ -391,7 +391,7 @@ class elfio
|
||||
header->set_sections_offset( header->get_header_size() +
|
||||
header->get_segment_entry_size() * segments.size() );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool save_header( std::ofstream& f )
|
||||
{
|
||||
@ -435,7 +435,7 @@ class elfio
|
||||
|
||||
std::streampos headerPosition = (std::streamoff)header->get_sections_offset() +
|
||||
header->get_section_entry_size() * sections_[i]->get_index();
|
||||
|
||||
|
||||
sections_[i]->save( f, headerPosition, (std::streamoff)current_file_pos );
|
||||
|
||||
if ( SHT_NOBITS != sections_[i]->get_type() ) {
|
||||
@ -458,7 +458,7 @@ class elfio
|
||||
if ( segment_align > 1 && current_file_pos % segment_align != 0 ) {
|
||||
current_file_pos += segment_align - current_file_pos % segment_align;
|
||||
}
|
||||
|
||||
|
||||
Elf_Xword current_data_pos = current_file_pos;
|
||||
// Write segment's data
|
||||
for ( unsigned int j = 0; j <segments[i]->get_sections_num(); ++j ) {
|
||||
@ -468,7 +468,7 @@ class elfio
|
||||
if ( secAlign > 1 && current_data_pos % secAlign != 0 ) {
|
||||
current_data_pos += secAlign - current_data_pos % secAlign;
|
||||
}
|
||||
|
||||
|
||||
std::streampos headerPosition = (std::streamoff)header->get_sections_offset() +
|
||||
header->get_section_entry_size()*sec->get_index();
|
||||
if ( !sec->is_address_initialized() ) {
|
||||
@ -488,7 +488,7 @@ class elfio
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
public:
|
||||
@ -500,24 +500,24 @@ class elfio
|
||||
parent( parent_ )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Half size() const
|
||||
{
|
||||
return (Elf_Half)parent->sections_.size();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
section* operator[]( unsigned int index ) const
|
||||
{
|
||||
return parent->sections_[index];
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
section* operator[]( const std::string& name ) const
|
||||
{
|
||||
section* sec = 0;
|
||||
|
||||
|
||||
std::vector<section*>::const_iterator it;
|
||||
for ( it = parent->sections_.begin(); it != parent->sections_.end(); ++it ) {
|
||||
if ( (*it)->get_name() == name ) {
|
||||
@ -543,12 +543,12 @@ class elfio
|
||||
|
||||
return new_section;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
private:
|
||||
elfio* parent;
|
||||
} sections;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
public:
|
||||
friend class Segments;
|
||||
@ -559,38 +559,38 @@ class elfio
|
||||
parent( parent_ )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Half size() const
|
||||
{
|
||||
return (Elf_Half)parent->segments_.size();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
segment* operator[]( unsigned int index ) const
|
||||
{
|
||||
return parent->segments_[index];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
segment* add()
|
||||
{
|
||||
return parent->create_segment();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
private:
|
||||
elfio* parent;
|
||||
} segments;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
private:
|
||||
elf_header* header;
|
||||
std::vector<section*> sections_;
|
||||
std::vector<segment*> segments_;
|
||||
endianess_convertor convertor;
|
||||
|
||||
|
||||
Elf_Xword current_file_pos;
|
||||
};
|
||||
|
||||
|
@ -42,7 +42,7 @@ class note_section_accessor
|
||||
{
|
||||
return note_start_positions.size();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool
|
||||
get_note( Elf_Word index,
|
||||
@ -84,7 +84,7 @@ class note_section_accessor
|
||||
Elf_Word descSize )
|
||||
{
|
||||
const endianess_convertor& convertor = elf_file.get_convertor();
|
||||
|
||||
|
||||
Elf_Word nameLen = name.size() + 1;
|
||||
Elf_Word nameLenConv = convertor( nameLen );
|
||||
std::string buffer( reinterpret_cast<char*>( &nameLenConv ), sizeof( nameLenConv ) );
|
||||
@ -110,7 +110,7 @@ class note_section_accessor
|
||||
note_start_positions.push_back( note_section->get_size() );
|
||||
note_section->append_data( buffer );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
//------------------------------------------------------------------------------
|
||||
void process_section()
|
||||
@ -131,7 +131,7 @@ class note_section_accessor
|
||||
note_start_positions.push_back( current );
|
||||
Elf_Word namesz = convertor(
|
||||
*(Elf_Word*)( data + current ) );
|
||||
Elf_Word descsz = convertor(
|
||||
Elf_Word descsz = convertor(
|
||||
*(Elf_Word*)( data + current + sizeof( namesz ) ) );
|
||||
|
||||
int align = sizeof( Elf_Xword );
|
||||
|
@ -88,14 +88,14 @@ class relocation_section_accessor
|
||||
get_entries_num() const
|
||||
{
|
||||
Elf_Xword nRet = 0;
|
||||
|
||||
|
||||
if ( 0 != relocation_section->get_entry_size() ) {
|
||||
nRet = relocation_section->get_size() / relocation_section->get_entry_size();
|
||||
}
|
||||
|
||||
|
||||
return nRet;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool
|
||||
get_entry( Elf_Xword index,
|
||||
@ -107,7 +107,7 @@ class relocation_section_accessor
|
||||
if ( index >= get_entries_num() ) { // Is index valid
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ( elf_file.get_class() == ELFCLASS32 ) {
|
||||
if ( SHT_REL == relocation_section->get_type() ) {
|
||||
generic_get_entry_rel< Elf32_Rel >( index, offset, symbol,
|
||||
@ -131,7 +131,7 @@ class relocation_section_accessor
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool
|
||||
get_entry( Elf_Xword index,
|
||||
@ -145,18 +145,18 @@ class relocation_section_accessor
|
||||
// Do regular job
|
||||
Elf_Word symbol;
|
||||
bool ret = get_entry( index, offset, symbol, type, addend );
|
||||
|
||||
|
||||
// Find the symbol
|
||||
Elf_Xword size;
|
||||
unsigned char bind;
|
||||
unsigned char symbolType;
|
||||
Elf_Half section;
|
||||
unsigned char other;
|
||||
|
||||
|
||||
symbol_section_accessor symbols( elf_file, elf_file.sections[get_symbol_table_index()] );
|
||||
ret = symbols.get_symbol( symbol, symbolName, symbolValue,
|
||||
ret = symbols.get_symbol( symbol, symbolName, symbolValue,
|
||||
size, bind, symbolType, section, other );
|
||||
|
||||
|
||||
if ( ret ) { // Was it successful?
|
||||
switch ( type ) {
|
||||
case R_386_NONE: // none
|
||||
@ -187,7 +187,7 @@ class relocation_section_accessor
|
||||
case R_386_GOTOFF: // S + A - GOT
|
||||
calcValue = 0;
|
||||
break;
|
||||
case R_386_GOTPC: // GOT + A - P
|
||||
case R_386_GOTPC: // GOT + A - P
|
||||
calcValue = 0;
|
||||
break;
|
||||
default: // Not recognized symbol!
|
||||
@ -195,7 +195,7 @@ class relocation_section_accessor
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -210,7 +210,7 @@ class relocation_section_accessor
|
||||
generic_add_entry< Elf64_Rel >( offset, info );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
add_entry( Elf64_Addr offset, Elf_Word symbol, unsigned char type )
|
||||
@ -222,10 +222,10 @@ class relocation_section_accessor
|
||||
else {
|
||||
info = ELF64_R_INFO( symbol, type );
|
||||
}
|
||||
|
||||
|
||||
add_entry( offset, info );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
add_entry( Elf64_Addr offset, Elf_Xword info, Elf_Sxword addend )
|
||||
@ -237,7 +237,7 @@ class relocation_section_accessor
|
||||
generic_add_entry< Elf64_Rela >( offset, info, addend );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
add_entry( Elf64_Addr offset, Elf_Word symbol, unsigned char type,
|
||||
@ -250,10 +250,10 @@ class relocation_section_accessor
|
||||
else {
|
||||
info = ELF64_R_INFO( symbol, type );
|
||||
}
|
||||
|
||||
|
||||
add_entry( offset, info, addend );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
add_entry( string_section_accessor str_writer,
|
||||
@ -272,16 +272,16 @@ class relocation_section_accessor
|
||||
sym_info, other, shndx );
|
||||
add_entry( offset, sym_index, type );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
private:
|
||||
private:
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Half
|
||||
get_symbol_table_index() const
|
||||
{
|
||||
return (Elf_Half)relocation_section->get_link();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Half
|
||||
getTargetSectionIndex() const
|
||||
@ -299,7 +299,7 @@ class relocation_section_accessor
|
||||
Elf_Sxword& addend ) const
|
||||
{
|
||||
const endianess_convertor& convertor = elf_file.get_convertor();
|
||||
|
||||
|
||||
const T* pEntry = reinterpret_cast<const T*>(
|
||||
relocation_section->get_data() +
|
||||
index * relocation_section->get_entry_size() );
|
||||
@ -309,7 +309,7 @@ class relocation_section_accessor
|
||||
type = get_sym_and_type<T>::get_r_type( tmp );
|
||||
addend = 0;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
template< class T >
|
||||
void
|
||||
@ -320,7 +320,7 @@ class relocation_section_accessor
|
||||
Elf_Sxword& addend ) const
|
||||
{
|
||||
const endianess_convertor& convertor = elf_file.get_convertor();
|
||||
|
||||
|
||||
const T* pEntry = reinterpret_cast<const T*>(
|
||||
relocation_section->get_data() +
|
||||
index * relocation_section->get_entry_size() );
|
||||
@ -330,28 +330,28 @@ class relocation_section_accessor
|
||||
type = get_sym_and_type<T>::get_r_type( tmp );
|
||||
addend = convertor( pEntry->r_addend );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
template< class T >
|
||||
void
|
||||
generic_add_entry( Elf64_Addr offset, Elf_Xword info )
|
||||
{
|
||||
const endianess_convertor& convertor = elf_file.get_convertor();
|
||||
|
||||
|
||||
T entry;
|
||||
entry.r_offset = convertor( offset );
|
||||
entry.r_info = convertor( info );
|
||||
|
||||
|
||||
relocation_section->append_data( reinterpret_cast<char*>( &entry ), sizeof( entry ) );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
template< class T >
|
||||
void
|
||||
generic_add_entry( Elf64_Addr offset, Elf_Xword info, Elf_Sxword addend )
|
||||
{
|
||||
const endianess_convertor& convertor = elf_file.get_convertor();
|
||||
|
||||
|
||||
T entry;
|
||||
entry.r_offset = offset;
|
||||
entry.r_info = info;
|
||||
@ -359,10 +359,10 @@ class relocation_section_accessor
|
||||
entry.r_offset = convertor( entry.r_offset );
|
||||
entry.r_info = convertor( entry.r_info );
|
||||
entry.r_addend = convertor( entry.r_addend );
|
||||
|
||||
|
||||
relocation_section->append_data( reinterpret_cast<char*>( &entry ), sizeof( entry ) );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
private:
|
||||
elfio& elf_file;
|
||||
|
@ -84,7 +84,7 @@ class section_impl : public section
|
||||
{
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Section info functions
|
||||
ELFIO_GET_SET_ACCESS( Elf_Word, type, header.sh_type );
|
||||
@ -127,7 +127,7 @@ class section_impl : public section
|
||||
header.sh_addr = (*convertor)( header.sh_addr );
|
||||
is_address_set = true;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool
|
||||
is_address_initialized()
|
||||
@ -157,14 +157,14 @@ class section_impl : public section
|
||||
|
||||
set_size( size );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
set_data( const std::string& str_data )
|
||||
{
|
||||
return set_data( str_data.c_str(), str_data.size() );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
append_data( const char* raw_data, Elf_Word size )
|
||||
@ -186,14 +186,14 @@ class section_impl : public section
|
||||
set_size( get_size() + size );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
append_data( const std::string& str_data )
|
||||
{
|
||||
return append_data( str_data.c_str(), str_data.size() );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
protected:
|
||||
//------------------------------------------------------------------------------
|
||||
@ -221,7 +221,7 @@ class section_impl : public section
|
||||
data_size = size;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
save( std::ofstream& f,
|
||||
@ -232,7 +232,7 @@ class section_impl : public section
|
||||
header.sh_offset = data_offset;
|
||||
header.sh_offset = (*convertor)( header.sh_offset );
|
||||
}
|
||||
|
||||
|
||||
save_header( f, header_offset );
|
||||
if ( get_type() != SHT_NOBITS && get_type() != SHT_NULL &&
|
||||
get_size() != 0 && data != 0 ) {
|
||||
@ -250,7 +250,7 @@ class section_impl : public section
|
||||
f.seekp( header_offset );
|
||||
f.write( reinterpret_cast<const char*>( &header ), sizeof( header ) );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
save_data( std::ofstream& f,
|
||||
|
@ -114,14 +114,14 @@ class segment_impl : public segment
|
||||
|
||||
return sections.size();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Half
|
||||
get_sections_num() const
|
||||
{
|
||||
return sections.size();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Half
|
||||
get_section_index_at( Elf_Half num ) const
|
||||
@ -129,10 +129,10 @@ class segment_impl : public segment
|
||||
if ( num < sections.size() ) {
|
||||
return sections[num];
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
protected:
|
||||
//------------------------------------------------------------------------------
|
||||
@ -141,7 +141,7 @@ class segment_impl : public segment
|
||||
{
|
||||
index = value;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
load( std::ifstream& stream,
|
||||
@ -149,7 +149,7 @@ class segment_impl : public segment
|
||||
{
|
||||
stream.seekg( header_offset );
|
||||
stream.read( reinterpret_cast<char*>( &ph ), sizeof( ph ) );
|
||||
|
||||
|
||||
if ( PT_NULL != get_type() && 0 != get_file_size() ) {
|
||||
stream.seekg( (*convertor)( ph.p_offset ) );
|
||||
Elf_Xword size = get_file_size();
|
||||
|
@ -68,7 +68,7 @@ class string_section_accessor
|
||||
current_position++;
|
||||
}
|
||||
string_section->append_data( str, std::strlen( str ) + 1 );
|
||||
|
||||
|
||||
return current_position;
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ class string_section_accessor
|
||||
}
|
||||
string_section->append_data( str );
|
||||
string_section->append_data( empty_string, 1 );
|
||||
|
||||
|
||||
return current_position;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class symbol_section_accessor
|
||||
if ( 0 != symbols_section->get_entry_size() ) {
|
||||
nRet = symbols_section->get_size() / symbols_section->get_entry_size();
|
||||
}
|
||||
|
||||
|
||||
return nRet;
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ class symbol_section_accessor
|
||||
ret = generic_get_symbol<Elf64_Sym>( index, name, value, size, bind, type,
|
||||
section_index, other );
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ class symbol_section_accessor
|
||||
unsigned char& other ) const
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
|
||||
if ( 0 != get_hash_table_index() ) {
|
||||
Elf_Word nbucket = *(Elf_Word*)hash_section->get_data();
|
||||
Elf_Word val = elf_hash( (const unsigned char*)name.c_str() );
|
||||
@ -102,7 +102,7 @@ class symbol_section_accessor
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ class symbol_section_accessor
|
||||
Elf_Half shndx )
|
||||
{
|
||||
Elf_Word nRet;
|
||||
|
||||
|
||||
if ( symbols_section->get_size() == 0 ) {
|
||||
if ( elf_file.get_class() == ELFCLASS32 ) {
|
||||
nRet = generic_add_symbol<Elf32_Sym>( 0, 0, 0, 0, 0, 0 );
|
||||
@ -122,7 +122,7 @@ class symbol_section_accessor
|
||||
nRet = generic_add_symbol<Elf64_Sym>( 0, 0, 0, 0, 0, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( elf_file.get_class() == ELFCLASS32 ) {
|
||||
nRet = generic_add_symbol<Elf32_Sym>( name, value, size, info, other,
|
||||
shndx );
|
||||
@ -131,10 +131,10 @@ class symbol_section_accessor
|
||||
nRet = generic_add_symbol<Elf64_Sym>( name, value, size, info, other,
|
||||
shndx );
|
||||
}
|
||||
|
||||
|
||||
return nRet;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Word
|
||||
add_entry( Elf_Word name, Elf64_Addr value, Elf_Xword size,
|
||||
@ -143,7 +143,7 @@ class symbol_section_accessor
|
||||
{
|
||||
return add_entry( name, value, size, ELF_ST_INFO( bind, type ), other, shndx );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Word
|
||||
add_entry( string_section_accessor& pStrWriter, const char* str,
|
||||
@ -154,7 +154,7 @@ class symbol_section_accessor
|
||||
Elf_Word index = pStrWriter.add_string( str );
|
||||
return add_entry( index, value, size, info, other, shndx );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Word
|
||||
add_entry( string_section_accessor& pStrWriter, const char* str,
|
||||
@ -164,7 +164,7 @@ class symbol_section_accessor
|
||||
{
|
||||
return add_entry( pStrWriter, str, value, size, ELF_ST_INFO( bind, type ), other, shndx );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
private:
|
||||
//------------------------------------------------------------------------------
|
||||
@ -202,7 +202,7 @@ class symbol_section_accessor
|
||||
bool
|
||||
generic_get_symbol( Elf_Xword index,
|
||||
std::string& name, Elf64_Addr& value,
|
||||
Elf_Xword& size,
|
||||
Elf_Xword& size,
|
||||
unsigned char& bind, unsigned char& type,
|
||||
Elf_Half& section_index,
|
||||
unsigned char& other ) const
|
||||
@ -214,7 +214,7 @@ class symbol_section_accessor
|
||||
symbols_section->get_data() + index * symbols_section->get_entry_size() );
|
||||
|
||||
const endianess_convertor& convertor = elf_file.get_convertor();
|
||||
|
||||
|
||||
section* string_section = elf_file.sections[get_string_table_index()];
|
||||
string_section_accessor str_reader( string_section );
|
||||
const char* pStr = str_reader.get_string( convertor( pSym->st_name ) );
|
||||
@ -229,8 +229,8 @@ class symbol_section_accessor
|
||||
other = pSym->st_other;
|
||||
|
||||
ret = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -242,25 +242,25 @@ class symbol_section_accessor
|
||||
Elf_Half shndx )
|
||||
{
|
||||
const endianess_convertor& convertor = elf_file.get_convertor();
|
||||
|
||||
|
||||
T entry;
|
||||
entry.st_name = convertor( name );
|
||||
entry.st_value = value;
|
||||
entry.st_value = convertor( entry.st_value );
|
||||
entry.st_size = size;
|
||||
entry.st_size = size;
|
||||
entry.st_size = convertor( entry.st_size );
|
||||
entry.st_info = convertor( info );
|
||||
entry.st_other = convertor( other );
|
||||
entry.st_shndx = convertor( shndx );
|
||||
|
||||
|
||||
symbols_section->append_data( reinterpret_cast<char*>( &entry ),
|
||||
sizeof( entry ) );
|
||||
|
||||
Elf_Word nRet = symbols_section->get_size() / sizeof( entry ) - 1;
|
||||
|
||||
|
||||
return nRet;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
private:
|
||||
const elfio& elf_file;
|
||||
|
@ -59,7 +59,7 @@ THE SOFTWARE.
|
||||
virtual void set_##NAME( TYPE value ) = 0;
|
||||
|
||||
namespace ELFIO {
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
class endianess_convertor {
|
||||
public:
|
||||
@ -68,7 +68,7 @@ class endianess_convertor {
|
||||
{
|
||||
need_conversion = false;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
setup( unsigned char elf_file_encoding )
|
||||
|
@ -7,7 +7,7 @@ class ELFODynamicWriter : public IELFODynamicWriter
|
||||
public:
|
||||
ELFODynamicWriter( IELFO* pIELFO, IELFOSection* pSection );
|
||||
~ELFODynamicWriter();
|
||||
|
||||
|
||||
virtual int addRef();
|
||||
virtual int release();
|
||||
|
||||
|
@ -313,8 +313,8 @@ int main( int argc, char** argv )
|
||||
printf( " No Type Name\n" );
|
||||
for ( int i = 0; i < nNotesNo; ++i ) { // For all notes
|
||||
Elf_Word type;
|
||||
std::string name;
|
||||
void* desc;
|
||||
std::string name;
|
||||
void* desc;
|
||||
Elf_Word descsz;
|
||||
|
||||
notes.get_note( i, type, name, desc, descsz );
|
||||
|
@ -14,18 +14,21 @@
|
||||
<ProjectGuid>{CBAA735F-E237-4976-909F-2349920ED871}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>ELFDump</RootNamespace>
|
||||
<VCTargetsPath Condition="'$(VCTargetsPath11)' != '' and '$(VSVersion)' == '' and $(VisualStudioVersion) == ''">$(VCTargetsPath11)</VCTargetsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
|
@ -27,13 +27,13 @@ int main( void )
|
||||
0x10,
|
||||
0 );
|
||||
// Add data into it
|
||||
char text[] = { '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4
|
||||
'\xBB', '\x01', '\x00', '\x00', '\x00', // mov ebx, 1
|
||||
'\xB9', '\x00', '\x00', '\x00', '\x00', // mov ecx, msg
|
||||
'\xBA', '\x0E', '\x00', '\x00', '\x00', // mov edx, 14
|
||||
'\xCD', '\x80', // int 0x80
|
||||
'\xB8', '\x01', '\x00', '\x00', '\x00', // mov eax, 1
|
||||
'\xCD', '\x80', // int 0x80
|
||||
char text[] = { '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4
|
||||
'\xBB', '\x01', '\x00', '\x00', '\x00', // mov ebx, 1
|
||||
'\xB9', '\x00', '\x00', '\x00', '\x00', // mov ecx, msg
|
||||
'\xBA', '\x0E', '\x00', '\x00', '\x00', // mov edx, 14
|
||||
'\xCD', '\x80', // int 0x80
|
||||
'\xB8', '\x01', '\x00', '\x00', '\x00', // mov eax, 1
|
||||
'\xCD', '\x80', // int 0x80
|
||||
'\x48', '\x65', '\x6C', '\x6C', '\x6F', // msg: db 'Hello, World!', 10
|
||||
'\x2C', '\x20', '\x57', '\x6F', '\x72',
|
||||
'\x6C', '\x64', '\x21', '\x0A'
|
||||
|
Loading…
x
Reference in New Issue
Block a user