long int GetInt(const char* param) { long int result; char *endptr; errno = 0; result = strtol(param, &endptr, 10); #ifdef WIN32 /* Windows do not report correctly errno */ if (result == LONG_MAX || result == LONG_MIN) { #else if ((errno == ERANGE && (result == LONG_MAX || result == LONG_MIN))) { #endif printf_err(_("Number out of range: %s\n"), param); exit(2); } if (*endptr != '\0') { printf_err(_("Parameter is not a number: %s\n"), param); exit(2); } return result; }
void flash_perror(int err) { switch (err) { case ERR_OK: break; case ERR_TIMOUT: printf_err("timeout writing to FLASH\n"); break; case ERR_NOT_ERASED: printf_err("FLASH not erased\n"); break; case ERR_INVAL: printf_err("outside available FLASH\n"); break; case ERR_ALIGN: printf_err("start and/or end address not on sector boundary\n"); break; case ERR_UNKNOWN_FLASH_VENDOR: printf_err("unknown vendor of FLASH\n"); break; case ERR_UNKNOWN_FLASH_TYPE: printf_err("unknown type of FLASH\n"); break; case ERR_PROG_ERROR: printf_err("general FLASH programming error\n"); break; default: printf_err("%s[%d] FIXME: rc=%d\n", __FILE__, __LINE__, err); break; } }
//map pages for bss segment pointed to by shdr //stores program break (end of .bss segment) in prog_break //stored start of .bss segment in bss_loc static void alloc_bss(page_directory_t* new_dir, elf_s_header* shdr, int* prog_break, int* bss_loc) { printf("ELF .bss mapped @ %x - %x\n", shdr->addr, shdr->addr + shdr->size); for (uint32_t i = 0; i <= shdr->size + PAGE_SIZE; i += PAGE_SIZE) { page_t* page = get_page(shdr->addr + i, 1, new_dir); if (!alloc_frame(page, 0, 1)) { printf_err(".bss %x wasn't alloc'd", shdr->addr + i); } char* pagebuf = kmalloc_a(PAGE_SIZE); //zero out .bss memset(pagebuf, 0, PAGE_SIZE); page_t* local_page = get_page((uint32_t)pagebuf, 1, page_dir_current()); ASSERT(local_page, "elf_load_segment couldn't find page for pagebuf"); extern void copy_page_physical(uint32_t page, uint32_t dest); copy_page_physical(local_page->frame * PAGE_SIZE, page->frame * PAGE_SIZE); //now that the buffer has been copied, we can safely free the buffer kfree(pagebuf); } //set program break to .bss segment *prog_break = shdr->addr + shdr->size; *bss_loc = shdr->addr; }
static int is_eeprom_fru(char *eeprom_file, GtkTextBuffer *buf, GtkTextIter *iter) { FILE *fp; unsigned char *raw_input_data = NULL; size_t bytes; struct FRU_DATA *fru = NULL; char text[256]; fp = fopen(eeprom_file, "rb"); if(fp == NULL) { int errsv = errno; printf_err("Cannot open file %s\n%s\n", eeprom_file, strerror(errsv)); return 0; } raw_input_data = x_calloc(1, 1024); bytes = fread(raw_input_data, 1024, 1, fp); fclose(fp); /* Since EOF should be reached, bytes should be zero */ if (!bytes) fru = parse_FRU(raw_input_data); if (fru) { sprintf(text, "Found %s:\n", eeprom_file); gtk_text_buffer_insert(buf, iter, text, -1); if (fru->Board_Area->manufacturer && fru->Board_Area->manufacturer[0] & 0x3F) { sprintf(text, "FMC Manufacture : %s\n", &fru->Board_Area->manufacturer[1]); gtk_text_buffer_insert(buf, iter, text, -1); } if (fru->Board_Area->product_name && fru->Board_Area->product_name[0] & 0x3F) { sprintf(text, "Product Name: %s\n", &fru->Board_Area->product_name[1]); gtk_text_buffer_insert(buf, iter, text, -1); } if (fru->Board_Area->part_number && fru->Board_Area->part_number[0] & 0x3F) { sprintf(text, "Part Number : %s\n", &fru->Board_Area->part_number[1]); gtk_text_buffer_insert(buf, iter, text, -1); } if (fru->Board_Area->serial_number && fru->Board_Area->serial_number[0] & 0x3F) { sprintf(text, "Serial Number : %s\n", &fru->Board_Area->serial_number[1]); gtk_text_buffer_insert(buf, iter, text, -1); } if (fru->Board_Area->mfg_date) { time_t tmp = min2date(fru->Board_Area->mfg_date); sprintf(text, "Date of Man : %s", ctime(&tmp)); gtk_text_buffer_insert(buf, iter, text, -1); } sprintf(text, "\n"); gtk_text_buffer_insert(buf, iter, text, -1); free(fru); fru = NULL; return 1; } return 0; }
int main(int argc, char* argv[]) { global_config_struct global_config; process_args(argc, argv, &global_config); run(&global_config); #ifndef NDEBUG printf_err("DONE"); #endif return 0; }
bool elf_load_segment(page_directory_t* new_dir, unsigned char* src, elf_phdr* seg) { //loadable? if (seg->type != PT_LOAD) { printf_err("Tried to load non-loadable segment"); printk_err("Tried to load non-loadable segment"); return false; } unsigned char* src_base = src + seg->offset; //figure out range to map this binary to in virtual memory uint32_t dest_base = seg->vaddr; uint32_t dest_limit = dest_base + seg->memsz; printf("dest_base %x dest_limit %x\n", dest_base, dest_limit); //alloc enough mem for new task for (uint32_t i = dest_base, page_counter = 0; i <= dest_limit; i += PAGE_SIZE, page_counter++) { page_t* page = get_page(i, 1, new_dir); ASSERT(page, "elf_load_segment couldn't get page in new addrspace at %x\n", i); bool got_frame = alloc_frame(page, 0, 0); ASSERT(got_frame, "elf_load_segment couldn't alloc frame for page %x\n", i); char* pagebuf = kmalloc_a(PAGE_SIZE); page_t* local_page = get_page((uint32_t)pagebuf, 0, page_dir_current()); ASSERT(local_page, "couldn't get local_page!"); int old_frame = local_page->frame; local_page->frame = page->frame; invlpg(pagebuf); //create buffer in current address space, //copy data, //and then map frame into new address space memset(pagebuf, 0, (dest_limit - dest_base)); //only seg->filesz bytes are garuanteed to be in the file! //_not_ memsz //any extra bytes between filesz and memsz should be set to 0, which is done above //memcpy(dest_base, src_base, seg->filesz); memcpy(pagebuf, src_base + (page_counter * PAGE_SIZE), seg->filesz); //now that we've copied the data in the local address space, //get the page in local address space, //and copy backing physical frame data to physical frame of //page in new address space //now that the buffer has been copied, we can safely free the buffer local_page->frame = old_frame; invlpg(pagebuf); kfree(pagebuf); } // Copy data //memset((void*)dest_base, 0, (void*)(dest_limit - dest_base)); return true; }
void dequeue_task(task_small_t* task) { lock(mutex); if (task->queue < 0 || task->queue >= queues->size) { ASSERT(0, "Tried to remove %s from invalid queue %d", task->name, task->queue); } array_m* raw = array_m_lookup(queues, task->queue); int idx = array_m_index(raw, task); if (idx < 0) { printf_err("Tried to dequeue %s from queue %d it didn't belong to!", task->name, task->queue); //fall back on searching all queues for this task for (int i = 0; i < queues->size; i++) { array_m* queue = array_m_lookup(queues, i); for (int j = 0; j < queue->size; j++) { task_t* tmp = array_m_lookup(queue, j); if (task == tmp) { //found task we were looking for printf_info("Task was actually in queue %d", i); array_m_remove(queue, j); unlock(mutex); return; } } } //never found the task! printf_err("Task %s did not exist in any queues!", task->name); return; } array_m_remove(raw, idx); unlock(mutex); //if for some reason this task is still in the queue (if it was added to queue twice), //dequeue it again if (array_m_index(raw, task) != ARR_NOT_FOUND) { dequeue_task(task); } }
int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { printf("Resetting the board..."); milisecdelay(500); full_reset(); /* After full chip reset we should not reach next step... */ puts("\n"); printf_err("RESET FAILED!\n"); return 0; }
task_t* task_with_pid_auth(int pid) { Deprecated(); //first, ensure this task is allowed to do this! //permission to use task_with_pid is controlled by the PROC_MASTER_PERMISSION flag //only check if this is a non-kernel task //check for .bss segment as heuristic for whether this is an external program if (current_task->prog_break) { if (!(current_task->permissions & PROC_MASTER_PERMISSION)) { printf_err("%s[%d] is not authorized to use task_with_pid!", current_task->name, getpid()); return NULL; } } //operation permitted return task_with_pid(pid); }
void env_relocate(void) { DEBUGF("%s[%d] offset = 0x%lx\n", __FUNCTION__,__LINE__, gd->reloc_off); #if defined(ENV_IS_EMBEDDED) /* * The environment buffer is embedded with the text segment, * just relocate the environment pointer */ env_ptr = (env_t *)((ulong)env_ptr + gd->reloc_off); DEBUGF("%s[%d] embedded ENV at %p\n", __FUNCTION__,__LINE__,env_ptr); #else /* We must allocate a buffer for the environment */ env_ptr = (env_t *)malloc(CFG_ENV_SIZE); DEBUGF("%s[%d] malloced ENV at %p\n", __FUNCTION__,__LINE__,env_ptr); #endif /* After relocation to RAM, we can always use the "memory" functions */ env_get_char = env_get_char_memory; if (gd->env_valid == 0) { #if !defined(CFG_ENV_IS_NOWHERE) printf_wrn("bad env CRC, using default,\n" " use 'saveenv' to save it in FLASH\n\n"); #endif if (sizeof(default_environment) > ENV_SIZE) { printf_err("default env is too big!\n"); return; } memset(env_ptr, 0, sizeof(env_t)); memcpy(env_ptr->data, default_environment, sizeof(default_environment)); #if defined(CFG_REDUNDAND_ENVIRONMENT) env_ptr->flags = 0xFF; #endif env_crc_update(); gd->env_valid = 1; } else { env_relocate_spec(); } gd->env_addr = (ulong)&(env_ptr->data); }
int isphal_set_param_by_sensor_id(act_isp_init_param_t* init_param,int sensor_id) { int i; int nsupport = sizeof(isphal_param_support_sensor_id) / sizeof(int); for (i = 0; i < nsupport; i++) { if(isphal_param_support_sensor_id[i] == sensor_id) { break; } } if(i < nsupport) { isphal_param_support_func[i](init_param); printf("info!find sensor_id(%x) sucess!\n",sensor_id); return 0; } printf_err("err!can not support the sensor_id(%x)!\n",sensor_id); return -1; }
void reap_task(task_t* tmp) { Deprecated(); if (tmp->state == ZOMBIE) { array_m* queue = array_m_lookup(queues, tmp->queue); int idx = array_m_index(queue, tmp); if (idx != ARR_NOT_FOUND) { printk("reap() unlisting %s\n", tmp->name); lock(mutex); array_m_remove(queue, idx); unlock(mutex); destroy_task(tmp); } else { //couldn't find task in the queue it said it was in //fall back on searching through each queue bool found = false; for (int i = 0; i < queues->size && !found; i++) { array_m* queue = array_m_lookup(queues, i); for (int j = 0; j < queues->size && !found; j++) { task_t* to_test = array_m_lookup(queue, j); if (to_test == tmp) { lock(mutex); array_m_remove(queue, j); unlock(mutex); destroy_task(tmp); found = true; break; } } } if (!found) { printf_err("Tried to reap task %s[%d] but it didn't exist in a queue", tmp->name, tmp->id); } } } }
void enqueue_task(task_small_t* task, int queue) { lock(mutex); if (queue < 0 || queue >= queues->size) { ASSERT(0, "Tried to insert %s into invalid queue %d", task->name, queue); } array_m* raw = array_m_lookup(queues, queue); //ensure task does not already exist in this queue if (array_m_index(raw, task) == ARR_NOT_FOUND) { lock(mutex); array_m_insert(raw, task); unlock(mutex); task->queue = queue; //new queue, reset lifespan task->lifespan = 0; } else { printf_err("Tried to enqueue %s onto queue where it already existed (%d)", task->name, queue); } unlock(mutex); }
static void syntax_err(void) { printf_err("syntax error!\n"); }
/* run_pipe_real() starts all the jobs, but doesn't wait for anything * to finish. See checkjobs(). * * return code is normally -1, when the caller has to wait for children * to finish to determine the exit status of the pipe. If the pipe * is a simple builtin command, however, the action is done by the * time run_pipe_real returns, and the exit code is provided as the * return value. * * The input of the pipe is always stdin, the output is always * stdout. The outpipe[] mechanism in BusyBox-0.48 lash is bogus, * because it tries to avoid running the command substitution in * subshell, when that is in fact necessary. The subshell process * now has its stdout directed to the input of the appropriate pipe, * so this routine is noticeably simpler. */ static int run_pipe_real(struct pipe *pi) { int i; int nextin; int flag = do_repeat ? CMD_FLAG_REPEAT : 0; struct child_prog *child; cmd_tbl_t *cmdtp; char *p; # if __GNUC__ /* Avoid longjmp clobbering */ (void) &i; (void) &nextin; (void) &child; # endif nextin = 0; /* Check if this is a simple builtin (not part of a pipe). * Builtins within pipes have to fork anyway, and are handled in * pseudo_exec. "echo foo | read bar" doesn't work on bash, either. */ if (pi->num_progs == 1) child = &(pi->progs[0]); if (pi->num_progs == 1 && child->group) { int rcode; debug_printf("non-subshell grouping\n"); rcode = run_list_real(child->group); return rcode; } else if (pi->num_progs == 1 && pi->progs[0].argv != NULL) { for (i = 0; is_assignment(child->argv[i]); i++) { /* nothing */ } if (i != 0 && child->argv[i] == NULL) { /* assignments, but no command: set the local environment */ for (i = 0; child->argv[i] != NULL; i++) { /* Ok, this case is tricky. We have to decide if this is a * local variable, or an already exported variable. If it is * already exported, we have to export the new value. If it is * not exported, we need only set this as a local variable. * This junk is all to decide whether or not to export this * variable. */ int export_me = 0; char *name, *value; name = xstrdup(child->argv[i]); debug_printf("Local environment set: %s\n", name); value = strchr(name, '='); if (value) *value = 0; free(name); p = insert_var_value(child->argv[i]); set_local_var(p, export_me); if (p != child->argv[i]) free(p); } return EXIT_SUCCESS; /* don't worry about errors in set_local_var() yet */ } for (i = 0; is_assignment(child->argv[i]); i++) { p = insert_var_value(child->argv[i]); set_local_var(p, 0); if (p != child->argv[i]) { child->sp--; free(p); } } if (child->sp) { char * str = NULL; str = make_string((child->argv + i)); parse_string_outer(str, FLAG_EXIT_FROM_LOOP | FLAG_REPARSING); free(str); return last_return_code; } /* check ";", because ,example , argv consist from * "help;flinfo" must not execute */ if (strchr(child->argv[i], ';')) { printf_err("unknown command '%s' - try 'help' or use 'run' command\n", child->argv[i]); return -1; } /* Look up command in command table */ if ((cmdtp = find_cmd(child->argv[i])) == NULL) { printf_err("unknown command '%s' - try 'help'\n", child->argv[i]); return -1; /* give up after bad command */ } else { int rcode; #if defined(CONFIG_CMD_BOOTD) extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); /* avoid "bootd" recursion */ if (cmdtp->cmd == do_bootd) { if (flag & CMD_FLAG_BOOTD) { printf_err("'bootd' recursion detected!\n"); return -1; } else { flag |= CMD_FLAG_BOOTD; } } #endif /* CONFIG_CMD_BOOTD */ /* found - check max args */ if ((child->argc - i) > cmdtp->maxargs) { print_cmd_help(cmdtp); return -1; } child->argv += i; /* XXX horrible hack */ /* OK - call function to do the command */ rcode = (cmdtp->cmd)(cmdtp, flag, child->argc - i, &child->argv[i]); if (!cmdtp->repeatable) flag_repeat = 0; child->argv -= i; /* XXX restore hack so free() can work right */ return rcode; } } return -1; }
void interrupt_handle_invalid_tss(register_state_t* regs) { printf_err("Invalid TSS section!"); common_halt(regs, false); }
/** * main */ int main(int argc, char *argv[]) { int rc; int arg_iter; int srv_sock, cli_sock; int family; int true = 1; struct sockaddr_storage cli_sock_saddr; struct sockaddr *cli_sock_addr; struct sockaddr_in *cli_sock_4addr; struct sockaddr_in6 *cli_sock_6addr; socklen_t cli_sock_addr_len; short srv_sock_port; char *srv_sock_path = NULL; char buffer[RECV_BUF_LEN]; char cli_sock_addr_str[ADDR_STR_LEN]; security_context_t ctx; char *ctx_str; FILE *log = NULL; /* get the command line arguments */ do { arg_iter = getopt(argc, argv, "hl:"); switch (arg_iter) { case 'l': if (log) usage(argv[0]); log = fopen(optarg, "a"); if (log == NULL) { printf_err("error: unable to open \"%s\"\n", optarg); exit(1); } break; case 'h': /* help */ usage(argv[0]); break; default: break; } } while (arg_iter > 0); srv_sock_port = atoi(argv[optind]); if (srv_sock_port == 0) srv_sock_path = argv[optind]; rc = getcon(&ctx); if (rc < 0) ctx_str = strdup("NO_CONTEXT"); else ctx_str = strdup(ctx); printf_err("-> running as %s\n", ctx_str); free(ctx_str); printf_err("-> creating socket ... "); if (srv_sock_path == NULL) { family = AF_INET6; srv_sock = socket(family, SOCK_STREAM, IPPROTO_TCP); if (srv_sock < 0) { family = AF_INET; srv_sock = socket(family, SOCK_STREAM, IPPROTO_TCP); } } else { family = AF_UNIX; srv_sock = socket(AF_UNIX, SOCK_STREAM, 0); } if (srv_sock < 0) { printf_err("error: %d\n", srv_sock); return 1; } rc = setsockopt(srv_sock, SOL_SOCKET, SO_REUSEADDR, &true, sizeof(true)); if (rc < 0) { printf_err("error: %d\n", srv_sock); return 1; } printf_err("ok\n"); if (srv_sock_path == NULL) { struct sockaddr_in6 srv_sock_addr; printf_err("-> listening on TCP port %hu ... ", srv_sock_port); memset(&srv_sock_addr, 0, sizeof(srv_sock_addr)); srv_sock_addr.sin6_family = family; memcpy(&srv_sock_addr.sin6_addr, &in6addr_any, sizeof(in6addr_any)); srv_sock_addr.sin6_port = htons(srv_sock_port); rc = bind(srv_sock, (struct sockaddr *)&srv_sock_addr, sizeof(srv_sock_addr)); } else { struct sockaddr_un srv_sock_addr; printf_err("-> listening on UNIX socket %s ... ", srv_sock_path); srv_sock_addr.sun_family = family; strncpy(srv_sock_addr.sun_path, srv_sock_path, UNIX_PATH_MAX); srv_sock_addr.sun_path[UNIX_PATH_MAX - 1] = '\0'; rc = bind(srv_sock, (struct sockaddr *)&srv_sock_addr, sizeof(srv_sock_addr)); } if (rc < 0) { printf_err("bind error: %d\n", rc); return 1; } rc = listen(srv_sock, LISTEN_QUEUE); if (rc < 0) { printf_err("listen error: %d\n", rc); return 1; } else printf_err("ok\n"); cli_sock_addr = (struct sockaddr *)&cli_sock_saddr; cli_sock_4addr = (struct sockaddr_in *)&cli_sock_saddr; cli_sock_6addr = (struct sockaddr_in6 *)&cli_sock_saddr; /* loop forever */ for (;;) { printf_err("-> waiting ... "); memset(&cli_sock_saddr, 0, sizeof(cli_sock_saddr)); cli_sock_addr_len = sizeof(cli_sock_saddr); cli_sock = accept(srv_sock, cli_sock_addr, &cli_sock_addr_len); if (cli_sock < 0) { printf_err("error: %d\n", cli_sock); continue; } rc = getpeercon(cli_sock, &ctx); if (rc < 0) ctx_str = strdup("NO_CONTEXT"); else ctx_str = strdup(ctx); switch (cli_sock_addr->sa_family) { case AF_INET: inet_ntop(cli_sock_addr->sa_family, (void *)&cli_sock_4addr->sin_addr, cli_sock_addr_str, ADDR_STR_LEN); printf_err("connect(%s,%s)\n", cli_sock_addr_str, ctx_str); break; case AF_INET6: if (IN6_IS_ADDR_V4MAPPED(&cli_sock_6addr->sin6_addr)) inet_ntop(AF_INET, (void *)&cli_sock_6addr->sin6_addr.s6_addr32[3], cli_sock_addr_str, ADDR_STR_LEN); else inet_ntop(cli_sock_addr->sa_family, (void *)&cli_sock_6addr->sin6_addr, cli_sock_addr_str, ADDR_STR_LEN); printf_err("connect(%s,%s)\n", cli_sock_addr_str, ctx_str); break; case AF_UNIX: printf_err("connect(UNIX,%s)\n", ctx_str); break; default: printf_err("connect(%d,%s)\n", cli_sock_addr->sa_family, ctx_str); } free(ctx_str); do { rc = recv(cli_sock, buffer, RECV_BUF_LEN, 0); if (rc < 0) { printf_err("error: %d\n", rc); } else { buffer[rc] = '\0'; printf_out("%s", buffer); } } while (rc > 0); close(cli_sock); printf_err("-> connection closed\n"); } if (log) fclose(log); return 0; }
void Restore(int argc, char *argv[]) { GSM_Error error; GSM_Backup Backup; GSM_FMStation FMStation; GSM_DateTime date_time; GSM_CalendarEntry Calendar; GSM_Bitmap Bitmap; GSM_Ringtone Ringtone; GSM_MemoryEntry Pbk; GSM_MemoryStatus MemStatus; GSM_ToDoEntry ToDo; GSM_ToDoStatus ToDoStatus; GSM_NoteEntry Note; GSM_Profile Profile; GSM_MultiWAPSettings Settings; GSM_GPRSAccessPoint GPRSPoint; GSM_WAPBookmark Bookmark; int i, j, used, max = 0; gboolean Past = TRUE, First; gboolean Found, DoRestore; error = GSM_ReadBackupFile(argv[2],&Backup,GSM_GuessBackupFormat(argv[2], FALSE)); Print_Error(error); signal(SIGINT, interrupt); fprintf(stderr, "%s\n", _("Press Ctrl+C to break...")); if (Backup.DateTimeAvailable) fprintf(stderr, LISTFORMAT "%s\n", _("Time of backup"),OSDateTime(Backup.DateTime,FALSE)); if (Backup.Model[0]!=0) fprintf(stderr, LISTFORMAT "%s\n", _("Phone"),Backup.Model); if (Backup.IMEI[0]!=0) fprintf(stderr, LISTFORMAT "%s\n", _("IMEI"),Backup.IMEI); if (Backup.Creator[0]!=0) fprintf(stderr, LISTFORMAT "%s\n", _("File created by"),Backup.Creator); if (argc == 4 && strcasecmp(argv[3],"-yes") == 0) always_answer_yes = TRUE; if (Backup.MD5Calculated[0]!=0) { if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) { if (!answer_yes(_("Checksum in backup file do not match (original: %s, new: %s). Continue?"), Backup.MD5Original, Backup.MD5Calculated)) return; } } GSM_Init(TRUE); printf("%s\n", _("Please note that restoring data will cause existing data in phone to be deleted.")); printf("%s\n", _("Use addnew command if you just want to add some entries to your phone.")); DoRestore = FALSE; if (Backup.CallerLogos[0] != NULL) { Bitmap.Type = GSM_CallerGroupLogo; Bitmap.Location = 1; error=GSM_GetBitmap(gsm,&Bitmap); if (error == ERR_NONE) { if (answer_yes("%s", _("Restore phone caller groups and logos?"))) DoRestore = TRUE; } } if (DoRestore) { max = 0; while (Backup.CallerLogos[max]!=NULL) max++; for (i=0;i<max;i++) { error=GSM_SetBitmap(gsm,Backup.CallerLogos[i]); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } DoRestore = FALSE; if (Backup.PhonePhonebook[0] != NULL) { max = 0; while (Backup.PhonePhonebook[max]!=NULL) max++; MemStatus.MemoryType = MEM_ME; error=GSM_GetMemoryStatus(gsm, &MemStatus); /* Some phones do not support status, try reading some entry */ if (error != ERR_NONE) { Pbk.Location = 1; Pbk.MemoryType = MEM_ME; error = GSM_GetMemory(gsm, &Pbk); MemStatus.MemoryUsed = max; MemStatus.MemoryFree = max; } if (error == ERR_NONE || error == ERR_EMPTY) { fprintf(stderr, _("%i entries in backup file\n"),max); if (answer_yes("%s", _("Restore phone phonebook?"))) DoRestore = TRUE; } } if (DoRestore) { used = 0; for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { Pbk.MemoryType = MEM_ME; Pbk.Location = i + 1; Pbk.EntriesNum = 0; if (used<max && Backup.PhonePhonebook[used]->Location == Pbk.Location) { Pbk = *Backup.PhonePhonebook[used]; used++; if (Pbk.EntriesNum != 0) error=GSM_SetMemory(gsm, &Pbk); if (error == ERR_PERMISSION && GSM_IsPhoneFeatureAvailable(GSM_GetModelInfo(gsm), F_6230iCALLER)) { error=GSM_DeleteMemory(gsm, &Pbk); Print_Error(error); error=GSM_SetMemory(gsm, &Pbk); } if (error == ERR_MEMORY && GSM_IsPhoneFeatureAvailable(GSM_GetModelInfo(gsm), F_6230iCALLER)) { printf_err("%s\n", _("Probably caller group is missing from your backup, add it and use --restore again.")); GSM_Terminate(); Terminate(2); } if (Pbk.EntriesNum != 0 && error==ERR_NONE) { First = TRUE; for (j=0;j<Pbk.EntriesNum;j++) { if (Pbk.Entries[j].AddError == ERR_NONE) continue; if (First) { printf("\r"); printf(_("Location %d"), Pbk.Location); printf("%20s\n ", " "); First = FALSE; } PrintMemorySubEntry(&Pbk.Entries[j], gsm); printf(" %s\n", GSM_ErrorString(Pbk.Entries[j].AddError)); } } } if (Pbk.EntriesNum == 0) { /* Delete only when there was some content in phone */ if (MemStatus.MemoryUsed > 0) { error = GSM_DeleteMemory(gsm, &Pbk); if (error != ERR_EMPTY && error != ERR_NONE) { Print_Error(error); } } } fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / (MemStatus.MemoryUsed + MemStatus.MemoryFree) ); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } DoRestore = FALSE; if (Backup.SIMPhonebook[0] != NULL) { MemStatus.MemoryType = MEM_SM; error=GSM_GetMemoryStatus(gsm, &MemStatus); if (error==ERR_NONE) { max = 0; while (Backup.SIMPhonebook[max]!=NULL) max++; fprintf(stderr, _("%i entries in backup file\n"),max); if (answer_yes("%s", _("Restore SIM phonebook?"))) DoRestore = TRUE; } } if (DoRestore) { used = 0; for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { Pbk.MemoryType = MEM_SM; Pbk.Location = i + 1; Pbk.EntriesNum = 0; if (used<max && Backup.SIMPhonebook[used]->Location == Pbk.Location) { Pbk = *Backup.SIMPhonebook[used]; used++; if (Pbk.EntriesNum != 0) { error=GSM_SetMemory(gsm, &Pbk); if (error==ERR_NONE) { First = TRUE; for (j=0;j<Pbk.EntriesNum;j++) { if (Pbk.Entries[j].AddError == ERR_NONE) continue; if (First) { printf("\r"); printf(_("Location %d"), Pbk.Location); printf("%20s\n ", " "); First = FALSE; } PrintMemorySubEntry(&Pbk.Entries[j], gsm); printf(" %s\n",GSM_ErrorString(Pbk.Entries[j].AddError)); } } } } if (Pbk.EntriesNum == 0) error=GSM_DeleteMemory(gsm, &Pbk); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / (MemStatus.MemoryUsed + MemStatus.MemoryFree)); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } if (GSM_GetConfig(gsm, -1)->SyncTime == FALSE) { if (answer_yes("%s", _("Do you want to set phone date/time? (NOTE: in some phones it's required to correctly restore calendar notes and other items)"))) { GSM_GetCurrentDateTime(&date_time); error=GSM_SetDateTime(gsm, &date_time); Print_Error(error); } } DoRestore = FALSE; if (Backup.Calendar[0] != NULL) { Calendar.Location = 0; /* N6110 doesn't support getting calendar status */ error = GSM_GetNextCalendar(gsm,&Calendar,TRUE); if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) { max = 0; while (Backup.Calendar[max] != NULL) max++; fprintf(stderr, _("%i entries in backup file\n"),max); if (answer_yes("%s", _("Restore phone calendar notes?"))) { Past = answer_yes(" %s", _("Restore notes from the past?")); DoRestore = TRUE; } } } if (DoRestore) { fprintf(stderr, "%s ", _("Deleting old notes:")); error = GSM_DeleteAllCalendar(gsm); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { while (1) { error = GSM_GetNextCalendar(gsm,&Calendar,TRUE); if (error != ERR_NONE) break; error = GSM_DeleteCalendar(gsm,&Calendar); Print_Error(error); fprintf(stderr, "*"); } fprintf(stderr, "\n"); } else { fprintf(stderr, "%s\n", _("Done")); Print_Error(error); } for (i=0;i<max;i++) { if (!Past && GSM_IsCalendarNoteFromThePast(Backup.Calendar[i])) continue; Calendar = *Backup.Calendar[i]; error=GSM_AddCalendar(gsm,&Calendar); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } DoRestore = FALSE; if (Backup.ToDo[0] != NULL) { error = GSM_GetToDoStatus(gsm,&ToDoStatus); if (error == ERR_NONE) { max = 0; while (Backup.ToDo[max]!=NULL) max++; fprintf(stderr, _("%i entries in backup file\n"),max); if (answer_yes("%s", _("Restore phone todo?"))) DoRestore = TRUE; } } if (DoRestore) { ToDo = *Backup.ToDo[0]; error = GSM_SetToDo(gsm,&ToDo); } if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) { fprintf(stderr, "%s ", _("Deleting old todos:")); error=GSM_DeleteAllToDo(gsm); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { while (1) { error = GSM_GetNextToDo(gsm,&ToDo,TRUE); if (error != ERR_NONE) break; error = GSM_DeleteToDo(gsm,&ToDo); Print_Error(error); fprintf(stderr, "*"); } fprintf(stderr, "\n"); } else { fprintf(stderr, "%s\n", _("Done")); Print_Error(error); } for (i=0;i<max;i++) { ToDo = *Backup.ToDo[i]; ToDo.Location = 0; error=GSM_AddToDo(gsm,&ToDo); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } else if (DoRestore) { /* At first delete entries, that were deleted */ used = 0; error = GSM_GetNextToDo(gsm,&ToDo,TRUE); while (error == ERR_NONE) { used++; Found = FALSE; for (i=0;i<max;i++) { if (Backup.ToDo[i]->Location == ToDo.Location) { Found = TRUE; break; } } if (!Found) { error=GSM_DeleteToDo(gsm,&ToDo); Print_Error(error); } error = GSM_GetNextToDo(gsm,&ToDo,FALSE); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), used * 100 / ToDoStatus.Used); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); /* Now write modified/new entries */ for (i=0;i<max;i++) { ToDo = *Backup.ToDo[i]; error = GSM_SetToDo(gsm,&ToDo); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } DoRestore = FALSE; if (Backup.Note[0] != NULL) { error = GSM_GetNotesStatus(gsm,&ToDoStatus); if (error == ERR_NONE) { max = 0; while (Backup.Note[max]!=NULL) max++; fprintf(stderr, _("%i entries in backup file\n"),max); if (answer_yes("%s", _("Restore phone notes?"))) DoRestore = TRUE; } } if (DoRestore) { fprintf(stderr, "%s ", _("Deleting old notes:")); while (1) { error = GSM_GetNextNote(gsm,&Note,TRUE); if (error != ERR_NONE) break; error = GSM_DeleteNote(gsm,&Note); Print_Error(error); fprintf(stderr, "*"); } fprintf(stderr, "\n"); for (i=0;i<max;i++) { Note = *Backup.Note[i]; Note.Location = 0; error=GSM_AddNote(gsm,&Note); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } if (Backup.SMSC[0] != NULL && answer_yes("%s", _("Restore SIM SMSC profiles?"))) { max = 0; while (Backup.SMSC[max]!=NULL) max++; for (i=0;i<max;i++) { error=GSM_SetSMSC(gsm,Backup.SMSC[i]); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } if (Backup.StartupLogo != NULL && answer_yes("%s", _("Restore phone startup logo/text?"))) { error=GSM_SetBitmap(gsm,Backup.StartupLogo); Print_Error(error); } if (Backup.OperatorLogo != NULL && answer_yes("%s", _("Restore phone operator logo?"))) { error=GSM_SetBitmap(gsm,Backup.OperatorLogo); Print_Error(error); } DoRestore = FALSE; if (Backup.WAPBookmark[0] != NULL) { Bookmark.Location = 1; error = GSM_GetWAPBookmark(gsm,&Bookmark); if (error == ERR_NONE || error == ERR_INVALIDLOCATION) { if (answer_yes("%s", _("Restore phone WAP bookmarks?"))) DoRestore = TRUE; } } if (DoRestore) { fprintf(stderr, "%s ", _("Deleting old bookmarks:")); /* One thing to explain: DCT4 phones seems to have bug here. * When delete for example first bookmark, phone change * numeration for getting frame, not for deleting. So, we try to * get 1'st bookmark. Inside frame is "correct" location. We use * it later */ while (error==ERR_NONE) { error = GSM_DeleteWAPBookmark(gsm,&Bookmark); Bookmark.Location = 1; error = GSM_GetWAPBookmark(gsm,&Bookmark); fprintf(stderr, "*"); } fprintf(stderr, "\n"); max = 0; while (Backup.WAPBookmark[max]!=NULL) max++; for (i=0;i<max;i++) { Bookmark = *Backup.WAPBookmark[i]; Bookmark.Location = 0; error=GSM_SetWAPBookmark(gsm,&Bookmark); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } DoRestore = FALSE; if (Backup.WAPSettings[0] != NULL) { Settings.Location = 1; error = GSM_GetWAPSettings(gsm,&Settings); if (error == ERR_NONE) { if (answer_yes("%s", _("Restore phone WAP settings?"))) DoRestore = TRUE; } } if (DoRestore) { max = 0; while (Backup.WAPSettings[max]!=NULL) max++; for (i=0;i<max;i++) { error=GSM_SetWAPSettings(gsm,Backup.WAPSettings[i]); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } DoRestore = FALSE; if (Backup.MMSSettings[0] != NULL) { Settings.Location = 1; error = GSM_GetMMSSettings(gsm,&Settings); if (error == ERR_NONE) { if (answer_yes("%s", _("Restore phone MMS settings?"))) DoRestore = TRUE; } } if (DoRestore) { max = 0; while (Backup.MMSSettings[max]!=NULL) max++; for (i=0;i<max;i++) { error=GSM_SetMMSSettings(gsm,Backup.MMSSettings[i]); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } DoRestore = FALSE; if (Backup.Ringtone[0] != NULL) { Ringtone.Location = 1; Ringtone.Format = 0; error = GSM_GetRingtone(gsm,&Ringtone,FALSE); if (error == ERR_NONE || error ==ERR_EMPTY) { if (answer_yes("%s", _("Delete all phone user ringtones?"))) DoRestore = TRUE; } } if (DoRestore) { fprintf(stderr, LISTFORMAT, _("Deleting")); error=GSM_DeleteUserRingtones(gsm); Print_Error(error); fprintf(stderr, "%s\n", _("Done")); DoRestore = FALSE; if (answer_yes("%s", _("Restore user ringtones?"))) DoRestore = TRUE; } if (DoRestore) { max = 0; while (Backup.Ringtone[max]!=NULL) max++; for (i=0;i<max;i++) { error=GSM_RingtoneConvert(&Ringtone, Backup.Ringtone[i], Ringtone.Format); Print_Error(error); error=GSM_SetRingtone(gsm,&Ringtone,&i); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } DoRestore = FALSE; if (Backup.Profiles[0] != NULL) { Profile.Location = 1; error = GSM_GetProfile(gsm,&Profile); if (error == ERR_NONE) { if (answer_yes("%s", _("Restore phone profiles?"))) DoRestore = TRUE; } } if (DoRestore) { Profile.Location= 0; max = 0; while (Backup.Profiles[max]!=NULL) max++; for (i=0;i<max;i++) { Profile = *Backup.Profiles[i]; error=GSM_SetProfile(gsm,&Profile); Print_Error(error); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } DoRestore = FALSE; if (Backup.FMStation[0] != NULL) { FMStation.Location = 1; error = GSM_GetFMStation(gsm,&FMStation); if (error == ERR_NONE || error == ERR_EMPTY) { if (answer_yes("%s", _("Restore phone FM radio stations?"))) DoRestore = TRUE; } } if (DoRestore) { fprintf(stderr, "%s ", _("Deleting old FM stations:")); error=GSM_ClearFMStations(gsm); Print_Error(error); fprintf(stderr, "%s\n", _("Done")); max = 0; while (Backup.FMStation[max]!=NULL) max++; for (i=0;i<max;i++) { FMStation = *Backup.FMStation[i]; error=GSM_SetFMStation(gsm,&FMStation); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } DoRestore = FALSE; if (Backup.GPRSPoint[0] != NULL) { GPRSPoint.Location = 1; error = GSM_GetGPRSAccessPoint(gsm,&GPRSPoint); if (error == ERR_NONE || error == ERR_EMPTY) { if (answer_yes("%s", _("Restore phone GPRS Points?"))) DoRestore = TRUE; } } if (DoRestore) { max = 0; while (Backup.GPRSPoint[max]!=NULL) max++; for (i=0;i<max;i++) { error=GSM_SetGPRSAccessPoint(gsm,Backup.GPRSPoint[i]); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } GSM_FreeBackup(&Backup); GSM_Terminate(); }
void interrupt_handle_segment_not_present(register_state_t* regs) { printf_err("Segment not present"); common_halt(regs, false); }
void AddNew(int argc, char *argv[]) { GSM_Error error; GSM_Backup Backup; GSM_DateTime date_time; GSM_MemoryEntry Pbk; GSM_MemoryStatus MemStatus; GSM_ToDoEntry ToDo; GSM_ToDoStatus ToDoStatus; GSM_NoteEntry Note; GSM_CalendarEntry Calendar; GSM_WAPBookmark Bookmark; GSM_MemoryType MemoryType = 0; int i, max; error=GSM_ReadBackupFile(argv[2],&Backup,GSM_GuessBackupFormat(argv[2], FALSE)); if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); if (Backup.DateTimeAvailable) { fprintf(stderr, LISTFORMAT "%s\n", _("Time of backup"),OSDateTime(Backup.DateTime,FALSE)); } if (Backup.Model[0]!=0) { fprintf(stderr, LISTFORMAT "%s\n", _("Phone"),Backup.Model); } if (Backup.IMEI[0]!=0) { fprintf(stderr, LISTFORMAT "%s\n", _("IMEI"),Backup.IMEI); } for (i = 3; i < argc; i++) { if (strcasecmp(argv[i],"-yes") == 0) { always_answer_yes = TRUE; } else if (strcasecmp(argv[i],"-memory") == 0 && i + 1 < argc) { i++; MemoryType = GSM_StringToMemoryType(argv[i]); if (MemoryType == 0) { printf_err(_("Unknown memory type (\"%s\")\n"),argv[i]); Terminate(2); } } else { printf_err(_("Unknown parameter (\"%s\")\n"), argv[i]); Terminate(2); } } signal(SIGINT, interrupt); fprintf(stderr, "%s\n", _("Press Ctrl+C to break...")); GSM_Init(TRUE); if (Backup.PhonePhonebook[0] != NULL) { MemStatus.MemoryType = (MemoryType == 0 ? MEM_ME : MemoryType); error=GSM_GetMemoryStatus(gsm, &MemStatus); /* Some phones do not support status, try reading some entry */ if (error != ERR_NONE) { Pbk.Location = 1; Pbk.MemoryType = MEM_ME; error = GSM_GetMemory(gsm, &Pbk); MemStatus.MemoryFree = 9999999; } if (error == ERR_NONE || error == ERR_EMPTY) { max = 0; while (Backup.PhonePhonebook[max] != NULL) { max++; } fprintf(stderr, _("%i entries in backup file\n"), max); if (MemStatus.MemoryFree < max) { fprintf(stderr, _("Memory has only %i free locations.Exiting\n"), MemStatus.MemoryFree); } else if (answer_yes("%s", _("Add phone phonebook entries?"))) { for (i = 0; i < max; i++) { Pbk = *Backup.PhonePhonebook[i]; Pbk.MemoryType = (MemoryType == 0 ? MEM_ME : MemoryType); error=GSM_AddMemory(gsm, &Pbk); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } } } if (Backup.SIMPhonebook[0] != NULL) { MemStatus.MemoryType = (MemoryType == 0 ? MEM_SM : MemoryType); error=GSM_GetMemoryStatus(gsm, &MemStatus); if (error==ERR_NONE) { max = 0; while (Backup.SIMPhonebook[max]!=NULL) max++; fprintf(stderr, _("%i entries in backup file\n"),max); if (MemStatus.MemoryFree < max) { fprintf(stderr, _("Memory has only %i free locations.Exiting\n"),MemStatus.MemoryFree); } else if (answer_yes("%s", _("Add SIM phonebook entries?"))) { for (i=0;i<max;i++) { Pbk = *Backup.SIMPhonebook[i]; Pbk.MemoryType = (MemoryType == 0 ? MEM_SM : MemoryType); error=GSM_AddMemory(gsm, &Pbk); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } } } if (GSM_GetConfig(gsm, -1)->SyncTime == FALSE) { if (answer_yes("%s", _("Do you want to set phone date/time? (NOTE: in some phones it's required to correctly restore calendar notes and other items)"))) { GSM_GetCurrentDateTime(&date_time); error=GSM_SetDateTime(gsm, &date_time); Print_Error(error); } } if (Backup.Calendar[0] != NULL) { Calendar.Location = 1; error = GSM_GetNextCalendar(gsm,&Calendar,TRUE); if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) { if (answer_yes("%s", _("Add phone calendar notes?"))) { max = 0; while (Backup.Calendar[max]!=NULL) max++; for (i=0;i<max;i++) { Calendar = *Backup.Calendar[i]; error=GSM_AddCalendar(gsm,&Calendar); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } } } if (Backup.ToDo[0] != NULL) { ToDo.Location = 1; error=GSM_GetToDoStatus(gsm,&ToDoStatus); if (error == ERR_NONE) { if (answer_yes("%s", _("Add phone ToDo?"))) { max = 0; while (Backup.ToDo[max]!=NULL) max++; for (i=0;i<max;i++) { ToDo = *Backup.ToDo[i]; error = GSM_AddToDo(gsm,&ToDo); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } } } if (Backup.Note[0] != NULL) { Note.Location = 1; if (answer_yes("%s", _("Add notes to phone?"))) { max = 0; while (Backup.Note[max]!=NULL) max++; for (i=0;i<max;i++) { Note = *Backup.Note[i]; error = GSM_AddNote(gsm,&Note); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } } if (Backup.WAPBookmark[0] != NULL) { Bookmark.Location = 1; error = GSM_GetWAPBookmark(gsm,&Bookmark); if (error == ERR_NONE || error == ERR_INVALIDLOCATION) { if (answer_yes("%s", _("Add phone WAP bookmarks?"))) { max = 0; while (Backup.WAPBookmark[max]!=NULL) max++; for (i=0;i<max;i++) { Bookmark = *Backup.WAPBookmark[i]; Bookmark.Location = 0; error=GSM_SetWAPBookmark(gsm,&Bookmark); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Writing:")); fprintf(stderr, _("%i percent"), (i + 1) * 100 / max); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } } } GSM_FreeBackup(&Backup); GSM_Terminate(); }
void interrupt_handle_machine_check(register_state_t* regs) { printf_err("Machine check"); common_halt(regs, false); }
void elf_load_file(char* name, FILE* elf, char** argv) { //find file size fseek(elf, 0, SEEK_END); uint32_t binary_size = ftell(elf); fseek(elf, 0, SEEK_SET); char* filebuf = kmalloc(binary_size); for (uint32_t i = 0; i < binary_size; i++) { filebuf[i] = fgetc(elf); } elf_header* hdr = (elf_header*)filebuf; if (!elf_validate_header(hdr)) { return; } uint32_t new_dir_phys = 0; page_directory_t* new_dir = kmalloc_ap(sizeof(page_directory_t), &new_dir_phys); memset((uint8_t*)new_dir, 0, sizeof(page_directory_t)); //get offset of tablesPhysical from start of page_directory_t uint32_t offset = (uint32_t)new_dir->tablesPhysical - (uint32_t)new_dir; new_dir->physicalAddr = new_dir_phys + offset; for (int i = 0; i < 1024; i++) { new_dir->tables[i] = page_dir_kern()->tables[i]; new_dir->tablesPhysical[i] = page_dir_kern()->tablesPhysical[i] & ~4; } char* string_table = elf_get_string_table(hdr, binary_size); uint32_t prog_break = 0; uint32_t bss_loc = 0; for (int x = 0; x < hdr->shentsize * hdr->shnum; x += hdr->shentsize) { if (hdr->shoff + x > binary_size) { printf("Tried to read beyond the end of the file.\n"); return; } elf_s_header* shdr = (elf_s_header*)((uintptr_t)filebuf + (hdr->shoff + x)); char* section_name = (char*)((uintptr_t)string_table + shdr->name); //alloc memory for .bss segment if (!strcmp(section_name, ".bss")) { alloc_bss(new_dir, shdr, (int*)&prog_break, (int*)&bss_loc); } } uint32_t entry = elf_load_small(new_dir, (unsigned char*)filebuf); kfree(filebuf); //alloc stack space uint32_t stack_addr = 0x10000000; //give user program a 128kb stack for (int i = 0; i < 32; i++) { page_t* stacktop = get_page(stack_addr, 1, new_dir); //user, writeable alloc_frame(stacktop, 0, 1); stack_addr += PAGE_SIZE; } stack_addr -= PAGE_SIZE; //calculate argc count int argc = 0; while (argv[argc] != NULL) { argc++; } if (entry) { become_first_responder(); kernel_begin_critical(); task_t* elf = task_with_pid(getpid()); elf->prog_break = prog_break; elf->bss_loc = bss_loc; elf->name = strdup(name); elf->esp = elf->ebp = stack_addr; elf->eip = entry; elf->page_dir = new_dir; void goto_pid(int id, bool x); goto_pid(elf->id, false); /* int(*elf_main)(int, char**) = (int(*)(int, char**))entry; become_first_responder(); //calculate argc count int argc = 0; char* tmp = argv[argc]; while (argv[argc] != NULL) { argc++; } //jump to ELF entry point! int ret = elf_main(argc, argv); */ //binary should have called _exit() //if we got to this point, something went catastrophically wrong ASSERT(0, "ELF binary returned execution to loader!"); } else { printf_err("ELF wasn't loadable!"); return; } }
void interrupt_handle_stack_segment_fault(register_state_t* regs) { printf_err("Stack segment fault"); common_halt(regs, false); }
void interrupt_handle_general_protection_fault(register_state_t* regs) { printf_err("General protection fault"); common_halt(regs, false); }
void interrupt_handle_floating_point_exception(register_state_t* regs) { printf_err("Floating point exception"); common_halt(regs, false); }
void interrupt_handle_alignment_check(register_state_t* regs) { printf_err("Alignment check"); common_halt(regs, false); }
/* This is used to set local shell variables flg_export==0 if only local (not exporting) variable flg_export==1 if "new" exporting environ flg_export>1 if current startup environ (not call putenv()) */ static int set_local_var(const char *s, int flg_export) { char *name, *value; int result = 0; struct variables *cur; /* might be possible! */ if (!isalpha(*s)) return -1; name = strdup(s); if (getenv(name) != NULL) { printf_err("there is a global environment variable with the same name!\n"); free(name); return -1; } /* Assume when we enter this function that we are already in * NAME=VALUE format. So the first order of business is to * split 's' on the '=' into 'name' and 'value' */ value = strchr(name, '='); if (value == 0 && ++value == 0) { free(name); return -1; } *value++ = 0; for (cur = top_vars; cur; cur = cur->next) { if (strcmp(cur->name, name) == 0) break; } if (cur) { if (strcmp(cur->value, value) == 0) { if (flg_export > 0 && cur->flg_export == 0) cur->flg_export = flg_export; else result++; } else { if (cur->flg_read_only) { printf_err("%s: readonly variable", name); result = -1; } else { if (flg_export > 0 || cur->flg_export > 1) cur->flg_export = 1; free(cur->value); cur->value = strdup(value); } } } else { cur = malloc(sizeof(struct variables)); if (!cur) { result = -1; } else { cur->name = strdup(name); if (cur->name == 0) { free(cur); result = -1; } else { struct variables *bottom = top_vars; cur->value = strdup(value); cur->next = 0; cur->flg_export = flg_export; cur->flg_read_only = 0; while (bottom->next) bottom = bottom->next; bottom->next = cur; } } } free(name); return result; }
void SaveFile(int argc, char *argv[]) { GSM_Error error; GSM_Backup Backup; int i; size_t data_size = 0; FILE *file; unsigned char Buffer[100000]; GSM_MemoryEntry *pbk; long int location; if (strcasecmp(argv[2],"CALENDAR") == 0) { if (argc < 5) { printf("%s\n", _("Where is backup filename and location?")); Terminate(2); } location = GetInt(argv[5]) - 1; error = GSM_ReadBackupFile(argv[4], &Backup,GSM_GuessBackupFormat(argv[4], FALSE)); if (error != ERR_NOTIMPLEMENTED) { Print_Error(error); } i = 0; while (Backup.Calendar[i] != NULL) { if (i == location) break; i++; } if (i != location || Backup.Calendar[i] == NULL) { printf("%s\n", _("Calendar note not found in file")); GSM_FreeBackup(&Backup); Terminate(2); } error = GSM_EncodeVCALENDAR(Buffer, sizeof(Buffer), &data_size, Backup.Calendar[i],TRUE,Nokia_VCalendar); GSM_FreeBackup(&Backup); Print_Error(error); } else if (strcasecmp(argv[2],"BOOKMARK") == 0) { if (argc < 5) { printf("%s\n", _("Where is backup filename and location?")); Terminate(2); } location = GetInt(argv[5]) - 1; error = GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE)); if (error != ERR_NOTIMPLEMENTED) { Print_Error(error); } i = 0; while (Backup.WAPBookmark[i]!=NULL) { if (i == location) break; i++; } if (i != location || Backup.WAPBookmark[i] == NULL) { printf("%s\n", _("WAP bookmark not found in file")); GSM_FreeBackup(&Backup); Terminate(2); } error = GSM_EncodeURLFile(Buffer, &data_size, Backup.WAPBookmark[i]); GSM_FreeBackup(&Backup); Print_Error(error); } else if (strcasecmp(argv[2],"NOTE") == 0) { if (argc<5) { printf("%s\n", _("Where is backup filename and location?")); Terminate(2); } location = GetInt(argv[5]) - 1; error=GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE)); if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.Note[i]!=NULL) { if (i == location) break; i++; } if (i != location || Backup.Note[i] == NULL) { printf("%s\n", _("Note not found in file")); GSM_FreeBackup(&Backup); Terminate(2); } error = GSM_EncodeVNTFile(Buffer, sizeof(Buffer), &data_size, Backup.Note[i]); GSM_FreeBackup(&Backup); Print_Error(error); } else if (strcasecmp(argv[2],"TODO") == 0) { if (argc<5) { printf("%s\n", _("Where is backup filename and location?")); Terminate(2); } location = GetInt(argv[5]) - 1; error=GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE)); if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.ToDo[i]!=NULL) { if (i == location) break; i++; } if (i != location || Backup.ToDo[i] == NULL) { printf("%s\n", _("Todo note not found in file")); GSM_FreeBackup(&Backup); Terminate(2); } error = GSM_EncodeVTODO(Buffer, sizeof(Buffer), &data_size, Backup.ToDo[i], TRUE, Nokia_VToDo); GSM_FreeBackup(&Backup); Print_Error(error); } else if (strcasecmp(argv[2],"VCARD10") == 0 || strcasecmp(argv[2],"VCARD21") == 0) { if (argc<6) { printf("%s\n", _("Where is backup filename and location and memory type?")); Terminate(2); } location = GetInt(argv[6]) - 1; error=GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE)); if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; if (strcasecmp(argv[5],"SM") == 0) { while (Backup.SIMPhonebook[i]!=NULL) { if (i == location) break; i++; } if (i != location || Backup.SIMPhonebook[i] == NULL) { printf("%s\n", _("Phonebook entry not found in file")); GSM_FreeBackup(&Backup); Terminate(2); } pbk = Backup.SIMPhonebook[i]; } else if (strcasecmp(argv[5],"ME") == 0) { while (Backup.PhonePhonebook[i]!=NULL) { if (i == location) break; i++; } if (i != location || Backup.PhonePhonebook[i] == NULL) { printf("%s\n", _("Phonebook entry not found in file")); GSM_FreeBackup(&Backup); Terminate(2); } pbk = Backup.PhonePhonebook[i]; } else { printf(_("Unknown memory type: \"%s\"\n"),argv[5]); GSM_FreeBackup(&Backup); Terminate(2); } if (strcasecmp(argv[2],"VCARD10") == 0) { error = GSM_EncodeVCARD(GSM_GetDebug(gsm), Buffer, sizeof(Buffer), &data_size, pbk, TRUE, Nokia_VCard10); GSM_FreeBackup(&Backup); Print_Error(error); } else { error = GSM_EncodeVCARD(GSM_GetDebug(gsm), Buffer, sizeof(Buffer), &data_size, pbk, TRUE, Nokia_VCard21); GSM_FreeBackup(&Backup); Print_Error(error); } } else { printf(_("Unknown backup format: \"%s\"\n"), argv[2]); Terminate(2); } file = fopen(argv[3],"wb"); if (file == NULL) { printf_err("%s", _("Error while opening file for writing!\n")); Terminate(3); } if (data_size != fwrite(Buffer,1,data_size,file)) { printf_err("%s", _("Error while writing file!\n")); } if (fclose(file) != 0) { printf_err("%s", _("Error while closing file!\n")); } }
/** * Parse the target part of a rule. */ static int c2_parse_target(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult) { // Initialize leaf presult->isbranch = false; presult->l = malloc(sizeof(c2_l_t)); if (!presult->l) c2_error("Failed to allocate memory for new leaf."); c2_l_t * const pleaf = presult->l; memcpy(pleaf, &leaf_def, sizeof(c2_l_t)); // Parse negation marks while ('!' == pattern[offset]) { pleaf->neg = !pleaf->neg; ++offset; C2H_SKIP_SPACES(); } // Copy target name out unsigned tgtlen = 0; for (; pattern[offset] && (isalnum(pattern[offset]) || '_' == pattern[offset]); ++offset) { ++tgtlen; } if (!tgtlen) c2_error("Empty target."); pleaf->tgt = mstrncpy(&pattern[offset - tgtlen], tgtlen); // Check for predefined targets for (unsigned i = 1; i < sizeof(C2_PREDEFS) / sizeof(C2_PREDEFS[0]); ++i) { if (!strcmp(C2_PREDEFS[i].name, pleaf->tgt)) { pleaf->predef = i; pleaf->type = C2_PREDEFS[i].type; pleaf->format = C2_PREDEFS[i].format; break; } } // Alias for predefined targets if (!pleaf->predef) { #define TGTFILL(pdefid) \ (pleaf->predef = pdefid, \ pleaf->type = C2_PREDEFS[pdefid].type, \ pleaf->format = C2_PREDEFS[pdefid].format) // if (!strcmp("WM_NAME", tgt) || !strcmp("_NET_WM_NAME", tgt)) // TGTFILL(C2_L_PNAME); #undef TGTFILL // Alias for custom properties #define TGTFILL(target, type, format) \ (pleaf->target = mstrcpy(target), \ pleaf->type = type, \ pleaf->format = format) // if (!strcmp("SOME_ALIAS")) // TGTFILL("ALIAS_TEXT", C2_L_TSTRING, 32); #undef TGTFILL } C2H_SKIP_SPACES(); // Parse target-on-frame flag if ('@' == pattern[offset]) { pleaf->tgt_onframe = true; ++offset; C2H_SKIP_SPACES(); } // Parse index if ('[' == pattern[offset]) { offset++; C2H_SKIP_SPACES(); int index = -1; char *endptr = NULL; index = strtol(pattern + offset, &endptr, 0); if (!endptr || pattern + offset == endptr) c2_error("No index number found after bracket."); if (index < 0) c2_error("Index number invalid."); if (pleaf->predef) c2_error("Predefined targets can't have index."); pleaf->index = index; offset = endptr - pattern; C2H_SKIP_SPACES(); if (']' != pattern[offset]) c2_error("Index end marker not found."); ++offset; C2H_SKIP_SPACES(); } // Parse target type and format if (':' == pattern[offset]) { ++offset; C2H_SKIP_SPACES(); // Look for format bool hasformat = false; int format = 0; { char *endptr = NULL; format = strtol(pattern + offset, &endptr, 0); assert(endptr); if ((hasformat = (endptr && endptr != pattern + offset))) offset = endptr - pattern; C2H_SKIP_SPACES(); } // Look for type enum c2_l_type type = C2_L_TUNDEFINED; { switch (pattern[offset]) { case 'w': type = C2_L_TWINDOW; break; case 'd': type = C2_L_TDRAWABLE; break; case 'c': type = C2_L_TCARDINAL; break; case 's': type = C2_L_TSTRING; break; case 'a': type = C2_L_TATOM; break; default: c2_error("Invalid type character."); } if (type) { if (pleaf->predef) { printf_errf("(): Warning: Type specified for a default target will be ignored."); } else { if (pleaf->type && type != pleaf->type) printf_errf("(): Warning: Default type overridden on target."); pleaf->type = type; } } offset++; C2H_SKIP_SPACES(); } // Default format if (!pleaf->format) { switch (pleaf->type) { case C2_L_TWINDOW: case C2_L_TDRAWABLE: case C2_L_TATOM: pleaf->format = 32; break; case C2_L_TSTRING: pleaf->format = 8; break; default: break; } } // Write format if (hasformat) { if (pleaf->predef) printf_errf("(): Warning: Format \"%d\" specified on a default target will be ignored.", format); else if (C2_L_TSTRING == pleaf->type) printf_errf("(): Warning: Format \"%d\" specified on a string target will be ignored.", format); else { if (pleaf->format && pleaf->format != format) printf_err("Warning: Default format %d overridden on target.", pleaf->format); pleaf->format = format; } } } if (!pleaf->type) c2_error("Target type cannot be determined."); // if (!pleaf->predef && !pleaf->format && C2_L_TSTRING != pleaf->type) // c2_error("Target format cannot be determined."); if (pleaf->format && 8 != pleaf->format && 16 != pleaf->format && 32 != pleaf->format) c2_error("Invalid format."); return offset; }
void interrupt_handle_virtualization_exception(register_state_t* regs) { printf_err("Virtualization exception"); common_halt(regs, false); }