(self)
Checks that a detected incongruency is not caused by translation backends having a different
        idea of what constitutes a basic block.
Checks that a detected incongruency is not caused by translation backends having a different
        idea of what constitutes a basic block.
Checks that a detected incongruency is not caused by translation backends having a different idea of what constitutes a basic block .
def _validate_incongruency(self):
        """
        Checks that a detected incongruency is not caused by translation backends having a different
        idea of what constitutes a basic block.
        """

        ot = self._throw

        try:
            self._throw = False
            l.debug("Validating incongruency.")

            if ("UNICORN" in self.simgr.right[0].options) ^ ("UNICORN" in self.simgr.left[0].options):
                if "UNICORN" in self.simgr.right[0].options:
                    unicorn_stash = 'right'
                    normal_stash = 'left'
                else:
                    unicorn_stash = 'left'
                    normal_stash = 'right'

                unicorn_path = self.simgr.stashes[unicorn_stash][0]
                normal_path = self.simgr.stashes[normal_stash][0]

                if unicorn_path.arch.name in ("X86", "AMD64"):
                    # unicorn "falls behind" on loop and rep instructions, since
                    # it sees them as ending a basic block. Here, we will
                    # step the unicorn until it's caught up
                    npg = self.project.factory.simulation_manager(unicorn_path)
                    npg.explore(find=lambda p: p.addr == normal_path.addr, n=200)
                    if len(npg.found) == 0:
                        l.debug("Validator failed to sync paths.")
                        return True

                    new_unicorn = npg.found[0]
                    delta = new_unicorn.history.block_count - normal_path.history.block_count
                    normal_path.history.recent_block_count += delta
                    new_normal = normal_path
                elif unicorn_path.arch.name == "MIPS32":
                    # unicorn gets ahead here, because VEX falls behind for unknown reasons
                    # for example, this block:
                    #
                    # 0x1016f20:      lui     $gp, 0x17
                    # 0x1016f24:      addiu   $gp, $gp, -0x35c0
                    # 0x1016f28:      addu    $gp, $gp, $t9
                    # 0x1016f2c:      addiu   $sp, $sp, -0x28
                    # 0x1016f30:      sw      $ra, 0x24($sp)
                    # 0x1016f34:      sw      $s0, 0x20($sp)
                    # 0x1016f38:      sw      $gp, 0x10($sp)
                    # 0x1016f3c:      lw      $v0, -0x6cf0($gp)
                    # 0x1016f40:      move    $at, $at
                    npg = self.project.factory.simulation_manager(normal_path)
                    npg.explore(find=lambda p: p.addr == unicorn_path.addr, n=200)
                    if len(npg.found) == 0:
                        l.debug("Validator failed to sync paths.")
                        return True

                    new_normal = npg.found[0]
                    delta = new_normal.history.block_count - unicorn_path.history.block_count
                    unicorn_path.history.recent_block_count += delta
                    new_unicorn = unicorn_path
                else:
                    l.debug("Dunno!")
                    return True

                if self.compare_paths(new_unicorn, new_normal):
                    l.debug("Divergence accounted for by unicorn.")
                    self.simgr.stashes[unicorn_stash][0] = new_unicorn
                    self.simgr.stashes[normal_stash][0] = new_normal
                    return False
                else:
                    l.warning("Divergence unaccounted for by unicorn.")
                    return True
            else:
                # no idea
                l.warning("Divergence unaccounted for.")
                return True
        finally:
            self._throw = ot
def _validate_incongruency ( self ) : ot = self . _throw try : self . _throw = False l . debug ( "Validating incongruency." ) if ( "UNICORN" in self . simgr . right [ 0 ] . options ) ^ ( "UNICORN" in self . simgr . left [ 0 ] . options ) : if "UNICORN" in self . simgr . right [ 0 ] . options : unicorn_stash = 'right' normal_stash = 'left' else : unicorn_stash = 'left' normal_stash = 'right' unicorn_path = self . simgr . stashes [ unicorn_stash ] [ 0 ] normal_path = self . simgr . stashes [ normal_stash ] [ 0 ] if unicorn_path . arch . name in ( "X86" , "AMD64" ) : # unicorn "falls behind" on loop and rep instructions, since # it sees them as ending a basic block. Here, we will # step the unicorn until it's caught up npg = self . project . factory . simulation_manager ( unicorn_path ) npg . explore ( find = lambda p : p . addr == normal_path . addr , n = 200 ) if len ( npg . found ) == 0 : l . debug ( "Validator failed to sync paths." ) return True new_unicorn = npg . found [ 0 ] delta = new_unicorn . history . block_count - normal_path . history . block_count normal_path . history . recent_block_count += delta new_normal = normal_path elif unicorn_path . arch . name == "MIPS32" : # unicorn gets ahead here, because VEX falls behind for unknown reasons # for example, this block: # # 0x1016f20:      lui     $gp, 0x17 # 0x1016f24:      addiu   $gp, $gp, -0x35c0 # 0x1016f28:      addu    $gp, $gp, $t9 # 0x1016f2c:      addiu   $sp, $sp, -0x28 # 0x1016f30:      sw      $ra, 0x24($sp) # 0x1016f34:      sw      $s0, 0x20($sp) # 0x1016f38:      sw      $gp, 0x10($sp) # 0x1016f3c:      lw      $v0, -0x6cf0($gp) # 0x1016f40:      move    $at, $at npg = self . project . factory . simulation_manager ( normal_path ) npg . explore ( find = lambda p : p . addr == unicorn_path . addr , n = 200 ) if len ( npg . found ) == 0 : l . debug ( "Validator failed to sync paths." ) return True new_normal = npg . found [ 0 ] delta = new_normal . history . block_count - unicorn_path . history . block_count unicorn_path . history . recent_block_count += delta new_unicorn = unicorn_path else : l . debug ( "Dunno!" ) return True if self . compare_paths ( new_unicorn , new_normal ) : l . debug ( "Divergence accounted for by unicorn." ) self . simgr . stashes [ unicorn_stash ] [ 0 ] = new_unicorn self . simgr . stashes [ normal_stash ] [ 0 ] = new_normal return False else : l . warning ( "Divergence unaccounted for by unicorn." ) return True else : # no idea l . warning ( "Divergence unaccounted for." ) return True finally : self . _throw = ot