def sh(self, name='w3af', callback=None): """ Main cycle """ try: if callback: if hasattr(self, '_context'): ctx = self._context else: ctx = None self._context = callbackMenu( name, self, self._w3af, ctx, callback) else: self._context = rootMenu(name, self, self._w3af) self._lastWasArrow = False self._showPrompt() self._active = True term.setRawInputMode(True) self._executePending() while self._active: try: c = term.getch() self._handleKey(c) except Exception, e: om.out.console(str(e)) term.setRawInputMode(False)
def _execute(self): # term.writeln() line = self._getLineStr() term.setRawInputMode(False) om.out.console('') if len(line) and not line.isspace(): self._get_history().remember(self._line) try: # New menu is the result of any command. # If None, the menu is not changed. params = self.in_raw_line_mode() and line or self._parseLine( line) menu = self._context.execute(params) except ScanMustStopException: menu = None self.exit() except BaseFrameworkException, e: menu = None om.out.console(e.value) if menu: if callable(menu): # Command is able to delegate the detection # of the new menu to the console # (that's useful for back command: # otherwise it's not clear what must be added to the trace) # It's kind of hack, but I had no time # to think of anything better. # An other option is to allow menu # objects modify console state directly which I don't like # -- Sasha menu = menu() elif menu != self._context: # Remember this for the back command self._trace.append(self._context) if menu is not None: self._context = menu
def _execute(self): # term.writeln() line = self._getLineStr() term.setRawInputMode(False) om.out.console('') if len(line) and not line.isspace(): self._get_history().remember(self._line) try: # New menu is the result of any command. # If None, the menu is not changed. params = self.in_raw_line_mode() and line or self._parseLine(line) menu = self._context.execute(params) except ScanMustStopException: menu = None self.exit() except BaseFrameworkException, e: menu = None om.out.console(e.value) if menu: if callable(menu): # Command is able to delegate the detection # of the new menu to the console # (that's useful for back command: # otherwise it's not clear what must be added to the trace) # It's kind of hack, but I had no time # to think of anything better. # An other option is to allow menu # objects modify console state directly which I don't like # -- Sasha menu = menu() elif menu != self._context: # Remember this for the back command self._trace.append(self._context) if menu is not None: self._context = menu
# of the new menu to the console # (that's useful for back command: # otherwise it's not clear what must be added to the trace) # It's kind of hack, but I had no time # to think of anything better. # An other option is to allow menu # objects modify console state directly which I don't like # -- Sasha menu = menu() elif menu != self._context: # Remember this for the back command self._trace.append(self._context) if menu is not None: self._context = menu term.setRawInputMode(True) def _onEnter(self): self._execute() self._initPrompt() self._showPrompt() def _delWord(self): filt = str.isspace while (True): if self._position == 0: break char = self._line[self._position - 1] if filt(char):