Best Python code snippet using ATX
main.py
Source:main.py
1import os2from threading import Thread3from kivy.app import App4from kivy.core.window import Window5from kivy.clock import Clock, mainthread6from kivy.uix.button import Button7from kivy.uix.label import Label8from kivy.uix.scrollview import ScrollView9from kivy.uix.boxlayout import BoxLayout10from kivy.uix.gridlayout import GridLayout11from kivy.uix.anchorlayout import AnchorLayout12from kivy.uix.progressbar import ProgressBar13from kivy.uix.screenmanager import ScreenManager, Screen14from kivy.uix.filechooser import FileChooserListView15from kivy.uix.textinput import TextInput16from kivy.uix.spinner import Spinner17from kivy.utils import platform18from kivy.properties import StringProperty, BooleanProperty, Property19from kivy.lang import Builder20from utils import tprint, sidethread, specialthread21from fwupd import FWUpd22from fwget import FWGet23from nbcmd import Command24from nbclient import Client25class MainWindow(BoxLayout):26 pass27class CommandScreen(Screen):28 def setcmd(self,c):29 ScriptUI = self.ids['scriptspace']30 ScriptUI.clear_widgets()31 if c == 'changesn':32 changesnui = Builder.load_file("changesn.kv")33 ScriptUI.add_widget(changesnui)34 if c == 'dump':35 dumpui = Builder.load_file("dump.kv")36 ScriptUI.add_widget(dumpui)37class NineRiFt(App):38 def initialize(self):39 self.root_folder = self.user_data_dir40 self.cache_folder = os.path.join(self.root_folder, 'cache')41 if not os.path.exists(self.cache_folder):42 os.makedirs(self.cache_folder)43 self.conn = Client()44 self.conn.bind(on_error=lambda a,b: tprint(b))45 self.com = Command(self.conn)46 self.fwupd = FWUpd(self.conn)47 self.fwget = FWGet(self.cache_folder)48 self.versel = BooleanProperty(False)49 self.hasextbms = BooleanProperty(False)50 tprint("Don't forget to post a review")51 def build(self):52 self.initialize()53 self.mainwindow = MainWindow()54 return self.mainwindow55 @specialthread56 def connection_toggle(self):57 if self.conn.state == 'connected':58 self.conn.disconnect()59 elif self.conn.state == 'disconnected':60 self.conn.connect()61 @specialthread62 def fwget_select_model(self, screen, mod):63 if mod is not 'Model':64 self.fwget.setModel(mod)65 self.fwget.setRepo("https://files.scooterhacking.org/" + mod + "/fw/repo.json")66 tprint('loading repo')67 self.fwget.loadRepo(self.fwget.repoURL)68 self.fwget_update_versions(screen)69 else:70 tprint('set model to update available versions')71 @specialthread72 def fwget_func(self, dev, version):73 self.fwget.Gimme(dev, version)74 @sidethread75 def executecmd(self, c):76 if self.conn.state == 'connected':77 tprint(c+' execute')78 if c is 'lock':79 self.com.lock()80 if c is 'unlock':81 self.com.unlock()82 if c is 'reboot':83 self.com.reboot()84 if c is 'powerdown':85 self.com.powerdown()86 if c is 'sniff':87 self.com.sniff()88 if c is 'dump':89 if self.com.device is not '':90 self.com.dump(self.com.device)91 else:92 tprint('set device first')93 if c is 'info':94 self.com.info()95 if c is 'changesn':96 if self.com.new_sn is not '':97 self.com.changesn(self.com.new_sn)98 else:99 tprint('set NewSN first')100 elif self.conn.state == 'disconnected':101 tprint("You aren't connected")102 def selfile_filter(self, mod, vers, dev):103 check = ['!.md5']104 filters = []105 if mod is 'm365':106 if dev is not 'DRV':107 sf = ['*.bin']108 filters = sf+check109 elif dev is 'DRV':110 if vers=='>=141':111 sf = ['*.bin.enc']112 elif vers=='<141':113 sf = ['*.bin']114 else:115 sf = ['']116 filters = sf+check117 if mod is 'm365pro':118 if dev is 'DRV':119 sf = ['*.bin.enc']120 else:121 sf = ['*.bin']122 filters = sf+check123 if mod is 'esx' or 'max':124 sf = ['*.bin.enc']125 filters = sf+check126 print('selfile_filter set to %s' % filters)127 return filters128 @mainthread129 def fwget_update_versions(self, screen):130 sel = screen.ids.part.text131 if sel == 'BLE':132 dev = self.fwget.BLE133 elif sel == 'BMS':134 dev = self.fwget.BMS135 elif sel == 'DRV':136 dev = self.fwget.DRV137 else:138 dev = []139 if dev != []:140 versions = [str(e) for e in dev]141 tprint('FWGet Vers. available: '+str(versions))142 screen.ids.version.values = versions143 def select_model(self, mod):144 values = ['BLE', 'DRV', 'BMS']145 if mod.startswith('m365'):146 self.hasextbms = False147 if mod is 'm365':148 self.versel = True149 elif mod is 'm365pro':150 self.versel = False151 if mod is 'esx':152 self.versel = False153 self.hasextbms = True154 if mod is 'max':155 self.versel = False156 self.hasextbms = False157 if self.hasextbms is True:158 try:159 values.append('ExtBMS')160 except:161 print('ExtBMS entry already present')162 if self.hasextbms is False:163 try:164 values.remove('ExtBMS')165 except:166 print('no ExtBMS entry to remove')167 return values168 def on_stop(self):169 self.conn.disconnect()170 @sidethread171 def fwupd_func(self, chooser):172 if len(chooser.selection) != 1:173 tprint('Choose file to flash')174 return175 self.fwupd.Flash(chooser.selection[0])176 @mainthread177 def setprogbar(self, prog, maxprog):178 FlashScreen.setprog(prog, maxprog)179if __name__ == "__main__":...
script_dump-ui.py
Source:script_dump-ui.py
1from core.framework.module import FridaScript234class Module(FridaScript):5 meta = {6 'name': 'Frida Script: dump UI',7 'author': '@LanciniMarco (@MWRLabs)',8 'description': 'Print view hierarchy',9 'options': (10 ('output', True, False, 'Full path of the output file'),11 ),12 }1314 JS = '''\15if(ObjC.available) {16 ObjC.schedule(ObjC.mainQueue, () => {17 const window = ObjC.classes.UIWindow.keyWindow();18 const ui = window.recursiveDescription().toString();19 send(ui);20 });21} else {22 console.log("Objective-C Runtime is not available!");23}24 '''2526 # ==================================================================================================================27 # UTILS28 # ==================================================================================================================29 def __init__(self, params):30 FridaScript.__init__(self, params)31 # Setting default output file32 self.options['output'] = self.local_op.build_output_path_for_file(self, "frida_script_dumpui.txt")33 self.output = []3435 # ==================================================================================================================36 # RUN37 # ==================================================================================================================38 def module_run(self):39 # Run the payload40 try:41 self.printer.info("Parsing payload")42 hook = self.JS43 script = self.session.create_script(hook)44 script.on('message', self.on_message)45 script.load()46 except Exception as e:47 self.printer.warning("Script terminated abruptly")4849 # Save to file
...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!