예제 #1
0
    def decompile(self, offset=0, startIndent=0):
        '''Entry point for the decompilation process.'''
        try:
            cb = self.disassembler.getAllCodeBlocks(offset)
            print "[+] All code blocks got"
            flowGraph = structure.getGraphFromCodeBlocks(cb, self.debugDraw)
            print "[+] Flow graph from code blocks got"
            flowGraph.DFADecompile(self)
            print "[+] DFA decompiled"
            flowGraph.simplifyComplexIFs()
            print "[+] Complex IF's simplified"
            flowGraph.preprocessWhileLoops()
            print "[+] WHILE loops preprocessed"
            flowGraph.simplifyAllCompound()
            print "[+] All compounds simplified"
            flowGraph.simplifyConsecutive()
            print "[+] Consecutives simplified"
            if len(flowGraph.nodes) == 1:
                r = flowGraph.nodes[flowGraph.root].code
            else:
                print "\n\n"
                print "!!!INCOMPLETE DISASSEMBLY!!!!"
                print "%d code block uncoalesced" % len(flowGraph.nodes)
                #r = '>>> Fatal error: could not structure control flow graph.'
                r = ""
                ordered_nodes = flowGraph.nodes.keys()
                ordered_nodes.sort()
                for n in ordered_nodes:
                    if len(flowGraph.nodes[n].code) == 0:
                        continue
                    r += "#[NODE: %s]\n%s\n" % (n, flowGraph.nodes[n].code)

            return indentText(r, startIndent)
        except:
            traceback.print_exc()
예제 #2
0
 def decompile(self, offset=0, startIndent=0):
     '''Entry point for the decompilation process.'''
     cb = self.disassembler.getAllCodeBlocks(offset)
     flowGraph = structure.getGraphFromCodeBlocks(cb, self.debugDraw)
     flowGraph.DFADecompile(self)
     flowGraph.simplifyComplexIFs()
     flowGraph.preprocessWhileLoops()
     flowGraph.simplifyAllCompound()
     flowGraph.simplifyConsecutive()
     if len(flowGraph.nodes) == 1:
         r = flowGraph.nodes[flowGraph.root].code
     else:
         # TODO: throw exception
         r = '>>> Fatal error: could not structure control flow graph.'
     return indentText(r, startIndent)
예제 #3
0
    def decompile(self, offset=0, startIndent=0, full=True):
        '''Entry point for the decompilation process.'''

        if not full:
            co = self.disassembler.co
            func = NewFunction(co)
            r = self.STORE(co.name.value, func, startIndent, True)
            return indentText(r, startIndent)
        else:
            cb = self.disassembler.getAllCodeBlocks(offset)
            flowGraph = structure.getGraphFromCodeBlocks(cb, self.debugDraw)
            flowGraph.DFADecompile(self)
            flowGraph.simplifyComplexIFs()
            flowGraph.preprocessWhileLoops()
            flowGraph.simplifyAllCompound()
            flowGraph.simplifyConsecutive()
            if len(flowGraph.nodes) == 1:
                r = flowGraph.nodes[flowGraph.root].code
            else:
                raise StructuringErrorException()
                #r = '>>> Fatal error: could not structure control flow graph.'
            return indentText(r, startIndent)
예제 #4
0
    def decompile(self, offset=0, startIndent=0, full=True):
        '''Entry point for the decompilation process.'''

        if not full:
            co = self.disassembler.co
            func = NewFunction(co)
            r = self.STORE(co.name.value, func, startIndent, True)
            return indentText(r, startIndent)
        else:
            cb = self.disassembler.getAllCodeBlocks(offset)
            flowGraph = structure.getGraphFromCodeBlocks(cb, self.debugDraw)
            flowGraph.DFADecompile(self)
            flowGraph.simplifyComplexIFs()
            flowGraph.preprocessWhileLoops()
            flowGraph.simplifyAllCompound()
            flowGraph.simplifyConsecutive()
            if len(flowGraph.nodes) == 1:
                r = flowGraph.nodes[flowGraph.root].code
            else:
                raise StructuringErrorException()
                #r = '>>> Fatal error: could not structure control flow graph.'
            return indentText(r, startIndent)
예제 #5
0
 def decompile(self, offset=0, startIndent=0):
     '''Entry point for the decompilation process.'''
     try:
         cb = self.disassembler.getAllCodeBlocks(offset)
         print "[+] All code blocks got"
         flowGraph = structure.getGraphFromCodeBlocks(cb, self.debugDraw)
         print "[+] Flow graph from code blocks got"
         flowGraph.DFADecompile(self)
         print "[+] DFA decompiled"
         flowGraph.simplifyComplexIFs()
         print "[+] Complex IF's simplified"
         flowGraph.preprocessWhileLoops()
         print "[+] WHILE loops preprocessed"
         flowGraph.simplifyAllCompound()
         print "[+] All compounds simplified"
         flowGraph.simplifyConsecutive()
         print "[+] Consecutives simplified"
         if len(flowGraph.nodes) == 1:
             r = flowGraph.nodes[flowGraph.root].code
         else:
             print "\n\n"
             print "!!!INCOMPLETE DISASSEMBLY!!!!"
             print "%d code block uncoalesced"%len(flowGraph.nodes)
             #r = '>>> Fatal error: could not structure control flow graph.'
             r=""
             ordered_nodes=flowGraph.nodes.keys()
             ordered_nodes.sort()
             for n in ordered_nodes:
                 if len(flowGraph.nodes[n].code) == 0:
                     continue
                 r += "#[NODE: %s]\n%s\n"%(n, flowGraph.nodes[n].code)
             
            
         return indentText(r, startIndent)
     except:
         traceback.print_exc()