
from .base import SimSootExpr


class SimSootExpr_Phi(SimSootExpr):
    def __init__(self, expr, state):
        super(SimSootExpr_Phi, self).__init__(expr, state)

    def _execute(self):

        if len(self.expr.values) != 2:
            import ipdb; ipdb.set_trace();

        v1, v2 = [self._translate_value(v) for v in self.expr.values]
        v = self.expr = self.state.memory.load(v1, none_if_missing=True)
        if v is None:
            v = self.expr = self.state.memory.load(v2, none_if_missing=True)
        if v is None:
            import ipdb; ipdb.set_trace();

        self.expr = v


from .base import SimSootExpr

import logging
l = logging.getLogger('angr.engines.soot.expressions.phi')

class SimSootExpr_Phi(SimSootExpr):
    def __init__(self, expr, state):
        super(SimSootExpr_Phi, self).__init__(expr, state)

    def _execute(self):
        locals_option = [self._translate_value(v) for v in self.expr.values]
        values = []
        for local in locals_option:
            value = self.state.memory.load(local, none_if_missing=True)
            if value is not None:
                values.append(value)
        
        if len(values) == 0:
            l.warning("Couldn't find a value of Phi expression in memory.")
            return

        if len(values) > 2:
            l.warning("Found multiple values of Phi expression in memory.")
        
        self.expr = values[-1]

Extend Phi expression to work with more than 2 values
Extend Phi expression to work with more than 2 values

  
  from .base import SimSootExpr
  
+ import logging
+ l = logging.getLogger('angr.engines.soot.expressions.phi')
  
  class SimSootExpr_Phi(SimSootExpr):
      def __init__(self, expr, state):
          super(SimSootExpr_Phi, self).__init__(expr, state)
  
      def _execute(self):
+         locals_option = [self._translate_value(v) for v in self.expr.values]
+         values = []
+         for local in locals_option:
+             value = self.state.memory.load(local, none_if_missing=True)
+             if value is not None:
+                 values.append(value)
+         
+         if len(values) == 0:
+             l.warning("Couldn't find a value of Phi expression in memory.")
+             return
  
-         if len(self.expr.values) != 2:
+         if len(values) > 2:
-             import ipdb; ipdb.set_trace();
+             l.warning("Found multiple values of Phi expression in memory.")
+         
+         self.expr = values[-1]
  
-         v1, v2 = [self._translate_value(v) for v in self.expr.values]
-         v = self.expr = self.state.memory.load(v1, none_if_missing=True)
-         if v is None:
-             v = self.expr = self.state.memory.load(v2, none_if_missing=True)
-         if v is None:
-             import ipdb; ipdb.set_trace();
- 
-         self.expr = v
- 
Extend Phi expression to work with more than 2 values
## Code Before:

from .base import SimSootExpr


class SimSootExpr_Phi(SimSootExpr):
    def __init__(self, expr, state):
        super(SimSootExpr_Phi, self).__init__(expr, state)

    def _execute(self):

        if len(self.expr.values) != 2:
            import ipdb; ipdb.set_trace();

        v1, v2 = [self._translate_value(v) for v in self.expr.values]
        v = self.expr = self.state.memory.load(v1, none_if_missing=True)
        if v is None:
            v = self.expr = self.state.memory.load(v2, none_if_missing=True)
        if v is None:
            import ipdb; ipdb.set_trace();

        self.expr = v

## Instruction:
Extend Phi expression to work with more than 2 values
## Code After:

from .base import SimSootExpr

import logging
l = logging.getLogger('angr.engines.soot.expressions.phi')

class SimSootExpr_Phi(SimSootExpr):
    def __init__(self, expr, state):
        super(SimSootExpr_Phi, self).__init__(expr, state)

    def _execute(self):
        locals_option = [self._translate_value(v) for v in self.expr.values]
        values = []
        for local in locals_option:
            value = self.state.memory.load(local, none_if_missing=True)
            if value is not None:
                values.append(value)
        
        if len(values) == 0:
            l.warning("Couldn't find a value of Phi expression in memory.")
            return

        if len(values) > 2:
            l.warning("Found multiple values of Phi expression in memory.")
        
        self.expr = values[-1]
