예제 #1
0
파일: structure.py 프로젝트: zbx91/UnPyc
    def structureSingleLoop(self, n):
        '''
        @return: True, if loop was structured, False otherwise.

        '''
        (loope, ALe) = self.findLoopALEdge(n)
        (loop, AL) = (self.nodes[loope.toNode], self.nodes[ALe.toNode])
        if loop.forloop:
            (forloope, AFe) = self.findForAFEdge(loop)
            forloop = self.nodes[forloope.toNode]
            AF = self.nodes[AFe.toNode]
            if len(forloop.outgoing) == 1 and \
               forloop.outgoing[0].toNode == AF.name and \
               len(AF.outgoing) == 1 and AF.outgoing[0].toNode == AL.name:
                forloop.code = indentForText(forloop.code)
                if AF.code != '':
                    AF.code = 'else:\n' + indentText(AF.code, 1)
                self.removeEdge(loop, AF)
                self.removeEdge(n, AL)
                return True
            elif len(forloop.outgoing) == 1 and \
               forloop.outgoing[0].toNode == AF.name and \
               AF.name == AL.name:
                forloop.code = indentForText(forloop.code)
                self.removeEdge(loop, AF)
                self.removeEdge(n, AL)
                return True

        else:
            (te, fe) = self.findTrueFalseEdge(loop)
            (tn, fn) = (self.nodes[te.toNode], self.nodes[fe.toNode])
            if len(tn.outgoing) == 1 and tn.outgoing[0].toNode == fn.name and \
               len(fn.outgoing) == 1 and fn.outgoing[0].toNode == AL.name:
                loop.code = 'while ' + str(loop.condition) + ':\n'
                if tn.code == '': tn.code = 'pass\n'
                tn.code = indentText(tn.code, 1)
                if fn.code != '':
                    fn.code = 'else:\n' + indentText(fn.code, 1)
                self.removeEdge(loop, fn)
                self.removeEdge(n, AL)
                return True
            elif len(tn.outgoing) == 1 and tn.outgoing[0].toNode == fn.name and \
                 fn.name == AL.name:
                loop.code = 'while ' + str(loop.condition) + ':\n'
                if tn.code == '': tn.code = 'pass\n'
                tn.code = indentText(tn.code, 1)
                self.removeEdge(loop, fn)
                self.removeEdge(n, AL)
                return True
예제 #2
0
    def structureSingleLoop(self, n):
        '''
        @return: True, if loop was structured, False otherwise.

        '''
        #THIS ONLY WORKS IF optimizeJumps = True
        self.extra.append(n)
        #print "N: ",n 
        (loope, ALe) = self.findLoopALEdge(n)
        #print "LOOPE: %s"%(loope)
        #print "ALe: %s"%(ALe)
        (loop, AL) = (self.nodes[loope.toNode], self.nodes[ALe.toNode])
        #print "LOOP: %s"%(loop)
        #print "AL: %s"%(AL)
        
        #Rich mod change test condition to look for t/f edges not loop property
        
        if loop.forloop:
            
            (forloope, AFe) = self.findForAFEdge(loop)
            forloop = self.nodes[forloope.toNode]
            AF = self.nodes[AFe.toNode]
            #if len(forloop.outgoing) == 1 and \
            #   forloop.outgoing[0].toNode == AF.name and \
            #   len(AF.outgoing) == 1 and AF.outgoing[0].toNode == AL.name:
            if 1:
                
                forloop.code = indentForText(forloop.code)
                if AF.code != '':
                    AF.code = 'else:\n' + indentText(AF.code, 1)
                    
                
                self.removeEdge(loop, AF)
                self.removeEdge(n, AL)
                return True
        else:
            try:
                (te, fe) = self.findTrueFalseEdge(loop)
                (tn, fn) = (self.nodes[te.toNode], self.nodes[fe.toNode])
                if len(tn.outgoing) == 1 and tn.outgoing[0].toNode == fn.name and \
                   len(fn.outgoing) == 1 and fn.outgoing[0].toNode == AL.name:
                    loop.code = 'while ' + str(loop.condition) + ':\n'
                    if tn.code == '': tn.code = 'pass\n'
                    tn.code = indentText(tn.code, 1)
                    if fn.code != '':
                        fn.code = 'else:\n' + indentText(fn.code, 1)
                    self.removeEdge(loop, fn)
                    self.removeEdge(n, AL)
                    return True
            except Exception, err:
                print "[X] Rich exception caught", err
                traceback.print_exc()
                return False
예제 #3
0
    def structureSingleLoop(self, n):
        '''
        @return: True, if loop was structured, False otherwise.

        '''
        #THIS ONLY WORKS IF optimizeJumps = True
        self.extra.append(n)
        #print "N: ",n
        (loope, ALe) = self.findLoopALEdge(n)
        #print "LOOPE: %s"%(loope)
        #print "ALe: %s"%(ALe)
        (loop, AL) = (self.nodes[loope.toNode], self.nodes[ALe.toNode])
        #print "LOOP: %s"%(loop)
        #print "AL: %s"%(AL)

        #Rich mod change test condition to look for t/f edges not loop property

        if loop.forloop:

            (forloope, AFe) = self.findForAFEdge(loop)
            forloop = self.nodes[forloope.toNode]
            AF = self.nodes[AFe.toNode]
            #if len(forloop.outgoing) == 1 and \
            #   forloop.outgoing[0].toNode == AF.name and \
            #   len(AF.outgoing) == 1 and AF.outgoing[0].toNode == AL.name:
            if 1:

                forloop.code = indentForText(forloop.code)
                if AF.code != '':
                    AF.code = 'else:\n' + indentText(AF.code, 1)

                self.removeEdge(loop, AF)
                self.removeEdge(n, AL)
                return True
        else:
            try:
                (te, fe) = self.findTrueFalseEdge(loop)
                (tn, fn) = (self.nodes[te.toNode], self.nodes[fe.toNode])
                if len(tn.outgoing) == 1 and tn.outgoing[0].toNode == fn.name and \
                   len(fn.outgoing) == 1 and fn.outgoing[0].toNode == AL.name:
                    loop.code = 'while ' + str(loop.condition) + ':\n'
                    if tn.code == '': tn.code = 'pass\n'
                    tn.code = indentText(tn.code, 1)
                    if fn.code != '':
                        fn.code = 'else:\n' + indentText(fn.code, 1)
                    self.removeEdge(loop, fn)
                    self.removeEdge(n, AL)
                    return True
            except Exception, err:
                print "[X] Rich exception caught", err
                traceback.print_exc()
                return False