Example #1
0
def compute_metrics(files,metrics,verbose=0):
    list_dict=[]

    try :

        for f in files:
            c =  convert(f,verbose)
            d = {(0,"name"):f[f.rfind(os.sep)+len(os.sep):]}
            if metrics["halstead"] :
                d[(1,"halstead")]= halstead(c)
            if metrics["mccabe"]:
                d[(2,"mccabe")]= mccabe(c)
            if metrics["harrison"]:
                d[(3,"harrison")]= harrison(c)
            if metrics["oviedo"]:
                d[(4,"oviedo")]= oviedo(c)
            if metrics["henry"]:
                d[(5,"henry")]= henry(c)
            list_dict.append(d)
    except Exception,e:
        print traceback.print_exc()
        print e
        print "Failed to compute metrics on  "+format(files)
Example #2
0
#!/usr/bin/env python
import sys
import traceback
import os

from jshadobf.common.convert import convert
from jshadobf.transformations.add_if_statement import add_if_statement

if __name__ == "__main__":
    #input = sys.stdin.read()
    if len(sys.argv) > 1:
        prg = sys.argv[1]
    else:
        sys.exit()

    c = convert(prg)
    for _ in range(10):
        d = add_if_statement(c)
    print d
Example #3
0



if __name__=="__main__":
    import sys
    import optparse
  
    optparser = optparse.OptionParser(usage="usage: %prog [options]")
    optparser.add_option("-a" , "--ast" ,dest="ast",default=False, action='store_true',help="print the tree")
    optparser.add_option("-c" , "--cfg" ,dest="cfg",default=False, action='store_true',help="print the file")
    optparser.add_option("-f" , "--file" ,dest="file",default="", help="file name")
    optparser.add_option("-o" , "--output" ,dest="fileo",default="output", help="output basename")
    optparser.add_option("-v" , "--verbose" ,dest="verbose",default=False, action='store_true',help="verbose")
  
    (option , arg ) = optparser.parse_args(sys.argv)
    if option.file == "":
        optparser.print_help()
        sys.exit()
  
    c =  convert(option.file)
    if option.ast:
        gen_dot_file(c,filename=option.fileo+".ast.dot")
        os.system("dot -Tpng -o "+option.fileo+".ast.png "+ option.fileo+".ast.dot")
    if option.cfg:
        cfg = cfg_builder(c)
#    print RED, cfg,BLACK
        cfg_dot_file(cfg,filename=option.fileo+".cfg.dot")
        os.system("dot -Tpng -o "+option.fileo+".cfg.png "+ option.fileo+".cfg.dot")
    
Example #4
0
        temp = temp.split(" ")[-1]
        if temp != name:
            try:
                times = int(temp)
            except Exception, e:
                print e

        for tt in TRANSFORMATIONS:
            if tt.__name__.find(name) != -1:
                to_apply.append((tt, times))

    if option.file == "":

        c = convert_string(sys.stdin.read(), option.verbose > 2)
    else:
        c = convert(option.file, option.verbose > 2)
    d = c
    #  print to_apply
    for transfo, num in to_apply:
        if option.verbose > 1:
            print "Applying transfo : %s , times %d " % (transfo.__name__, num)
        for i in xrange(num):
            d = transfo(d, option.verbose)

    for i in xrange(option.all):
        for transfo in TRANSFORMATIONS:
            d = transfo(d, option.verbose)

    if option.printtree:
        print_level_order(d, option.verbose)
Example #5
0
 def convert(self, srccode=None):
     print self.path
     if srccode == None:
         self.tree = convert(self.path)
     else:
         self.tree = convert_string(srccode)