1#ifndef ROSE_BinaryAnalysis_Concolic_Architecture_H
2#define ROSE_BinaryAnalysis_Concolic_Architecture_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_CONCOLIC_TESTING
6#include <Rose/BinaryAnalysis/ByteOrder.h>
7#include <Rose/BinaryAnalysis/Concolic/BasicTypes.h>
8#include <Rose/BinaryAnalysis/Concolic/ExecutionLocation.h>
9#include <Rose/BinaryAnalysis/Debugger/BasicTypes.h>
10#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
11#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
12#include <Rose/BinaryAnalysis/Partitioner2/Engine.h>
13#include <Rose/BinaryAnalysis/RegisterDescriptor.h>
14#include <Rose/BinaryAnalysis/SmtSolver.h>
17#include <Sawyer/BitVector.h>
19#include <boost/filesystem.hpp>
25namespace BinaryAnalysis {
32 using Ptr = ArchitecturePtr;
43 TestCaseId testCaseId_;
44 TestCasePtr testCase_;
45 Partitioner2::PartitionerConstPtr partitioner_;
46 Debugger::BasePtr debugger_;
47 ExecutionLocation currentLocation_;
48 SystemCallMap systemCalls_;
49 SharedMemoryMap sharedMemory_;
50 InputVariablesPtr inputVariables_;
58 virtual ~Architecture();
72 static void registerFactory(
const Ptr &factory);
80 static bool deregisterFactory(
const Ptr &factory);
88 static std::vector<Ptr> registeredFactories();
100 static Ptr forge(
const DatabasePtr&, TestCaseId,
const Yaml::Node &config);
101 static Ptr forge(
const DatabasePtr&,
const TestCasePtr&,
const Yaml::Node &config);
105 virtual bool matchFactory(
const Yaml::Node &config)
const = 0;
111 virtual Ptr instanceFromFactory(
const DatabasePtr&, TestCaseId,
const Yaml::Node &config)
const = 0;
118 bool isFactory()
const;
130 const std::string& name()
const;
131 void name(
const std::string&);
138 DatabasePtr database()
const;
144 TestCaseId testCaseId()
const;
150 TestCasePtr testCase()
const;
155 Partitioner2::PartitionerConstPtr partitioner()
const;
156 void partitioner(
const Partitioner2::PartitionerConstPtr&);
163 Debugger::BasePtr debugger()
const;
164 void debugger(
const Debugger::BasePtr&);
189 ExecutionLocation currentLocation()
const;
190 void currentLocation(
const ExecutionLocation&);
202 const SystemCallMap& systemCalls()
const;
216 const SharedMemoryMap& sharedMemory()
const;
224 InputVariablesPtr inputVariables()
const;
225 void inputVariables(
const InputVariablesPtr&);
233 virtual Partitioner2::PartitionerPtr partition(
const Partitioner2::EnginePtr&,
const std::string &specimenName) = 0;
238 virtual void configureSystemCalls() = 0;
245 virtual void configureSharedMemory(
const Yaml::Node &config);
255 void sharedMemory(
const SharedMemoryCallbackPtr&);
256 void sharedMemory(
const SharedMemoryCallbackPtr&,
const AddressInterval&);
260 void systemCalls(
size_t syscallId,
const SyscallCallbackPtr&);
271 virtual void load(
const boost::filesystem::path &tempDirectory) = 0;
277 virtual bool isTerminated();
280 virtual InstructionSemantics::BaseSemantics::DispatcherPtr
281 makeDispatcher(
const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&) = 0;
291 virtual std::vector<ExecutionEventPtr> createMemoryRestoreEvents() = 0;
292 std::vector<ExecutionEventPtr> createMemoryRestoreEvents(
const MemoryMapPtr&);
298 virtual std::vector<ExecutionEventPtr> createMemoryHashEvents() = 0;
305 virtual std::vector<ExecutionEventPtr> createMemoryAdjustEvents(
const MemoryMapPtr&, rose_addr_t insnVa) = 0;
311 virtual std::vector<ExecutionEventPtr> createRegisterRestoreEvents();
317 void saveEvents(
const std::vector<ExecutionEventPtr>&, When);
328 size_t playAllEvents(
const Partitioner2::PartitionerConstPtr&);
336 virtual bool playEvent(
const ExecutionEventPtr&);
341 virtual void runToEvent(
const ExecutionEventPtr&,
const Partitioner2::PartitionerConstPtr&);
346 uint64_t readMemoryUnsigned(rose_addr_t va,
size_t nBytes);
353 virtual std::string readCString(rose_addr_t va,
size_t maxBytes = UNLIMITED);
362 virtual ByteOrder::Endianness memoryByteOrder() = 0;
367 virtual rose_addr_t ip();
368 virtual void ip(rose_addr_t);
375 virtual void mapMemory(
const AddressInterval &where,
unsigned permissions);
380 virtual void unmapMemory(
const AddressInterval &where);
385 virtual size_t writeMemory(rose_addr_t startVa,
const std::vector<uint8_t> &bytes);
391 virtual std::vector<uint8_t> readMemory(rose_addr_t startVa,
size_t nBytes);
399 virtual void writeRegister(RegisterDescriptor, uint64_t value);
416 virtual void advanceExecution(
const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&);
423 virtual void executeInstruction(
const Partitioner2::PartitionerConstPtr&);
424 virtual void executeInstruction(
const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&,
SgAsmInstruction*);
431 const ExecutionLocation& nextInstructionLocation();
439 const ExecutionLocation& nextEventLocation(When);
446 std::vector<ExecutionEventPtr> getRelatedEvents(
const ExecutionEventPtr&)
const;
459 virtual void createInputVariables(
const Partitioner2::PartitionerConstPtr&,
const Emulation::RiscOperatorsPtr&,
460 const SmtSolver::Ptr&) = 0;
479 virtual void restoreInputVariables(
const Partitioner2::PartitionerConstPtr&,
const Emulation::RiscOperatorsPtr&,
480 const SmtSolver::Ptr&);
490 virtual void systemCall(
const Partitioner2::PartitionerConstPtr&,
491 const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&) {}
505 virtual std::pair<ExecutionEventPtr, SymbolicExpressionPtr>
506 sharedMemoryRead(
const SharedMemoryCallbacks&,
const Partitioner2::PartitionerConstPtr&,
const Emulation::RiscOperatorsPtr&,
507 rose_addr_t memVa,
size_t nBytes);
509 sharedMemoryWrite(
const SharedMemoryCallbacks&,
const Partitioner2::PartitionerConstPtr&,
const Emulation::RiscOperatorsPtr&,
510 rose_addr_t memVa,
const InstructionSemantics::BaseSemantics::SValuePtr&);
517 virtual void runSharedMemoryPostCallbacks(
const ExecutionEventPtr &sharedMemoryEvent,
const Emulation::RiscOperatorsPtr&);
546 void fixupSharedMemoryEvents(
const ExecutionEventPtr &sharedMemoryEvent,
const Emulation::RiscOperatorsPtr&);
549 void printSharedMemoryEvents(
const ExecutionEventPtr &sharedMemoryEvent,
const Emulation::RiscOperatorsPtr&);
552 virtual void sharedMemoryAccessPost(
const Partitioner2::PartitionerConstPtr&,
const Emulation::RiscOperatorsPtr&);
An associative container whose keys are non-overlapping intervals.
Container associating values with keys.
Holds a value or nothing.
Creates SharedPointer from this.
Base class for reference counted objects.
Base class for machine instructions.
ROSE_DLL_API void load(SgProject *project, std::list< std::string > const &filepaths)
Load ASTs that have been saved to files.
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
const char * Architecture(int64_t)
Convert Rose::BinaryAnalysis::Disassembler::Mips::Decoder::Architecture enum constant to a string.