def test_check_input_invalid_length(): validator = val.Validator() for entry in invalid_sequence_length: with pytest.raises(opcodes.InvalidSequenceLength): validator.checkInput(entry)
def test_byteCount(): sequences = { "6001600203": 5, "6112344301": 5, "43": 1, "61123462123456024300": 10, "60014302601": 5 } for bytecode, length in sequences.items(): validator = val.Validator() assert length, validator.getByteCount(bytecode)
def result(filename): full_filename = os.path.join(app.config['UPLOAD_FOLDER'], filename) v = validator.Validator(full_filename, False) try: if not v.parse_file(): res = v.produce_result_file(True) return render_template("result.html", res=res) v.perform_all_checks() res = v.produce_result_file(False) except: logger.error("Error processing file: " + filename) shutil.copy(full_filename, "trouble_maker/" + datetime.datetime.now().strftime("%Y%m%d%H%M%S") + "-" \ + os.path.basename(full_filename)) os.remove(full_filename) raise os.remove(full_filename) return render_template("result.html", res=res)
def test_check_input_invalid_bytecodes(): validator = val.Validator() for entry in invalid_bytecodes: valid, invalid_msg = validator.checkInput(entry) assert not valid, invalid_msg
"-a", "--average", help="Prints the average amount of used opcodes per sequence", action="store_true") parser.add_argument("-u", "--usage", help="Prints the amount of used opcodes", action="store_true") parser.add_argument("-b", "--bytes", help="Prints the average amount of bytes per sequence", action="store_true") args = parser.parse_args() opcodes.initSequenceOpcodes() validator = val.Validator() if args.validate: # inc validates sequences counter VALIDATED_SEQUENCES += 1 valid, invalid_msg = validator.checkInput(args.validate) addSequenceLength(validator.getByteCount(args.validate)) if not valid: log.warn("Invalid opcode " + str(invalid_msg)) log.warn(str.format("[VALIDATION FAILED]")) else: log.info("[VALIDATION PASSED]") elif args.dir: readInputs, failed = checkInputDir(args.dir, validator) log.info(str.format("{} inputs checked", readInputs)) if failed > 0:
if LOG: sys.excepthook = error_logger log = open("log/" + datetime.datetime.now().strftime("%Y%m%d") + ".log", "a") sys.stdout = log sys.stderr = log log.write("*********************\n*") log.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "*\n*********************\n") root = Tkinter.Tk() root.withdraw() f = tkFileDialog.askopenfilename() if not f: sys.exit(0) global trouble_maker trouble_maker = f if LOG: log.write("File name: " + f.encode("utf8", errors="ignore") + "\n\n") v = validator.Validator(f, True) if not v.parse_file(): v.produce_result_file(True) sys.exit(-1) v.perform_all_checks() v.produce_result_file(False)