ROSE  0.9.9.139
sageInterfaceAsm.h
1 #ifndef ROSE_SAGE_INTERFACE_ASM
2 #define ROSE_SAGE_INTERFACE_ASM
3 
4 // These functions in this file are expected to become a part of the
5 // Binary Analysis and Transformation interfaces in the new ROSE API.
6 
7 namespace SageInterface
8  {
9  // DQ (4/26/2010): Added this file of functions to support binary analysis work.
10 
11  void addComment(SgAsmStatement* stmt, const std::string & input_string );
12 
13  SgAsmElfSection* getSection ( SgProject* project, const std::string & name );
14 
15  // Simple way to get the section that that a pointer points into (if any).
16  SgAsmElfSection* getSection ( SgProject* project, size_t ptr );
17 
19  SgAsmFunction* getAsmFunction ( SgAsmInstruction* asmInstruction );
20 
22  SgAsmBlock* getAsmBlock ( SgAsmInstruction* asmInstruction );
23 
26 
27  std::string generateUniqueName ( size_t value, std::map<size_t,int> & usedOffsets, size_t & counter );
28 
29  size_t get_value ( SgAsmValueExpression* asmValueExpression );
30  std::string get_valueString( SgAsmValueExpression* asmValueExpression );
31 
32  bool isMovInstruction ( SgAsmInstruction* asmInstruction );
33 
34  bool isInstructionKind ( SgAsmInstruction* asmInstruction, X86InstructionKind instuctionKind );
35 
36  typedef bool (*EquivalenceTestFunctionType) (SgNode* x, SgNode* y);
37 
38  // Definition of object equivalence for purposes of the AST matching using for instruction recognition.
39  bool equivalenceTest(SgNode* x, SgNode* y);
40 
41  // These functions are used internally within the find function.
42  std::vector<SgNode*> flattenAST ( SgNode* node );
43  std::vector<SgNode*> matchAST ( SgNode* node, std::vector<SgNode*> & listOfNodes, EquivalenceTestFunctionType equivalenceTest );
44 
45  // General function to find matching target AST in larger AST.
46  // SgNode* find ( SgNode* astNode, SgNode* target, EquivalenceTestFunctionType equivalenceTest );
47  std::vector<SgNode*> find ( SgNode* astNode, SgNode* target, EquivalenceTestFunctionType equivalenceTest );
48 
49  // DQ (4/28/2010): Added support for interface to detect NOP's in all their glory.
51  // bool isNOP ( const SgAsmInstruction* asmInstruction );
52  bool isNOP ( SgAsmInstruction* asmInstruction );
54  bool isNOP ( const std::vector<SgAsmInstruction*> & asmInstructionList );
56  std::vector<std::vector<SgAsmInstruction*> > find_NOP_sequences ( SgAsmBlock* asmBlock );
57 
58  // DQ (5/1/2010): We need a whole set of interface functions similar to this.
60  void insertInstruction(SgAsmInstruction* targetInstruction, SgAsmInstruction* newInstruction, bool insertBefore);
61 
63  void insertInstructionBefore(SgAsmInstruction* targetInstruction, SgAsmInstruction* newInstruction);
64 
66  void removeInstruction(SgAsmStatement* instruction);
67 
68  }
69 
70 // endif for ROSE_SAGE_INTERFACE_ASM
71 #endif
SgAsmFunction * getAsmFunction(SgAsmInstruction *asmInstruction)
Traverses AST backwards up the tree along the "parent" edges to the SgAsmFunction.
std::string generateUniqueName(const SgNode *node, bool ignoreDifferenceBetweenDefiningAndNondefiningDeclarations)
Generate unique name from C and C++ constructs. The name may contain space.
Instruction basic block.
Base class for all binary analysis IR nodes.
void insertInstruction(SgAsmInstruction *targetInstruction, SgAsmInstruction *newInstruction, bool insertBefore)
Support for insertion of instruction relative to a target instruction.
Base class for machine instructions.
std::vector< std::vector< SgAsmInstruction * > > find_NOP_sequences(SgAsmBlock *asmBlock)
find sequences of NOP instructions in a SgAsmBlock
SgAsmBlock * getAsmBlock(SgAsmInstruction *asmInstruction)
Traverses AST backwards up the tree along the "parent" edges to the SgAsmBlock.
Base class for ELF file sections.
Represents a synthesized function.
Functions that are useful when operating on the AST.
Definition: sageBuilder.h:25
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:8322
SgAsmInterpretation * getAsmInterpretation(SgAsmNode *asmNode)
Traverses AST backwards up the tree along the "parent" edges to the SgAsmInterpretation.
bool isNOP(SgAsmInstruction *asmInstruction)
Test an instruction for if it has no side-effect to the state (is so then it is a NOP)...
Base class for values.
This class represents a source project, with a list of SgFile objects and global information about th...
void insertInstructionBefore(SgAsmInstruction *targetInstruction, SgAsmInstruction *newInstruction)
Insert a instruction before a target instruction.
Represents an interpretation of a binary container.
void removeInstruction(SgAsmStatement *instruction)
Remove a instruction.