static void * handleServer(void *ptr) { struct handler *handler; struct client *c; int32_t op; c = (struct client *)ptr; while(1) { ret32(c, op); handler = find_op(op); if (handler == NULL) { logmessage(c, __FILE__, __LINE__, 0, "op %d not supported", (int)op); exit(1); } logmessage(c, __FILE__, __LINE__, 0, "---> Got op %s from server %s", handler->name, c->servername); if ((handler->func)(handler->op, c)) break; } return NULL; }
static int islparenoperand(void) { char *s; int num; if (nargc == 1) return 1; s = *(t_wp + 1); if (nargc == 2) return parenlevel == 1 && strcmp(s, ")") == 0; if (nargc != 3) return 0; num = find_op(s); return TOKEN_TYPE(num) == BINOP; }
static enum token t_lex(char *s) { int num; if (s == NULL) { return EOI; } num = find_op(s); if (((TOKEN_TYPE(num) == UNOP || TOKEN_TYPE(num) == BUNOP) && isunopoperand()) || (num == LPAREN && islparenoperand()) || (num == RPAREN && isrparenoperand())) return OPERAND; return num; }
static int isunopoperand(void) { char *s; char *t; int num; if (nargc == 1) return 1; s = *(t_wp + 1); if (nargc == 2) return parenlevel == 1 && strcmp(s, ")") == 0; t = *(t_wp + 2); num = find_op(s); return TOKEN_TYPE(num) == BINOP && (parenlevel == 0 || t[0] != ')' || t[1] != '\0'); }
static void exec_multi_reqs(struct list_head *req_list, int *ret) { int nr = 0; struct bs_request *bsreq; const struct acrd_req *reqs[MAX_MULTI_REQS]; struct acrd_rsp **rsps[MAX_MULTI_REQS]; struct acrd_op_tmpl *op; bsreq = list_first_entry(req_list, struct bs_request, w_list); op = find_op(bsreq->rq->opcode); list_for_each_entry(bsreq, req_list, w_list) { reqs[nr] = bsreq->rq; if (bsreq->rsp) rsps[nr] = (struct acrd_rsp **)&bsreq->rsp->msg; else rsps[nr] = NULL; nr++; }
int target_x86_compile(target_x86_t *target_x86) { int i; for(i = 0; i < target_x86->array_line->count; i++) { char *line = (char *) array_get(target_x86->array_line, i); op_t *op; op = find_op(line); if( op != NULL ) { char str[STR_LINE_SIZE]; sprintf(str, "; %s", line); add_line(target_x86, TARGET_TEXT, str); op->f(target_x86, i); } } return 0; }
static int eval(int p,int q,bool *success){ if(p > q) { /* Bad expression */ *success=false; return 0; } else if(p == q) { /* Single token. * * For now this token should be a number. * * Return the value of the number. * */ switch(tokens[p].type){ case NUM: return atoi(tokens[p].str);break; case HEX: return strtoull(tokens[p].str, NULL, 16); case REG: if (!strcmp(tokens[p].str, "$eax")) return cpu.eax; else if (!strcmp(tokens[p].str, "$ecx")) return cpu.ecx; else if (!strcmp(tokens[p].str, "$edx")) return cpu.edx; else if (!strcmp(tokens[p].str, "$ebx")) return cpu.ebx; else if (!strcmp(tokens[p].str, "$esp")) return cpu.esp; else if (!strcmp(tokens[p].str, "$ebp")) return cpu.ebp; else if (!strcmp(tokens[p].str, "$esi")) return cpu.esi; else if (!strcmp(tokens[p].str, "$edi")) return cpu.edi; else if (!strcmp(tokens[p].str, "$eip")) return cpu.eip; /* else if (!strcmp(temp, "$ax")) return reg_w(R_AX); else if (!strcmp(temp, "$al")) return reg_b(R_AL); else if (!strcmp(temp, "$ah")) return reg_b(R_AH); else if (!strcmp(temp, "$cx")) return reg_w(R_CX); else if (!strcmp(temp, "$cl")) return reg_b(R_CL); else if (!strcmp(temp, "$ch")) return reg_b(R_CH); else if (!strcmp(temp, "$dx")) return reg_w(R_DX); else if (!strcmp(temp, "$dl")) return reg_b(R_DL); else if (!strcmp(temp, "$dh")) return reg_b(R_DH); else if (!strcmp(temp, "$bx")) return reg_w(R_BX); else if (!strcmp(temp, "$bl")) return reg_b(R_BL); else if (!strcmp(temp, "$bh")) return reg_b(R_BH); */ default: *success=false; return 0; } } else if(check_parentheses(p, q,success) == true) { /* The expression is surrounded by a matched pair of parentheses. * * If that is the case, just throw away the parentheses. * */ return eval(p + 1, q - 1,success); } else { int op = find_op(p, q);//找到优先级最高的操作符 int eval2 = eval(op + 1, q,success); switch (tokens[op].type) { case NOT: return !eval2; case NEG: return -eval2; case BIT_NOT: return ~eval2; case POINTER: return swaddr_read(eval2, 4); //how long? default: assert(op != p); } int eval1 = eval(p, op - 1,success); switch(tokens[op].type) { case ADD: return eval1 + eval2; case SUB: return eval1 - eval2; case MUL: return eval1 * eval2; case DIV: return eval1 / eval2; case MOD: return eval1 % eval2; case AND: return eval1 && eval2; case OR: return eval1 || eval2; case BIT_OR: return eval1 | eval2; case BIT_XOR: return eval1 ^ eval2; case BIT_AND: return eval1 & eval2; case EQ: return eval1 == eval2; case NE: return eval1 != eval2; case LE: return eval1 <= eval2; case LS: return eval1 < eval2; case GE: return eval1 >= eval2; case GT: return eval1 > eval2; case RSHIFT: return eval1 >> eval2; case LSHIFT: return eval1 << eval2; default: assert(0); } exit(1); } return 0; /* We should do more things here. */ }