|
decompiler 1.0.0
|
Context maintained while parsing a single instruction. More...
#include <context.hh>
Public Types | |
| enum | parse_state { uninitialized = 0 , disassembly = 1 , pcode = 2 } |
| Possible states of the ParserContext. More... | |
Public Member Functions | |
| ParserContext (ContextCache *ccache, Translate *trans) | |
| Constructor. More... | |
| ~ParserContext (void) | |
| Destructor. | |
| uint1 * | getBuffer (void) |
| Get bytes in the stream at the point this instruction is encoded. | |
| void | initialize (AddrSpace *spc, int4 maxstate=INITIAL_STATE_NUM) |
| Preallocate nodes for constructor trees. More... | |
| parse_state | getParserState (void) const |
| Get the overall state of the parse. | |
| void | setParserState (parse_state st) |
| Update the overall parse state. | |
| void | deallocateState (ParserWalkerChange &walker) |
| Clear any existing constructor tree. More... | |
| void | allocateOperand (int4 i, ParserWalkerChange &walker) |
| Allocate a new child node in the constructor tree. More... | |
| void | setAddr (const Address &ad) |
| Set the starting address of the instruction. | |
| void | setNaddr (const Address &ad) |
| Set the ending address of the instruction. | |
| void | setCalladdr (const Address &ad) |
| Set the address of the call being overridden. | |
| void | addCommit (TripleSymbol *sym, int4 num, uintm mask, bool flow, ConstructState *point) |
| Add a formal SLEIGH context change command. More... | |
| void | clearCommits (void) |
| Clear all context commits. | |
| void | applyCommits (void) |
| Apply any pending commits to the context cache. | |
| const Address & | getAddr (void) const |
| Get the starting address of the current instruction. | |
| const Address & | getNaddr (void) const |
| Get the address of the next instruction. | |
| const Address & | getN2addr (void) const |
| Get the address of the instruction after the next. | |
| const Address & | getDestAddr (void) const |
| Get the destination address (inst_dest) for the overriden call. | |
| const Address & | getRefAddr (void) const |
| Get the reference address (inst_ref) for the p-code snippet. | |
| AddrSpace * | getCurSpace (void) const |
| Get the address space of the current instruction. | |
| AddrSpace * | getConstSpace (void) const |
| Get the address space for constants. | |
| uintm | getInstructionBytes (int4 byteoff, int4 numbytes, uint4 off) const |
| Get the specified instruction bytes. More... | |
| uintm | getContextBytes (int4 byteoff, int4 numbytes) const |
| Get bytes from the local context. More... | |
| uintm | getInstructionBits (int4 startbit, int4 size, uint4 off) const |
| Get the specific range of bits from the instruction stream. More... | |
| uintm | getContextBits (int4 startbit, int4 size) const |
| Get the specific range of bits from the local context. More... | |
| void | setContextWord (int4 i, uintm val, uintm mask) |
| Modify a context word, using given mask and value. | |
| void | loadContext (void) |
| Pull context words associated with the starting address into the local array. | |
| int4 | getLength (void) const |
| Get the length of the current instruction. | |
| void | setDelaySlot (int4 val) |
| Set (the number of instruction bytes) in the delay slot. | |
| int4 | getDelaySlot (void) const |
| Get the number of instruction bytes in the delay slot. | |
| void | expandState (int4 amount) |
| Expand the number of available nodes for the constructor tree. More... | |
Static Public Attributes | |
| static constexpr int4 | MAX_DEPTH = 32 |
| Maximum subconstructor depth in a single instruction. | |
| static constexpr int4 | MAX_OPERAND = 20 |
| Maximum operands for a single constructor. | |
| static constexpr int4 | MAX_INSTRUCTION_LEN = 16 |
| Maximum number of bytes in a single instruction. | |
| static constexpr int4 | INITIAL_STATE_NUM = 64 |
| Recommended number of initial states. | |
| static constexpr int4 | STATE_GROWTH = 64 |
Private Attributes | |
| Translate * | translate |
| The parent instruction parser. | |
| parse_state | parsestate |
| Overall state of the parse. | |
| AddrSpace * | const_space |
| Address space for constants. | |
| uint1 | buf [MAX_INSTRUCTION_LEN] |
| Buffer of bytes in the instruction stream. | |
| uintm * | context |
| Pointer to local context. | |
| int4 | contextsize |
| Number of entries in local context array. | |
| ContextCache * | contcache |
| Interface for getting/setting context. | |
| vector< ContextSet > | contextcommit |
| Changes to SLEIGH context slated by this instruction. | |
| Address | addr |
| Address of start of instruction. | |
| Address | naddr |
| Address of next instruction. | |
| Address | n2addr |
| Address of instruction after the next. | |
| Address | calladdr |
| For injections, this is the address of the call being overridden. | |
| vector< ConstructState * > | state |
| Available nodes for the constructor tree. | |
| ConstructState * | base_state |
| Root node of the constructor tree. | |
| int4 | alloc |
| Number of unallocated ConstructState nodes remaining. | |
| int4 | delayslot |
| delayslot depth | |
Friends | |
| class | ParserWalker |
| class | ParserWalkerChange |
Context maintained while parsing a single instruction.
This contains:
Possible states of the ParserContext.
| Enumerator | |
|---|---|
| uninitialized | Instruction has not been parsed at all. |
| disassembly | Instruction is parsed in preparation for disassembly. |
| pcode | Instruction is parsed in preparation for generating p-code. |
| ghidra::ParserContext::ParserContext | ( | ContextCache * | ccache, |
| Translate * | trans | ||
| ) |
Constructor.
| ccache | is the cache to use for formal context changes |
| trans | is the parent parser |
References contcache, context, contextsize, ghidra::ContextDatabase::getContextSize(), ghidra::ContextCache::getDatabase(), parsestate, translate, and uninitialized.
| void ghidra::ParserContext::addCommit | ( | TripleSymbol * | sym, |
| int4 | num, | ||
| uintm | mask, | ||
| bool | flow, | ||
| ConstructState * | point | ||
| ) |
Add a formal SLEIGH context change command.
| sym | is a symbol that resolves to the address where the setting takes effect |
| num | is the index of the context word being affected |
| mask | indicates the bits within the context word that are affected |
| flow | is true if the context change flows forward from the point where it is set |
| point | is the parse point where the change was made |
References context, contextcommit, ghidra::ContextSet::flow, ghidra::ContextSet::mask, ghidra::ContextSet::num, ghidra::ContextSet::point, ghidra::ContextSet::sym, and ghidra::ContextSet::value.
|
inline |
Allocate a new child node in the constructor tree.
The next available node is linked to the current active node in the walker at the given operand index. The child node becomes the new active node for the walker. The underlying constructor is not yet assigned.
| i | is the operand index of the new child |
| walker | is the walker for the parse |
References alloc, ghidra::ParserWalker::breadcrumb, ghidra::ConstructState::ct, ghidra::ParserWalker::depth, expandState(), MAX_DEPTH, MAX_OPERAND, ghidra::ConstructState::parent, ghidra::ParserWalker::point, ghidra::ConstructState::resolve, state, and STATE_GROWTH.
Referenced by ghidra::Sleigh::resolve(), and ghidra::InjectPayloadSleigh::setupParameters().
|
inline |
Clear any existing constructor tree.
The tree is reset to a single root node and the walker is prepared for a new parse
| walker | is the walker to initialize for a traversal |
References alloc, ghidra::ParserWalker::baseState(), ghidra::ParserWalkerChange::context, and state.
Referenced by ghidra::InjectPayloadSleigh::inject(), ghidra::ExecutablePcodeSleigh::inject(), and ghidra::Sleigh::resolve().
| void ghidra::ParserContext::expandState | ( | int4 | amount | ) |
Expand the number of available nodes for the constructor tree.
This can be called in the middle of a parse to accommodate larger constructor trees.
| amount | is the number of additional nodes to add |
References alloc, MAX_OPERAND, and state.
Referenced by allocateOperand().
| uintm ghidra::ParserContext::getContextBits | ( | int4 | startbit, |
| int4 | size | ||
| ) | const |
Get the specific range of bits from the local context.
| startbit | is the offset of the first bit |
| size | is the number of bits to return |
References context, and contextsize.
Referenced by ghidra::ParserWalker::getContextBits().
| uintm ghidra::ParserContext::getContextBytes | ( | int4 | bytestart, |
| int4 | size | ||
| ) | const |
Get bytes from the local context.
| bytestart | is the offset of the first byte to grab |
| size | is the number of bytes to grab |
References context, and contextsize.
Referenced by ghidra::ParserWalker::getContextBytes().
| uintm ghidra::ParserContext::getInstructionBits | ( | int4 | startbit, |
| int4 | size, | ||
| uint4 | off | ||
| ) | const |
Get the specific range of bits from the instruction stream.
Get bits from the instruction stream assuming big endian encoding.
| startbit | is the offset of the first bit (within the instruction stream) |
| size | is the number of bits to grab |
| off | is the number of bytes in the instruction already read |
References buf, and MAX_INSTRUCTION_LEN.
Referenced by ghidra::ParserWalker::getInstructionBits().
| uintm ghidra::ParserContext::getInstructionBytes | ( | int4 | bytestart, |
| int4 | size, | ||
| uint4 | off | ||
| ) | const |
Get the specified instruction bytes.
Get bytes from the instruction stream into a packed value assuming a big endian encoding.
| bytestart | is the number of bytes to skip |
| size | is the number of bytes to pack |
| off | is the number of bytes in the instruction already read |
References buf, and MAX_INSTRUCTION_LEN.
Referenced by ghidra::ParserWalker::getInstructionBytes().
| void ghidra::ParserContext::initialize | ( | AddrSpace * | spc, |
| int4 | maxstate = INITIAL_STATE_NUM |
||
| ) |
Preallocate nodes for constructor trees.
| spc | is the address space used for constants |
| maxstate | is the number of nodes to allocate (initially) |
References base_state, const_space, MAX_OPERAND, and state.
Referenced by ghidra::DisassemblyCache::initialize(), and ghidra::PcodeInjectLibrarySleigh::parseInject().
|
staticconstexpr |
Number of states to add for each expansion
Referenced by allocateOperand().