1#ifndef ROSE_BinaryAnalysis_Serialization_FlatBuffers_H
2#define ROSE_BinaryAnalysis_Serialization_FlatBuffers_H
4#include <featureTests.h>
5#ifdef ROSE_ENABLE_BINARY_ANALYSIS
6#ifdef ROSE_ENABLE_FLATBUFFERS
8#include <Rose/BinaryAnalysis/Architecture/BasicTypes.h>
9#include <Rose/BinaryAnalysis/MemoryMap.h>
10#include <Rose/BinaryAnalysis/Partitioner2/BasicBlock.h>
11#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
12#include <Rose/BinaryAnalysis/Partitioner2/Partitioner.h>
14#include <rosePublicConfig.h>
16#include <boost/filesystem/path.hpp>
24#include <flatbuffers/flatbuffers.h>
26#include <Rose/BinaryAnalysis/Serialization/FlatBufferSchema.h>
29namespace BinaryAnalysis {
30namespace Serialization {
34namespace FlatBuffers {
36static constexpr uint32_t version = 1;
60 explicit Serializer(
const P2::PartitionerConstPtr&);
61 ~Serializer() =
default;
63 Serializer(
const Serializer&) =
delete;
64 Serializer& operator=(
const Serializer&) =
delete;
66 template <
typename T>
using Handle = flatbuffers::Offset<T>;
76 std::pair<const uint8_t*, size_t> buffer()
const;
79 void write(std::ostream&)
const;
82 void write(
const boost::filesystem::path&)
const;
85 P2::PartitionerConstPtr partitioner_;
86 std::vector<char> bytes_;
87 std::unique_ptr<flatbuffers::FlatBufferBuilder> builder_;
90 Handle<Architecture> architecture(
const BinaryAnalysis::Architecture::BaseConstPtr& arch);
92 Handle<BasicBlock> basicBlock(
const P2::BasicBlockPtr& bb);
93 Handle<Function> function(
const P2::FunctionPtr& f);
94 Handle<CfgEdge> cfgEdge(
const P2::ControlFlowGraph::Edge& e);
95 Handle<Cfg> cfg(
const P2::ControlFlowGraph& cfg);
96 Handle<Segment> segment(
const BinaryAnalysis::MemoryMap::Super::Node& seg);
97 Handle<MemoryMap> mmap(
const BinaryAnalysis::MemoryMap& map);
98 std::pair<Handle<InstructionList>, Handle<BasicBlockList>>
99 instructionsBasicBlocks(
const std::vector<P2::BasicBlockPtr>& bbs);
100 Handle<FunctionList> functions(
const std::vector<P2::FunctionPtr>& funs);
101 Handle<Root> partitioner();
130 Deserializer() =
default;
133 static Deserializer fromFile(
const boost::filesystem::path&);
136 static Deserializer fromStream(std::istream&);
139 static Deserializer fromBytes(std::vector<char>&&);
142 static Deserializer fromBytes(
const std::vector<char>&);
152 void preferStoredBytes(
bool prefer) { preferStoredBytes_ = prefer; }
164 P2::PartitionerPtr
load(
const P2::BasePartitionerSettings& settings);
166 P2::PartitionerPtr
load();
170 std::vector<char> bytes_;
173 P2::PartitionerPtr partitioner_;
180 std::unordered_map<Address, SgAsmInstruction*> instructions_;
181 std::unordered_map<Address, P2::BasicBlock::Ptr> basic_blocks_;
192 bool preferStoredBytes_ =
false;
199 BinaryAnalysis::MemoryMap::Ptr mmap(
const MemoryMap* map)
const;
213 SgAsmInstruction* disassembleFromBytes(Address addr,
const flatbuffers::Vector<uint8_t>* bytes)
const;
224 void instruction(
const Instruction*
const& instr);
226 void basicBlock(
const BasicBlock*
const& bb);
228 void function(
const Function*
const& fun);
231 void cfg(
const Cfg*
const& cfg);
Base class for machine instructions.
Binary function detection.
ROSE_DLL_API void load(SgProject *project, std::list< std::string > const &filepaths)
Load ASTs that have been saved to files.