added lib dctor...

master
_xeroxz 3 years ago
parent 82c1f36b14
commit ac8ed08e43

@ -1,28 +1,36 @@
#include <coff/archive.hpp>
#include <coff/image.hpp>
#include <llodctor/llodctor_base.hpp>
namespace llo::s1
{
class dctor_lib_t : public dctor_base_t
{
struct obj_t
{
std::string_view name;
std::vector< std::uint8_t > raw;
coff::image_t *operator->()
{
return reinterpret_cast< coff::image_t * >( raw.data() );
}
};
std::vector< obj_t > objs;
public:
explicit dctor_lib_t( const std::vector< std::uint8_t > &image,
llo::s1::symbol_loader_base_t *symbol_loader = nullptr )
: dctor_base_t( image, symbol_loader )
{
const auto lib_header = reinterpret_cast< const ar::header_t * >( image.data() );
auto lib_entry = &lib_header->first_entry;
ar::entry_t *string_table = nullptr;
ar::view lib( image.data(), image.size() );
do
for ( auto itr = lib.begin(); itr != lib.end(); ++itr )
{
// TODO...
// BROKE!
if ( lib_entry->is_string_table() )
string_table = ( ar::entry_t * )lib_entry;
std::printf( "> object name = %s\n", lib_entry->to_string( string_table ) );
} while ( ( lib_entry = lib_header->first_entry.next() ) );
std::vector obj_data( itr->begin(), itr->end() );
objs.push_back( { itr->to_string( lib.string_table ), obj_data } );
}
}
void generate( lloiff_t &iff ) override;
};

@ -26,11 +26,53 @@ namespace llo
llo::utils::hash_t< std::string > section_name;
/// <summary>
/// opaque value, lifted from the original file format...
/// this is should only be used by code that understands what the underlying file
/// format was...
/// section protections...
/// </summary>
std::uint64_t characteristics;
struct prot_t
{
/// <summary>
/// section protection types...
/// </summary>
enum prot_e : std::uint16_t
{
none = 0b0000,
executable = 0b0001,
writeable = 0b0010
};
/// <summary>
/// IL section protections (writeable/executable)...
/// </summary>
prot_e prots;
/// <summary>
/// opaque value containing the native characteristics...
/// </summary>
std::uint64_t native;
/// <summary>
/// returns true if section is executable...
/// </summary>
/// <returns></returns>
bool is_executable()
{
return ( prots & prot_e::executable );
}
/// <summary>
/// returns true if section is writable...
/// </summary>
/// <returns></returns>
bool is_writable()
{
return ( prots & prot_e::writeable );
}
};
/// <summary>
/// section protections and characteristics
/// </summary>
prot_t protections;
/// <summary>
/// vector of symbols for this section...
@ -52,6 +94,17 @@ namespace llo
{
}
/// <summary>
/// makes a shared pointer containing a llo::lloiff_t...
/// </summary>
/// <param name="name">name of the file...</param>
/// <param name="raw">vector of bytes containing the raw file...</param>
/// <returns>returns a shared pointer of the new object...</returns>
static std::shared_ptr< llo::lloiff_t > make( const std::string &name, const std::vector< std::uint8_t > &raw )
{
return std::make_shared< llo::lloiff_t >( name, raw );
}
/// <summary>
/// entry point, where code execution begins....
/// this is lifted from the underlying file format...
@ -72,5 +125,11 @@ namespace llo
/// vector of bytes containing the entire original file...
/// </summary>
std::vector< std::uint8_t > raw;
/// <summary>
/// some file formats contain multiple other files inside of them such as LIB...
/// which is just an archive of OBJ's...
/// </summary>
std::vector< std::shared_ptr< llo::lloiff_t > > children;
};
} // namespace llo

@ -4,6 +4,8 @@ namespace llo::symbol
{
class symbol_opaque_t : public symbol_base_t
{
symbol_type_t type = symbol_type_t::s_opaque;
public:
explicit symbol_opaque_t( const llo::utils::hash_t< std::string > &symbol_name,
const llo::disposition_t &disposition )
@ -14,6 +16,7 @@ namespace llo::symbol
static std::shared_ptr< symbol_opaque_t > make( const llo::utils::hash_t< std::string > &symbol_name,
const llo::disposition_t &disposition );
void set_size( std::size_t size );
symbol_type_t get_type() const override;
std::size_t get_size() const override;
};

@ -93,6 +93,7 @@
<ClInclude Include="include\llosymbol\llosymbol_import.hpp" />
<ClInclude Include="include\llosymbol\llosymbol_opaque.hpp" />
<ClInclude Include="include\llosymbol_loader\llosymbol_loader_base.hpp" />
<ClInclude Include="include\llosymbol_loader\llosymbol_loader_coff.hpp" />
<ClInclude Include="include\llosymbol_loader\llosymbol_loader_map.hpp" />
<ClInclude Include="include\llosymbol_loader\llosymbol_loader_pdb.hpp" />
<ClInclude Include="include\lloutils.hpp" />

@ -311,6 +311,9 @@
<ClInclude Include="dependencies\linux-pe\includes\coff\auxiliaries\aux_weak_external.hpp">
<Filter>Header Files\linux-pe\coff\auxiliaries</Filter>
</ClInclude>
<ClInclude Include="include\llosymbol_loader\llosymbol_loader_coff.hpp">
<Filter>Header Files\llosymbol_loader</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include=".clang-format">

@ -5,7 +5,7 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommandArguments>-i llo-s1.lib</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>-i demo.lib</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

@ -2,5 +2,28 @@
void llo::s1::dctor_lib_t::generate( lloiff_t &iff )
{
// TODO
// add obj as children to the IFF as the IFF passed in is simply
// the LIB... also add section information for each...
std::for_each( objs.begin(), objs.end(), [ & ]( llo::s1::dctor_lib_t::obj_t &obj ) {
// use llo::lloiff::make to make a std::shared_ptr...
iff.children.push_back( iff.make( std::string( obj.name ), obj.raw ) );
// add sections to last IFF...
for ( auto idx = 0u; idx < obj->file_header.num_sections; ++idx )
{
auto obj_section = obj->get_section( idx );
std::string section_name( obj_section->name.to_string( obj->get_strings() ) );
llo::lloiff_t::iff_section_t section{ section_name };
section.protections.native = obj_section->prots.flags;
section.raw.insert( section.raw.begin(), obj_section->ptr_raw_data + obj.raw.data(),
obj_section->size_raw_data + obj_section->ptr_raw_data + obj.raw.data() );
iff.children.back()->sections.push_back( section );
}
} );
// coff symbol loader...
if ( symbol_loader )
symbol_loader->load( iff );
}

@ -7,7 +7,7 @@ void llo::s1::dctor_pe_t::generate( lloiff_t &iff )
{
llo::utils::hash_t< std::string > section_name{ std::string( sections[ idx ].name.to_string() ) };
llo::lloiff_t::iff_section_t section{ section_name };
section.characteristics = sections[ idx ].characteristics.flags;
section.protections.native = sections[ idx ].prots.flags;
// check to see if this section contains the entry point of the module...
if ( entry_point >= sections[ idx ].virtual_address &&

@ -10,11 +10,16 @@ namespace llo::symbol
symbol_type_t symbol_opaque_t::get_type() const
{
return symbol_type_t::s_opaque;
return type;
}
std::size_t symbol_opaque_t::get_size() const
{
return symbol_size;
}
void symbol_opaque_t::set_size( std::size_t size )
{
symbol_size = size;
}
} // namespace llo::symbol

@ -92,15 +92,18 @@ int __cdecl main( int argc, const char *argv[] )
llo::lloiff_t iff( name, image );
file_dctor->generate( iff );
std::printf( "> number of sections = %d\n", iff.sections.size() );
if ( iff.entry.get() )
std::printf( "> entry section name = %s, section offest = 0x%x\n", iff.entry->section_name.get_data().c_str(),
iff.entry->offset );
for ( auto &section : iff.sections )
std::printf( "> iff number of children = %d\n", iff.children.size() );
for ( auto &child : iff.children )
{
std::printf( "> section name = %s\n", section.section_name.get_data().c_str() );
std::printf( "> size of raw section = %d\n", section.raw.size() );
std::printf( "> number of symbols = %d\n", section.symbols.size() );
if ( iff.entry.get() )
std::printf( "> entry section name = %s, section offest = 0x%x\n",
iff.entry->section_name.get_data().c_str(), iff.entry->offset );
for ( auto &section : child->sections )
{
std::printf( "> section name = %s\n", section.section_name.get_data().c_str() );
std::printf( "> size of raw section = %d\n", section.raw.size() );
std::printf( "> number of symbols = %d\n", section.symbols.size() );
}
}
}
Loading…
Cancel
Save