Interface AssemblyResolvedPatterns
- All Superinterfaces:
AssemblyResolution
,Comparable<AssemblyResolution>
- All Known Implementing Classes:
DefaultAssemblyResolvedPatterns
-
Method Summary
Modifier and TypeMethodDescriptionbackfill
(RecursiveDescentSolver solver, Map<String, Long> vals) Apply as many backfill records as possibleboolean
Check if this and another resolution have equal encodingsCheck if the current encoding is forbidden by one of the attached patternsCombine the given backfill record into this resolutionCombine the encodings and backfills of the given resolution into this oneCombine a backfill resultUsed for testing and diagnostics: list the constructor line numbers used to resolve this encodingboolean
Check 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 blockint
Get the length of the instruction encoding, excluding trailing undefined bytesGet the forbidden patterns for this resolutionGet the instruction blockint
Get the length of the instruction encodingboolean
Check if this resolution has pending backfills to applySet all bits read by a given context operation to unknownGenerate a new nop right this resolution to its right.Get this same resolution, pushing its right siblings down to its childrenIterable
<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 byteStart, int size) Decode a portion of the instruction blockshift
(int shamt) Shift the resolution's instruction pattern to the right, if applicableSolve and apply context changes in reverse to forbidden patternstruncate
(int shamt) 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.withConstructor
(Constructor cons) Create a copy of this resolution with a replaced constructorwithDescription
(String description) Create a copy of this resolution with a new descriptionCreate a new resolution from this one with the given forbidden patterns recordedwithRight
(AssemblyResolution right) Create a copy of this resolution with a sibling to the rightwriteContextOp
(ContextOp cop, MaskedLong val) Encode the given value into the context block as specified by an operationMethods inherited from interface ghidra.app.plugin.assembler.sleigh.sem.AssemblyResolution
collectAllRight, getChildren, getDescription, getRight, hasChildren, isBackfill, isError, lineToString, toString, toString
Methods inherited from interface java.lang.Comparable
compareTo
-
Method Details
-
getInstruction
AssemblyPatternBlock getInstruction()Get the instruction block- Returns:
- the instruction block
-
getContext
AssemblyPatternBlock getContext()Get the context block- Returns:
- the context block
-
getInstructionLength
int getInstructionLength()Get 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- Returns:
- the length of the instruction block
-
getDefinedInstructionLength
int getDefinedInstructionLength()Get the length of the instruction encoding, excluding trailing undefined bytesNOTE: this DOES include the offset
NOTE: this DOES NOT include pending backfills- Returns:
- the length of the defined bytes in the instruction block
-
getBackfills
Collection<AssemblyResolvedBackfill> getBackfills()Get the backfill records for this resolution, if any- Returns:
- the backfills
-
hasBackfills
boolean hasBackfills()Check if this resolution has pending backfills to apply- Returns:
- true if there are backfills
-
getForbids
Collection<AssemblyResolvedPatterns> getForbids()Get 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.
- Returns:
- the forbidden patterns
-
readInstruction
Decode a portion of the instruction block- Parameters:
byteStart
- the first byte to decodesize
- the number of bytes to decode- Returns:
- the read masked value
- See Also:
-
readContext
Decode a portion of the context block- Parameters:
start
- the first byte to decodelen
- the number of bytes to decode- Returns:
- the read masked value
- See Also:
-
readContextOp
Decode 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.
- Parameters:
cop
- the context operation whose "variable" to read.- Returns:
- the masked result.
-
bitsEqual
Check if this and another resolution have equal encodingsThis is like
Object.equals(Object)
, but it ignores backfill records and forbidden patterns.- Parameters:
that
- the other resolution- Returns:
- true if both have equal encodings
-
equivalentConstructState
Check if this assembled construct state is the same as the given dis-assembled construct state. -
shift
Description copied from interface:AssemblyResolution
Shift the resolution's instruction pattern to the right, if applicableThis also shifts any backfill and forbidden pattern records.
- Specified by:
shift
in interfaceAssemblyResolution
- Parameters:
shamt
- the number of bytes to shift.- Returns:
- the result
-
withDescription
Create a copy of this resolution with a new description- Parameters:
description
- the new description- Returns:
- the copy
-
withRight
Create a copy of this resolution with a sibling to the rightThe right sibling is a mechanism for collecting children of a parent yet to be created. See
parent(String, int)
.- Parameters:
right
- the right sibling- Returns:
- the new resolution
-
withConstructor
Create a copy of this resolution with a replaced constructor- Parameters:
cons
- the new constructor- Returns:
- the copy
-
combine
Combine 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.
- Parameters:
pat
- the other resolution- Returns:
- the result if successful, or null
-
combine
Combine the given backfill record into this resolution- Parameters:
bf
- the backfill record- Returns:
- the result
-
combineLessBackfill
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.
- Parameters:
that
- the result from backfillingbf
- the resolved backfilled record- Returns:
- the result if successful, or null
-
parent
Description copied from interface:AssemblyResolution
Get this same resolution, pushing its right siblings down to its children- Specified by:
parent
in interfaceAssemblyResolution
-
backfill
Apply 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.
- Parameters:
solver
- the solver, usually the same as the original attempt to solve.vals
- the values.- Returns:
- the result, or an error.
-
checkNotForbidden
AssemblyResolution checkNotForbidden()Check 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.
- Returns:
- false if the pattern is forbidden (and thus in error), true if permitted
-
nopLeftSibling
AssemblyResolvedPatterns nopLeftSibling()Generate 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.
- Returns:
- the nop resolution
-
solveContextChangesForForbids
AssemblyResolvedPatterns solveContextChangesForForbids(AssemblyConstructorSemantic sem, Map<String, Long> vals) Solve 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.
- Parameters:
sem
- the constructor whose context changes to solvevals
- any defined symbols- Returns:
- the result
- See Also:
-
possibleInsVals
Get 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
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.- Parameters:
forCtx
- the context at the assembly address- Returns:
- the iterable
-
dumpConstructorTree
String dumpConstructorTree()Used for testing and diagnostics: list the constructor line numbers used to resolve this encodingThis includes braces to describe the tree structure
- Returns:
- the constructor tree
- See Also:
-
truncate
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.- Parameters:
shamt
- the number of bytes to remove from the left- Returns:
- the result
-
withForbids
Create a new resolution from this one with the given forbidden patterns recorded- Parameters:
more
- the additional forbidden patterns to record- Returns:
- the new resolution
-
maskOut
Set all bits read by a given context operation to unknown- Parameters:
cop
- the context operation- Returns:
- the result
- See Also:
-
writeContextOp
Encode 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.
- Parameters:
cop
- the context operation specifying the location of the value to encodeval
- the masked value to encode- Returns:
- the result
-