static void db_add_field_column(struct db_field *f, struct db_collection *c) { char str_query[512]={0}, *emsg; snprintf(str_query, 512, "ALTER TABLE %s ADD COLUMN %s varchar(%d)", c->name, f->name, DEFAULT_FIELD_SIZE); if (sqlite3_exec(__db, str_query, NULL, 0, &emsg) != SQLITE_OK) { display_msg(GTK_MESSAGE_ERROR, gettext("Error"), "%s", emsg); sqlite3_free(emsg); return; } snprintf(str_query, 512, "INSERT INTO collection_fields (cat_id, name, " "field_size, screen_name, status) VALUES " "(%d, \"%s\", %d, \"%s\", %d)", c->id, f->name, DEFAULT_FIELD_SIZE, f->screen_name, FIELD_ACTIVE); if (sqlite3_exec(__db, str_query, NULL, 0, &emsg) != SQLITE_OK) { display_msg(GTK_MESSAGE_ERROR, gettext("Error"), "%s", emsg); sqlite3_free(emsg); return; } }
int main(int argc, char *argv[]){ input_parameters_t *in_para; in_para = (input_parameters_t *)malloc(sizeof(input_parameters_t)); display_msg("Reading the configure file \n"); load_parameters_from_file(in_para,argv[1]); char *crossover_file_name = NULL; int ind, ind_ref_1, ind_ref_2, cros_choose; //Setting crossover file name crossover_file_name = Malloc(char, MAX_FILE_NAME); strcpy(crossover_file_name, "pop_crossover.pdb"); primary_seq_t *primary_sequence; // Primary Sequence of Protein protein_t *population_p; // main population protein_t *new_population; // main population //Loading Fasta file primary_sequence = _load_amino_seq(in_para->seq_protein_file_name); //Allocating PDB ATOMS of population_p population_p = allocateProtein(&in_para->size_population); new_population = allocateProtein(&in_para->size_population); //Loading initial population and allocating atom and topology load_initial_population_file(population_p, &in_para->size_population, in_para->path_local_execute,in_para->initial_pop_file_name, primary_sequence); //Only to initialize new_population load_initial_population_file(new_population, &in_para->size_population, in_para->path_local_execute,in_para->initial_pop_file_name, primary_sequence); initialize_protein_population_atoms(new_population, &in_para->size_population); //Checking what crossover will be applied cros_choose = 0; while ( (cros_choose <= 0) || (cros_choose > MAX_CROS)){ printf ("Enter type of crossover 1 - 1-Point "); scanf ("%d",&cros_choose); } for (ind = 0; ind < in_para->size_population; ind++){ ind_ref_1 = 0; ind_ref_2 = 1; if (cros_choose == 1){ crossover_one_point(&new_population[ind], &population_p[ind_ref_1], &population_p[ind_ref_2]); } } save_population_file(new_population, in_para->path_local_execute, crossover_file_name, &in_para->size_population); deAllocateload_parameters(in_para); display_msg("Done 2PG Crossover \n"); return 0; }
std::string RecoveryInstaller::get_install_type() { if (_prop.find("mbtool.installer.install-location") != _prop.end()) { std::string location = _prop["mbtool.installer.install-location"]; display_msg("Installing to " + location); return location; } else { display_msg("Installation location not specified"); return CANCELLED; } }
int main(int argc, char *argv[]) { input_parameters_t in_param; display_msg("Reading the configure file \n"); load_parameters_from_file(&in_param,argv[1]); build_initial_population(&in_param); deAllocateload_parameters(&in_param); display_msg("Done Build Initial Population !!! \n"); return 0; }
static int db_create_collection_table(struct db_collection *c) { char *emsg; GString *s; GList *l; struct db_field *f; s = g_string_new(NULL); g_string_printf(s, "CREATE TABLE %s (" "id integer primary key autoincrement, " "c_image varchar(256) default default_image_xpm", c->name); for (l = g_list_first(c->fields); l; l = l->next) { f = (struct db_field *)l->data; g_string_append_printf(s, ", %s varchar(%d)", f->name, DEFAULT_FIELD_SIZE); } g_string_append_printf(s, ")"); if (sqlite3_exec(__db, s->str, NULL, 0, &emsg) != SQLITE_OK) { display_msg(GTK_MESSAGE_ERROR, gettext(gettext("Error")), "%s", emsg); sqlite3_free(emsg); return -1; } g_string_free(s, TRUE); return 0; }
void RomInstaller::on_cleanup(Installer::ProceedState ret) { (void) ret; // Fix permissions on log file if (chmod(log_file, 0664) < 0) { LOGE("%s: Failed to chmod: %s", log_file, strerror(errno)); } if (!util::chown(log_file, "media_rw", "media_rw", 0)) { LOGE("%s: Failed to chown: %s", log_file, strerror(errno)); if (chown(log_file, 1023, 1023) < 0) { LOGE("%s: Failed to chown: %s", log_file, strerror(errno)); } } std::string context; if (util::selinux_lget_context("/data/media/0", &context) && !util::selinux_lset_context(log_file, context)) { LOGE("%s: Failed to set context to %s: %s", log_file, context.c_str(), strerror(errno)); } display_msg("The log file was saved as MultiBoot.log on the " "internal storage."); }
void db_create_collection(struct db_collection *c, int gtk_status) { char str_query[256]={0}, *emsg; int collection_id; if (db_create_collection_table(c) < 0) return; /* Insert the new collection entry */ snprintf(str_query, 256, "INSERT INTO tab_collection (name, screen_name) " "VALUES (\"%s\", \"%s\")", c->name, c->screen_name); if (sqlite3_exec(__db, str_query, NULL, 0, &emsg) != SQLITE_OK) { if (gtk_status == TRUE) display_msg(GTK_MESSAGE_ERROR, gettext("Error"), "%s", emsg); else fprintf(stderr, "Error: %s\n", emsg); sqlite3_free(emsg); return; } collection_id = db_get_collection_id(c->name); /* Insert fields from the new collection */ g_list_foreach(c->fields, (GFunc)__insert_field, &collection_id); create_collection_image_dir(collection_id); c->image_path = get_db_collection_image_path(collection_id); }
void RomInstaller::on_cleanup(Installer::ProceedState ret) { (void) ret; display_msg("The log file was saved as MultiBoot.log on the " "internal storage."); }
void RecoveryInstaller::on_cleanup(Installer::ProceedState ret) { static const char *log_file = "/data/media/0/MultiBoot.log"; if (ret == ProceedState::Fail) { if (!util::copy_file("/tmp/recovery.log", log_file, 0)) { LOGE("Failed to copy log file: %s", strerror(errno)); } if (chmod(log_file, 0664) < 0) { LOGE("%s: Failed to chmod: %s", log_file, strerror(errno)); } if (!util::chown(log_file, "media_rw", "media_rw", 0)) { LOGE("%s: Failed to chown: %s", log_file, strerror(errno)); if (chown(log_file, 1023, 1023) < 0) { LOGE("%s: Failed to chown: %s", log_file, strerror(errno)); } } std::string context; if (util::selinux_lget_context("/data/media/0", &context) && !util::selinux_lset_context(log_file, context)) { LOGE("%s: Failed to set context to %s: %s", log_file, context.c_str(), strerror(errno)); } display_msg("The log file was saved as MultiBoot.log on the " "internal storage."); } }
int main(int argc, char *argv[]){ input_parameters_t in_param; display_msg("Reading the configure file \n"); load_parameters_from_file(&in_param,argv[1]); if (in_param.number_fitness == 1){ ea_mono(&in_param); }else{ fatal_error("In mono-objective, NumberObjective option must be 1. Please, check it. \n"); } deAllocateload_parameters(&in_param); display_msg("Done EA Mono !!! \n"); return 0; }
/*============================================================================= Function : kfront_write Description : Input : Output : Return : =============================================================================*/ static ssize_t kfront_write(struct file *filp, const char __user *buff, size_t len, loff_t *off) { char *kbuf; dprintk("%s > (len %d, offs %d)\n", __func__, len, (int) *off); kbuf = kmalloc(len + 1, GFP_KERNEL); if (kbuf == NULL) { printk("FP: no free memory\n"); return -ENOMEM; } copy_from_user(kbuf, buff, len); kbuf[len] = '\0'; if (down_interruptible(&sem_lock)) return -ERESTARTSYS; display_msg(kbuf); kfree(kbuf); up(&sem_lock); return len; }
Installer::ProceedState RomInstaller::on_pre_install() { if (is_aroma(_temp + "/updater")) { display_msg("ZIP files using the AROMA installer can only be flashed " "from recovery"); return ProceedState::Cancel; } char *ld_library_path = getenv("LD_LIBRARY_PATH"); if (ld_library_path) { _ld_library_path = ld_library_path; } char *ld_preload = getenv("LD_PRELOAD"); if (ld_preload) { _ld_preload = ld_preload; } if (setenv("LD_LIBRARY_PATH", "/sbin", 1) < 0) { LOGE("Failed to set LD_LIBRARY_PATH: %s", strerror(errno)); return ProceedState::Fail; } if (unsetenv("LD_PRELOAD") < 0) { LOGE("Failed to unset LD_PRELOAD: %s", strerror(errno)); return ProceedState::Fail; } return ProceedState::Continue; }
static int dlg_add_entry(struct dlg_data *dlg_data, GtkWidget **textbox) { struct dlg_line *line; const char *s; int i; GtkTreeIter iter; gtk_list_store_append(GTK_LIST_STORE(dlg_data->priv.model), &iter); line = create_dlg_line(LINE_ADDED); if (!line) { display_msg(GTK_MESSAGE_ERROR, gettext("Error"), gettext("Error creating structure for new line!")); return 0; } for (i = 0; i < dlg_data->c->active_fields; i++) { s = gtk_entry_get_text(GTK_ENTRY(textbox[i])); gtk_list_store_set(GTK_LIST_STORE(dlg_data->priv.model), &iter, i, s, -1); line->column = g_list_append(line->column, strdup(s)); } if (dlg_data->priv.bt_img_filename != NULL) line->img_filename = strdup(dlg_data->priv.bt_img_filename); else line->img_filename = strdup("default_image_xpm"); g_array_append_vals(dlg_data->priv.data, line, 1); return 1; }
static void report_finish(void) { int i; beep_on(); if (g_timeout) { display_msg("----"); g_rf.tx.err |= err_timeout; g_rf.tx.finish.time = 0; } else g_rf.tx.finish.time = wc_get_time(&g_wc); display_hex(g_rf.tx.finish.time); for (i = REPEAT_MSGS; i; --i) { rfb_send_msg(&g_rf, pkt_finish); wc_delay(&g_wc, REPEAT_MSGS_DELAY); } beep_off(); if (P2IN & XSTATUS) { uart_send_time_hex(g_rf.tx.finish.time); } }
int db_delete_collection(const char *name) { char str_query[256]={0}, *emsg; int collection_id; collection_id = db_get_collection_id(name); if (collection_id <= 0) { display_msg(GTK_MESSAGE_ERROR, gettext("Error"), gettext("Collection '%s' not found!"), name); return 0; } snprintf(str_query, 256, "DELETE FROM tab_collection WHERE id = %d", collection_id); if (sqlite3_exec(__db, str_query, NULL, 0, &emsg) != SQLITE_OK) { display_msg(GTK_MESSAGE_ERROR, gettext("Error"), "%s", emsg); sqlite3_free(emsg); return 0; } snprintf(str_query, 256, "DELETE FROM collection_fields WHERE cat_id = %d", collection_id); if (sqlite3_exec(__db, str_query, NULL, 0, &emsg) != SQLITE_OK) { display_msg(GTK_MESSAGE_ERROR, gettext("Error"), "%s", emsg); sqlite3_free(emsg); return 0; } snprintf(str_query, 256, "DROP TABLE IF EXISTS %s", name); if (sqlite3_exec(__db, str_query, NULL, 0, &emsg) != SQLITE_OK) { display_msg(GTK_MESSAGE_ERROR, gettext("Error"), "%s", emsg); sqlite3_free(emsg); return 0; } remove_collection_dir(collection_id); return 1; }
/*============================================================================= Function : kfront_thread Description : Input : Output : Return : =============================================================================*/ static int kfront_thread(void *__us) { struct kfront_tag *us = (struct kfront_tag *)__us; int pulse = 0; display_msg("----"); while (!us->bQuit) { scan_key(); msleep(LOOP_DELAY); #ifdef REPEAT_KEY_SUPPORT cur_loop_count++; #endif if (kfront_mode) // run { if (kfront_display_mode == 1) full(0x00); else if (kfront_display_mode == 2) full(0xff); else { } } else // standby { /* display time pulse */ pulse++; if (pulse >= (500 / LOOP_DELAY)) { toggle_time_pulse(); pulse = 0; } } /* display new string */ if (display_flag) { display_msg(display_data); display_flag = 0; } } }
void display_bold_communication(char *s) { char *p; char ch; char temp[MAXSIZ]; if(strchr(s, '>')) { p = strchr(s, '>'); ch = *p; --p; *p = '\0'; sprintf(temp, "%c%s%c %c%s", BOLDCHAR, s, BOLDCHAR, ch, p + 2); display_msg(temp); } else if(strchr(s, ':')) { p = strchr(s, ':'); ch = *p; --p; *p = '\0'; sprintf(temp, "%c%s%c %c%s", BOLDCHAR, s, BOLDCHAR, ch, p + 2); display_msg(temp); } else if(strchr(s, '=')) { p = strchr(s, '='); ch = *p; --p; *p = '\0'; sprintf(temp, "%c%s%c %c%s", BOLDCHAR, s, BOLDCHAR, ch, p + 2); display_msg(temp); } else if(strchr(s, '!')) { p = strchr(s, '!'); ch = *p; --p; *p = '\0'; sprintf(temp, "%c%s%c %c%s", BOLDCHAR, s, BOLDCHAR, ch, p + 2); display_msg(temp); } else { display_msg(s); } }
void RecoveryInstaller::on_cleanup(Installer::ProceedState ret) { if (ret == ProceedState::Fail) { if (!util::copy_file("/tmp/recovery.log", MULTIBOOT_LOG_INSTALLER, 0)) { LOGE("Failed to copy log file: %s", strerror(errno)); } fix_multiboot_permissions(); display_msg("The log file was saved as MultiBoot.log on the " "internal storage."); } }
static void db_update_field_status(struct db_field *f, struct db_collection *c) { char str_query[512]={0}, *emsg; snprintf(str_query, 512, "UPDATE collection_fields SET status = %d WHERE " "cat_id = %d AND name = \"%s\"", !f->status, c->id, f->name); if (sqlite3_exec(__db, str_query, NULL, 0, &emsg) != SQLITE_OK) { display_msg(GTK_MESSAGE_ERROR, gettext("Error"), "%s", emsg); sqlite3_free(emsg); return; } }
static void __insert_field(struct db_field *f, int *collection_id) { char str_query[256]={0}, *emsg; memset(str_query, 0, sizeof(str_query)); snprintf(str_query, 256, "INSERT INTO collection_fields (cat_id, name, " "field_size, screen_name, status) VALUES " "(%d, \"%s\", %d, \"%s\", %d)", *collection_id, f->name, DEFAULT_FIELD_SIZE, f->screen_name, f->status); if (sqlite3_exec(__db, str_query, NULL, 0, &emsg) != SQLITE_OK) { display_msg(GTK_MESSAGE_ERROR, gettext("Error"), "%s", emsg); sqlite3_free(emsg); return; } }
Installer::ProceedState RecoveryInstaller::on_initialize() { struct stat sb; if (stat("/sys/fs/selinux", &sb) == 0) { if (!patch_sepolicy()) { LOGE("Failed to patch sepolicy. Trying to disable SELinux"); int fd = open(SELINUX_ENFORCE_FILE, O_WRONLY); if (fd >= 0) { write(fd, "0", 1); close(fd); } else { LOGE("Failed to set SELinux to permissive mode"); display_msg("Could not patch or disable SELinux"); } } } return ProceedState::Continue; }
// Setup working channel static void setup_channel(void) { int r; set_state(st_setup); // Select control channel rf_set_channel(CTL_CHANNEL); // Wait setup message r = rfb_receive_msg(&g_rf, pkt_setup); if (r) { // Show error message rfb_err_msg(r); // Reset itself wc_delay(&g_wc, SHORT_DELAY_TICKS); reset(); } else { // Show channel number display_msg("Ch"); display_set_dp(1); display_hex_(g_rf.rx.p.setup.chan, 2, 2); } beep_on(); // Set working channel rf_set_channel(g_rf.rx.p.setup.chan); // Delay to allow sender to switch to RX wc_delay(&g_wc, SETUP_RESP_DELAY); // Send test message g_rf.tx.setup_resp.li = g_rf.rx.li; rfb_send_msg(&g_rf, pkt_setup_resp); beep_off(); // Reset itself on error or in test mode if (r || (g_rf.rx.p.setup.flags & SETUP_F_TEST)) reset(); }
int main(int argc, char *argv[]){ input_parameters_t in_param; char *path_file_name; path_file_name = Malloc(char, MAX_PATH_FILE_NAME); strcpy(path_file_name, argv[1]); solutions = loading_file_solutions(&num_solutions, &num_obj, path_file_name); dominance = allocate_dominance(&num_solutions); set_dominance(dominance, solutions, &num_solutions); show_dominance(dominance, &num_solutions); save_dominance(dominance, &num_solutions); desallocate_dominance(dominance, &num_solutions); desallocate_solution(solutions, &num_solutions); free(path_file_name); display_msg("Done Dominance !!! \n"); return 0; }
/* * get_set_creds() * * do a krb5 login to get and set krb5 creds (needed after a pw change * on pw expire on login) */ static void get_set_creds( pam_handle_t *pamh, krb5_module_data_t *kmd, char *user, char *newpass, int debug) { int login_result; if (!kmd || kmd->age_status != PAM_NEW_AUTHTOK_REQD) return; /* * if pw has expired, get/set krb5 creds ala auth mod * * pwchange verified user sufficiently, so don't request strict * tgt verification (will cause rcache perm issues possibly anyways) */ login_result = attempt_krb5_auth(pamh, kmd, user, &newpass, 0); if (debug) syslog(LOG_DEBUG, "PAM-KRB5 (password): get_set_creds: login_result= %d", login_result); /* * the krb5 login should not fail, but if so, * warn the user they have to kinit(1) */ if (login_result != PAM_SUCCESS) { display_msg(pamh, PAM_TEXT_INFO, dgettext(TEXT_DOMAIN, "Warning: " "Could not cache Kerberos" " credentials, please run " "kinit(1) or re-login\n")); } set_ccname(pamh, kmd, login_result, debug); }
static int db_get_collection_id(const char *name) { int id=0; char str_query[256]={0}; sqlite3_stmt *stmt; snprintf(str_query, 256, "SELECT id FROM tab_collection WHERE name = '%s'", name); if (sqlite3_prepare_v2(__db, str_query, -1, &stmt, NULL) != SQLITE_OK) { display_msg(GTK_MESSAGE_ERROR, gettext(gettext("Error")), gettext("Error searching the '%s' collection id"), name); return -1; } while (sqlite3_step(stmt) == SQLITE_ROW) id = strtol((char *)sqlite3_column_text(stmt, 0), NULL, 10); sqlite3_finalize(stmt); return id; }
void msg(char *fmt, ...) { va_list vargs; char buf[MAXSIZ]; char *p; if(!GET_BIT(options, DISPLAYING) || paused) { return; } va_start(vargs, fmt); vsprintf(buf, fmt, vargs); va_end(vargs); if(!action_match_suppress) { p = buf; /* So '-- A' and 'A' don't match twice */ if(!strncmp(buf, "-- ", 3)) { p += 3; } if(handle_action_matches(p)) { return; } } if(kill_client_output) { if(logfile.redirect && logfile.on) { fprintf(logfile.fd, "%s\n", buf); } return; } display_msg(buf); }
Installer::ProceedState RomInstaller::on_checked_device() { // /sbin is not going to be populated with anything useful in a normal boot // image. We can almost guarantee that a recovery image is going to be // installed though, so we'll open the recovery partition with libmbp and // extract its /sbin with libarchive into the chroot's /sbin. std::string block_dev(_recovery_block_dev); mbp::BootImage bi; mbp::CpioFile innerCpio; const unsigned char *ramdisk_data; std::size_t ramdisk_size; bool using_boot = false; // Check if the device has a combined boot/recovery partition. If the // FOTAKernel partition is listed, it will be used instead of the combined // ramdisk from the boot image bool combined = mb_device_flags(_device) & FLAG_HAS_COMBINED_BOOT_AND_RECOVERY; if (combined && block_dev.empty()) { block_dev = _boot_block_dev; using_boot = true; } if (block_dev.empty()) { display_msg("Could not determine the recovery block device"); return ProceedState::Fail; } if (!bi.loadFile(block_dev)) { display_msg("Failed to load recovery partition image"); return ProceedState::Fail; } // Load ramdisk bi.ramdiskImageC(&ramdisk_data, &ramdisk_size); if (using_boot) { if (!innerCpio.load(ramdisk_data, ramdisk_size)) { display_msg("Failed to load ramdisk from combined boot image"); return ProceedState::Fail; } if (!innerCpio.contentsC("sbin/ramdisk-recovery.cpio", &ramdisk_data, &ramdisk_size)) { display_msg("Could not find recovery ramdisk in combined boot image"); return ProceedState::Fail; } } autoclose::archive in(archive_read_new(), archive_read_free); autoclose::archive out(archive_write_disk_new(), archive_write_free); if (!in || !out) { LOGE("Out of memory"); return ProceedState::Fail; } archive_entry *entry; // Set up input archive_read_support_filter_gzip(in.get()); archive_read_support_filter_lzop(in.get()); archive_read_support_filter_lz4(in.get()); archive_read_support_filter_lzma(in.get()); archive_read_support_filter_xz(in.get()); archive_read_support_format_cpio(in.get()); int ret = archive_read_open_memory(in.get(), const_cast<unsigned char *>(ramdisk_data), ramdisk_size); if (ret != ARCHIVE_OK) { LOGW("Failed to open recovery ramdisk: %s", archive_error_string(in.get())); return ProceedState::Fail; } // Set up output archive_write_disk_set_options(out.get(), ARCHIVE_EXTRACT_ACL | ARCHIVE_EXTRACT_FFLAGS | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_SECURE_NODOTDOT | ARCHIVE_EXTRACT_SECURE_SYMLINKS | ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_UNLINK | ARCHIVE_EXTRACT_XATTR); while ((ret = archive_read_next_header(in.get(), &entry)) == ARCHIVE_OK) { std::string path = archive_entry_pathname(entry); if (path == "default.prop") { path = "default.recovery.prop"; } else if (!util::starts_with(path, "sbin/")) { continue; } LOGE("Copying from recovery: %s", path.c_str()); archive_entry_set_pathname(entry, in_chroot(path).c_str()); if (util::libarchive_copy_header_and_data( in.get(), out.get(), entry) != ARCHIVE_OK) { return ProceedState::Fail; } archive_entry_set_pathname(entry, path.c_str()); } if (ret != ARCHIVE_EOF) { LOGE("Archive extraction ended without reaching EOF: %s", archive_error_string(in.get())); return ProceedState::Fail; } // Create fake /etc/fstab file to please installers that read the file std::string etc_fstab(in_chroot("/etc/fstab")); if (access(etc_fstab.c_str(), R_OK) < 0 && errno == ENOENT) { autoclose::file fp(autoclose::fopen(etc_fstab.c_str(), "w")); if (fp) { auto system_devs = mb_device_system_block_devs(_device); auto cache_devs = mb_device_cache_block_devs(_device); auto data_devs = mb_device_data_block_devs(_device); // Set block device if it's provided and non-empty const char *system_dev = system_devs && system_devs[0] && system_devs[0][0] ? system_devs[0] : "dummy"; const char *cache_dev = cache_devs && cache_devs[0] && cache_devs[0][0] ? cache_devs[0] : "dummy"; const char *data_dev = data_devs && data_devs[0] && data_devs[0][0] ? data_devs[0] : "dummy"; fprintf(fp.get(), "%s /system ext4 rw 0 0\n", system_dev); fprintf(fp.get(), "%s /cache ext4 rw 0 0\n", cache_dev); fprintf(fp.get(), "%s /data ext4 rw 0 0\n", data_dev); } } // Load recovery properties util::file_get_all_properties( in_chroot("/default.recovery.prop"), &_recovery_props); return ProceedState::Continue; }
void deAllocateProteinArray(protein* prot,const int *size){ free(prot); display_msg("Must be implemented - deAllocateProteinArray \n"); }
Installer::ProceedState RomInstaller::on_checked_device() { // /sbin is not going to be populated with anything useful in a normal boot // image. We can almost guarantee that a recovery image is going to be // installed though, so we'll open the recovery partition with libmbp and // extract its /sbin with libarchive into the chroot's /sbin. mbp::BootImage bi; if (!bi.loadFile(_recovery_block_dev)) { display_msg("Failed to load recovery partition image"); return ProceedState::Fail; } const unsigned char *ramdisk_data; std::size_t ramdisk_size; bi.ramdiskImageC(&ramdisk_data, &ramdisk_size); autoclose::archive in(archive_read_new(), archive_read_free); autoclose::archive out(archive_write_disk_new(), archive_write_free); if (!in | !out) { LOGE("Out of memory"); return ProceedState::Fail; } archive_entry *entry; // Set up input archive_read_support_filter_gzip(in.get()); archive_read_support_filter_lzop(in.get()); archive_read_support_filter_lz4(in.get()); archive_read_support_filter_lzma(in.get()); archive_read_support_format_cpio(in.get()); int ret = archive_read_open_memory(in.get(), const_cast<unsigned char *>(ramdisk_data), ramdisk_size); if (ret != ARCHIVE_OK) { LOGW("Failed to open recovery ramdisk: %s", archive_error_string(in.get())); return ProceedState::Fail; } // Set up output archive_write_disk_set_options(out.get(), ARCHIVE_EXTRACT_ACL | ARCHIVE_EXTRACT_FFLAGS | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_SECURE_NODOTDOT | ARCHIVE_EXTRACT_SECURE_SYMLINKS | ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_UNLINK | ARCHIVE_EXTRACT_XATTR); while ((ret = archive_read_next_header(in.get(), &entry)) == ARCHIVE_OK) { std::string path = archive_entry_pathname(entry); if (!util::starts_with(path, "sbin/")) { continue; } LOGE("Copying from recovery: %s", path.c_str()); archive_entry_set_pathname(entry, (_chroot + "/" + path).c_str()); if (util::archive_copy_header_and_data(in.get(), out.get(), entry) != ARCHIVE_OK) { return ProceedState::Fail; } archive_entry_set_pathname(entry, path.c_str()); } if (ret != ARCHIVE_EOF) { LOGE("Archive extraction ended without reaching EOF: %s", archive_error_string(in.get())); return ProceedState::Fail; } return ProceedState::Continue; }
void handle_key(void){ if (NeedsPoll) poll_keyboard(); if (key[syskeys[0]] || key[KEY_ESC]) { do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[0]] || key[KEY_ESC]); key_done=1; } if (key[syskeys[1]]) { do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[1]]); mute_audio(); mute_voice(); abaut(); do { rest(5); if (NeedsPoll) poll_keyboard(); if (key[KEY_ALT] && key[KEY_ENTER]) { app_data.fullscreen = app_data.fullscreen ? 0 : 1; grmode(); abaut(); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[KEY_ENTER]); } } while ((!key[syskeys[1]]) && (!key[KEY_ESC]) && (!key[syskeys[0]])); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[1]]); init_sound_stream(); } if (key[syskeys[5]]) { if (savestate(app_data.statefile)==0) { display_msg("Savefile saved.",5); } do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[5]]); } /* LOAD STATE */ if (key[syskeys[6]]) { int stateError; if ((stateError=loadstate(app_data.statefile))==0) { display_msg("Savefile loaded.",5); } else if (stateError>=199) { if (stateError==199) display_msg("Wrong ROM-File for Savefile.",5); else if (stateError==200+ROM_O2) display_msg("Wrong BIOS for Savefile: O2ROM needed.",5); else if (stateError==200+ROM_G7400) display_msg("Wrong BIOS for Savefile: G7400 ROM needed.",5); else if (stateError==200+ROM_C52) display_msg("Wrong BIOS for Savefile: C52 ROM needed.",5); else if (stateError==200+ROM_JOPAC) display_msg("Wrong BIOS for Savefile: JOPAC ROM needed.",5); else display_msg("Wrong BIOS for Savefile: UNKNOWN ROM needed.",5); } do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[6]]); } if (key[syskeys[2]]) key_debug=1; if (key[syskeys[3]]) { init_cpu(); init_roms(); init_vpp(); clearscr(); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[3]]); } /* SET HIGHSCORE */ if (key[syskeys[7]]) { set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore); } if (key[syskeys[4]]) { BITMAP *bmp; PALETTE pal; char *p; static char name[1024]; static int scshot_counter = 0; if (strlen(app_data.scshot)>0){ if ((p=strchr(app_data.scshot,'@'))) { *p = 0; sprintf(name, "%s%02d%s", app_data.scshot, scshot_counter++, p+1); *p = '@'; } else { strcpy(name, app_data.scshot); } get_palette(pal); bmp = create_sub_bitmap(screen, 0, 0, SCREEN_W, SCREEN_H); save_bitmap(name, bmp, pal); destroy_bitmap(bmp); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[4]]); } } // switch joystick if (key[syskeys[8]]) { joyswitch = joyswitch ? 0 : 1; set_defjoykeys(0,joyswitch); set_defjoykeys(1,joyswitch ? 0 : 1); int tmp = app_data.stick[0]; app_data.stick[0] = app_data.stick[1]; app_data.stick[1] = tmp; do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[8]]); } if (key[KEY_ALT] && key[KEY_ENTER]) { app_data.fullscreen = app_data.fullscreen ? 0 : 1; grmode(); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[KEY_ENTER]); } }