Пример #1
0
static void keypress (hashcat_ctx_t *hashcat_ctx)
{
  status_ctx_t   *status_ctx   = hashcat_ctx->status_ctx;
  user_options_t *user_options = hashcat_ctx->user_options;

  // this is required, because some of the variables down there are not initialized at that point
  while (status_ctx->devices_status == STATUS_INIT) usleep (100000);

  const bool quiet = user_options->quiet;

  tty_break ();

  while (status_ctx->shutdown_outer == false)
  {
    int ch = tty_getchar ();

    if (ch == -1) break;

    if (ch ==  0) continue;

    //https://github.com/hashcat/hashcat/issues/302
    //#if defined (_POSIX)
    //if (ch != '\n')
    //#endif

    hc_thread_mutex_lock (status_ctx->mux_display);

    event_log_info (hashcat_ctx, NULL);

    switch (ch)
    {
      case 's':
      case '\r':
      case '\n':

        event_log_info (hashcat_ctx, NULL);

        status_display (hashcat_ctx);

        event_log_info (hashcat_ctx, NULL);

        if (quiet == false) send_prompt (hashcat_ctx);

        break;

      case 'b':

        event_log_info (hashcat_ctx, NULL);

        bypass (hashcat_ctx);

        event_log_info (hashcat_ctx, "Next dictionary / mask in queue selected. Bypassing current one.");

        event_log_info (hashcat_ctx, NULL);

        if (quiet == false) send_prompt (hashcat_ctx);

        break;

      case 'p':

        if (status_ctx->devices_status != STATUS_PAUSED)
        {
          event_log_info (hashcat_ctx, NULL);

          SuspendThreads (hashcat_ctx);

          if (status_ctx->devices_status == STATUS_PAUSED)
          {
            event_log_info (hashcat_ctx, "Paused");
          }

          event_log_info (hashcat_ctx, NULL);
        }

        if (quiet == false) send_prompt (hashcat_ctx);

        break;

      case 'r':

        if (status_ctx->devices_status == STATUS_PAUSED)
        {
          event_log_info (hashcat_ctx, NULL);

          ResumeThreads (hashcat_ctx);

          if (status_ctx->devices_status != STATUS_PAUSED)
          {
            event_log_info (hashcat_ctx, "Resumed");
          }

          event_log_info (hashcat_ctx, NULL);
        }

        if (quiet == false) send_prompt (hashcat_ctx);

        break;

      case 'c':

        event_log_info (hashcat_ctx, NULL);

        stop_at_checkpoint (hashcat_ctx);

        if (status_ctx->checkpoint_shutdown == true)
        {
          event_log_info (hashcat_ctx, "Checkpoint enabled. Will quit at next restore-point update.");
        }
        else
        {
          event_log_info (hashcat_ctx, "Checkpoint disabled. Restore-point updates will no longer be monitored.");
        }

        event_log_info (hashcat_ctx, NULL);

        if (quiet == false) send_prompt (hashcat_ctx);

        break;

      case 'q':

        event_log_info (hashcat_ctx, NULL);

        myquit (hashcat_ctx);

        break;

      default:

        if (quiet == false) send_prompt (hashcat_ctx);

        break;
    }

    //https://github.com/hashcat/hashcat/issues/302
    //#if defined (_POSIX)
    //if (ch != '\n')
    //#endif

    hc_thread_mutex_unlock (status_ctx->mux_display);
  }

  tty_fix ();
}
Пример #2
0
int main( int argc, const char* argv[] )
{
  
  std::string s1("s1");  
  std::string s2("s2");  
  std::string s3 = s1+s2;  
  
  GB_DriverBase = DriverBase::ptr(&GB_driver,smartpointer_nodeleter<DriverBase>());
  
  GB_debug = false;
  GB_nofile = false;

  GB_num_arg_parsed = 1;
  
  GB_argc  = argc;
  
  GB_argv  = new std::string[argc];
  for(int i=0; i<argc; ++i)
    GB_argv[i] = argv[i];
  GB_cmdline = "";

  // Get environment variables
//  CheckEnvDir( _T("AMI_HELP"),    GB_help_dir,    _T("tokens.html"));
//  CheckEnvDir( _T("AMI_SCRIPTS"), GB_scripts_dir, _T("scripts.amil"));
  
  GB_help_dir    = ".";
  GB_scripts_dir = ".";
  
  RegisterBuiltinTypes();
  
  AddWrapImports();

  GB_typeconversions.DisplayTypes();
  
   if(tty_break() != 0)
     return 1;
   
  std::string command_input;
  
  std::list<std::string> commands;

  
  start_color();      /* Start color      */
  init_pair(1, COLOR_RED, COLOR_BLACK);
  attron(COLOR_PAIR(1));

  // Get all the mouse events
  mousemask(ALL_MOUSE_EVENTS, NULL);

  refresh();
  
  NcursesWindow cmd_win;
  cmd_win.SetScreenPosition(1,1, 6, 85);
  cmd_win.Create();
  keypad(cmd_win.GetWin(), true); 
  scrollok(cmd_win.GetWin(),TRUE);

  NcursesWindow cout_win;
  cout_win.SetScreenPosition(7,1, 30, 85);
  cout_win.Create();
  keypad(cout_win.GetWin(), true); 
  scrollok(cout_win.GetWin(),TRUE);
  
  NcursesWindow cerr_win;
  cerr_win.SetScreenPosition(32,1, 50, 85);
  cerr_win.Create();
  keypad(cerr_win.GetWin(), true); 
  scrollok(cerr_win.GetWin(),TRUE);
  
  nc::nc_window_streambuf cout_buf( cout_win.GetWin(), std::cout );
  nc::nc_window_streambuf cerr_buf( cerr_win.GetWin(), std::cerr );
  std::cerr << "__Error test" << std::endl;
// 
  std::string current_command = "";
  commands.push_front(current_command);
  std::list<std::string>::iterator commands_it = commands.begin();
  
  int c;
  int cursor_x,cursor_y;
  cmd_win.SetCursorPos(0,0);
  NcursesWindow* current_win = &cmd_win;
  
  std::cout << "start" << std::endl;
  
  while (command_input!="quit")
  {
    
    
    attron(COLOR_PAIR(1));
    cerr_win.Display();
    cout_win.Display();
    bool redraw=true;
    cmd_win.GetCursorXY(cursor_x,cursor_y);
    cmd_win.RefreshCusor();
    c = getch();
    
    int cy = cerr_win.GetCursorY();
//    std::cout << "cerr y pos = " << cy << std::endl;
    
    bool key_mouse = false;
    switch(c)
    {
        case KEY_MOUSE:
          // do nothing for the moment
          key_mouse = true;
          MEVENT event;
          if (getmouse(&event)==OK)
          {
            std::cerr << "mouse state " << event.bstate << std::endl;
            // check on which window is the mouse
            if (cmd_win.IsInside(event.x,event.y)) current_win = &cmd_win;
            else 
            if (cout_win.IsInside(event.x,event.y)) current_win = &cout_win;
            else 
                            current_win = &cerr_win;
            current_win->Display();
          }
          break;
          
        default:
          // automatically set the command window if a character is pressed
          if ((c>=32)&&(c<=126))
            if (current_win!=&cmd_win)
              current_win = &cmd_win;
          
    }
    if (current_win==&cmd_win)
    {
//      std::cout << "current_win is cmd win" << std::endl;

      // don't maintain completion if tab is not pressed
      if (c!=9) 
      {
        in_completion = false;
      }
      
      switch(c)
      {
        
          // tab for completion
          case 9:
            ProcessTab(current_command,cursor_x);
            break;
            
          case KEY_UP:
            // save front command
            if (commands_it == commands.begin())
              commands.front() = command_input;
            ++commands_it;
            if (commands_it == commands.end()) --commands_it;
            current_command = *commands_it;
            break;
          case KEY_DOWN:
            if (commands_it!=commands.begin())
              --commands_it;
            current_command = *commands_it;
            break;
          case KEY_LEFT:
            cursor_x--;
            break;
          case KEY_RIGHT:
            cursor_x++;
            break;
          case KEY_BACKSPACE:
            // locate the character to remove
            // if one line command
            // if multiline command?
            if (cursor_x-1<current_command.size())
            {
              current_command.erase(cursor_x-1,1);
              mvwprintw(cmd_win.GetWin(),0,0,"%s ",current_command.c_str());
            }
            redraw = false;
            cursor_x--;
            break;
  //        case KEY_DC:
  //          break;
        case 10:
        {
  //         current_command+="[enter]";
          command_input = current_command;
          std::cout << current_command << std::endl;
          try{
          GB_driver.parse_string(command_input+"\n");
          }
          catch (std::exception& e)
          {
             std::cerr << e.what() << '\n';
          }
          commands.front() = command_input;
          current_command = "";
          commands.push_front(current_command);
          commands_it = commands.begin();
          cursor_x = 0;
          cursor_y = 0;
          
//           // Get contents
//           char cerr_contents[1000];
//           winnstr(cerr_win.GetWin(),cerr_contents,1000);
//           std::cout <<  "error window contents  = [" << cerr_contents << "]" << std::endl;
        }
          
        break;
          
        default:
          if ((c>=32)&&(c<=126))
          {
            int pos = std::min((int)current_command.size(),cursor_x);
//             std::cout << "pos = " << pos << std::endl;
            if (pos<0) pos = 0;
            current_command.insert(current_command.begin()+pos, char(c));
            cursor_x++;
          }
          else
            std::cerr << (boost::format("[%1%]") % c).str() << std::endl;
      }

      if (redraw)
      {
        wclear(cmd_win.GetWin());
        mvwprintw(cmd_win.GetWin(),0,0,"%s",current_command.c_str());
        //wprintw(cmd_win.GetWin(),"%s",current_command.c_str());
      }
      cmd_win.SetCursorPos(cursor_x,cursor_y);
      cmd_win.Display();
      
      //std::cout << cout_buf.GetLineCount() << std::endl;
    } 
    else
    {
      switch(c)
      {
          case KEY_UP:
          {
            current_win->ScrollUp();
            current_win->Display();
            //std::cerr << "KEY_UP:"<< err << std::endl;
            break;
          }
          case KEY_DOWN:
          {
            current_win->ScrollDown();
            current_win->Display();
            //std::cerr << "KEY_DOWN:" << err << std::endl;
            break;
          }
          case KEY_PPAGE:
          {
            current_win->ScrollUp(10);
            current_win->Display();
            //std::cerr << "KEY_DOWN:" << err << std::endl;
            break;
          }
          case KEY_NPAGE:
          {
            current_win->ScrollDown(10);
            current_win->Display();
            //std::cerr << "KEY_DOWN:" << err << std::endl;
            break;
          }
      }
    }
    
                            /* print the message at the center of the screen */
    
//     putchar(c);
    
//    std::getline(std::cin,command_input);
    //std::cout << " command is '" << command_input << "'" << std::endl;
//    GB_driver.parse_string(command_input+"\n");
  }
  
  tty_fix();
  
  return 0;
}