added map file parsing and opaque symbol...

master
_xeroxz 3 years ago
parent a7abd2055c
commit c5f3f9dccb

@ -11,11 +11,13 @@ namespace llo::symbol
s_function,
s_data,
s_import,
s_export
s_export,
s_opaque
};
class symbol_base_t
{
protected:
disposition_t disposition;
llo::utils::hash_t< std::string > symbol_name;
std::size_t symbol_size;

@ -0,0 +1,20 @@
#include <llosymbol/llosymbol_base.hpp>
namespace llo::symbol
{
class symbol_opaque_t : public symbol_base_t
{
public:
explicit symbol_opaque_t( const llo::utils::hash_t< std::string > &symbol_name,
const llo::disposition_t &disposition )
: symbol_base_t( symbol_name, disposition )
{
}
static std::shared_ptr< symbol_opaque_t > make( const llo::utils::hash_t< std::string > &symbol_name,
const llo::disposition_t &disposition );
symbol_type_t get_type() const override;
std::size_t get_size() const override;
};
} // namespace llo::symbol

@ -4,17 +4,19 @@
#include <llosymbol/llosymbol_base.hpp>
#include <string>
#include <vector>
#include <regex>
namespace llo::s1
{
class symbol_loader_base_t
{
protected:
std::string symbols_path;
public:
explicit symbol_loader_base_t( const std::string &path ) : symbols_path{ path }
{
}
virtual void load( llo::lloiff_t & ) = 0;
virtual bool load( llo::lloiff_t & ) = 0;
};
} // namespace llo::s1

@ -1,4 +1,5 @@
#include <llosymbol_loader/llosymbol_loader_base.hpp>
#include <llosymbol/llosymbol_opaque.hpp>
namespace llo::s1
{
@ -8,6 +9,6 @@ namespace llo::s1
explicit symbol_loader_map_t( const std::string &path ) : symbol_loader_base_t( path )
{
}
void load( llo::lloiff_t &iff ) override;
bool load( llo::lloiff_t &iff ) override;
};
} // namespace llo::s1

@ -108,6 +108,7 @@
<ClCompile Include="src\llodctor\llodctor_lib.cpp" />
<ClCompile Include="src\llodctor\llodctor_pe.cpp" />
<ClCompile Include="src\llodisposition\llodisposition_types.cpp" />
<ClCompile Include="src\llosymbol\llosymbol_opaque.cpp" />
<ClCompile Include="src\llosymbol_loader\llosymbol_loader_map.cpp" />
<ClCompile Include="src\main.cpp" />
</ItemGroup>

@ -51,6 +51,9 @@
<Filter Include="Source Files\llodisposition">
<UniqueIdentifier>{4370901a-12c1-43ce-883a-6a6c3f48845a}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\llosymbol">
<UniqueIdentifier>{6eecf6e2-47aa-4bf3-97ce-e34688ad8ae3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\lloiff.hpp">
@ -342,5 +345,8 @@
<ClCompile Include="src\llodisposition\llodisposition_types.cpp">
<Filter>Source Files\llodisposition</Filter>
</ClCompile>
<ClCompile Include="src\llosymbol\llosymbol_opaque.cpp">
<Filter>Source Files\llosymbol</Filter>
</ClCompile>
</ItemGroup>
</Project>

@ -0,0 +1,20 @@
#include <llosymbol/llosymbol_opaque.hpp>
namespace llo::symbol
{
std::shared_ptr< symbol_opaque_t > symbol_opaque_t::make( const llo::utils::hash_t< std::string > &symbol_name,
const llo::disposition_t &disposition )
{
return std::make_shared< symbol_opaque_t >( symbol_name, disposition );
}
symbol_type_t symbol_opaque_t::get_type() const
{
return symbol_type_t::s_opaque;
}
std::size_t symbol_opaque_t::get_size() const
{
return symbol_size;
}
} // namespace llo::symbol

@ -1,6 +1,44 @@
#include <llosymbol_loader/llosymbol_loader_map.hpp>
void llo::s1::symbol_loader_map_t::load( llo::lloiff_t &iff )
bool llo::s1::symbol_loader_map_t::load( llo::lloiff_t &iff )
{
// TODO
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;
// insert new opaque symbol into symbols list...
llo::disposition_t disposition( iff.name, iff.sections[ section_number - 1 ].section_name, section_offset );
auto new_opaque_symbol = llo::symbol::symbol_opaque_t::make( symbol_name, disposition );
iff.sections[ section_number - 1 ].symbols.push_back( new_opaque_symbol );
}
return true;
}

@ -50,11 +50,11 @@ int __cdecl main( int argc, const char *argv[] )
if ( cli_parser.exists( "symbols" ) )
{
std::filesystem::path symbols_file{ cli_parser.get< std::string >( "symbols" ) };
if ( symbols_file.extension().compare( ".map" ) )
if ( !symbols_file.extension().compare( ".map" ) )
{
symbol_loader = std::make_shared< llo::s1::symbol_loader_map_t >( symbols_file.string() );
}
else if ( symbols_file.extension().compare( ".pdb" ) )
else if ( !symbols_file.extension().compare( ".pdb" ) )
{
// TODO:
// symbol_loader = std::make_shared< llo::s1::symbol_loader_pdb_t >( symbols_file );
@ -69,16 +69,16 @@ int __cdecl main( int argc, const char *argv[] )
std::shared_ptr< llo::s1::dctor_base_t > file_dctor = nullptr;
std::filesystem::path file_path{ name };
if ( file_path.extension().compare( ".exe" ) || file_path.extension().compare( ".dll" ) ||
file_path.extension().compare( ".sys" ) )
if ( !file_path.extension().compare( ".exe" ) || !file_path.extension().compare( ".dll" ) ||
!file_path.extension().compare( ".sys" ) )
{
file_dctor = std::make_shared< llo::s1::dctor_pe_t >( image, symbol_loader.get() );
}
else if ( file_path.extension().compare( ".lib" ) )
else if ( !file_path.extension().compare( ".lib" ) )
{
file_dctor = std::make_shared< llo::s1::dctor_lib_t >( image, symbol_loader.get() );
}
else if ( file_path.extension().compare( ".o" ) || file_path.extension().compare( ".so" ) )
else if ( !file_path.extension().compare( ".o" ) || !file_path.extension().compare( ".so" ) )
{
// TODO:
// file_dctor = std::make_shared< llo::s1::dctor_elf_t >( image, symbol_loader.get() );

Loading…
Cancel
Save