int exec_all_funcs(char ***cmd) { int len_cmd; int ret; while (cmd && *cmd) { len_cmd = len_arr_triple(cmd); if (len_cmd >= 2) { ret = choose_case(&cmd); if (ret == -1) return (-1); else if (ret == 0) break ; } else { if (exec_func(*cmd)) return (-1) ; cmd++; } } return (0); }
int main(void) { static char buf[16]; int i = 0; void (*exec_func)(void) = NULL; INTR_DISABLE; /* 割込み無効にする */ init(); puts("kzload (kozos boot loader) started.\n"); while (1) { puts("kzload> "); /* プロンプト表示 */ gets(buf); /* シリアルからのコマンド受信 */ for( i = 0 ; cmd_list[i].cmd != NULL; i++ ) { if(!strcmp(buf,cmd_list[i].cmd)) { exec_func = (void (*)(void))cmd_list[i].func; break; } } if(!exec_func) { puts("unknown.\n"); } else { exec_func(); } exec_func = NULL; } return 0; }
void video_renderer_task_req_hdlr(ilm_struct *ilm_msg) { #if defined(__MTK_TARGET__) _video_renderer_task_local_param_t *local_para_ptr; video_renderer_task_exec_func_t exec_func; void * exec_param; ASSERT(NULL != ilm_msg); ASSERT(KAL_FALSE == kal_if_hisr()); ASSERT(KAL_FALSE == kal_if_lisr()); // get ilm parameters local_para_ptr = (_video_renderer_task_local_param_t*) ilm_msg->local_para_ptr; ASSERT(NULL != local_para_ptr); exec_func = local_para_ptr->exec_func; exec_param = &(local_para_ptr->exec_param); // do execution if (exec_func) { exec_func(exec_param); } #endif //#if defined(__MTK_TARGET__) }
void do_fork_exec(const char *cmdline, int *pid, int *stdin_fd, int *stdout_fd, int *stderr_fd) { int inpipe[2], outpipe[2], errpipe[2]; if (socketpair(AF_UNIX, SOCK_STREAM, 0, inpipe) || socketpair(AF_UNIX, SOCK_STREAM, 0, outpipe) || (stderr_fd && socketpair(AF_UNIX, SOCK_STREAM, 0, errpipe))) { perror("socketpair"); exit(1); } switch (*pid = fork()) { case -1: perror("fork"); exit(-1); case 0: if (stderr_fd) { fix_fds(inpipe[0], outpipe[1], errpipe[1]); } else fix_fds(inpipe[0], outpipe[1], 2); if (exec_func != NULL) exec_func(cmdline); exit(-1); default:; } close(inpipe[0]); close(outpipe[1]); *stdin_fd = inpipe[1]; *stdout_fd = outpipe[0]; if (stderr_fd) { close(errpipe[1]); *stderr_fd = errpipe[0]; } }
int main(int argc, char *argv[]) { char *path = NULL;// "C:\\FlareOn2017\\payload.dll"; if (argc < 3) { printf("Args: <path> <index>\n"); printf("path: path to the crackme\n"); printf("index: index of the chunk that you want to see\n"); system("pause"); return -1; } path = argv[1]; g_index = atoi(argv[2]); peconv::hooking_func_resolver my_res; my_res.add_hook("MessageBoxA", (FARPROC) &my_MessageBoxA); size_t v_size = 0; BYTE* loaded_pe = peconv::load_pe_executable( path, v_size, (peconv::t_function_resolver*) &my_res ); if (!loaded_pe) { printf("Loading module failed!\n"); system("pause"); return 0; } ULONGLONG func_offset = (ULONGLONG)loaded_pe + 0x5D30; ULONGLONG srand_offset = (ULONGLONG)loaded_pe + 0x7900; ULONGLONG rand_offset = (ULONGLONG)loaded_pe + 0x78D4; ULONGLONG calc_index_offset = (ULONGLONG)loaded_pe + 0x4710; peconv::redirect_to_local64((void*)srand_offset, (ULONGLONG)&srand); peconv::redirect_to_local64((void*)rand_offset, (ULONGLONG)&rand); peconv::redirect_to_local64((void*)calc_index_offset, (ULONGLONG)&my_index); to_overwrite_mem = ( __int64 (__fastcall *)(__int64 ))func_offset; __int64 ret = to_overwrite_mem(0); std::vector<std::string> names_vec; if (peconv::get_exported_names(loaded_pe, names_vec) > 0) { const char *first_name = names_vec[0].c_str(); exec_func((HMODULE)loaded_pe, const_cast<char *>(first_name)); } peconv::free_pe_buffer(loaded_pe, v_size); return 0; }
static void process_command( uint8_t * buf, int sz ) { int i; uint8_t cmd; cmd = buf[0]; uint8_t * data = &(buf[1]); switch ( cmd ) { case CMD_SET_ARGS: for ( i=0; i<(sz-1); i++ ) args[i] = data[i]; break; case CMD_EXEC_FUNC: // Execute function by it's index. exec_func(); break; } }
/** * 数または関数 * * @param[in] calc calcinfo構造体 * @return 値 */ static dbl token(calcinfo *calc) { dbl result = 0.0; /* 結果 */ int sign = '+'; /* 単項+- */ char func[MAX_FUNC_STRING + 1]; /* 関数文字列 */ int pos = 0; /* 配列位置 */ dbglog("start"); if (is_error(calc)) return EX_ERROR; /* 初期化 */ (void)memset(func, 0, sizeof(func)); if (calc->ch == '+' || calc->ch == '-') { /* 単項+- */ sign = calc->ch; readch(calc); } if (isdigit(calc->ch)) { /* 数値 */ result = number(calc); } else if (isalpha(calc->ch)) { /* 関数 */ while (isalpha(calc->ch) && calc->ch != '\0' && pos <= MAX_FUNC_STRING) { func[pos++] = calc->ch; readch(calc); } dbglog("func=%s", func); result = exec_func(calc, func); } else { /* エラー */ dbglog("ch=%c", calc->ch); set_errorcode(calc, E_SYNTAX); } dbglog(calc->fmt, result); return (sign == '+') ? result : -result; }
int main() { char *cmdline = NULL; size_t size = 0, chr = 0; int index; char** arr_of_str; char c; while((c = getchar()) != EOF) //check each character { if(size <= chr) { size += 1; cmdline = realloc(cmdline,size); index = 0; } if(c == '\n') //check for new lines { cmdline[chr] = '\0'; //terminate the string chr = 0; size = 0; index = 1; arr_of_str = parse_cmdline(cmdline); //calling the parse_cmdline function exec_func(arr_of_str); //calling the exec_func function free(arr_of_str); free(str); //free the memory allocation free(cmdline); cmdline = NULL; } else { cmdline[chr++] = c; } } if(index == 0) { free(cmdline); //free the memory allocation } return 0; }
bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression::ENode *p_node, Variant &r_ret, String &r_error_str) { switch (p_node->type) { case Expression::ENode::TYPE_INPUT: { const Expression::InputNode *in = static_cast<const Expression::InputNode *>(p_node); if (in->index < 0 || in->index >= p_inputs.size()) { r_error_str = vformat(RTR("Invalid input %i (not passed) in expression"), in->index); return true; } r_ret = p_inputs[in->index]; } break; case Expression::ENode::TYPE_CONSTANT: { const Expression::ConstantNode *c = static_cast<const Expression::ConstantNode *>(p_node); r_ret = c->value; } break; case Expression::ENode::TYPE_SELF: { if (!p_instance) { r_error_str = RTR("self can't be used because instance is null (not passed)"); return true; } r_ret = p_instance; } break; case Expression::ENode::TYPE_OPERATOR: { const Expression::OperatorNode *op = static_cast<const Expression::OperatorNode *>(p_node); Variant a; bool ret = _execute(p_inputs, p_instance, op->nodes[0], a, r_error_str); if (ret) return true; Variant b; if (op->nodes[1]) { ret = _execute(p_inputs, p_instance, op->nodes[1], b, r_error_str); if (ret) return true; } bool valid = true; Variant::evaluate(op->op, a, b, r_ret, valid); if (!valid) { r_error_str = vformat(RTR("Invalid operands to operator %s, %s and %s."), Variant::get_operator_name(op->op), Variant::get_type_name(a.get_type()), Variant::get_type_name(b.get_type())); return true; } } break; case Expression::ENode::TYPE_INDEX: { const Expression::IndexNode *index = static_cast<const Expression::IndexNode *>(p_node); Variant base; bool ret = _execute(p_inputs, p_instance, index->base, base, r_error_str); if (ret) return true; Variant idx; ret = _execute(p_inputs, p_instance, index->index, idx, r_error_str); if (ret) return true; bool valid; r_ret = base.get(idx, &valid); if (!valid) { r_error_str = vformat(RTR("Invalid index of type %s for base type %s"), Variant::get_type_name(idx.get_type()), Variant::get_type_name(base.get_type())); return true; } } break; case Expression::ENode::TYPE_NAMED_INDEX: { const Expression::NamedIndexNode *index = static_cast<const Expression::NamedIndexNode *>(p_node); Variant base; bool ret = _execute(p_inputs, p_instance, index->base, base, r_error_str); if (ret) return true; bool valid; r_ret = base.get_named(index->name, &valid); if (!valid) { r_error_str = vformat(RTR("Invalid named index '%s' for base type %s"), String(index->name), Variant::get_type_name(base.get_type())); return true; } } break; case Expression::ENode::TYPE_ARRAY: { const Expression::ArrayNode *array = static_cast<const Expression::ArrayNode *>(p_node); Array arr; arr.resize(array->array.size()); for (int i = 0; i < array->array.size(); i++) { Variant value; bool ret = _execute(p_inputs, p_instance, array->array[i], value, r_error_str); if (ret) return true; arr[i] = value; } r_ret = arr; } break; case Expression::ENode::TYPE_DICTIONARY: { const Expression::DictionaryNode *dictionary = static_cast<const Expression::DictionaryNode *>(p_node); Dictionary d; for (int i = 0; i < dictionary->dict.size(); i += 2) { Variant key; bool ret = _execute(p_inputs, p_instance, dictionary->dict[i + 0], key, r_error_str); if (ret) return true; Variant value; ret = _execute(p_inputs, p_instance, dictionary->dict[i + 1], value, r_error_str); if (ret) return true; d[key] = value; } r_ret = d; } break; case Expression::ENode::TYPE_CONSTRUCTOR: { const Expression::ConstructorNode *constructor = static_cast<const Expression::ConstructorNode *>(p_node); Vector<Variant> arr; Vector<const Variant *> argp; arr.resize(constructor->arguments.size()); argp.resize(constructor->arguments.size()); for (int i = 0; i < constructor->arguments.size(); i++) { Variant value; bool ret = _execute(p_inputs, p_instance, constructor->arguments[i], value, r_error_str); if (ret) return true; arr.write[i] = value; argp.write[i] = &arr[i]; } Variant::CallError ce; r_ret = Variant::construct(constructor->data_type, (const Variant **)argp.ptr(), argp.size(), ce); if (ce.error != Variant::CallError::CALL_OK) { r_error_str = vformat(RTR("Invalid arguments to construct '%s'"), Variant::get_type_name(constructor->data_type)); return true; } } break; case Expression::ENode::TYPE_BUILTIN_FUNC: { const Expression::BuiltinFuncNode *bifunc = static_cast<const Expression::BuiltinFuncNode *>(p_node); Vector<Variant> arr; Vector<const Variant *> argp; arr.resize(bifunc->arguments.size()); argp.resize(bifunc->arguments.size()); for (int i = 0; i < bifunc->arguments.size(); i++) { Variant value; bool ret = _execute(p_inputs, p_instance, bifunc->arguments[i], value, r_error_str); if (ret) return true; arr.write[i] = value; argp.write[i] = &arr[i]; } Variant::CallError ce; exec_func(bifunc->func, (const Variant **)argp.ptr(), &r_ret, ce, r_error_str); if (ce.error != Variant::CallError::CALL_OK) { r_error_str = "Builtin Call Failed. " + r_error_str; return true; } } break; case Expression::ENode::TYPE_CALL: { const Expression::CallNode *call = static_cast<const Expression::CallNode *>(p_node); Variant base; bool ret = _execute(p_inputs, p_instance, call->base, base, r_error_str); if (ret) return true; Vector<Variant> arr; Vector<const Variant *> argp; arr.resize(call->arguments.size()); argp.resize(call->arguments.size()); for (int i = 0; i < call->arguments.size(); i++) { Variant value; ret = _execute(p_inputs, p_instance, call->arguments[i], value, r_error_str); if (ret) return true; arr.write[i] = value; argp.write[i] = &arr[i]; } Variant::CallError ce; r_ret = base.call(call->method, (const Variant **)argp.ptr(), argp.size(), ce); if (ce.error != Variant::CallError::CALL_OK) { r_error_str = vformat(RTR("On call to '%s':"), String(call->method)); return true; } } break; } return false; }
/* bll and parent bll */ int pre_exec_new(struct band_list_el *head){ struct band_list_el *bll = head; int id = bll->band_id; switch(id){ case CAPET_NUMB: return exec_capet_numb(bll); case CAPET_CHR: return exec_capet_chr(bll); case CAPET_STR: return exec_capet_str(bll); case CAPET_FLOAT: return exec_capet_float(bll); case CAPET_IDT: return exec_capet_idt(bll); case CAPET_CRG1: return exec_capet_crg1(bll); case CAPET_CRG2: return exec_capet_crg2(bll); case CAPET_STRMEM: return exec_capet_strmem(bll); case CAPET_EXPR: return exec_capet_expr(bll); case INIT_DOVR: return exec_init_dovr(bll); case CHECK_DOVR: return exec_check_dovr(bll); case STEP_DOVR: return exec_step_dovr(bll); case NEQEDERKI2: return exec_neqederki_exp(bll); case NEQ_TOP: return exec_neq_top(bll); case SEC1: return exec_secim(bll); case HAL1: return exec_hal1(bll); case HAL1S: return exec_hal1s(bll); case SUS1: return exec_sus1(bll); case FREE_SEC_DYN_STK: return exec_free_sec_dyn_stk(bll); case EGER_EXP2: return exec_eger_exp(bll); case YOXSA: return exec_yoxsa(bll); case ASGN: return exec_asgn(bll); case NUMB: return exec_numb(bll); case ARTSIN: return exec_artsin(bll); case AZALSIN: return exec_azalsin(bll); case FLOAT: return exec_float(bll); case SHERT: return exec_shert(bll); case CHR: return exec_chr(bll); case EXPR: return exec_expr(bll); case STR_ADRS: return exec_str_adrs(bll); case IDT_ADRS: return exec_idt_adrs(bll); case IDT_VAL: return exec_idt_val(bll); case IDT_OFST: return exec_idt_ofst(bll); case CRG1_ADRS: return exec_crg1_adrs(bll); case CRG1_VAL: return exec_crg1_val(bll); case CRG1_OFST: return exec_crg1_ofst(bll); case CRG2_OFST: return exec_crg2_ofst(bll); case STRMEM_VAL: return exec_strmem_val(bll); case CRG2_ADRS: return exec_crg2_adrs(bll); case CRG2_VAL: return exec_crg2_val(bll); case DAXILET_IDT: return exec_daxilet_idt(bll); case DAVAMET1: return exec_davamet1(bll); case DAYAN1: return exec_dayan1(bll); case FUNK: return exec_func(bll); case FCALL1: return exec_fcall1(bll, NULL); case SNMEM: return exec_snmem(bll); case PUT_RET_ADDR: return exec_put_ret_addr(bll); case POP_OBSTK: return exec_pop_obstk(bll); case FARGS_NUMB: return exec_fargs_numb(bll); case FPARM_IDT_VAL: return exec_fparm_idt_val(bll); case QAYTAR1: return exec_qaytar1(bll); case SON: return exec_son(bll); } return 0; }