def input(prompt=None, *, default=None, validator=None): if prompt is not None: prompt_default = " [{}]".format(default) if default is not None else "" prompt = "{}{}: ".format(prompt, prompt_default) if validator is None: validator = lambda x: x while True: if prompt is not None: output.info(prompt, newline=False) try: inp = _input().strip() except EOFError: if prompt: output.newline() fail() if not inp: if default is not None: return default else: output.warning("Must enter a value") continue try: inp = validator(inp) except ValueError as e: output.warning("Invalid input ({})".format(e)) else: return inp
def execute_program(HMMER=False, filter=True, score_threshold=False): """ Executes the program and creates a gene list. This function is used if this is the first time executing the progam. This fuction creates a gene list and stores all of the relevant information from a variety of databases and HMMER output. Parameter HMMER: says whether to create a new HMMER file. Preconditon: HMMER is a bool Parameter filter: says whether to filter out other proteins except the longest transcript Preconditon: filter is a bool Parameter score_threshold: says whether to get only output proteins with a score above 17.7 Preconditon: score_threshold is a bool """ data = genetics.hmmer_output(create_new=HMMER) full_dict_proteins = genetics.Protein.full_protein_dict() protein_list = genetics.Protein.create_protein_set(data) gene_list = genetics.Gene.create_gene_list(protein_list, full_dict_proteins) genetics.Protein.get_zf_protein_info(data, gene_list) genetics.Protein.gene_list_set_sequence(gene_list, full_dict_proteins) database.search(gene_list) database.search_mutation_info(gene_list) genetics.Protein.remove_proteins(gene_list, score_threshold) output.info(gene_list, create_txt=True, create_tab=True, create_chart=True, create_tab_dis=True)
def generate(self): self.tree = SyntaxTree() self.tokens = TokenTape(self.unit.tokenised_repr) self.parse() if self.unit.pipeline_input.verbose: for line in str(self.tree).split("\n"): output.info("Parser", line)
def loadModules(): output.info("Loading Modules...") global modules for name in os.listdir('modules'): if os.path.isdir(os.path.join('modules', name)) and os.path.isfile( os.path.join('modules', name) + '/module.json'): modules.append(name) output.success("Found " + str(len(modules)) + " Modules")
def generate(self): raw = self.unit.pipeline_input # First we generate the simple tokens for source_line in raw: line = source_line.line self.tokenise(source_line.row_number, 1, line) self.add_token(Token(TokenType.EOF, source_line.row_number, -1)) # Now we take the ProtoTokens and create the more complex ones. self.bundle_tokens() self.unit.tokenised_repr = self.tokenised_repr if self.unit.pipeline_input.verbose: for token in self.unit.tokenised_repr: output.info("Tokeniser", str(token))
pkt = dpkt.ethernet.Ethernet() pkt.type = dpkt.ethernet.ETH_MIN pkt.dst = '\xFF\xFF\xFF\xFF\xFF\xFF' #Connect to controller ofmsg = openflow.messages() parser = of.msg.parser(ofmsg) ofnet = of.simu.network() for i in range(1,swno+1): ofsw = of.simu.switch(ofmsg, args[0], port, dpid=i, parser=parser) ofnet.add_switch(ofsw) ofsw.send_hello() output.info("Running "+str(swno)+" switches at "+str(rate)+\ " packets per seconds for "+str(duration)+" s") starttime = time.time() running = True interval = 1.0/(rate*swno) ntime=time.time()+(interval/10.0) swindex = 0 pcount = 0 rcount = 0 while running: ctime = time.time() time.sleep(max(0,min(ntime-ctime,interval/10.0))) if ((ctime-starttime) <= duration): #Send packet if time's up if (ctime >= ntime):
def cmdUseGenerate(modulename): #read the duckyscript and replace the uac key if needed global moduleAttributes ducky = moduleAttributes['sdcard_mount'] suffix = "/" if os.name == 'nt': suffix = "\\" if not ducky.endswith(suffix, len(ducky) - 1, len(ducky)): if os.name == 'nt': ducky = ducky + "\\" else: ducky = ducky + "/" lang = moduleAttributes['language'] moduleAttributes.pop('sdcard_mount', None) moduleAttributes.pop('language', None) output.info("Reading duckyscript.txt") tmpduckyscript = '' with open('modules/' + modulename + '/duckyscript.txt', 'r') as script: if loadedModule['requirements']['has_uac_bypass'].lower() == "true": #now replace the uac key output.info("Replacing <uac_bypass_key>") tmpduckyscript = script.read().replace( '<uac_bypass_key>', moduleAttributes['uac_bypass_key']) output.success("Replacing <uac_bypass_key> key... Done!") #pop uac_bypass_key moduleAttributes.pop('uac_bypass_key', None) else: output.info("No UAC Bypass needed") tmpduckyscript = script.read() for key, value in moduleAttributes.items(): output.info("Replacing <" + key + "> with " + value) tmpduckyscript = tmpduckyscript.replace('<' + key + '>', value) output.info("Writing temporary duckyscript...") with open('tmp.duckyscript', 'w') as w: w.write(tmpduckyscript) output.success("Writing temporary duckyscript...Done!") output.info("Generating inject.bin...") # Generate the inject.bin encoderPath = "encoder/encoder.jar" inputFlag = "-i tmp.duckyscript" outputFlag = "-o inject.bin" langFlag = "-l " + lang fullExecCommand = "java -jar " + encoderPath + " " + inputFlag + " " + outputFlag + " " + langFlag result = subprocess.check_output(fullExecCommand, stderr=subprocess.STDOUT, shell=True) result = result.decode("utf-8") print(result) output.success("Generating inject.bin...Done!") os.remove("tmp.duckyscript") if "folders" in loadedModule['requirements']: output.info("Creating the necessary folders...") for folder in loadedModule['requirements']['folders']: if os.path.exists(ducky + folder): shutil.rmtree(ducky + folder) time.sleep(2) os.makedirs(ducky + folder) output.success("Creating the necessary folders...Done!") else: output.info("No folder creation needed") if "files" in loadedModule['requirements']: output.info("Copying files...") for ffile in loadedModule['requirements']['files']: if os.path.isfile(ducky + ffile): os.remove(ducky + ffile) time.sleep(2) shutil.copyfile('modules/' + modulename + '/' + ffile, ducky + ffile) output.success("Copying files...Done!") else: output.info("No file copying needed") output.info("Copying inject.bin to Ducky...") shutil.copyfile('inject.bin', ducky + "inject.bin") time.sleep(2) os.remove("inject.bin") output.success("Copying inject.bin to Ducky...Done!") print('') output.success("Thanks 4 shopping with PyDuckGen") sys.exit()
output.set_mode("DBG") elif (opt in ("-p","--port")): port=int(arg) else: assert (False,"Unhandled option :"+opt) #Connect to controller ofmsg = openflow.messages() parser = of.msg.parser(ofmsg) ofsw = of.simu.switch(ofmsg, args[0], port, dpid=int("0xcafecafe",16), parser=parser) ofsw.send_hello() #Send echo and wait xid = 22092009 running = True ofsw.send_echo(xid) starttime = time.time() while running: msg = ofsw.connection.msgreceive(True, 0.00001) pkttime = time.time() dic = ofmsg.peek_from_front("ofp_header", msg) if (dic["type"][0] == ofmsg.get_value("OFPT_ECHO_REPLY") and dic["xid"][0] == xid): #Check reply for echo request output.info("Received echo reply after "+\ str((pkttime-starttime)*1000)+" ms", "ping-controller") running = False else: ofsw.receive_openflow(msg)
#Form packet pkt = dpkt.ethernet.Ethernet() pkt.type = dpkt.ethernet.ETH_MIN pkt.dst = '\xFF\xFF\xFF\xFF\xFF\xFF' #Connect to controller ofmsg = openflow.messages() parser = of.msg.parser(ofmsg) ofnet = of.simu.network() for i in range(1, swno + 1): ofsw = of.simu.switch(ofmsg, args[0], port, dpid=i, parser=parser) ofnet.add_switch(ofsw) ofsw.send_hello() output.info("Running "+str(swno)+" switches at "+str(rate)+\ " packets per seconds for "+str(duration)+" s") starttime = time.time() running = True interval = 1.0 / (rate * swno) ntime = time.time() + (interval / 10.0) swindex = 0 pcount = 0 rcount = 0 while running: ctime = time.time() time.sleep(max(0, min(ntime - ctime, interval / 10.0))) if ((ctime - starttime) <= duration): #Send packet if time's up if (ctime >= ntime):