static float expression(void) { token operator = T_PLUS; if (sym == T_PLUS || sym == T_MINUS) { operator = sym; get_sym(); } float t1 = term(); if (operator == T_MINUS) { t1 = -1 * t1; } while ( sym == T_PLUS || sym == T_MINUS || sym == T_OP_OR ) { operator = sym; get_sym(); float t2 = term(); switch(operator) { case T_PLUS: t1 = t1 + t2; break; case T_MINUS: t1 = t1 - t2; break; case T_OP_OR: t1 = _or( t1, t2 ); break; default: error("expression: oops"); } } return t1; }
void makelocal (struct command *cmd) /* makes symbol local */ { if (get_sym (cmd->symname, cmd->args, amSEARCH_VERY_LOCAL)) { sprintf (string, "local variable '%s' already defined within this subroutine", strip (cmd->symname)); error (ERROR, string); return; } get_sym (cmd->symname, cmd->args, amADD_LOCAL); }
void get_kernel_syms() { printf("[+] Looking up kernel symbols...\n"); commit_creds = (_commit_creds) get_sym("commit_creds"); if (!commit_creds) { printf("[-] Could not find commit_creds...\n"); exit(1); } prepare_kernel_cred = (_prepare_kernel_cred) get_sym("prepare_kernel_cred"); if (!prepare_kernel_cred) { printf("[-] Could not find prepare_kernel_cred...\n"); exit(1); } }
void print_opnd_type(Opnd o) { if(is_reg(o)) { if(is_hard_reg(o)) { std::cout << "(is hard reg)"; } else if(is_virtual_reg(o)) { std::cout << "(is virtual reg)[$vr"<<get_reg(o)<<"]"; } else { std::cout << "(is undeterminate reg)"; } } else if(is_immed(o)) { if(is_immed_integer(o)) { std::cout << "(is immed integer)"; } else if(is_immed_string(o)) { std::cout << "(is immed string)"; } else { std::cout << "(is undeterminate immed)"; } } else if(is_addr(o)) { if(is_addr_sym(o)) { FormattedText ft; Sym *symbol = get_sym(o); symbol->print(ft); char* addr_name; addr_name = (char*)(symbol->get_name()).c_str(); std::cout << "(is addr sym)["<<addr_name<<"]"; } else if(is_addr_exp(o)) { std::cout << "(is addr exp)"; } else { std::cout << "(is undeterminate addr)"; } } else if(is_var(o)) { FormattedText ft; VarSym *vsym = get_var(o); vsym->print(ft); char* var_name; var_name = (char*)(vsym->get_name()).c_str(); std::cout << "(is var)["<<var_name<<"]"; } else if(is_null(o)) { std::cout << "(is null)"; } else { std::cout << "(I don't know) !!!)"; } return; }
Elf32_Sym *mips_elf_find_address(struct mips_cpu *pcpu, Elf32_Addr addr) { Elf32_Shdr *shsymtab = pcpu->shsymtab; unsigned n = shsymtab->sh_size / shsymtab->sh_entsize; Elf32_Addr min = (unsigned)-1; Elf32_Sym *ret = NULL; unsigned i; if((shsymtab->sh_offset + shsymtab->sh_size > pcpu->elfsz) || (addr >= pcpu->memsz)) return NULL; for(i = 0; i < n; i++) { Elf32_Sym *sym = get_sym(pcpu->elf, pcpu->elfsz, shsymtab, i); if(!sym) return NULL; if((ELF_ST_BIND(sym->st_info) != STB_GLOBAL) || (ELF_ST_TYPE(sym->st_info) >= STT_SECTION)) continue; if(sym->st_value <= addr) { Elf32_Addr diff = addr - sym->st_value; if(diff < min) { min = diff; ret = sym; if(diff == 0) break; } } } return ret; }
Elf32_Sym *mips_elf_find_symbol(struct mips_cpu *pcpu, const char *name) { Elf32_Shdr *shsymtab = pcpu->shsymtab; unsigned n =shsymtab->sh_size / shsymtab->sh_entsize; unsigned i; if(shsymtab->sh_offset + shsymtab->sh_size > pcpu->elfsz) return NULL; for(i = 0; i < n; i++) { Elf32_Sym *sym = get_sym(pcpu->elf, pcpu->elfsz, shsymtab, i); const char *symname; if(!sym) return NULL; if(ELF_ST_BIND(sym->st_info) != STB_GLOBAL) continue; symname = get_string(pcpu->elf, pcpu->elfsz, pcpu->shsymstr, sym->st_name); if(!symname) return NULL; if(Sequal(name, symname)) return sym; } return NULL; }
char* get_token(char *p) { if(isalpha(*p)) {p=get_word(p);} else if((isdigit(*p))||((*p=='-')&&(isdigit(*(p+1))))) {p=get_num(p);} else {p=get_sym(p);} return p; }
int ne_parse(const char *formula) { int err; struct symbol_table *sym; ne.buf = yy_scan_string(formula, ne.scanner); yyset_lineno(1, ne.scanner); yyset_column(1, ne.scanner); __ne_clear_error(&ne); err = yyparse(&ne); if (!err) { __ne_put_result(&ne, eval(&ne, ne.root)); sym = get_sym(&ne, "y"); if (sym && sym->dirty) { __ne_put_result(&ne, __ne_get_y(&ne)); clean_output_sym(&ne); } } if (ne.error != 0) err = ne.error; else if (ne.warrning != 0) err = ne.warrning; free_ast(ne.root); ne.root = NULL; ne.stop = 0; yy_delete_buffer(ne.buf, ne.scanner); return err; }
static struct node_t *comp_expr(struct c_desc *cd) { int tok,opr; struct node_t *p,*q; p = term_expr(cd); /* don't do while, see syntax. */ if(S_LESS <= cd->op && cd->op <= S_MORE) { tok = cd->op; get_sym(cd); q = term_expr(cd); switch(tok) { case S_LESS: opr = O_LESS; break; case S_LESSEQ: opr = O_LESSEQ; break; case S_EQ: opr = O_EQ; break; case S_MOREEQ: opr = O_MOREEQ; break; case S_MORE: opr = O_MORE; break; default: opr = O_ERR; break; /* impossible */ } p = new_node_t(opr,p,q); } return p; }
void count_params (struct command *cmd) /* count number of function parameters */ { struct symbol *sym; sym = get_sym (cmd->symname, syNUMBER, amADD_LOCAL); sym->value = abs (count_args (FALSE)); }
float evaluate(char *expression_string) { last_error = NULL; tokenizer_init( expression_string ); get_sym(); float result = expression(); expect(T_EOF); return result; }
static bool accept(token t) { if (t == sym) { get_sym(); return true; } return false; }
inline void VariableFound(char *var) { optional opt = get_sym(tab, var); if (opt.e) { arr_push(operands, opt.val); } else { //printf("Error at line %d position %d Use of undeclared variable %s\n", get_linenum(), get_position(), var); fprintf(sym_file, "Error at line %d position %d Use of undeclared variable %s\n", get_linenum(), get_position(), var); stop(); } }
/* * add label to symbol table, error if symbol already exists */ void put_label(void) { struct sym *get_sym(char *); if (get_sym(label) == NULL) { if (put_sym(label, pc)) fatal(F_OUTMEM, "symbols"); } else asmerr(E_MULSYM); }
static struct node_t *term_expr(struct c_desc *cd) { struct node_t *p; char *id; int *i; switch(cd->op) { case S_NUM: i = (int *)xmalloc(sizeof(int)); *i = cd->val; p = new_node_t(O_NUM,(struct node_t *)i,NULL); get_sym(cd); break; case S_ID: id = strdup(cd->id); p = new_node_t(O_ID,(struct node_t *)id,NULL); get_sym(cd); break; case S_LPAREN: get_sym(cd); p = cond_expr(cd); if(!p) { /* NULL */ display(MSDL_ERR,"asmrule: parse error\n"); } else if(cd->op != S_RPAREN) { display(MSDL_ERR,"asmrule: no closing ')'\n"); } get_sym(cd); break; default: display(MSDL_ERR,"asmrule: syntax error at %s\n",cd->cur_p); p = NULL; } return p; }
void ne_error(char *result) { struct symbol_table *sym = NULL; weak_t *val; *result = '\0'; sym = get_sym(&ne, NE_ERROR); if (sym) { val = &sym->ret; weak_sprintf(result, val); } }
void sim_resume(int step){ do { /* if we are in remote debugmode we will check ctrl+c and breakpoint */ if(remote_debugmode){ int i; WORD addr; /* to detect if Ctrl+c is pressed.. */ if(remote_interrupt()) return; addr = arch_instance->get_pc(); for (i = 0;i < skyeye_ice.num_bps;i++){ if(skyeye_ice.bps[i] == addr) return; } /* for */ if (skyeye_ice.tps_status==TRACE_STARTED) { for (i=0;i<skyeye_ice.num_tps;i++) { if (((skyeye_ice.tps[i].tp_address==addr)&& (skyeye_ice.tps[i].status==TRACEPOINT_ENABLED))||(skyeye_ice.tps[i].status==TRACEPOINT_STEPPING)) { handle_tracepoint(i); } } } } /* if(remote_debugmode) */ if (skyeye_config.log.logon >= 1) { WORD pc = arch_instance->get_pc(); if (pc >= skyeye_config.log.start && pc <= skyeye_config.log.end) { #if !defined(__MINGW32__) char * func_name = get_sym(pc); if(func_name) fprintf (skyeye_logfd,"\n in %s\n", func_name); #endif /* if (skyeye_config.log.logon >= 2) fprintf (skyeye_logfd, "pc=0x%x", pc); SKYEYE_OUTREGS (skyeye_logfd); if (skyeye_config.log.logon >= 3) SKYEYE_OUTMOREREGS (skyeye_logfd); */ } }/* if (skyeye_config.log.logon >= 1) */ arch_instance->step_once (); }while(!step); }
static int deffuncs(struct lk_ctx *ctx, int fd) { unsigned int i; int ct = 0; char *ptr, *s; struct kbsentry kbs; for (i = 0; i < MAX_NR_FUNC; i++) { kbs.kb_func = (unsigned char) i; ptr = lk_array_get_ptr(ctx->func_table, i); if (ptr) { strcpy((char *)kbs.kb_string, ptr); if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs)) { s = ostr(ctx, (char *)kbs.kb_string); if (s == NULL) return -1; ERR(ctx, _("failed to bind string '%s' to function %s"), s, get_sym(ctx, KT_FN, kbs.kb_func)); free(s); } else { ct++; } } else if (ctx->flags & LK_FLAG_CLEAR_STRINGS) { kbs.kb_string[0] = 0; if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs)) { ERR(ctx, _("failed to clear string %s"), get_sym(ctx, KT_FN, kbs.kb_func)); } else { ct++; } } } return ct; }
static match_t *get_match_or_create(char *name) { int i; for (i = 0; i < num_matches; i++) { if (!strcmp(matches[i].name->name, name)) { return &matches[i]; } } if (num_matches < NUM_CUSTOM_MATCHES) { matches[num_matches].name = get_sym(name); return &matches[num_matches++]; } return NULL; }
static struct c_desc *new_c_desc(char *asmrule) { struct c_desc *cd = (struct c_desc *)xmalloc(sizeof(struct c_desc)); cd->whole_line = asmrule; cd->cur_p = cd->whole_line; cd->op = S_NULL; cd->val = 0; cd->id = (char *)xmalloc(100); cd->id_len = 100; get_sym(cd); return cd; }
void F_print(void) { forth_obj e = pop(&pstack); dprintf(("print(%x)\n", e.num)); if(get_type(e) == TYPE_FIXNUM){ printf("%d\n", get_num(e)); }else if (get_type(e) == TYPE_STRING){ printf("%s\n", get_sym(e)); }else{ printf("#<unprintable %x>\n", e.num & ~TYPE_MASK); } dprintf(("print end\n")); pc++; }
void ne_insert(const char *name, int val) { struct symbol_table *sym; sym = get_sym(&ne, name); if (!sym) sym = put_sym(&ne, name, SYM_INPUT); sym->type = SYM_INPUT; sym->ret.type = WEAK_INT; sym->ret.val.i = val; sym->dirty = true; }
char* get_addr_name(Opnd addr_sym) { claim(is_addr_sym(addr_sym), "opnd.cpp::get_addr_name:the type must be addr_sym!"); FormattedText ft; Sym *symbol = get_sym(addr_sym); symbol->print(ft); char* addr_name; addr_name = (char*)(symbol->get_name()).c_str(); return addr_name; }
int openat64(int fd, char const *path, int flags, ...) { static void *cached_next = 0; openat_t *next; mode_t mode; int original_fd; GET_OPEN_MODE(mode, flags) original_fd = parse_path(path); if (original_fd == -1) { next = get_sym(&cached_next, "openat64"); return (*next)(fd, path, flags, mode); } return dup(original_fd); }
TypeId get_deref_type(Opnd opnd) { if (is_addr_sym(opnd)) { Sym *sym = get_sym(opnd); if (is_kind_of<LabelSym>(sym)) return NULL; else { claim(is_kind_of<VarSym>(sym) || is_kind_of<ProcSym>(sym)); return sym->get_type(); } } claim(is_addr_exp(opnd)); IrOpnd *o = opnd; return static_cast<OpndAddrExp*>(o)->get_deref_type(); }
/* * EQU */ int op_equ(void) { if (!gencode) return(0); if (pass == 1) { /* Pass 1 */ if (get_sym(label) == NULL) { sd_val = eval(operand); if (put_sym(label, sd_val)) fatal(F_OUTMEM, "symbols"); } else asmerr(E_MULSYM); } else { /* Pass 2 */ sd_flag = 1; sd_val = eval(operand); } return(0); }
void print_forth_obj(forth_obj* e) { printf("%p(%04x):", e, get_type(*e)); switch(get_type(*e)){ case TYPE_FIXNUM: printf("FIXNUM:%8d\n", get_num(*e)); break; case TYPE_PRIM: printf("PRIM :%p\t%s\n", get_prim(*e),forth_dict_name(e)); break; case TYPE_THREAD: printf("THREAD:%p\t%s\n", get_prim(*e),forth_dict_name(e)); break; case TYPE_STRING: printf("STRING:%s\n", get_sym(*e)); break; } }
FILE *fopen64(char const *path, char const *mode) { static void *cached_next = 0; fopen_t *next; int original_fd; int duped_fd; original_fd = parse_path(path); if (original_fd == -1) { next = get_sym(&cached_next, "fopen64"); return (*next)(path, mode); } duped_fd = dup(original_fd); if (duped_fd == -1) { return NULL; } return fdopen(duped_fd, mode); }
void ne_result(char *result) { struct symbol_table *sym = NULL; weak_t *val; *result = '\0'; sym = get_sym(&ne, NE_RESULT); if (sym) { val = &sym->ret; weak_sprintf(result, val); if (val->type == WEAK_STRING && val->val.s) { nfree(val->val.s); val->val.s = NULL; } val->type = WEAK_INT; val->val.i = 0; } }
static struct node_t *cond_expr(struct c_desc *cd) { int tok,opr; struct node_t *p,*q; p = comp_expr(cd); /* don't do while, see syntax */ if(cd->op == S_AND || cd->op == S_OR) { tok = cd->op; get_sym(cd); q = comp_expr(cd); if(tok == S_AND) opr = O_AND; else if(tok == S_OR) opr = O_OR; else opr = O_ERR; /* impossible */ p = new_node_t(opr,p,q); } return p; }