Class SleighAssembler
- java.lang.Object
-
- ghidra.app.plugin.assembler.sleigh.SleighAssembler
-
- All Implemented Interfaces:
Assembler
public class SleighAssembler extends java.lang.Object implements Assembler
AnAssemblerfor aSleighLanguage. To obtain one of these, please useSleighAssemblerBuilder, or better yet, the static methods ofAssemblers.
-
-
Field Summary
Fields Modifier and Type Field Description protected AssemblyContextGraphctxGraphprotected static DbgTimerdbgstatic intDEFAULT_MAX_RECURSION_DEPTHprotected AssemblyDefaultContextdefaultContextprotected SleighLanguagelangprotected Listinglistingprotected Memorymemoryprotected AssemblyParserparserprotected Programprogramprotected AssemblySelectorselector
-
Constructor Summary
Constructors Modifier Constructor Description protectedSleighAssembler(AssemblySelector selector, SleighLanguage lang, AssemblyParser parser, AssemblyDefaultContext defaultContext, AssemblyContextGraph ctxGraph)Construct a SleighAssembler.protectedSleighAssembler(AssemblySelector selector, Program program, AssemblyParser parser, AssemblyDefaultContext defaultContext, AssemblyContextGraph ctxGraph)Construct a SleighAssembler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InstructionIteratorassemble(Address at, java.lang.String... assembly)Assemble a sequence of instructions and place them at the given address.byte[]assembleLine(Address at, java.lang.String line)Assemble a line instruction at the given address.byte[]assembleLine(Address at, java.lang.String line, AssemblyPatternBlock ctx)Assemble a line instruction at the given address, assuming the given context.AssemblyPatternBlockgetContextAt(Address addr)Get the context at a given addressprotected java.util.Map<java.lang.String,java.lang.Long>getProgramLabels()A convenience to obtain a map of program labels strings to long valuesjava.util.Collection<AssemblyParseResult>parseLine(java.lang.String line)Parse a line instruction.InstructionIteratorpatchProgram(byte[] insbytes, Address at)Place instruction bytes into the bound program.InstructionpatchProgram(AssemblyResolvedConstructor res, Address at)Place a resolved (and fully-masked) instruction into the bound program.AssemblyResolutionResultsresolveLine(Address at, java.lang.String line)Assemble a line instruction at the given address.AssemblyResolutionResultsresolveLine(Address at, java.lang.String line, AssemblyPatternBlock ctx)Assemble a line instruction at the given address, assuming the given context.AssemblyResolutionResultsresolveTree(AssemblyParseResult parse, Address at)Resolve a given parse tree at the given address.AssemblyResolutionResultsresolveTree(AssemblyParseResult parse, Address at, AssemblyPatternBlock ctx)Resolve a given parse tree at the given address, assuming the given context
-
-
-
Field Detail
-
DEFAULT_MAX_RECURSION_DEPTH
public static final int DEFAULT_MAX_RECURSION_DEPTH
- See Also:
- Constant Field Values
-
dbg
protected static final DbgTimer dbg
-
selector
protected AssemblySelector selector
-
program
protected Program program
-
listing
protected Listing listing
-
memory
protected Memory memory
-
parser
protected AssemblyParser parser
-
defaultContext
protected AssemblyDefaultContext defaultContext
-
ctxGraph
protected AssemblyContextGraph ctxGraph
-
lang
protected SleighLanguage lang
-
-
Constructor Detail
-
SleighAssembler
protected SleighAssembler(AssemblySelector selector, Program program, AssemblyParser parser, AssemblyDefaultContext defaultContext, AssemblyContextGraph ctxGraph)
Construct a SleighAssembler.- Parameters:
selector- a method of selecting one result from manyprogram- the program to bind to (must have same language as parser)parser- the parser for the SLEIGH languagedefaultContext- the default context for the languagectxGraph- the context graph
-
SleighAssembler
protected SleighAssembler(AssemblySelector selector, SleighLanguage lang, AssemblyParser parser, AssemblyDefaultContext defaultContext, AssemblyContextGraph ctxGraph)
Construct a SleighAssembler. NOTE: This variant does not permitassemble(Address, String...).- Parameters:
selector- a method of selecting one result from manylang- the SLEIGH language (must be same as to create the parser)parser- the parser for the SLEIGH languagedefaultContext- the default context for the languagectxGraph- the context graph
-
-
Method Detail
-
patchProgram
public Instruction patchProgram(AssemblyResolvedConstructor res, Address at) throws MemoryAccessException
Description copied from interface:AssemblerPlace a resolved (and fully-masked) instruction into the bound program.This method is not valid without a program binding. Also, this method must be called during a program database transaction.
- Specified by:
patchProgramin interfaceAssembler- Parameters:
res- the resolved and fully-masked instructionat- the location of the start of the instruction- Returns:
- the new
Instructioncode unit - Throws:
MemoryAccessException- there is an issue writing the result to program memory
-
patchProgram
public InstructionIterator patchProgram(byte[] insbytes, Address at) throws MemoryAccessException
Description copied from interface:AssemblerPlace instruction bytes into the bound program.This method is not valid without a program binding. Also, this method must be called during a program database transaction.
- Specified by:
patchProgramin interfaceAssembler- Parameters:
insbytes- the instruction dataat- the location of the start of the instruction- Returns:
- an iterator over the disassembled instructions
- Throws:
MemoryAccessException- there is an issue writing the result to program memory
-
assemble
public InstructionIterator assemble(Address at, java.lang.String... assembly) throws AssemblySyntaxException, AssemblySemanticException, MemoryAccessException, AddressOverflowException
Description copied from interface:AssemblerAssemble a sequence of instructions and place them at the given address.This method is only valid if the assembler is bound to a program. An instance may optionally implement this method without a program binding. In that case, the returned iterator will refer to pseudo instructions.
NOTE: There must be an active transaction on the bound program for this method to succeed.
- Specified by:
assemblein interfaceAssembler- Parameters:
at- the location where the resulting instructions should be placedassembly- a new-line separated or array sequence of instructions- Returns:
- an iterator over the resulting instructions
- Throws:
AssemblySyntaxException- a textual instruction is non well-formedAssemblySemanticException- a well-formed instruction cannot be assembledMemoryAccessException- there is an issue writing the result to program memoryAddressOverflowException- the resulting block is beyond the valid address range
-
assembleLine
public byte[] assembleLine(Address at, java.lang.String line) throws AssemblySyntaxException, AssemblySemanticException
Description copied from interface:AssemblerAssemble a line instruction at the given address.This method is valid with or without a bound program. Even if bound, the program is not modified; however, the appropriate context information is taken from the bound program. Without a program, the language's default context is taken at the given location.
- Specified by:
assembleLinein interfaceAssembler- Parameters:
at- the location of the start of the instructionline- the textual assembly code- Returns:
- the binary machine code, suitable for placement at the given address
- Throws:
AssemblySyntaxException- the textual instruction is not well-formedAssemblySemanticException- the the well-formed instruction cannot be assembled
-
parseLine
public java.util.Collection<AssemblyParseResult> parseLine(java.lang.String line)
Description copied from interface:AssemblerParse a line instruction.Generally, you should just use
Assembler.assembleLine(Address, String), but if you'd like access to the parse trees outside of anAssemblySelector, then this may be an acceptable option. Most notably, this is an excellent way to obtain suggestions for auto-completion.Each item in the returned collection is either a complete parse tree, or a syntax error Because all parse paths are attempted, it's possible to get many mixed results. For example, The input line may be a valid instruction; however, there may be suggestions to continue the line toward another valid instruction.
-
resolveTree
public AssemblyResolutionResults resolveTree(AssemblyParseResult parse, Address at)
Description copied from interface:AssemblerResolve a given parse tree at the given address.Each item in the returned collection is either a completely resolved instruction, or a semantic error. Because all resolutions are attempted, it's possible to get many mixed results.
NOTE: The resolved instructions are given as masks and values. Where the mask does not cover, you can choose any value.
- Specified by:
resolveTreein interfaceAssembler- Parameters:
parse- a parse result giving a valid treeat- the location of the start of the instruction- Returns:
- the results of semantic resolution
-
resolveTree
public AssemblyResolutionResults resolveTree(AssemblyParseResult parse, Address at, AssemblyPatternBlock ctx)
Description copied from interface:AssemblerResolve a given parse tree at the given address, assuming the given contextEach item in the returned collection is either a completely resolved instruction, or a semantic error. Because all resolutions are attempted, it's possible to get many mixed results.
NOTE: The resolved instructions are given as masks and values. Where the mask does not cover, you can choose any value.
- Specified by:
resolveTreein interfaceAssembler- Parameters:
parse- a parse result giving a valid treeat- the location of the start of the instructionctx- the context register value at the start of the instruction- Returns:
- the results of semantic resolution
-
resolveLine
public AssemblyResolutionResults resolveLine(Address at, java.lang.String line) throws AssemblySyntaxException
Description copied from interface:AssemblerAssemble a line instruction at the given address.This method works like
Assembler.resolveLine(Address, String, AssemblyPatternBlock), except that it derives the context usingAssembler.getContextAt(Address).- Specified by:
resolveLinein interfaceAssembler- Parameters:
at- the location of the start of the instructionline- the textual assembly code- Returns:
- the collection of semantic resolution results
- Throws:
AssemblySyntaxException- the textual instruction is not well-formed
-
resolveLine
public AssemblyResolutionResults resolveLine(Address at, java.lang.String line, AssemblyPatternBlock ctx) throws AssemblySyntaxException
Description copied from interface:AssemblerAssemble a line instruction at the given address, assuming the given context.This method works like
Assembler.assembleLine(Address, String, AssemblyPatternBlock), except that it returns all possible resolutions for the parse trees that pass theAssemblySelector.- Specified by:
resolveLinein interfaceAssembler- Parameters:
at- the location of the start of the instructionline- the textual assembly codectx- the context register value at the start of the instruction- Returns:
- the collection of semantic resolution results
- Throws:
AssemblySyntaxException- the textual instruction is not well-formed
-
assembleLine
public byte[] assembleLine(Address at, java.lang.String line, AssemblyPatternBlock ctx) throws AssemblySemanticException, AssemblySyntaxException
Description copied from interface:AssemblerAssemble a line instruction at the given address, assuming the given context.This method works like
Assembler.assembleLine(Address, String)except that it allows you to override the assumed context at that location.- Specified by:
assembleLinein interfaceAssembler- Parameters:
at- the location of the start of the instructionline- the textual assembly codectx- the context register value at the start of the instruction- Returns:
- the results of semantic resolution (from all parse results)
- Throws:
AssemblySemanticException- the well-formed instruction cannot be assembledAssemblySyntaxException- the textual instruction is not well-formed
-
getProgramLabels
protected java.util.Map<java.lang.String,java.lang.Long> getProgramLabels()
A convenience to obtain a map of program labels strings to long values- Returns:
- the map TODO Use a Map<String, Address> instead so that, if possible, symbol values can be checked lest they be an invalid substitution for a given operand.
-
getContextAt
public AssemblyPatternBlock getContextAt(Address addr)
Description copied from interface:AssemblerGet the context at a given addressIf there is a program binding, this will extract the actual context at the given address. Otherwise, it will obtain the default context at the given address for the language.
- Specified by:
getContextAtin interfaceAssembler- Parameters:
addr- the address- Returns:
- the context
-
-