1#ifndef ROSE_BinaryAnalysis_Concolic_I386Linux_Architecture_H
2#define ROSE_BinaryAnalysis_Concolic_I386Linux_Architecture_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_CONCOLIC_TESTING
6#include <Rose/BinaryAnalysis/Concolic/Architecture.h>
7#include <Rose/BinaryAnalysis/Concolic/ExecutionEvent.h>
8#include <Rose/BinaryAnalysis/Concolic/SharedMemory.h>
9#include <Rose/BinaryAnalysis/Concolic/SystemCall.h>
10#include <Rose/BinaryAnalysis/MemoryMap.h>
13#include <Sawyer/Callbacks.h>
15#include <boost/filesystem.hpp>
18namespace BinaryAnalysis {
28 using Super = Concolic::Architecture;
32 using Ptr = ArchitecturePtr;
35 bool markingArgvAsInput_ =
true;
36 bool markingEnvpAsInput_ =
false;
53 static Ptr instance(
const DatabasePtr&, TestCaseId,
const Yaml::Node &config);
54 static Ptr instance(
const DatabasePtr&,
const TestCasePtr&,
const Yaml::Node &config);
59 Debugger::LinuxPtr debugger()
const;
62 RegisterDescriptor systemCallReturnRegister();
66 virtual bool matchFactory(
const Yaml::Node&)
const override;
67 virtual Super::Ptr instanceFromFactory(
const DatabasePtr&, TestCaseId,
const Yaml::Node &config)
const override;
68 virtual Partitioner2::PartitionerPtr partition(
const Partitioner2::EnginePtr&,
const std::string &specimen)
override;
69 virtual void configureSystemCalls()
override;
70 virtual void configureSharedMemory(
const Yaml::Node &config)
override;
71 virtual void load(
const boost::filesystem::path&)
override;
72 virtual ByteOrder::Endianness memoryByteOrder()
override;
73 virtual std::vector<ExecutionEventPtr> createMemoryRestoreEvents()
override;
74 virtual std::vector<ExecutionEventPtr> createMemoryHashEvents()
override;
75 virtual std::vector<ExecutionEventPtr> createMemoryAdjustEvents(
const MemoryMap::Ptr&, rose_addr_t insnVa)
override;
76 virtual bool playEvent(
const ExecutionEventPtr&)
override;
77 virtual void mapMemory(
const AddressInterval&,
unsigned permissions)
override;
78 virtual void unmapMemory(
const AddressInterval&)
override;
79 virtual void createInputVariables(
const Partitioner2::PartitionerConstPtr&,
const Emulation::RiscOperatorsPtr&,
80 const SmtSolver::Ptr &solver)
override;
81 virtual void systemCall(
const Partitioner2::PartitionerConstPtr&,
82 const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&)
override;
83 virtual void advanceExecution(
const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&)
override;
84 virtual InstructionSemantics::BaseSemantics::DispatcherPtr
85 makeDispatcher(
const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&)
override;
89 void mapScratchPage();
93 std::vector<ExecutionEventPtr> copyMemory(
const MemoryMap::Ptr &src,
const MemoryMap::Ptr &dst,
const AddressInterval &where,
97 std::vector<MemoryMap::ProcessMapRecord> disposableMemory();
100 void unmapAllMemory();
104 uint64_t systemCallFunctionNumber(
const Partitioner2::PartitionerConstPtr&,
105 const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&);
108 InstructionSemantics::BaseSemantics::SValuePtr
109 systemCallArgument(
const Partitioner2::PartitionerConstPtr&,
110 const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&,
size_t argNumber);
113 InstructionSemantics::BaseSemantics::SValuePtr
114 systemCallReturnValue(
const Partitioner2::PartitionerConstPtr&,
115 const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&);
118 InstructionSemantics::BaseSemantics::SValuePtr
119 systemCallReturnValue(
const Partitioner2::PartitionerConstPtr&,
120 const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&,
121 const InstructionSemantics::BaseSemantics::SValuePtr&);
132class SyscallBase:
public SyscallCallback {
133 ExecutionEventPtr latestReturnEvent_;
134 ExecutionEventPtr penultimateReturnEvent_;
138 virtual ~SyscallBase();
145 void hello(
const std::string &name,
const SyscallContext&)
const;
152 virtual void playback(SyscallContext&) = 0;
171 virtual void handlePreSyscall(SyscallContext&) {}
172 virtual void handlePostSyscall(SyscallContext&) = 0;
189 ExecutionEventPtr latestReturnEvent()
const;
190 ExecutionEventPtr penultimateReturnEvent()
const;
197 void showRecentReturnValues(std::ostream&,
const SyscallContext&)
const;
204 SymbolicExpressionPtr penultimateSymbolicReturn()
const;
208 virtual bool operator()(
bool , SyscallContext&)
override final;
216class SyscallUnimplemented:
public SyscallBase {
218 SyscallUnimplemented();
220 ~SyscallUnimplemented();
224 static Ptr instance();
226 void playback(SyscallContext&)
override;
227 void handlePostSyscall(SyscallContext&)
override;
234class SyscallReturnsInput:
public SyscallBase {
236 SyscallReturnsInput();
238 ~SyscallReturnsInput();
242 static Ptr instance();
244 void playback(SyscallContext&)
override;
245 void handlePostSyscall(SyscallContext&)
override;
249class SyscallTerminates:
public SyscallBase {
253 ~SyscallTerminates();
257 static Ptr instance();
259 void playback(SyscallContext&)
override;
260 void handlePostSyscall(SyscallContext&)
override;
266class SyscallReturn:
public SyscallBase {
279 virtual std::pair<SymbolicExpressionPtr, Sawyer::Optional<uint64_t>> makeReturnConstraint(SyscallContext&) = 0;
282 void handlePostSyscall(SyscallContext&)
override final;
290class SyscallConstant:
public SyscallReturn {
298 static Ptr instance();
300 void playback(SyscallContext&)
override;
301 std::pair<SymbolicExpressionPtr, Sawyer::Optional<uint64_t>> makeReturnConstraint(SyscallContext&)
override;
307class SyscallNondecreasing:
public SyscallReturn {
309 SyscallNondecreasing();
311 ~SyscallNondecreasing();
315 static Ptr instance();
317 void playback(SyscallContext&)
override;
318 std::pair<SymbolicExpressionPtr, Sawyer::Optional<uint64_t>> makeReturnConstraint(SyscallContext&)
override;
322class SyscallAccess:
public SyscallBase {
330 static Ptr instance();
332 void playback(SyscallContext&)
override;
333 void handlePostSyscall(SyscallContext&)
override;
337class SyscallBrk:
public SyscallBase {
345 static Ptr instance();
347 void playback(SyscallContext&)
override;
348 void handlePostSyscall(SyscallContext&)
override;
352class SyscallMmap2:
public SyscallBase {
360 static Ptr instance();
362 void playback(SyscallContext&)
override;
363 void handlePostSyscall(SyscallContext&)
override;
367class SyscallOpenat:
public SyscallBase {
375 static Ptr instance();
377 void playback(SyscallContext&)
override;
378 void handlePostSyscall(SyscallContext&)
override;
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.