static void test_file(const char *filename) { int size, i; char **list_str; char *content, *tmp; struct CMUnitTest *tests; int issue_num, number_of_tests; printf("[+] TARGET: %s\n", filename); content = readfile(filename); counter = 0; failed_setup = 0; function = NULL; if (strstr(filename, "issue")) { number_of_tests = 0; list_lines = split(content, "\n", &size_lines); tests = NULL; for (i = 0; i < size_lines; ++i) { if ((!strncmp(list_lines[i], "// !# issue", 11) && e_flag == 1) || (!strncmp(list_lines[i], "!# issue", 8) && e_flag == 0)) { tests = (struct CMUnitTest *)realloc(tests, sizeof(struct CMUnitTest) * (number_of_tests + 1)); tests[number_of_tests] = (struct CMUnitTest)cmocka_unit_test_setup_teardown(test_issue, setup_issue, teardown_issue); tests[number_of_tests].name = strdup(list_lines[i]); number_of_tests ++; } } _cmocka_run_group_tests("Testing issues", tests, number_of_tests, NULL, NULL); } else { list_lines = split(content, "\n", &size_lines); number_of_tests = 0; tests = NULL; for (i = 1; i < size_lines; ++i) { if ((!strncmp(list_lines[i], "// 0x", 5) && e_flag == 1) || (!strncmp(list_lines[i], "0x", 2) && e_flag == 0)) { tmp = (char *)malloc(sizeof(char) * 100); sprintf(tmp, "Line %d", i+1); tests = (struct CMUnitTest *)realloc(tests, sizeof(struct CMUnitTest) * (number_of_tests + 1)); tests[number_of_tests] = (struct CMUnitTest)cmocka_unit_test_setup_teardown(test_MC, setup_MC, teardown_MC); tests[number_of_tests].name = tmp; number_of_tests ++; } } _cmocka_run_group_tests("Testing MC", tests, number_of_tests, NULL, NULL); } printf("[+] DONE: %s\n", filename); printf("[!] Noted:\n[ ERROR ] --- \"<capstone result>\" != \"<user result>\"\n"); printf("\n\n"); free_strs(list_lines, size_lines); }
// Main function int main(int argc, char const *argv[]) { char input[MAX_LINE]; // input string char **cmd_argv; // parsed arguments int cmd_argc; // arguments number bool cmd_found; // flag to indicate if command is found // Print initial help message cmd_help.execute(1,&(cmd_help.cmd)); update_current_dir(); // Main superloop while(true) { // Read command from input stream printf("[%s]%c ", current_dir, INVITE_CHAR); gets(input); // Parse input stream cmd_argv = parse(input, ARG_SEPARATOR, &cmd_argc); remove_empty_or_whitespace(&cmd_argv, &cmd_argc); if (cmd_argc == 0) continue; // Search for appropriate built-in command and execute it cmd_found = false; for (int i = 0; i < commands_count; ++i) { if (strcmp(cmd_argv[0],commands[i]->cmd) == 0) { cmd_found = true; commands[i]->execute(cmd_argc, cmd_argv); break; } } // Search for appropriate executable file and execute it if (!cmd_found) { if (is_exe_file(cmd_argv[0])) { cmd_found = true; execute_file(cmd_argc, cmd_argv); } } // Error message, if command not found if (!cmd_found) { fprintf(stderr, "Error: \"%s\" command not found!\n", cmd_argv[0]); } // Release resources free_strs(cmd_argv, cmd_argc); } return EXIT_SUCCESS; }
void ConfigFmThs :: SetRxSearchAfThs ( const char *file, UINT fd ) { int index; struct NAME_MAP *found; char **grps = NULL; char **grps_cpy = NULL; keyfile = get_key_file(); ALOGD("%s: file name is: %s\n", __func__, file); if(!parse_load_file(keyfile, file)) { ALOGE("Error in loading threshold file\n"); }else { grps_cpy = grps = get_grps(keyfile); if(grps != NULL) { while(*grps != NULL) { ALOGE("Search grp: %s\n", *grps); found = (NAME_MAP *)bsearch(*grps, GRPS_MAP, MAX_GRPS, sizeof(NAME_MAP), compare_name); if(found != NULL) { ALOGE("Found group: %s\n", found->name); switch(found->num) { case AF_THS: set_af_ths(fd); break; case SRCH_THS: set_srch_ths(fd); break; case HYBRD_SRCH_LIST: set_hybrd_list(fd); break; case BAND_CFG: set_band_cfgs(fd); break; } } grps++; } }else { ALOGE("No of groups found is zero\n"); } free_strs(grps_cpy); } free_key_file(keyfile); keyfile = NULL; }
void ConfigFmThs :: set_af_ths ( UINT fd ) { signed char ret = FM_SUCCESS; char **keys; char **keys_cpy; char *key_value; int value; FmPerformanceParams perf_params; struct NAME_MAP *found; if(keyfile != NULL) { keys_cpy = keys = get_keys(keyfile, GRPS_MAP[0].name); if(keys != NULL) { while(*keys != NULL) { ALOGE("key found is: %s\n", *keys); found = (NAME_MAP *)bsearch(*keys, AF_PARAMS_MAP, MAX_AF_PARAMS, sizeof(NAME_MAP), compare_name); if(found != NULL) { key_value = get_value(keyfile, GRPS_MAP[0].name, found->name); if((key_value != NULL) && strcmp(key_value, "")) { value = atoi(key_value); switch(found->num) { case AF_RMSSI_TH: if((value >= AF_RMSSI_TH_MIN) && (value <= AF_RMSSI_TH_MAX)) { ALOGE("Set af rmssi th: %d\n", value); ret = perf_params.SetAfRmssiTh(fd, value); if(ret == FM_FAILURE) { ALOGE("Error in setting Af Rmssi th\n"); break; } unsigned short th; ret = perf_params.GetAfRmssiTh(fd, th); if(ret == FM_SUCCESS) { ALOGE("Read af rmssith: %hd\n", th); }else { ALOGE("Error in reading Af Rmssi th\n"); } } break; case AF_RMSSI_SAMPLES: if((value >= AF_RMSSI_SAMPLES_MIN) && (value <= AF_RMSSI_SAMPLES_MAX)) { ALOGE("Set af rmssi samples cnt: %d\n", value); ret = perf_params.SetAfRmssiSamplesCnt(fd, value); if(ret == FM_FAILURE) { ALOGE("Error in setting af rmssi samples\n"); break; } unsigned char cnt; ret = perf_params.GetAfRmssiSamplesCnt(fd, cnt); if(ret == FM_SUCCESS) { ALOGE("Read af rmssi samples cnt: %hhd\n", cnt); }else { ALOGE("Error in reading rmssi samples\n"); } } break; case GOOD_CH_RMSSI_TH: if((value >= GOOD_CH_RMSSI_TH_MIN) && (value <= GOOD_CH_RMSSI_TH_MAX)) { ALOGE("Set Good channle rmssi th: %d\n", value); ret = perf_params.SetGoodChannelRmssiTh(fd, value); if(ret == FM_FAILURE) { ALOGE("Error in setting Good channle rmssi th\n"); break; } signed char th; ret = perf_params.GetGoodChannelRmssiTh(fd, th); if(ret == FM_SUCCESS) { ALOGE("Read good channel rmssi th: %d\n", th); }else { ALOGE("Error in reading Good channle rmssi th\n"); } } break; } }else { ALOGE("key_val for key: %s is empty\n", *keys); } free(key_value); } keys++; } }else { ALOGE("No of keys found is zero\n"); } free_strs(keys_cpy); }else { ALOGE("key file is null\n"); } }
void ConfigFmThs :: set_hybrd_list ( UINT fd ) { signed char ret = FM_SUCCESS; char **keys = NULL; char **keys_cpy = NULL; char *key_value = NULL; char *freqs = NULL; unsigned int *freqs_array = NULL; signed char *sinrs_array = NULL; char *sinrs = NULL; int value; unsigned int freq_cnt = 0; unsigned int sinr_cnt = 0; FmPerformanceParams perf_params; struct NAME_MAP *found; ALOGE("Inside hybrid srch list\n"); if(keyfile != NULL) { keys_cpy = keys = get_keys(keyfile, GRPS_MAP[1].name); if(keys != NULL) { while(*keys != NULL) { found = (NAME_MAP *)bsearch(*keys, HYBRD_SRCH_MAP, MAX_HYBRID_SRCH_PARAMS, sizeof(NAME_MAP), compare_name); if(found != NULL) { key_value = get_value(keyfile, GRPS_MAP[1].name, found->name); if((key_value != NULL) && strcmp(key_value, "")) { switch(found->num) { case FREQ_LIST: freqs = key_value; break; case SINR_LIST: sinrs = key_value; break; default: free(key_value); break; } } } keys++; } free_strs(keys_cpy); }else { ALOGE("No of keys found is zero\n"); } }else { ALOGE("key file is null\n"); } freq_cnt = extract_comma_sep_freqs(freqs, &freqs_array, ","); sinr_cnt = extract_comma_sep_sinrs(sinrs, &sinrs_array, ","); if((freq_cnt == sinr_cnt) && (sinr_cnt > 0)) { perf_params.SetHybridSrchList(fd, freqs_array, sinrs_array, freq_cnt); } free(freqs); free(sinrs); free(freqs_array); free(sinrs_array); }
void ConfigFmThs :: set_srch_ths ( UINT fd ) { signed char ret = FM_SUCCESS; char **keys = NULL; char **keys_cpy = NULL; char *key_value = NULL; int value; FmPerformanceParams perf_params; struct NAME_MAP *found = NULL; if(keyfile != NULL) { keys_cpy = keys = get_keys(keyfile, GRPS_MAP[2].name); if(keys != NULL) { while(*keys != NULL) { found = (NAME_MAP *)bsearch(*keys, SEACH_PARAMS_MAP, MAX_SRCH_PARAMS, sizeof(NAME_MAP), compare_name); if(found != NULL) { key_value = get_value(keyfile, GRPS_MAP[2].name, found->name); ALOGE("found srch ths: %s: %s\n", found->name, key_value); if((key_value != NULL) && strcmp(key_value, "")) { value = atoi(key_value); switch(found->num) { case SINR_FIRST_STAGE: if((value >= SINR_FIRST_STAGE_MIN) && (value <= SINR_FIRST_STAGE_MAX)) { ALOGE("Set sinr first stage: %d\n", value); ret = perf_params.SetSinrFirstStage(fd, value); if(ret == FM_FAILURE) { ALOGE("Error in setting sinr first stage\n"); break; } signed char th; ret = perf_params.GetSinrFirstStage(fd, th); if(ret == FM_SUCCESS) { ALOGE("Read sinr first stage: %d\n", th); }else { ALOGE("Error in reading sinr first stage\n"); } } break; case RMSSI_FIRST_STAGE: if((value >= RMSSI_FIRST_STAGE_MIN) && (value <= RMSSI_FIRST_STAGE_MAX)) { ALOGE("Set rmssi first stage: %d\n", value); ret = perf_params.SetRmssiFirstStage(fd, value); if(ret == FM_FAILURE) { ALOGE("Error in setting rmssi first stage\n"); break; } signed char th; ret = perf_params.GetRmssiFirstStage(fd, th); if(ret == FM_SUCCESS) { ALOGE("Read rmssi first stage: %d\n", th); }else { ALOGE("Error in reading rmssi first stage\n"); } } break; case INTF_LOW_TH: if((value >= INTF_LOW_TH_MIN) && (value <= INTF_LOW_TH_MAX)) { ALOGE("Set intf low th: %d\n", value); ret = perf_params.SetIntfLowTh(fd, value); if(ret == FM_FAILURE) { ALOGE("Error in setting intf low th\n"); break; } unsigned char th; ret = perf_params.GetIntfLowTh(fd, th); if(ret == FM_SUCCESS) { ALOGE("Read intf low th: %u\n", th); }else { ALOGE("Error in reading intf low th\n"); } } break; case INTF_HIGH_TH: if((value >= INTF_HIGH_TH_MIN) && (value <= INTF_HIGH_TH_MAX)) { ALOGE("Set intf high th: %d\n", value); ret = perf_params.SetIntfHighTh(fd, value); if(ret == FM_FAILURE) { ALOGE("Error in setting intf high th\n"); break; } unsigned char th; ret = perf_params.GetIntfHighTh(fd, th); if(ret == FM_SUCCESS) { ALOGE("Read intf high th: %u\n", th); }else { ALOGE("Error in reading intf high th\n"); } } break; case CF0_TH: ALOGE("Set cf0 th: %d\n", value); ret = perf_params.SetCf0Th12(fd, value); if(ret == FM_FAILURE) { ALOGE("Error in setting cf0 th\n"); break; } int th; ret = perf_params.GetCf0Th12(fd, th); if(ret == FM_SUCCESS) { ALOGE("Read CF012 th: %d\n", th); }else { ALOGE("Error in reading cf0 th\n"); } break; case SRCH_ALGO_TYPE: if((value >= SRCH_ALGO_TYPE_MIN) && (value <= SRCH_ALGO_TYPE_MAX)) { ALOGE("Set search algo type: %d\n", value); ret = perf_params.SetSrchAlgoType(fd, value); if(ret == FM_FAILURE) { ALOGE("Error in setting search algo type\n"); break; } unsigned char algo; ret = perf_params.GetSrchAlgoType(fd, algo); if(ret == FM_SUCCESS) { ALOGE("Read algo type: %u\n", algo); }else { ALOGE("Error in reading search algo type\n"); } } break; case SINR_SAMPLES: if((value >= SINR_SAMPLES_CNT_MIN) && (value <= SINR_SAMPLES_CNT_MAX)) { ALOGE("Set sinr samples count: %d\n", value); ret = perf_params.SetSinrSamplesCnt(fd, value); if(ret == FM_FAILURE) { ALOGE("Error in setting sinr samples count\n"); break; } unsigned char cnt; ret = perf_params.GetSinrSamplesCnt(fd, cnt); if(ret == FM_SUCCESS) { ALOGE("Read sinr samples cnt: %u\n", cnt); }else { ALOGE("Error in reading sinr samples count\n"); } } break; case SINR: if((value >= SINR_FINAL_STAGE_MIN) && (value <= SINR_FINAL_STAGE_MAX)) { ALOGE("Set final stage sinr: %d\n", value); ret = perf_params.SetSinrFinalStage(fd, value); if(ret == FM_FAILURE) { ALOGE("Error in setting final stage sinr\n"); break; } signed char th; ret = perf_params.GetSinrFinalStage(fd, th); if(ret == FM_SUCCESS) { ALOGE("Read final stage sinr: %d\n", th); }else { ALOGE("Error in reading final stage sinr\n"); } } break; } }else { ALOGE("key_value for key: %s is empty\n", *keys); } free(key_value); } keys++; } }else { ALOGE("No of keys found is zero\n"); } free_strs(keys_cpy); }else { ALOGE("key file is null\n"); } }
static int setup_MC(void **state) { csh *handle; char **list_params; int size_params; int arch, mode; int i, index, tmp_counter; if (failed_setup) { fprintf(stderr, "[ ERROR ] --- Invalid file to setup\n"); return -1; } tmp_counter = 0; while (tmp_counter < size_lines && list_lines[tmp_counter][0] != '#') tmp_counter++; list_params = split(list_lines[tmp_counter] + 2, ", ", &size_params); if (size_params != 3) { fprintf(stderr, "[ ERROR ] --- Invalid options ( arch, mode, option )\n"); failed_setup = 1; return -1; } arch = get_value(arches, NUMARCH, list_params[0]); if (!strcmp(list_params[0], "CS_ARCH_ARM64")) mc_mode = 2; else mc_mode = 1; mode = 0; for (i = 0; i < NUMMODE; ++i) { if (strstr(list_params[1], modes[i].str)) { mode += modes[i].value; switch (modes[i].value) { case CS_MODE_16: mc_mode = 0; break; case CS_MODE_64: mc_mode = 2; break; case CS_MODE_THUMB: mc_mode = 1; break; default: break; } } } if (arch == -1) { fprintf(stderr, "[ ERROR ] --- Arch is not supported!\n"); failed_setup = 1; return -1; } handle = (csh *)malloc(sizeof(csh)); if(cs_open(arch, mode, handle) != CS_ERR_OK) { fprintf(stderr, "[ ERROR ] --- Cannot initialize capstone\n"); failed_setup = 1; return -1; } for (i = 0; i < NUMOPTION; ++i) { if (strstr(list_params[2], options[i].str)) { if (cs_option(*handle, options[i].first_value, options[i].second_value) != CS_ERR_OK) { fprintf(stderr, "[ ERROR ] --- Option is not supported for this arch/mode\n"); failed_setup = 1; return -1; } } } *state = (void *)handle; counter++; if (e_flag == 0) while (counter < size_lines && strncmp(list_lines[counter], "0x", 2)) counter++; else while (counter < size_lines && strncmp(list_lines[counter], "// 0x", 5)) counter++; free_strs(list_params, size_params); return 0; }
static int setup_issue(void **state) { csh *handle; char **list_params; int size_params; int arch, mode; int i, index, result; char *(*function)(csh *, cs_mode, cs_insn*); getDetail = 0; failed_setup = 0; if (e_flag == 0) while (counter < size_lines && strncmp(list_lines[counter], "!# ", 3)) counter++; // get issue line else while (counter < size_lines && strncmp(list_lines[counter], "// !# ", 6)) counter++; counter++; if (e_flag == 0) while (counter < size_lines && strncmp(list_lines[counter], "!#", 2)) counter++; // get arch line else while (counter < size_lines && strncmp(list_lines[counter], "// !# ", 6)) counter++; if (e_flag == 0) list_params = split(list_lines[counter] + 3, ", ", &size_params); else list_params = split(list_lines[counter] + 6, ", ", &size_params); arch = get_value(arches, NUMARCH, list_params[0]); if (!strcmp(list_params[0], "CS_ARCH_ARM64")) mc_mode = 2; else mc_mode = 1; mode = 0; for (i = 0; i < NUMMODE; ++i) { if (strstr(list_params[1], modes[i].str)) { mode += modes[i].value; switch (modes[i].value) { case CS_MODE_16: mc_mode = 0; break; case CS_MODE_64: mc_mode = 2; break; case CS_MODE_THUMB: mc_mode = 1; break; default: break; } } } if (arch == -1) { fprintf(stderr, "[ ERROR ] --- Arch is not supported!\n"); failed_setup = 1; return -1; } handle = (csh *)calloc(1, sizeof(csh)); if(cs_open(arch, mode, handle) != CS_ERR_OK) { fprintf(stderr, "[ ERROR ] --- Cannot initialize capstone\n"); failed_setup = 1; return -1; } for (i = 0; i < NUMOPTION; ++i) { if (strstr(list_params[2], options[i].str)) { if (cs_option(*handle, options[i].first_value, options[i].second_value) != CS_ERR_OK) { fprintf(stderr, "[ ERROR ] --- Option is not supported for this arch/mode\n"); failed_setup = 1; return -1; } if (i == 0) { result = set_function(arch); if (result == -1) { fprintf(stderr, "[ ERROR ] --- Cannot get details\n"); failed_setup = 1; return -1; } getDetail = 1; } } } *state = (void *)handle; issue_mode = mode; if (e_flag == 0) while (counter < size_lines && strncmp(list_lines[counter], "0x", 2)) counter++; else while (counter < size_lines && strncmp(list_lines[counter], "// 0x", 5)) counter++; free_strs(list_params, size_params); return 0; }
void ConfigFmThs :: set_band_cfgs ( UINT fd ) { signed char ret = FM_SUCCESS; char **keys; char **keys_cpy; char *key_value; int value; FmPerformanceParams perf_params; struct NAME_MAP *found; if(keyfile != NULL) { keys_cpy = keys = get_keys(keyfile, GRPS_MAP[1].name); if(keys != NULL) { while(*keys != NULL) { ALOGE("key found is: %s\n", *keys); found = (NAME_MAP *)bsearch(*keys, BAND_CFG_MAP, MAX_BAND_PARAMS, sizeof(NAME_MAP), compare_name); if(found != NULL) { key_value = get_value(keyfile, GRPS_MAP[1].name, found->name); if((key_value != NULL) && strcmp(key_value, "")) { value = atoi(key_value); switch(found->num) { case RADIO_BAND: ALOGE("RADIO_BAND\n"); if((value >= BAND_87500_108000) && (value <= BAND_76000_90000)) { ALOGE("%s:Set band as: %d\n",__func__, value); ret = perf_params.SetBand(fd, value); if(ret == FM_FAILURE) ALOGE("Error in setting band\n"); } break; case EMPHASIS: ALOGE("EMPHASIS\n"); if((value >= DE_EMP75) && (value <= DE_EMP50)) { ALOGE("%s:Set Emphasis as: %d\n",__func__, value); ret = perf_params.SetEmphsis(fd, value); if(ret == FM_FAILURE) ALOGE("Error in setting Emphasis\n"); } break; case CHANNEL_SPACING: ALOGE("CHANNEL_SPACING\n"); if((value >= CHAN_SPACE_200) && (value <= CHAN_SPACE_50)) { ALOGE("%s:Set CH space as: %d\n",__func__, value); ret = perf_params.SetChannelSpacing(fd, value); if(ret == FM_FAILURE) ALOGE("Error in setting channel spacing\n"); } break; } }else { ALOGE("key_val for key: %s is empty\n", *keys); } free(key_value); } keys++; } }else { ALOGE("No of keys found is zero\n"); } free_strs(keys_cpy); }else { ALOGE("key file is null\n"); } }