コード例 #1
0
ファイル: server.cpp プロジェクト: nealey/vera
int ida_server(DWORD dwInput, BYTE* pInput,
               DWORD* pcbOutput, BYTE** ppOutput,
               IRAPIStream* pStream)
{
  lprintf("IDA " SYSTEM SYSBITS " remote debug server v1.%d.\n"
    "Copyright Hex-Rays 2004-2010\n", IDD_INTERFACE_VERSION);

  // Call the debugger module to initialize its subsystem once
  if ( !init_subsystem() )
  {
    lprintf("Could not initialize subsystem!");
    return -1;
  }

  // check our crc32
  DWORD crc32 = calc_our_crc32((char *)pInput);
  DWORD dummy = 0;
  pStream->Write(&crc32, sizeof(crc32), &dummy);
  if ( dummy != sizeof(crc32) )
  {
ERR:
    pStream->Release();
    //    lprintf("Debugger server checksum mismatch - shutting down\n");
    return ERROR_CRC;
  }
  DWORD ok;
  dummy = 0;
  pStream->Read(&ok, sizeof(ok), &dummy);
  if ( dummy != sizeof(ok) || ok != 1 )
    goto ERR;

  // only one instance is allowed
  if ( in_use )
  {
    static const char busy[] = "BUSY";
    pStream->Write(busy, sizeof(busy)-1, &dummy);
    pStream->Release();
    return ERROR_BUSY;
  }
  in_use = true;

  ptr = (uchar*)ida_server;
  idarpc_stream_t *irs;
  {
    get_permissions_t all_permissions;
    irs = protected_privileged_session(pStream);
  }

  if ( irs != NULL )
    term_server_irs(irs);

  in_use = false;
  return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: limitusus/perfmonger
int
main(int argc, char **argv)
{
    option_t opt;
    if (parse_args(argc, argv, &opt) != 0){
        fprintf(stderr, "Argument error. Exit.\n");
        exit(EXIT_FAILURE);
    }

    init_subsystem(&opt);
    collector_loop(&opt);
    destroy_subsystem(&opt);

    return 0;
}
コード例 #3
0
//--------------------------------------------------------------------------
static bool init_plugin(void)
{
#ifndef RPC_CLIENT
  if (!init_subsystem())
    return false;
#endif
  if ( !netnode::inited() || is_miniidb() || inf.is_snapshot() )
  {
    //dosbox is always remote.
    return debugger.is_remote();
  }

  if ( inf.filetype != f_EXE && inf.filetype != f_COM )
    return false; // only MSDOS EXE or COM files
  if ( ph.id != PLFM_386 )
    return false; // only IBM PC

  return true;
}
コード例 #4
0
ファイル: server.cpp プロジェクト: nealey/vera
//--------------------------------------------------------------------------
// debugger remote server - TCP/IP mode
int NT_CDECL main(int argc, char *argv[])
{
  int port_number = DEBUGGER_PORT_NUMBER;
  lprintf("IDA " SYSTEM SYSBITS " remote debug server(" __SERVER_TYPE__ ") v1.%d. Copyright HexRays 2004-2010\n", IDD_INTERFACE_VERSION);
  while ( argc > 1 && (argv[1][0] == '-' || argv[1][0] == '/'))
  {
    switch ( argv[1][1] )
    {
    case 'p':
      port_number = atoi(&argv[1][2]);
      break;
    case 'P':
      server_password = argv[1] + 2;
      break;
    case 'v':
      verbose = true;
      break;
    default:
      error("usage: ida_remote [switches]\n"
        "  -p...  port number\n"
        "  -P...  password\n"
        "  -v     verbose\n");
    }
    argv++;
    argc--;
  }

  // call the debugger module to initialize its subsystem once
  if (
    !init_subsystem()
#ifndef __SINGLE_THREADED_SERVER__
    || ((g_lock = qmutex_create())== NULL)
#endif
    )
  {
    lprintf("Could not initialize subsystem!");
    return -1;
  }

#ifndef __NT__
  signal(SIGHUP, shutdown_gracefully);
#endif
  signal(SIGINT, shutdown_gracefully);
  signal(SIGTERM, shutdown_gracefully);
  signal(SIGSEGV, shutdown_gracefully);
  //  signal(SIGPIPE, SIG_IGN);

  if ( !init_irs_layer() )
  {
    neterr(NULL, "init_sockets");
  }

  listen_socket = socket(AF_INET, SOCK_STREAM, 0);

  if ( listen_socket == -1 )
    neterr(NULL, "socket");

  setup_irs((idarpc_stream_t*)listen_socket);

  struct sockaddr_in sa;
  memset(&sa, 0, sizeof(sa));
  sa.sin_family = AF_INET;
  sa.sin_port   = qhtons(short(port_number));

  if ( bind(listen_socket, (sockaddr *)&sa, sizeof(sa)) == SOCKET_ERROR )
    neterr((idarpc_stream_t *)listen_socket, "bind");

  if ( listen(listen_socket, SOMAXCONN) == SOCKET_ERROR )
    neterr((idarpc_stream_t *)listen_socket, "listen");

  hostent *local_host = gethostbyname("");
  if ( local_host != NULL )
  {
    const char *local_ip = inet_ntoa (*(struct in_addr *)*local_host->h_addr_list);
    if ( local_host->h_name != NULL && local_ip != NULL )
      lprintf("Host %s (%s): ", local_host->h_name, local_ip);
    else if ( local_ip != NULL )
      lprintf("Host %s: ", local_ip);
  }
  lprintf("Listening on port #%u...\n", port_number);

  while ( true )
  {
    sockaddr_in sa;
    socklen_t salen = sizeof(sa);
    SOCKET rpc_socket = accept(listen_socket, (sockaddr *)&sa, &salen);
    if ( rpc_socket == -1 )
      neterr((idarpc_stream_t *)listen_socket, "accept");
#if defined(__LINUX__) && defined(LIBWRAP)
    const char *p;
    if ( (p=check_connection(rpc_socket)) != NULL )
    {
      fprintf(stderr,
        "ida-server CONNECTION REFUSED from %s (tcp_wrappers)\n", p);
      shutdown(rpc_socket, 2);
      close(rpc_socket);
      continue;
    }
#endif // defined(__LINUX__) && defined(LIBWRAP)

    rpc_server_t *server = new rpc_server_t(rpc_socket);
    server->verbose = verbose;
    server->set_debugger_instance(create_debug_session());
    handle_session(server);
  }
/* NOTREACHED
  term_subsystem();
#ifndef __SINGLE_THREADED_SERVER__
  qmutex_free(g_lock);
#endif
*/
}
コード例 #5
0
ファイル: kmain.c プロジェクト: Kijewski/chaOS
void
_start (void)
{
  // debugging
  /*
  volatile char xxx = 0;
  while (xxx == 0)
    asm volatile ("pause" ::: "memory");
  //*/

  // clear BSS:
  memset (&_section_bss_start[0], 0,
          &_section_bss_end[0] - &_section_bss_start[0]);

  videoram_cls (COLOR_NORMAL);

  // some welcoming information:
  videoram_printf ("\n  Welcome to \e%c chaOS! \n\n", COLOR_ERROR);
  put_cpu_info ();
  put_memory_map ();

  if (!nx_bit_present ())
    {
      videoram_puts (" Your CPU does not support the NX bit! \n", COLOR_ERROR);
      khalt ();
    }

  init_subsystem ("interrupt handling", &interrupts_init, NULL);

  videoram_puts ("Running a syscall test: ", COLOR_NORMAL);
  if (syscall_test ())
    videoram_put_right (" ok ", COLOR_INFO);
  else
    {
      videoram_put_right (" FAIL ", COLOR_ERROR);
      khalt ();
    }

  init_subsystem ("PIC", &pic_init, NULL);
  pit_set_handler (pic_handler_fun);
  pic_mask (~PIC_MASK_PIT);

  videoram_puts ("Setting CPU standards", COLOR_NORMAL);
  cr0_set_reset (CR0_WP|CR0_NE, CR0_MP|CR0_EM|CR0_NE|CR0_AM|CR0_CD|CR0_NW);
  msr_set_reset (MSR_EFER, EFER_NXE, 0);
  videoram_put_right (" ok ", COLOR_INFO);

  init_subsystem ("paging", &paging_init, NULL);

  videoram_puts ("Enabling interrupts", COLOR_NORMAL);
  asm volatile ("sti");
  videoram_put_right (" ok ", COLOR_INFO);

  init_subsystem ("real-time clock", &rtc_init, NULL);
  init_subsystem ("timeout handler", &timeout_init, NULL);
  init_subsystem ("random number generator", &random_init, NULL);
  init_subsystem ("frame allocator", &frame_allocator_init, NULL);

  init_subsystem ("Interrupt timer (33Hz)", &pit_init_33hz, NULL);
  pic_mask (~0);

  init_subsystem ("PS/2 keyboard", &keyboard_init, NULL);
  init_subsystem ("PS/2 mouse", &mouse_init, NULL);

  init_subsystem ("keypress handler", &keypress_handler_init, NULL);
  ENSURE (keypress_handler_set_keymap (KEYMAP_QWERTZ_DE_DE));

  // TODO: initialize more subsystems

  put_welcoming_message ();

  // TODO: do something
  for (;;)
    {
      int c = keypress_handler_getc ();
      if (!c)
        break;
      if (c < 128 && c != 127)
        videoram_printf ("C: <%c>\n", c);
    }
  
  khalt ();
}
コード例 #6
0
ファイル: server.cpp プロジェクト: mailwl/android_server
//--------------------------------------------------------------------------
// debugger remote server - TCP/IP mode
int NT_CDECL main(int argc, char *argv[])
{
#ifdef ENABLE_LOWCNDS
  init_idc();
#endif

  // call the debugger module to initialize its subsystem once
  if ( !init_lock()
    || !init_subsystem()
#ifndef __SINGLE_THREADED_SERVER__
    || !srv_lock_init()
#endif
    )
  {
    lprintf("Could not initialize subsystem!");
    return -1;
  }

  bool reuse_conns = are_broken_connections_supported();
  int port_number = DEBUGGER_PORT_NUMBER;
  lprintf("IDA " SYSTEM SYSBITS " remote debug server(" __SERVER_TYPE__ ") v1.%d. Hex-Rays (c) 2004-2014\n", IDD_INTERFACE_VERSION);
  while ( argc > 1 && (argv[1][0] == '-' || argv[1][0] == '/'))
  {
    switch ( argv[1][1] )
    {
    case 'p':
      port_number = atoi(&argv[1][2]);
      break;
    case 'P':
      server_password = argv[1] + 2;
      break;
    case 'i':
      ipv4_address = argv[1] + 2;
      break;
    case 'v':
      verbose = true;
      break;
    case 'k':
      if ( !reuse_conns )
        error("Sorry, debugger doesn't support reusing broken connections\n");
      keep_broken_connections = true;
      break;
    default:
      error("usage: ida_remote [switches]\n"
               "  -i...  IP address to bind to (default to any)\n"
               "  -v     verbose\n"
               "  -p...  port number\n"
               "  -P...  password\n"
               "%s", reuse_conns ? "  -k     keep broken connections\n" : "");
      break;
    }
    argv++;
    argc--;
  }

#ifndef UNDER_CE
#ifndef __NT__
  signal(SIGHUP, shutdown_gracefully);
#endif
  signal(SIGINT, shutdown_gracefully);
  signal(SIGTERM, shutdown_gracefully);
  signal(SIGSEGV, shutdown_gracefully);
  //  signal(SIGPIPE, SIG_IGN);
#endif

  if ( !init_irs_layer() )
  {
    neterr(NULL, "init_sockets");
  }

  listen_socket = socket(AF_INET, SOCK_STREAM, 0);
  if ( listen_socket == INVALID_SOCKET )
    neterr(NULL, "socket");

  idarpc_stream_t *irs = (idarpc_stream_t *)listen_socket;
  setup_irs(irs);

  struct sockaddr_in sa;
  memset(&sa, 0, sizeof(sa));
  sa.sin_family = AF_INET;
  sa.sin_port   = qhtons(short(port_number));
  if ( ipv4_address != NULL )
    sa.sin_addr.s_addr = inet_addr(ipv4_address);
  if( sa.sin_addr.s_addr == INADDR_NONE )
  {
    lprintf("Cannot parse IP v4 address %s, falling back to INADDR_ANY\n", ipv4_address);
    sa.sin_addr.s_addr = INADDR_ANY;
    ipv4_address = NULL;
  }

  if ( bind(listen_socket, (sockaddr *)&sa, sizeof(sa)) == SOCKET_ERROR )
    neterr(irs, "bind");

  if ( listen(listen_socket, SOMAXCONN) == SOCKET_ERROR )
    neterr(irs, "listen");

  hostent *local_host = gethostbyname("");
  if ( local_host != NULL )
  {
    const char *local_ip;
    if ( ipv4_address != NULL )
      local_ip = ipv4_address;
    else
      local_ip = inet_ntoa(*(struct in_addr *)*local_host->h_addr_list);
    if ( local_host->h_name != NULL && local_ip != NULL )
      lprintf("Host %s (%s): ", local_host->h_name, local_ip);
    else if ( local_ip != NULL )
      lprintf("Host %s: ", local_ip);
  }
  lprintf("Listening on port #%u...\n", port_number);

  while ( true )
  {
    socklen_t salen = sizeof(sa);
    SOCKET rpc_socket = accept(listen_socket, (sockaddr *)&sa, &salen);
    if ( rpc_socket == INVALID_SOCKET )
    {
#ifdef UNDER_CE
      if ( WSAGetLastError() != WSAEINTR )
#else
      if ( errno != EINTR )
#endif
        neterr(irs, "accept");
      continue;
    }
#if defined(__LINUX__) && defined(LIBWRAP)
    const char *p = check_connection(rpc_socket);
    if ( p != NULL )
    {
      fprintf(stderr,
        "ida-server CONNECTION REFUSED from %s (tcp_wrappers)\n", p);
      shutdown(rpc_socket, 2);
      close(rpc_socket);
      continue;
    }
#endif // defined(__LINUX__) && defined(LIBWRAP)

    rpc_server_t *server = new rpc_server_t((idarpc_stream_t *)rpc_socket);
    server->verbose = verbose;
    server->set_debugger_instance(create_debug_session());
    {
#ifdef UNDER_CE
      get_permissions_t all_permissions;
#endif
      handle_session(server);
    }
  }
/* NOTREACHED
  term_lock();
  term_subsystem();
#ifndef __SINGLE_THREADED_SERVER__
  qmutex_free(g_lock);
#endif
*/
}