pub(crate) fn operand_value(
        &self,
        operand: &cs_x86_op,
        instruction: &capstone::Instr,
    ) -> Result<Expression> {
        match operand.type_ {
            x86_op_type::X86_OP_INVALID => Err("Invalid operand".into()),
            x86_op_type::X86_OP_REG => {
                // Get the register value
                get_register(self, operand.reg())?.get()
            }
            x86_op_type::X86_OP_MEM => {
                let mem = operand.mem();
                let base_capstone_reg = mem.base;
                let index_capstone_reg = mem.index;

                let base = match base_capstone_reg {
                    x86_reg::X86_REG_INVALID => None,
                    reg => Some(self.get_register_expression(reg, instruction)?),
                };

                let index = match index_capstone_reg {
                    x86_reg::X86_REG_INVALID => None,
                    reg => Some(self.get_register_expression(reg, instruction)?),
                };

                let scale = Expr::constant(Constant::new(mem.scale as i64 as u64, self.bits()));

                let si = match index {
                    Some(index) => Some(Expr::mul(index, scale)?),
                    None => None,
                };

                // Handle base and scale/index
                let op: Option<Expression> = if base.is_some() {
                    if si.is_some() {
                        Some(Expr::add(base.unwrap(), si.unwrap())?)
                    } else {
                        base
                    }
                } else if si.is_some() {
                    si
                } else {
                    None
                };

                // handle disp
                let op = if let Some(op) = op {
                    match mem.disp.cmp(&0) {
                        Ordering::Greater => {
                            Expr::add(op, expr_const(mem.disp as u64, self.bits()))?
                        }
                        Ordering::Less => {
                            Expr::sub(op, expr_const(mem.disp.abs() as u64, self.bits()))?
                        }
                        Ordering::Equal => op,
                    }
                } else {
                    expr_const(mem.disp as u64, self.bits())
                };

                match mem.segment {
                    x86_reg::X86_REG_INVALID => Ok(op),
                    x86_reg::X86_REG_CS
                    | x86_reg::X86_REG_DS
                    | x86_reg::X86_REG_ES
                    | x86_reg::X86_REG_FS
                    | x86_reg::X86_REG_GS
                    | x86_reg::X86_REG_SS => {
                        let segment_register = self.get_register(mem.segment)?.get()?;
                        Ok(Expr::add(segment_register, op)?)
                    }
                    _ => bail!("invalid segment register"),
                }
            }
            x86_op_type::X86_OP_IMM => {
                // https://github.com/aquynh/capstone/issues/1586
                let operand_size = if operand.size == 0 {
                    8
                } else {
                    operand.size as usize * 8
                };
                Ok(expr_const(operand.imm() as u64, operand_size))
            }
            #[cfg(not(feature = "capstone4"))]
            x86_op_type::X86_OP_FP => Err("Unhandled operand".into()),
        }
    }
/// Gets the value of an operand as an IL expression
Gets the value of an operand as an IL expression
Gets the value of an operand as an IL expression
pub(crate) fn operand_value(
        &self,
        operand: &cs_x86_op,
        instruction: &capstone::Instr,
    ) -> Result<Expression> {
        match operand.type_ {
            x86_op_type::X86_OP_INVALID => Err("Invalid operand".into()),
            x86_op_type::X86_OP_REG => {
                // Get the register value
                get_register(self, operand.reg())?.get()
            }
            x86_op_type::X86_OP_MEM => {
                let mem = operand.mem();
                let base_capstone_reg = mem.base;
                let index_capstone_reg = mem.index;
                let base = match base_capstone_reg {
                    x86_reg::X86_REG_INVALID => None,
                    reg => Some(self.get_register_expression(reg, instruction)?),
                };
                let index = match index_capstone_reg {
                    x86_reg::X86_REG_INVALID => None,
                    reg => Some(self.get_register_expression(reg, instruction)?),
                };
                let scale = Expr::constant(Constant::new(mem.scale as i64 as u64, self.bits()));
                let si = match index {
                    Some(index) => Some(Expr::mul(index, scale)?),
                    None => None,
                };
                // Handle base and scale/index
                let op: Option<Expression> = if base.is_some() {
                    if si.is_some() {
                        Some(Expr::add(base.unwrap(), si.unwrap())?)
                    } else {
                        base
                    }
                } else if si.is_some() {
                    si
                } else {
                    None
                };
                // handle disp
                let op = if let Some(op) = op {
                    match mem.disp.cmp(&0) {
                        Ordering::Greater => {
                            Expr::add(op, expr_const(mem.disp as u64, self.bits()))?
                        }
                        Ordering::Less => {
                            Expr::sub(op, expr_const(mem.disp.abs() as u64, self.bits()))?
                        }
                        Ordering::Equal => op,
                    }
                } else {
                    expr_const(mem.disp as u64, self.bits())
                };
                match mem.segment {
                    x86_reg::X86_REG_INVALID => Ok(op),
                    x86_reg::X86_REG_CS
                    | x86_reg::X86_REG_DS
                    | x86_reg::X86_REG_ES
                    | x86_reg::X86_REG_FS
                    | x86_reg::X86_REG_GS
                    | x86_reg::X86_REG_SS => {
                        let segment_register = self.get_register(mem.segment)?.get()?;
                        Ok(Expr::add(segment_register, op)?)
                    }
                    _ => bail!("invalid segment register"),
                }
            }
            x86_op_type::X86_OP_IMM => {
                // https://github.com/aquynh/capstone/issues/1586
                let operand_size = if operand.size == 0 {
                    8
                } else {
                    operand.size as usize * 8
                };
                Ok(expr_const(operand.imm() as u64, operand_size))
            }
            #[cfg(not(feature = "capstone4"))]
            x86_op_type::X86_OP_FP => Err("Unhandled operand".into()),
        }
    }
pub ( crate ) fn operand_value ( & self , operand : & cs_x86_op , instruction : & capstone :: Instr , ) -> Result < Expression > { match operand . type_ { x86_op_type :: X86_OP_INVALID => Err ( " " . into ( ) ) , x86_op_type :: X86_OP_REG => { // Get the register value get_register ( self , operand . reg ( ) ) ? . get ( ) } x86_op_type :: X86_OP_MEM => { let mem = operand . mem ( ) ; let base_capstone_reg = mem . base ; let index_capstone_reg = mem . index ; let base = match base_capstone_reg { x86_reg :: X86_REG_INVALID => None , reg => Some ( self . get_register_expression ( reg , instruction ) ? ) , } ; let index = match index_capstone_reg { x86_reg :: X86_REG_INVALID => None , reg => Some ( self . get_register_expression ( reg , instruction ) ? ) , } ; let scale = Expr :: constant ( Constant :: new ( mem . scale as i64 as u64 , self . bits ( ) ) ) ; let si = match index { Some ( index ) => Some ( Expr :: mul ( index , scale ) ? ) , None => None , } ; // Handle base and scale/index let op : Option < Expression > = if base . is_some ( ) { if si . is_some ( ) { Some ( Expr :: add ( base . unwrap ( ) , si . unwrap ( ) ) ? ) } else { base } } else if si . is_some ( ) { si } else { None } ; // handle disp let op = if let Some ( op ) = op { match mem . disp . cmp ( & 0 ) { Ordering :: Greater => { Expr :: add ( op , expr_const ( mem . disp as u64 , self . bits ( ) ) ) ? } Ordering :: Less => { Expr :: sub ( op , expr_const ( mem . disp . abs ( ) as u64 , self . bits ( ) ) ) ? } Ordering :: Equal => op , } } else { expr_const ( mem . disp as u64 , self . bits ( ) ) } ; match mem . segment { x86_reg :: X86_REG_INVALID => Ok ( op ) , x86_reg :: X86_REG_CS | x86_reg :: X86_REG_DS | x86_reg :: X86_REG_ES | x86_reg :: X86_REG_FS | x86_reg :: X86_REG_GS | x86_reg :: X86_REG_SS => { let segment_register = self . get_register ( mem . segment ) ? . get ( ) ? ; Ok ( Expr :: add ( segment_register , op ) ? ) } _ => bail ! ( " " ) , } } x86_op_type :: X86_OP_IMM => { // https://github.com/aquynh/capstone/issues/1586 let operand_size = if operand . size == 0 { 8 } else { operand . size as usize * 8 } ; Ok ( expr_const ( operand . imm ( ) as u64 , operand_size ) ) } # [ cfg ( not ( feature " " ) ) ] x86_op_type :: X86_OP_FP => Err ( " " . into ( ) ) , } }
Gets the value of an operand as an IL expression
Gets the value of an operand as an IL expression
&self
operand
&cs_x86_op
instruction
&capstone::Instr
&self
operand
&cs_x86_op
instruction
&capstone::Instr