int idaapi type_builder_t::visit_expr(cexpr_t *e) { // check if the expression being visited is variable if(e->op == cot_var) { // get the variable name char expr_name[MAXSTR]; e->print1(expr_name, MAXSTR, NULL); tag_remove(expr_name, expr_name, 0); // check for the target variable if(match_expression(expr_name)) { struct_filed str_fld; if(check_ptr(e, str_fld)) { std::pair<std::map<int,struct_filed>::iterator,bool> ret; ret = structure.insert(std::pair<int,struct_filed>(str_fld.offset, str_fld)); if ((ret.second == false) && (str_fld.vftbl != BADADDR)) { structure[str_fld.offset] = str_fld; } } } } return 0; }
nir_alu_instr * nir_replace_instr(nir_alu_instr *instr, const nir_search_expression *search, const nir_search_value *replace, void *mem_ctx) { uint8_t swizzle[4] = { 0, 0, 0, 0 }; for (unsigned i = 0; i < instr->dest.dest.ssa.num_components; ++i) swizzle[i] = i; assert(instr->dest.dest.is_ssa); struct match_state state; state.variables_seen = 0; if (!match_expression(search, instr, instr->dest.dest.ssa.num_components, swizzle, &state)) return NULL; /* Inserting a mov may be unnecessary. However, it's much easier to * simply let copy propagation clean this up than to try to go through * and rewrite swizzles ourselves. */ nir_alu_instr *mov = nir_alu_instr_create(mem_ctx, nir_op_imov); mov->dest.write_mask = instr->dest.write_mask; nir_ssa_dest_init(&mov->instr, &mov->dest.dest, instr->dest.dest.ssa.num_components, NULL); mov->src[0] = construct_value(replace, nir_op_infos[instr->op].output_type, instr->dest.dest.ssa.num_components, &state, &instr->instr, mem_ctx); nir_instr_insert_before(&instr->instr, &mov->instr); nir_ssa_def_rewrite_uses(&instr->dest.dest.ssa, nir_src_for_ssa(&mov->dest.dest.ssa), mem_ctx); /* We know this one has no more uses because we just rewrote them all, * so we can remove it. The rest of the matched expression, however, we * don't know so much about. We'll just let dead code clean them up. */ nir_instr_remove(&instr->instr); return mov; }
/** "Returns 1 if the expression agrees with one of the legal robot expressions, otherwise it returns 0." <p> "Expression" is a line, not in individal token. It checks the individual tokens, and then it checks the syntax of the line. If it returns false, it's guaranteed to set synax.error. <p> It uses parse.c to tokenise, so it will destroy any temp data that you have. */ int isValidExpression(const char *const expression) { const struct Token *token; int shift; char avatar[512] = "", *a, *b; /* check the arguments */ if(!expression) { snprintf(syntax.error, sizeof syntax.error, "null expression"); syntax.index = -1; return 0; } /* parse expression into Tokens and put them into the avatar (expression buffer or whatever) */ initBuffer(expression); a = avatar; while(hasNextToken()) { if(!(token = match_token(nextToken()))) return 0; /* danger! (undefined behaviour) snprintf(avatar, sizeof avatar, "%s%c", avatar, token->avatar) */ if(a >= avatar + sizeof avatar / sizeof(char) - 1 /*null*/) { snprintf(syntax.error, sizeof syntax.error, "line too long; %u tokens", (int)sizeof avatar); /* index is set in parse.c */ return 0; } *(a++) = token->avatar; *a = '\0'; } if(debug) fprintf(stderr, "isValidExp avatar before <%s>\n", avatar); /* group tokens together; it could have been combined with the previous step for greater effecacity, but more confusion */ while((b = strrchr(avatar, 'E'))) { for(a = b - 1; a >= avatar && *a == '$'; a--); a++; for(shift = b - a, *(a++) = '%'; (*a = *(a + shift)); a++); } if(debug) fprintf(stderr, "isValidExp avatar grouping <%s>\n", avatar); return match_expression(avatar) ? 1 : 0; }
node statement() { ts_trans tr(ts_); if( ts_->end_of_input() ) { return node(); } rule_t exp = match_list( { match_expression(), token(3) }); node n = exp(ts_); std::cout << "statement: " << n.is_null() << "\n"; if( !n.is_null() ) { n.annotate( "statement" ); tr.commit(); } return n; }
/* * Check header permissions. * Does newsgroup checks if ReadPat is specified * Does Retention check if retention > 0 */ static int check_headperm(char *msgid) { char *ng; time_t msgdate; HLIST *hdr = NULL, *allhdrs = NULL; char header[MAX_HEADER]; char value[MAX_HEADER]; char *hval; CLEARBUF if ( cfg.LocalDreader == 1 && strcmp(client->user->readpat, "all") == 0 && client->profile->Retention == 0) return CHECK_ARTICLE_OK; if ( writeserver(client, "HEAD %s\r\n", msgid) == false ) return CHECK_ARTICLE_FAIL; if ( (readserverline(client->bbuf, cfg.BufSize)) == NULL ) return CHECK_ARTICLE_FAIL; if ( atoi(client->bbuf) > 399 ) return CHECK_ARTICLE_FAIL; /* read headers from server */ while( readserverline(client->bbuf, cfg.BufSize) != NULL ) { if ((sscanf(client->bbuf, "%63[^\t ] %1023[^\r\n]", header, value)) == 0) strncpy(value, client->bbuf, MAX_HEADER-1); hdr = insert_hlist(hdr, header, value); if ( allhdrs == NULL ) allhdrs = hdr; if ( header[0] == '.' ) break; } hdr = allhdrs; /* check retention time first */ if ( client->profile->Retention > 0 ) { msgdate = 0; if ( (hval=hlist_get_value(hdr, "NNTP-Posting-Date:")) != NULL ) msgdate = parsedate(hval); else if ( (hval=hlist_get_value(hdr, "Date:")) != NULL ) msgdate = parsedate(hval); if ( msgdate < (time(NULL) - (client->profile->Retention * 86400)) ) { free_hlist(hdr); return CHECK_ARTICLE_NOPERM; } } /* check newsgroup permission */ if ( (ng=hlist_get_value(hdr, "Newsgroups:")) != NULL ) { free_hlist(hdr); /* now we've found the article and have the newsgroups header */ if ( match_expression((unsigned char *)ng , (unsigned char *)getwildmat(client->user->readpat) , 0) ) return CHECK_ARTICLE_OK; else return CHECK_ARTICLE_NOPERM; } /* If we reach this, the article wouldn't have a newsgroups header. */ free_hlist(hdr); return CHECK_ARTICLE_FAIL; }
PROTO int group(const char *group, char nogroupecho) { char b[MAX_SERVERRSP]; ACTIVE *newgroup; SERVER *svr; CLEARBUF if ( nullstr(group) ) { swriteclient(client,"500 You must select a group\r\n"); return 1; } /* only change group if it has changed */ if ( client->group == NULL || strcmp(client->group->newsgroup, group) != 0 ) { /* check for read permission */ if ( ! match_expression((unsigned char *)group , (unsigned char *)getwildmat(client->user->readpat) , 0) ) { if ( ! nogroupecho ) swriteclient(client, MSG_NOSUCHGROUP); return 1; } /* find and load our new group */ if ( (newgroup = getgroup(group)) == NULL ) { if ( ! nogroupecho ) swriteclient(client, MSG_NOSUCHGROUP); return 1; } if ( (svr=getserver(newgroup->server)) == NULL ) return swriteclient(client, "500 Cant find server for group\r\n"); /* disconnect first if we have to change server */ if ( client->groupserver != NULL && client->connected == 1 && strcmp(svr->Groups, client->groupserver->Groups) != 0 ) { disconnect_server(client); } /* close group and reconnect */ closegroup(); client->group = newgroup; switch ( connect_groupserver(client, svr->Name) ) { case CONNECT_ERR: return swriteclient(client, "500 Error selecting server\r\n"); case CONNECT_DOWN: sleep(cfg.DownDelay); return writeclient(client, MSG_SERVER_DOWN); default: break; } /* reset by connect_groupserver (via disconnect_server FIXME) */ client->group = newgroup; client->groups++; } if ( ! writeserver(client, "GROUP %s\r\n", group) ) return -1; if ( ! readserver(client, b, MAX_SERVERRSP-1) ) return -1; syslog(LOG_NOTICE, "%s: group %s", client->hostname, group); if ( ! nogroupecho ) return swriteclient(client,b); return 0; }
static bool match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src, unsigned num_components, const uint8_t *swizzle, struct match_state *state) { uint8_t new_swizzle[4]; /* If the source is an explicitly sized source, then we need to reset * both the number of components and the swizzle. */ if (nir_op_infos[instr->op].input_sizes[src] != 0) { num_components = nir_op_infos[instr->op].input_sizes[src]; swizzle = identity_swizzle; } for (int i = 0; i < num_components; ++i) new_swizzle[i] = instr->src[src].swizzle[swizzle[i]]; switch (value->type) { case nir_search_value_expression: if (!instr->src[src].src.is_ssa) return false; if (instr->src[src].src.ssa->parent_instr->type != nir_instr_type_alu) return false; return match_expression(nir_search_value_as_expression(value), nir_instr_as_alu(instr->src[src].src.ssa->parent_instr), num_components, new_swizzle, state); case nir_search_value_variable: { nir_search_variable *var = nir_search_value_as_variable(value); assert(var->variable < NIR_SEARCH_MAX_VARIABLES); if (state->variables_seen & (1 << var->variable)) { if (!nir_srcs_equal(state->variables[var->variable].src, instr->src[src].src)) return false; assert(!instr->src[src].abs && !instr->src[src].negate); for (int i = 0; i < num_components; ++i) { if (state->variables[var->variable].swizzle[i] != new_swizzle[i]) return false; } return true; } else { if (var->is_constant && instr->src[src].src.ssa->parent_instr->type != nir_instr_type_load_const) return false; if (var->type != nir_type_invalid) { if (instr->src[src].src.ssa->parent_instr->type != nir_instr_type_alu) return false; nir_alu_instr *src_alu = nir_instr_as_alu(instr->src[src].src.ssa->parent_instr); if (nir_op_infos[src_alu->op].output_type != var->type && !(var->type == nir_type_bool && alu_instr_is_bool(src_alu))) return false; } state->variables_seen |= (1 << var->variable); state->variables[var->variable].src = instr->src[src].src; state->variables[var->variable].abs = false; state->variables[var->variable].negate = false; for (int i = 0; i < 4; ++i) { if (i < num_components) state->variables[var->variable].swizzle[i] = new_swizzle[i]; else state->variables[var->variable].swizzle[i] = 0; } return true; } } case nir_search_value_constant: { nir_search_constant *const_val = nir_search_value_as_constant(value); if (!instr->src[src].src.is_ssa) return false; if (instr->src[src].src.ssa->parent_instr->type != nir_instr_type_load_const) return false; nir_load_const_instr *load = nir_instr_as_load_const(instr->src[src].src.ssa->parent_instr); switch (nir_op_infos[instr->op].input_types[src]) { case nir_type_float: for (unsigned i = 0; i < num_components; ++i) { if (load->value.f[new_swizzle[i]] != const_val->data.f) return false; } return true; case nir_type_int: case nir_type_unsigned: case nir_type_bool: for (unsigned i = 0; i < num_components; ++i) { if (load->value.i[new_swizzle[i]] != const_val->data.i) return false; } return true; default: unreachable("Invalid alu source type"); } } default: unreachable("Invalid search value type"); } }