//-------------------------------------------------------------------------- int main(int /*argc*/, char* /*argv*/[]) { idarpc_stream_t *irs = init_client_irs(NULL, 0); if ( irs == NULL ) { printf("Error: %s\n", winerr(GetLastError())); return 1; } printf("READY\n"); while( true ) { char c = getch(); if ( c == 0x1B ) break; qprintf("%c", c); rpc_packet_t rp; rp.length = 0; rp.code = c; if ( irs_send(irs, &rp, sizeof(rp)) != sizeof(rp) ) { printf("irs_send: %s\n", winerr(irs_error(irs))); break; } memset(&rp, 0, sizeof(rp)); if ( irs_recv(irs, &rp, sizeof(rp), -1) != sizeof(rp) ) { printf("irs_recv: %s\n", winerr(irs_error(irs))); break; } qprintf("%c", rp.code); } qprintf("\n"); term_client_irs(irs); return 0; }
//-------------------------------------------------------------------------- bool rpc_debmod_t::open_remote( const char *hostname, int port_number, const char *password) { rpc_packet_t *rp = NULL; network_error_code = 0; irs = init_client_irs(hostname, port_number); if ( irs == NULL ) { FAILURE: if ( rp != NULL ) qfree(rp); term_irs(); return false; } rp = recv_request(); if ( rp == NULL || rp->code != RPC_OPEN ) // is this an ida debugger server? { rpc_client_t::dwarning("ICON ERROR\nAUTOHIDE NONE\n" "Bogus or irresponsive remote server"); goto FAILURE; } const uchar *answer = (uchar *)(rp+1); const uchar *end = answer + rp->length; int version = extract_long(&answer, end); int remote_debugger_id = extract_long(&answer, end); int easize = extract_long(&answer, end); qstring errstr; if ( version != IDD_INTERFACE_VERSION ) errstr.sprnt("protocol version is %d, expected %d", version, IDD_INTERFACE_VERSION); else if ( remote_debugger_id != debugger.id ) errstr.sprnt("debugger id is %d, expected %d (%s)", remote_debugger_id, debugger.id, debugger.name); else if ( easize != get_expected_addrsize() ) errstr.sprnt("address size is %d bytes, expected %d", easize, inf.is_64bit() ? 8 : 4); if ( !errstr.empty() ) { bytevec_t req = prepare_rpc_packet(RPC_OK); append_dd(req, false); send_request(req); warning("ICON ERROR\nAUTOHIDE NONE\n" "Incompatible debugging server:\n" "%s\n", errstr.c_str()); goto FAILURE; } qfree(rp); bytevec_t req = prepare_rpc_packet(RPC_OK); append_dd(req, true); append_str(req, password); send_request(req); rp = recv_request(); if ( rp == NULL || rp->code != RPC_OK ) goto FAILURE; answer = (uchar *)(rp+1); end = answer + rp->length; bool password_ok = extract_long(&answer, end) != 0; if ( !password_ok ) // is this an ida debugger server? { warning("ICON ERROR\nAUTOHIDE NONE\n" "Bad password"); goto FAILURE; } qfree(rp); return true; }
//-------------------------------------------------------------------------- bool rpc_debmod_t::open_remote(const char *hostname, int port_number, const char *password) { rpc_packet_t *rp = NULL; irs = init_client_irs(hostname, port_number); if (irs == NULL) { failed: connection_failed(rp); return false; } rp = recv_request(PRF_DONT_POLL); if ( rp == NULL ) goto failed; if ( rp->code != RPC_OPEN ) // is this an ida debugger server? { connection_failed(rp); rpc_client_t::dwarning("ICON ERROR\nAUTOHIDE NONE\n" "Bogus remote server"); return false; } const uchar *answer = (uchar *)(rp+1); const uchar *end = answer + rp->length; int version = extract_long(&answer, end); int remote_debugger_id = extract_long(&answer, end); int easize = extract_long(&answer, end); qstring errstr; if ( version != IDD_INTERFACE_VERSION ) errstr.sprnt("protocol version is %d, expected %d", version, IDD_INTERFACE_VERSION); else if ( remote_debugger_id != debugger.id ) errstr.sprnt("debugger id is %d, expected %d (%s)", remote_debugger_id, debugger.id, debugger.name); else if ( easize != (inf.is_64bit() ? 8 : 4) ) errstr.sprnt("address size is %d bytes, expected %d", easize, inf.is_64bit() ? 8 : 4); if ( !errstr.empty() ) { connection_failed(rp); qstring cmd = prepare_rpc_packet(RPC_OK); append_long(cmd, false); send_request(cmd); warning("ICON ERROR\nAUTOHIDE NONE\n" "Incompatible debugging server:\n" "%s\n", errstr.c_str()); return false; } qfree(rp); qstring cmd = prepare_rpc_packet(RPC_OK); append_long(cmd, true); append_str(cmd, password); send_request(cmd); rp = recv_request(PRF_DONT_POLL); if ( rp == NULL || rp->code != RPC_OK ) goto failed; answer = (uchar *)(rp+1); end = answer + rp->length; bool password_ok = extract_long(&answer, end); if ( !password_ok ) // is this an ida debugger server? { connection_failed(rp); warning("ICON ERROR\nAUTOHIDE NONE\n" "Bad password"); return false; } qfree(rp); return true; }