int main(int argc, char *argv[]) { char buffer[MAX_PACKET_SIZE]; static struct sockaddr_in addr; int rc, i, count; struct timeval t1, t2, dt; KICK(argc < 3, "incorrect usage\n" "Usage:\n" "./linphone_proxy <local_ip> <remote_ip>\n"); local_ip = argv[1]; remote_ip = argv[2]; add_poll(&fds[0], STDIN_FILENO); proxy_to_linphone_socket = create_socket(SOCK_DGRAM, SIP_LINPHONE); init_sockaddr(&proxy_to_linphone_addr, "127.0.0.1", SIP_PORT); add_poll(&fds[1], proxy_to_linphone_socket); eprintf("created proxy_to_linphone SIP socket SRC:localhost:%d - DST:localhost:%d\n", SIP_LINPHONE, SIP_PORT); proxy_to_proxy_socket = create_socket(SOCK_DGRAM, SIP_PROXY); init_sockaddr(&proxy_to_proxy_addr, remote_ip, SIP_PROXY); add_poll(&fds[2], proxy_to_proxy_socket); eprintf("created proxy_to_sip SIP socket SRC:localhost:%d - DST:%s:%d\n", SIP_PROXY, remote_ip, SIP_PROXY); proxy_to_linphone_data_socket = create_socket(SOCK_DGRAM, DATA_LINPHONE); init_sockaddr(&proxy_to_linphone_data_addr, "127.0.0.1", DATA_PORT); add_poll(&fds[3], proxy_to_linphone_data_socket); eprintf("created proxy_to_linphone DATA socket SRC:localhost:%d - DST:localhost:%d\n", DATA_LINPHONE, DATA_PORT); proxy_to_proxy_data_socket = create_socket(SOCK_DGRAM, DATA_PROXY); init_sockaddr(&proxy_to_proxy_data_addr, remote_ip, DATA_PROXY); add_poll(&fds[4], proxy_to_proxy_data_socket); eprintf("created proxy_to_proxy DATA socket SRC:localhost:%d - DST:%s:%d\n", DATA_PROXY, remote_ip, DATA_PROXY); manager_socket = create_socket(SOCK_DGRAM, MANAGER_PORT); init_sockaddr(&manager_addr, "0.0.0.0", MANAGER_PORT); add_poll(&fds[5], manager_socket); eprintf("created manager socket SRC:localhost:%d - DST:0.0.0.0:0\n", MANAGER_PORT); while (1) { rc = poll(fds, NUM_FDS, -1); DIE(-1 == rc, "poll"); for (i = 0; i < NUM_FDS; i++) { if (0 == fds[i].revents) { continue; } switch(i) { /* receive line from console */ case 0: break; /* receive SIP packet from linphone */ case 1: gettimeofday_safe(&t1); count = recv_msg(fds[i].fd, &proxy_to_linphone_addr, buffer); if (begins_with(buffer, "INVITE")) { copy_packet(&out_invite, buffer, count); //printf("captured INVITE packet:\n%s\n", out_invite.buffer); } else if (begins_with(buffer, "ACK")) { copy_packet(&out_ack, buffer, count); //printf("captured ACK packet:\n%s\n", out_ack.buffer); } else if (strstr(buffer, "200 OK") && strstr(buffer, "OPTIONS" )) { copy_packet(&out_op_ok, buffer, count); //printf("captured OPTIONS OK packet:\n%s\n", out_op_ok.buffer); } send_msg(proxy_to_proxy_socket, &proxy_to_proxy_addr, buffer, count); gettimeofday_safe(&t2); time_diff(&t1, &t2, &dt); printf("time case 1: %lu.%06lu\n", dt.tv_sec, dt.tv_usec); break; /* receive SIP packet from proxy */ case 2: gettimeofday_safe(&t1); count = recv_msg(fds[i].fd, &addr, buffer); send_msg(proxy_to_linphone_socket, &proxy_to_linphone_addr, buffer, count); gettimeofday_safe(&t2); time_diff(&t1, &t2, &dt); printf("time case 2: %lu.%06lu\n", dt.tv_sec, dt.tv_usec); break; /* receive data packet from linphone */ case 3: gettimeofday_safe(&t1); count = recv_msg(fds[i].fd, &proxy_to_linphone_data_addr, buffer); send_msg(proxy_to_proxy_data_socket, &proxy_to_proxy_data_addr, buffer, count); gettimeofday_safe(&t2); time_diff(&t1, &t2, &dt); printf("time case 3: %lu.%06lu\n", dt.tv_sec, dt.tv_usec); break; /* receive data packet from proxy */ case 4: gettimeofday_safe(&t1); count = recv_msg(fds[i].fd, &addr, buffer); send_msg(proxy_to_linphone_data_socket, &proxy_to_linphone_data_addr, buffer, count); gettimeofday_safe(&t2); time_diff(&t1, &t2, &dt); printf("time case 4: %lu.%06lu\n", dt.tv_sec, dt.tv_usec); break; /* receive command from manager */ case 5: count = recv_msg(fds[i].fd, &manager_addr, buffer); if (begins_with(buffer, "IP: ")) { while (!isdigit(buffer[count - 1])) { buffer[--count] = 0; } strcpy(migrate_ip, buffer + 4); migrate_init(); } else if (begins_with(buffer, "establish")) { migrate_establish(); } else if (begins_with(buffer, "redirect: ")) { while (!isdigit(buffer[count - 1])) { buffer[--count] = 0; } strcpy(redirect_ip, buffer + 10); migrate_redirect(); } break; /* error */ default: break; } } } return EXIT_SUCCESS; }
static void usage(void) { eprintf("usage: %s [name]\n", argv0); }
int main(int argc, char **argv) { const char *addr = NULL; RCore *c, *c2; RDiff *d; ut8 *bufa, *bufb; int o, sza, szb, /*diffmode = 0,*/ delta = 0; int mode = MODE_DIFF; int diffops = 0; int threshold = -1; int gdiff_mode = 0; double sim; while ((o = getopt (argc, argv, "a:b:CDnpg:Ojrhcdsvxt:")) != -1) { switch (o) { case 'a': arch = optarg; break; case 'b': bits = atoi (optarg); break; case 'p': useva = false; break; case 'r': diffmode = 'r'; break; case 'g': mode = MODE_GRAPH; addr = optarg; break; case 'c': showcount = 1; break; case 'C': mode = MODE_CODE; gdiff_mode++; break; case 'n': showbare = true; break; case 'O': diffops = 1; break; case 't': threshold = atoi (optarg); printf ("%s\n", optarg); break; case 'd': delta = 1; break; case 'D': disasm = true; break; case 'h': return show_help (1); case 's': mode = MODE_DIST; break; case 'x': mode = MODE_COLS; break; case 'v': printf ("radiff2 v"R2_VERSION"\n"); return 0; case 'j': diffmode = 'j'; break; default: return show_help (0); } } if (argc<3 || optind+2>argc) return show_help (0); if (optind<argc) { file = argv[optind]; } else { file = NULL; } if (optind+1<argc) { file2 = argv[optind+1]; } else { file2 = NULL; } switch (mode) { case MODE_GRAPH: case MODE_CODE: c = opencore (file); if (!c) eprintf ("Cannot open '%s'\n", r_str_get (file)); c2 = opencore (file2); if (!c || !c2) { eprintf ("Cannot open '%s'\n", r_str_get (file2)); return 1; } if (arch) { r_config_set (c->config, "asm.arch", arch); r_config_set (c2->config, "asm.arch", arch); } if (bits) { r_config_set_i (c->config, "asm.bits", bits); r_config_set_i (c2->config, "asm.bits", bits); } r_config_set_i (c->config, "diff.bare", showbare); r_config_set_i (c2->config, "diff.bare", showbare); r_anal_diff_setup_i (c->anal, diffops, threshold, threshold); r_anal_diff_setup_i (c2->anal, diffops, threshold, threshold); if (mode == MODE_GRAPH) { char *words = strdup (addr? addr: "0"); char *second = strstr (words, ","); if (second) { ut64 off; *second++ = 0; off = r_num_math (c->num, words); // define the same function at each offset r_core_anal_fcn (c, off, UT64_MAX, R_ANAL_REF_TYPE_NULL, 0); r_core_anal_fcn (c2, r_num_math (c2->num, second), UT64_MAX, R_ANAL_REF_TYPE_NULL, 0); r_core_gdiff (c, c2, false); // compute the diff r_core_anal_graph (c, off, R_CORE_ANAL_GRAPHBODY | R_CORE_ANAL_GRAPHDIFF); } else { r_core_anal_fcn (c, r_num_math (c->num, words), UT64_MAX, R_ANAL_REF_TYPE_NULL, 0); r_core_anal_fcn (c2, r_num_math (c2->num, words), UT64_MAX, R_ANAL_REF_TYPE_NULL, 0); r_core_gdiff (c, c2, gdiff_mode); r_core_anal_graph (c, r_num_math (c->num, addr), R_CORE_ANAL_GRAPHBODY | R_CORE_ANAL_GRAPHDIFF); } free (words); } else { r_core_gdiff (c, c2, gdiff_mode); r_core_diff_show (c, c2); } r_cons_flush (); return 0; } bufa = (ut8*)r_file_slurp (file, &sza); if (!bufa) { eprintf ("radiff2: Cannot open %s\n", r_str_get (file)); return 1; } bufb = (ut8*)r_file_slurp (file2, &szb); if (!bufb) { eprintf ("radiff2: Cannot open: %s\n", r_str_get (file2)); free (bufa); return 1; } switch (mode) { case MODE_COLS: { int cols = (r_cons_get_size (NULL)>112)?16:8; dump_cols (bufa, sza, bufb, szb, cols); } break; case MODE_DIFF: d = r_diff_new (0LL, 0LL); r_diff_set_delta (d, delta); if (diffmode == 'j') { printf("{\"files\":[{\"filename\":\"%s\", \"size\":%d, \"sha256\":\"", file, sza); handle_sha256 (bufa, sza); printf("\"},\n{\"filename\":\"%s\", \"size\":%d, \"sha256\":\"", file2, szb); handle_sha256 (bufb, szb); printf("\"}],\n"); printf("\"changes\":["); } r_diff_set_callback (d, &cb, 0);//(void *)(size_t)diffmode); r_diff_buffers (d, bufa, sza, bufb, szb); if (diffmode == 'j') printf("]\n"); r_diff_free (d); break; case MODE_DIST: r_diff_buffers_distance (NULL, bufa, sza, bufb, szb, &count, &sim); printf ("similarity: %.2f\n", sim); printf ("distance: %d\n", count); break; } if (diffmode == 'j' && showcount) printf (",\"count\":%d}\n",count); else if (showcount && diffmode != 'j') printf ("%d\n", count); else if (!showcount && diffmode == 'j') printf ("}\n"); free (bufa); free (bufb); return 0; }
R_API int r_core_visual_panels(RCore *core) { #define OS_INIT() ostack.size = 0; ostack.panels[0] = 0; #define OS_PUSH(x) if (ostack.size<LIMIT) {ostack.panels[++ostack.size]=x;} #define OS_POP() ((ostack.size>0)? ostack.panels[--ostack.size]:0) int okey, key, wheel; int w, h; int asm_comments = 0; int asm_bytes = 0; n_panels = 0; panels = NULL; callgraph = 0; _core = core; OS_INIT(); w = r_cons_get_size (&h); can = r_cons_canvas_new (w, h); can->linemode = 1; can->color = r_config_get_i (core->config, "scr.color"); // disable colors in disasm because canvas doesnt supports ansi text yet r_config_set_i (core->config, "scr.color", 0); //can->color = 0; if (!can) { eprintf ("Cannot create RCons.canvas context\n"); return R_FALSE; } n_panels = bbPanels (core, &panels); if (!panels) { r_config_set_i (core->config, "scr.color", can->color); free (can); return R_FALSE; } reloadPanels (core); asm_comments = r_config_get_i (core->config, "asm.comments"); r_config_set_i (core->config, "asm.comments", 0); asm_bytes = r_config_get_i (core->config, "asm.bytes"); r_config_set_i (core->config, "asm.bytes", 0); repeat: core->cons->event_data = core; core->cons->event_resize = \ (RConsEvent)r_core_panels_refresh; w = r_cons_get_size (&h); Layout_run (panels); r_core_panels_refresh (core); wheel = r_config_get_i (core->config, "scr.wheel"); if (wheel) r_cons_enable_mouse (R_TRUE); // r_core_graph_inputhandle() okey = r_cons_readchar (); key = r_cons_arrow_to_hjkl (okey); switch (key) { case ' ': case '\n': if (menu_y) { const char *action = menus_sub[menu_x][menu_y-1]; eprintf ("ACTION %s\n", action); if (strstr (action, "New")) { int i; // add new panel for testing for (i=0; panels[i].text; i++) { // find last panel } panels[i].text = strdup ("Test"); panels[i].cmd = r_str_newf ("pxW $r-2"); panels[i].addr = core->offset; panels[i].type = PANEL_TYPE_FRAME; i++; n_panels++; panels[i].text = NULL; } if (strstr (action, "Quit")) { goto beach; } } break; case '?': r_cons_clear00 (); r_cons_printf ("Visual Ascii Art Panels:\n" " ! run r2048 game\n" " . - center graph to the current node\n" " : - run r2 command in prompt\n" " hl - toggle scr.color\n" " HL - move vertical column split\n" " JK - select prev/next panels\n" " jk - scroll/select menu\n" " q - quit, back to visual mode\n" ); r_cons_flush (); r_cons_any_key (NULL); break; case ':': core->vmode = R_FALSE; r_core_visual_prompt_input (core); core->vmode = R_TRUE; break; case 'C': can->color = !!!can->color; //WTF //r_config_swap (core->config, "scr.color"); // refresh graph // reloadPanels (core); break; case '!': r_cons_2048 (); break; case 'j': if (panels[curnode].type == PANEL_TYPE_FLOAT) { if (menus_sub[menu_x][menu_y]) menu_y ++; } break; case 'k': if (panels[curnode].type == PANEL_TYPE_FLOAT) { menu_y --; if (menu_y<0) menu_y = 0; } break; case 'J': curnode++; if (!panels[curnode].text) { curnode--; } break; case 'K': curnode--; if (curnode<0) curnode = 0; break; case 'H': COLW += 4; break; case 'L': COLW -= 4; if (COLW<0) COLW=0; break; case 'h': if (menu_x) { menu_x --; menu_y = menu_y?1:0; } break; case 'l': if (menus[menu_x + 1]) { menu_x ++; menu_y = menu_y?1:0; } break; case 'q': case -1: // EOF goto beach; case 27: // ESC if (r_cons_readchar () == 91) { if (r_cons_readchar () == 90) { } } break; default: //eprintf ("Key %d\n", key); //sleep (1); break; } goto repeat; beach: free (panels); r_config_set_i (core->config, "scr.color", can->color); free (can); r_config_set_i (core->config, "asm.comments", asm_comments); r_config_set_i (core->config, "asm.bytes", asm_bytes); return R_TRUE; }
static void usage(void) { eprintf("usage: %s [-dqtu] [-p directory] [template]\n", argv0); }
int main(int argc, char **argv) { int maxtokens = 50; int ntokens, verbose = 0, i; Tokenizer *tkz; const char *sep; char str[100]; #ifdef NDEBUG eprintf("ERR@%s:%d:" "Unit tests must be compiled without -DNDEBUG flag\n", __FILE__, __LINE__); #endif switch (argc) { case 1: break; case 2: if(strncmp(argv[1], "-v", 2) != 0) eprintf("usage: xtokenizer [-v]\n"); verbose = 1; break; default: eprintf("usage: xtokenizer [-v]\n"); } tkz = Tokenizer_new(maxtokens); assert(Tokenizer_ntokens(tkz) == 0); strcpy(str, "; now; \t: \t is ::the ,time \n,"); sep = ";:,"; if(verbose) { printf("sep=\"%s\"\n", sep); printf("str=\"%s\"\n", str); } ntokens = Tokenizer_split(tkz, str, sep); if(verbose) { printf("ntokens=%d\n", ntokens); fflush(stdout); } assert(ntokens == Tokenizer_ntokens(tkz)); assert(ntokens == 5); assert(strcmp(Tokenizer_token(tkz, 0), " now") == 0); assert(strcmp(Tokenizer_token(tkz, 1), " \t") == 0); assert(strcmp(Tokenizer_token(tkz, 2), " \t is ") == 0); assert(strcmp(Tokenizer_token(tkz, 3), "the ") == 0); assert(strcmp(Tokenizer_token(tkz, 4), "time \n") == 0); if(verbose) { for(i = 0; i < ntokens; ++i) printf("%4d \"%s\"\n", i, Tokenizer_token(tkz, i)); } ntokens = Tokenizer_strip(tkz, " \t\n"); assert(ntokens == 4); assert(strcmp(Tokenizer_token(tkz, 0), "now") == 0); assert(strcmp(Tokenizer_token(tkz, 1), "is") == 0); assert(strcmp(Tokenizer_token(tkz, 2), "the") == 0); assert(strcmp(Tokenizer_token(tkz, 3), "time") == 0); assert(Tokenizer_find(tkz, "now") == 0); assert(Tokenizer_find(tkz, "is") == 1); assert(Tokenizer_find(tkz, "the") == 2); assert(Tokenizer_find(tkz, "time") == 3); assert(Tokenizer_find(tkz, "not there") == ntokens); if(verbose) { printf("after stripping extraneous chars, ntokens is %d\n", ntokens); for(i = 0; i < ntokens; ++i) printf("%4d \"%s\"\n", i, Tokenizer_token(tkz, i)); printf("Tokenizer_print:\n"); Tokenizer_print(tkz, stdout); } strcpy(str, "afasf"); ntokens = Tokenizer_split(tkz, str, ":"); assert(ntokens == 1); strcpy(str, ""); ntokens = Tokenizer_split(tkz, str, ":"); assert(ntokens == 0); Tokenizer_free(tkz); unitTstResult("Tokenizer", "OK"); fflush(stdout); return 0; }
bool uiAskNextVolume(wchar *VolName,size_t MaxSize) { eprintf(St(MAskNextVol),VolName); return Ask(St(MContinueQuit))!=2; }
static void Read_EDGE_DATA_SECTION() { Node *Ni, *Nj; int i, j; CheckSpecificationPart(); if (!EdgeDataFormat) eprintf("Missing EDGE_DATA_FORMAT specification"); if (!FirstNode) CreateNodes(); if (ProblemType == HPP) Dimension--; if (!strcmp(EdgeDataFormat, "EDGE_LIST")) { if (!fscanint(ProblemFile, &i)) i = -1; while (i != -1) { if (i <= 0 || i > (ProblemType != ATSP ? Dimension : Dimension / 2)) eprintf("(EDGE_DATA_SECTION) Node number out of range: %d", i); fscanint(ProblemFile, &j); if (j <= 0 || j > (ProblemType != ATSP ? Dimension : Dimension / 2)) eprintf("(EDGE_DATA_SECTION) Node number out of range: %d", j); if (i == j) eprintf("(EDGE_DATA_SECTION) Illgal edge: %d to %d", i, j); if (ProblemType == ATSP) { i += Dimension / 2; j += Dimension / 2; } Ni = &NodeSet[i]; Nj = &NodeSet[j]; if (!Ni->CandidateSet) { Ni->V = 1; assert(Ni->CandidateSet = (Candidate *) calloc(2, sizeof(Candidate))); Ni->CandidateSet[0].To = Nj; Ni->CandidateSet[0].Cost = 0; } else { Ni->CandidateSet[Ni->V].To = Nj; Ni->CandidateSet[Ni->V].Cost = 0; assert(Ni->CandidateSet = (Candidate *) realloc(Ni->CandidateSet, (++Ni->V + 1) * sizeof(Candidate))); Ni->CandidateSet[Ni->V].To = 0; } if (!Nj->CandidateSet) { Nj->V = 1; assert(Nj->CandidateSet = (Candidate *) calloc(3, sizeof(Candidate))); Nj->CandidateSet[0].To = Ni; Nj->CandidateSet[0].Cost = 0; } else { Nj->CandidateSet[Nj->V].To = Ni; Nj->CandidateSet[Nj->V].Cost = 0; assert(Nj->CandidateSet = (Candidate *) realloc(Nj->CandidateSet, (++Nj->V + 1) * sizeof(Candidate))); Nj->CandidateSet[Nj->V].To = 0; } fscanint(ProblemFile, &i); } } else if (!strcmp(EdgeDataFormat, "ADJ_LIST")) { Ni = FirstNode; do Ni->V = 0; while ((Ni = Ni->Suc) != FirstNode); if (!fscanint(ProblemFile, &i)) i = -1; while (i != -1) { if (i <= 0 || i > (ProblemType != ATSP ? Dimension : Dimension / 2)) eprintf("(EDGE_DATA_SECTION) Node number out of range: %d", i); if (ProblemType == ATSP) i += Dimension / 2; Ni = &NodeSet[i]; fscanint(ProblemFile, &j); while (j != -1) { if (j <= 0 || j > (ProblemType != ATSP ? Dimension : Dimension / 2)) eprintf ("(EDGE_DATA_SECTION) Node number out of range: %d", j); if (i == j) eprintf("(EDGE_DATA_SECTION) Illgal edge: %d to %d", i, j); if (ProblemType == ATSP) j += Dimension / 2; Nj = &NodeSet[j]; if (!Ni->CandidateSet) { Ni->V = 1; assert(Ni->CandidateSet = (Candidate *) calloc(3, sizeof(Candidate))); Ni->CandidateSet[0].To = Nj; Ni->CandidateSet[0].Cost = 0; } else { Ni->CandidateSet[Ni->V].To = Nj; Ni->CandidateSet[Ni->V].Cost = 0; assert(Ni->CandidateSet = (Candidate *) realloc(Ni->CandidateSet, (++Ni->V + 1) * sizeof(Candidate))); Ni->CandidateSet[Ni->V].To = 0; } if (!Nj->CandidateSet) { Nj->V = 1; assert(Nj->CandidateSet = (Candidate *) calloc(3, sizeof(Candidate))); Nj->CandidateSet[0].To = Ni; Nj->CandidateSet[0].Cost = 0; } else { Nj->CandidateSet[Nj->V].To = Ni; Nj->CandidateSet[Nj->V].Cost = 0; assert(Nj->CandidateSet = (Candidate *) realloc(Nj->CandidateSet, (++Nj->V + 1) * sizeof(Candidate))); Nj->CandidateSet[Nj->V].To = 0; } fscanint(ProblemFile, &j); } fscanint(ProblemFile, &i); } } else eprintf("(EDGE_DATA_SECTION) No EDGE_DATA_FORMAT specified"); if (ProblemType == HPP) Dimension++; Distance = Distance_1; }
static void Read_EDGE_WEIGHT_SECTION() { Node *Ni, *Nj; int i, j, n, W; CheckSpecificationPart(); if (!FirstNode) CreateNodes(); if (ProblemType != ATSP) { assert(CostMatrix = (int *) calloc(Dimension * (Dimension - 1) / 2, sizeof(int))); Ni = FirstNode->Suc; do { Ni->C = &CostMatrix[(Ni->Id - 1) * (Ni->Id - 2) / 2] - 1; } while ((Ni = Ni->Suc) != FirstNode); } else { n = Dimension / 2; assert(CostMatrix = (int *) calloc(n * n, sizeof(int))); for (Ni = FirstNode; Ni->Id <= n; Ni = Ni->Suc) Ni->C = &CostMatrix[(Ni->Id - 1) * n] - 1; } if (ProblemType == HPP) Dimension--; switch (WeightFormat) { case FULL_MATRIX: if (ProblemType == ATSP) { n = Dimension / 2; for (i = 1; i <= n; i++) { Ni = &NodeSet[i]; for (j = 1; j <= n; j++) { if (!fscanint(ProblemFile, &W)) eprintf("Missing weight in EDGE_WEIGHT_SECTION"); Ni->C[j] = W; if (i != j && W > M) M = W; } Nj = &NodeSet[i + n]; if (!Ni->FixedTo1) Ni->FixedTo1 = Nj; else if (!Ni->FixedTo2) Ni->FixedTo2 = Nj; if (!Nj->FixedTo1) Nj->FixedTo1 = Ni; else if (!Nj->FixedTo2) Nj->FixedTo2 = Ni; } Distance = Distance_ATSP; WeightType = -1; } else for (i = 1, Ni = FirstNode; i <= Dimension; i++, Ni = Ni->Suc) { for (j = 1; j <= Dimension; j++) { if (!fscanint(ProblemFile, &W)) eprintf("Missing weight in EDGE_WEIGHT_SECTION"); if (j < i) Ni->C[j] = W; } } break; case UPPER_ROW: for (i = 1, Ni = FirstNode; i < Dimension; i++, Ni = Ni->Suc) { for (j = i + 1, Nj = Ni->Suc; j <= Dimension; j++, Nj = Nj->Suc) { if (!fscanint(ProblemFile, &W)) eprintf("Missing weight in EDGE_WEIGHT_SECTION"); Nj->C[i] = W; } } break; case LOWER_ROW: for (i = 2, Ni = FirstNode->Suc; i <= Dimension; i++, Ni = Ni->Suc) { for (j = 1; j < i; j++) { if (!fscanint(ProblemFile, &W)) eprintf("Missing weight in EDGE_WEIGHT_SECTION"); Ni->C[j] = W; } } break; case UPPER_DIAG_ROW: for (i = 1, Ni = FirstNode; i <= Dimension; i++, Ni = Ni->Suc) { for (j = i, Nj = Ni; j <= Dimension; j++, Nj = Nj->Suc) { if (!fscanint(ProblemFile, &W)) eprintf("Missing weight in EDGE_WEIGHT_SECTION"); if (i != j) Nj->C[i] = W; } } break; case LOWER_DIAG_ROW: for (i = 1, Ni = FirstNode; i <= Dimension; i++, Ni = Ni->Suc) { for (j = 1; j <= i; j++) { if (!fscanint(ProblemFile, &W)) eprintf("Missing weight in EDGE_WEIGHT_SECTION"); if (j != i) Ni->C[j] = W; } } break; case UPPER_COL: for (j = 2, Nj = FirstNode->Suc; j <= Dimension; j++, Nj = Nj->Suc) { for (i = 1; i < j; i++) { if (!fscanint(ProblemFile, &W)) eprintf("Missing weight in EDGE_WEIGHT_SECTION"); Nj->C[i] = W; } } break; case LOWER_COL: for (j = 1, Nj = FirstNode; j < Dimension; j++, Nj = Nj->Suc) { for (i = j + 1, Ni = Nj->Suc; i <= Dimension; i++, Ni = Ni->Suc) { if (!fscanint(ProblemFile, &W)) eprintf("Missing weight in EDGE_WEIGHT_SECTION"); Ni->C[j] = W; } } break; case UPPER_DIAG_COL: for (j = 1, Nj = FirstNode; j <= Dimension; j++, Nj = Nj->Suc) { for (i = 1; i <= j; i++) { if (!fscanint(ProblemFile, &W)) eprintf("Missing weight in EDGE_WEIGHT_SECTION"); if (i != j) Nj->C[i] = W; } } break; case LOWER_DIAG_COL: for (j = 1, Nj = FirstNode; j <= Dimension; j++, Ni = Ni->Suc) { for (i = j, Ni = Nj; i <= Dimension; i++, Ni = Ni->Suc) { if (!fscanint(ProblemFile, &W)) eprintf("Missing weight in EDGE_WEIGHT_SECTION"); if (i != j) Ni->C[j] = W; } } break; } if (ProblemType == HPP) Dimension++; }
void CheckSpecificationPart() { if (ProblemType == -1) eprintf("TYPE is missing"); if (Dimension < 3) eprintf("DIMENSION < 3 or not specified"); if (WeightType == -1 && ProblemType != ATSP && ProblemType != HCP) eprintf("EDGE_WEIGHT_TYPE is missing"); if (WeightType == EXPLICIT && WeightFormat == -1) eprintf("EDGE_WEIGHT_FORMAT is missing"); if (WeightType == EXPLICIT && WeightFormat == FUNCTION) eprintf("Conflicting EDGE_WEIGHT_TYPE and EDGE_WEIGHT_FORMAT"); if (WeightType != EXPLICIT && (WeightType != SPECIAL || CoordType != NO_COORDS) && WeightType != -1 && WeightFormat != -1 && WeightFormat != FUNCTION) eprintf("Conflicting EDGE_WEIGHT_TYPE and EDGE_WEIGHT_FORMAT"); if (ProblemType == ATSP && WeightType != EXPLICIT && WeightType != -1) eprintf("Conflicting TYPE and EDGE_WEIGHT_TYPE"); if (ProblemType == ATSP && WeightFormat != FULL_MATRIX) eprintf("Conflicting TYPE and EDGE_WEIGHT_FORMAT"); if (CandidateSetType == DELAUNAY && !TwoDWeightType() && MaxCandidates > 0) eprintf ("Illegal EDGE_WEIGHT_TYPE for CANDIDATE_SET_TYPE = DELAUNAY"); if (CandidateSetType == NN && !TwoDWeightType() && !ThreeDWeightType() && MaxCandidates > 0) eprintf ("Illegal EDGE_WEIGHT_TYPE for CANDIDATE_SET_TYPE = " "NEAREST-NEIGHBOR"); if (CandidateSetType == QUADRANT && !TwoDWeightType() && !ThreeDWeightType() && MaxCandidates + ExtraCandidates > 0) eprintf ("Illegal EDGE_WEIGHT_TYPE for CANDIDATE_SET_TYPE = QUADRANT"); if (ExtraCandidateSetType == NN && !TwoDWeightType() && !ThreeDWeightType() && ExtraCandidates > 0) eprintf ("Illegal EDGE_WEIGHT_TYPE for EXTRA_CANDIDATE_SET_TYPE = " "NEAREST-NEIGHBOR"); if (ExtraCandidateSetType == QUADRANT && !TwoDWeightType() && !ThreeDWeightType() && ExtraCandidates > 0) eprintf ("Illegal EDGE_WEIGHT_TYPE for EXTRA_CANDIDATE_SET_TYPE = " "QUADRANT"); if (InitialTourAlgorithm == QUICK_BORUVKA && !TwoDWeightType() && !ThreeDWeightType()) eprintf ("Illegal EDGE_WEIGHT_TYPE for INITIAL_TOUR_ALGORITHM = " "QUICK-BORUVKA"); if (InitialTourAlgorithm == SIERPINSKI && !TwoDWeightType()) eprintf ("Illegal EDGE_WEIGHT_TYPE for INITIAL_TOUR_ALGORITHM = " "SIERPINSKI"); if (DelaunayPartitioning && !TwoDWeightType()) eprintf("Illegal EDGE_WEIGHT_TYPE for DELAUNAY specification"); if (KarpPartitioning && !TwoDWeightType() && !ThreeDWeightType()) eprintf("Illegal EDGE_WEIGHT_TYPE for KARP specification"); if (MoorePartitioning && !TwoDWeightType()) eprintf("Illegal EDGE_WEIGHT_TYPE for MOORE specification"); if (RohePartitioning && !TwoDWeightType() && !ThreeDWeightType()) eprintf("Illegal EDGE_WEIGHT_TYPE for ROHE specification"); if (SierpinskiPartitioning && !TwoDWeightType()) eprintf("Illegal EDGE_WEIGHT_TYPE for SIERPINSKI specification"); if (SubproblemBorders && !TwoDWeightType() && !ThreeDWeightType()) eprintf("Illegal EDGE_WEIGHT_TYPE for BORDERS specification"); }
static void Read_NAME() { if (!(Name = Copy(strtok(0, Delimiters)))) eprintf("NAME: string expected"); }
void ReadProblem() { int i, K; char *Line, *Keyword; if (!(ProblemFile = fopen(ProblemFileName, "r"))) eprintf("Cannot open PROBLEM_FILE: \"%s\"", ProblemFileName); if (TraceLevel >= 1) printff("Reading PROBLEM_FILE: \"%s\" ... ", ProblemFileName); FreeStructures(); FirstNode = 0; WeightType = WeightFormat = -1; CoordType = NO_COORDS; Name = "Unnamed"; Type = EdgeWeightType = EdgeWeightFormat = 0; EdgeDataFormat = NodeCoordType = DisplayDataType = 0; Distance = 0; C = 0; c = 0; while ((Line = ReadLine(ProblemFile))) { if (!(Keyword = strtok(Line, Delimiters))) continue; for (i = 0; i < (int) strlen(Keyword); i++) Keyword[i] = (char) toupper(Keyword[i]); if (!strcmp(Keyword, "COMMENT")); else if (!strcmp(Keyword, "DEMAND_SECTION")) eprintf("Not implemented: %s", Keyword); else if (!strcmp(Keyword, "DEPOT_SECTION")) eprintf("Not implemented: %s", Keyword); else if (!strcmp(Keyword, "DIMENSION")) Read_DIMENSION(); else if (!strcmp(Keyword, "DISPLAY_DATA_SECTION")) Read_DISPLAY_DATA_SECTION(); else if (!strcmp(Keyword, "DISPLAY_DATA_TYPE")) Read_DISPLAY_DATA_TYPE(); else if (!strcmp(Keyword, "EDGE_DATA_FORMAT")) Read_EDGE_DATA_FORMAT(); else if (!strcmp(Keyword, "EDGE_DATA_SECTION")) Read_EDGE_DATA_SECTION(); else if (!strcmp(Keyword, "EDGE_WEIGHT_FORMAT")) Read_EDGE_WEIGHT_FORMAT(); else if (!strcmp(Keyword, "EDGE_WEIGHT_SECTION")) Read_EDGE_WEIGHT_SECTION(); else if (!strcmp(Keyword, "EDGE_WEIGHT_TYPE")) Read_EDGE_WEIGHT_TYPE(); else if (!strcmp(Keyword, "EOF")) break; else if (!strcmp(Keyword, "FIXED_EDGES_SECTION")) Read_FIXED_EDGES_SECTION(); else if (!strcmp(Keyword, "NAME")) Read_NAME(); else if (!strcmp(Keyword, "NODE_COORD_SECTION")) Read_NODE_COORD_SECTION(); else if (!strcmp(Keyword, "NODE_COORD_TYPE")) Read_NODE_COORD_TYPE(); else if (!strcmp(Keyword, "TOUR_SECTION")) Read_TOUR_SECTION(&ProblemFile); else if (!strcmp(Keyword, "TYPE")) Read_TYPE(); else eprintf("Unknown keyword: %s", Keyword); } Swaps = 0; /* Adjust parameters */ if (Seed == 0) Seed = 1; if (Precision == 0) Precision = 100; if (InitialStepSize == 0) InitialStepSize = 1; if (MaxSwaps < 0) MaxSwaps = Dimension; if (KickType > Dimension / 2) KickType = Dimension / 2; if (Runs == 0) Runs = 10; if (MaxCandidates > Dimension - 1) MaxCandidates = Dimension - 1; if (ExtraCandidates > Dimension - 1) ExtraCandidates = Dimension - 1; if (SubproblemSize >= Dimension) SubproblemSize = Dimension; else if (SubproblemSize == 0) { if (AscentCandidates > Dimension - 1) AscentCandidates = Dimension - 1; if (InitialPeriod < 0) { InitialPeriod = Dimension / 2; if (InitialPeriod < 100) InitialPeriod = 100; } if (Excess < 0) Excess = 1.0 / Dimension; if (MaxTrials == -1) MaxTrials = Dimension; MakeHeap(Dimension); } if (CostMatrix == 0 && Dimension <= MaxMatrixDimension && Distance != 0 && Distance != Distance_1 && Distance != Distance_ATSP && WeightType != GEO && WeightType != GEOM && WeightType != GEO_MEEUS && WeightType != GEOM_MEEUS) { Node *Ni, *Nj; assert(CostMatrix = (int *) calloc(Dimension * (Dimension - 1) / 2, sizeof(int))); Ni = FirstNode->Suc; do { Ni->C = &CostMatrix[(Ni->Id - 1) * (Ni->Id - 2) / 2] - 1; if (ProblemType != HPP || Ni->Id < Dimension) for (Nj = FirstNode; Nj != Ni; Nj = Nj->Suc) Ni->C[Nj->Id] = Fixed(Ni, Nj) ? 0 : Distance(Ni, Nj); else for (Nj = FirstNode; Nj != Ni; Nj = Nj->Suc) Ni->C[Nj->Id] = 0; } while ((Ni = Ni->Suc) != FirstNode); WeightType = EXPLICIT; c = 0; } if (Precision > 1 && (WeightType == EXPLICIT || ProblemType == ATSP)) { int j, n = ProblemType == ATSP ? Dimension / 2 : Dimension; for (i = 2; i <= n; i++) { Node *N = &NodeSet[i]; for (j = 1; j < i; j++) if (N->C[j] * Precision / Precision != N->C[j]) eprintf("PRECISION (= %d) is too large", Precision); } } C = WeightType == EXPLICIT ? C_EXPLICIT : C_FUNCTION; D = WeightType == EXPLICIT ? D_EXPLICIT : D_FUNCTION; if (SubsequentMoveType == 0) SubsequentMoveType = MoveType; K = MoveType >= SubsequentMoveType || !SubsequentPatching ? MoveType : SubsequentMoveType; if (PatchingC > K) PatchingC = K; if (PatchingA > 1 && PatchingA >= PatchingC) PatchingA = PatchingC > 2 ? PatchingC - 1 : 1; if (NonsequentialMoveType == -1 || NonsequentialMoveType > K + PatchingC + PatchingA - 1) NonsequentialMoveType = K + PatchingC + PatchingA - 1; if (PatchingC >= 1 && NonsequentialMoveType >= 4) { BestMove = BestSubsequentMove = BestKOptMove; if (!SubsequentPatching && SubsequentMoveType <= 5) { MoveFunction BestOptMove[] = { 0, 0, Best2OptMove, Best3OptMove, Best4OptMove, Best5OptMove }; BestSubsequentMove = BestOptMove[SubsequentMoveType]; } } else { MoveFunction BestOptMove[] = { 0, 0, Best2OptMove, Best3OptMove, Best4OptMove, Best5OptMove }; BestMove = MoveType <= 5 ? BestOptMove[MoveType] : BestKOptMove; BestSubsequentMove = SubsequentMoveType <= 5 ? BestOptMove[SubsequentMoveType] : BestKOptMove; } if (TraceLevel >= 1) { printff("done\n"); PrintParameters(); } else printff("PROBLEM_FILE = %s\n", ProblemFileName ? ProblemFileName : ""); fclose(ProblemFile); if (InitialTourFileName) ReadTour(InitialTourFileName, &InitialTourFile); if (InputTourFileName) ReadTour(InputTourFileName, &InputTourFile); if (SubproblemTourFileName && SubproblemSize > 0) ReadTour(SubproblemTourFileName, &SubproblemTourFile); if (MergeTourFiles >= 1) { free(MergeTourFile); assert(MergeTourFile = (FILE **) malloc(MergeTourFiles * sizeof(FILE *))); for (i = 0; i < MergeTourFiles; i++) ReadTour(MergeTourFileName[i], &MergeTourFile[i]); } free(LastLine); LastLine = 0; }
static void Read_TOUR_SECTION(FILE ** File) { Node *First = 0, *Last = 0, *N, *Na; int i, k; if (TraceLevel >= 1) { printff("Reading "); if (File == &InitialTourFile) printff("INITIAL_TOUR_FILE: \"%s\" ... ", InitialTourFileName); else if (File == &InputTourFile) printff("INPUT_TOUR_FILE: \"%s\" ... ", InputTourFileName); else if (File == &SubproblemTourFile) printff("SUBPROBLEM_TOUR_FILE: \"%s\" ... ", SubproblemTourFileName); else for (i = 0; i < MergeTourFiles; i++) if (File == &MergeTourFile[i]) printff("MERGE_TOUR_FILE: \"%s\" ... ", MergeTourFileName[i]); } if (!FirstNode) CreateNodes(); N = FirstNode; do N->V = 0; while ((N = N->Suc) != FirstNode); if (ProblemType == HPP) Dimension--; if (ProblemType == ATSP) Dimension /= 2; if (!fscanint(*File, &i)) i = -1; for (k = 0; k <= Dimension && i != -1; k++) { if (i <= 0 || i > Dimension) eprintf("(TOUR_SECTION) Node number out of range: %d", i); N = &NodeSet[i]; if (N->V == 1 && k != Dimension) eprintf("(TOUR_SECTION) Node number occours twice: %d", N->Id); N->V = 1; if (k == 0) First = Last = N; else { if (ProblemType == ATSP) { Na = Last + Dimension; Na->V = 1; } else Na = 0; if (File == &InitialTourFile) { if (!Na) Last->InitialSuc = N; else { Last->InitialSuc = Na; Na->InitialSuc = N; } } else if (File == &InputTourFile) { if (!Na) Last->InputSuc = N; else { Last->InputSuc = Na; Na->InputSuc = N; } } else if (File == &SubproblemTourFile) { if (!Na) (Last->SubproblemSuc = N)->SubproblemPred = Last; else { (Last->SubproblemSuc = Na)->SubproblemPred = Last; (Na->SubproblemSuc = N)->SubproblemPred = Na; } } else { for (i = 0; i < MergeTourFiles; i++) { if (File == &MergeTourFile[i]) { if (!Na) Last->MergeSuc[i] = N; else { Last->MergeSuc[i] = Na; Na->MergeSuc[i] = N; } } } } Last = N; } if (k < Dimension) fscanint(*File, &i); if (k == Dimension - 1) i = First->Id; } N = FirstNode; do if (!N->V) eprintf("(TOUR_SECTION) Node is missing: %d", N->Id); while ((N = N->Suc) != FirstNode); if (File == &SubproblemTourFile) { do { if (N->FixedTo1 && N->SubproblemPred != N->FixedTo1 && N->SubproblemSuc != N->FixedTo1) eprintf("Fixed edge (%d, %d) " "does not belong to subproblem tour", N->Id, N->FixedTo1->Id); if (N->FixedTo2 && N->SubproblemPred != N->FixedTo2 && N->SubproblemSuc != N->FixedTo2) eprintf("Fixed edge (%d, %d) " "does not belong to subproblem tour", N->Id, N->FixedTo2->Id); } while ((N = N->Suc) != FirstNode); } if (ProblemType == HPP) Dimension++; if (ProblemType == ATSP) Dimension *= 2; if (TraceLevel >= 1) printff("done\n"); }
int r_bin_mdmp_init_directory(struct r_bin_mdmp_obj *obj, PMINIDUMP_DIRECTORY dir) { size_t i, j, k; void *p, *m; switch (dir->StreamType) { case UnusedStream: break; case ThreadListStream: if (r_bin_mdmp_directory_check(obj, dir, sizeof(MINIDUMP_THREAD), "ThreadListStream")) { r_list_append(obj->threads, obj->b->buf + dir->Location.Rva); }; break; case ModuleListStream: if (r_bin_mdmp_directory_check(obj, dir, sizeof(MINIDUMP_MODULE_LIST), "ModuleListStream")) { p = obj->b->buf + dir->Location.Rva; j = ((PMINIDUMP_MODULE_LIST)p)->NumberOfModules; for (i = 0; i < j; i++) { p = (void *)(&((PMINIDUMP_MODULE_LIST)p)->Modules[i]); if (p - (void *)obj->b->buf + sizeof(MINIDUMP_MODULE) > obj->b->length) { eprintf("Warning in r_bin_mdmp_init_directory: length too short, not enough space for all MINIDUMP_MODULE\n"); break; } r_list_append(obj->modules, p); }; }; break; case MemoryListStream: break; case ExceptionStream: break; case SystemInfoStream: if (obj->system_info) { eprintf("Warning in r_bin_mdmp_init_directory: another SystemInfoStream encountered, ignored\n"); return R_FALSE; } if (r_bin_mdmp_directory_check(obj, dir, sizeof(MINIDUMP_SYSTEM_INFO), "SystemInfoStream")) { obj->system_info = (PMINIDUMP_SYSTEM_INFO)(obj->b->buf + dir->Location.Rva); }; break; case ThreadExListStream: break; case Memory64ListStream: if (r_bin_mdmp_directory_check(obj, dir, sizeof(MINIDUMP_MEMORY64_LIST), "Memory64ListStream")) { p = obj->b->buf + dir->Location.Rva; j = ((PMINIDUMP_MEMORY64_LIST)p)->NumberOfMemoryRanges; for (i = 0; i < j; i++) { p = (void *)(&((PMINIDUMP_MEMORY64_LIST)p)->MemoryRanges[i]); if (p - (void *)obj->b->buf + sizeof(MINIDUMP_MEMORY_DESCRIPTOR64) > obj->b->length) { eprintf("Warning in r_bin_mdmp_init_directory: length too short, not enough space for all MINIDUMP_MEMORY_DESCRIPTOR64\n"); break; } r_list_append(obj->memory64, p); }; }; break; case CommentStreamA: break; case CommentStreamW: break; case HandleDataStream: break; case FunctionTableStream: break; case UnloadedModuleListStream: break; case MiscInfoStream: if (dir->Location.Rva + dir->Location.DataSize > obj->b->length) { eprintf("Warning in r_bin_mdmp_init_directory: length too short, not enough space for MiscInfoStream\n"); return R_FALSE; } p = obj->b->buf + dir->Location.Rva; i = ((PMINIDUMP_MISC_INFO)p)->SizeOfInfo; if (i != dir->Location.DataSize) { eprintf("Warning in r_bin_mdmp_init_directory: MINIDUMP_MISC_INFO DataSize size mismatch\n"); return R_FALSE; } if(!(m = malloc(sizeof(MINIDUMP_MISC_INFO_N)))) { eprintf("Warning in r_bin_mdmp_init_directory: malloc failed\n"); return R_FALSE; } memset(m, 0, sizeof(MINIDUMP_MISC_INFO_N)); if (i <= sizeof(MINIDUMP_MISC_INFO_N)) { memcpy(m, p, i); } else { memcpy (m, p, sizeof(MINIDUMP_MISC_INFO_N)); eprintf ("Warning in r_bin_mdmp_init_directory: PMINIDUMP_MISC_INFO structure bigger than expected, truncated from %d\n", (int)i); } r_list_append(obj->misc_info, m); break; case MemoryInfoListStream: if (r_bin_mdmp_directory_check(obj, dir, sizeof(MINIDUMP_MEMORY_INFO_LIST), "MemoryInfoListStream")) { p = obj->b->buf + dir->Location.Rva; if ((sizeof(MINIDUMP_MEMORY_INFO_LIST) != ((PMINIDUMP_MEMORY_INFO_LIST)p)->SizeOfHeader) || (sizeof(MINIDUMP_MEMORY_INFO) != ((PMINIDUMP_MEMORY_INFO_LIST)p)->SizeOfEntry)) { eprintf("Warning in r_bin_mdmp_init_directory: MemoryInfoListStream size mismatch\n"); return R_FALSE; }; j = ((PMINIDUMP_MEMORY_INFO_LIST)p)->NumberOfEntries; for (i = 0; i < j; i++) { k = dir->Location.Rva + sizeof(MINIDUMP_MEMORY_INFO_LIST) + i * sizeof(MINIDUMP_MEMORY_INFO); if (k + sizeof(MINIDUMP_MEMORY_INFO) > obj->b->length) { eprintf("Warning in r_bin_mdmp_init_directory: length too short, not enough space for all MINIDUMP_MEMORY_INFO\n"); break; } r_list_append(obj->memory_info, obj->b->buf + k); }; }; break; case ThreadInfoListStream: if (r_bin_mdmp_directory_check(obj, dir, sizeof(MINIDUMP_THREAD_INFO_LIST), "ThreadInfoListStream")) { p = obj->b->buf + dir->Location.Rva; if ((sizeof(MINIDUMP_THREAD_INFO_LIST) != ((PMINIDUMP_THREAD_INFO_LIST)p)->SizeOfHeader) || (sizeof(MINIDUMP_THREAD_INFO) != ((PMINIDUMP_THREAD_INFO_LIST)p)->SizeOfEntry)) { eprintf("Warning in r_bin_mdmp_init_directory: ThreadInfoListStream size mismatch\n"); return R_FALSE; }; j = ((PMINIDUMP_THREAD_INFO_LIST)p)->NumberOfEntries; for (i = 0; i < j; i++) { k = dir->Location.Rva + sizeof(MINIDUMP_THREAD_INFO_LIST) + i * sizeof(MINIDUMP_THREAD_INFO); if (k + sizeof(MINIDUMP_THREAD_INFO) > obj->b->length) { eprintf("Warning in r_bin_mdmp_init_directory: length too short, not enough space for all MINIDUMP_THREAD_INFO\n"); break; } r_list_append(obj->thread_info, obj->b->buf + k); }; }; break; case HandleOperationListStream: break; case TokenStream: break; case JavaScriptDataStream: break; default : eprintf("Warning in r_bin_mdmp_init_directory: uknown stream %d\n", dir->StreamType); } return R_TRUE; }
// TODO: use esil here? R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) { RAnalBlock *bb; RAnalFunction *f; char *cstr, ret[128]; char *r0 = r_anal_value_to_string (op->dst); char *a0 = r_anal_value_to_string (op->src[0]); char *a1 = r_anal_value_to_string (op->src[1]); if (!r0) r0 = strdup ("?"); if (!a0) a0 = strdup ("?"); if (!a1) a1 = strdup ("?"); switch (op->type) { case R_ANAL_OP_TYPE_MOV: snprintf (ret, sizeof (ret), "%s = %s", r0, a0); break; case R_ANAL_OP_TYPE_CJMP: if ((bb = r_anal_bb_from_offset (anal, op->addr))) { cstr = r_anal_cond_to_string (bb->cond); snprintf (ret, sizeof (ret), "if (%s) goto 0x%"PFMT64x, cstr, op->jump); free (cstr); } else { snprintf (ret, sizeof (ret), "if (%s) goto 0x%"PFMT64x, "?", op->jump); } break; case R_ANAL_OP_TYPE_JMP: snprintf (ret, sizeof (ret), "goto 0x%"PFMT64x, op->jump); break; case R_ANAL_OP_TYPE_UJMP: case R_ANAL_OP_TYPE_RJMP: case R_ANAL_OP_TYPE_IJMP: case R_ANAL_OP_TYPE_IRJMP: snprintf (ret, sizeof (ret), "goto %s", r0); break; case R_ANAL_OP_TYPE_PUSH: case R_ANAL_OP_TYPE_UPUSH: snprintf (ret, sizeof (ret), "push %s", a0); break; case R_ANAL_OP_TYPE_POP: snprintf (ret, sizeof (ret), "pop %s", r0); break; case R_ANAL_OP_TYPE_UCALL: case R_ANAL_OP_TYPE_RCALL: case R_ANAL_OP_TYPE_ICALL: case R_ANAL_OP_TYPE_IRCALL: snprintf (ret, sizeof (ret), "%s()", r0); break; case R_ANAL_OP_TYPE_CALL: f = r_anal_get_fcn_in (anal, op->jump, R_ANAL_FCN_TYPE_NULL); if (f) { snprintf (ret, sizeof (ret), "%s()", f->name); } else { snprintf (ret, sizeof (ret), "0x%"PFMT64x"()", op->jump); } break; case R_ANAL_OP_TYPE_CCALL: f = r_anal_get_fcn_in (anal, op->jump, R_ANAL_FCN_TYPE_NULL); if ((bb = r_anal_bb_from_offset (anal, op->addr))) { cstr = r_anal_cond_to_string (bb->cond); if (f) snprintf (ret, sizeof (ret), "if (%s) %s()", cstr, f->name); else snprintf (ret, sizeof (ret), "if (%s) 0x%"PFMT64x"()", cstr, op->jump); free (cstr); } else { if (f) snprintf (ret, sizeof (ret), "if (unk) %s()", f->name); else snprintf (ret, sizeof (ret), "if (unk) 0x%"PFMT64x"()", op->jump); } break; case R_ANAL_OP_TYPE_ADD: if (!a1 || !strcmp (a0, a1)) { snprintf (ret, sizeof (ret), "%s += %s", r0, a0); } else { snprintf (ret, sizeof (ret), "%s = %s + %s", r0, a0, a1); } break; case R_ANAL_OP_TYPE_SUB: if (!a1 || !strcmp (a0, a1)) { snprintf (ret, sizeof (ret), "%s -= %s", r0, a0); } else { snprintf (ret, sizeof (ret), "%s = %s - %s", r0, a0, a1); } break; case R_ANAL_OP_TYPE_MUL: if (!a1 || !strcmp (a0, a1)) { snprintf (ret, sizeof (ret), "%s *= %s", r0, a0); } else { snprintf (ret, sizeof (ret), "%s = %s * %s", r0, a0, a1); } break; case R_ANAL_OP_TYPE_DIV: if (!a1 || !strcmp (a0, a1)) { snprintf (ret, sizeof (ret), "%s /= %s", r0, a0); } else snprintf (ret, sizeof (ret), "%s = %s / %s", r0, a0, a1); break; case R_ANAL_OP_TYPE_AND: if (!a1 || !strcmp (a0, a1)) { snprintf (ret, sizeof (ret), "%s &= %s", r0, a0); } else snprintf (ret, sizeof (ret), "%s = %s & %s", r0, a0, a1); break; case R_ANAL_OP_TYPE_OR: if (!a1 || !strcmp (a0, a1)) { snprintf (ret, sizeof (ret), "%s |= %s", r0, a0); } else snprintf (ret, sizeof (ret), "%s = %s | %s", r0, a0, a1); break; case R_ANAL_OP_TYPE_XOR: if (!a1 || !strcmp (a0, a1)) { snprintf (ret, sizeof (ret), "%s ^= %s", r0, a0); } else snprintf (ret, sizeof (ret), "%s = %s ^ %s", r0, a0, a1); break; case R_ANAL_OP_TYPE_LEA: snprintf (ret, sizeof (ret), "%s -> %s", r0, a0); break; case R_ANAL_OP_TYPE_CMP: memcpy (ret, ";", 2); break; case R_ANAL_OP_TYPE_NOP: memcpy (ret, "nop", 4); break; case R_ANAL_OP_TYPE_RET: memcpy (ret, "ret", 4); break; case R_ANAL_OP_TYPE_CRET: if ((bb = r_anal_bb_from_offset (anal, op->addr))) { cstr = r_anal_cond_to_string (bb->cond); snprintf (ret, sizeof (ret), "if (%s) ret", cstr); free (cstr); } else { strcpy (ret, "if (unk) ret"); } break; case R_ANAL_OP_TYPE_LEAVE: memcpy (ret, "leave", 6); break; case R_ANAL_OP_TYPE_MOD: if (!a1 || !strcmp (a0, a1)) { snprintf (ret, sizeof (ret), "%s %%= %s", r0, a0); } else { snprintf (ret, sizeof (ret), "%s = %s %% %s", r0, a0, a1); } break; case R_ANAL_OP_TYPE_XCHG: if (!a1 || !strcmp (a0, a1)) { snprintf (ret, sizeof (ret), "tmp = %s; %s = %s; %s = tmp", r0, r0, a0, a0); } else { snprintf (ret, sizeof (ret), "%s = %s ^ %s", r0, a0, a1); } break; case R_ANAL_OP_TYPE_ROL: case R_ANAL_OP_TYPE_ROR: case R_ANAL_OP_TYPE_SWITCH: case R_ANAL_OP_TYPE_CASE: eprintf ("Command not implemented.\n"); free (r0); free (a0); free (a1); return NULL; default: free (r0); free (a0); free (a1); return NULL; } free (r0); free (a0); free (a1); return strdup (ret); }
static void Read_EDGE_WEIGHT_TYPE() { unsigned int i; if (!(EdgeWeightType = Copy(strtok(0, Delimiters)))) eprintf("EDGE_WEIGHT_TYPE: string expected"); for (i = 0; i < strlen(EdgeWeightType); i++) EdgeWeightType[i] = (char) toupper(EdgeWeightType[i]); if (!strcmp(EdgeWeightType, "ATT")) { WeightType = ATT; Distance = Distance_ATT; c = c_ATT; CoordType = TWOD_COORDS; } else if (!strcmp(EdgeWeightType, "CEIL_2D")) { WeightType = CEIL_2D; Distance = Distance_CEIL_2D; c = c_CEIL_2D; CoordType = TWOD_COORDS; } else if (!strcmp(EdgeWeightType, "CEIL_3D")) { WeightType = CEIL_3D; Distance = Distance_CEIL_3D; c = c_CEIL_3D; CoordType = THREED_COORDS; } else if (!strcmp(EdgeWeightType, "EUC_2D")) { WeightType = EUC_2D; Distance = Distance_EUC_2D; c = c_EUC_2D; CoordType = TWOD_COORDS; } else if (!strcmp(EdgeWeightType, "EUC_3D")) { WeightType = EUC_3D; Distance = Distance_EUC_3D; c = c_EUC_3D; CoordType = THREED_COORDS; } else if (!strcmp(EdgeWeightType, "EXPLICIT")) { WeightType = EXPLICIT; Distance = Distance_EXPLICIT; } else if (!strcmp(EdgeWeightType, "MAN_2D")) { WeightType = MAN_2D; Distance = Distance_MAN_2D; CoordType = TWOD_COORDS; } else if (!strcmp(EdgeWeightType, "MAN_3D")) { WeightType = MAN_3D; Distance = Distance_MAN_3D; CoordType = THREED_COORDS; } else if (!strcmp(EdgeWeightType, "MAX_2D")) { WeightType = MAX_2D; Distance = Distance_MAX_2D; CoordType = TWOD_COORDS; } else if (!strcmp(EdgeWeightType, "MAX_3D")) { WeightType = MAX_3D; Distance = Distance_MAX_3D; CoordType = THREED_COORDS; } else if (!strcmp(EdgeWeightType, "GEO")) { WeightType = GEO; Distance = Distance_GEO; c = c_GEO; CoordType = TWOD_COORDS; } else if (!strcmp(EdgeWeightType, "GEOM")) { WeightType = GEOM; Distance = Distance_GEOM; c = c_GEOM; CoordType = TWOD_COORDS; } else if (!strcmp(EdgeWeightType, "GEO_MEEUS")) { WeightType = GEO_MEEUS; Distance = Distance_GEO_MEEUS; c = c_GEO_MEEUS; CoordType = TWOD_COORDS; } else if (!strcmp(EdgeWeightType, "GEOM_MEEUS")) { WeightType = GEOM_MEEUS; Distance = Distance_GEOM_MEEUS; c = c_GEOM_MEEUS; CoordType = TWOD_COORDS; } else if (!strcmp(EdgeWeightType, "SPECIAL")) { WeightType = SPECIAL; Distance = Distance_SPECIAL; } else if (!strcmp(EdgeWeightType, "XRAY1") || !strcmp(EdgeWeightType, "XRAY2")) eprintf("EDGE_WEIGHT_TYPE not implemented: %s", EdgeWeightType); else eprintf("Unknown EDGE_WEIGHT_TYPE: %s", EdgeWeightType); }
static void feh_load_options_for_theme(char *theme) { FILE *fp = NULL; char *home = getenv("HOME"); char *rcpath = NULL; char *oldrcpath = NULL; char *confbase = getenv("XDG_CONFIG_HOME"); char s[1024], s1[1024], s2[1024]; int cont = 0; int bspos; if (!home) eprintf("You have no HOME, cannot read themes"); oldrcpath = estrjoin("/", home, ".fehrc", NULL); if (confbase) rcpath = estrjoin("/", confbase, "feh/themes", NULL); else rcpath = estrjoin("/", home, ".config/feh/themes", NULL); fp = fopen(rcpath, "r"); free(rcpath); if (!fp && ((fp = fopen(oldrcpath, "r")) != NULL)) weprintf("The theme config file was moved from ~/.fehrc to " "~/.config/feh/themes. Run\n" " mkdir -p ~/.config/feh; mv ~/.fehrc ~/.config/feh/themes\n" "to fix this."); free(oldrcpath); if (!fp && ((fp = fopen("/etc/feh/themes", "r")) == NULL)) return; /* Oooh. We have an options file :) */ for (; fgets(s, sizeof(s), fp);) { s1[0] = '\0'; s2[0] = '\0'; if (cont) { sscanf(s, " %[^\n]\n", (char *) &s2); if (!*s2) break; D(("Got continued options %s\n", s2)); } else { sscanf(s, "%s %[^\n]\n", (char *) &s1, (char *) &s2); if (!(*s1) || (!*s2) || (*s1 == '\n') || (*s1 == '#')) { cont = 0; continue; } D(("Got theme/options pair %s/%s\n", s1, s2)); } if (!strcmp(s1, theme) || cont) { bspos = strlen(s2)-1; if (s2[bspos] == '\\') { D(("Continued line\n")); s2[bspos] = '\0'; cont = 1; /* A trailing whitespace confuses the option parser */ if (bspos && (s2[bspos-1] == ' ')) s2[bspos-1] = '\0'; } else cont = 0; D(("A match. Using options %s\n", s2)); feh_parse_options_from_string(s2); if (!cont) break; } } fclose(fp); return; }
static void print_escaped_string (const char *str, int len) { eprintf ("\""); const char *end = str + len; while (str < end) { int n = valid_utf8_char (str); if (n < 0) { eprintf ("\\x%02x", (int)(unsigned char)*str); str ++; } else if (n >= 2) { int i; for (i = 0; i < n; i++) { eprintf ("%c", *(str ++)); } } else if (((unsigned char)*str) >= ' ' && *str != '"' && *str != '\\') { eprintf ("%c", *str); str ++; } else { switch (*str) { case '\n': eprintf("\\n"); break; case '\r': eprintf("\\r"); break; case '\t': eprintf("\\t"); break; case '\b': eprintf("\\b"); break; case '\a': eprintf("\\a"); break; case '\\': eprintf ("\\\\"); break; case '"': eprintf ("\\\""); break; default: eprintf ("\\x%02x", (int)(unsigned char)*str); break; } str ++; } } eprintf ("\""); }
void printvect(string name, vector vec) { eprintf("[%s: %12s %10.5f %10.5f %10.5f]\n", getargv0(), name, vec[0], vec[1], vec[2]); }
static void print_offset (void) { int i; for (i = 0; i < multiline_offset; i++) { eprintf (" "); } }
void CommandData::ProcessSwitch(const wchar *Switch) { switch(toupperw(Switch[0])) { case '@': ListMode=Switch[1]=='+' ? RCLM_ACCEPT_LISTS:RCLM_REJECT_LISTS; break; case 'A': switch(toupperw(Switch[1])) { case 'C': ClearArc=true; break; case 'D': AppendArcNameToPath=true; break; #ifndef SFX_MODULE case 'G': if (Switch[2]=='-' && Switch[3]==0) GenerateArcName=0; else { GenerateArcName=true; wcsncpyz(GenerateMask,Switch+2,ASIZE(GenerateMask)); } break; #endif case 'I': IgnoreGeneralAttr=true; break; case 'N': // Reserved for archive name. break; case 'O': AddArcOnly=true; break; case 'P': wcscpy(ArcPath,Switch+2); break; case 'S': SyncFiles=true; break; default: BadSwitch(Switch); break; } break; case 'C': if (Switch[2]==0) switch(toupperw(Switch[1])) { case '-': DisableComment=true; break; case 'U': ConvertNames=NAMES_UPPERCASE; break; case 'L': ConvertNames=NAMES_LOWERCASE; break; } break; case 'D': if (Switch[2]==0) switch(toupperw(Switch[1])) { case 'S': DisableSortSolid=true; break; case 'H': OpenShared=true; break; case 'F': DeleteFiles=true; break; } break; case 'E': switch(toupperw(Switch[1])) { case 'P': switch(Switch[2]) { case 0: ExclPath=EXCL_SKIPWHOLEPATH; break; case '1': ExclPath=EXCL_BASEPATH; break; case '2': ExclPath=EXCL_SAVEFULLPATH; break; case '3': ExclPath=EXCL_ABSPATH; break; } break; default: if (Switch[1]=='+') { InclFileAttr|=GetExclAttr(Switch+2); InclAttrSet=true; } else ExclFileAttr|=GetExclAttr(Switch+1); break; } break; case 'F': if (Switch[1]==0) FreshFiles=true; else BadSwitch(Switch); break; case 'H': switch (toupperw(Switch[1])) { case 'P': EncryptHeaders=true; if (Switch[2]!=0) { Password.Set(Switch+2); cleandata((void *)Switch,wcslen(Switch)*sizeof(Switch[0])); } else if (!Password.IsSet()) { uiGetPassword(UIPASSWORD_GLOBAL,NULL,&Password); eprintf(L"\n"); } break; default : BadSwitch(Switch); break; } break; case 'I': if (wcsnicomp(Switch+1,L"LOG",3)==0) { wcsncpyz(LogName,Switch[4]!=0 ? Switch+4:DefLogName,ASIZE(LogName)); break; } if (wcsicomp(Switch+1,L"SND")==0) { Sound=true; break; } if (wcsicomp(Switch+1,L"ERR")==0) { MsgStream=MSG_STDERR; break; } if (wcsnicomp(Switch+1,L"EML",3)==0) { wcsncpyz(EmailTo,Switch[4]!=0 ? Switch+4:L"@",ASIZE(EmailTo)); break; } if (wcsicomp(Switch+1,L"NUL")==0) { MsgStream=MSG_NULL; break; } if (toupperw(Switch[1])=='D') { for (uint I=2;Switch[I]!=0;I++) switch(toupperw(Switch[I])) { case 'Q': MsgStream=MSG_ERRONLY; break; case 'C': DisableCopyright=true; break; case 'D': DisableDone=true; break; case 'P': DisablePercentage=true; break; } break; } if (wcsicomp(Switch+1,L"OFF")==0) { Shutdown=true; break; } break; case 'K': switch(toupperw(Switch[1])) { case 'B': KeepBroken=true; break; case 0: Lock=true; break; } break; case 'M': switch(toupperw(Switch[1])) { case 'C': { const wchar *Str=Switch+2; if (*Str=='-') for (uint I=0;I<ASIZE(FilterModes);I++) FilterModes[I].State=FILTER_DISABLE; else while (*Str!=0) { int Param1=0,Param2=0; FilterState State=FILTER_AUTO; FilterType Type=FILTER_NONE; if (IsDigit(*Str)) { Param1=atoiw(Str); while (IsDigit(*Str)) Str++; } if (*Str==':' && IsDigit(Str[1])) { Param2=atoiw(++Str); while (IsDigit(*Str)) Str++; } switch(toupperw(*(Str++))) { case 'T': Type=FILTER_PPM; break; case 'E': Type=FILTER_E8; break; case 'D': Type=FILTER_DELTA; break; case 'A': Type=FILTER_AUDIO; break; case 'C': Type=FILTER_RGB; break; case 'I': Type=FILTER_ITANIUM; break; case 'R': Type=FILTER_ARM; break; } if (*Str=='+' || *Str=='-') State=*(Str++)=='+' ? FILTER_FORCE:FILTER_DISABLE; FilterModes[Type].State=State; FilterModes[Type].Param1=Param1; FilterModes[Type].Param2=Param2; } } break; case 'M': break; case 'D': break; case 'S': { wchar StoreNames[1024]; wcsncpyz(StoreNames,(Switch[2]==0 ? DefaultStoreList:Switch+2),ASIZE(StoreNames)); wchar *Names=StoreNames; while (*Names!=0) { wchar *End=wcschr(Names,';'); if (End!=NULL) *End=0; if (*Names=='.') Names++; wchar Mask[NM]; if (wcspbrk(Names,L"*?.")==NULL) swprintf(Mask,ASIZE(Mask),L"*.%ls",Names); else wcsncpyz(Mask,Names,ASIZE(Mask)); StoreArgs.AddString(Mask); if (End==NULL) break; Names=End+1; } } break; #ifdef RAR_SMP case 'T': Threads=atoiw(Switch+2); if (Threads>MaxPoolThreads || Threads<1) BadSwitch(Switch); else { } break; #endif default: Method=Switch[1]-'0'; if (Method>5 || Method<0) BadSwitch(Switch); break; } break; case 'N': case 'X': if (Switch[1]!=0) { StringList *Args=toupperw(Switch[0])=='N' ? &InclArgs:&ExclArgs; if (Switch[1]=='@' && !IsWildcard(Switch)) { RAR_CHARSET Charset=FilelistCharset; #if defined(_WIN_ALL) && !defined(GUI) // for compatibility reasons we use OEM encoding // in Win32 console version by default // if (Charset==RCH_DEFAULT) // Charset=RCH_OEM; #endif ReadTextFile(Switch+2,Args,false,true,Charset,true,true,true); } else Args->AddString(Switch+1); } break; case 'O': switch(toupperw(Switch[1])) { case '+': Overwrite=OVERWRITE_ALL; break; case '-': Overwrite=OVERWRITE_NONE; break; case 0: Overwrite=OVERWRITE_FORCE_ASK; break; #ifdef _WIN_ALL case 'C': SetCompressedAttr=true; break; #endif case 'H': SaveHardLinks=true; break; #ifdef SAVE_LINKS case 'L': SaveSymLinks=true; if (toupperw(Switch[2])=='A') AbsoluteLinks=true; break; #endif case 'R': Overwrite=OVERWRITE_AUTORENAME; break; #ifdef _WIN_ALL case 'S': SaveStreams=true; break; #endif case 'W': ProcessOwners=true; break; default : BadSwitch(Switch); break; } break; case 'P': if (Switch[1]==0) { uiGetPassword(UIPASSWORD_GLOBAL,NULL,&Password); eprintf(L"\n"); } else { Password.Set(Switch+1); cleandata((void *)Switch,wcslen(Switch)*sizeof(Switch[0])); } break; #ifndef SFX_MODULE case 'Q': if (toupperw(Switch[1])=='O') switch(toupperw(Switch[2])) { case 0: QOpenMode=QOPEN_AUTO; break; case '-': QOpenMode=QOPEN_NONE; break; case '+': QOpenMode=QOPEN_ALWAYS; break; default: BadSwitch(Switch); break; } else BadSwitch(Switch); break; #endif case 'R': switch(toupperw(Switch[1])) { case 0: Recurse=RECURSE_ALWAYS; break; case '-': Recurse=RECURSE_DISABLE; break; case '0': Recurse=RECURSE_WILDCARDS; break; case 'I': { Priority=atoiw(Switch+2); if (Priority<0 || Priority>15) BadSwitch(Switch); const wchar *ChPtr=wcschr(Switch+2,':'); if (ChPtr!=NULL) { SleepTime=atoiw(ChPtr+1); if (SleepTime>1000) BadSwitch(Switch); InitSystemOptions(SleepTime); } SetPriority(Priority); } break; } break; case 'S': if (IsDigit(Switch[1])) { Solid|=SOLID_COUNT; SolidCount=atoiw(&Switch[1]); } else switch(toupperw(Switch[1])) { case 0: Solid|=SOLID_NORMAL; break; case '-': Solid=SOLID_NONE; break; case 'E': Solid|=SOLID_FILEEXT; break; case 'V': Solid|=Switch[2]=='-' ? SOLID_VOLUME_DEPENDENT:SOLID_VOLUME_INDEPENDENT; break; case 'D': Solid|=SOLID_VOLUME_DEPENDENT; break; case 'L': if (IsDigit(Switch[2])) FileSizeLess=atoilw(Switch+2); break; case 'M': if (IsDigit(Switch[2])) FileSizeMore=atoilw(Switch+2); break; case 'C': { bool AlreadyBad=false; // Avoid reporting "bad switch" several times. RAR_CHARSET rch=RCH_DEFAULT; switch(toupperw(Switch[2])) { case 'A': rch=RCH_ANSI; break; case 'O': rch=RCH_OEM; break; case 'U': rch=RCH_UNICODE; break; default : BadSwitch(Switch); AlreadyBad=true; break; }; if (!AlreadyBad) { if (Switch[3]==0) CommentCharset=FilelistCharset=ErrlogCharset=rch; else for (uint I=3;Switch[I]!=0 && !AlreadyBad;I++) switch(toupperw(Switch[I])) { case 'C': CommentCharset=rch; break; case 'L': FilelistCharset=rch; break; default: BadSwitch(Switch); AlreadyBad=true; break; } } } break; } break; case 'T': switch(toupperw(Switch[1])) { case 'K': ArcTime=ARCTIME_KEEP; break; case 'L': ArcTime=ARCTIME_LATEST; break; case 'O': FileTimeBefore.SetAgeText(Switch+2); break; case 'N': FileTimeAfter.SetAgeText(Switch+2); break; case 'B': FileTimeBefore.SetIsoText(Switch+2); break; case 'A': FileTimeAfter.SetIsoText(Switch+2); break; case 'S': { EXTTIME_MODE Mode=EXTTIME_HIGH3; bool CommonMode=Switch[2]>='0' && Switch[2]<='4'; if (CommonMode) Mode=(EXTTIME_MODE)(Switch[2]-'0'); if (Switch[2]=='-') Mode=EXTTIME_NONE; if (CommonMode || Switch[2]=='-' || Switch[2]=='+' || Switch[2]==0) xmtime=xctime=xatime=Mode; else { if (Switch[3]>='0' && Switch[3]<='4') Mode=(EXTTIME_MODE)(Switch[3]-'0'); if (Switch[3]=='-') Mode=EXTTIME_NONE; switch(toupperw(Switch[2])) { case 'M': xmtime=Mode; break; case 'C': xctime=Mode; break; case 'A': xatime=Mode; break; } } } break; case '-': Test=false; break; case 0: Test=true; break; default: BadSwitch(Switch); break; } break; case 'U': if (Switch[1]==0) UpdateFiles=true; else BadSwitch(Switch); break; case 'V': switch(toupperw(Switch[1])) { case 'P': VolumePause=true; break; case 'E': if (toupperw(Switch[2])=='R') VersionControl=atoiw(Switch+3)+1; break; case '-': VolSize=0; break; default: VolSize=VOLSIZE_AUTO; // UnRAR -v switch for list command. break; } break; case 'W': wcsncpyz(TempPath,Switch+1,ASIZE(TempPath)); AddEndSlash(TempPath,ASIZE(TempPath)); break; case 'Y': AllYes=true; break; case 'Z': if (Switch[1]==0) { #ifndef GUI // stdin is not supported by WinRAR. // If comment file is not specified, we read data from stdin. wcscpy(CommentFile,L"stdin"); #endif } else wcsncpyz(CommentFile,Switch+1,ASIZE(CommentFile)); break; #ifndef GUI case '?' : OutHelp(RARX_SUCCESS); break; #endif default : BadSwitch(Switch); break; } }
R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbin) { int isdebug = r_config_get_i (core->config, "cfg.debug"); char *path; ut64 laddr = r_config_get_i (core->config, "bin.laddr"); RCoreFile *file = NULL; RCoreFile *ofile = core->file; RBinFile *bf = ofile ? r_bin_file_find_by_fd (core->bin, ofile->fd) : NULL; RIODesc *odesc = (core->io && ofile) ? r_io_desc_get (core->io, ofile->fd) : NULL; char *ofilepath = NULL, *obinfilepath = (bf && bf->file)? strdup (bf->file): NULL; int ret = false; ut64 origoff = core->offset; if (odesc) { if (odesc->referer) { ofilepath = odesc->referer; } else if (odesc->uri) { ofilepath = odesc->uri; } } if (r_sandbox_enable (0)) { eprintf ("Cannot reopen in sandbox\n"); free (obinfilepath); return false; } if (!core->file) { eprintf ("No file opened to reopen\n"); free (ofilepath); free (obinfilepath); return false; } int newpid = odesc? odesc->fd: -1; if (isdebug) { r_debug_kill (core->dbg, core->dbg->pid, core->dbg->tid, 9); // KILL perm = 7; } else { if (!perm) { perm = 4; //R_PERM_R; } } if (!ofilepath) { eprintf ("Unknown file path"); free (obinfilepath); return false; } // HACK: move last mapped address to higher place // XXX - why does this hack work? // when the new memory maps are created. path = strdup (ofilepath); free (obinfilepath); obinfilepath = strdup (ofilepath); // r_str_trim (path); file = r_core_file_open (core, path, perm, laddr); if (file) { bool had_rbin_info = false; if (ofile) { if (r_bin_file_delete (core->bin, ofile->fd)) { had_rbin_info = true; } } r_core_file_close (core, ofile); r_core_file_set_by_file (core, file); ofile = NULL; odesc = NULL; // core->file = file; eprintf ("File %s reopened in %s mode\n", path, (perm & R_PERM_W)? "read-write": "read-only"); if (loadbin && (loadbin == 2 || had_rbin_info)) { ut64 baddr = r_config_get_i (core->config, "bin.baddr"); ret = r_core_bin_load (core, obinfilepath, baddr); r_core_bin_update_arch_bits (core); if (!ret) { eprintf ("Error: Failed to reload rbin for: %s", path); } } if (core->bin->cur && core->io && r_io_desc_get (core->io, file->fd) && !loadbin) { //force here NULL because is causing uaf look this better in future XXX @alvarofe core->bin->cur = NULL; } // close old file } else if (ofile) { eprintf ("r_core_file_reopen: Cannot reopen file: %s with perms 0x%x," " attempting to open read-only.\n", path, perm); // lower it down back //ofile = r_core_file_open (core, path, R_PERM_R, addr); r_core_file_set_by_file (core, ofile); } else { eprintf ("Cannot reopen\n"); } if (isdebug) { int newtid = newpid; // XXX - select the right backend if (core->file) { newpid = r_io_fd_get_pid (core->io, core->file->fd); newtid = r_io_fd_get_tid (core->io, core->file->fd); #if __linux__ core->dbg->main_pid = newpid; newtid = newpid; #endif #pragma message ("fix debugger-concept in core") #if __WINDOWS__ r_debug_select (core->dbg, newpid, newtid); core->dbg->reason.type = R_DEBUG_REASON_NONE; #endif } //reopen and attach r_core_setup_debugger (core, "native", true); r_debug_select (core->dbg, newpid, newtid); } if (core->file) { r_io_use_fd (core->io, core->file->fd); core->switch_file_view = 1; r_core_block_read (core); #if 0 else {
/* hack from print */ R_API int r_print_format_length (const char *fmt) { int nargs, i, j, idx, times, endian; char *args, *bracket, tmp, last = 0; const char *arg = fmt; const char *argend = arg+strlen (fmt); char namefmt[8]; int viewflags = 0; nargs = endian = i = j = 0; while (*arg && iswhitechar (*arg)) arg++; /* get times */ times = atoi (arg); if (times > 0) while ((*arg>='0'&&*arg<='9')) arg++; bracket = strchr (arg,'{'); if (bracket) { char *end = strchr (arg,'}'); if (end == NULL) { eprintf ("No end bracket. Try pm {ecx}b @ esi\n"); return 0; } *end='\0'; times = r_num_math (NULL, bracket+1); arg = end + 1; } if (*arg=='\0') return 0; /* get args */ args = strchr (arg, ' '); if (args) { int l=0, maxl = 0; argend = args; args = strdup (args+1); nargs = r_str_word_set0 (args+1); if (nargs == 0) R_FREE (args); for (i=0; i<nargs; i++) { int len = strlen (r_str_word_get0 (args+1, i)); if (len>maxl) maxl = len; } l++; snprintf (namefmt, sizeof (namefmt), "%%%ds : ", maxl); } /* go format */ i = 0; if (!times) times = 1; for (; times; times--) { // repeat N times const char * orig = arg; idx = 0; arg = orig; for (idx=0; arg<argend && *arg; idx++, arg++) { tmp = *arg; feed_me_again: if (tmp == 0 && last != '*') break; /* skip chars */ switch (tmp) { case '*': if (i<=0) break; tmp = last; arg--; idx--; goto feed_me_again; case '+': idx--; viewflags = !viewflags; continue; case 'e': // tmp swap endian idx--; endian ^= 1; continue; case '.': // skip char i++; idx--; continue; case 'p': tmp = (sizeof (void*)==8)? 'q': 'x'; break; case '?': // help idx--; return 0; } switch (tmp) { case 'e': i += 8; break; case 'q': i += 8; break; case 'b': i++; break; case 'c': i++; break; case 'B': i += 4; break; case 'i': i += 4; break; case 'd': i += 4; break; case 'x': i += 4; break; case 'w': case '1': i+=2; break; case 'z': // XXX unsupported case 'Z': // zero terminated wide string break; case 's': i += 4; break; // S for 8? case 'S': i += 8; break; // S for 8? default: /* ignore unknown chars */ break; } last = tmp; } arg = orig; idx = 0; } // free((void *)&args); return i; }
static int modify_trace_bit(RDebug *dbg, xnu_thread *th, int enable) { R_DEBUG_REG_T *state; kern_return_t kr; int ret; ret = xnu_thread_get_drx (dbg, th); if (ret == R_FALSE) { eprintf ("error to get drx registers modificy_trace_bit arm\n"); return R_FALSE; } state = (R_DEBUG_REG_T)th->drx; if (state->flavor == ARM_DEBUG_STATE64) { state->uds.ds64.__mdscr_el1 = (state->uds64.__mdscr_el1 \ & SS_ENABLE) & (enable ? SS_ENABLE : 0); } else if (state->flavor == ARM_DEBUG_STATE32) { R_REG_T *regs; ret = xnu_thread_get_gpr (dbg, th); if (ret == R_FALSE) { eprintf ("error to get gpr register modificy_trace_bit arm\n"); return R_FALSE; } regs = (R_REG_T)th->gpr; if (enable) { int r, i = 0; RIOBind *bio = &dbg->io; (R_DEBUG_REG_T)th->oldstate = state; //set a breakpoint that will stop when the PC doesn't //match the current one //set the current PC as the breakpoint address state->uds.ds32.__bvr[i] = regs->ts_32.__pc; state->uds.ds32.__bcr[i] = BCR_M_IMVA_MISMATCH | //stop on address mismatch S_USER | //stop only in user mode BCR_ENABLE; // enable this breakpoint if (regs->ts_32.__cpsr & 0x20) { ut16 op; // Thumb breakpoint if (regs->ts_32.__pc & 2) { state->uds.ds32.__bcr[i] |= BAS_IMVA_2_3; } else { state->uds.ds32.__bcr[i] |= BAS_IMVA_0_1; } if (bio->read_at (bio->io, regs->ts_32.__pc, (void *)&op, 2) < 1) { eprintf ("Failed to read opcode modify_trace_bit\n"); return false; } if (is_thumb_32 (op)) { eprintf ("Thumb32 chain stepping not supported yet\n"); return false; } else { // Extend the number of bits to ignore for the mismatch state->uds.ds32.__bcr[i] |= BAS_IMVA_ALL; } } else { // ARM breakpoint state->uds.ds32.__bcr[i] |= BAS_IMVA_ALL; // Stop when any address bits change } //disable bits for (i = i + 1; i < 16; i++) { //Disable all others state->uds.ds32.__bcr[i] = 0; state->uds.ds32.__bvr[i] = 0; } } else { state->uds.ds32 = ((R_DEBUG_REG_T)th->oldstate)->uds.ds32; //we set the old state } } else { eprintf ("Bad flavor modificy_trace_bit arm\n"); return false; } //set state th->count = state->dsh.count; memcpy (th->state, state->uds, th->count); if (!xnu_thread_set_drx (dbg, th)) { eprintf ("error to set drx modificy_trace_bit arm\n"); return false; } return true; #elif __POWERPC__ // no need to do this here return false; #else #error "unknown architecture" #endif }
static ut64 num_callback(RNum *userptr, const char *str, int *ok) { RCore *core = (RCore *)userptr; // XXX ? RFlagItem *flag; RAnalOp op; ut64 ret = 0; *ok = 0; if (str[0]=='[') { int refsz = (core->assembler->bits & R_SYS_BITS_64)? 8: 4; const char *p = strchr (str+5, ':'); ut64 n; // TODO: honor endian if (p) { refsz = atoi (str+1); str = p; } // push state { const char *q = r_num_calc_index (core->num, NULL); n = r_num_math (core->num, str+1); r_num_calc_index (core->num, q); } // pop state switch (refsz) { case 8: { ut64 num = 0; r_io_read_at (core->io, n, (ut8*)&num, sizeof (num)); return num; } case 4: { ut32 num = 0; r_io_read_at (core->io, n, (ut8*)&num, sizeof (num)); return num; } case 2: { ut16 num = 0; r_io_read_at (core->io, n, (ut8*)&num, sizeof (num)); return num; } case 1: { ut8 num = 0; r_io_read_at (core->io, n, (ut8*)&num, sizeof (num)); return num; } default: eprintf ("Invalid reference size: %d\n", refsz); break; } } else if (str[0]=='$') { *ok = 1; // TODO: group analop-dependant vars after a char, so i can filter r_anal_op (core->anal, &op, core->offset, core->block, core->blocksize); switch (str[1]) { case '.': // can use pc, sp, a0, a1, ... return r_debug_reg_get (core->dbg, str+2); case '{': { char *ptr, *bptr = strdup (str+2); ptr = strchr (bptr, '}'); if (ptr != NULL) { ut64 ret; ptr[0]='\0'; ret = r_config_get_i (core->config, bptr); free (bptr); return ret; } } return 0; case 'e': return op.eob; case 'j': return op.jump; case 'f': return op.fail; case 'r': return op.ref; case 'l': return op.length; case 'b': return core->blocksize; case 's': return core->file->size; case 'w': { int bits = r_config_get_i (core->config, "asm.bits"); return bits/8; } break; case 'S': { RIOSection *s = r_io_section_get (core->io, r_io_section_vaddr_to_offset (core->io, core->offset)); return s? (str[2]=='S'?s->size: s->offset): 0; } case '?': return core->num->value; case '$': return core->offset; case 'o': return core->io->off; case 'C': return getref (core, atoi (str+2), 'r', R_ANAL_REF_TYPE_CALL); case 'J': return getref (core, atoi (str+2), 'r', R_ANAL_REF_TYPE_CODE); case 'D': return getref (core, atoi (str+2), 'r', R_ANAL_REF_TYPE_DATA); case 'X': return getref (core, atoi (str+2), 'x', R_ANAL_REF_TYPE_CALL); case 'I': { RAnalFunction *fcn = r_anal_fcn_find (core->anal, core->offset, 0); if (fcn) return fcn->ninstr; return 0; } case 'F': { RAnalFunction *fcn = r_anal_fcn_find (core->anal, core->offset, 0); if (fcn) return fcn->size; return 0; } } } else if (*str>'A') { if ((flag = r_flag_get (core->flags, str))) { ret = flag->offset; *ok = R_TRUE; } else *ok = ret = 0; } return ret; }
bool FileCreate(RAROptions *Cmd,File *NewFile,char *Name,wchar *NameW, OVERWRITE_MODE Mode,bool *UserReject,Int64 FileSize, uint FileTime) { if (UserReject!=NULL) *UserReject=false; while (FileExist(Name,NameW)) { if (Mode==OVERWRITE_NONE) { if (UserReject!=NULL) *UserReject=true; return(false); } #ifdef SILENT Mode=OVERWRITE_ALL; #endif if (Cmd->AllYes || Mode==OVERWRITE_ALL) break; if (Mode==OVERWRITE_ASK) { eprintf(St(MFileExists),Name); int Choice=Ask(St(MYesNoAllRenQ)); if (Choice==1) break; if (Choice==2) { if (UserReject!=NULL) *UserReject=true; return(false); } if (Choice==3) { Cmd->Overwrite=OVERWRITE_ALL; break; } if (Choice==4) { if (UserReject!=NULL) *UserReject=true; Cmd->Overwrite=OVERWRITE_NONE; return(false); } if (Choice==5) { mprintf(St(MAskNewName)); char NewName[NM]; #ifdef _WIN_32 File SrcFile; SrcFile.SetHandleType(FILE_HANDLESTD); int Size=SrcFile.Read(NewName,NM); NewName[Size]=0; OemToChar(NewName,NewName); #else fgets(NewName,sizeof(NewName),stdin); #endif RemoveLF(NewName); if (PointToName(NewName)==NewName) strcpy(PointToName(Name),NewName); else strcpy(Name,NewName); if (NameW!=NULL) *NameW=0; continue; } if (Choice==6) ErrHandler.Exit(USER_BREAK); } } if (NewFile!=NULL && NewFile->Create(Name,NameW)) return(true); PrepareToDelete(Name,NameW); CreatePath(Name,NameW,true); return(NewFile!=NULL ? NewFile->Create(Name,NameW):DelFile(Name,NameW)); }
static int bin_strings (RCore *r, int mode, ut64 baddr, int va) { char *q, str[R_FLAG_NAME_SIZE]; RBinSection *section; int hasstr, minstr, maxstr, rawstr; RBinString *string; RListIter *iter; RList *list; RBin *bin = r->bin; RBinFile * binfile = r_core_bin_cur (r); RBinPlugin *plugin = r_bin_file_cur_plugin (binfile); if (!binfile) return R_FALSE; minstr = r_config_get_i (r->config, "bin.minstr"); maxstr = r_config_get_i (r->config, "bin.maxstr"); rawstr = r_config_get_i (r->config, "bin.rawstr"); binfile->rawstr = rawstr; if (!(hasstr = r_config_get_i (r->config, "bin.strings"))) return 0; if (!plugin) return 0; if (plugin->info && plugin->name) { if (!strcmp (plugin->name, "any")) { if (!rawstr) { #if 0 eprintf ("NOTE: Use '-e bin.rawstr=true' or 'r2 -zz' or '.!rabin2 -zz $FILE'" " to find strings on unknown file types\n"); #endif return R_FALSE; } } } #if 0 if (bin->minstrlen == 0) bin->minstrlen = minstr; else plugin->minstrlen? plugin->minstrlen: 4; #endif bin->minstrlen = minstr; #if 0 if (bin->minstrlen <= 0) bin->minstrlen = R_MIN (minstr, 4); #endif minstr = bin->minstrlen; if ((list = r_bin_get_strings (bin)) == NULL) return R_FALSE; if ((mode & R_CORE_BIN_JSON)) { r_cons_printf ("["); r_list_foreach (list, iter, string) { ut64 vaddr = r_bin_get_vaddr (bin, baddr, string->vaddr, string->paddr); ut64 paddr = string->paddr; if (maxstr && string->length>maxstr) continue; q = r_base64_encode_dyn (string->string, 0); if (string->length>minstr) { r_cons_printf ("%s{\"vaddr\":%"PFMT64d ",\"paddr\":%"PFMT64d ",\"length\":%d,\"size\":%d," "\"type\":\"%s\",\"string\":\"%s\"}", iter->p? ",": "", vaddr, paddr, string->length, string->size, string->type=='w'?"wide":"ascii", q); } free (q); }
// TODO: return RAnalException * R_API int r_anal_op_execute(RAnal *anal, RAnalOp *op) { while (op) { if (op->delay > 0) { anal->queued = r_anal_op_copy (op); return false; } switch (op->type) { case R_ANAL_OP_TYPE_JMP: case R_ANAL_OP_TYPE_UJMP: case R_ANAL_OP_TYPE_RJMP: case R_ANAL_OP_TYPE_IJMP: case R_ANAL_OP_TYPE_IRJMP: case R_ANAL_OP_TYPE_CALL: break; case R_ANAL_OP_TYPE_ADD: // dst = src[0] + src[1] + src[2] r_anal_value_set_ut64 (anal, op->dst, r_anal_value_to_ut64 (anal, op->src[0]) + r_anal_value_to_ut64 (anal, op->src[1]) + r_anal_value_to_ut64 (anal, op->src[2])); break; case R_ANAL_OP_TYPE_SUB: // dst = src[0] + src[1] + src[2] r_anal_value_set_ut64 (anal, op->dst, r_anal_value_to_ut64 (anal, op->src[0]) - r_anal_value_to_ut64 (anal, op->src[1]) - r_anal_value_to_ut64 (anal, op->src[2])); break; case R_ANAL_OP_TYPE_DIV: { ut64 div = r_anal_value_to_ut64 (anal, op->src[1]); if (div == 0) { eprintf ("r_anal_op_execute: division by zero\n"); eprintf ("TODO: throw RAnalException\n"); } else r_anal_value_set_ut64 (anal, op->dst, r_anal_value_to_ut64 (anal, op->src[0])/div); } break; case R_ANAL_OP_TYPE_MUL: r_anal_value_set_ut64 (anal, op->dst, r_anal_value_to_ut64 (anal, op->src[0])* r_anal_value_to_ut64 (anal, op->src[1])); break; case R_ANAL_OP_TYPE_MOV: // dst = src[0] r_anal_value_set_ut64 (anal, op->dst, r_anal_value_to_ut64 (anal, op->src[0])); break; case R_ANAL_OP_TYPE_NOP: // do nothing break; } op = op->next; } if (anal->queued) { anal->queued->delay--; if (anal->queued->delay == 0) { r_anal_op_execute (anal, anal->queued); r_anal_op_free (anal->queued); anal->queued = NULL; } } return true; }
static int cb(RDiff *d, void *user, RDiffOp *op) { int i; //, diffmode = (int)(size_t)user; if (showcount) { count++; return 1; } switch (diffmode) { case 'r': if (disasm) { eprintf ("r2cmds (-r) + disasm (-D) not yet implemented\n"); } if (op->a_len == op->b_len) { printf ("wx "); for (i=0; i<op->b_len; i++) printf ("%02x", op->b_buf[i]); printf (" @ 0x%08"PFMT64x"\n", op->b_off); } else { if ((op->a_len)>0) printf ("r-%d @ 0x%08"PFMT64x"\n", op->a_len, op->a_off+delta); if (op->b_len> 0) { printf ("r+%d @ 0x%08"PFMT64x"\n", op->b_len, op->b_off+delta); printf ("wx "); for (i=0; i<op->b_len; i++) printf ("%02x", op->b_buf[i]); printf (" @ 0x%08"PFMT64x"\n", op->b_off+delta); } delta += (op->b_off - op->a_off); } return 1; case 'j': if (disasm) { eprintf ("JSON (-j) + disasm (-D) not yet implemented\n"); } if (json_started) printf(",\n"); json_started = 1; printf ("{\"offset\":%"PFMT64d",", op->a_off); printf("\"from\":\""); for (i = 0;i<op->a_len;i++) printf ("%02x", op->a_buf[i]); printf ("\", \"to\":\""); for (i=0; i<op->b_len; i++) printf ("%02x", op->b_buf[i]); printf ("\"}"); //,\n"); return 1; case 0: default: if (disasm) { printf ("--- 0x%08"PFMT64x"\n", op->a_off); if (!core) { core = opencore (file); if (arch) { r_config_set (core->config, "asm.arch", arch); } if (bits) { r_config_set_i (core->config, "asm.bits", bits); } } if (core) { RAsmCode *ac = r_asm_mdisassemble (core->assembler, op->a_buf, op->a_len); printf ("%s\n", ac->buf_asm); //r_asm_code_free (ac); } } else { printf ("0x%08"PFMT64x" ", op->a_off); for (i = 0; i < op->a_len; i++) printf ("%02x", op->a_buf[i]); } if (disasm) { printf ("+++ 0x%08"PFMT64x"\n", op->b_off); if (!core) { core = opencore (NULL); } if (core) { RAsmCode *ac = r_asm_mdisassemble (core->assembler, op->b_buf, op->b_len); printf ("%s\n", ac->buf_asm); //r_asm_code_free (ac); } } else { printf (" => "); for (i=0; i < op->b_len; i++) printf ("%02x", op->b_buf[i]); printf (" 0x%08"PFMT64x"\n", op->b_off); } return 1; } }
static inline void migrate_establish() { char buffer[MAX_PACKET_SIZE]; struct pollfd fd; int count, rc; char *p, *q; add_poll(&fd, manager_socket); rc = poll(&fd, 1, -1); DIE(-1 == rc, "poll"); count = recv_msg(manager_socket, &manager_addr, buffer); copy_packet(&useful_invite, buffer, count); eprintf("%s\n\n", useful_invite.buffer); rc = poll(&fd, 1, -1); DIE(-1 == rc, "poll"); count = recv_msg(manager_socket, &manager_addr, buffer); copy_packet(&useful_ack, buffer, count); eprintf("%s\n\n", useful_ack.buffer); rc = poll(&fd, 1, -1); DIE(-1 == rc, "poll"); count = recv_msg(manager_socket, &manager_addr, buffer); copy_packet(&useful_op_ok, buffer, count); eprintf("%s\n\n", buffer); get_data(useful_ack.buffer, &ack_data); printf("\nACK data\n"); printf("branch: %s\n", ack_data.branch); printf("From: %s\n", ack_data.from); printf("tag: %s\n", ack_data.from_tag); printf("To: %s\n", ack_data.to); printf("tag: %s\n", ack_data.to_tag); printf("Call-id: %s\n", ack_data.call_id); printf("\n"); get_data(useful_op_ok.buffer, &op_ok_data); printf("\nOPTIONS OK data\n"); printf("branch: %s\n", op_ok_data.branch); printf("From: %s\n", op_ok_data.from); printf("tag: %s\n", op_ok_data.from_tag); printf("To: %s\n", op_ok_data.to); printf("tag: %s\n", op_ok_data.to_tag); printf("Call-id: %s\n", op_ok_data.call_id); printf("\n"); p = strstr(ack_data.from, "@") + 1; q = strstr(p, ">"); count = q - p; strncpy(initial_ip, p, count); initial_ip[count] = 0; printf("initial_ip: %s\n", initial_ip); replace_all(useful_invite.buffer, remote_ip, local_ip); replace_all(useful_invite.buffer, initial_ip, remote_ip); replace_all(useful_invite.buffer, ack_data.from_tag, ack_data.to_tag); useful_invite.size = strlen(useful_invite.buffer); printf("INVITE:\n%s\n", useful_invite.buffer); send_msg(proxy_to_linphone_socket, &proxy_to_linphone_addr, useful_invite.buffer, strlen(useful_invite.buffer)); add_poll(&fd, proxy_to_linphone_socket); rc = poll(&fd, 1, -1); DIE(-1 == rc, "poll"); recv_msg(proxy_to_linphone_socket, &proxy_to_linphone_addr, buffer); printf("\nreceived:\n%s\n", buffer); rc = poll(&fd, 1, -1); DIE(-1 == rc, "poll"); recv_msg(proxy_to_linphone_socket, &proxy_to_linphone_addr, buffer); printf("\nreceived:\n%s\n", buffer); get_data(buffer, &data_101); rc = poll(&fd, 1, -1); DIE(-1 == rc, "poll"); count = recv_msg(proxy_to_linphone_socket, &proxy_to_linphone_addr, buffer); copy_packet(&options, buffer, count); printf("\nreceived:\n%s\n", buffer); get_data(options.buffer, &options_data); printf("\nOPTIONS data\n"); printf("branch: %s\n", options_data.branch); printf("From: %s\n", options_data.from); printf("tag: %s\n", options_data.from_tag); printf("To: %s\n", options_data.to); printf("tag: %s\n", options_data.to_tag); printf("Call-id: %s\n", options_data.call_id); printf("\n"); replace_all(useful_op_ok.buffer, remote_ip, local_ip); replace_all(useful_op_ok.buffer, initial_ip, remote_ip); replace_all(useful_op_ok.buffer, op_ok_data.from_tag, options_data.from_tag); replace_all(useful_op_ok.buffer, op_ok_data.to_tag, options_data.to_tag); replace_all(useful_op_ok.buffer, op_ok_data.branch, options_data.branch); replace_all(useful_op_ok.buffer, op_ok_data.call_id, options_data.call_id); printf("\nforged OPTIONS OK: \n%s\n", useful_op_ok.buffer); send_msg(proxy_to_linphone_socket, &proxy_to_linphone_addr, useful_op_ok.buffer, strlen(useful_op_ok.buffer)); replace_all(useful_ack.buffer, remote_ip, local_ip); replace_all(useful_ack.buffer, initial_ip, remote_ip); replace_all(useful_ack.buffer, ack_data.from_tag, "magic"); replace_all(useful_ack.buffer, ack_data.to_tag, data_101.to_tag); replace_all(useful_ack.buffer, "magic", ack_data.to_tag); printf("\nforged ACK: \n%s\n", useful_ack.buffer); printf("1\n"); rc = poll(&fd, 1, -1); DIE(-1 == rc, "poll"); recv_msg(proxy_to_linphone_socket, &proxy_to_linphone_addr, buffer); printf("\nreceived:\n%s\n", buffer); printf("2\n"); rc = poll(&fd, 1, -1); DIE(-1 == rc, "poll"); recv_msg(proxy_to_linphone_socket, &proxy_to_linphone_addr, buffer); printf("\nreceived:\n%s\n", buffer); printf("3\n"); send_msg(proxy_to_linphone_socket, &proxy_to_linphone_addr, useful_ack.buffer, strlen(useful_ack.buffer)); printf("4\n"); strcpy(buffer, "done"); send_msg(manager_socket, &manager_addr, buffer, 4); printf("5\n"); }