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.

135 lines
4.4 KiB

#pragma once
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include <llosymbol/llosymbol_base.hpp>
#include <lloutils.hpp>
namespace llo
{
/// <summary>
/// lloiff class which contains all of the information for representing a file format in a IL format...
/// </summary>
class lloiff_t
{
public:
/// <summary>
/// iff section struct containing IL information about a section...
/// </summary>
struct iff_section_t
{
/// <summary>
/// section name, hashed so that there can be multiple...
/// </summary>
llo::utils::hash_t< std::string > section_name;
/// <summary>
/// section protections...
/// </summary>
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...
/// </summary>
std::vector< std::shared_ptr< llo::symbol::symbol_base_t > > symbols;
/// <summary>
/// vector of raw bytes containing the original bytes of this section...
/// </summary>
std::vector< std::uint8_t > raw;
};
/// <summary>
/// explicit constructor, must pass a name and the original file as a vector of bytes...
/// </summary>
/// <param name="name">name for this iff object...</param>
/// <param name="raw">vector of raw bytes containing the original file...</param>
explicit lloiff_t( const std::string &name, const std::vector< std::uint8_t > &raw ) : name( name ), raw( raw )
{
}
/// <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...
/// </summary>
std::shared_ptr< disposition_t > entry;
/// <summary>
/// name of the iff file, hashed so there can be unique objects...
/// </summary>
llo::utils::hash_t< std::string > name;
/// <summary>
/// vector of iff sections...
/// </summary>
std::vector< iff_section_t > sections;
/// <summary>
/// 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