Package ghidra.app.decompiler
Class DecompileCallback
java.lang.Object
ghidra.app.decompiler.DecompileCallback
Routines that the decompiler invokes to gather info during decompilation of a
function.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Data returned for a query about strings -
Field Summary
-
Constructor Summary
ConstructorDescriptionDecompileCallback
(Program prog, Language language, CompilerSpec compilerSpec, PcodeDataTypeManager dt) -
Method Summary
Modifier and TypeMethodDescriptionstatic void
encodeInstruction
(Encoder encoder, Address addr, PcodeOp[] ops, int fallthruoffset, int paramshift, AddressFactory addrFactory) Encode a list of pcode, representing an entire Instruction, to the streambyte[]
Get bytes from the program's memory image.getCodeLabel
(Address addr) Return the first symbol name at the given addressvoid
getComments
(Address addr, int types, Encoder resultEncoder) Collect any/all comments for the function starting at the indicated address.void
getCPoolRef
(long[] refs, Encoder resultEncoder) Look up details of a specific constant pool referencevoid
getDataType
(String name, long id, Encoder resultEncoder) Get a description of a data-type given its name and type idvoid
getExternalRef
(Address addr, Encoder resultEncoder) Get a description of an external reference at the given addressvoid
getMappedSymbols
(Address addr, Encoder resultEncoder) Describe data or functions at the given address; either function, reference, data, or hole.void
getNamespacePath
(long id, Encoder resultEncoder) Write a description of the formal namespace path to the given namespacevoid
getPcode
(Address addr, PatchEncoder resultEncoder) Generate p-code ops for the instruction at the given address.void
getPcodeInject
(String nm, Decoder paramDecoder, int type, Encoder resultEncoder) Generate p-code ops for a named injection payloadvoid
getRegister
(String name, Encoder resultEncoder) Return a description of the register with the given namegetRegisterName
(Address addr, int size) Given a storage location, return the register name for that location, or null if there is no register there.getStringData
(Address addr, int maxChars, String dtName, long dtId) Check for a string at the given address and return a UTF8 encoded byte array.void
getTrackedRegisters
(Address addr, Encoder resultEncoder) Get "tracked" register values, constant values associated with a specific register at a specific point in the code.getUserOpName
(int index) Get the name of a user op given its indexboolean
isNameUsed
(String name, long startId, long stopId) Decide if a given name is used by any namespace between a starting namespace and a stopping namespace.void
setFunction
(Function func, Address entry, DecompileDebug dbg) Establish function and debug context for next decompilation
-
Field Details
-
MAX_SYMBOL_COUNT
public static final int MAX_SYMBOL_COUNT- See Also:
-
-
Constructor Details
-
DecompileCallback
public DecompileCallback(Program prog, Language language, CompilerSpec compilerSpec, PcodeDataTypeManager dt)
-
-
Method Details
-
setFunction
Establish function and debug context for next decompilation- Parameters:
func
- is the function to be decompiledentry
- is the function's entry addressdbg
- is the debugging context (or null)
-
getNativeMessage
- Returns:
- the last message from the decompiler
-
getBytes
Get bytes from the program's memory image. Any exceptions are caught, resulting in null being returned. The decompiler treats a null as a DataUnavailError but will continue to process the function.- Parameters:
addr
- is the starting address to fetch bytes fromsize
- is the number of bytes to fetch- Returns:
- the bytes matching the query or null if the query can't be met
-
getComments
Collect any/all comments for the function starting at the indicated address. Filter based on selected comment types.- Parameters:
addr
- is the indicated addresstypes
- is the set of flagsresultEncoder
- will contain the collected comments- Throws:
IOException
- for errors in the underlying stream
-
getPcode
Generate p-code ops for the instruction at the given address. Any exceptions are caught, resulting in an empty result. The decompiler interprets these as a BadDataError, but will continue to process the function.- Parameters:
addr
- is the given addressresultEncoder
- will contain the generated p-code ops
-
encodeInstruction
public static void encodeInstruction(Encoder encoder, Address addr, PcodeOp[] ops, int fallthruoffset, int paramshift, AddressFactory addrFactory) throws IOException Encode a list of pcode, representing an entire Instruction, to the stream- Parameters:
encoder
- is the stream encoderaddr
- is the Address to associate with the Instructionops
- is the pcode opsfallthruoffset
- number of bytes after instruction start that pcode flow falls intoparamshift
- special instructions for injection useaddrFactory
- is the address factory for recovering address space names- Throws:
IOException
- for errors in the underlying stream
-
getPcodeInject
public void getPcodeInject(String nm, Decoder paramDecoder, int type, Encoder resultEncoder) throws DecoderException, UnknownInstructionException, IOException, MemoryAccessException, NotFoundException Generate p-code ops for a named injection payload- Parameters:
nm
- is the name of the payloadparamDecoder
- contains the contexttype
- is the type of payloadresultEncoder
- will contain the generated p-code ops- Throws:
DecoderException
- for problems decoding the injection contextUnknownInstructionException
- if there is no instruction at the injection siteIOException
- for errors encoding the injection resultNotFoundException
- if an expected aspect of the injection is not present in contextMemoryAccessException
- for problems establishing the injection context
-
getCPoolRef
Look up details of a specific constant pool reference- Parameters:
refs
- is the constant id (which may consist of multiple integers)resultEncoder
- will contain the reference details- Throws:
IOException
- for errors in the underlying stream while encoding results
-
getCodeLabel
Return the first symbol name at the given address- Parameters:
addr
- is the given address- Returns:
- the symbol or null if no symbol is found
- Throws:
IOException
- for errors trying to encode the symbol
-
isNameUsed
Decide if a given name is used by any namespace between a starting namespace and a stopping namespace. I.e. check for a name collision along a specific namespace path. Currently, Ghidra is inefficient at calculating this perfectly, so this routine calculates an approximation that can occasionally indicate a collision when there isn't.- Parameters:
name
- is the given name to check for collisionsstartId
- is the id specifying the starting namespacestopId
- is the id specifying the stopping namespace- Returns:
- true if the name (likely) occurs in one of the namespaces on the path
-
getNamespacePath
Write a description of the formal namespace path to the given namespace- Parameters:
id
- is the ID of the given namespaceresultEncoder
- is where to write the encoded result- Throws:
IOException
- for errors in the underlying stream
-
getMappedSymbols
Describe data or functions at the given address; either function, reference, data, or hole. Called by the native decompiler to query the GHIDRA database about any symbols at the given address.- Parameters:
addr
- is the given addressresultEncoder
- is where to write encoded description- Throws:
IOException
- for errors encoding the result
-
getExternalRef
Get a description of an external reference at the given address- Parameters:
addr
- is the given addressresultEncoder
- will contain the resulting description- Throws:
IOException
- for errors encoding the result
-
getDataType
Get a description of a data-type given its name and type id- Parameters:
name
- is the name of the data-typeid
- is the type idresultEncoder
- will contain the resulting description- Throws:
IOException
- for errors in the underlying stream while encoding
-
getRegister
Return a description of the register with the given name- Parameters:
name
- is the given nameresultEncoder
- is where to write the description- Throws:
IOException
- for errors writing to the underlying stream
-
getRegisterName
Given a storage location, return the register name for that location, or null if there is no register there.- Parameters:
addr
- is the starting address of the storage locationsize
- is the size of storage in bytes- Returns:
- the register name or null
-
getTrackedRegisters
Get "tracked" register values, constant values associated with a specific register at a specific point in the code.- Parameters:
addr
- is the "point" in the code to look for tracked valuesresultEncoder
- will hold the resulting description of registers and values- Throws:
IOException
- for errors in the underlying stream writing the result
-
getUserOpName
Get the name of a user op given its index- Parameters:
index
- is the given index- Returns:
- the userop name or null
-
getStringData
public DecompileCallback.StringData getStringData(Address addr, int maxChars, String dtName, long dtId) Check for a string at the given address and return a UTF8 encoded byte array. If there is already data present at the address, use this to determine the string encoding. Otherwise use the data-type info passed in to determine the encoding. Check that the bytes at the address represent a valid string encoding that doesn't exceed the maximum character limit passed in. Return null if the string is invalid. Return the string translated into a UTF8 byte array otherwise. A (valid) empty string is returned as a zero length array.- Parameters:
addr
- is the given addressmaxChars
- is the maximum character limitdtName
- is the name of a character data-typedtId
- is the id associated with the character data-type- Returns:
- the UTF8 encoded byte array or null
-