Пример #1
0
    def generateDot(self, f):
        dot = CDotDiagram()
        func = self.pyew.functions[f]
        bbs = {}
        nodes = {}
        for bb in func.basic_blocks:
            instructions = []
            bb_start = bb.instructions[0].offset
            end_offset = bb.instructions[-1].offset
            bb_end = end_offset + bb.instructions[-1].size

            buf = self.pyew.getBytes(bb_start, bb_end - bb_start)
            instructions = self.pyew.disassemble(buf=buf,
                                                 baseoffset=bb_start,
                                                 marker=False)
            instructions = instructions.replace("\r", "").replace("\n", "\\l")
            instructions = instructions.replace('"', '\"')

            bbs[bb_start] = instructions
            bbs[end_offset] = instructions

            n = CNode(bb.offset, instructions)
            dot.addNode(n)
            nodes[bb.offset] = n

        for bb in func.basic_blocks:
            for conn in bb.connections:
                a, b = conn
                next_head = self.pyew.NextHead(bb.instructions[-1].offset)
                if nodes.has_key(b) and nodes.has_key(bb.offset):
                    if len(bb.connections) == 1:
                        color = "blue"
                    elif next_head == b:
                        color = "red"
                    else:
                        color = "green"

                    dot.addConnectedNode(nodes[bb.offset], nodes[b], color)

        return dot.generateDot()
Пример #2
0
 def generateDot(self, f):
     dot = CDotDiagram()
     func = self.pyew.functions[f]
     bbs = {}
     nodes = {}
     for bb in func.basic_blocks:
         instructions = []
         bb_start = bb.instructions[0].offset
         end_offset = bb.instructions[-1].offset
         bb_end = end_offset + bb.instructions[-1].size
         
         buf = self.pyew.getBytes(bb_start, bb_end-bb_start)
         instructions = self.pyew.disassemble(buf=buf, baseoffset=bb_start, marker=False)
         instructions = instructions.replace("\r", "").replace("\n", "\\l")
         instructions = instructions.replace('"', '\"')
         
         bbs[bb_start] = instructions
         bbs[end_offset] = instructions
         
         n = CNode(bb.offset, instructions)
         dot.addNode(n)
         nodes[bb.offset] = n
     
     for bb in func.basic_blocks:
         for conn in bb.connections:
             a, b = conn
             next_head = self.pyew.NextHead(bb.instructions[-1].offset)
             if nodes.has_key(b) and nodes.has_key(bb.offset):
                 if len(bb.connections) == 1:
                     color = "blue"
                 elif next_head == b:
                     color = "red"
                 else:
                     color = "green"
                 
                 dot.addConnectedNode(nodes[bb.offset], nodes[b], color)
     
     return dot.generateDot()