static i32 parse_adapt_result (struct app_options *opt, list<CfgEntry> *cfg, char *buf, ssize_t buf_len, vector<string> *lines) { char *end = buf, *start = buf; ssize_t size; i32 lnr = -1; u32 i, num_obj = 0; string *obj_name = NULL; u32 malloc_size = 0; ptr_t code_addr = 0; list<CfgEntry>::iterator it; DynMemEntry *tmp = NULL; bool found; end = strchr(start, ';'); if (end == NULL) goto parse_err; if (sscanf(start, "%u", &num_obj) != 1) goto parse_err; size = end - start; start += size + 1; for (i = 1; i <= num_obj; i++) { // get object name or reserved cfg entry for (;;) { if (parse_adp_string(&start, &obj_name)) goto parse_err; if (*obj_name == "proc_name") { lnr = 0; } else if (*obj_name == "game_binpath") { lnr = opt->binpath_line; if (lnr <= 0) { if (parse_adp_string(&start, &obj_name)) goto parse_err; lnr = -1; continue; } } if (lnr >= 0) { if (parse_adp_string(&start, &obj_name)) goto parse_err; if (lnr == 0) { if (strcmp(opt->game_call, opt->proc_name) == 0) opt->game_call = to_c_str(obj_name); opt->proc_name = to_c_str(obj_name); } else if ((u32) lnr == opt->binpath_line) { *obj_name = "game_binpath " + *obj_name; opt->game_binpath = to_c_str(obj_name); if (strcmp(basename(opt->game_binpath), opt->proc_name) != 0) goto parse_err; } lines->at(lnr) = *obj_name; lnr = -1; continue; } break; } if (sscanf(start, "%x", &malloc_size) != 1) goto parse_err; end = strchr(start, ';'); if (end == NULL) goto parse_err; size = end - start; start += size + 1; if (sscanf(start, SCN_PTR, &code_addr) != 1) goto parse_err; // find object and set adp_size and adp_addr found = false; list_for_each (cfg, it) { tmp = it->dynmem; if (tmp && !tmp->adp_addr && tmp->name == *obj_name) { tmp->adp_size = malloc_size; tmp->adp_addr = code_addr; cout << "Class " << tmp->name << ", old_size: " << tmp->mem_size << ", new_size: " << tmp->adp_size << endl; cout << "Class " << tmp->name << ", old_code: 0x" << hex << tmp->code_addr << ", new_code: 0x" << tmp->adp_addr << dec << endl; found = true; break; } } if (!found) goto parse_err; if (i == num_obj) break; end = strchr(start, ';'); if (end == NULL) goto parse_err; size = end - start; start += size + 1; }
static i32 parse_adapt_result (Options *opt, char *buf, ssize_t buf_len, vector<string> *cfg_lines) { list<CfgEntry> *cfg = opt->cfg; char *end = buf, *start = buf; ssize_t size; i32 lnr = -1; // -1: object name, >= 0: reserved cfg entry u32 i, num_obj = 0; char *obj_name = NULL; u32 malloc_size = 0; ptr_t code_addr = 0; list<CfgEntry>::iterator it; DynMemEntry *tmp = NULL; bool found; end = strchr(start, ';'); if (end == NULL) goto parse_err; if (sscanf(start, "%u", &num_obj) != 1) goto parse_err; size = end - start; start += size + 1; for (i = 1; i <= num_obj; i++) { // get object name or reserved cfg entry for (;;) { if (parse_adp_string(&start, &obj_name)) goto parse_err; if (!strncmp(obj_name, "proc_name", sizeof("proc_name") - 1)) { lnr = 0; } else if (!strncmp(obj_name, "game_binpath", sizeof("game_binpath") - 1)) { lnr = opt->binpath_line; // Not configured? if (lnr <= 0) { // ignore the game binpath argument if (parse_adp_string(&start, &obj_name)) goto parse_err; lnr = -1; continue; } } // Reserved cfg entry read? if (lnr >= 0) { string tmp_line; // read parameter if (parse_adp_string(&start, &obj_name)) goto parse_err; if (lnr == 0) { tmp_line = string(obj_name); if (*opt->game_call == *opt->proc_name) { *opt->proc_name = tmp_line; *opt->game_call = tmp_line; } else { *opt->proc_name = tmp_line; } } else if ((u32) lnr == opt->binpath_line) { tmp_line = string(obj_name); *opt->game_binpath = tmp_line; if (cppbasename(opt->game_binpath) != *opt->proc_name) goto parse_err; tmp_line = "game_binpath " + string(obj_name); } cfg_lines->at(lnr) = tmp_line; lnr = -1; continue; } break; } if (sscanf(start, "%x", &malloc_size) != 1) goto parse_err; end = strchr(start, ';'); if (end == NULL) goto parse_err; size = end - start; start += size + 1; if (sscanf(start, SCN_PTR, &code_addr) != 1) goto parse_err; // find object and set adp_size and adp_addr found = false; list_for_each (cfg, it) { tmp = it->dynmem; if (tmp && !tmp->adp_addr && tmp->name == string(obj_name)) { tmp->adp_size = malloc_size; tmp->adp_addr = code_addr; ugout << "Class " << tmp->name << ", old_size: " << tmp->mem_size << ", new_size: " << tmp->adp_size << endl; ugout << "Class " << tmp->name << ", old_code: 0x" << hex << tmp->code_addr << ", new_code: 0x" << tmp->adp_addr << dec << endl; found = true; break; } } if (!found) goto parse_err; if (i == num_obj) break; end = strchr(start, ';'); if (end == NULL) goto parse_err; size = end - start; start += size + 1; }