コード例 #1
0
ファイル: preloader.c プロジェクト: depletionmode/preloader
static void _exec_target(char *target_path, char *params, char *lib_path, int flags)
{
  _disable_display();

  exec_target( target_path, params, lib_path );

  if( flags & EXEC_PROMPT ) {
    fprintf( stderr,"\n\nPress enter to continue...\n" );
    getchar();
  }

  _init_display();
}
コード例 #2
0
ファイル: fakecygpty.c プロジェクト: jfmc/fakecygpty
int
main (int argc, char* argv[])
{
  struct termios oldtm;
  fd_set sel, sel0;
  int status;
  char* newarg0;

  /* SIGINT and SIGBREAK are indistinctive under cygwin environment. */
  /* Using Win32API to handle SIGINT.                              */
  SetConsoleCtrlHandler (ctrl_handler, TRUE);

  if (argc < 1)
    {
      fprintf (stderr, "Unable to get arg[0].");
      exit (1);
    }

  newarg0 = real_command_name (argv[0]);
  if (newarg0)
    {
      argv[0] = newarg0;
      exec_target (argv);     /* This sets globals masterfd, child_pid */
    }
  else if (argc > 1)
    {
      exec_target (argv + 1); /* This sets globals masterfd, child_pid */
    }
  else
    {
      fprintf (stderr, "Unable to get arg[1].");
      exit (1);
    }

  setup_tty_attributes ();

  FD_ZERO (&sel0);
  FD_SET (masterfd, &sel0);
  FD_SET (0, &sel0);

  /* communication loop */
  while (1)
    {
      char buf[BUFSIZE];
      int ret;

      sel = sel0;
      if (select (FD_SETSIZE, &sel, NULL, NULL, NULL) <= 0)
	break;

      if (FD_ISSET (masterfd, &sel))
	{
	  ret = read (masterfd, buf, BUFSIZE);
	  if (ret > 0)
	      write (1, buf, ret);
	  else
	    break;
	}
      else if (FD_ISSET (0, &sel))
	{
	  ret = read (0, buf, BUFSIZE);
	  if (ret > 0)
	      write (masterfd, buf, ret);
	  else
	    {
	      FD_CLR (0, &sel0);
	      close (masterfd);
	    }
	}
    }

  restore_tty_attributes ();

  kill (child_pid, SIGKILL);
  waitpid (child_pid, &status, 0);
  return WEXITSTATUS (status);
}
コード例 #3
0
ファイル: btrace.c プロジェクト: 0x36/BinTrace
int main(int argc, char **argv)
{
	struct bt_opts opts;
	struct btproc *bt_proc;

	bt_proc = parse_args(argc, argv, &opts);

	bt_proc->pi->pi_debug = opts.debug_opt;
	if (opts.target_opt && opts.pid_opt) {
		bt_proc_destroy(bt_proc);
		printfd(2,
			FATAL " You can't choose target and pid together !\n");
		btrace_banner(*argv, 1);
	} else if (!opts.target_opt && !opts.pid_opt) {
		printfd(2, FATAL "No such target or porcess\n");
		btrace_banner(*argv, 1);
	} else {
		/* using target executable */
		if (opts.target_opt) {
			bt_proc->exec =
			    check_target_path(bt_proc->pi->pi_target,
					      bt_proc->pi->pi_perm);

			if (!bt_proc->exec) {
				bt_proc_destroy(bt_proc);
				btrace_banner(*argv, 1);
			}
			if (opts.target_has_args)
				bt_proc->args_parser((char *)bt_proc->pi->
						     pi_args, bt_proc);

			else
				bt_proc->proc_arguments[0] =
				    strdup((const char *)bt_proc->exec);

			if ((!opts.force_addr_opt && opts.off_opt) ||
			    (opts.force_addr_opt && !opts.off_opt)) {
				printfd(STDERR_FILENO,
					WARN
					"You may choose both of address and offset !\n");
				bt_proc_destroy(bt_proc);
				btrace_banner(*argv, 1);
			}
			/* if address & offset are set */
			else {
				bt_proc->pi->pi_stack->ma_map[0] =
					bt_proc->pi->pi_address;
				bt_proc->pi->pi_stack->ma_map[1] =
					bt_proc->pi->pi_address +
					bt_proc->pi->pi_offset;
				
				bt_proc->pi->pi_addr->ma_map[0] =
				    bt_proc->pi->pi_address;
				bt_proc->pi->pi_addr->ma_map[1] =
				    bt_proc->pi->pi_address +
				    bt_proc->pi->pi_offset;
			}

			exec_target(bt_proc);

			/* If force address and offset are not set we read 
			 * from profs and fetch memory base address 
			 * and write new elf binary
			 */
			if (!opts.force_addr_opt && !opts.off_opt) {
				printfd(2,
					DO "Target :" GREEN " %s " NORM
					" PID : " GREEN "%d" NORM "\n",
					bt_proc->exec, bt_proc->pi->pi_pid);
				if (read_procfs_maps(bt_proc->pi) == -1)
					die("no such process");
			}

			fetch_data(bt_proc->pi);
		}

		/* pid attach */
		if (opts.pid_opt) {
			if (attach_process(bt_proc->pi) == -1)
				die(FATAL "Can't attach process");

			get_cmdline_by_pid(bt_proc->pi);
			printfd(2,
				DO "Attach PID:" GREEN " %d" NORM "  Target :"
				GREEN " %s" NORM "\n", bt_proc->pi->pi_pid,
				bt_proc->pi->pi_perm->p_full_path);

			if ((!opts.force_addr_opt && opts.off_opt) ||
			    (opts.force_addr_opt && !opts.off_opt)) {
				printfd(STDERR_FILENO,
					WARN
					"You may choose both of address and offset !\n");
				bt_proc_destroy(bt_proc);
				btrace_banner(*argv, 1);
			}
			/* if address & offset are set */
			else {
				bt_proc->pi->pi_stack->ma_map[0] =
					bt_proc->pi->pi_address;
				bt_proc->pi->pi_stack->ma_map[1] =
					bt_proc->pi->pi_address +
					bt_proc->pi->pi_offset;
				
				bt_proc->pi->pi_addr->ma_map[0] =
				    bt_proc->pi->pi_address;
				bt_proc->pi->pi_addr->ma_map[1] =
				    bt_proc->pi->pi_address +
				    bt_proc->pi->pi_offset;

			}

			if (!opts.force_addr_opt && !opts.off_opt)
				if (read_procfs_maps(bt_proc->pi) == -1)
					die(FATAL "No such process");

			/* it shouldn't return anything 
			 * BACK TO ME 
			 */
			fetch_data(bt_proc->pi);
		}

		if (opts.raw_opt)
			raw_dump(bt_proc->pi);
		else
			dump_using_memory(bt_proc->pi);

		if(opts.elf_dump_opts) {
			
		}
		
		pinfo_destroy(bt_proc->pi);
		bt_proc_destroy(bt_proc);

	}
	return 0;

}
コード例 #4
0
ファイル: fakecygpty.c プロジェクト: d5884/fakecygpty
int main(int argc, char* argv[])
{
  fd_set sel, sel0;
  int status;
  int pty_alloc_only = FALSE;
  char* newarg0;

  /* SIGINT and SIGBREAK are indistinctive under cygwin environment. */
  /* Using Win32API to handle SIGINT.                               */
  SetConsoleCtrlHandler(ctrl_handler, TRUE);

  if (argc < 1) {
    fputs("Unable to get arg[0].", stderr);
    exit(EXIT_FAILURE);
  }

  newarg0 = real_command_name(argv[0]);

  if (newarg0)
    argv[0] = newarg0;
  else if (argc >=2)
    argv++;
  else
    pty_alloc_only = TRUE;

  if (isatty(STDIN_FILENO) && !pty_alloc_only) {
    execvp(argv[0], argv);
    fprintf(stderr, "Failed to execute \"%s\": %s\n", argv[0], strerror(errno));
    exit(EXIT_FAILURE);
  }

  master_fd = open_master_pty();

  child_pid = exec_target(master_fd, argv, pty_alloc_only);

  setup_signal_handlers();

  FD_ZERO(&sel0);
  FD_SET(master_fd, &sel0);
  FD_SET(STDIN_FILENO, &sel0);

  /* communication loop */
  while (1) {
    char buf[BUFSIZE];
    int ret;

    if (sig_winch_caught == TRUE) {
      sig_winch_caught = FALSE;
      if (child_pid != -1 && resize_tty_window(master_fd, sig_window_size) == 0)
	kill(child_pid, SIGWINCH);
    }

    sel = sel0;
    if (select (FD_SETSIZE, &sel, NULL, NULL, NULL) <= 0) {
      if(errno == EINTR)
	continue;
      else
	break;
    }

    if (FD_ISSET(master_fd, &sel)) {
      ret = safe_read(master_fd, buf, BUFSIZE);
      if (ret > 0) {
	if (safe_write_full(STDOUT_FILENO, buf, ret) < 0)
	  break;
      }
      else
	break;
    }
    else if (FD_ISSET(STDIN_FILENO, &sel)) {
      ret = safe_read(STDIN_FILENO, buf, BUFSIZE);
      if (ret > 0) {
	if (safe_write_full_checking_eof(master_fd, buf, ret) < 0)
	  break;
      } else {
	FD_CLR(STDIN_FILENO, &sel0);
	close(master_fd);
      }
    }
  }

  if (pty_alloc_only) {
    kill(child_pid, SIGKILL);
    status = 0;
  } else {
    while(waitpid(child_pid, &status, 0) < 0 && errno == EINTR)
      ;

    if (WIFEXITED(status))
      status = WEXITSTATUS(status);
    else if(WIFSIGNALED(status)) /* ntemacs cannot distinct killed by signal */
      status = 0x80 +  WTERMSIG(status);
  }

  return status;
}