Class AssemblyConstructorSemantic

  • All Implemented Interfaces:
    java.lang.Comparable<AssemblyConstructorSemantic>

    public class AssemblyConstructorSemantic
    extends java.lang.Object
    implements java.lang.Comparable<AssemblyConstructorSemantic>
    Describes a SLEIGH constructor semantic These are collected and associated with productions in the grammar based on the given constructor's print pieces.
    • Constructor Detail

      • AssemblyConstructorSemantic

        public AssemblyConstructorSemantic​(Constructor cons,
                                           java.util.List<java.lang.Integer> indices)
        Build a new SLEIGH constructor semantic
        Parameters:
        cons - the SLEIGH constructor
        indices - the indices of RHS non-terminals in the associated production that represent an operand in the SLEIGH constructor
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getConstructor

        public Constructor getConstructor()
        Get the SLEIGH constructor
        Returns:
        the constructor
      • getPatterns

        public java.util.Collection<AssemblyResolvedConstructor> getPatterns()
        Get the associated encoding patterns for the constructor
        Returns:
        the patterns
      • getOperandIndex

        public int getOperandIndex​(int printpos)
        Convert the index of a print piece to its associated operand index
        Parameters:
        printpos - position excluding whitespace and string tokens.
        Returns:
        the operand index
      • getOperandIndices

        public java.util.List<java.lang.Integer> getOperandIndices()
        Get the list of operand indices in print piece order
        Returns:
        the list
      • getOperandIndexIterator

        public java.util.Iterator<java.lang.Integer> getOperandIndexIterator()
        Get an iterator over the operand indices If this iterator is advanced for each non-terminal, while simultaneously iterating over the RHS of the associated production, then this will identify the corresponding operand index for each non-terminal
        Returns:
        the iterator
      • computeAllForbids

        protected void computeAllForbids()
        Initialize upatterns with an unmodifiable copy of patterns, with forbidden patterns added
      • withComputedForbids

        protected AssemblyResolvedConstructor withComputedForbids​(AssemblyResolvedConstructor pat)
        Add the list of forbidden patterns to one of the constructor's patterns SLEIGH disambiguates multiple matching pattern by two rules. First, if one is more specific than ("specializes") another, i.e., it matches on more bits than another pattern, the more specific pattern is chosen. Second, if the two are equally special, then the one that occurs first in the SLEIGH specification is taken. So, during resolution, if a less-special or later-occurring constructor is chosen, we must prevent continued resolution from matching the more-special or earlier-occurring pattern(s). Essentially, this states, "you may choose any value matching my pattern, except those that match these forbidden patterns." This takes a given pattern, and searches the rest of the language for any patterns that would take precedence, and combines them as forbidden patterns with the given pattern.
        Parameters:
        pat - the given pattern
        Returns:
        the same pattern with forbidden records added
      • solveContextChanges

        public AssemblyResolution solveContextChanges​(AssemblyResolvedConstructor res,
                                                      java.util.Map<java.lang.String,​java.lang.Long> vals,
                                                      java.util.Map<java.lang.Integer,​java.lang.Object> opvals)
        Solve this constructor's context changes
        Parameters:
        res - the combined resolution requirements derived from the subconstructors
        vals - any defined symbols (usually inst_start, and inst_next)
        opvals - a map from operand index to operand value
        Returns:
        the resolution with context changes applied in reverse, or an error Each value in opvals must either be a numeric value, e.g., an index from a varnode list, or another AssemblyResolvedConstructor for a subconstructor operand. It's helpful to think of the SLEIGH disassembly process here. Normally, once the appropriate constructor has been identified (by matching patterns), its context changes are applied, and then its operands parsed (possibly parsing subconstructor operands). Thus, res can be thought of as the intermediate result between applying context changes and parsing operands, except in reverse. The output of this method corresponds to the state before context changes were applied, i.e., immediately after selecting the constructor. Thus, in reverse, the context is solved immediately before applying the selected constructor patterns.
        See Also:
        AssemblyTreeResolver.resolveSelectedChildren(AssemblyProduction, List, List, Collection)
      • applyForward

        public AssemblyResolvedConstructor applyForward​(AssemblyResolvedConstructor outer)
        Apply just context transformations in the forward (disassembly) direction
        Parameters:
        outer - the state before context changes
        Returns:
        the state after context changes Unlike the usual disassembly process, this method does not take into account any information from the instruction encoding. Any context bits that depend on it are set to unknown (x) in the output. This method is used to pre-compute a context transition graph in order to quickly resolve purely-recursive semantics on the root constructor table.