mirror of
https://github.com/serge1/ELFIO.git
synced 2024-12-26 18:15:40 +00:00
A test program added; str_elf_class output implemented
This commit is contained in:
parent
daa8c81bfb
commit
6d60be2dfd
@ -0,0 +1,97 @@
|
||||
/*
|
||||
Copyright (C) 2001-2011 by Serge Lamikhov-Center
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef ELFIO_DUMP_HPP
|
||||
#define ELFIO_DUMP_HPP
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#include <elfio.hpp>
|
||||
|
||||
namespace ELFIO {
|
||||
//------------------------------------------------------------------------------
|
||||
class dump
|
||||
{
|
||||
public:
|
||||
//------------------------------------------------------------------------------
|
||||
static void
|
||||
header( std::ostream& out, elfio& reader )
|
||||
{
|
||||
out << "ELF Header\n" << std::endl;
|
||||
out << " Class: "
|
||||
<< str_elf_class( reader.get_class() )
|
||||
<< "(" << (int)reader.get_class() << ")"
|
||||
<< std::endl;
|
||||
out << " Encoding: "
|
||||
<< ( ( ELFDATA2LSB == reader.get_encoding() ) ? "Little endian" : "" )
|
||||
<< ( ( ELFDATA2MSB == reader.get_encoding() ) ? "Big endian" : "" )
|
||||
<< ( ( ( ELFDATA2LSB != reader.get_encoding() ) &&
|
||||
( ELFDATA2MSB != reader.get_encoding() ) ) ? "Unknown" : "" )
|
||||
<< std::endl;
|
||||
out << " ELFVersion: "
|
||||
<< ( ( EV_CURRENT == reader.get_elf_version() ) ? "Current" : "Unknown" )
|
||||
<< "(" << (int)reader.get_elf_version() << ")"
|
||||
<< std::endl;
|
||||
out << " Type: " << std::hex << reader.get_type() << std::endl;
|
||||
out << " Machine: " << std::hex << reader.get_machine() << std::endl;
|
||||
out << " Version: " << std::hex << reader.get_version() << std::endl;
|
||||
out << " Entry: " << std::hex << reader.get_entry() << std::endl;
|
||||
out << " Flags: " << std::hex << reader.get_flags() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static std::string
|
||||
str_section_type( Elf_Word type )
|
||||
{
|
||||
}
|
||||
|
||||
static std::string
|
||||
str_elf_class( Elf_Word type )
|
||||
{
|
||||
struct convert
|
||||
{
|
||||
Elf_Word type;
|
||||
const char* str;
|
||||
};
|
||||
convert converts[] =
|
||||
{
|
||||
{ ELFCLASS32, "ELF32" },
|
||||
{ ELFCLASS64, "ELF64" },
|
||||
};
|
||||
|
||||
std::string res = "UNKNOWN";
|
||||
for ( unsigned int i = 0; i < sizeof( converts )/sizeof( convert ); ++i ) {
|
||||
if ( converts[i].type == type ) {
|
||||
res = converts[i].str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace ELFIO
|
||||
|
||||
#endif // ELFIO_DUMP_HPP
|
27
elfio/elfio_dump_test.cpp
Normal file
27
elfio/elfio_dump_test.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include <iostream>
|
||||
#include <elfio_dump.hpp>
|
||||
|
||||
using namespace ELFIO;
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
if ( argc != 2 ) {
|
||||
printf( "Usage: ELFDump <file_name>\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Open ELF reader
|
||||
elfio reader;
|
||||
|
||||
if ( !reader.load( argv[1] ) ) {
|
||||
printf( "File %s is not found or it is not an ELF file\n", argv[1] );
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Print ELF file header
|
||||
dump::header( std::cout, reader );
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user