Class AddressEvaluator

java.lang.Object
generic.expressions.ExpressionEvaluator
ghidra.program.util.AddressEvaluator

public class AddressEvaluator extends ExpressionEvaluator
Class for evaluating expressions as an Address. See ExpressionOperator for the full list of supported operators. All values are interpreted as longs or symbols that resolve to an address.

ExpressionEvaluators can operate in either decimal or hex mode. If in hex mode, all numbers are assumed to be hexadecimal values. In decimal mode, numbers are assumed to be decimal values, but hexadecimal values can still be specified by prefixing them with "0x".

There are also two convenience static methods that can be called to evaluate address expressions. These methods will either return an Address as the result or null if there was an error evaluating the expression. To get error messages related to parsing the expression, instantiate an AddressEvaluator and call parseAsAddress(String) which will throw a ExpressionException when the expression can't be evaluated.

  • Constructor Details

    • AddressEvaluator

      public AddressEvaluator(Program program, boolean assumeHex)
      Constructs an AddressEvalutor for the given program and in the specified hex/decimal mode.
      Parameters:
      program - the program to use to evaluate expressions into valid addresses.
      assumeHex - if true, all numeric values are assumed to be hexadecimal numbers.
    • AddressEvaluator

      public AddressEvaluator(AddressFactory factory, boolean assumeHex)
      Constructs an AdddressEvaluator without a full program. This version will not be able to evaluate symbol or memory block names. This is mostly for backwards compatibility.
      Parameters:
      factory - the address factory for creating addresses
      assumeHex - if true, all numeric values are assumed to be hexadecimal numbers.
    • AddressEvaluator

      public AddressEvaluator(Program program, AddressSpace defaultSpace, boolean assumeHex)
      Constructs an AddressEvalutor for the given program and in the specified hex/decimal mode.
      Parameters:
      program - the program to use to evaluate expressions into valid addresses.
      defaultSpace - The address space to use when converting long values into addresses. If this value is null, then the default address space will be used.
      assumeHex - if true, all numeric values are assumed to be hexadecimal numbers.
  • Method Details

    • evaluate

      public static Address evaluate(Program p, String inputExpression)
      Gets a valid address for the specified program as indicated by the input expression.
      Parameters:
      p - the program to use for determining the address.
      inputExpression - string representation of the address desired.
      Returns:
      the address. Otherwise, return null if the string fails to evaluate to a unique legitimate address.
    • evaluate

      public static Address evaluate(Program p, Address baseAddr, String inputExpression)
      Gets a valid address for the specified program as indicated by the input expression.
      Parameters:
      p - the program to use for determining the address.
      baseAddr - the base address to use for relative addressing.
      inputExpression - string representation of the address desired.
      Returns:
      the address. Otherwise, return null if the string fails to evaluate to a unique legitimate address.
    • parseAsAddress

      public Address parseAsAddress(String input) throws ExpressionException
      Evaluates the given input expression as an address.
      Parameters:
      input - the expression to evaluate
      Returns:
      the Address the expression evaluates to
      Throws:
      ExpressionException - if the input expression can't be evaluated to a valid, unique address.
    • parseAsRelativeAddress

      public Address parseAsRelativeAddress(String input, Address baseAddress) throws ExpressionException
      Evaluates the given input expression as a relative offset that will be added to the given base address.
      Parameters:
      input - the expression to evaluate as an offset
      baseAddress - the base address the evaluted expression will be added to to get the resulting address.
      Returns:
      the Address after the evaluated offset is added to the given base address.
      Throws:
      ExpressionException - if the input expression can't be evaluated to a valid, unique address.
    • getAddressFactory

      public AddressFactory getAddressFactory()
      Returns the AddressFactory being used by this address evaluator
      Returns:
      the AddressFactory being used by this address evaluator
    • setPreferredAddressSpace

      public void setPreferredAddressSpace(AddressSpace space)
      Sets the AddressSpace to be used to convert long values into addresses.
      Parameters:
      space - the address space to convert long values into addresses
    • evaluateSymbol

      protected ExpressionValue evaluateSymbol(String input)
      Overrides:
      evaluateSymbol in class ExpressionEvaluator