Files
serge1-COFFI/examples/tutorial/tutorial.cpp
T
2020-06-15 18:14:13 +02:00

62 lines
1.8 KiB
C++

#include <iostream>
#include <coffi/coffi.hpp>
using namespace COFFI;
int main( int argc, char** argv )
{
if ( argc != 2 ) {
std::cout << "Usage: tutorial <coff_file>" << std::endl;
return 1;
}
// Create an coffi reader
coffi reader;
// Load COFF data
if ( !reader.load( argv[1] ) ) {
std::cout << "Can't find or process COFF file " << argv[1] << std::endl;
return 2;
}
// Print COFF file properties
std::cout << "COFF file architecture: ";
switch (reader.get_architecture()) {
case COFFI_ARCHITECTURE_PE:
if (reader.get_optional_header()) {
if (reader.get_optional_header()->get_magic() == OH_MAGIC_PE32PLUS ) {
std::cout << "Portable Executable PE32+" << std::endl;
} else {
std::cout << "Portable Executable PE32" << std::endl;
}
} else {
std::cout << "Portable Executable" << std::endl;
}
break;
case COFFI_ARCHITECTURE_CEVA:
std::cout << "CEVA" << std::endl;
break;
case COFFI_ARCHITECTURE_TI:
std::cout << "Texas Instruments" << std::endl;
break;
}
// Print COFF file sections info
auto sec_num = reader.get_sections().size();
std::cout << "Number of sections: " << sec_num << std::endl;
for (auto sec: reader.get_sections()) {
std::cout << " [" << sec->get_index() << "] "
<< sec->get_name()
<< "\t"
<< sec->get_data_size()
<< std::endl;
}
// Print COFF file symbols info
for (auto sym: *reader.get_symbols()) {
std::cout << sym.get_index() << " " << sym.get_name() << " " << sym.get_value() << std::endl;
}
return 0;
}