Package ghidra.program.util
Class AddressEvaluator
java.lang.Object
generic.expressions.ExpressionEvaluator
ghidra.program.util.AddressEvaluator
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 Summary
ConstructorsConstructorDescriptionAddressEvaluator
(AddressFactory factory, boolean assumeHex) Constructs an AdddressEvaluator without a full program.AddressEvaluator
(Program program, boolean assumeHex) Constructs an AddressEvalutor for the given program and in the specified hex/decimal mode.AddressEvaluator
(Program program, AddressSpace defaultSpace, boolean assumeHex) Constructs an AddressEvalutor for the given program and in the specified hex/decimal mode. -
Method Summary
Modifier and TypeMethodDescriptionstatic Address
Gets a valid address for the specified program as indicated by the input expression.static Address
Gets a valid address for the specified program as indicated by the input expression.protected ExpressionValue
evaluateSymbol
(String input) Returns theAddressFactory
being used by this address evaluatorparseAsAddress
(String input) Evaluates the given input expression as an address.parseAsRelativeAddress
(String input, Address baseAddress) Evaluates the given input expression as a relative offset that will be added to the given base address.void
Sets theAddressSpace
to be used to convert long values into addresses.Methods inherited from class generic.expressions.ExpressionEvaluator
evaluateToLong, evaluateToLong, parse, parse, parseAsLong, setAssumeHex
-
Constructor Details
-
AddressEvaluator
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
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 addressesassumeHex
- if true, all numeric values are assumed to be hexadecimal numbers.
-
AddressEvaluator
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
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
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
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
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 offsetbaseAddress
- 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
Returns theAddressFactory
being used by this address evaluator- Returns:
- the
AddressFactory
being used by this address evaluator
-
setPreferredAddressSpace
Sets theAddressSpace
to be used to convert long values into addresses.- Parameters:
space
- the address space to convert long values into addresses
-
evaluateSymbol
- Overrides:
evaluateSymbol
in classExpressionEvaluator
-