class Processor: """ This represents the processor itself. Most work and operations will be outsourced to other objects referenced by the processor. The processor holds the values of valP, valE, valA, valB, valC, and rA, rB. """ def __init__(self, mem_size: int = 10000): """ The following is an abstraction for a bank of values such as valA, which will be used during each cycle. It's set up as an object to avoid circular import. """ self.ValBank = ValBank() """ The following are functional units like memory, registers, or flags """ self.Memory = Memory(mem_size) self.RegisterBank = RegisterBank() self.ZF = CCFlag("ZF") # zero flag self.OF = CCFlag("OF") # overflow flag self.SF = CCFlag("SF") # sign flag self.ErrorFlag = StateFlag("Error Flag", error_lib) self.StateFlag = StateFlag("State Flag", state_lib) self.ALU = ALU(self.ValBank, self.StateFlag, self.ErrorFlag, self.SF, self.OF, self.ZF) """ The following are functional abstractions of operations that the processor performs """ self.Fetcher = Fetcher(self.ValBank, self.RegisterBank, self.Memory, self.StateFlag, self.ErrorFlag) self.Decoder = Decoder(self.ValBank, self.RegisterBank, self.Memory) self.Executor = Executor(self.ValBank, self.ALU, self.OF, self.ZF, self.SF) self.Memorizer = Memorizer(self.ValBank, self.Memory) self.RegWriter = RegWriter(self.RegisterBank, self.ValBank) self.PCUpdater = PCUpdater(self.RegisterBank, self.ValBank) def run(self): """ This is the only necessary public method for the processor. Currently the way to operate this is by manually loading values into the memory using the place_instruction method, then calling the 'run' method for the processor. Afterwards calling print on the memory object will reveal the finish state of the processor. """ while self.StateFlag.State == 0: self.Fetcher.fetch() self.Decoder.decode() self.Executor.execute() self.Memorizer.memory_write() self.RegWriter.write_back() self.PCUpdater.update_pc()
class Requst_processor(object): """ This class have infinite cycle for read, parse and run command, send reply. stmp - send mail imap - read mail executor - make changes in sheet """ def __init__(self, gmail, password, sheets): self.smtp = SMTP(gmail, password) self.imap = IMAP(gmail, password) self.executor = Executor(sheets) def run(self): period = 0 while True: self.imap.chec_mail() # print(self.imap.get_comand()) for comand in self.imap.get_comand(): try: print('-', comand) self.executor.execute(comand) # return status and comand #self.executor.transfer() # ?? try && except Exception as e: str_exeption = str(type(e)) + str(e.args) write_log(log=self.reply_on_comand( comand['address'], comand['command'], str_exeption)) else: write_log(log=self.reply_on_comand( comand['address'], comand['command'], 'SUCCESS')) period += 1 time.sleep(25) def reply_on_comand(self, address, command, result): self.smtp.send(address, result) if result == 'SUCCESS': print(result) else: print('ERROR ', result) result = result return '/' + address + '/' + command + '/' + result
def main(args): #Init settings Settings.init() Settings.enableDebug = args.debug print(args.debug) print(Settings.enableDebug) executor = Executor() validationDataPath = os.path.abspath("ValidationData") #Load validation data with open(validationDataPath + '/validator.json') as json_file: validationData = json.load(json_file) validationData = validationData['exams'] #load labels label_file = executor.input.modelPath + '/yolo-obj.names' labels = open(label_file).read().strip().split('\n') #init result rate which means % success rate of each label resultRate = {} for label in labels: resultRate[label] = 0 #star validation for item in validationData: #execute detection executeResult = executor.execute(validationDataPath + '/' + item['image']) #validate and get result validationResult = validateResult(item['data'], executeResult, labels) #add validation result to final result for label in labels: resultRate[label] = resultRate[label] + validationResult[label] showResult(resultRate, validationData) return
def main(args): executor = Executor() executor.execute(args.file) return
class FuzzerClientProtocol(amp.AMP): def __init__(self): self.executor = Executor() self.original_file = None self.original_file_name = None self.mutation_types = None self.program = None self.mutator = None def connectionMade(self): setupDeferreds = [self.getOriginalFile(), self.getProgram(), self.getMutationTypes()] defer.gatherResults(setupDeferreds).addCallback(self.finishSetup).addErrback(stop) def finishSetup(self, ign): # we have all the pieces the mutator needs self.mutator = Mutator( self.original_file, self.mutation_types, self.original_file_name, self.factory.tmp_directory) # enter continuous loop self.lc = LoopingCall(self.getNextMutation) self.lc.start(0) def getNextMutation(self): ''' Ask the server for the next mutation ''' return (self.callRemote(commands.GetNextMutation) # return deferred .addCallback(self.executeNextMutation) .addErrback(stop)) def executeNextMutation(self, mutation): if mutation['stop']: stop("Server said to stop") return False if mutation['pause']: print 'Sever said to pause - sleeping for 60 seconds' sleep(60) return True # create the mutated file new_file_name = self.mutator.createMutatedFile(mutation['offset'], mutation['mutation_index']) # execute it print '(%d,%d)' % (mutation['offset'], mutation['mutation_index']), output = self.executor.execute(self.program, new_file_name) if output: print 'Got output, Offset = %d, Mutation_Index = %d, File = %s' % (mutation['offset'], mutation['mutation_index'], new_file_name) self.callRemote( commands.LogResults, mutation_index=mutation['mutation_index'], offset=mutation['offset'], output=output, filename=new_file_name ) # copy the file - it caused a crash copy("%s"%new_file_name, "%s"%join(self.factory.save_directory, split(new_file_name)[-1])) # remove the file remove("%s"%new_file_name) @defer.inlineCallbacks def getOriginalFile(self): ''' get original file and file name''' response = yield self.callRemote(commands.GetOriginalFile) print '[*] Got original_file :', response['original_file_name'] self.original_file = response['original_file'] self.original_file_name = response['original_file_name'] @defer.inlineCallbacks def getMutationTypes(self): ''' get list of mutations that will be used ''' response = yield self.callRemote(commands.GetMutationTypes) print '[*] Got mutation types' self.mutation_types = response['mutation_types'] @defer.inlineCallbacks def getProgram(self): ''' get target program that will be executed ''' response = yield self.callRemote(commands.GetProgram) print '[*] Got program :', response['program'] self.program = response['program']
def main(argv): varTypeD = {} # dictionary for variable types varValueD = {} # dictionary for variable values labelD = {} # dictionary for labels source = [] # source code lineNum = 1 # file line number NUM_ARGS = 2 # Minimum number of args MAX_ARGS = 3 # Maximum number of args verbose = False # Flag for -v option numArgs = len(argv) # check for correct number of arguments if numArgs < NUM_ARGS or numArgs > MAX_ARGS: print("Usage: %s <BEEP source> [-v]" % (argv[0])) sys.exit(1) # validate filename and optional command line arguments filename = argv[1] if '-v' in argv: verbose = True elif numArgs == MAX_ARGS: print("Usage: %s <BEEP source> [-v]" % (argv[0])) sys.exit(1) if os.path.isfile(filename) == False: print("Error: %s is not a file" % (filename)) sys.exit(1) # compile the regular expressions labelRE = re.compile(r'\s*(\w+):') varRE = re.compile(r'^VAR\s([\w]+)\s([\w]+)\s"?(.*?)"?$') # parse file for labels and variables and print contents file = open(filename, "r", encoding='latin-1') print('BEEP source code in %s:' % (filename)) while True: line = file.readline() if line == "": break if labelRE.match(line) != None: labelMO = labelRE.match(line) label = labelMO.group(1).upper() if labelD.get(label, None) != None: print( "***Error: label '%s' appears on multiple lines: %d and %d" % (label, labelD[label], lineNum)) else: labelD[label] = lineNum elif varRE.match(line) != None: varMO = varRE.match(line) declareVar(varMO, varTypeD, varValueD) source.append(line) # print line and line number print("%d. %s" % (lineNum, line)) lineNum += 1 # print labels and variables printVariables(varTypeD, varValueD) printLabels(labelD) executor = Executor(varTypeD, varValueD, labelD, source) # execute the source if verbose: executor.execute(source, verbose=True) else: executor.execute(source)
class Server: youBanned = Info.Info("Your ip have been banned!") userNotFound = Error.Error("User not found!") alreadyBanned = Error.Error("This ip already banned!") notBanned = Error.Error("This ip has not banned!") def __init__(self, ip, port=9090, max_users=20): self.console = False self.HOST = ip self.PORT = port self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.bind((self.HOST, self.PORT)) self.sock.listen(max_users) self.blacklist = [] self.users = [] self.ex = Executor(self) self.th = threading.Thread(target=self.acceptor) self.th.start() def set_console(self, ip): self.console = ip def manager(self, msg, owner): print(msg.get_text()) if msg.text[0] == "/": name = msg.text[1:].split()[0] args = msg.text[1:].split()[1:] self.ex.execute(name, owner, args) else: self.resend(msg) def resend(self, msg): if isinstance(msg, Bcast.Bcast): print(msg.get_text()) for u in self.users: u.send(msg) def acceptor(self): while True: conn, addr = self.sock.accept() u = User(addr[0], conn, self) if u.ip not in self.blacklist: u.accept_success() if u.ip == self.console: u.admin = True self.console = "" else: u.accept_canceled(Server.youBanned) def nick2user(self, nick): for u in self.users: if u.nick == nick: return u return Server.userNotFound def ban(self, ip): if ip in self.blacklist: return Server.alreadyBanned self.blacklist.append(ip) def unban(self, ip): if ip not in self.blacklist: return Server.notBanned self.blacklist.remove(ip)