pub enum Expression {
Var(Variable),
Const(Bitvector),
BinOp {
op: BinOpType,
lhs: Box<Expression>,
rhs: Box<Expression>,
},
UnOp {
op: UnOpType,
arg: Box<Expression>,
},
Cast {
op: CastOpType,
size: ByteSize,
arg: Box<Expression>,
},
Unknown {
description: String,
size: ByteSize,
},
Subpiece {
low_byte: ByteSize,
size: ByteSize,
arg: Box<Expression>,
},
}
Expand description
An expression is a calculation rule on how to compute a certain value given some variables (register values) as input.
The basic building blocks of expressions are the same as for Ghidra P-Code. However, expressions can be nested, unlike original P-Code.
Computing the value of an expression is a side-effect-free operation.
Expressions are typed in the sense that each expression has a ByteSize
indicating the size of the result when evaluating the expression.
Some expressions impose restrictions on the sizes of their inputs
for the expression to be well-typed.
All operations are defined the same as the corresponding P-Code operation. Further information about specific operations can be obtained by looking up the P-Code mnemonics in the P-Code Reference Manual.
Variants§
Var(Variable)
A variable representing a register or temporary value of known size.
Const(Bitvector)
A constant value represented by a bitvector.
BinOp
Fields
lhs: Box<Expression>
The left hand side expression
rhs: Box<Expression>
The right hand side expression
A binary operation.
Note that most (but not all) operations require the left hand side (lhs
)
and right hand side (rhs
) to be of equal size.
UnOp
A unary operation
Cast
Fields
op: CastOpType
The opcode/type of the cast operation
arg: Box<Expression>
The argument of the expression
A cast operation for type cast between integer and floating point types of different byte lengths.
Unknown
Fields
An unknown value but with known size. This may be generated for e.g. unsupported assembly instructions. Note that computation of an unknown value is still required to be side-effect-free!
Subpiece
Fields
low_byte: ByteSize
The lowest byte (i.e. least significant byte if interpreted as integer) of the sub-bitvector to extract.
arg: Box<Expression>
The argument from which to extract the bitvector from.
Extracting a sub-bitvector from the argument expression.
Implementations§
source§impl Expression
impl Expression
sourcepub fn plus(self, rhs: Expression) -> Expression
pub fn plus(self, rhs: Expression) -> Expression
Shortcut for creating an IntAdd
-expression
sourcepub fn plus_const(self, value: i64) -> Expression
pub fn plus_const(self, value: i64) -> Expression
Construct an expression that adds a constant value to the given expression.
The bytesize of the value is automatically adjusted to the bytesize of the given expression.
source§impl Expression
impl Expression
sourcepub fn substitute_trivial_operations(&mut self)
pub fn substitute_trivial_operations(&mut self)
Substitute some trivial expressions with their result.
E.g. substitute a XOR a
with zero or substitute a OR a
with a
.
source§impl Expression
impl Expression
sourcepub fn bytesize(&self) -> ByteSize
pub fn bytesize(&self) -> ByteSize
Return the size (in bytes) of the result value of the expression.
sourcepub fn input_vars(&self) -> Vec<&Variable>
pub fn input_vars(&self) -> Vec<&Variable>
Return an array of all input variables of the given expression. The array may contain duplicates.
sourcepub fn substitute_input_var(
&mut self,
input_var: &Variable,
replace_with_expression: &Expression
)
pub fn substitute_input_var( &mut self, input_var: &Variable, replace_with_expression: &Expression )
Substitute every occurrence of input_var
in self
with the given replace_with_expression
.
sourcepub fn recursion_depth(&self) -> u64
pub fn recursion_depth(&self) -> u64
Compute a recursion depth for the expression.
Because of the recursive nature of the Expression type, overly complex expressions are very costly to clone, which in turn can negatively affect some analyses. The recursion depth measure can be used to detect and handle such cases.
Trait Implementations§
source§impl Clone for Expression
impl Clone for Expression
source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Expression
impl Debug for Expression
source§impl<'de> Deserialize<'de> for Expression
impl<'de> Deserialize<'de> for Expression
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for Expression
impl Display for Expression
source§impl From<Expression> for Expression
impl From<Expression> for Expression
source§fn from(expr: Expression) -> IrExpression
fn from(expr: Expression) -> IrExpression
Translates a P-Code expression into an expression of the internally used IR if possible. Panics if translation is not possible.
Cases where translation is not possible:
LOAD
andSTORE
, since these are not expressions (they have side effects).- Expressions which store the size of their output in the output variable (to which we do not have access here).
These include
SUBPIECE
,INT_ZEXT
,INT_SEXT
,INT2FLOAT
,FLOAT2FLOAT
,TRUNC
,LZCOUNT
andPOPCOUNT
. Translation of these expressions is handled explicitly during translation ofDef
.
source§impl From<Variable> for Expression
impl From<Variable> for Expression
source§fn from(pcode_var: Variable) -> IrExpression
fn from(pcode_var: Variable) -> IrExpression
Translate a P-Code variable into a Var
or Const
expression of the internally used IR.
Panics if the translation fails.
source§impl Hash for Expression
impl Hash for Expression
source§impl PartialEq for Expression
impl PartialEq for Expression
source§fn eq(&self, other: &Expression) -> bool
fn eq(&self, other: &Expression) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for Expression
impl Serialize for Expression
impl Eq for Expression
impl StructuralEq for Expression
impl StructuralPartialEq for Expression
Auto Trait Implementations§
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnwindSafe for Expression
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.