示例#1
0
def update(msg: Msg, model: Model) -> Tuple[Model, List[Cmd[Any]]]:
    """
    Given an inbound message and the current robot model, produce a new model
    and a list of commands to execute.
    """

    if isinstance(msg, Actions):
        # Received actions from the Q-algorithm node.

        parsed = [parse_action(act) for act in msg.actions]
        new_actions = [act for act in parsed if act is not None]

        if not new_actions:
            print("WARN: None of the received optimal actions could be parsed")
            return (model, cmd.none)

        # Add received actions to the action queue.

        actions = model.actions + new_actions
        return (replace(model, actions=actions), cmd.none)

    if (action := head(model.actions)) is None:
        # No actions currently in the queue; do nothing.

        return (model, cmd.none)
示例#2
0
def symbolic (filee, inputs, analysis, jalangi=util.DEFAULT_INSTALL):
    try:
        shutil.rmtree("jalangi_tmp")
    except: pass
    os.mkdir("jalangi_tmp")
    os.putenv("JALANGI_HOME", jalangi.get_home())
    os.chdir("jalangi_tmp")
    (instrumented_f, out) = instrument(os.path.join(os.pardir,filee), jalangi=jalangi)
    i = 0
    iters = 1
    while i <= iters and i <= inputs:
        try:                    # Ignore failures on first iteration
            os.remove("inputs.js")
        except:
            pass
        if not os.path.isfile("inputs.js"):
            util.mkempty("inputs.js")
        util.run_node_script_std(jalangi.symbolic_script(), analysis, os.path.join(os.path.dirname(os.path.join(os.pardir,filee) + ".js"),instrumented_f), jalangi=jalangi, savestderr=True)
        try:
            iters = int(util.head("jalangi_tail",1)[0])
        except: pass
        i = i + 1
    if iters == inputs:
        print "{}.js passed".format(filee)
        with open("../jalangi_sym_test_results", 'a') as f:
         f.write("{}.js passed\n".format(filee))
    else:
        print "{}.js failed".format(filee)
        with open("../jalangi_sym_test_results", 'a') as f:
         f.write("{}.js failed\n".format(filee))
    print "Tests Generated = {}".format(iters)
示例#3
0
def concolic (filee, inputs, instrumented, line_range, jalangi=util.DEFAULT_INSTALL):
    try:
        shutil.rmtree("jalangi_tmp")
    except: pass
    os.mkdir("jalangi_tmp")
    os.mkdir("jalangi_tmp/out")
    os.putenv("JALANGI_HOME", jalangi.get_home())
    os.chdir("jalangi_tmp")
    (instrumented_f, out) = instrument(os.path.join(os.pardir,filee), jalangi=jalangi) if (instrumented == "") else (instrumented, "")
    i = 0
    iters = 0
    while i <= iters and i <= inputs:
        try: # Ignore failures on first iteration
            os.remove("inputs.js")
            shutil.copy("jalangi_inputs{}.js".format(i), "inputs.js")
        except:
            pass
        if not os.path.isfile("inputs.js"):
            util.mkempty("inputs.js")
        print "==== Input {} ====".format(i)
        print "---- Recording execution of {} ----".format(filee)
        print record(os.path.join(os.pardir,filee),instrumented_f,jalangi=jalangi)
        print "---- Replaying {} ----".format(filee)
        print replay(jalangi=jalangi,analysis=[jalangi.concolic_analysis()])
        
        print parse_stacktrace(str(iters),instrumented_f,line_range,jalangi=jalangi)
        with open(os.path.abspath(os.pardir) + '/jalangi_tmp/jalangi_stop', 'r') as myfile:
    		data=myfile.read().replace('\n', '')
    	if data == "true":
    		break

        try:
            iters = int(util.head("jalangi_tail",1)[0])
        except: pass
        i = i + 1
        
    for i in glob.glob("jalangi_inputs*"):
        print "*** Generated (jalangi_tmp/{}:1:1) for ({}.js:1:1)".format(i,filee)
    iters = iters + 1
    if iters == inputs:
        print "{}.js passed".format(filee)
        with open("../jalangi_sym_test_results", 'a') as f:
         f.write("{}.js passed\n".format(filee))
    else:
        print "{}.js failed".format(filee)
        with open("../jalangi_sym_test_results", 'a') as f:
         f.write("{}.js failed\n".format(filee))
    util.move_coverage(jalangi)
示例#4
0
def concolic(filee, inputs, jalangi=util.DEFAULT_INSTALL):
    try:
        shutil.rmtree("jalangi_tmp")
    except:
        pass
    os.mkdir("jalangi_tmp")
    os.mkdir("jalangi_tmp/out")
    os.putenv("JALANGI_HOME", jalangi.get_home())
    os.chdir("jalangi_tmp")
    (instrumented_f, out) = instrument(os.path.join(os.pardir, filee),
                                       jalangi=jalangi)
    i = 0
    iters = 0
    while i <= iters and i <= inputs:
        try:  # Ignore failures on first iteration
            os.remove("inputs.js")
            shutil.copy("jalangi_inputs{}.js".format(i), "inputs.js")
        except:
            pass
        if not os.path.isfile("inputs.js"):
            util.mkempty("inputs.js")
        print "==== Input {} ====".format(i)
        print "---- Recording execution of {} ----".format(filee)
        print record(os.path.join(os.pardir, filee),
                     instrumented_f,
                     jalangi=jalangi)
        print "---- Replaying {} ----".format(filee)
        print replay(jalangi=jalangi, analysis=[jalangi.concolic_analysis()])

        try:
            iters = int(util.head("jalangi_tail", 1)[0])
        except:
            pass
        i = i + 1

    for i in glob.glob("jalangi_inputs*"):
        print "*** Generated (jalangi_tmp/{}:1:1) for ({}.js:1:1)".format(
            i, filee)
    iters = iters + 1
    if iters == inputs:
        print "{}.js passed".format(filee)
        with open("../jalangi_sym_test_results", 'a') as f:
            f.write("{}.js passed\n".format(filee))
    else:
        print "{}.js failed".format(filee)
        with open("../jalangi_sym_test_results", 'a') as f:
            f.write("{}.js failed\n".format(filee))
    util.move_coverage(jalangi)
示例#5
0
def concolic (filee, inputs, jalangi=util.DEFAULT_INSTALL):
    try:
        shutil.rmtree("jalangi_tmp")
    except: pass
    os.mkdir("jalangi_tmp")
    os.mkdir("jalangi_tmp/out")
    os.putenv("JALANGI_HOME", jalangi.get_home())
    os.chdir("jalangi_tmp")
    (instrumented_f, out) = instrument(os.path.join(os.pardir,filee), jalangi=jalangi)
    i = 0
    iters = 0
    while i <= iters and i <= inputs:
        try: # Ignore failures on first iteration
            os.remove("inputs.js")
            shutil.copy("jalangi_inputs{}.js".format(i), "inputs.js")
        except:
            pass
        if not os.path.isfile("inputs.js"):
            util.mkempty("inputs.js")
        print "==== Input {} ====".format(i)
        print "---- Recording execution of {} ----".format(filee)
        os.putenv("JALANGI_MODE", "record")
        os.putenv("JALANGI_ANALYSIS", "none")
        util.run_node_script_std(os.path.join(os.path.dirname(os.path.join(os.pardir,filee) + ".js"),instrumented_f), jalangi=jalangi)
        print "---- Replaying {} ----".format(filee)
        os.putenv("JALANGI_MODE", "replay")
        os.putenv("JALANGI_ANALYSIS", "analyses/concolic/SymbolicEngine")
        util.run_node_script_std(jalangi.replay_script(), jalangi=jalangi)
        
        try:
            iters = int(util.head("jalangi_tail",1)[0])
        except: pass
        i = i + 1
        
    for i in glob.glob("jalangi_inputs*"):
        print "*** Generated (jalangi_tmp/{}:1:1) for ({}.js:1:1)".format(i,filee)
    iters = iters + 1
    if iters == inputs:
        print "{}.js passed".format(filee)
        with open("../jalangi_sym_test_results", 'a') as f:
         f.write("{}.js passed\n".format(filee))
    else:
        print "{}.js failed".format(filee)
        with open("../jalangi_sym_test_results", 'a') as f:
         f.write("{}.js failed\n".format(filee))
    util.move_coverage(jalangi)
示例#6
0
def symbolic(filee, inputs, analysis, jalangi=util.DEFAULT_INSTALL):
    try:
        shutil.rmtree("jalangi_tmp")
    except:
        pass
    os.mkdir("jalangi_tmp")
    os.putenv("JALANGI_HOME", jalangi.get_home())
    os.chdir("jalangi_tmp")
    (instrumented_f, out) = instrument(os.path.join(os.pardir, filee),
                                       jalangi=jalangi)
    i = 0
    iters = 1
    while i <= iters and i <= inputs:
        try:  # Ignore failures on first iteration
            os.remove("inputs.js")
        except:
            pass
        if not os.path.isfile("inputs.js"):
            util.mkempty("inputs.js")
        util.run_node_script_std(
            jalangi.symbolic_script(),
            analysis,
            os.path.join(
                os.path.dirname(os.path.join(os.pardir, filee) + ".js"),
                instrumented_f),
            jalangi=jalangi,
            savestderr=True)
        try:
            iters = int(util.head("jalangi_tail", 1)[0])
        except:
            pass
        i = i + 1
    if iters == inputs:
        print "{}.js passed".format(filee)
        with open("../jalangi_sym_test_results", 'a') as f:
            f.write("{}.js passed\n".format(filee))
    else:
        print "{}.js failed".format(filee)
        with open("../jalangi_sym_test_results", 'a') as f:
            f.write("{}.js failed\n".format(filee))
    print "Tests Generated = {}".format(iters)
示例#7
0
def concolic_tgn (filee, inputs, jalangi=util.DEFAULT_INSTALL):
    print inputs
    try:
        shutil.rmtree("jalangi_tmp")
    except: pass
    os.mkdir("jalangi_tmp")
    os.mkdir("jalangi_tmp/out")
    os.putenv("JALANGI_HOME", jalangi.get_home())
    os.chdir("jalangi_tmp")
    (instrumented_f, out) = instrument(os.path.join(os.pardir,filee), jalangi=jalangi)
    i = 0
    iters = 0
    while i <= iters and i <= inputs:
        try: # Ignore failures on first iteration
            os.remove("inputs.js")
            shutil.copy("jalangi_inputs{}.js".format(i), "inputs.js")
        except:
            pass
        if not os.path.isfile("inputs.js"):
            util.mkempty("inputs.js")
        print "==== Input {} ====".format(i)
        print "---- Recording execution of {} ----".format(filee)
        output = record(os.path.join(os.pardir,filee),instrumented_f,jalangi=jalangi)

        with open("jalangi_outputs{}.js".format(i), 'w') as output_f:
            output_f.write(output);

        print output
        print "---- Replaying {} ----".format(filee)
        print replay(jalangi=jalangi,analysis=[jalangi.concolic_analysis()])

        try:
            iters = int(util.head("jalangi_tail",1)[0])
        except: pass
        i = i + 1

    for i in glob.glob("jalangi_inputs*"):
        print "*** Generated (jalangi_tmp/{}:1:1) for ({}.js:1:1)".format(i,filee)
    iters = iters + 1
    util.move_coverage(jalangi)
示例#8
0
def concolic (filee, inputs, jalangi=util.DEFAULT_INSTALL):
    try:
        shutil.rmtree("jalangi_tmp")
    except: pass
    os.mkdir("jalangi_tmp")
    os.mkdir("jalangi_tmp/out")
    os.putenv("JALANGI_HOME", jalangi.get_home())
    os.chdir("jalangi_tmp")
    (instrumented_f, out) = instrument(os.path.join(os.pardir,filee), jalangi=jalangi)
    i = 0
    iters = 0
    mismatch = False
    while i <= iters and i <= inputs:
        try:                    # Ignore failures on first iteration
            os.remove("inputs.js")
            shutil.copy("jalangi_inputs{}.js".format(i), "inputs.js")
        except:
            pass
        if not os.path.isfile("inputs.js"):
            util.mkempty("inputs.js")
        print "==== Input {} ====".format(i)
        print "---- Runing without instrumentation ----"
        try:
            os.remove("jalangi_trace")
        except:
            pass
        norm = util.run_node_script(os.path.join(os.pardir,filee + ".js"), jalangi=jalangi, savestderr=True)
        #(open("jalangi_normal", "w")).write(norm)
        print "---- Recording execution of {} ----".format(filee)
        rec = record(os.path.join(os.pardir,filee), instrumented_f)
        print "---- Replaying {} ----".format(filee)
        os.putenv("JALANGI_MODE", "replay")
        os.putenv("JALANGI_ANALYSIS", "analyses/concolic/SymbolicEngine")
        rep = replay()
        (open("jalangi_replay", "w")).write(rep)
        print rep
	try:
		wcl = util.count_lines("jalangi_trace")
	
		with open("../jalangi_test_results", 'a') as f:
		    f.write("# of lines in jalangi_trace for {}: {}".format(filee,str(wcl)))
		    f.write("\n")
	except: pass	
        if norm != rep: #TODO: Factor out this.
            import difflib
            with open("../jalangi_test_results", 'a') as f:
                f.write("\n")
                for line in difflib.unified_diff(norm.splitlines(1), rec.splitlines(1), fromfile='normal.{}'.format(filee), tofile='replay.{}'.format(filee)):
                    f.write(line)
        if rec != rep:
            import difflib
            with open("../jalangi_test_results", 'a') as f:
                f.write("\n")
                for line in difflib.unified_diff(rec.splitlines(1), rep.splitlines(1), fromfile='replay.{}'.format(filee), tofile='record.{}'.format(filee)):
                    f.write(line)
	
        try:
            iters = int(util.head("jalangi_tail",1)[0])
        except: pass
        i = i + 1
        
    for i in glob.glob("jalangi_inputs*"):
        print "*** Generated ({}:1:1) for ({}.js:1:1)".format(os.path.abspath(i),filee)
    iters = iters + 1
    if iters == inputs:
        print "{}.js passed".format(filee)
    else:
        print "{}.js failed".format(filee)
    util.move_coverage(jalangi)
示例#9
0
import pcapy as pc
import struct
import util
import TCPDecode
import UDPDecode
import IPv4Decode
import EthernetDecode
import csv

reader = pc.open_offline('./data/22_02.pcap')
f = open('./data/data.csv', 'w', encoding='utf-8', newline='')
csvWriter = csv.writer(f)
csvWriter.writerow(util.head())

while (1):
    (Pkthdr, packet) = reader.next()
    length = len(packet)
    if (length == 0):
        break
    Ethernet = EthernetDecode.Ethernet()
    Ethernet.decodeEthernet(packet[0:14])

    if (Ethernet.IPType == '0800'):  #exclusively decode IPv4
        IPv4 = IPv4Decode.IPv4()
        IPv4.decodeIP(packet[14:34])
        if (IPv4.protocol == 6):
            TCP = TCPDecode.TCP()
            TCP.decodeTCP(packet[34:])
            csvData = Ethernet.data() + IPv4.data() + TCP.data()
            csvWriter.writerow(csvData)
        elif (IPv4.protocol == 17):