Class DecompileCallback


  • public class DecompileCallback
    extends java.lang.Object
    Routines that the decompiler invokes to gather info during decompilation of a function.
    • Nested Class Summary

      Nested Classes 
      ChangeModifier and Type Class Description
      static class  DecompileCallback.StringData
      Data returned for a query about strings
    • Field Summary

      Fields 
      ChangeModifier and Type Field Description
      NEWstatic int MAX_SYMBOL_COUNT  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      ChangeModifier and Type Method Description
      static java.lang.String buildInstruction​(PcodeOp[] ops, int fallthruoffset, int paramshift, AddressFactory addrFactory)
      Build an XML representation of all the pcode op's a given Instruction is defined to perform.
      byte[] getBytes​(java.lang.String addrxml)  
      java.lang.String getComments​(java.lang.String addrstring, java.lang.String types)
      Collect any/all comments for the function starting at the indicated address
      java.lang.String getCPoolRef​(long[] refs)  
      java.lang.String getExternalRefXML​(java.lang.String addrstring)  
      java.lang.String getMappedSymbolsXML​(java.lang.String addrstring)
      Called by the native decompiler to query the GHIDRA database about any symbols at the given address.
      NEWjava.lang.String getNamespacePath​(long id)
      Return an XML description of the formal namespace path to the given namespace
      java.lang.String getNativeMessage()  
      java.lang.String getPcodeInject​(java.lang.String nm, java.lang.String context, int type)  
      PackedBytes getPcodePacked​(java.lang.String addrstring)  
      java.lang.String getRegister​(java.lang.String name)  
      java.lang.String getRegisterName​(java.lang.String addrstring)  
      NEWDecompileCallback.StringData getStringData​(java.lang.String addrString, java.lang.String dtName, java.lang.String dtId)
      Check for a string at an address and return a UTF8 encoded byte array.
      java.lang.String getSymbol​(java.lang.String addrstring)  
      java.lang.String getTrackedRegisters​(java.lang.String addrstring)  
      java.lang.String getType​(java.lang.String name, java.lang.String idstr)  
      java.lang.String getUserOpName​(java.lang.String indexStr)  
      NEWboolean isNameUsed​(java.lang.String name, long startId, long stopId)
      Decide if a given name is used by any namespace between a starting namespace and a stopping namespace.
      java.util.ArrayList<java.lang.String> readXMLNameList​(java.lang.String xml)  
      int readXMLSize​(java.lang.String addrxml)  
      void setFunction​(Function func, Address entry, DecompileDebug dbg)
      Establish function and debug context for next decompilation
      REMOVED void setShowNamespace(boolean showNamespace)
      (Removed)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

  • Method Detail

    • setFunction

      public void setFunction​(Function func,
                              Address entry,
                              DecompileDebug dbg)
      Establish function and debug context for next decompilation
      Parameters:
      func - is the function to be decompiled
      entry - is the function's entry address
      dbg - is the debugging context (or null)
    • getNativeMessage

      public java.lang.String getNativeMessage()
      Returns:
      the last message from the decompiler
    • readXMLSize

      public int readXMLSize​(java.lang.String addrxml)
    • getBytes

      public byte[] getBytes​(java.lang.String addrxml)
    • getComments

      public java.lang.String getComments​(java.lang.String addrstring,
                                          java.lang.String types)
      Collect any/all comments for the function starting at the indicated address
      Parameters:
      addrstring - is the XML rep of function address
      types - is the string encoding of the comment type flags
      Returns:
      XML document describing comments
    • getPcodePacked

      public PackedBytes getPcodePacked​(java.lang.String addrstring)
    • buildInstruction

      public static java.lang.String buildInstruction​(PcodeOp[] ops,
                                                      int fallthruoffset,
                                                      int paramshift,
                                                      AddressFactory addrFactory)
      Build an XML representation of all the pcode op's a given Instruction is defined to perform.
      Parameters:
      ops - pcode ops
      fallthruoffset - number of bytes after instruction start that pcode flow falls into
      paramshift - special instructions for injection use
      addrFactory - is the address factory for recovering address space names
      Returns:
      XML document as string representing all the p-code
    • getPcodeInject

      public java.lang.String getPcodeInject​(java.lang.String nm,
                                             java.lang.String context,
                                             int type)
    • getCPoolRef

      public java.lang.String getCPoolRef​(long[] refs)
                                   throws java.io.IOException
      Throws:
      java.io.IOException
    • getSymbol

      public java.lang.String getSymbol​(java.lang.String addrstring)
    • isNameUsed NEW

      public boolean isNameUsed​(java.lang.String name,
                                long startId,
                                long stopId)
      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 collisions
      startId - is the id specifying the starting namespace
      stopId - is the id specifying the stopping namespace
      Returns:
      true if the name (likely) occurs in one of the namespaces on the path
    • getNamespacePath NEW

      public java.lang.String getNamespacePath​(long id)
      Return an XML description of the formal namespace path to the given namespace
      Parameters:
      id - is the ID of the given namespace
      Returns:
      a parent XML tag
    • getMappedSymbolsXML

      public java.lang.String getMappedSymbolsXML​(java.lang.String addrstring)
      Called by the native decompiler to query the GHIDRA database about any symbols at the given address.
      Parameters:
      addrstring - XML encoded address to query
      Returns:
      XML encoded result. Either function, reference, datatype, or hole
    • getExternalRefXML

      public java.lang.String getExternalRefXML​(java.lang.String addrstring)
    • getType

      public java.lang.String getType​(java.lang.String name,
                                      java.lang.String idstr)
    • getRegister

      public java.lang.String getRegister​(java.lang.String name)
    • getRegisterName

      public java.lang.String getRegisterName​(java.lang.String addrstring)
    • getTrackedRegisters

      public java.lang.String getTrackedRegisters​(java.lang.String addrstring)
    • getUserOpName

      public java.lang.String getUserOpName​(java.lang.String indexStr)
    • getStringData NEW

      public DecompileCallback.StringData getStringData​(java.lang.String addrString,
                                                        java.lang.String dtName,
                                                        java.lang.String dtId)
      Check for a string at an 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:
      addrString - is the XML encoded address and maximum byte limit
      dtName - is the name of a character data-type
      dtId - is the id associated with the character data-type
      Returns:
      the UTF8 encoded byte array or null