You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
stage-one/src/llosymbol_loader/llosymbol_loader_map.cpp

40 lines
1.1 KiB

#include <llosymbol_loader/llosymbol_loader_map.hpp>
bool llo::s1::symbol_loader_map_t::load( llo::lloiff_t &iff )
{
std::ifstream map_file( symbols_path );
if ( !map_file.is_open() )
return false;
bool has_advanced = false;
std::string line, begin_symbols( " Address Publics by Value" );
// segment_idx:segment_offset symbol_name...
std::regex pattern( "([0-9a-fA-F]+):([0-9a-fA-F]+)\\s+([_A-Za-z0-9:?@$]+)" );
while ( std::getline( map_file, line ) )
{
// advance past header...
if ( !has_advanced )
{
if ( !line.substr( 0, begin_symbols.size() ).compare( begin_symbols ) )
has_advanced = true;
continue;
}
std::smatch m;
if ( !std::regex_search( line, m, pattern ) )
continue;
auto section_number = std::strtoull( m[ 0 ].str().c_str(), nullptr, 16 );
auto section_offset = std::strtoull( m[ 2 ].str().c_str(), nullptr, 16 );
auto symbol_name = m[ 3 ].str();
if ( !section_number )
continue;
// TODO do something with these symbols...
}
return true;
}