📄 cli.py
字号:
if (args == ""): if (self.current != None): self.current.list() else: print "No current stream. Use the load or set commands" else: numarg = self.numarg(args) if (numarg == None): self.help_list() return if ((numarg < 0) or (numarg >= len(self.streams))): print "Stream must be between 0 and %d." % (len(self.streams) - 1) self.help_list() return self.streams[numarg].list() def help_list(self): print "list (N)" print "list packets from current stream or the stream at index N " def complete_list(self, text, line, begidx, endidx): stream_list = [] for i in range(0, len(self.streams)): stream_list.append(str(i)) return stream_list def do_print(self, args): if (args == ""): if (self.current == None): print "No current stream. Use the load or set commands" return else: numarg = self.current.position else: numarg = self.numarg(args) if (numarg == None): self.help_print() return if ((numarg < 0) or (numarg > (len(self.current.packets) - 1))): print "Index must be between 0 and %d." % (len(self.current.packets) - 1) return self.current.display(numarg, self.current.packets[numarg]) def help_print(self): print "print (N)" print "print the current packet in the current stream or packet N in the current stream" def do_delete(self, args): "delete the current packet or the packet given by N in the current stream" if (args == ""): if (self.current == None): print "No current stream. Use the load or set commands" return else: numarg = self.current.position else: numarg = self.numarg(args) if (numarg == None): self.help_delete() return if ((numarg < 0) or (numarg > (len(self.current.packets) - 1))): print "Index must be between 0 and %d." % (len(self.current.packets) - 1) return del self.current.packets[numarg] def help_delete(self): print "delete (N)" print "delete the current packet or the packet given by N in the current stream" def do_send(self, args): "send the current packet or the packet given by N in the current stream" if (args == ""): if (self.current == None): print "No current stream. Use the load or set commands" return else: numarg = self.current.position else: numarg = self.numarg(args) if (numarg == None): self.help_print() return if ((numarg < 0) or (numarg > (len(self.current.packets) - 1))): print "Index must be between 0 and %d." % (len(self.current.packets) - 1) return self.current.send(self.current.packets[numarg]) def help_send(self): print "send (N)" print "send the current packet or the packet given by N in the current stream" # # Global set command, for debugger state. # def do_set(self, args): if len(args) <= 0: self.help_set() return try: (key, value) = args.split() except: self.help_set() return if key == "list_length": self.options.list_length = int(value) elif key == "layer": value = int(value) if value < 0: self.options.layer = None if value > 7: self.help_set() else: self.options.layer = value elif key == "current": if (value == None): print "Must supply a number between 0 and %d" % len(self.streams - 1) self.help_set() return value = int(value) if value < 0: print "Must be greater than 0" self.help_set() return if value >= len(self.streams): print "Must be less than %d" % (len(self.streams) - 1) self.help_set() return else: self.current = self.streams[value] def complete_set(self, text, line, begidx, endidx): """Completion for the set command""" if (text in ["li", "lis", "list", "list_", "list_l", "list_le", "list_len", "list_leng", "list_lengt"]): return ["list_length"] elif (text in ["la", "lay", "laye"]): return ["layer"] elif (text in ["c", "cu", "cur", "curr", "curre", "curren"]): return ["current"] else: if (line == "set current "): stream_list = [] for i in range(0, len(self.streams)): stream_list.append(str(i)) return stream_list def help_set(self): print "set option value\n\noptions: list_length - how many packets to list at one time.\n layer - ISO layer to show, -1 shows all\n current - set the current stream we're inspecting [0..n]" def do_show(self, args): """Show the current options that are set.""" print self.options # # Stream manipulation commands. Breakpoints, position changes # and packet manipluation. # def do_break(self, args): """set a breakpoint at the current index in the stream or at the numeric index given""" if (args == ""): numarg = self.current.position else: numarg = self.numarg(args) if (numarg == None): self.help_break() return self.current.add_break(numarg) def help_break(self): print "break (N)" print "set a breakpoint at the current index in the stream or at the numeric index given" def do_next(self, args): """Move to the next packet""" if (self.current == None): print "No current stream. Use the load or set commands" return if (len(args) > 0): jump = self.numarg(args) if (jump == None): self.help_next() return else: self.current.next(jump) else: self.current.next() def help_next(self): print "next (N)" print "Move to the next packet in the list. With a numeric argument, N, move N packets ahead in the list." def do_prev(self, args): """Move to the previous packet""" if (self.current == None): print "No current stream. Use the load or set commands" return if (len(args) > 0): jump = self.numarg(args) if (jump == None): self.help_prev() return else: self.current.prev(jump) else: self.current.prev() def help_prev(self): print "prev (N)" print "Move to the previous packet in the list. With a numeric argument, N, move N packets back in the list." # # Miscellaneous helper functions for our cli # def numarg(self, args): """If the argument passed is numeric pass back the number, otherwise pass back None""" if (type(args) != str): print "N must be a number" return None if (args.isdigit() != True): print "N must be a number" return None return int(args)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -