/** * tnsp_content_display_flash: * @content: a FlashContent structure. * * Display fields of a FlashContent structure. * * Return value: an error code, 0 otherwise. **/ int tnsp_content_display_flash(FlashContent *content) { FlashContent *ptr = content; if (content == NULL) { tifiles_critical("%s(NULL)", __FUNCTION__); return ERR_INVALID_FILE; } for (ptr = content; ptr != NULL; ptr = ptr->next) { tifiles_info("FlashContent for TI-Nspire: %p", ptr); tifiles_info("Model: %02X (%u)", ptr->model, ptr->model); tifiles_info("Signature: %s", tifiles_calctype2signature(ptr->model)); tifiles_info("model_dst: %02X (%u)", ptr->model_dst, ptr->model_dst); tifiles_info("Revision: %u.%u", ptr->revision_major, ptr->revision_minor); tifiles_info("Flags: %02X", ptr->flags); tifiles_info("Object type: %02X", ptr->object_type); tifiles_info("Date: %02X/%02X/%02X%02X", ptr->revision_day, ptr->revision_month, ptr->revision_year & 0xff, (ptr->revision_year & 0xff00) >> 8); tifiles_info("Name: %s", ptr->name); tifiles_info("Data type: OS data"); tifiles_info("Length: %08X (%i)", ptr->data_length, ptr->data_length); tifiles_info("Data part: %p", ptr->data_part); tifiles_info("Next: %p", ptr->next); } return 0; }
/** * tnsp_content_display_flash: * @content: a FlashContent structure. * * Display fields of a FlashContent structure. * * Return value: an error code, 0 otherwise. **/ int tnsp_content_display_flash(FlashContent *content) { FlashContent *ptr = content; if (content == NULL) { tifiles_critical("%s(NULL)", __FUNCTION__); return ERR_INVALID_FILE; } tifiles_info("Signature: %s", tifiles_calctype2signature(ptr->model)); tifiles_info("Revision: %i.%i", ptr->revision_major, ptr->revision_minor); tifiles_info("Flags: %02X", ptr->flags); tifiles_info("Object type: %02X", ptr->object_type); tifiles_info("Date: %02X/%02X/%02X%02X", ptr->revision_day, ptr->revision_month, ptr->revision_year & 0xff, (ptr->revision_year & 0xff00) >> 8); tifiles_info("Name: %s", ptr->name); tifiles_info("Device type: %s", ptr->device_type == DEVICE_TYPE_89 ? "ti89" : "ti92+"); tifiles_info("Data type: OS data"); tifiles_info("Length: %08X (%i)", ptr->data_length, ptr->data_length); tifiles_info(""); return 0; }
/** * ti9x_content_display_regular: * @content: a Ti9xRegular structure. * * Display fields of a Ti9xRegular structure. * * Return value: an error code, 0 otherwise. **/ int ti9x_content_display_regular(Ti9xRegular *content) { int i; char trans[17]; if (content == NULL) { tifiles_critical("%s(NULL)", __FUNCTION__); return ERR_INVALID_FILE; } tifiles_info("Signature: %s", tifiles_calctype2signature(content->model)); tifiles_info("Comment: %s", content->comment); tifiles_info("Default folder: %s", content->default_folder); tifiles_info("Number of entries: %i", content->num_entries); for (i = 0; i < content->num_entries; i++) { if (content->entries[i] != NULL) { tifiles_info("Entry #%i", i); tifiles_info(" folder: %s", content->entries[i]->folder); tifiles_info(" name: %s", ticonv_varname_to_utf8_s(content->model, content->entries[i]->name, trans, content->entries[i]->type)); tifiles_info(" type: %02X (%s)", content->entries[i]->type, tifiles_vartype2string(content->model, content->entries[i]->type)); tifiles_info(" attr: %s", tifiles_attribute_to_string(content->entries[i]->attr)); tifiles_info(" length: %04X (%i)", content->entries[i]->size, content->entries[i]->size); } } tifiles_info("Checksum: %04X (%i) ", content->checksum, content->checksum); return 0; }
/** * ti9x_content_display_backup: * @content: a Ti9xBackup structure. * * Display fields of a Ti9xBackup structure. * * Return value: an error code, 0 otherwise. **/ int ti9x_content_display_backup(Ti9xBackup *content) { if (content == NULL) { tifiles_critical("%s(NULL)", __FUNCTION__); return ERR_INVALID_FILE; } tifiles_info("signature: %s", tifiles_calctype2signature(content->model)); tifiles_info("comment: %s", content->comment); tifiles_info("ROM version: %s", content->rom_version); tifiles_info("type: %02X (%s)", content->type, tifiles_vartype2string(content->model, content->type)); tifiles_info("data length: %08X (%i)", content->data_length, content->data_length); tifiles_info("checksum: %04X (%i) ", content->checksum, content->checksum); return 0; }
/** * ti9x_content_display_flash: * @content: a Ti9xFlash structure. * * Display fields of a Ti9xFlash structure. * * Return value: an error code, 0 otherwise. **/ int ti9x_content_display_flash(Ti9xFlash *content) { Ti9xFlash *ptr; for (ptr = content; ptr != NULL; ptr = ptr->next) { tifiles_info("FlashContent for TI-9x: %p", ptr); tifiles_info("Model: %02X (%u)", ptr->model, ptr->model); tifiles_info("Signature: %s", tifiles_calctype2signature(ptr->model)); tifiles_info("model_dst: %02X (%u)", ptr->model_dst, ptr->model_dst); tifiles_info("Revision: %u.%u", ptr->revision_major, ptr->revision_minor); tifiles_info("Flags: %02X", ptr->flags); tifiles_info("Object type: %02X", ptr->object_type); tifiles_info("Date: %02X/%02X/%02X%02X", ptr->revision_day, ptr->revision_month, ptr->revision_year & 0xff, (ptr->revision_year & 0xff00) >> 8); tifiles_info("Name: %s", ptr->name); tifiles_info("Device type: %s", ptr->device_type == DEVICE_TYPE_89 ? "ti89" : "ti92+"); switch (ptr->data_type) { case 0x23: tifiles_info("Data type: OS data"); break; case 0x24: tifiles_info("Data type: APP data"); break; case 0x20: case 0x25: tifiles_info("Data type: certificate"); break; case 0x3E: tifiles_info("Data type: license"); break; default: tifiles_info("Data type: Unknown (send mail to [email protected])"); break; } tifiles_info("Hardware ID: %02X (%u)", ptr->hw_id, ptr->hw_id); tifiles_info("Length: %08X (%u)", ptr->data_length, ptr->data_length); tifiles_info("Data part: %p", ptr->data_part); tifiles_info("Next: %p", ptr->next); } return 0; }
/** * ti9x_file_write_backup: * @filename: name of backup file where to write. * @content: the file content to write. * * Write content to a backup file. * * Return value: an error code, 0 otherwise. **/ int ti9x_file_write_backup(const char *filename, Ti9xBackup *content) { FILE *f; if (filename == NULL || content == NULL) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; } f = g_fopen(filename, "wb"); if (f == NULL) { tifiles_info("Unable to open this file: %s", filename); return ERR_FILE_OPEN; } if (fwrite_8_chars(f, tifiles_calctype2signature(content->model)) < 0) goto tfwb; if (fwrite(fsignature, 1, 2, f) < 2) goto tfwb; if (fwrite_8_chars(f, "") < 0) goto tfwb; if (fwrite_n_bytes(f, 40, (uint8_t *)content->comment) < 0) goto tfwb; if (fwrite_word(f, 1) < 0) goto tfwb; if (fwrite_long(f, 0x52) < 0) goto tfwb; if (fwrite_8_chars(f, content->rom_version) < 0) goto tfwb; if (fwrite_word(f, content->type) < 0) goto tfwb; if (fwrite_word(f, 0) < 0) goto tfwb; if (fwrite_long(f, content->data_length + 0x52 + 2) < 0) goto tfwb; if (fwrite_word(f, 0x5aa5) < 0) goto tfwb; if (fwrite(content->data_part, 1, content->data_length, f) < content->data_length) goto tfwb; content->checksum = tifiles_checksum(content->data_part, content->data_length); if (fwrite_word(f, content->checksum) < 0) goto tfwb; fclose(f); return 0; tfwb: // release on exit tifiles_critical("%s: error writing file %s", __FUNCTION__, filename); fclose(f); return ERR_FILE_IO; }
/** * ti9x_file_write_regular: * @filename: name of single/group file where to write or NULL. * @content: the file content to write. * @real_filename: pointer address or NULL. Must be freed if needed when no longer needed. * * Write one (or several) variable(s) into a single (group) file. If filename is set to NULL, * the function build a filename from varname and allocates resulting filename in %real_fname. * %filename and %real_filename can be NULL but not both ! * * %real_filename must be freed when no longer used. * * Return value: an error code, 0 otherwise. **/ int ti9x_file_write_regular(const char *fname, Ti9xRegular *content, char **real_fname) { FILE *f; unsigned int i; char *filename = NULL; uint32_t offset = 0x52; int **table; unsigned int num_folders; char default_folder[FLDNAME_MAX]; char fldname[FLDNAME_MAX], varname[VARNAME_MAX]; if (content->entries == NULL) { tifiles_warning("%s: skipping content with NULL content->entries", __FUNCTION__); return 0; } if (fname != NULL) { filename = g_strdup(fname); if (filename == NULL) { return ERR_MALLOC; } } else { if (content->entries[0]) { filename = tifiles_build_filename(content->model_dst, content->entries[0]); } else { tifiles_warning("%s: asked to build a filename from null content->entries[0], bailing out", __FUNCTION__); if (real_fname != NULL) { *real_fname = NULL; } return 0; } if (real_fname != NULL) { *real_fname = g_strdup(filename); } } // build the table of folder & variable entries table = tifiles_create_table_of_entries((FileContent *)content, &num_folders); if (table == NULL) { g_free(filename); return ERR_MALLOC; } f = g_fopen(filename, "wb"); if (f == NULL) { tifiles_info( "Unable to open this file: %s", filename); tifiles_free_table_of_entries(table); g_free(filename); return ERR_FILE_OPEN; } // write header if (fwrite_8_chars(f, tifiles_calctype2signature(content->model)) < 0) goto tfwr; if (fwrite(fsignature, 1, 2, f) < 2) goto tfwr; if (content->num_entries == 1) // folder entry for single var is placed here { strncpy(content->default_folder, content->entries[0]->folder, sizeof(content->default_folder) - 1); content->default_folder[sizeof(content->default_folder) - 1] = 0; } ticonv_varname_to_tifile_sn(content->model, content->default_folder, default_folder, sizeof(default_folder), -1); if (fwrite_8_chars(f, default_folder) < 0) goto tfwr; if (fwrite_n_bytes(f, 40, (uint8_t *)content->comment) < 0) goto tfwr; if (content->num_entries > 1) { if (fwrite_word(f, (uint16_t) (content->num_entries + num_folders)) < 0) goto tfwr; offset += 16 * (content->num_entries + num_folders - 1); } else { if (fwrite_word(f, 1) < 0) goto tfwr; } // write table of entries for (i = 0; table[i] != NULL; i++) { VarEntry *fentry; int j, idx = table[i][0]; fentry = content->entries[idx]; if (fentry == NULL) { tifiles_warning("%s: skipping null content entry %d", __FUNCTION__, i); continue; } if (content->num_entries > 1) // single var does not have folder entry { if (fwrite_long(f, offset) < 0) goto tfwr; ticonv_varname_to_tifile_sn(content->model, fentry->folder, fldname, sizeof(fldname), -1); if (fwrite_8_chars(f, fldname) < 0) goto tfwr; if (fwrite_byte(f, (uint8_t)tifiles_folder_type(content->model)) < 0) goto tfwr; if (fwrite_byte(f, 0x00) < 0) goto tfwr; for (j = 0; table[i][j] != -1; j++); if (fwrite_word(f, (uint16_t) j) < 0) goto tfwr; } for (j = 0; table[i][j] != -1; j++) { int idx2 = table[i][j]; VarEntry *entry = content->entries[idx2]; uint8_t attr = ATTRB_NONE; if (fwrite_long(f, offset) < 0) goto tfwr; ticonv_varname_to_tifile_sn(content->model, entry->name, varname, sizeof(varname), entry->type); if (fwrite_8_chars(f, varname) < 0) goto tfwr; if (fwrite_byte(f, entry->type) < 0) goto tfwr; attr = (entry->attr == ATTRB_ARCHIVED) ? 3 : entry->attr; if (fwrite_byte(f, attr) < 0) goto tfwr; if (fwrite_word(f, 0) < 0) goto tfwr; offset += entry->size + 4 + 2; } } if (fwrite_long(f, offset) < 0) goto tfwr; if (fwrite_word(f, 0x5aa5) < 0) goto tfwr; // write data for (i = 0; table[i] != NULL; i++) { int j; for (j = 0; table[i][j] != -1; j++) { int idx = table[i][j]; VarEntry *entry = content->entries[idx]; uint16_t sum; if (fwrite_long(f, 0) < 0) goto tfwr; if (fwrite(entry->data, 1, entry->size, f) < entry->size) goto tfwr; sum = tifiles_checksum(entry->data, entry->size); if (fwrite_word(f, sum) < 0) goto tfwr; } } tifiles_free_table_of_entries(table); g_free(filename); fclose(f); return 0; tfwr: // release on exit tifiles_critical("%s: error writing file %s", __FUNCTION__, filename); tifiles_free_table_of_entries(table); g_free(filename); fclose(f); return ERR_FILE_IO; }