def test_run_zipextractor(self): conf = WhatTheFileConfiguration() output_safe_directory = "./tests/examples/safe_directory" conf.parse_string(""" [whatthefile] modules_package = src.modules safe_output_path = """ + output_safe_directory + """ output = list log_output = stdout [module.zipextractor] active = true """) final_file = os.path.abspath(output_safe_directory) + \ "/1/zipextractor/" + \ os.path.abspath("./tests/examples/collie.jpg.zip/collie.jpg").replace(":", "") final_file = os.path.abspath(final_file) if os.path.exists(final_file): os.remove(final_file) self._remove_test_folders(output_safe_directory) self.assertFalse(os.path.exists(final_file)) path = "./tests/examples/collie.jpg.zip" output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(path) self.assertTrue(os.path.exists(final_file)) paths = [] for element in output.get_list(): paths.append(element["path"]) self.assertTrue(os.path.abspath(final_file) in paths) os.remove(final_file) self._remove_test_folders(output_safe_directory)
def __init__(self) -> None: """ Instantiate before the game launches """ Core.__init__(self) self.config = self.load_config() self.settings = self.config["settings"] self.gridvalues = [255, 0]
def __init__(self): self.config = Config() self.core = Core() self.logs = Logs() self.database = Database() self.data = {} # Data assets self.running = True
def a_test_run_all(self): conf = WhatTheFileConfiguration() conf.parse_dict({ "whatthefile": { "modules_package": "src.modules", "output": "list", "log_output": "stdout", "safe_output_path": "./tests/examples/safe_directory" }, "module.commentextractor": { "active": True }, "module.entropy": { "active": True }, "module.hashes": { "active": True, 'hashes_to_calculate': "MD5,SHA1,SHA256" }, "module.imagerecognitiontensorflow": { "active": True }, "module.metadata": { "active": True }, "module.ocrtesseract": { "active": True }, "module.qrbcreader": { "active": True }, "module.strings": { "active": True, "char_min": 4 }, "module.virustotal": { "active": True }, "module.zipextractor": { "active": True }, "module.tikaparser": { "active": True }, "module.certificatereader": { "active": True }, "module.browserhisstory": { "active": True } }) path = "./tests/examples/collie.jpg" output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(path) self.assertEqual( "collie" in output.get_list()[0]["imagerecognitiontensorflow"])
def startPushButtonEvent(self): if self.working == False: toCheck = [] additional = False if self.ip_v4CheckBox.isChecked(): toCheck.append("ipv4") if self.ip_v6CheckBox.isChecked(): toCheck.append("ipv6") if self.socialSecNoCheckBox.isChecked(): toCheck.append("socialsec") if self.idNoCheckBox.isChecked(): toCheck.append("id_number") if self.macCheckButton.isChecked(): toCheck.append("mac") if self.domainsCheckBox.isChecked(): toCheck.append("domain") if self.emailsCheckBox.isChecked(): toCheck.append("email") if self.passwdsCheckBox.isChecked(): toCheck.append("password") if self.loginsCheckBox.isChecked(): toCheck.append("login") if self.phoneNoCheckBox.isChecked(): toCheck.append("phone_number") if self.additionalCheckBox.isChecked(): additional = True dictPath = None if self.dictCheckBox.isChecked(): dictPath = self.dictPathLineEdit.text() self.progressValue = 0 self.progressBar.setValue(self.progressValue) self.working = True if self.outPathLineEdit.text() == '': inPath = self.inPathLineEdit.text() self.outPathLineEdit.setText( os.path.splitext(inPath)[0] + "_output.json") try: self.core = Core(self.inPathLineEdit.text(), self.outPathLineEdit.text(), expectedRegexes=toCheck, data=self.data, additional=additional, progressEvent=self.progressBarEvent, finishedEvent=self.finishedDataEvent, dictionaryPath=dictPath) except Exception as x: self.displayException(x) self.stopPushButtonEvent() return self.core.start()
def run(self, arguments): if len(arguments) != 3: Console.print_help(arguments) sys.exit() else: conf = WhatTheFileConfiguration() conf.parse_file(arguments[1]) output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(arguments[2])
def __init__(self): self.root = Tk() self.actions = Action(root=self.root) self.cores = Core() self.screensize = "400x600" # default screen size self.filename = "" self.savepath = "" self.tabs = None
def test_run_hashes(self): conf = WhatTheFileConfiguration() conf.parse_dict({ "whatthefile": { "modules_package": "src.modules", "output": "list", "log_output": "stdout", "safe_output_path": "./tests/examples/safe_directory" }, "module.commentextractor": { "active": True }, "module.entropy": { "active": False }, "module.hashes": { "active": True, 'hashes_to_calculate': "MD5,SHA1,SHA256" }, "module.imagerecognitiontensorflow": { "active": False }, "module.metadata": { "active": False }, "module.ocrtesseract": { "active": False }, "module.qrbcreader": { "active": False }, "module.strings": { "active": False, "char_min": 10 }, "module.virustotal": { "active": False }, "module.zipextractor": { "active": False } }) path = "./tests/examples/collie.jpg.zip" output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(path) self.assertTrue("SHA256" in output.get_list()[0]["hashes"]) self.assertTrue("start_module" in output.get_list()[0]["hashes"]) self.assertTrue("end_module" in output.get_list()[0]["hashes"]) self.assertTrue("begin_analysis" in output.get_list()[0]) self.assertTrue("end_analysis" in output.get_list()[0])
def test_run_directory(self): conf = WhatTheFileConfiguration() conf.parse_dict({ "whatthefile": { "modules_package": "src.modules", "output": "list", "log_output": "stdout", "safe_output_path": "./tests/examples/safe_directory" }, "module.commentextractor": { "active": True }, "module.entropy": { "active": True }, "module.hashes": { "active": True, 'hashes_to_calculate': "MD5,SHA1,SHA256" }, "module.imagerecognitiontensorflow": { "active": True }, "module.metadata": { "active": True }, "module.ocrtesseract": { "active": True }, "module.qrbcreader": { "active": True }, "module.strings": { "active": True, "char_min": 4 }, "module.virustotal": { "active": False }, "module.zipextractor": { "active": True } }) path = "./tests/examples/testdirectorydonotinsertmoreitems" output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(path) self.assertEqual(len(output.get_list()), 3)
class Action: def __init__(self, root=None): self.root = root self.cores = Core() self.filetypes = [("All files", "*"), ("Text file", "*.txt")] def newTabs(self, content=""): w = (self.root.winfo_screenwidth()-10) h = (self.root.winfo_screenheight()-50) texts = Text(self.root, width=w, height=h) texts.pack() texts.configure(undo=True, maxundo=-1, autoseparators=True) texts.focus() if content != "": texts.insert("1.0", content) return texts def about(self): info_dict = self.cores.get_info()["info"] showinfo("About!", "TE is a very simple Text Editor\n\nAuthor: " + info_dict["author"] + "\nVersion: " + str(info_dict["version"]) + "\nSource: " + info_dict["source"]) def askOpenFile(self): openfile = askopenfilename(filetypes=self.filetypes) if openfile != "": return openfile def askSaveFile(self): savefile = asksaveasfilename(filetypes=self.filetypes) if savefile != "": return savefile
def test_post_decrement_a(): warrior = Warrior(processes=[0]) core = Core(data=[MOV('I', '}', 1, '$', 1), DAT('F', '$', 0, '$', 0)]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert core[1].a_value() == 0 assert core[1].b_value() == 0
def test_ignore(self): conf = WhatTheFileConfiguration() conf.parse_dict({ "whatthefile": { "modules_package": "src.modules", "output": "list", "log_output": "stdout", "safe_output_path": "./tests/examples/safe_directory" }, "module.hashes": { "active": True, 'hashes_to_calculate': "MD5,SHA1,SHA256" }, "module.ignore": { "active": True, 'file_hashes_md5_to_ignore': './tests/examples/ignoredhashesmd5.txt' }, "module.imagerecognitiontensorflow": { "active": False }, "module.metadata": { "active": False }, "module.ocrtesseract": { "active": False }, "module.qrbcreader": { "active": False }, "module.strings": { "active": True, "char_min": 10 }, "module.virustotal": { "active": False }, "module.zipextractor": { "active": False } }) path = "./tests/examples/collie.jpg" output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(path) self.assertEqual(len(output.get_list()), 0)
def test_sub_x(): warrior = Warrior(processes=[0]) core = Core(data=[SUB('X', '#', '3', '$', '1'), DAT('F', '$', 2, '$', -5)]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() instruction = game.core()[1] assert instruction.a_value() == 1 assert instruction.b_value() == -8
def test_sub_typical(): warrior = Warrior(processes=[0]) core = Core( data=[SUB('AB', '#', '3', '$', '1'), DAT('F', '$', 1, '$', -5)]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.core()[1].b_value() == -8
def test_seq_i_no(): warrior = Warrior(processes=[0]) core = Core(data=[ SEQ('I', '$', 1, '$', 2), JMP('F', '$', 2, '$', 4), DAT('F', '$', 2, '$', 4) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert warrior.processes()[0] == 1
def test_jmp_typical(): warrior = Warrior(processes=[2]) core = Core(data=[ DAT('F', '$', 1, '$', -5), DAT('F', '$', 1, '$', -5), JMP('B', '$', -1, '$', 0) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.warriors()[0].processes()[0] == 1
def test_mod_zero(): warrior = Warrior(processes=[0]) core = Core(data=[ MOD('I', '$', 1, '$', 2), DAT('F', '$', 0, '$', 0), DAT('F', '$', 0, '$', 0) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert len(warrior.processes()) == 0
def test_djn_f_not_zero(): warrior = Warrior(processes=[0]) core = Core(data=[ DJN('B', '$', 2, '$', 0), DAT('F', '$', 0, '$', 1), DAT('F', '$', 0, '$', 1) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert warrior.processes() == [2]
def test_spl_typical(): warrior = Warrior(processes=[0]) core = Core(data=[ SPL('F', '$', 2, '$', 2), DAT('F', '$', 0, '$', 0), DAT('F', '$', 0, '$', 0) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert warrior.processes() == [1, 2]
def test_core_add_cycle_begin_two_times(): warrior = Warrior(processes=[1]) core = Core(data=[ DAT('F', '$', 1, '$', 5), ADD('AB', '#', '3', '$', '-5'), DAT('F', '$', 1, '$', -5) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.core()[2].b_value() == -2
def test_mov_x(): warrior = Warrior(processes=[0]) core = Core(data=[ MOV('X', '$', '1', '$', '2'), DAT('F', '$', 1, '$', 7), DAT('F', '$', 0, '$', 0) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.core()[2].a_value() == 7 assert game.core()[2].b_value() == 1
def test_zipextractor_unzip_with_zip_inside(self): output_safe_directory = "./tests/examples/safe_directory" final_file = os.path.abspath(output_safe_directory) + \ "/2/zipextractor/" + \ os.path.abspath(output_safe_directory).replace(":", "") + \ "/1/zipextractor/" + \ os.path.abspath("./tests/examples/folderzip.zip/folderzip/Surprisezip.txt.zip/Surprisezip.txt").replace(":", "") final_file = os.path.abspath(final_file) temporal_zip = os.path.abspath(output_safe_directory) + \ "/1/zipextractor/" + \ os.path.abspath("./tests/examples/folderzip.zip/folderzip/Surprisezip.txt.zip").replace(":", "") temporal_zip = os.path.abspath(temporal_zip) conf = WhatTheFileConfiguration() conf.parse_string(""" [whatthefile] modules_package = src.modules safe_output_path = """ + output_safe_directory + """ output = list log_output = stdout [module.zipextractor] active = true """) if os.path.exists(final_file): os.remove(final_file) self._remove_test_folders(output_safe_directory) self.assertFalse(os.path.exists(final_file)) path = "./tests/examples/folderzip.zip" output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(path) paths = [] for element in output.get_list(): paths.append(os.path.abspath(element["path"])) self.assertTrue(temporal_zip in paths) self._remove_test_folders(output_safe_directory)
def __init__(self, warriors, core=None, core_size=8000, init_warriors=True, gui=None, number=0, max_cycles=80000): """ Round constructor :param warriors: Required warriors list :param core: Optional core for testing purposes :param core_size: Other core size than default :param init_warriors: Execute init_warriors() for testing purposes """ self._core = core if core else Core(core_size, gui=gui) self._warriors = warriors if gui: self._gui = gui self._gui.init_game_screen() else: self._gui = MockGUI(core_size) if init_warriors: self.init_warriors() self._number = number self._cycles = 0 self._max_cycles = max_cycles
def importRoutes(rootpath, app, config_object: Config): """Add user routes to app.""" conf = WhatTheFileConfiguration() conf.parse_file(config_object.WHATTHEFILECONFIGFILE) output = ListOutput() core = Core(conf, output) @app.route(rootpath, methods=['GET', 'POST']) def index_or_upload_file(): if request.method == 'GET': return send_file("pages/index.html", mimetype='text/html') else: if 'fileToUpload' not in request.files: abort(404) else: file = request.files['fileToUpload'] binary = file.read() if len(binary) != 0: path = _write_file(config_object, binary, os.path.basename(file.filename)) output.get_list().clear() core.run(path) _remove_file(path) core.clean_safe_output_path() result = output.get_list() remove_internal_info(result) return Response(json.dumps(result, default=str), 200, mimetype='application/json') else: return Response(json.dumps({"error": "invalid file"}, default=str), 400, mimetype='application/json') @app.route(rootpath + "favicon.ico", methods=['GET']) def get_favicon(): return send_file("images/favicon.png", mimetype='image/png')
""" Modules stucture Activator - check that this plugin should be activated Requester - gwts request and processed it, returns response `future` object Responser - returns data to user """ from src.core import Core if __name__ == "__main__": config_path = '../config.yaml' core = Core(config_path) core.run()
import argparse # LOCALHOST = '127.0.0.1' # # parser = argparse.ArgumentParser() # parser.add_argument('config', help='Config', nargs='?') # parser.add_argument('--client', help='Client mode', action='store_true') # parser.add_argument('--bind-address', help='IP address to bind to', default=LOCALHOST) # options = parser.parse_args() # # print(options) from src.core import Core from src.utils.registry import get_registry core = Core(config_directory='./data') print(get_registry().crops) print(get_registry().configs.to_dict())
class Acticity: def __init__(self): self.config = Config() self.core = Core() self.logs = Logs() self.database = Database() self.data = {} # Data assets self.running = True def setup(self): pygame.init() self.database.connect() self.config.read() self.data = self.core.get_data self.speed = self.config.parse["settings"]["speed"] set_caption(self.config.getName + " " + self.config.getVersion) self.screen = set_mode(self.config.getRect.size) self.core.load_assets() if self.data["icon"]: self.logs.info("Mengatur icon") set_icon(self.data["icon"]) set_visible(True) self.clock = Clock() #=== Background game ===# self.BACKGROUND = self.data["backgrounds"][random.choice( [x for x in self.data["backgrounds"]][1:])] self.BACKGROUND = scale(self.BACKGROUND, self.config.getRect.size) #=== Settings tanah texture ===# self.tanah = self.data["textures"]["tanah0"] self.tanah = scale(self.tanah, (1000, self.tanah.get_height())) self.tanah_diff = self.tanah.get_width() - self.BACKGROUND.get_width() self.tanah_position = [0, self.config.getRect.height * 0.95] #=== Settings grass texture ===# self.grass = self.data["textures"]["grass0"] self.grass = scale(self.grass, (1000, 10)) self.grass_diff = self.grass.get_width() - self.BACKGROUND.get_width() self.grass_position = [10, self.config.getRect.height * 0.94] #=== Settings rumput texture ===# rumput_image_list = [] for x in self.data["textures"]: if "rumput" in x: rumput_image_list.append(x) self.rumputGroup = Group() for x in range(random.randint(2, 4)): image = self.data["textures"]["rumput0"] self.rumputGroup.add( Rumput(image, [ random.randint(self.config.getRect.width, 3000), self.config.getRect.height * 0.80 ])) #=== Settings keris image ===# self.kerisGroup = Group() for x in range(random.randint(1, 3)): keris = Keris(self.data["anim"]["keris"], [ random.randint(self.config.getRect.width, self.config.getRect.width * 2), 10 ]) keris.rect.bottom += random.randint( 10, self.config.getRect.height - 130) self.kerisGroup.add(keris) #=== Settings bambu image ===# self.bambuGroup = Group() for x in range(random.randint(1, 3)): bambu = Bambu(self.data["other"]["bambu"], [ random.randint(self.config.getRect.width, self.config.getRect.width * 2), 10 ]) bambu.rect.bottom += self.config.getRect.height * 0.78 self.bambuGroup.add(bambu) #=== Settings player image ===# self.player = Player(self.data["anim"]["player1"], [60, self.config.getRect.height - 40]) #=== Settings score ===# self.score = Score(self.data) #=== Health bar ===# self.health = Health(self.data) def run(self): self.setup() self.running = introGame(self.screen, self.data, self.database.getProfile()) add_rumput = True add_keris = True add_bambu = True while self.running: events = self.core.events() if events["type"]["quit"]: self.running = False break elif events["type"]["keydown"]: if events["keys"]["space"] or events["keys"]["up"]: self.player.jump_up() #=== Move position ===# boundary_values = [0, self.grass_position[-1]] self.player.update( boundary_values, float( self.clock.tick(self.config.parse["settings"]["frame"]) / 1000)) self.tanah_position[0] = -( (-self.tanah_position[0] + self.speed) % self.tanah_diff) self.grass_position[0] = -( (-self.grass_position[0] + self.speed) % self.grass_diff) #=== Move rumput object ===# for rumput in self.rumputGroup: rumput.rect.left -= self.config.parse["settings"]["speed"] if rumput.rect.left < 4 and rumput.rect.left > 0 and add_rumput: if len(self.rumputGroup) > 50: continue else: image = self.data["textures"][ "rumput" + str(random.randint(1, 6))] self.rumputGroup.add( Rumput(image, [ random.randint(self.config.getRect.width, 3000), self.config.getRect.height * 0.80 ])) elif rumput.rect.right < 0: if len(self.rumputGroup) > 50: self.rumputGroup.remove(rumput) else: self.rumputGroup.remove(rumput) image = self.data["textures"][ "rumput" + str(random.randint(1, 6))] self.rumputGroup.add( Rumput(image, [ random.randint(self.config.getRect.width, 3000), self.config.getRect.height * 0.80 ])) #=== Move keris object ===# for keris in self.kerisGroup: keris.rect.left -= self.config.parse["settings"]["speed"] #=== Check object to object ===# if collide_mask(self.player, keris) and not keris.is_used: keris.is_used = True self.kerisGroup.remove(keris) add_keris = True self.health.add_value() if self.score.add_score(): self.running = False break if keris.rect.left < 4 and keris.rect.left > 0 and add_keris: if self.health.revalue(): self.running = False break keris = Keris(self.data["anim"]["keris"], [ random.randint(self.config.getRect.width, self.config.getRect.width * 2), 10 ]) keris.rect.bottom += random.randint( 10, self.config.getRect.height - 130) self.kerisGroup.add(keris) add_keris = False elif add_keris and keris.is_used: if random.randint(0, 1) == 1: for _ in range(random.randint(1, 2)): keris = Keris(self.data["anim"]["keris"], [ random.randint(self.config.getRect.width, self.config.getRect.width * 2), 10 ]) keris.rect.bottom += random.randint( 10, self.config.getRect.height - 130) self.kerisGroup.add(keris) else: keris = Keris(self.data["anim"]["keris"], [ random.randint(self.config.getRect.width, self.config.getRect.width * 2), 10 ]) keris.rect.bottom += random.randint( 10, self.config.getRect.height - 130) self.kerisGroup.add(keris) add_keris = False elif keris.rect.right < 0: self.health.revalue() self.kerisGroup.remove(keris) keris = Keris(self.data["anim"]["keris"], [ random.randint(self.config.getRect.width, self.config.getRect.width * 2), 10 ]) keris.rect.bottom += random.randint( 10, self.config.getRect.height - 130) self.kerisGroup.add(keris) for bambuEnemy in self.bambuGroup: bambuEnemy.rect.left -= self.config.parse["settings"]["speed"] if collide_mask(self.player, bambuEnemy) and not bambuEnemy.is_used: bambuEnemy.is_used = True add_bambu = True self.health.revalue() self.score.rescore() if bambuEnemy.rect.left < 4 and bambuEnemy.rect.left > 0 and add_bambu: bambu = Bambu(self.data["other"]["bambu"], [ random.randint(self.config.getRect.width, self.config.getRect.width * 2), 10 ]) bambu.rect.bottom += self.config.getRect.height * 0.78 self.bambuGroup.add(bambu) add_bambu = False elif bambuEnemy.rect.right < 0: self.bambuGroup.remove(bambuEnemy) bambu = Bambu(self.data["other"]["bambu"], [ random.randint(self.config.getRect.width, self.config.getRect.width * 2), 10 ]) bambu.rect.bottom += self.config.getRect.height * 0.78 self.bambuGroup.add(bambu) #=== Screen display ===# self.screen.blit(self.BACKGROUND, (0, 0)) self.rumputGroup.draw(self.screen) self.screen.blit(self.tanah, self.tanah_position) self.screen.blit(self.grass, self.grass_position) self.bambuGroup.draw(self.screen) self.health.draw(self.screen) self.kerisGroup.draw(self.screen) self.player.draw(self.screen) self.score.draw(self.screen) #=== Check ===# if self.score.check(): self.running = False elif self.health.check(): self.running = False self.clock.tick(self.config.parse["settings"]["frame"]) update() self.logs.warning("Menyimpan score") self.database.updateScore(self.score.getScore) self.logs.warning("Menutup game...") pygame.quit()
def test_get_cycled_value_begin(): instruction_1 = DAT('F', '$', 1, '$', 5) instruction_2 = ADD('AB', '#', '3', '$', '-2') instruction_3 = DAT('F', '$', 1, '$', -5) core = Core(data=[instruction_1, instruction_2, instruction_3]) assert core[-5] == instruction_2
def __init__(self, root=None): self.root = root self.cores = Core() self.filetypes = [("All files", "*"), ("Text file", "*.txt")]
def init_server(): core = Core() core.run()