コード例 #1
0
ファイル: dataflow.py プロジェクト: androguard/androguard
def place_declarations(graph, dvars, du, ud):
    idom = graph.immediate_dominators()
    for node in graph.post_order():
        for loc, ins in node.get_loc_with_ins():
            for var in ins.get_used_vars():
                if (not isinstance(dvars[var], Variable) or
                        isinstance(dvars[var], Param)):
                    continue
                var_defs_locs = ud[var, loc]
                def_nodes = set()
                for def_loc in var_defs_locs:
                    def_node = graph.get_node_from_loc(def_loc)
                    # TODO: place declarations in catch if needed
                    if def_node.in_catch:
                        continue
                    def_nodes.add(def_node)
                if not def_nodes:
                    continue
                common_dominator = def_nodes.pop()
                for def_node in def_nodes:
                    common_dominator = common_dom(
                        idom, common_dominator, def_node)
                if any(var in range(*common_dominator.ins_range)
                       for var in ud[var, loc]):
                    continue
                common_dominator.add_variable_declaration(dvars[var])
コード例 #2
0
def place_declarations(graph, dvars, du, ud):
    idom = graph.immediate_dominators()
    for node in graph.post_order():
        for loc, ins in node.get_loc_with_ins():
            for var in ins.get_used_vars():
                if (not isinstance(dvars[var], Variable)
                        or isinstance(dvars[var], Param)):
                    continue
                var_defs_locs = ud[var, loc]
                def_nodes = set()
                for def_loc in var_defs_locs:
                    def_node = graph.get_node_from_loc(def_loc)
                    # TODO: place declarations in catch if needed
                    if def_node.in_catch:
                        continue
                    def_nodes.add(def_node)
                if not def_nodes:
                    continue
                common_dominator = def_nodes.pop()
                for def_node in def_nodes:
                    common_dominator = common_dom(idom, common_dominator,
                                                  def_node)
                if any(var in range(*common_dominator.ins_range)
                       for var in ud[var, loc]):
                    continue
                common_dominator.add_variable_declaration(dvars[var])
コード例 #3
0
ファイル: graph.py プロジェクト: AndroidTamer/AppAnalyzer
 def immediate_dominators(self):
     '''
     Create a mapping of the nodes of a graph with their corresponding
     immediate dominator
     '''
     idom = dict((n, None) for n in self.nodes)
     for node in self.rpo:
         for pred in self.preds(node):
             if pred.num < node.num:
                 idom[node] = common_dom(idom, idom[node], pred)
     return idom
コード例 #4
0
ファイル: graph.py プロジェクト: Appsloka/android-tools
 def immediate_dominators(self):
     '''
     Create a mapping of the nodes of a graph with their corresponding
     immediate dominator
     '''
     idom = dict((n, None) for n in self.nodes)
     for node in self.rpo:
         for pred in self.preds(node):
             if pred.num < node.num:
                 idom[node] = common_dom(idom, idom[node], pred)
     return idom
コード例 #5
0
ファイル: graph.py プロジェクト: andymg/androguard
 def immediate_dominators(self):
     """
     Create a mapping of the nodes of a graph with their corresponding
     immediate dominator
     """
     idom = dict((n, None) for n in self.nodes)
     for node in self.rpo:
         if node.in_catch:
             predecessor = self.all_preds
         else:
             predecessor = self.preds
         for pred in predecessor(node):
             if pred.num < node.num:
                 idom[node] = common_dom(idom, idom[node], pred)
     return idom
コード例 #6
0
def switch_struct(graph, idoms):
    unresolved = set()
    for node in graph.post_order():
        if node.is_switch():
            m = node
            for suc in graph.sucs(node):
                if idoms[suc] is not node:
                    m = common_dom(idoms, node, suc)
            ldominates = []
            for n, dom in idoms.iteritems():
                if m is dom and len(graph.preds(n)) > 1:
                    ldominates.append(n)
            if len(ldominates) > 0:
                n = max(ldominates, key=lambda x: x.num)
                node.set_switch_follow(n)
                for x in unresolved:
                    x.set_switch_follow(n)
                unresolved = set()
            else:
                unresolved.add(node)
            node.order_cases()
コード例 #7
0
ファイル: control_flow.py プロジェクト: fanyao/androguard
def switch_struct(graph, idoms):
    unresolved = set()
    for node in graph.post_order():
        if node.type.is_switch:
            m = node
            for suc in graph.sucs(node):
                if idoms[suc] is not node:
                    m = common_dom(idoms, node, suc)
            ldominates = []
            for n, dom in idoms.iteritems():
                if m is dom and len(graph.preds(n)) > 1:
                    ldominates.append(n)
            if len(ldominates) > 0:
                n = max(ldominates, key=lambda x: x.num)
                node.follow['switch'] = n
                for x in unresolved:
                    x.follow['switch'] = n
                unresolved = set()
            else:
                unresolved.add(node)
            node.order_cases()