mirror of
https://github.com/QuasarApp/ELFIO.git
synced 2025-05-10 10:09:33 +00:00
Add tests for the new flavor of get_symbol()
This commit is contained in:
parent
1a5ac38fae
commit
3e4a2fabfd
@ -436,3 +436,50 @@ BOOST_AUTO_TEST_CASE( elf_exe_loadsave_ppc32big3 )
|
|||||||
checkExeAreEqual( in, out, SEG_ALIGN );
|
checkExeAreEqual( in, out, SEG_ALIGN );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
BOOST_AUTO_TEST_CASE( get_symbol_32 )
|
||||||
|
{
|
||||||
|
elfio elf;
|
||||||
|
std::string name;
|
||||||
|
ELFIO::Elf_Xword size;
|
||||||
|
unsigned char bind;
|
||||||
|
unsigned char type;
|
||||||
|
ELFIO::Elf_Half section_index;
|
||||||
|
unsigned char other;
|
||||||
|
std::string in = "../elf_examples/hello_32";
|
||||||
|
|
||||||
|
BOOST_REQUIRE_EQUAL( elf.load(in), true );
|
||||||
|
section* psymsec = elf.sections[ ".symtab" ];
|
||||||
|
const symbol_section_accessor symbols( elf, psymsec );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( true,
|
||||||
|
symbols.get_symbol( 0x08048478, name, size, bind,
|
||||||
|
type, section_index, other) );
|
||||||
|
BOOST_CHECK_EQUAL( "_IO_stdin_used", name );
|
||||||
|
BOOST_CHECK_EQUAL( 14, section_index );
|
||||||
|
BOOST_CHECK_EQUAL( 4, size );
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
BOOST_AUTO_TEST_CASE( get_symbol_64 )
|
||||||
|
{
|
||||||
|
elfio elf;
|
||||||
|
std::string name;
|
||||||
|
ELFIO::Elf_Xword size;
|
||||||
|
unsigned char bind;
|
||||||
|
unsigned char type;
|
||||||
|
ELFIO::Elf_Half section_index;
|
||||||
|
unsigned char other;
|
||||||
|
std::string in = "../elf_examples/hello_64";
|
||||||
|
|
||||||
|
BOOST_REQUIRE_EQUAL( elf.load(in), true );
|
||||||
|
section* psymsec = elf.sections[ ".symtab" ];
|
||||||
|
const symbol_section_accessor symbols( elf, psymsec );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( true,
|
||||||
|
symbols.get_symbol(0x00400498, name, size, bind,
|
||||||
|
type, section_index, other) );
|
||||||
|
BOOST_CHECK_EQUAL( "main", name );
|
||||||
|
BOOST_CHECK_EQUAL( 12, section_index );
|
||||||
|
BOOST_CHECK_EQUAL( 21, size );
|
||||||
|
}
|
||||||
|
@ -39,7 +39,6 @@ THE SOFTWARE.
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include <elfio/elf_types.hpp>
|
#include <elfio/elf_types.hpp>
|
||||||
#include <elfio/elfio_utils.hpp>
|
#include <elfio/elfio_utils.hpp>
|
||||||
|
@ -92,9 +92,8 @@ class symbol_section_accessor_template
|
|||||||
Elf_Word nchain = *(const Elf_Word*)( hash_section->get_data() +
|
Elf_Word nchain = *(const Elf_Word*)( hash_section->get_data() +
|
||||||
sizeof( Elf_Word ) );
|
sizeof( Elf_Word ) );
|
||||||
Elf_Word val = elf_hash( (const unsigned char*)name.c_str() );
|
Elf_Word val = elf_hash( (const unsigned char*)name.c_str() );
|
||||||
|
Elf_Word y = *(const Elf_Word*)( hash_section->get_data() +
|
||||||
Elf_Word y = *(const Elf_Word*)( hash_section->get_data() +
|
( 2 + val % nbucket ) * sizeof( Elf_Word ) );
|
||||||
( 2 + val % nbucket ) * sizeof( Elf_Word ) );
|
|
||||||
std::string str;
|
std::string str;
|
||||||
get_symbol( y, str, value, size, bind, type, section_index, other );
|
get_symbol( y, str, value, size, bind, type, section_index, other );
|
||||||
while ( str != name && STN_UNDEF != y && y < nchain ) {
|
while ( str != name && STN_UNDEF != y && y < nchain ) {
|
||||||
@ -125,9 +124,9 @@ class symbol_section_accessor_template
|
|||||||
const endianess_convertor& convertor = elf_file.get_convertor();
|
const endianess_convertor& convertor = elf_file.get_convertor();
|
||||||
section* string_section = elf_file.sections[get_string_table_index()];
|
section* string_section = elf_file.sections[get_string_table_index()];
|
||||||
|
|
||||||
Elf_Xword idx = 0;
|
Elf_Xword idx = 0;
|
||||||
bool match = false;
|
bool match = false;
|
||||||
Elf64_Addr v = 0;
|
Elf64_Addr v = 0;
|
||||||
|
|
||||||
if ( elf_file.get_class() == ELFCLASS32 ) {
|
if ( elf_file.get_class() == ELFCLASS32 ) {
|
||||||
match = generic_search_symbols<Elf32_Sym>([&convertor, &value](const Elf32_Sym* sym) {
|
match = generic_search_symbols<Elf32_Sym>([&convertor, &value](const Elf32_Sym* sym) {
|
||||||
@ -139,11 +138,8 @@ class symbol_section_accessor_template
|
|||||||
}, idx);
|
}, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match) {
|
if ( match ) {
|
||||||
bool found = get_symbol( idx, name, v, size, bind, type, section_index, other );
|
return get_symbol( idx, name, v, size, bind, type, section_index, other );
|
||||||
assert(found);
|
|
||||||
assert(v == value);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user