ROSE 0.11.145.293
Rose/BinaryAnalysis/Partitioner2/BasicTypes.h
1#ifndef ROSE_BinaryAnalysis_Partitioner2_BasicTypes_H
2#define ROSE_BinaryAnalysis_Partitioner2_BasicTypes_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/AddressInterval.h>
7
8#include <Sawyer/Graph.h>
9#include <Sawyer/Map.h>
10#include <Sawyer/Set.h>
11#include <Sawyer/SharedPointer.h>
12
13#include <boost/filesystem.hpp>
14#include <boost/regex.hpp>
15#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
16#include <boost/serialization/access.hpp>
17#endif
18
19#include <set>
20#include <string>
21#include <vector>
22
23// Define this as one if you want extra invariant checks that are quite expensive, or define as zero. This only makes a
24// difference if NDEBUG and SAWYER_NDEBUG are both undefined--if either one of them are defined then no expensive (or
25// inexpensive) checks are performed.
26#define ROSE_PARTITIONER_EXPENSIVE_CHECKS 0
27
28namespace Rose {
29namespace BinaryAnalysis {
30namespace Partitioner2 {
31
33namespace Precision {
34enum Level {
35 LOW,
37 HIGH
39};
40} // namespace
41
43namespace AllowParallelEdges {
44enum Type {
46 YES
47};
48} // namespace
49
60
63 E_NORMAL = 0x00000001,
64 E_FUNCTION_CALL = 0x00000002,
65 E_FUNCTION_RETURN = 0x00000004,
68 E_CALL_RETURN = 0x00000008,
74 E_FUNCTION_XFER = 0x00000010,
80 E_USER_DEFINED = 0x00000020,
83};
84
90
96
106
113
121
134
135#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
136private:
137 friend class boost::serialization::access;
138 template<class S> void serialize(S&, unsigned version);
139#endif
140
141public:
148 s.allowEmptyGlobalBlock = false;
150 s.allowEmptyBasicBlocks = false;
151 s.copyAllInstructions = true;
152 return s;
153 }
154
162 s.allowEmptyGlobalBlock = true;
164 s.allowEmptyBasicBlocks = true;
165 s.copyAllInstructions = true; // true keeps the AST a tree instead of a lattice
166 return s;
167 }
168};
169
171// Settings. All settings must act like properties, which means the following:
172// 1. Each setting must have a name that does not begin with a verb.
173// 2. Each setting must have a command-line switch to manipulate it.
174// 3. Each setting must have a method that queries the property (same name as the property and taking no arguments).
175// 4. Each setting must have a modifier method (same name as property but takes a value and returns void)
177
190
222
229 bool memoryIsExecutable = false;
230
238 bool linkObjectFiles = true;
239
248
259 std::string linker = "ld -o %o --unresolved-symbols=ignore-all --whole-archive %f";
260
265 std::vector<std::string> envEraseNames;
266
271 std::vector<boost::regex> envErasePatterns;
272
278 std::vector<std::string> envInsert;
279
280#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
281private:
282 friend class boost::serialization::access;
283 template<class S> void serialize(S&, unsigned version);
284#endif
285};
286
295 bool doDisassemble = true;
296
302 std::string isaName;
303
304#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
305private:
306 friend class boost::serialization::access;
307 template<class S> void serialize(S&, unsigned version);
308#endif
309};
310
322
331 bool usingSemantics = false;
332
336 bool checkingCallBranch = false;
337
348
356
357#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
358private:
359 friend class boost::serialization::access;
360 template<class S> void serialize(S&, unsigned version);
361#endif
362};
363
374
379 std::vector<Address> functionStartingVas;
380
406
413
420
427 std::vector<Address> ipRewrites;
428
434
441 bool findingDeadCode = true;
442
448
455
461
467
473
478
484
490
496
502
508
513 bool doingPostAnalysis = true;
514
519
524
529
535
541
553
559
565
571 bool findingThunks = true;
572
577 bool splittingThunks = false;
578
584
593
600
605 bool namingSyscalls = true;
606
613 boost::filesystem::path syscallHeader;
614
619 bool demangleNames = true;
620
627 bool naiveJumpTables = true;
628
629#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
630private:
631 friend class boost::serialization::access;
632 template<class S> void serialize(S&, unsigned version);
633#endif
634};
635
636namespace IndirectControlFlow {
638 struct Settings {
642 bool enabled = false;
643
649 size_t maxReversePathLength = 10;
650
655 size_t maxInliningDepth = 1;
656
663 size_t maxDataflowIterationFactor = 2;
664
669 size_t maxDataflowVertices = 50;
670
675 size_t maxDataflowSetSize = 10;
676
680 size_t maxSymbolicExprSize = 10000;
681
687 bool reanalyzeSomeBlocks = true;
688
690 Sawyer::Optional<Address> debugAddress;
691 };
692} // namespace
693
694
703 std::vector<std::string> configurationNames;
704
711 bool exitOnError = true;
712
713#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
714private:
715 friend class boost::serialization::access;
716 template<class S> void serialize(S&, unsigned version);
717#endif
718};
719
727 std::vector<std::string> classPath;
728
732 bool loadAllClasses = false;
733
734#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
735private:
736 friend class boost::serialization::access;
737 template<class S> void serialize(S&, unsigned version);
738#endif
739};
740
741// Additional declarations incomplete definitions.
742class AddressUser;
743class AddressUsers;
744class AddressUsageMap;
745
746class BasicBlock;
749class BasicBlockError;
750
755using BasicBlockSuccessors = std::vector<BasicBlockSuccessor>;
758
759class CfgEdge;
760
761class CfgVertex;
762
765class Configuration;
766
767class DataBlock;
770class DataBlockError;
771
772class Engine;
774
775class EngineBinary;
777
778class EngineJvm;
780
781class Exception;
782
783class Function;
789
798class FunctionError;
799
800class JumpTable;
801using JumpTablePtr = std::shared_ptr<JumpTable>;
802using JumpTableConstPtr = std::shared_ptr<const JumpTable>;
804class MemoryTable;
805using MemoryTablePtr = std::shared_ptr<MemoryTable>;
806using MemoryTableConstPtr = std::shared_ptr<const MemoryTable>;
808class Partitioner;
812class PlaceholderError;
813
814class Reference;
815using ReferenceSet = std::set<Reference>;
818class ThunkPredicates;
821} // namespace
822} // namespace
823} // namespace
824
825#endif
826#endif
Base class for adjusting basic blocks during discovery.
Definition Modules.h:39
Engine for specimens containing machine instructions.
Engine for Java Virtual Machine (JVM) specimens.
Definition EngineJvm.h:21
Base class for engines driving the partitioner.
Base class for matching function padding.
Definition Modules.h:134
Base class for matching function prologues.
Definition Modules.h:108
Utilities for working with jump tables.
Definition JumpTable.h:15
Utilities for working with tables.
Definition MemoryTable.h:18
Partitions instructions into basic blocks and functions.
Reference to a function, basic block, instruction, or address.
Definition Reference.h:25
static Interval hull(Address v1, Address v2)
Construct an interval from two endpoints.
Definition Interval.h:162
static Interval whole()
Construct an interval that covers the entire domain.
Definition Interval.h:191
Holds a value or nothing.
Definition Optional.h:56
bool reanalyzeSomeBlocks(const Settings &, const PartitionerPtr &)
Reanalyze all basic blocks that have indirect control flow.
MemoryDataAdjustment
How the partitioner should globally treat memory.
@ DATA_NO_CHANGE
Do not make any global changes to the memory map.
@ DATA_IS_INITIALIZED
Treat all memory as if it were initialized.
@ DATA_IS_CONSTANT
Treat all memory as if it were constant.
std::shared_ptr< MemoryTable > MemoryTablePtr
Shared-ownership pointer for MemoryTable.
std::shared_ptr< const JumpTable > JumpTableConstPtr
Shared-ownership pointer for JumpTable.
std::shared_ptr< JumpTable > JumpTablePtr
Shared-ownership pointer for JumpTable.
std::shared_ptr< const MemoryTable > MemoryTableConstPtr
Shared-ownership pointer for MemoryTable.
std::vector< BasicBlockSuccessor > BasicBlockSuccessors
All successors in no particular order.
@ E_CALL_RETURN
Edge is a function return from the call site.
@ E_NORMAL
Normal control flow edge, nothing special.
@ ASSUMED
The value is an assumption without any proof.
FunctionReturnAnalysis
Controls whether the function may-return analysis runs.
@ MAYRETURN_ALWAYS_NO
Assume that a function cannot return without ever running the may-return analysis.
@ MAYRETURN_DEFAULT_YES
Assume a function returns if the may-return analysis cannot decide whether it may return.
@ MAYRETURN_ALWAYS_YES
Assume that all functions return without ever running the may-return analysis.
@ MAYRETURN_DEFAULT_NO
Assume a function cannot return if the may-return analysis cannot decide whether it may return.
@ V_BASIC_BLOCK
A basic block or placeholder for a basic block.
@ V_INDETERMINATE
Special vertex destination for indeterminate edges.
@ V_NONEXISTING
Special vertex destination for non-existing basic blocks.
std::uint64_t Address
Address.
Definition Address.h:11
The ROSE library.
bool allowFunctionWithNoBasicBlocks
Whether to allow functions with no basic blocks.
static AstConstructionSettings permissive()
Default permissive settings.
bool checkingCallBranch
Whether to look for function calls used as branches.
bool basicBlockSemanticsAutoDrop
Whether to automatically drop semantics for attached basic blocks.
std::vector< std::string > configurationNames
Configuration files names.
std::vector< boost::regex > envErasePatterns
Patterns to erase from the environment.
bool memoryIsExecutable
Whether all of memory should be made executable.
MemoryDataAdjustment memoryDataAdjustment
How to globally adjust memory segment access bits for data areas.
size_t deExecuteZerosLeaveAtFront
When to remove execute permission from zero bytes.
std::vector< std::string > envInsert
Environment variables to insert.
bool linkStaticArchives
Whether to link library archives before parsing.
size_t deExecuteZerosThreshold
When to remove execute permission from zero bytes.
size_t deExecuteZerosLeaveAtBack
When to remove execute permission from zero bytes.
std::vector< std::string > envEraseNames
Names to erase from the environment.
bool findingSymbolFunctions
Whether to make functions according to symbol tables.
std::vector< Address > functionStartingVas
Starting addresses for disassembly.
bool doingPostFunctionStackDelta
Whether to run the function stack delta analysis.
size_t functionReturnAnalysisMaxSorts
Maximum number of function may-return sorting operations.
bool splittingThunks
Whether to split thunk instructions into mini functions.
bool findingDataFunctionPointers
Whether to search static data for function pointers.
SemanticMemoryParadigm semanticMemoryParadigm
Type of container for semantic memory.
bool findingEntryFunctions
Whether to make functions at program entry points.
AddressInterval interruptVector
Property: Location of machine interrupt vector.
FunctionReturnAnalysis functionReturnAnalysis
How to run the function may-return analysis.
bool doingPostFunctionMayReturn
Whether to run the function may-return analysis.
bool doingPostAnalysis
Whether to perform any post-partitioning analysis steps.
bool findingInterFunctionCalls
Whether to search for function calls between exiting functions.
bool findingCodeFunctionPointers
Whether to search existing instructions for function pointers.
bool findingFunctionCallFunctions
Whether to turn function call targets into functions.
boost::filesystem::path syscallHeader
Header file in which system calls are defined.