Logo Search packages:      
Sourcecode: eresi version File versions  Download package

int revm_loop ( int  argc,
char **  argv 
)

The infinite main loop of the interactive command

Definition at line 15 of file loop.c.

References profiler_error(), revm_execmd(), revm_execscript(), revm_loop(), revm_output(), revm_parseopt(), and revm_select().

Referenced by revm_loop(), and revm_run().

{
  int       ret;

  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);
  ret = 0;

  do {

    /* Come back to the loop if a script turns into interactive mode */
  reenter:

    /* Fill argv from stdin if we are in interactive mode */
    if ((world.state.revm_mode != REVM_STATE_CMDLINE 
       && world.state.revm_mode != REVM_STATE_TRACER) 
      || world.state.revm_net == 1)
      {
      if (world.state.revm_mode != REVM_STATE_SCRIPT)
        {
          if (revm_select() < 0)
            {
            fprintf(stderr,"revm_select : failed \n");
            revm_exit(-1);
            }

          /* If the FIFO does not exist anymore, 
             the server has quit, so we quit too */
          if (world.state.revm_mode == REVM_STATE_DEBUGGER && 
            (access(REVM_FIFO_S2C, F_OK) < 0 || 
             access(REVM_FIFO_C2S, F_OK) < 0))
            PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);         
        }

      /* Take a line, execute old command if void line */
      argv = revm_input(&argc, NULL);
      if (world.state.revm_mode == REVM_STATE_INTERACTIVE ||
          world.state.revm_mode == REVM_STATE_DEBUGGER    ||
          world.state.revm_mode == REVM_STATE_SCRIPT      ||
          world.state.revm_net)
        {
          if (argv == ((char **) REVM_INPUT_VOID))
            continue;
          else if (argv == ((char **) REVM_INPUT_TRANSFERED))
            continue;
        }

      /* CTRL-D -> !argv */
      if (!argv)
        {
          revm_output("\n");

          /* when debugging -> back to main program */
          if (world.state.revm_mode == REVM_STATE_DEBUGGER)
            {
            revm_cleanup();
            PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, ret);
            }

          /* if net is enable but we are not in e2dbg -> ignore */
          if (world.state.revm_net)
            continue;

          /* othewise exit */
          break;

        }
      }

    /* Fetch the current scripting command */
    if (revm_parseopt(argc, argv) < 0)
      {
      if (world.state.revm_mode != REVM_STATE_CMDLINE
          && world.state.revm_mode != REVM_STATE_TRACER)
        {
          XFREE(__FILE__, __FUNCTION__, __LINE__, argv);
          if (world.state.revm_mode != REVM_STATE_INTERACTIVE &&
            world.state.revm_mode != REVM_STATE_DEBUGGER)
            goto end;
        }
      else if (!world.state.revm_net)
        revm_exit(-1);
      }

    /* Just execute one command if we are not in script mode */
    if (world.state.revm_mode != REVM_STATE_SCRIPT)
      {
      world.curjob->curcmd = world.curjob->script[0];
      switch (revm_execmd())
        {
        case REVM_SCRIPT_CONTINUE:
          //printf(" [*] e2dbg continue from revm_execmd \n");
          revm_cleanup();
          PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, ret);         
        case REVM_SCRIPT_ERROR:
          profiler_error();
        default:
          break;
        }
      }

    /* Quit parsing if necessary */
    if ((!world.curjob->curcmd && world.state.revm_mode == REVM_STATE_SCRIPT)) //||
      /*(world.curjob->curcmd && world.curjob->curcmd->name &&
       (!strcmp(world.curjob->curcmd->name, CMD_QUIT) ||
       !strcmp(world.curjob->curcmd->name, CMD_QUIT2))))*/
      break;
  }
  while ((world.state.revm_mode != REVM_STATE_CMDLINE
        && world.state.revm_mode != REVM_STATE_TRACER)
       || world.state.revm_net);

  /* If we are in scripting, execute commands list now */
  if (world.state.revm_mode == REVM_STATE_SCRIPT)
    {
      fprintf(stderr, "we are in script mode from revm_loop ! \n");

      world.curjob->curcmd = world.curjob->script[0];
      ret = revm_execscript();
      if (ret == REVM_SCRIPT_STOP)
      {
        XCLOSE(world.curjob->ws.io.input_fd, -1);
        world.curjob->ws.io.input_fd = 0;
        goto reenter;
      }
      else if (ret < 0)
      profiler_error();
    }

 end:
  revm_postexec(ret);
  revm_callback_handler_remove();
  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, (ret));

  /* Clean the script machine state when a script is over */
  //XXX: looks never called now -- world.curjob->curcmd = NULL;
  //revm_cleanup();
  //PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, (ret));
}


Generated by  Doxygen 1.6.0   Back to index