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.

117 lines
3.8 KiB

#pragma once
#include <cstdint>
#include <lloutils.hpp>
#include <memory>
#include <string>
#include <vector>
#define XED_ENCODER
extern "C"
{
#include <xed-decode.h>
#include <xed-interface.h>
}
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>
/// section protections structure...
/// </summary>
struct iff_prot_t
{
/// <summary>
/// the raw characteristics of the original binary file...
/// </summary>
std::uint64_t characteristics;
/// <summary>
/// bit field structure containing IL version of characteristics...
/// </summary>
union
{
struct
{
std::uint32_t is_executable : 1;
std::uint32_t is_writable : 1;
std::uint32_t is_discardable : 1;
};
std::uint32_t flags;
} prot;
};
/// <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>
/// vector of raw bytes containing the original bytes of this section...
/// </summary>
std::vector< std::uint8_t > raw;
/// <summary>
/// IL and native characteristics of a section...
/// contains information such as: is the section executable,
/// writable, and or discardable?
/// </summary>
iff_prot_t characteristics;
/// <summary>
/// a vector containing every single instruction of this section...
/// </summary>
std::vector< xed_decoded_inst_t > instrs;
};
/// <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>
/// 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