Class DefaultAssemblyResolvedPatterns
- All Implemented Interfaces:
AssemblyResolution,AssemblyResolvedPatterns,Comparable<AssemblyResolution>
AssemblyResolution indicating successful application of a constructor
This is almost analogous to DisjointPattern, in that is joins an instruction AssemblyPatternBlock with a
corresponding context AssemblyPatternBlock. However, this object is mutable, and it
collects backfill records, as well as forbidden patterns.
When the applied constructor is from the "instruction" subtable, this represents a fully-
constructed instruction with required context. All backfill records ought to be resolved and
applied before the final result is given to the user, i.e., passed into the
AssemblySelector. If at any time during the resolution or backfill process, the result
becomes confined to one of the forbidden patterns, it must be dropped, since the encoding will
actually invoke a more specific SLEIGH constructor.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Set<AssemblyResolvedBackfill> protected final Constructorprotected final AssemblyPatternBlockprotected static final Stringprotected final Set<AssemblyResolvedPatterns> protected final AssemblyPatternBlockprotected static final Stringprotected static final Patternprotected static final StringFields inherited from class ghidra.app.plugin.assembler.sleigh.sem.AbstractAssemblyResolution
children, description, factory, right -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefaultAssemblyResolvedPatterns(AbstractAssemblyResolutionFactory<?, ?> factory, String description, Constructor cons, List<? extends AssemblyResolution> children, AssemblyResolution right, AssemblyPatternBlock ins, AssemblyPatternBlock ctx, Set<AssemblyResolvedBackfill> backfills, Set<AssemblyResolvedPatterns> forbids) -
Method Summary
Modifier and TypeMethodDescriptionbackfill(RecursiveDescentSolver solver, Map<String, Long> vals) Apply as many backfill records as possiblebooleanCheck if this and another resolution have equal encodingsCheck if the current encoding is forbidden by one of the attached patternsprotected StringchildrenToString(String indent) Get the child portion ofAbstractAssemblyResolution.toString()Combine the given backfill record into this resolutionCombine the encodings and backfills of the given resolution into this oneCombine a backfill resultprotected intcopyAppendDescription(String append) Duplicate this resolution, with additional description text appendedcopyAppendDescriptionBuilder(String append) Used for testing and diagnostics: list the constructor line numbers used to resolve this encodingbooleanbooleanCheck if this assembled construct state is the same as the given dis-assembled construct state.Get the backfill records for this resolution, if anyGet the context blockintGet the length of the instruction encoding, excluding trailing undefined bytesGet the forbidden patterns for this resolutionGet the instruction blockintGet the length of the instruction encodingprotected static intgetOpIndex(String piece) protected static ConstructStategetPureRecursion(ConstructState state) If the construct state is a^instructionor other purely-recursive constructor, get its single child.intCount the number of bits specified in the resolution patternsbooleanCheck if this resolution has pending backfills to applybooleanCheck if this record has childrenbooleanCheck if this record describes a backfillbooleanisError()Check if this record describes an errorDisplay the resolution result in one line (omitting child details)Set all bits read by a given context operation to unknownmaskOutBuilder(ContextOp cop) Generate a new nop right this resolution to its right.Get this same resolution, pushing its right siblings down to its childrenparentBuilder(String description, int opCount) protected booleanIterable<byte[]> possibleInsVals(AssemblyPatternBlock forCtx) Get an iterable over all the possible fillings of the instruction pattern given a contextreadContext(int start, int len) Decode a portion of the context blockreadContextOp(ContextOp cop) Decode the value from the context located where the given context operation would writereadInstruction(int start, int len) Decode a portion of the instruction blockshift(int amt) Shift the resolution's instruction pattern to the right, if applicableshiftBuilder(int amt) Solve and apply context changes in reverse to forbidden patternstruncate(int amt) Truncate (unshift) the resolved instruction pattern from the left NOTE: This drops all backfill and forbidden pattern records, since this method is typically used to read token fields rather than passed around for resolution.truncateBuilder(int amt) withConstructor(Constructor cons) Create a copy of this resolution with a replaced constructorCreate a copy of this resolution with a new contextwithDescription(String description) Create a copy of this resolution with a new descriptionwithDescriptionBuilder(String description) Create a new resolution from this one with the given forbidden patterns recordedwithRight(AssemblyResolution right) Get this same resolution, but with the given right siblingwriteContextOp(ContextOp cop, MaskedLong val) Encode the given value into the context block as specified by an operationwriteContextOpBuilder(ContextOp cop, MaskedLong val) Methods inherited from class ghidra.app.plugin.assembler.sleigh.sem.AbstractAssemblyResolution
collectAllRight, compareTo, getAllRight, getChildren, getDescription, getRight, hashCode, toString, toString, withoutRightMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface ghidra.app.plugin.assembler.sleigh.sem.AssemblyResolution
collectAllRight, getChildren, getDescription, getRight, toString, toStringMethods inherited from interface java.lang.Comparable
compareTo
-
Field Details
-
INS
- See Also:
-
CTX
- See Also:
-
SEP
- See Also:
-
cons
-
ins
-
ctx
-
backfills
-
forbids
-
pat
-
-
Constructor Details
-
DefaultAssemblyResolvedPatterns
protected DefaultAssemblyResolvedPatterns(AbstractAssemblyResolutionFactory<?, ?> factory, String description, Constructor cons, List<? extends AssemblyResolution> children, AssemblyResolution right, AssemblyPatternBlock ins, AssemblyPatternBlock ctx, Set<AssemblyResolvedBackfill> backfills, Set<AssemblyResolvedPatterns> forbids)
-
-
Method Details
-
computeHash
protected int computeHash()- Specified by:
computeHashin classAbstractAssemblyResolution
-
partsEqual
-
equals
-
shiftBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> shiftBuilder(int amt) -
shift
Description copied from interface:AssemblyResolutionShift the resolution's instruction pattern to the right, if applicableThis also shifts any backfill and forbidden pattern records.
- Specified by:
shiftin interfaceAssemblyResolution- Specified by:
shiftin interfaceAssemblyResolvedPatterns- Specified by:
shiftin classAbstractAssemblyResolution- Parameters:
amt- the number of bytes to shift.- Returns:
- the result
-
truncateBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> truncateBuilder(int amt) -
truncate
Description copied from interface:AssemblyResolvedPatternsTruncate (unshift) the resolved instruction pattern from the left NOTE: This drops all backfill and forbidden pattern records, since this method is typically used to read token fields rather than passed around for resolution.- Specified by:
truncatein interfaceAssemblyResolvedPatterns- Parameters:
amt- the number of bytes to remove from the left- Returns:
- the result
-
checkNotForbiddenBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolutionBuilder<?,?> checkNotForbiddenBuilder() -
checkNotForbidden
Description copied from interface:AssemblyResolvedPatternsCheck if the current encoding is forbidden by one of the attached patternsThe pattern becomes forbidden if this encoding's known bits are an overset of any forbidden pattern's known bits.
- Specified by:
checkNotForbiddenin interfaceAssemblyResolvedPatterns- Returns:
- false if the pattern is forbidden (and thus in error), true if permitted
-
bitsEqual
Description copied from interface:AssemblyResolvedPatternsCheck if this and another resolution have equal encodingsThis is like
Object.equals(Object), but it ignores backfill records and forbidden patterns.- Specified by:
bitsEqualin interfaceAssemblyResolvedPatterns- Parameters:
that- the other resolution- Returns:
- true if both have equal encodings
-
combineBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> combineBuilder(AssemblyResolvedPatterns that) -
combineLessBackfillBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> combineLessBackfillBuilder(AssemblyResolvedPatterns that, AssemblyResolvedBackfill bf) -
combine
Description copied from interface:AssemblyResolvedPatternsCombine the encodings and backfills of the given resolution into this oneThis combines corresponding pattern blocks (assuming they agree), collects backfill records, and collects forbidden patterns.
- Specified by:
combinein interfaceAssemblyResolvedPatterns- Parameters:
that- the other resolution- Returns:
- the result if successful, or null
-
combineLessBackfill
public AssemblyResolvedPatterns combineLessBackfill(AssemblyResolvedPatterns that, AssemblyResolvedBackfill bf) Combine a backfill resultWhen a backfill is successful, the result should be combined with the owning resolution. In addition, for bookkeeping's sake, the resolved record should be removed from the list of backfills.
- Specified by:
combineLessBackfillin interfaceAssemblyResolvedPatterns- Parameters:
that- the result from backfillingbf- the resolved backfilled record- Returns:
- the result if successful, or null
-
combineBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> combineBuilder(AssemblyResolvedBackfill bf) -
combine
Description copied from interface:AssemblyResolvedPatternsCombine the given backfill record into this resolution- Specified by:
combinein interfaceAssemblyResolvedPatterns- Parameters:
bf- the backfill record- Returns:
- the result
-
withForbidsBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> withForbidsBuilder(Set<AssemblyResolvedPatterns> more) -
withForbids
Description copied from interface:AssemblyResolvedPatternsCreate a new resolution from this one with the given forbidden patterns recorded- Specified by:
withForbidsin interfaceAssemblyResolvedPatterns- Parameters:
more- the additional forbidden patterns to record- Returns:
- the new resolution
-
withDescriptionBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> withDescriptionBuilder(String description) -
withDescription
Description copied from interface:AssemblyResolvedPatternsCreate a copy of this resolution with a new description- Specified by:
withDescriptionin interfaceAssemblyResolvedPatterns- Parameters:
description- the new description- Returns:
- the copy
-
withConstructorBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> withConstructorBuilder(Constructor cons) -
withConstructor
Description copied from interface:AssemblyResolvedPatternsCreate a copy of this resolution with a replaced constructor- Specified by:
withConstructorin interfaceAssemblyResolvedPatterns- Parameters:
cons- the new constructor- Returns:
- the copy
-
writeContextOpBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> writeContextOpBuilder(ContextOp cop, MaskedLong val) -
writeContextOp
Description copied from interface:AssemblyResolvedPatternsEncode the given value into the context block as specified by an operationThis is the forward (as in disassembly) direction of applying context operations. The pattern expression is evaluated, and the result is written as specified.
- Specified by:
writeContextOpin interfaceAssemblyResolvedPatterns- Parameters:
cop- the context operation specifying the location of the value to encodeval- the masked value to encode- Returns:
- the result
-
readContextOp
Description copied from interface:AssemblyResolvedPatternsDecode the value from the context located where the given context operation would writeThis is used to read the value from the left-hand-side "variable" of a context operation. It seems backward, because it is. When assembling, the right-hand-side expression of a context operation must be solved. This means the "variable" is known from the context(s) of the resolved children constructors. The value read is then used as the goal in solving the expression.
- Specified by:
readContextOpin interfaceAssemblyResolvedPatterns- Parameters:
cop- the context operation whose "variable" to read.- Returns:
- the masked result.
-
copyAppendDescriptionBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> copyAppendDescriptionBuilder(String append) -
copyAppendDescription
Duplicate this resolution, with additional description text appended- Parameters:
append- the text to append- Returns:
- the duplicate NOTE: An additional separator
": "is inserted
-
withRightBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> withRightBuilder(AssemblyResolution right) -
withRight
Description copied from class:AbstractAssemblyResolutionGet this same resolution, but with the given right sibling- Specified by:
withRightin interfaceAssemblyResolvedPatterns- Specified by:
withRightin classAbstractAssemblyResolution- Parameters:
right- the right sibling- Returns:
- the resolution
-
nopLeftSiblingBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> nopLeftSiblingBuilder() -
nopLeftSibling
Description copied from interface:AssemblyResolvedPatternsGenerate a new nop right this resolution to its right.Alternatively phrased: append a nop to the left of this list of siblings, returning the new head.
- Specified by:
nopLeftSiblingin interfaceAssemblyResolvedPatterns- Returns:
- the nop resolution
-
parentBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> parentBuilder(String description, int opCount) -
parent
Description copied from interface:AssemblyResolutionGet this same resolution, pushing its right siblings down to its children- Specified by:
parentin interfaceAssemblyResolution- Specified by:
parentin interfaceAssemblyResolvedPatterns
-
maskOutBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> maskOutBuilder(ContextOp cop) -
maskOut
Description copied from interface:AssemblyResolvedPatternsSet all bits read by a given context operation to unknown- Specified by:
maskOutin interfaceAssemblyResolvedPatterns- Parameters:
cop- the context operation- Returns:
- the result
- See Also:
-
backfill
Description copied from interface:AssemblyResolvedPatternsApply as many backfill records as possibleEach backfill record is resolved in turn, if the record cannot be resolved, it remains listed. If the record can be resolved, but it conflicts, an error record is returned. Each time a record is resolved and combined successfully, all remaining records are tried again. The result is the combined resolved backfills, with only the unresolved backfill records listed.
- Specified by:
backfillin interfaceAssemblyResolvedPatterns- Parameters:
solver- the solver, usually the same as the original attempt to solve.vals- the values.- Returns:
- the result, or an error.
-
lineToString
Description copied from interface:AssemblyResolutionDisplay the resolution result in one line (omitting child details)- Specified by:
lineToStringin interfaceAssemblyResolution- Returns:
- the display description
-
hasBackfills
public boolean hasBackfills()Description copied from interface:AssemblyResolvedPatternsCheck if this resolution has pending backfills to apply- Specified by:
hasBackfillsin interfaceAssemblyResolvedPatterns- Returns:
- true if there are backfills
-
solveContextChangesForForbidsBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> solveContextChangesForForbidsBuilder(AssemblyConstructorSemantic sem, Map<String, Long> vals) -
solveContextChangesForForbids
public AssemblyResolvedPatterns solveContextChangesForForbids(AssemblyConstructorSemantic sem, Map<String, Long> vals) Description copied from interface:AssemblyResolvedPatternsSolve and apply context changes in reverse to forbidden patternsTo avoid circumstances where a context change during disassembly would invoke a more specific sub-constructor than was used to assembly the instruction, we must solve the forbidden patterns in tandem with the overall resolution. If the context of any forbidden pattern cannot be solved, we simply drop the forbidden pattern -- the lack of a solution implies there is no way the context change could produce the forbidden pattern.
- Specified by:
solveContextChangesForForbidsin interfaceAssemblyResolvedPatterns- Parameters:
sem- the constructor whose context changes to solvevals- any defined symbols- Returns:
- the result
- See Also:
-
getInstructionLength
public int getInstructionLength()Description copied from interface:AssemblyResolvedPatternsGet the length of the instruction encodingThis is used to ensure each operand is encoded at the correct offset
NOTE: this DOES include the offset
NOTE: this DOES include pending backfills- Specified by:
getInstructionLengthin interfaceAssemblyResolvedPatterns- Returns:
- the length of the instruction block
-
getDefinedInstructionLength
public int getDefinedInstructionLength()Description copied from interface:AssemblyResolvedPatternsGet the length of the instruction encoding, excluding trailing undefined bytesNOTE: this DOES include the offset
NOTE: this DOES NOT include pending backfills- Specified by:
getDefinedInstructionLengthin interfaceAssemblyResolvedPatterns- Returns:
- the length of the defined bytes in the instruction block
-
getInstruction
Description copied from interface:AssemblyResolvedPatternsGet the instruction block- Specified by:
getInstructionin interfaceAssemblyResolvedPatterns- Returns:
- the instruction block
-
getContext
Description copied from interface:AssemblyResolvedPatternsGet the context block- Specified by:
getContextin interfaceAssemblyResolvedPatterns- Returns:
- the context block
-
withContextBuilder
protected AbstractAssemblyResolutionFactory.AbstractAssemblyResolvedPatternsBuilder<?> withContextBuilder(AssemblyPatternBlock ctx) -
withContext
Description copied from interface:AssemblyResolvedPatternsCreate a copy of this resolution with a new context- Specified by:
withContextin interfaceAssemblyResolvedPatterns- Parameters:
ctx- the new context- Returns:
- the copy
-
readInstruction
Description copied from interface:AssemblyResolvedPatternsDecode a portion of the instruction block- Specified by:
readInstructionin interfaceAssemblyResolvedPatterns- Parameters:
start- the first byte to decodelen- the number of bytes to decode- Returns:
- the read masked value
- See Also:
-
readContext
Description copied from interface:AssemblyResolvedPatternsDecode a portion of the context block- Specified by:
readContextin interfaceAssemblyResolvedPatterns- Parameters:
start- the first byte to decodelen- the number of bytes to decode- Returns:
- the read masked value
- See Also:
-
isError
public boolean isError()Description copied from interface:AssemblyResolutionCheck if this record describes an error- Specified by:
isErrorin interfaceAssemblyResolution- Returns:
- true if the record is an error
-
isBackfill
public boolean isBackfill()Description copied from interface:AssemblyResolutionCheck if this record describes a backfill- Specified by:
isBackfillin interfaceAssemblyResolution- Returns:
- true if the record is a backfill
-
hasChildren
public boolean hasChildren()Description copied from interface:AssemblyResolutionCheck if this record has childrenIf a subclass has another, possibly additional, notion of children that it would like to include in
AssemblyResolution.toString(), it must override this method to return true when such children are present.- Specified by:
hasChildrenin interfaceAssemblyResolution- Overrides:
hasChildrenin classAbstractAssemblyResolution- Returns:
- true if this record has children
-
childrenToString
Description copied from class:AbstractAssemblyResolutionGet the child portion ofAbstractAssemblyResolution.toString()If a subclass has another, possible additional, notion of children that it would like to include in
AbstractAssemblyResolution.toString(), it must override this method.- Overrides:
childrenToStringin classAbstractAssemblyResolution- Parameters:
indent- the current indentation- Returns:
- the indented description for each child on its own line
- See Also:
-
dumpConstructorTree
Description copied from interface:AssemblyResolvedPatternsUsed for testing and diagnostics: list the constructor line numbers used to resolve this encodingThis includes braces to describe the tree structure
- Specified by:
dumpConstructorTreein interfaceAssemblyResolvedPatterns- Returns:
- the constructor tree
- See Also:
-
getSpecificity
public int getSpecificity()Count the number of bits specified in the resolution patternsTotals the specificity of the instruction and context pattern blocks.
- Returns:
- the number of bits in the resulting patterns
- See Also:
-
possibleInsVals
Description copied from interface:AssemblyResolvedPatternsGet an iterable over all the possible fillings of the instruction pattern given a contextThis is meant to be used idiomatically, as in an enhanced for loop:
for (byte[] ins : rcon.possibleInsVals(ctx)) { System.out.println(format(ins)); }This is similar to calling
AssemblyResolvedPatterns.getInstruction().AssemblyPatternBlock.possibleVals(), but with forbidden patterns removed. A context is required so that only those forbidden patterns matching the given context are actually removed. This method should always be preferred to the sequence mentioned above, sinceAssemblyPatternBlock.possibleVals()on its own may yield bytes that do not produce the desired instruction.NOTE: The implementation is based on
AssemblyPatternBlock.possibleVals(), so be aware that a single array is reused for each iterate. You should not retain a pointer to the array, but rather make a copy.- Specified by:
possibleInsValsin interfaceAssemblyResolvedPatterns- Parameters:
forCtx- the context at the assembly address- Returns:
- the iterable
-
getOpIndex
-
getPureRecursion
If the construct state is a^instructionor other purely-recursive constructor, get its single child.- Parameters:
state- the parent state- Returns:
- the child state if recursive, or null
-
equivalentConstructState
Description copied from interface:AssemblyResolvedPatternsCheck if this assembled construct state is the same as the given dis-assembled construct state.- Specified by:
equivalentConstructStatein interfaceAssemblyResolvedPatterns
-
getConstructor
-
getBackfills
Description copied from interface:AssemblyResolvedPatternsGet the backfill records for this resolution, if any- Specified by:
getBackfillsin interfaceAssemblyResolvedPatterns- Returns:
- the backfills
-
getForbids
Description copied from interface:AssemblyResolvedPatternsGet the forbidden patterns for this resolutionThese represent patterns included in the current resolution that would actually get matched by a more specific constructor somewhere in the resolved tree, and thus are subtracted.
- Specified by:
getForbidsin interfaceAssemblyResolvedPatterns- Returns:
- the forbidden patterns
-