示例#1
0
文件: concrete.py 项目: Auzzy/pystick
def generate_injected_funcs():
	import funcs
	funcs_src = "{0}.py".format(splitext(funcs.__file__)[0])
	tree_str = open(funcs_src,'r').read()
	del funcs
	tree = parseAST(tree_str)
	return tree.body
示例#2
0
文件: dart.py 项目: Auzzy/school
def run(program_text, func):
	global all_linear,forcing_ok,stack,directed,solutions,path_constraints

	all_linear,forcing_ok = True,True
	solutions = {}
	path_constraints = {}
	program = parseAST(program_text)
	program.body = [node for node in program.body if type(node) is FunctionDef and node.name==func.func_name]
	func_args = func.func_code.co_varnames[:func.func_code.co_argcount]

	import unparseAST
	print unparseAST.to_source(program)
	print
	print

	while True:
		stack = []
		
		inputs = random_inputs(func_args)
		first = inputs

		directed = True
	
		while directed:
			try:
				inputs = execute_program(program,func,inputs)
			except KeyboardInterrupt:
				raise
			except:
				from sys import exc_info
				from traceback import print_tb
				print >> sys.stderr, exc_info()
				print_tb(exc_info()[-1])
				if forcing_ok:
					print "Bug found"
					exit()
				else:
					forcing_ok = True
	
		if first:
			solutions[first] = get_solutions(path_constraints[first],first.keys())
			solutions[first] = filter_inputs(solutions[first],first.keys())

		if all_linear:
			break

	
	for key in solutions:
		print key
		for inputs in sorted(solutions[key]):
			print inputs
		print
	

	return solutions
示例#3
0
def run(program_text, func):
    global all_linear, forcing_ok, stack, directed, solutions, path_constraints

    all_linear, forcing_ok = True, True
    solutions = {}
    path_constraints = {}
    program = parseAST(program_text)
    program.body = [
        node for node in program.body
        if type(node) is FunctionDef and node.name == func.func_name
    ]
    func_args = func.func_code.co_varnames[:func.func_code.co_argcount]

    while True:
        stack = []

        inputs = random_inputs(func_args)
        first = inputs

        directed = True

        while directed:
            try:
                inputs = execute_program(program, func, inputs)
            except KeyboardInterrupt:
                raise
            except:
                from sys import exc_info
                from traceback import print_tb
                print >> sys.stderr, exc_info()
                print_tb(exc_info()[-1])
                if forcing_ok:
                    print "Bug found"
                    exit()
                else:
                    forcing_ok = True

        if first:
            solutions[first] = get_solutions(path_constraints[first],
                                             first.keys())
            solutions[first] = filter_inputs(solutions[first], first.keys())

        if all_linear:
            break

    return solutions
示例#4
0
文件: logging.py 项目: Auzzy/school
def log(program_text, func, input_list):
	program = parseAST(program_text)
	program.body = [node for node in program.body if type(node) is FunctionDef and node.name==func.func_name]
	func_args = func.func_code.co_varnames[:func.func_code.co_argcount]

	instrumented = Instrument().visit(program)

	trace = []

	if input_list:
		for inputs in input_list:
			env = execute_func(instrumented,func,inputs)
			trace.append(env[Log.log_dict])
	else:
		env = execute_func(instrumented,func,{})
		trace.append(env[Log.log_dict])

	return trace
示例#5
0
文件: logging.py 项目: Auzzy/pystick
def log(program_text, func, input_list):
    program = parseAST(program_text)
    program.body = [
        node for node in program.body
        if type(node) is FunctionDef and node.name == func.func_name
    ]
    func_args = func.func_code.co_varnames[:func.func_code.co_argcount]

    instrumented = Instrument().visit(program)

    trace = []

    if input_list:
        for inputs in input_list:
            env = execute_func(instrumented, func, inputs)
            trace.append(env[Log.log_dict])
    else:
        env = execute_func(instrumented, func, {})
        trace.append(env[Log.log_dict])

    return trace
示例#6
0
def log(program_text, func, input_list):
	program = parseAST(program_text)
	program.body = [node for node in program.body if type(node) is FunctionDef and node.name==func.func_name]
	func_args = func.func_code.co_varnames[:func.func_code.co_argcount]

	instrumented = Instrument().visit(program)
	print "instrumented"
	import unparseAST
	print unparseAST.to_source(instrumented)

	trace = []

	if input_list:
		for inputs in input_list:
			env = execute_func(instrumented,func,inputs)
			trace.append(env[Log.log_dict])
			
			"""
			for point in env[Log.log_dict]:
				print point
				print env[Log.log_dict][point]
			print
			"""
	else:
		env = execute_func(instrumented,func,{})
		trace.append(env[Log.log_dict])
	
	"""
	print
	for trace_points in trace:
		for trace_point in trace_points:
			print str(trace_point) + ": " + str(trace_points[trace_point])
		print
	"""

	return trace
示例#7
0
文件: dart.py 项目: Auzzy/school
def run(program_text, func):
	global all_linear,forcing_ok,stack,directed,solutions,path_constraints

	all_linear,forcing_ok = True,True
	solutions = {}
	path_constraints = {}
	program = parseAST(program_text)
	program.body = [node for node in program.body if type(node) is FunctionDef and node.name==func.func_name]
	func_args = func.func_code.co_varnames[:func.func_code.co_argcount]

	while True:
		stack = []
		inputs = random_inputs(func_args)
		first = inputs
		directed = True
	
		while directed:
			try:
				inputs = execute_program(program,func,inputs)
			except KeyboardInterrupt:
				raise
			except:
				if forcing_ok:
					print "Bug found"
					exit()
				else:
					forcing_ok = True
	
		if first:
			solutions[first] = get_solutions(path_constraints[first],first.keys())
			solutions[first] = filter_inputs(solutions[first],first.keys())

		if all_linear:
			break

	return solutions
def process(wf, args):
    log = wf.logger

    try:
        ast = parseAST(args)
    except ASTSyntaxError as e:
        log.debug('opps')
        wf.send_feedback()
        return

    target_time = arrow.now()

    presetFormat = None

    for func in ast:
        funcName = func[0]
        args = []
        if len(func) > 1:
            args = func[1:]

        if funcName == 'reset':
            if len(args) > 0:
                try:
                    target_time = arrow.get(args[0]).to('local')
                except ValueError:
                    target_time = arrow.get(args[0] / 1000).to('local')
            else:
                target_time = arrow.now()
            continue

        if funcName == 'set':
            params = {}
            if args[0] == 'timezone':
                timezone = str(abs(int(args[1]))) + ':00'
                if abs(args[1]) < 10:
                    timezone = '0' + timezone

                if args[1] < 0:
                    timezone = '-' + timezone
                else:
                    timezone = '+' + timezone

                log.debug(timezone)
                target_time = target_time.to(timezone)

            else:
                params[args[0]] = int(args[1])
                target_time = target_time.replace(**params)
            continue

        if funcName == 'shift':
            params = {}
            params[args[1] + 's'] = int(args[0])
            target_time = target_time.replace(**params)
            continue

        if funcName == 'start_of':
            target_time = target_time.floor(args[0])
            continue

        if funcName == 'end_of':
            target_time = target_time.ceil(args[0])
            continue

        if funcName == 'format' and len(args) > 0:
            presetFormat = ' '.join(args)

    if presetFormat is not None:
        add_item(wf, target_time.format(presetFormat), presetFormat)
    else:
        # Add an item to Alfred feedback
        timestamp = str(int(time.mktime(target_time.datetime.timetuple()) * 1e3 + target_time.datetime.microsecond / 1e3))
        wf.add_item(timestamp, subtitle = u'Timestamp, ' + target_time.humanize(), arg = timestamp, valid = True)

        formats = moment_format.load_format(wf)
        if len(formats) == 0:
            add_item(wf, target_time.format('YYYY-MM-DD HH:mm:ss ZZ'), 'Standard format, you can use "format-moment" to add your format.')
        else:
            for formatStr in formats:
                value = target_time.format(formatStr)
                wf.add_item(value, subtitle = 'Saved format: "' + formatStr + '"', arg = value, valid = True)

    # Send output to Alfred
    wf.send_feedback()
示例#9
0
def process(wf, args):
    log = wf.logger

    try:
        ast = parseAST(args)
    except ASTSyntaxError as e:
        log.debug('opps')
        wf.send_feedback()
        return

    target_time = arrow.now()

    presetFormat = None

    for func in ast:
        funcName = func[0]
        args = []
        if len(func) > 1:
            args = func[1:]

        if funcName == 'reset':
            if len(args) > 0:
                try:
                    target_time = arrow.get(args[0]).to('local')
                except ValueError:
                    target_time = arrow.get(args[0] / 1000).to('local')
            else:
                target_time = arrow.now()
            continue

        if funcName == 'set':
            params = {}
            if args[0] == 'timezone':
                timezone = str(abs(int(args[1]))) + ':00'
                if abs(args[1]) < 10:
                    timezone = '0' + timezone

                if args[1] < 0:
                    timezone = '-' + timezone
                else:
                    timezone = '+' + timezone

                log.debug(timezone)
                target_time = target_time.to(timezone)

            else:
                params[args[0]] = int(args[1])
                target_time = target_time.replace(**params)
            continue

        if funcName == 'shift':
            params = {}
            params[args[1] + 's'] = int(args[0])
            target_time = target_time.replace(**params)
            continue

        if funcName == 'start_of':
            target_time = target_time.floor(args[0])
            continue

        if funcName == 'end_of':
            target_time = target_time.ceil(args[0])
            continue

        if funcName == 'format' and len(args) > 0:
            presetFormat = ' '.join(args)

    if presetFormat is not None:
        add_item(wf, target_time.format(presetFormat), presetFormat)
    else:
        # Add an item to Alfred feedback
        timestamp = str(
            int(
                time.mktime(target_time.datetime.timetuple()) * 1e3 +
                target_time.datetime.microsecond / 1e3))
        wf.add_item(timestamp,
                    subtitle=u'Timestamp, ' + target_time.humanize(),
                    arg=timestamp,
                    valid=True)

        formats = moment_format.load_format(wf)
        if len(formats) == 0:
            add_item(
                wf, target_time.format('YYYY-MM-DD HH:mm:ss ZZ'),
                'Standard format, you can use "format-moment" to add your format.'
            )
        else:
            for formatStr in formats:
                value = target_time.format(formatStr)
                wf.add_item(value,
                            subtitle='Saved format: "' + formatStr + '"',
                            arg=value,
                            valid=True)

    # Send output to Alfred
    wf.send_feedback()
示例#10
0
文件: concrete.py 项目: Auzzy/school
	# Begin debugging stuff
	# import unparseAST
	# print unparseAST.to_source(tree)
	# print

	print "CONCRETE STATE"
	env_dict = env["__env_dict"]
	for lineno in sorted(env_dict.keys()):
		print '{0}: {1}'.format(lineno,env_dict[lineno])
	print
	#End debugging stuff

	return env["__env_dict"]

if __name__=="__main__":
	from sys import argv
	from os.path import basename,splitext
	from imp import load_source as load_module
	
	file_name,func_name = argv[1:]

	program_text = open(file_name,'r').read()
	user_mod = load_module(splitext(basename(file_name))[0],file_name)
	user_func = getattr(user_mod,func_name)
	program = parseAST(program_text)
	program.body = [node for node in program.body if type(node) is FunctionDef and node.name==user_func.func_name]

	#eval(program,user_func,{"x":6})
	eval(program,user_func,{})
示例#11
0
文件: temp.py 项目: Auzzy/school
from util import *
from ast import parse as parseAST

file_name = "test.py"

program_text = open(file_name, "r").read()
tree = parseAST(program_text)
print_tree_info(tree)