ROSE 0.11.145.192
Partitioner.h
1#ifndef ROSE_BinaryAnalysis_Partitioner2_Partitioner_H
2#define ROSE_BinaryAnalysis_Partitioner2_Partitioner_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
6
7#include <Rose/BinaryAnalysis/Partitioner2/AddressUsageMap.h>
8#include <Rose/BinaryAnalysis/Partitioner2/Configuration.h>
9#include <Rose/BinaryAnalysis/Partitioner2/ControlFlowGraph.h>
10#include <Rose/BinaryAnalysis/Partitioner2/Semantics.h>
11
12#include <Rose/BinaryAnalysis/Architecture/BasicTypes.h>
13#include <Rose/BinaryAnalysis/InstructionProvider.h>
14#include <Rose/BinaryAnalysis/InstructionSemantics/SymbolicSemantics.h>
15#include <Rose/BinaryAnalysis/SerialIo.h>
16#include <Rose/BinaryAnalysis/SourceLocations.h>
17#include <Rose/BinaryAnalysis/Unparser/Settings.h>
18#include <Rose/Progress.h>
19
20#include <Sawyer/Attribute.h>
21#include <Sawyer/Callbacks.h>
22#include <Sawyer/IntervalSet.h>
23#include <Sawyer/Map.h>
24#include <Sawyer/Message.h>
25#include <Sawyer/Optional.h>
26#include <Sawyer/ProgressBar.h>
27#include <Sawyer/SharedObject.h>
28#include <Sawyer/SharedPointer.h>
29
30#include <boost/filesystem.hpp>
31#include <boost/format.hpp>
32#include <boost/move/utility_core.hpp>
33#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
34#include <boost/serialization/access.hpp>
35#endif
36
37#include <ostream>
38#include <set>
39#include <string>
40#include <vector>
41
42// [Robb Matzke 2022-06-22]: deprecated. Needed because some user code doesn't include the old InstructionSemantics2 header
43// files where this same thing is defined, yet they use InstructionSemantics2 because such things were once declared by this
44// header file due to it originally including InstructionSemantics2 headers (which it no longer does).
45namespace Rose { namespace BinaryAnalysis { namespace InstructionSemantics2 = InstructionSemantics; }}
46
47namespace Rose {
48namespace BinaryAnalysis {
49namespace Partitioner2 {
50
263class ROSE_DLL_API Partitioner /*final*/
264 : public Sawyer::SharedObject, public Sawyer::SharedFromThis<Partitioner>, public Sawyer::Attribute::Storage<> {
265 BOOST_MOVABLE_BUT_NOT_COPYABLE(Partitioner)
266
267
269 //
270 // Types
271 //
274public:
282 // Callback list types
285 typedef std::vector<FunctionPrologueMatcherPtr> FunctionPrologueMatchers;
286 typedef std::vector<FunctionPaddingMatcherPtr> FunctionPaddingMatchers;
289 struct Thunk {
291 rose_addr_t target;
292 Thunk(const BasicBlockPtr&, rose_addr_t target);
293 ~Thunk();
294 };
295
298
301 //
302 // Data members
303 //
306private:
307 BasePartitionerSettings settings_; // settings adjustable from the command-line
308 Configuration config_; // configuration information about functions, blocks, etc.
309 Architecture::BaseConstPtr architecture_; // architecture information such as the ISA, word size, etc.
310 InstructionProvider::Ptr instructionProvider_; // cache for all disassembled instructions
311 MemoryMap::Ptr memoryMap_; // description of memory, especially insns and non-writable
312 SgAsmInterpretation *interpretation_ = nullptr; // Interpretation corresponding to the memory map
313 ControlFlowGraph cfg_; // basic blocks that will become part of the ROSE AST
314 CfgVertexIndex vertexIndex_; // Vertex-by-address index for the CFG
315 AddressUsageMap aum_; // How addresses are used for each address represented by the CFG
316 SmtSolverPtr solver_; // Satisfiable modulo theory solver used by semantic expressions
317 Functions functions_; // List of all attached functions by entry address
318 bool autoAddCallReturnEdges_ = false; // Add E_CALL_RETURN edges when blocks are attached to CFG?
319 bool assumeFunctionsReturn_ = true; // Assume that unproven functions return to caller?
320 size_t stackDeltaInterproceduralLimit_ = 1; // Max depth of call stack when computing stack deltas
321 AddressNameMap addressNames_; // Names for various addresses
322 SourceLocations sourceLocations_; // Mapping between source locations and addresses
323 SemanticMemoryParadigm semanticMemoryParadigm_ = LIST_BASED_MEMORY; // Slow and precise, or fast and imprecise?
324 Unparser::BasePtr unparser_; // For unparsing things to pseudo-assembly
325 Unparser::BasePtr insnUnparser_; // For unparsing single instructions in diagnostics
326 Unparser::BasePtr insnPlainUnparser_; // For unparsing just instruction mnemonic and operands
327
328 // Callback lists
329 CfgAdjustmentCallbacks cfgAdjustmentCallbacks_;
330 BasicBlockCallbacks basicBlockCallbacks_;
331 FunctionPrologueMatchers functionPrologueMatchers_;
332 FunctionPaddingMatchers functionPaddingMatchers_;
333
334 // Special CFG vertices.
335 ControlFlowGraph::VertexIterator undiscoveredVertex_;
336 ControlFlowGraph::VertexIterator indeterminateVertex_;
337 ControlFlowGraph::VertexIterator nonexistingVertex_;
338 static const size_t nSpecialVertices = 3;
339
340 // Optional cached information
341 Sawyer::Optional<rose_addr_t> elfGotVa_; // address of ELF GOT, set by findElfGotVa
342
343 // Protects the following data members
344 mutable SAWYER_THREAD_TRAITS::Mutex mutex_;
345 Progress::Ptr progress_; // Progress reporter to update, or null
346 mutable size_t cfgProgressTotal_ = 0; // Expected total for the CFG progress bar; initialized at first report
347
350 //
351 // Serialization
352 //
355#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
356private:
357 friend class boost::serialization::access;
358 template<class Archive> void serializeCommon(Archive&, unsigned);
359 template<class Archive> void save(Archive&, unsigned) const;
360 template<class Archive> void load(Archive&, unsigned);
361 BOOST_SERIALIZATION_SPLIT_MEMBER();
362#endif
363
366 //
367 // Constructors
368 //
371private:
372 Partitioner(); // needed for Boost serialization
373
374 // Partitioner objects are reference counted and always allocated on the heap. Use the `instance` methods to construct
375 // these objects. Also, since the Partitioner class is final, we make the constructors private instead of the usual
376 // protected constructors elsewhere in ROSE.
379public:
380 ~Partitioner();
381
382public:
388
394
399 static PartitionerPtr instanceFromRbaFile(const boost::filesystem::path&, SerialIo::Format = SerialIo::BINARY);
400
402 void saveAsRbaFile(const boost::filesystem::path &name, SerialIo::Format fmt) const;
403
405 Partitioner(BOOST_RV_REF(Partitioner));
406
409
417
419 void clear();
420
436
454
465 bool addressIsExecutable(rose_addr_t) const;
466
467
470 //
471 // Unparsing
472 //
475public:
504
509
518 std::string unparse(SgAsmInstruction*) const;
519 void unparse(std::ostream&, SgAsmInstruction*) const;
520 void unparse(std::ostream&, const BasicBlockPtr&) const;
521 void unparse(std::ostream&, const DataBlockPtr&) const;
522 void unparse(std::ostream&, const FunctionPtr&) const;
523 void unparse(std::ostream&) const;
529 std::string unparsePlain(SgAsmInstruction*) const;
530
533 //
534 // Partitioner CFG queries
535 //
538public:
544 size_t nBytes() const;
545
553 ControlFlowGraph::VertexIterator undiscoveredVertex();
554 ControlFlowGraph::ConstVertexIterator undiscoveredVertex() const;
567 ControlFlowGraph::VertexIterator indeterminateVertex();
568 ControlFlowGraph::ConstVertexIterator indeterminateVertex() const;
580 ControlFlowGraph::VertexIterator nonexistingVertex();
581 ControlFlowGraph::ConstVertexIterator nonexistingVertex() const;
590 const ControlFlowGraph& cfg() const;
591
598 const AddressUsageMap& aum() const;
599
602
607 std::vector<AddressUser> users(rose_addr_t) const;
608
616 std::set<rose_addr_t> ghostSuccessors() const;
617
646 bool isEdgeIntraProcedural(ControlFlowGraph::ConstEdgeIterator edge, const FunctionPtr&) const;
647 bool isEdgeIntraProcedural(const ControlFlowGraph::Edge &edge, const FunctionPtr&) const;
648 bool isEdgeIntraProcedural(ControlFlowGraph::ConstEdgeIterator edge) const;
649 bool isEdgeIntraProcedural(const ControlFlowGraph::Edge &edge) const;
686 bool isEdgeInterProcedural(ControlFlowGraph::ConstEdgeIterator edge) const;
687 bool isEdgeInterProcedural(ControlFlowGraph::ConstEdgeIterator edge, const FunctionPtr &sourceFunction) const;
688 bool isEdgeInterProcedural(ControlFlowGraph::ConstEdgeIterator edge, const FunctionPtr &sourceFunction,
689 const FunctionPtr &targetFunction) const;
690
691 bool isEdgeInterProcedural(const ControlFlowGraph::Edge &edge) const;
692 bool isEdgeInterProcedural(const ControlFlowGraph::Edge &edge, const FunctionPtr &sourceFunction) const;
693 bool isEdgeInterProcedural(const ControlFlowGraph::Edge &edge, const FunctionPtr &sourceFunction,
694 const FunctionPtr &targetFunction) const;
701 //
702 // Partitioner instruction operations
703 //
706public:
712 size_t nInstructions() const;
713
723 AddressUser instructionExists(rose_addr_t startVa) const;
733 ControlFlowGraph::ConstVertexIterator instructionVertex(rose_addr_t insnVa) const;
734
743 std::vector<SgAsmInstruction*> instructionsOverlapping(const AddressInterval&) const;
744
753 std::vector<SgAsmInstruction*> instructionsSpanning(const AddressInterval&) const;
754
764 std::vector<SgAsmInstruction*> instructionsContainedIn(const AddressInterval&) const;
765
774
787 SgAsmInstruction* discoverInstruction(rose_addr_t startVa) const;
788
794
795
796
799 //
800 // Partitioner basic block placeholder operations
801 //
804public:
814 size_t nPlaceholders() const;
815
824 bool placeholderExists(rose_addr_t startVa) const;
825
836 ControlFlowGraph::VertexIterator findPlaceholder(rose_addr_t startVa);
837 ControlFlowGraph::ConstVertexIterator findPlaceholder(rose_addr_t startVa) const;
856 ControlFlowGraph::VertexIterator insertPlaceholder(rose_addr_t startVa);
857
871 BasicBlockPtr erasePlaceholder(const ControlFlowGraph::ConstVertexIterator &placeholder) /*final*/;
872 BasicBlockPtr erasePlaceholder(rose_addr_t startVa) /*final*/;
879 //
880 // Partitioner basic block operations
881 //
884public:
911
920 size_t nBasicBlocks() const;
921
929 std::vector<BasicBlockPtr> basicBlocks() const;
930
952 BasicBlockPtr basicBlockExists(rose_addr_t startVa) const;
965 std::vector<BasicBlockPtr> basicBlocksOverlapping(const AddressInterval&) const;
966
977 std::vector<BasicBlockPtr> basicBlocksSpanning(const AddressInterval&) const;
978
988 std::vector<BasicBlockPtr> basicBlocksContainedIn(const AddressInterval&) const;
989
997
1008
1015
1040 BasicBlockPtr detachBasicBlock(rose_addr_t startVa);
1042 BasicBlockPtr detachBasicBlock(const ControlFlowGraph::ConstVertexIterator &placeholder);
1056 ControlFlowGraph::VertexIterator truncateBasicBlock(const ControlFlowGraph::ConstVertexIterator &basicBlock,
1057 SgAsmInstruction *insn);
1058
1092 void attachBasicBlock(const ControlFlowGraph::ConstVertexIterator &placeholder, const BasicBlockPtr&);
1180 BasicBlockPtr discoverBasicBlock(rose_addr_t startVa) const;
1181 BasicBlockPtr discoverBasicBlock(const ControlFlowGraph::ConstVertexIterator &placeholder) const;
1199
1208 std::vector<rose_addr_t> basicBlockConcreteSuccessors(const BasicBlockPtr&, bool *isComplete=NULL) const;
1209
1228 std::set<rose_addr_t> basicBlockGhostSuccessors(const BasicBlockPtr&) const;
1229
1239 bool basicBlockIsFunctionCall(const BasicBlockPtr&, Precision::Level precision = Precision::HIGH) const;
1240
1252
1258
1300 basicBlockStackDeltaIn(const BasicBlockPtr&, const FunctionPtr &function) const;
1301
1303 basicBlockStackDeltaOut(const BasicBlockPtr&, const FunctionPtr &function) const;
1314 void forgetStackDeltas() const;
1315 void forgetStackDeltas(const FunctionPtr&) const;
1382 Sawyer::Optional<bool> basicBlockOptionalMayReturn(const ControlFlowGraph::ConstVertexIterator&) const;
1392
1393private:
1394 // Per-vertex data used during may-return analysis
1395 struct MayReturnVertexInfo {
1396 enum State {INIT, CALCULATING, FINISHED};
1397 State state; // current state of vertex
1398 bool processedCallees; // have we processed BBs this vertex calls?
1399 boost::logic::tribool anyCalleesReturn; // do any of those called BBs have a true may-return value?
1400 boost::logic::tribool result; // final result (eventually cached in BB)
1401 MayReturnVertexInfo(): state(INIT), processedCallees(false), anyCalleesReturn(false), result(boost::indeterminate) {}
1402 };
1403
1404 // Is edge significant for analysis? See .C file for full documentation.
1405 bool mayReturnIsSignificantEdge(const ControlFlowGraph::ConstEdgeIterator &edge,
1406 std::vector<MayReturnVertexInfo> &vertexInfo) const;
1407
1408 // Determine (and cache in vertexInfo) whether any callees return.
1409 boost::logic::tribool mayReturnDoesCalleeReturn(const ControlFlowGraph::ConstVertexIterator &vertex,
1410 std::vector<MayReturnVertexInfo> &vertexInfo) const;
1411
1412 // Maximum may-return result from significant successors including phantom call-return edge.
1413 boost::logic::tribool mayReturnDoesSuccessorReturn(const ControlFlowGraph::ConstVertexIterator &vertex,
1414 std::vector<MayReturnVertexInfo> &vertexInfo) const;
1415
1416 // The guts of the may-return analysis
1417 Sawyer::Optional<bool> basicBlockOptionalMayReturn(const ControlFlowGraph::ConstVertexIterator &start,
1418 std::vector<MayReturnVertexInfo> &vertexInfo) const;
1419
1420
1421
1424 //
1425 // Partitioner data block operations
1426 //
1429public:
1435 size_t nDataBlocks() const;
1436
1444
1454
1467
1475
1486
1500
1510 std::vector<DataBlockPtr> dataBlocksOverlapping(const AddressInterval&) const;
1511
1521 std::vector<DataBlockPtr> dataBlocksSpanning(const AddressInterval&) const;
1522
1532 std::vector<DataBlockPtr> dataBlocksContainedIn(const AddressInterval&) const;
1533
1541
1547 std::vector<DataBlockPtr> dataBlocks() const;
1548
1549
1550
1553 //
1554 // Partitioner function operations
1555 //
1558public:
1564 size_t nFunctions() const;
1565
1584 FunctionPtr functionExists(rose_addr_t entryVa) const;
1585 FunctionPtr functionExists(const BasicBlockPtr &entryBlock) const;
1594 std::vector<FunctionPtr> functions() const;
1595
1605 std::vector<FunctionPtr> functionsOverlapping(const AddressInterval&) const;
1606
1617 std::vector<FunctionPtr> functionsSpanning(const AddressInterval&) const;
1618
1628 std::vector<FunctionPtr> functionsContainedIn(const AddressInterval&) const;
1629
1647 void functionExtent(const FunctionPtr &function, AddressIntervalSet &retval /*in,out*/) const;
1649 void functionBasicBlockExtent(const FunctionPtr &function, AddressIntervalSet &retval /*in,out*/) const;
1651 void functionDataBlockExtent(const FunctionPtr &function, AddressIntervalSet &retval /*in,out*/) const;
1691
1726
1732 std::vector<Function::Ptr> entryFunctions();
1733
1768 std::vector<FunctionPtr>
1769 functionsOwningBasicBlock(const ControlFlowGraph::Vertex&, bool doSort = true) const;
1770
1771 std::vector<FunctionPtr>
1772 functionsOwningBasicBlock(const ControlFlowGraph::ConstVertexIterator&, bool doSort = true) const;
1773
1774 std::vector<FunctionPtr>
1775 functionsOwningBasicBlock(rose_addr_t bblockVa, bool doSort = true) const;
1776
1777 std::vector<FunctionPtr>
1778 functionsOwningBasicBlock(const BasicBlockPtr&, bool doSort = true) const;
1779
1780 template<class Container> // container can hold any type accepted by functionsOwningBasicBlock
1781 std::vector<FunctionPtr>
1782 functionsOwningBasicBlocks(const Container &bblocks) const {
1783 std::vector<FunctionPtr> retval;
1784 for (const typename Container::value_type& bblock: bblocks) {
1785 for (const FunctionPtr &function: functionsOwningBasicBlock(bblock, false))
1786 insertUnique(retval, function, sortFunctionsByAddress);
1787 }
1788 return retval;
1789 }
1801 std::vector<FunctionPtr> discoverCalledFunctions() const;
1802
1814 std::vector<FunctionPtr> discoverFunctionEntryVertices() const;
1815
1826
1837 void discoverFunctionBasicBlocks(const FunctionPtr &function) const;
1838
1845 std::set<rose_addr_t> functionGhostSuccessors(const FunctionPtr&) const;
1846
1855
1876
1881
1889
1894
1930 const CallingConvention::Definition::Ptr &dflt) const;
1949
2011 void fixInterFunctionEdge(const ControlFlowGraph::ConstEdgeIterator&);
2031 bool functionIsNoop(const FunctionPtr&) const;
2032
2038 void allFunctionIsNoop() const;
2039
2055 std::set<rose_addr_t> functionDataFlowConstants(const FunctionPtr&) const;
2056
2057
2058
2061 //
2062 // Callbacks
2063 //
2066public:
2100public:
2136 std::vector<FunctionPtr> nextFunctionPrologue(rose_addr_t startVa);
2137 std::vector<FunctionPtr> nextFunctionPrologue(rose_addr_t startVa, rose_addr_t &lastSearchedVa /*out*/);
2140public:
2158
2159
2160
2163 //
2164 // Partitioner miscellaneous
2165 //
2168public:
2180 void dumpCfg(std::ostream&, const std::string &prefix="", bool showBlocks=true, bool computeProperties=true) const;
2181
2195 void cfgGraphViz(std::ostream&, const AddressInterval &restrict = AddressInterval::whole(), bool showNeighbors=true) const;
2196
2202 static std::string vertexName(const ControlFlowGraph::Vertex&);
2203 std::string vertexName(const ControlFlowGraph::ConstVertexIterator&) const;
2209 static std::string vertexNameEnd(const ControlFlowGraph::Vertex&);
2210
2216 static std::string edgeNameSrc(const ControlFlowGraph::Edge&);
2217 std::string edgeNameSrc(const ControlFlowGraph::ConstEdgeIterator&) const;
2225 static std::string edgeNameDst(const ControlFlowGraph::Edge&);
2226 std::string edgeNameDst(const ControlFlowGraph::ConstEdgeIterator&) const;
2234 static std::string edgeName(const ControlFlowGraph::Edge&);
2235 std::string edgeName(const ControlFlowGraph::ConstEdgeIterator&) const;
2241 static std::string basicBlockName(const BasicBlockPtr&);
2242
2246 static std::string dataBlockName(const DataBlockPtr&);
2247
2251 static std::string functionName(const FunctionPtr&);
2252
2258
2284 void updateProgress(const std::string &phase, double completion) const;
2285
2287 void showStatistics() const;
2288
2289 // Checks consistency of internal data structures when debugging is enable (when NDEBUG is not defined).
2290 void checkConsistency() const;
2291
2298
2303
2304
2305
2308 //
2309 // Settings
2310 //
2313public:
2314
2334 void enableSymbolicSemantics(bool = true);
2391 void addressName(rose_addr_t, const std::string&);
2392 const std::string& addressName(rose_addr_t) const;
2421 //
2422 // Instruction semantics
2423 //
2426public:
2447
2471
2472
2473
2476 //
2477 // Python API support functions
2478 //
2481#ifdef ROSE_ENABLE_PYTHON_API
2482 void pythonUnparse() const;
2483#endif
2484
2485
2486
2489 //
2490 // Partitioner internal utilities
2491 //
2494private:
2495 void init(const MemoryMap::Ptr&);
2496 void init(const Partitioner&);
2497 void updateCfgProgress();
2498
2499private:
2500 // Convert a CFG vertex iterator from one partitioner to another. This is called during copy construction when the source
2501 // and destination CFGs are identical.
2502 ControlFlowGraph::VertexIterator convertFrom(const Partitioner &other,
2503 ControlFlowGraph::ConstVertexIterator otherIter);
2504
2505 // Adjusts edges for a placeholder vertex. This method erases all outgoing edges for the specified placeholder vertex and
2506 // then inserts a single edge from the placeholder to the special "undiscovered" vertex. */
2507 ControlFlowGraph::EdgeIterator adjustPlaceholderEdges(const ControlFlowGraph::VertexIterator &placeholder);
2508
2509 // Adjusts edges for a non-existing basic block. This method erases all outgoing edges for the specified vertex and
2510 // then inserts a single edge from the vertex to the special "non-existing" vertex. */
2511 ControlFlowGraph::EdgeIterator adjustNonexistingEdges(const ControlFlowGraph::VertexIterator &vertex);
2512
2513 // Implementation for the discoverBasicBlock methods. The startVa must not be the address of an existing placeholder.
2514 BasicBlockPtr discoverBasicBlockInternal(rose_addr_t startVa) const;
2515
2516 // This method is called whenever a new placeholder is inserted into the CFG or a new basic block is attached to the
2517 // CFG/AUM. The call happens immediately after the CFG/AUM are updated.
2518 void bblockAttached(const ControlFlowGraph::VertexIterator &newVertex);
2519
2520 // This method is called whenever a basic block is detached from the CFG/AUM or when a placeholder is erased from the CFG.
2521 // The call happens immediately after the CFG/AUM are updated.
2522 void bblockDetached(rose_addr_t startVa, const BasicBlockPtr &removedBlock);
2523
2524 // Rebuild the vertexIndex_ and other cache-like data members from the control flow graph
2525 void rebuildVertexIndices();
2526};
2527
2528} // namespace
2529} // namespace
2530} // namespace
2531
2532#endif
2533#endif
Provides and caches instructions.
Partitions instructions into basic blocks and functions.
Sawyer::Container::Map< rose_addr_t, std::string > AddressNameMap
Map address to name.
AddressIntervalSet basicBlockInstructionExtent(const BasicBlockPtr &) const
Returns the addresses used by basic block instructions.
Sawyer::Callbacks< CfgAdjustmentCallback::Ptr > CfgAdjustmentCallbacks
See cfgAdjustmentCallbacks.
const Configuration & configuration() const
Property: Configuration information.
std::vector< FunctionPtr > nextFunctionPrologue(rose_addr_t startVa)
Finds the next function by searching for a function prologue.
ControlFlowGraph::VertexIterator nonexistingVertex()
Returns the special "non-existing" vertex.
ControlFlowGraph::ConstVertexIterator nonexistingVertex() const
Returns the special "non-existing" vertex.
static std::string dataBlockName(const DataBlockPtr &)
Name of a data block.
BasicBlockPtr basicBlockContainingInstruction(rose_addr_t insnVa) const
Returns the basic block that contains a specific instruction address.
bool basicBlockIsFunctionReturn(const BasicBlockPtr &) const
Determine if a basic block looks like a function return.
std::vector< Function::Ptr > entryFunctions()
Entry points of the binary.
std::vector< BasicBlockPtr > basicBlocksContainedIn(const AddressInterval &) const
Returns basic blocks that are fully contained in an address interval.
FunctionPrologueMatchers & functionPrologueMatchers()
Ordered list of function prologue matchers.
ControlFlowGraph::VertexIterator undiscoveredVertex()
Returns the special "undiscovered" vertex.
void basicBlockDropSemantics() const
Immediately drop semantic information for all attached basic blocks.
size_t nDataBlocks() const
Returns the number of data blocks attached to the CFG/AUM.
ControlFlowGraph::ConstVertexIterator indeterminateVertex() const
Returns the special "indeterminate" vertex.
void allFunctionCallingConvention() const
Compute calling conventions for all functions.
InstructionSemantics::BaseSemantics::SValuePtr functionStackDelta(const FunctionPtr &function) const
Stack delta analysis for one function.
void interpretation(SgAsmInterpretation *)
Property: Interpretation corresponding to the memory map.
Unparser::BasePtr unparser() const
Returns an unparser.
void forgetFunctionIsNoop() const
Clears cached function no-op analysis results.
CfgAdjustmentCallbacks & cfgAdjustmentCallbacks()
List of all callbacks invoked when the CFG is adjusted.
Sawyer::Optional< bool > functionOptionalMayReturn(const FunctionPtr &function) const
May-return analysis for one function.
bool addressIsExecutable(rose_addr_t) const
Returns true if address is executable.
std::vector< SgAsmInstruction * > instructionsContainedIn(const AddressInterval &) const
Returns instructions that are fully contained in an address interval.
Sawyer::Optional< bool > basicBlockOptionalMayReturn(const BasicBlockPtr &) const
Determine if part of the CFG can pop the top stack frame.
BasicBlockSuccessors basicBlockSuccessors(const BasicBlockPtr &, Precision::Level precision=Precision::HIGH) const
Determine successors for a basic block.
std::vector< DataBlockPtr > dataBlocksContainedIn(const AddressInterval &) const
Returns data blocks that are fully contained in an address interval.
SemanticMemoryParadigm semanticMemoryParadigm() const
Property: Whether to use map- or list-based memory states.
void allFunctionCallingConvention(const CallingConvention::Definition::Ptr &dflt) const
Compute calling conventions for all functions.
FunctionCallGraph functionCallGraph(AllowParallelEdges::Type allowParallelEdges) const
Returns a function call graph.
SgAsmInstruction * discoverInstruction(rose_addr_t startVa) const
Discover an instruction.
size_t stackDeltaInterproceduralLimit() const
Property: max depth for inter-procedural stack delta analysis.
void stackDeltaInterproceduralLimit(size_t)
Property: max depth for inter-procedural stack delta analysis.
FunctionPtr functionExists(const FunctionPtr &function) const
Determines whether a function exists in the CFG/AUM.
void forgetStackDeltas(const FunctionPtr &) const
Clears all cached stack deltas.
void unparse(std::ostream &, const DataBlockPtr &) const
Unparse some entity.
std::vector< FunctionPtr > functionsOverlapping(const AddressInterval &) const
Returns functions that overlap with specified address interval.
DataBlockPtr matchFunctionPadding(const FunctionPtr &)
Finds function padding.
std::set< rose_addr_t > basicBlockGhostSuccessors(const BasicBlockPtr &) const
Determine ghost successors for a basic block.
void configureInsnPlainUnparser(const Unparser::BasePtr &) const
Configure plain single-instruction unparser.
bool functionIsNoop(const FunctionPtr &) const
Function no-op analysis.
void fixInterFunctionEdge(const ControlFlowGraph::ConstEdgeIterator &)
Adjust inter-function edge types.
ControlFlowGraph::VertexIterator truncateBasicBlock(const ControlFlowGraph::ConstVertexIterator &basicBlock, SgAsmInstruction *insn)
Truncate an attached basic-block.
Sawyer::Optional< Thunk > functionIsThunk(const FunctionPtr &) const
True if function is a thunk.
std::set< rose_addr_t > ghostSuccessors() const
Determine all ghost successors in the control flow graph.
size_t attachFunctionBasicBlocks(const Functions &)
Create placeholders for function basic blocks.
const ControlFlowGraph & cfg() const
Returns the control flow graph.
const CallingConvention::Analysis & functionCallingConvention(const FunctionPtr &, const CallingConvention::Definition::Ptr &dflt) const
Calling convention analysis for one function.
const SourceLocations & sourceLocations() const
Property: Source locations.
Partitioner & operator=(BOOST_RV_REF(Partitioner))
Move assignment.
bool isEdgeInterProcedural(ControlFlowGraph::ConstEdgeIterator edge) const
Determine if an edge is inter-procedural.
void checkingCallBranch(bool)
Property: Whether to look for function calls used as branches.
std::vector< BasicBlockPtr > basicBlocksSpanning(const AddressInterval &) const
Returns basic blocks that span an entire address interval.
Configuration & configuration()
Property: Configuration information.
BasicBlockPtr discoverBasicBlock(rose_addr_t startVa) const
Discover instructions for a detached basic block.
AddressUsageMap aum(const FunctionPtr &) const
Returns the address usage map for a single function.
std::vector< FunctionPaddingMatcherPtr > FunctionPaddingMatchers
See functionPaddingMatchers.
ControlFlowGraph::VertexIterator findPlaceholder(rose_addr_t startVa)
Find the CFG vertex for a basic block placeholder.
bool placeholderExists(rose_addr_t startVa) const
Determines whether a basic block placeholder exists in the CFG.
SgAsmGenericSection * elfGot(SgAsmElfFileHeader *)
Find the ELF global offset table and save its address.
std::vector< DataBlockPtr > dataBlocksSpanning(const AddressInterval &) const
Returns data blocks that span an entire address interval.
DataBlockPtr findBestDataBlock(const AddressInterval &) const
Find an existing data block.
void forgetStackDeltas() const
Clears all cached stack deltas.
void allFunctionStackDelta() const
Compute stack delta analysis for all functions.
bool assumeFunctionsReturn() const
Property: Assume (or not) that function calls return.
static std::string basicBlockName(const BasicBlockPtr &)
Name of a basic block.
void unparse(std::ostream &, const BasicBlockPtr &) const
Unparse some entity.
AddressIntervalSet basicBlockDataExtent(const BasicBlockPtr &) const
Returns the addresses used by basic block data.
size_t nPlaceholders() const
Returns the number of basic basic block placeholders in the CFG.
const std::string & addressName(rose_addr_t) const
Property: Name for address.
AddressIntervalSet functionExtent(const FunctionPtr &) const
Returns the addresses used by a function.
std::vector< BasicBlockPtr > basicBlocks() const
Returns all basic blocks attached to the CFG.
bool isEdgeInterProcedural(const ControlFlowGraph::Edge &edge, const FunctionPtr &sourceFunction) const
Determine if an edge is inter-procedural.
size_t nFunctions() const
Returns the number of functions attached to the CFG/AUM.
std::vector< FunctionPtr > discoverCalledFunctions() const
Scans the CFG to find function calls.
bool isEdgeIntraProcedural(ControlFlowGraph::ConstEdgeIterator edge) const
Determine if an edge is intra-procedural.
FunctionPtr functionExists(rose_addr_t entryVa) const
Determines whether a function exists in the CFG/AUM.
BasicBlockPtr basicBlockExists(const BasicBlockPtr &) const
Determines whether a discovered basic block exists in the CFG/AUM.
void settings(const BasePartitionerSettings &)
Partitioner settings.
bool autoAddCallReturnEdges() const
Property: Insert (or not) function call return edges.
Architecture::BaseConstPtr architecture() const
Property: Architecture information.
void unparse(std::ostream &, SgAsmInstruction *) const
Unparse some entity.
bool isEdgeInterProcedural(const ControlFlowGraph::Edge &edge, const FunctionPtr &sourceFunction, const FunctionPtr &targetFunction) const
Determine if an edge is inter-procedural.
std::string edgeName(const ControlFlowGraph::ConstEdgeIterator &) const
Name of an edge.
void unparse(std::ostream &, const FunctionPtr &) const
Unparse some entity.
void addressName(rose_addr_t, const std::string &)
Property: Name for address.
ControlFlowGraph::VertexIterator indeterminateVertex()
Returns the special "indeterminate" vertex.
bool isEdgeIntraProcedural(const ControlFlowGraph::Edge &edge, const FunctionPtr &) const
Determine if an edge is intra-procedural.
ControlFlowGraph::ConstVertexIterator findPlaceholder(rose_addr_t startVa) const
Find the CFG vertex for a basic block placeholder.
size_t nBytes() const
Returns the number of bytes represented by the CFG.
bool basicBlockIsFunctionCall(const BasicBlockPtr &, Precision::Level precision=Precision::HIGH) const
Determine if a basic block looks like a function call.
void attachBasicBlock(const ControlFlowGraph::ConstVertexIterator &placeholder, const BasicBlockPtr &)
Attach a basic block to the CFG/AUM.
InstructionSemantics::BaseSemantics::RiscOperatorsPtr newOperators(SemanticMemoryParadigm) const
Obtain new RiscOperators.
void basicBlockMayReturnReset() const
Clear all may-return properties.
BasicBlockPtr basicBlockExists(rose_addr_t startVa) const
Determines whether a discovered basic block exists in the CFG/AUM.
void discoverFunctionBasicBlocks(const FunctionPtr &function) const
Adds basic blocks to a function.
const CallingConvention::Analysis & functionCallingConvention(const FunctionPtr &) const
Calling convention analysis for one function.
bool usingSymbolicSemantics() const
Use or not use symbolic semantics.
std::vector< FunctionPtr > functionsOwningBasicBlocks(const Container &bblocks) const
Finds functions that own the specified basic block.
bool checkingCallBranch() const
Property: Whether to look for function calls used as branches.
void cfgGraphViz(std::ostream &, const AddressInterval &restrict=AddressInterval::whole(), bool showNeighbors=true) const
Output CFG as GraphViz.
const BasicBlockCallbacks & basicBlockCallbacks() const
Callbacks for adjusting basic block during discovery.
std::vector< SgAsmInstruction * > instructionsSpanning(const AddressInterval &) const
Returns instructions that span an entire address interval.
static std::string functionName(const FunctionPtr &)
Name of a function.
std::vector< FunctionPtr > functionsOwningBasicBlock(const BasicBlockPtr &, bool doSort=true) const
Finds functions that own the specified basic block.
void expandIndeterminateCalls()
Expands indeterminate function calls.
ControlFlowGraph::ConstVertexIterator instructionVertex(rose_addr_t insnVa) const
Returns the CFG vertex containing specified instruction.
void unparse(std::ostream &) const
Unparse some entity.
bool isEdgeIntraProcedural(const ControlFlowGraph::Edge &edge) const
Determine if an edge is intra-procedural.
DataBlockPtr attachDataBlock(const DataBlockPtr &)
Attach a data block to the CFG/AUM.
size_t attachFunctionBasicBlocks(const FunctionPtr &)
Create placeholders for function basic blocks.
void dumpCfg(std::ostream &, const std::string &prefix="", bool showBlocks=true, bool computeProperties=true) const
Output the control flow graph.
InstructionSemantics::BaseSemantics::RiscOperatorsPtr newOperators() const
Obtain new RiscOperators.
void assumeFunctionsReturn(bool)
Property: Assume (or not) that function calls return.
std::set< rose_addr_t > functionGhostSuccessors(const FunctionPtr &) const
Returns ghost successors for a single function.
DataBlockPtr dataBlockExists(const DataBlockPtr &) const
Determine if a data block or its equivalent is attached to the CFG/AUM.
DataBlockPtr attachDataBlockToBasicBlock(const DataBlockPtr &, const BasicBlockPtr &)
Attach a data block to a basic block.
bool basicBlockSemanticsAutoDrop() const
Property: Automatically drop semantics for attached basic blocks.
std::vector< DataBlockPtr > dataBlocksOverlapping(const AddressInterval &) const
Returns data blocks that overlap with specified address interval.
Partitioner(BOOST_RV_REF(Partitioner))
Move constructor.
BasicBlockPtr detachBasicBlock(const BasicBlockPtr &basicBlock)
Detach a basic block from the CFG/AUM.
InstructionSemantics::BaseSemantics::DispatcherPtr newDispatcher(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &) const
Obtain a new instruction semantics dispatcher.
std::vector< BasicBlockPtr > basicBlocksOverlapping(const AddressInterval &) const
Returns basic blocks that overlap with specified address interval.
void attachBasicBlock(const BasicBlockPtr &)
Attach a basic block to the CFG/AUM.
SgAsmInterpretation * interpretation() const
Property: Interpretation corresponding to the memory map.
ControlFlowGraph::VertexIterator insertPlaceholder(rose_addr_t startVa)
Insert a basic-block placeholder.
std::string unparsePlain(SgAsmInstruction *) const
Unparse an instruction in a plain way.
Progress::Ptr progress() const
Property: How to report progress.
void detachFunction(const FunctionPtr &)
Detaches a function from the CFG/AUM.
Sawyer::Optional< rose_addr_t > elfGotVa() const
Returns a previously cached ELF GOT address.
static std::string vertexNameEnd(const ControlFlowGraph::Vertex &)
Name of last instruction in vertex.
void insnUnparser(const Unparser::BasePtr &)
Returns an unparser.
void detachDataBlock(const DataBlockPtr &)
Detaches a data block from the CFG/AUM.
std::string vertexName(const ControlFlowGraph::ConstVertexIterator &) const
Name of a vertex.
void showStatistics() const
Print some partitioner performance statistics.
static Ptr instance(const Architecture::BaseConstPtr &)
Default allocating constructor.
void disableSymbolicSemantics()
Use or not use symbolic semantics.
std::vector< rose_addr_t > basicBlockConcreteSuccessors(const BasicBlockPtr &, bool *isComplete=NULL) const
Determines concrete successors for a basic block.
const AddressUsageMap & aum() const
Returns the address usage map.
std::vector< FunctionPtr > functions() const
All functions attached to the CFG/AUM.
void saveAsRbaFile(const boost::filesystem::path &name, SerialIo::Format fmt) const
Save this partitioner as an RBA file.
BasicBlockPtr erasePlaceholder(const ControlFlowGraph::ConstVertexIterator &placeholder)
Remove a basic block placeholder from the CFG/AUM.
void progress(const Progress::Ptr &)
Property: How to report progress.
std::vector< FunctionPtr > functionsSpanning(const AddressInterval &) const
Returns functions that span an entire address interval.
std::vector< SgAsmInstruction * > instructionsOverlapping(const AddressInterval &) const
Returns instructions that overlap with specified address interval.
void enableSymbolicSemantics(bool=true)
Use or not use symbolic semantics.
const FunctionPrologueMatchers & functionPrologueMatchers() const
Ordered list of function prologue matchers.
size_t nInstructions() const
Returns the number of instructions attached to the CFG/AUM.
void unparser(const Unparser::BasePtr &)
Returns an unparser.
static Ptr instance(const Architecture::BaseConstPtr &, const MemoryMap::Ptr &)
Construct a partitioner.
void autoAddCallReturnEdges(bool)
Property: Insert (or not) function call return edges.
InstructionSemantics::BaseSemantics::SValuePtr basicBlockStackDeltaOut(const BasicBlockPtr &, const FunctionPtr &function) const
Return the stack delta expression.
void clear()
Reset CFG/AUM to initial state.
BasicBlockPtr discoverBasicBlock(const ControlFlowGraph::ConstVertexIterator &placeholder) const
Discover instructions for a detached basic block.
std::vector< FunctionPtr > nextFunctionPrologue(rose_addr_t startVa, rose_addr_t &lastSearchedVa)
Finds the next function by searching for a function prologue.
bool isDefaultConstructed() const
Return true if this is a default constructed partitioner.
void allFunctionMayReturn() const
Compute may-return analysis for all functions.
std::vector< FunctionPrologueMatcherPtr > FunctionPrologueMatchers
See functionPrologueMatchers.
Unparser::BasePtr insnUnparser() const
Returns an unparser.
SmtSolverPtr smtSolver() const
SMT solver.
std::vector< FunctionPtr > functionsOwningBasicBlock(const ControlFlowGraph::Vertex &, bool doSort=true) const
Finds functions that own the specified basic block.
bool isEdgeIntraProcedural(ControlFlowGraph::ConstEdgeIterator edge, const FunctionPtr &) const
Determine if an edge is intra-procedural.
BasicBlockPtr detachBasicBlock(rose_addr_t startVa)
Detach a basic block from the CFG/AUM.
FunctionPtr attachOrMergeFunction(const FunctionPtr &)
Attaches or merges a function into the CFG/AUM.
DataBlockPtr attachDataBlockToFunction(const DataBlockPtr &, const FunctionPtr &)
Attach a data block to an attached or detached function.
size_t attachFunctions(const Functions &)
Attaches a function to the CFG/AUM.
BasicBlockPtr detachBasicBlock(const ControlFlowGraph::ConstVertexIterator &placeholder)
Detach a basic block from the CFG/AUM.
void functionBasicBlockExtent(const FunctionPtr &function, AddressIntervalSet &retval) const
Returns the addresses used by a function.
size_t nBasicBlocks() const
Returns the number of basic blocks attached to the CFG/AUM.
const AddressNameMap & addressNames() const
Property: Name for address.
AddressUser instructionExists(rose_addr_t startVa) const
Determines whether an instruction is attached to the CFG/AUM.
std::string edgeNameDst(const ControlFlowGraph::ConstEdgeIterator &) const
Name of an outgoing edge.
void configureInsnUnparser(const Unparser::BasePtr &) const
Configure the single-instruction unparser.
CallingConvention::Dictionary functionCallingConventionDefinitions(const FunctionPtr &) const
Return list of matching calling conventions.
bool basicBlockPopsStack(const BasicBlockPtr &) const
Determine if the basic block pops at least one byte from the stack.
std::set< rose_addr_t > functionDataFlowConstants(const FunctionPtr &) const
Find constants in function using data-flow.
std::vector< FunctionPtr > functionsOwningBasicBlock(const ControlFlowGraph::ConstVertexIterator &, bool doSort=true) const
Finds functions that own the specified basic block.
void fixInterFunctionEdges()
Adjust inter-function edge types.
void allFunctionIsNoop() const
Analyze all functions for whether they are effectivly no-ops.
std::vector< FunctionPtr > functionsOwningBasicBlock(rose_addr_t bblockVa, bool doSort=true) const
Finds functions that own the specified basic block.
BasicBlockPtr erasePlaceholder(rose_addr_t startVa)
Remove a basic block placeholder from the CFG/AUM.
std::vector< DataBlockPtr > dataBlocks() const
Returns the list of all attached data blocks.
void functionDataBlockExtent(const FunctionPtr &function, AddressIntervalSet &retval) const
Returns the addresses used by a function.
bool isEdgeInterProcedural(ControlFlowGraph::ConstEdgeIterator edge, const FunctionPtr &sourceFunction, const FunctionPtr &targetFunction) const
Determine if an edge is inter-procedural.
const FunctionPaddingMatchers & functionPaddingMatchers() const
Ordered list of function padding matchers.
std::string edgeNameSrc(const ControlFlowGraph::ConstEdgeIterator &) const
Name of an incoming edge.
static std::string vertexName(const ControlFlowGraph::Vertex &)
Name of a vertex.
void semanticMemoryParadigm(SemanticMemoryParadigm)
Property: Whether to use map- or list-based memory states.
BasicBlockCallbacks & basicBlockCallbacks()
Callbacks for adjusting basic block during discovery.
FunctionPtr functionExists(const BasicBlockPtr &entryBlock) const
Determines whether a function exists in the CFG/AUM.
AddressIntervalSet functionDataBlockExtent(const FunctionPtr &function) const
Returns the addresses used by a function.
InstructionProvider & instructionProvider()
Returns the instruction provider.
Sawyer::Callbacks< BasicBlockCallbackPtr > BasicBlockCallbacks
See basicBlockCallbacks.
void sourceLocations(const SourceLocations &)
Property: Source locations.
size_t attachFunction(const FunctionPtr &)
Attaches a function to the CFG/AUM.
void forgetFunctionIsNoop(const FunctionPtr &) const
Clears cached function no-op analysis results.
static std::string edgeName(const ControlFlowGraph::Edge &)
Name of an edge.
static std::string edgeNameDst(const ControlFlowGraph::Edge &)
Name of an outgoing edge.
const CfgAdjustmentCallbacks & cfgAdjustmentCallbacks() const
List of all callbacks invoked when the CFG is adjusted.
void functionExtent(const FunctionPtr &function, AddressIntervalSet &retval) const
Returns the addresses used by a function.
AddressInterval instructionExtent(SgAsmInstruction *) const
Returns the address interval for an instruction.
void basicBlockSemanticsAutoDrop(bool)
Property: Automatically drop semantics for attached basic blocks.
MemoryMap::Ptr memoryMap() const
Returns the memory map.
CrossReferences instructionCrossReferences(const AddressIntervalSet &restriction) const
Cross references.
bool isEdgeInterProcedural(ControlFlowGraph::ConstEdgeIterator edge, const FunctionPtr &sourceFunction) const
Determine if an edge is inter-procedural.
std::vector< FunctionPtr > functionsContainedIn(const AddressInterval &) const
Returns functions that are fully contained in an address interval.
std::vector< FunctionPtr > discoverFunctionEntryVertices() const
Scans the CFG to find function entry basic blocks.
void allFunctionCallingConventionDefinition(const CallingConvention::Definition::Ptr &) const
Analyzes calling conventions and saves results.
SourceLocations & sourceLocations()
Property: Source locations.
bool isEdgeInterProcedural(const ControlFlowGraph::Edge &edge) const
Determine if an edge is inter-procedural.
std::vector< AddressUser > users(rose_addr_t) const
Entities that exist at a particular address.
AddressIntervalSet functionBasicBlockExtent(const FunctionPtr &function) const
Returns the addresses used by a function.
const InstructionProvider & instructionProvider() const
Returns the instruction provider.
FunctionPaddingMatchers & functionPaddingMatchers()
Ordered list of function padding matchers.
Sawyer::Optional< bool > basicBlockOptionalMayReturn(const ControlFlowGraph::ConstVertexIterator &) const
Determine if part of the CFG can pop the top stack frame.
const BasePartitionerSettings & settings() const
Partitioner settings.
static std::string edgeNameSrc(const ControlFlowGraph::Edge &)
Name of an incoming edge.
ControlFlowGraph::ConstVertexIterator undiscoveredVertex() const
Returns the special "undiscovered" vertex.
std::string unparse(SgAsmInstruction *) const
Unparse some entity.
void updateProgress(const std::string &phase, double completion) const
Update partitioner with a new progress report.
CallingConvention::Dictionary functionCallingConventionDefinitions(const FunctionPtr &, const CallingConvention::Definition::Ptr &) const
Return list of matching calling conventions.
void allFunctionCallingConventionDefinition() const
Analyzes calling conventions and saves results.
AddressInterval dataBlockExtent(const DataBlockPtr &) const
Returns the addresses used by a data block.
static PartitionerPtr instanceFromRbaFile(const boost::filesystem::path &, SerialIo::Format=SerialIo::BINARY)
Construct a partitioner by loading it and an AST from a file.
InstructionSemantics::BaseSemantics::SValuePtr basicBlockStackDeltaIn(const BasicBlockPtr &, const FunctionPtr &function) const
Return the stack delta expression.
AddressUser instructionExists(SgAsmInstruction *insn) const
Determines whether an instruction is attached to the CFG/AUM.
Format
Format of the state file.
Definition SerialIo.h:120
Bidirectional mapping between addresses and source locations.
API and storage for attributes.
Definition Attribute.h:215
Container associating values with keys.
Definition Sawyer/Map.h:72
Holds a value or nothing.
Definition Optional.h:56
Creates SharedPointer from this.
Base class for reference counted objects.
Reference-counting intrusive smart pointer.
Represents the file header of an ELF binary container.
Contiguous region of a file.
Base class for machine instructions.
Represents an interpretation of a binary container.
std::shared_ptr< const Base > BaseConstPtr
Reference counted pointer for Architecture::Base.
std::vector< DefinitionPtr > Dictionary
An ordered collection of calling convention definitions.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
std::vector< BasicBlockSuccessor > BasicBlockSuccessors
All successors in no particular order.
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.
The ROSE library.
Represents information about a thunk.
rose_addr_t target
The one and only successor for the basic block.
BasicBlockPtr bblock
The one and only basic block for the thunk.