|
decompiler 1.0.0
|
Build p-code from a pre-parsed instruction. More...
#include <sleigh.hh>
Public Member Functions | |
| SleighBuilder (ParserWalker *w, DisassemblyCache *dcache, PcodeCacher *pc, AddrSpace *cspc, AddrSpace *uspc, uint4 umask) | |
| Constructor. More... | |
| virtual void | appendBuild (OpTpl *bld, int4 secnum) |
| Execute or filter a build directive in sequence. More... | |
| virtual void | delaySlot (OpTpl *op) |
| Execute or filter a delayslot directive in sequence. More... | |
| virtual void | setLabel (OpTpl *op) |
| Process or filter a label in sequence. More... | |
| virtual void | appendCrossBuild (OpTpl *bld, int4 secnum) |
| Process or filter a crossbuild directive in sequence. More... | |
Public Member Functions inherited from ghidra::PcodeBuilder | |
| PcodeBuilder (uint4 lbcnt) | |
| Construct with a starting label index. | |
| virtual | ~PcodeBuilder (void) |
| Destructor. | |
| uint4 | getLabelBase (void) const |
| Get the starting label index for this builder. | |
| ParserWalker * | getCurrentWalker () const |
| Get the current instruction context. | |
| void | build (ConstructTpl *construct, int4 secnum) |
| Build the semantics for the given constructor. More... | |
| virtual void | appendBuild (OpTpl *bld, int4 secnum)=0 |
| Execute or filter a build directive in sequence. More... | |
| virtual void | delaySlot (OpTpl *op)=0 |
| Execute or filter a delayslot directive in sequence. More... | |
| virtual void | setLabel (OpTpl *op)=0 |
| Process or filter a label in sequence. More... | |
| virtual void | appendCrossBuild (OpTpl *bld, int4 secnum)=0 |
| Process or filter a crossbuild directive in sequence. More... | |
Private Member Functions | |
| virtual void | dump (OpTpl *op) |
| Output/build the given p-code operation. More... | |
| void | buildEmpty (Constructor *ct, int4 secnum) |
| Build a named p-code section of a constructor that contains only implied BUILD directives. More... | |
| void | generateLocation (const VarnodeTpl *vntpl, VarnodeData &vn) |
| Generate a concrete VarnodeData object from the given template (VarnodeTpl) More... | |
| AddrSpace * | generatePointer (const VarnodeTpl *vntpl, VarnodeData &vn) |
| Generate a pointer VarnodeData from a dynamic template (VarnodeTpl) More... | |
| void | generatePointerAdd (PcodeData *op, const VarnodeTpl *vntpl) |
| Add in an additional offset to the address of a dynamic Varnode. More... | |
| void | setUniqueOffset (const Address &addr) |
| Set uniquifying bits for the current instruction. More... | |
Private Attributes | |
| AddrSpace * | const_space |
| The constant address space. | |
| AddrSpace * | uniq_space |
| The unique address space. | |
| uintb | uniquemask |
| Mask of address bits to use to uniquify temporary registers. | |
| uintb | uniqueoffset |
| Uniquifier bits for this instruction. | |
| DisassemblyCache * | discache |
| Cache of disassembled instructions. | |
| PcodeCacher * | cache |
| Cache accumulating p-code data for the instruction. | |
Additional Inherited Members | |
| virtual void | dump (OpTpl *op)=0 |
| Output/build the given p-code operation. More... | |
Protected Attributes inherited from ghidra::PcodeBuilder | |
| ParserWalker * | walker |
| Current instruction context. | |
Build p-code from a pre-parsed instruction.
Through the build() method, this walks the parse tree and prepares data for final emission as p-code. (The final emitting is done separately through the PcodeCacher.emit() method). Generally, only p-code for one instruction is prepared. But, through the delay-slot mechanism, build() may recursively visit additional instructions.
| ghidra::SleighBuilder::SleighBuilder | ( | ParserWalker * | w, |
| DisassemblyCache * | dcache, | ||
| PcodeCacher * | pc, | ||
| AddrSpace * | cspc, | ||
| AddrSpace * | uspc, | ||
| uint4 | umask | ||
| ) |
Constructor.
| w | is the parsed instruction |
| dcache | is a cache of nearby instruction parses |
| pc | will hold the PcodeData and VarnodeData objects produced by this builder |
| cspc | is the constant address space |
| uspc | is the unique address space |
| umask | is the mask to use to find unique bits within an Address |
References cache, const_space, discache, ghidra::ParserWalker::getAddr(), ghidra::Address::getOffset(), uniq_space, uniquemask, uniqueoffset, and ghidra::PcodeBuilder::walker.
|
virtual |
Execute or filter a build directive in sequence.
Any recursion through build directives into ConstructTpl for sub-constructors happens here.
| bld | is the build directive, which encodes the particular sub-construction |
| secnum | is the current section number of the constructor |
Implements ghidra::PcodeBuilder.
References ghidra::PcodeBuilder::build(), buildEmpty(), ghidra::ParserWalker::getConstructor(), ghidra::OpTpl::getIn(), ghidra::VarnodeTpl::getOffset(), ghidra::ConstTpl::getReal(), ghidra::ParserWalker::popOperand(), ghidra::ParserWalker::pushOperand(), and ghidra::PcodeBuilder::walker.
|
virtual |
Process or filter a crossbuild directive in sequence.
Any recursion through crossbuild directives into new instructions and sections happens here.
| bld | is the crossbuild directive |
| secnum | is the current section number being processed |
Implements ghidra::PcodeBuilder.
References ghidra::ParserWalker::baseState(), ghidra::PcodeBuilder::build(), buildEmpty(), discache, ghidra::ConstTpl::fix(), ghidra::ConstTpl::fixSpace(), ghidra::ParserWalker::getConstructor(), ghidra::OpTpl::getIn(), ghidra::VarnodeTpl::getOffset(), ghidra::DisassemblyCache::getParserContext(), ghidra::ParserWalker::getParserContext(), ghidra::ParserContext::getParserState(), ghidra::ConstTpl::getReal(), ghidra::VarnodeTpl::getSpace(), ghidra::ParserContext::pcode, setUniqueOffset(), uniqueoffset, ghidra::PcodeBuilder::walker, and ghidra::AddrSpace::wrapOffset().
|
private |
Build a named p-code section of a constructor that contains only implied BUILD directives.
If a named section of a constructor is empty, we still need to walk through any subtables that might contain p-code in their named sections. This method treats each subtable operand as an implied build directive, in the otherwise empty section.
| ct | is the matching currently Constructor being built |
| secnum | is the particular named section number to build |
References ghidra::PcodeBuilder::build(), buildEmpty(), ghidra::ParserWalker::getConstructor(), ghidra::ParserWalker::popOperand(), ghidra::ParserWalker::pushOperand(), and ghidra::PcodeBuilder::walker.
Referenced by appendBuild(), appendCrossBuild(), and buildEmpty().
|
virtual |
Execute or filter a delayslot directive in sequence.
Any recursion through delayslot directives into new instructions happens here.
| op | is the delayslot directive, which encodes the number of bytes in the particular delay slot. |
Implements ghidra::PcodeBuilder.
References ghidra::ParserWalker::baseState(), ghidra::PcodeBuilder::build(), discache, ghidra::ParserWalker::getAddr(), ghidra::ParserWalker::getConstructor(), ghidra::ParserContext::getDelaySlot(), ghidra::ParserContext::getLength(), ghidra::ParserWalker::getLength(), ghidra::DisassemblyCache::getParserContext(), ghidra::ParserWalker::getParserContext(), ghidra::ParserContext::getParserState(), ghidra::ParserContext::pcode, setUniqueOffset(), uniqueoffset, and ghidra::PcodeBuilder::walker.
|
privatevirtual |
Output/build the given p-code operation.
This is the main hook point for different p-code generation strategies. It is called once, in sequence, for each p-code operation generated for a specific instruction. Directives and labels have had the opportunity to be expanded or filtered by other methods.
| op | is the p-code operation to process |
Implements ghidra::PcodeBuilder.
References ghidra::PcodeCacher::addLabelRef(), ghidra::PcodeCacher::allocateInstruction(), ghidra::PcodeCacher::allocateVarnodes(), cache, const_space, ghidra::CPUI_LOAD, ghidra::CPUI_STORE, generateLocation(), generatePointer(), generatePointerAdd(), ghidra::OpTpl::getIn(), ghidra::PcodeBuilder::getLabelBase(), ghidra::VarnodeTpl::getOffset(), ghidra::OpTpl::getOpcode(), ghidra::OpTpl::getOut(), ghidra::ConstTpl::getSelect(), ghidra::PcodeData::invar, ghidra::VarnodeTpl::isDynamic(), ghidra::PcodeData::isize, ghidra::VarnodeTpl::isRelative(), ghidra::OpTpl::numInput(), ghidra::VarnodeData::offset, ghidra::PcodeData::opc, ghidra::PcodeData::outvar, ghidra::VarnodeData::size, ghidra::VarnodeData::space, ghidra::ConstTpl::v_offset_plus, and ghidra::PcodeBuilder::walker.
|
private |
Generate a concrete VarnodeData object from the given template (VarnodeTpl)
| vntpl | is the template to reference |
| vn | is the object to fill in with concrete values |
References ghidra::calc_mask(), const_space, ghidra::ConstTpl::fix(), ghidra::ConstTpl::fixSpace(), ghidra::VarnodeTpl::getOffset(), ghidra::VarnodeTpl::getSize(), ghidra::VarnodeTpl::getSpace(), ghidra::VarnodeData::offset, ghidra::VarnodeData::size, ghidra::VarnodeData::space, uniq_space, uniqueoffset, ghidra::PcodeBuilder::walker, and ghidra::AddrSpace::wrapOffset().
Referenced by dump().
|
private |
Generate a pointer VarnodeData from a dynamic template (VarnodeTpl)
The symbol represents a value referenced through a dynamic pointer. This method generates the varnode representing the pointer itself and also returns the address space in anticipation of generating the LOAD or STORE that actually manipulates the value.
| vntpl | is the dynamic template to reference |
| vn | is the object to fill with concrete values |
References ghidra::calc_mask(), const_space, ghidra::ParserWalker::getFixedHandle(), ghidra::ConstTpl::getHandleIndex(), ghidra::VarnodeTpl::getOffset(), ghidra::VarnodeData::offset, ghidra::FixedHandle::offset_offset, ghidra::FixedHandle::offset_size, ghidra::FixedHandle::offset_space, ghidra::VarnodeData::size, ghidra::FixedHandle::space, ghidra::VarnodeData::space, uniq_space, uniqueoffset, ghidra::PcodeBuilder::walker, and ghidra::AddrSpace::wrapOffset().
Referenced by dump().
|
private |
Add in an additional offset to the address of a dynamic Varnode.
The Varnode is ultimately read/written via LOAD/STORE operation AND has undergone a truncation operation, so an additional offset needs to get added to the pointer referencing the Varnode.
| op | is the LOAD/STORE operation being generated |
| vntpl | is the dynamic Varnode |
References ghidra::PcodeCacher::allocateInstruction(), ghidra::PcodeCacher::allocateVarnodes(), cache, const_space, ghidra::CPUI_INT_ADD, ghidra::VarnodeTpl::getOffset(), ghidra::ConstTpl::getReal(), ghidra::AddrSpace::getTrans(), ghidra::Translate::getUniqueStart(), ghidra::PcodeData::invar, ghidra::PcodeData::isize, ghidra::VarnodeData::offset, ghidra::PcodeData::opc, ghidra::PcodeData::outvar, ghidra::Translate::RUNTIME_BITRANGE_EA, ghidra::VarnodeData::size, ghidra::VarnodeData::space, and uniq_space.
Referenced by dump().
|
virtual |
Process or filter a label in sequence.
The builder has the opportunity to record exactly where in sequence the given label occurs.
| op | is the OpTpl encoding the label index |
Implements ghidra::PcodeBuilder.
References ghidra::PcodeCacher::addLabel(), cache, ghidra::OpTpl::getIn(), ghidra::PcodeBuilder::getLabelBase(), ghidra::VarnodeTpl::getOffset(), and ghidra::ConstTpl::getReal().
|
private |
Set uniquifying bits for the current instruction.
Bits used to make temporary registers unique across multiple instructions are generated based on the given address.
| addr | is the given Address |
References ghidra::Address::getOffset(), uniquemask, and uniqueoffset.
Referenced by appendCrossBuild(), and delaySlot().