Exemple #1
0
    def process_sources(self):

        splitted_source = ""

        for file_name,file_source in self.project_files:

            ast_source = remove_Directives(file_source)

            # print "@file_source[%s]"%file_name #,file_source
            try:
                # ast = get_ast_from_text(file_source)
                ast = None
            except Exception, e:
                print e
                debuglines= 8
                line = int(str(e).split(':')[1])
                for i in range(debuglines):
                    try:
                        print "INFO file[%s] line[%s]: %s" % (file_name,line+i-debuglines/2+1,file_source.split('\n')[line+i-debuglines/2])
                    except:
                        pass
                ast = None
            if ast is not None:
                #ast.show()
                # print ast.ext
                pass

            holsted, mackkeib,jilb, sloc = (
                function(file_source,ast) for function in (
                    get_holsted,
                    get_mackkeib,
                    get_jilb,
                    get_sloc
                )
            )

            #BUF to fix
            if holsted != (-1,-1,-1):
                splitted_source += "\n"+file_source
            
            vulns = get_vulns_count(file_source,ast)
        
            metrix = Metrix(
                            holsted = str(holsted),
                            mackkeib = str(mackkeib),
                            jilb = str(jilb),
                            sloc = str(sloc)
                        )
            metrix.put()
            vulnerability = Vulnerability(
                                    vulnerability = str(vulns)
                                )
            vulnerability.put()

            potential = self.calc_potential(
                                    holsted[0],
                                    mackkeib,
                                    jilb,
                                    vulns
                                )
            p = self.calc_p(potential)

            short = self.project.short + md5(file_name).hexdigest()

            # print ("filename & sloc & holsted & mackkeib & jilb & vulns & potential & p")            
            print ("{} & {} & {} & {} & {} & {} & {} & {}\\\\".format(
                    file_name,
                    sloc,
                    holsted[0],
                    mackkeib,
                    jilb,
                    vulns,
                    potential,
                    p
                ))
            source = Source(
                    project = self.project,
                    file_name = file_name,
                    file_source = file_source,
                    file_db_item = SourceFile(
                            short = short,
                            project = self.project,
                            name = file_name,
                            source = file_source,
                            metrix = metrix,
                            vulnerability = vulnerability,
                            potential = potential,
                            p = p
                        ),
                    holsted = holsted,
                    mackkeib = mackkeib,
                    jilb = jilb,
                    sloc = sloc,
                    vulns = vulns,
                    potential = potential,
                    p = p   
                )
            source.file_db_item.put()
            self.files.append(source)
Exemple #2
0
    def process_sources(self):

        splitted_source = ""

        for file_name, file_source in self.project_files:

            ast_source = remove_Directives(file_source)

            # print "@file_source[%s]"%file_name #,file_source
            try:
                # ast = get_ast_from_text(file_source)
                ast = None
            except Exception, e:
                print e
                debuglines = 8
                line = int(str(e).split(':')[1])
                for i in range(debuglines):
                    try:
                        print "INFO file[%s] line[%s]: %s" % (
                            file_name, line + i - debuglines / 2 + 1,
                            file_source.split('\n')[line + i - debuglines / 2])
                    except:
                        pass
                ast = None
            if ast is not None:
                #ast.show()
                # print ast.ext
                pass

            holsted, mackkeib, jilb, sloc = (function(
                file_source, ast) for function in (get_holsted, get_mackkeib,
                                                   get_jilb, get_sloc))

            #BUF to fix
            if holsted != (-1, -1, -1):
                splitted_source += "\n" + file_source

            vulns = get_vulns_count(file_source, ast)

            metrix = Metrix(holsted=str(holsted),
                            mackkeib=str(mackkeib),
                            jilb=str(jilb),
                            sloc=str(sloc))
            metrix.put()
            vulnerability = Vulnerability(vulnerability=str(vulns))
            vulnerability.put()

            potential = self.calc_potential(holsted[0], mackkeib, jilb, vulns)
            p = self.calc_p(potential)

            short = self.project.short + md5(file_name).hexdigest()

            # print ("filename & sloc & holsted & mackkeib & jilb & vulns & potential & p")
            print("{} & {} & {} & {} & {} & {} & {} & {}\\\\".format(
                file_name, sloc, holsted[0], mackkeib, jilb, vulns, potential,
                p))
            source = Source(project=self.project,
                            file_name=file_name,
                            file_source=file_source,
                            file_db_item=SourceFile(
                                short=short,
                                project=self.project,
                                name=file_name,
                                source=file_source,
                                metrix=metrix,
                                vulnerability=vulnerability,
                                potential=potential,
                                p=p),
                            holsted=holsted,
                            mackkeib=mackkeib,
                            jilb=jilb,
                            sloc=sloc,
                            vulns=vulns,
                            potential=potential,
                            p=p)
            source.file_db_item.put()
            self.files.append(source)
Exemple #3
0
        holsted = get_holsted(splitted_source,None)

        mackkeib = get_mackkeib(splitted_source,None)

        jilb = get_jilb(splitted_source,None)

        vulns = reduce(lambda x,y: (x+y), map(lambda x: x.vulns, self.files))

        potential = reduce(lambda x,y : x if x>y else y, map(lambda x: x.potential, self.files))

        p = reduce(lambda x,y : x if x>y else y, map(lambda x: x.p, self.files))

        self.project.potential = potential
        self.project.p = p

        metrix = Metrix(
                sloc = str(sloc),
                holsted = str(holsted),
                mackkeib = str(mackkeib),
                jilb = str(jilb)
            )
        metrix.put()
        self.project.metrix = metrix
        vulnerability = Vulnerability(
                vulnerability = str(vulns)
            )
        vulnerability.put()
        self.project.vulnerability = vulnerability


__author__ = 'andrew.vasyltsiv'
Exemple #4
0
        sloc = reduce(lambda x, y: x + y, map(lambda x: x.sloc, self.files))

        holsted = get_holsted(splitted_source, None)

        mackkeib = get_mackkeib(splitted_source, None)

        jilb = get_jilb(splitted_source, None)

        vulns = reduce(lambda x, y: (x + y), map(lambda x: x.vulns,
                                                 self.files))

        potential = reduce(lambda x, y: x if x > y else y,
                           map(lambda x: x.potential, self.files))

        p = reduce(lambda x, y: x if x > y else y,
                   map(lambda x: x.p, self.files))

        self.project.potential = potential
        self.project.p = p

        metrix = Metrix(sloc=str(sloc),
                        holsted=str(holsted),
                        mackkeib=str(mackkeib),
                        jilb=str(jilb))
        metrix.put()
        self.project.metrix = metrix
        vulnerability = Vulnerability(vulnerability=str(vulns))
        vulnerability.put()
        self.project.vulnerability = vulnerability

__author__ = 'andrew.vasyltsiv'