static bool idaapi pdiff_menu_callback(void *ud) { ushort option = 0, prev = 0; options_t * opt = (options_t *)ud; const char format[] = "STARTITEM 0\n" "PatchDiff2 options\n" "<##Settings #>\n" "<#Uses 'pipe' with the second IDA instance to speed up graph display#Keep second IDB open :C>\n" "<#Saves PatchDiff2 results into the current IDB#Save results to IDB :C>>\n\n" ; option |= opt->ipc ? 1 : 0; option |= opt->save_db ? 2 : 0; prev = opt->ipc; if (AskUsingForm_c(format, &option)) { opt->ipc = !!(option & 1); opt->save_db = !!(option & 2); if (prev && !option) ipc_close(); } return true; }
int main(int argc, char ** argv){ char * program_name; struct status cl_program; int i; ipc_params_t client_params; init_processes(); if(argc > 1){ program_name = argv[1]; }else{ printf("Entrada incorrecta\n"); return 0; } client_params = get_params_from_pid(getpid(), PROGRAM_STATUS, sizeof(struct status)); client_header_t header = calloc(1, sizeof(struct client_header)); header->program_size = strlen(program_name); header->client_id = getpid(); ipc_open(server_params, O_WRONLY); server_params->msg_type = PRE_HEADER; ipc_send(server_params, header, sizeof(struct client_header)); server_params->msg_type = PROGRAM_STRING; ipc_send(server_params, program_name, header->program_size); ipc_close(server_params); ipc_create(client_params); ipc_open(client_params, O_RDONLY); while (!ipc_receive(client_params, &cl_program, sizeof(struct status))); ipc_close(client_params); ipc_destroy(client_params); for (i = 0; i < MEM_SIZE; i++){ printf("%d ", cl_program.mem[i]); } printf("\n"); return 0; }
static void idaapi close_window(void *obj) { deng_t * d = (deng_t *)obj; d->wnum--; if (!d->wnum) ipc_close(); return; }
psa_status_t psa_mac_abort(psa_mac_operation_t *operation) { if (operation->handle <= PSA_NULL_HANDLE) { return (PSA_SUCCESS); } psa_crypto_ipc_t psa_crypto_ipc = { .func = PSA_MAC_ABORT, .handle = 0, .alg = 0 }; psa_invec in_vec = { &psa_crypto_ipc, sizeof(psa_crypto_ipc) }; psa_status_t status = ipc_call(&operation->handle, &in_vec, 1, NULL, 0, true); return (status); } static psa_status_t psa_mac_setup(psa_mac_operation_t *operation, psa_key_handle_t key_handle, psa_algorithm_t alg, psa_sec_function_t func) { if (operation->handle != PSA_NULL_HANDLE) { return (PSA_ERROR_BAD_STATE); } psa_crypto_ipc_t psa_crypto_ipc = { .func = func, .handle = key_handle, .alg = alg }; psa_invec in_vec = { &psa_crypto_ipc, sizeof(psa_crypto_ipc) }; psa_status_t status = ipc_connect(PSA_MAC_ID, &operation->handle); if (status != PSA_SUCCESS) { return (status); } status = ipc_call(&operation->handle, &in_vec, 1, NULL, 0, false); if (status != PSA_SUCCESS) { ipc_close(&operation->handle); } return (status); } psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation, psa_key_handle_t key_handle, psa_algorithm_t alg) { psa_status_t status = psa_mac_setup(operation, key_handle, alg, PSA_MAC_SIGN_SETUP); return (status); }
void gui_shutdown(GtkObject *object, gpointer user_data) { printf("Shutting down...\n"); if(ipc_close() < 0) printf("Could not close socket!\n"); printf("BYE-BYE!\n"); exit(0); }
coroutine void client2(int u) { int s = tls_attach_client(u, -1); errno_assert(s >= 0); int rc = bsend(s, "ABC", 3, -1); errno_assert(rc == 0); u = tls_detach(s, -1); errno_assert(u >= 0); rc = bsend(u, "DEF", 3, -1); errno_assert(rc == 0); rc = ipc_close(u, -1); errno_assert(rc == 0); }
static void idaapi term(void) { if (d_engine) { if (options_save_db(d_opt)) backup_save_results(d_engine); diff_engine_free(d_engine); unhook_from_notification_point(HT_UI, ui_callback); } ipc_close(); options_close(d_opt); }
void shutdown_(int sig) { int errNr = errno; printf("Cleaning up...\n"); if (ipc_close() < 0) printf("Could not close socket!\n"); printf("BYE-BYE!\n"); errno = errNr; exit(sig); }
int ipc_init(int from_id) { printf("%s: init...\n", from_id == SRV_ID? "Server":"Client"); switch(from_id) { case SRV_ID: ipc_close(from_id); __set_srv_socket(from_id); __verify(bind(__srv_socket, res->ai_addr, res->ai_addrlen), "Bind error"); __verify(listen(__srv_socket, BACKLOG), "Listen error"); return OK; default: return OK; } }
static psa_status_t ipc_call(psa_handle_t *handle, psa_invec *in_vec, size_t in_vec_size, psa_outvec *out_vec, size_t out_vec_size, bool close) { if (*handle <= PSA_NULL_HANDLE) { return (PSA_ERROR_BAD_STATE); } psa_status_t status = psa_call(*handle, in_vec, in_vec_size, out_vec, out_vec_size); if (close) { ipc_close(handle); } return (status); }
void answer_error_to_client(int err_code, int client_id){ ipc_params_t client_params; status client_program; client_params = get_params_from_pid(client_id, PROGRAM_STATUS, sizeof(struct status), server_params->semid); client_params->socklistener = TRUE; client_program.flag = err_code; printf("Answering to client: %d\n", client_id); ipc_open(client_params, O_WRONLY); ipc_send(client_params, &client_program, sizeof(struct status)); ipc_close(client_params); free(client_params->file); free(client_params); }
void * run_program(void * program_stat) { ipc_params_t client_params; stack_t c_stack; graph_t c_graph; int memkey, i; status client_program; process_t process_type; thread_status_t thread_info = (thread_status_t)program_stat; c_stack = parse_file((char*)thread_info->file); c_graph = build_graph(c_stack); if (c_graph != NULL) { create_sh_graph(c_graph, get_graph_size(c_graph), &memkey, &client_program.g_header); client_program.cursor = 0; client_program.flag = FALSE; for(i = 0; i < MEM_SIZE; i++) { client_program.mem[i] = 0; } process_type = c_graph->first->instruction_process->instruction_type; client_program.mtype = process_type->params->unique_mq_id; ipc_send(process_type->params, &client_program, sizeof(struct status)); } else { printf("Entrada incorrecta\n"); } while(!ipc_receive(server_receive_params, &client_program, sizeof(struct status))) sleep(1); client_params = get_params_from_pid(thread_info->client_id, PROGRAM_STATUS, sizeof(struct status)); ipc_open(client_params, O_WRONLY); ipc_send(client_params, &client_program, sizeof(struct status)); ipc_close(client_params); }
void * run_server_receive(void * params){ ipc_params_t client_params; status client_final; ipc_create(server_receive_params); ipc_open(server_receive_params, O_RDONLY|O_NONBLOCK); while(1){ if(ipc_receive(server_receive_params, &client_final, sizeof(struct status))){ client_params = get_params_from_pid(client_final.client_id, PROGRAM_STATUS, sizeof(struct status), server_params->semid); client_params->socklistener = TRUE; printf("Answering to client: %d\n", client_final.client_id); ipc_open(client_params, O_WRONLY); ipc_send(client_params, &client_final, sizeof(struct status)); ipc_close(client_params); free(client_params->file); free(client_params); } sleep(1); } }
void myquitcallback(int sig) { TutOut("myquitcallback called with signal %d\n",sig); ipc_close(); exit(0); }
int *ipc_close_(void) { return( (int*) ipc_close() ); }
int main(int argc, char **argv) { int i = 0, client_id; char buf[200]; boolean failed = false; FILE * file; string messages[] = {"hello", "world!", NULL}; switch (fork()) { case -1: __fatal("Fork error"); break; case 0: /* child */ usleep(1000); client_id=getpid(); while ( messages[i]!=NULL && !failed ) { printf("\nEntro hijo\n"); ipc_connect(client_id, SRV_ID); printf("\nChild: about to send (\"%s\")\n", messages[i]); ipc_send(client_id, SRV_ID, messages[i], strlen(messages[i])); printf("Child: msg sent\n"); ipc_recv(client_id, buf, SRV_RESP_LEN); printf("Child: response received (%.*s)\n", SRV_RESP_LEN, buf); failed = !strneq(OK_MSG, buf, SRV_RESP_LEN); if (failed) { printf("Child: Error\n"); } else { printf("Child: ok response received\n"); } ipc_disconnect(client_id, SRV_ID); i++; } ipc_close(client_id); printf("Child: out %s\n",failed? "[ERROR]":"[OK]"); break; default: /* parent */ printf("\nPadre:\n"); printf("Server id in Test%d\n", getpid()); ipc_init(SRV_ID); printf("\nEntro padre\n"); while ( messages[i]!=NULL ) { ipc_connect(SRV_ID, INVALID); printf("Parent: about to read\n"); ipc_recv(SRV_ID, buf, strlen(messages[i])); // I can't omit this because usually the server receives the id at the beginning file=__open("client", "r", CLIENT_PATH); if(file==NULL){ printf("%s\n","Error opening client id file in parent"); } while(fscanf(file, "%d\n", &client_id) != EOF) {;} printf("Client id %d\n", client_id); printf("Parent: read (\"%.*s\") --(expecting: \"%s\")\n", (int)strlen(messages[i]), buf, messages[i]); if (strneq(messages[i], buf, strlen(messages[i]))) { printf("Parent: [OK]\n"); ipc_send(SRV_ID, client_id, OK_MSG, SRV_RESP_LEN); } else { printf("Parent: [ERROR]\n"); ipc_send(SRV_ID, client_id, NOT_OK_MSG, SRV_RESP_LEN); } ipc_disconnect(SRV_ID, INVALID); fclose(file); file = NULL; i++; } usleep(1000); ipc_close(SRV_ID); printf("Parent: out\n"); break; } return 0; }
int main(void) { char buf[16]; /* Test simple data exchange, with explicit handshake. */ int u[2]; int rc = ipc_pair(u); errno_assert(rc == 0); int cr = go(client1(u[1])); errno_assert(cr >= 0); int s = tls_attach_server(u[0], "tests/cert.pem", "tests/key.pem", -1); errno_assert(s >= 0); rc = brecv(s, buf, 3, -1); errno_assert(rc == 0); assert(buf[0] == 'A' && buf[1] == 'B' && buf[2] == 'C'); rc = brecv(s, buf, 3, -1); errno_assert(rc == -1 && errno == EPIPE); rc = bsend(s, "DEF", 3, -1); errno_assert(rc == 0); rc = tls_done(s, -1); errno_assert(rc == 0); u[0] = tls_detach(s, -1); errno_assert(u[0] >= 0); rc = hclose(u[0]); errno_assert(rc == 0); rc = bundle_wait(cr, -1); errno_assert(rc == 0); rc = hclose(cr); errno_assert(rc == 0); /* Test simple data transfer, terminated by tls_detach(). Then send some data over undelying IPC connection. */ rc = ipc_pair(u); errno_assert(rc == 0); cr = go(client2(u[1])); errno_assert(cr >= 0); s = tls_attach_server(u[0], "tests/cert.pem", "tests/key.pem", -1); errno_assert(s >= 0); rc = brecv(s, buf, 3, -1); errno_assert(rc == 0); assert(buf[0] == 'A' && buf[1] == 'B' && buf[2] == 'C'); u[0] = tls_detach(s, -1); errno_assert(u[0] >= 0); rc = brecv(u[0], buf, 3, -1); errno_assert(rc == 0); assert(buf[0] == 'D' && buf[1] == 'E' && buf[2] == 'F'); rc = ipc_close(u[0], -1); errno_assert(rc == 0); rc = bundle_wait(cr, -1); errno_assert(rc == 0); rc = hclose(cr); errno_assert(rc == 0); /* Transfer large amount of data. */ rc = ipc_pair(u); errno_assert(rc == 0); cr = go(client3(u[1])); errno_assert(cr >= 0); s = tls_attach_server(u[0], "tests/cert.pem", "tests/key.pem", -1); errno_assert(s >= 0); uint8_t c = 0; int i; for(i = 0; i != 2777; ++i) { uint8_t b[257]; rc = brecv(s, b, sizeof(b), -1); errno_assert(rc == 0); int j; for(j = 0; j != sizeof(b); ++j) { assert(b[j] == c); c++; } } u[0] = tls_detach(s, -1); errno_assert(u[0] >= 0); rc = bundle_wait(cr, -1); errno_assert(rc == 0); rc = hclose(cr); errno_assert(rc == 0); rc = hclose(u[0]); errno_assert(rc == 0); return 0; }
void company_closeIpc() { log_debug("Closing IPC"); ipc_close(company->id + 1); }