static void do_extract_png_or_jp2(deark *c, lctx *d, struct page_ctx *pg) { de_byte buf[8]; de_finfo *fi = NULL; de_dbg(c, "Trying to extract file at %d\n", (int)pg->image_pos); // Detect the format de_read(buf, pg->image_pos, sizeof(buf)); fi = de_finfo_create(c); de_finfo_set_name_from_sz(c, fi, pg->filename_token, DE_ENCODING_ASCII); if(buf[4]=='j' && buf[5]=='P') { dbuf_create_file_from_slice(c->infile, pg->image_pos, pg->image_len, "jp2", fi, 0); } else if(buf[0]==0x89 && buf[1]==0x50) { dbuf_create_file_from_slice(c->infile, pg->image_pos, pg->image_len, "png", fi, 0); } else { de_err(c, "(Image #%d) Unidentified file format\n", pg->image_num); } de_finfo_destroy(c, fi); }
static void handler_attachedfile_end(deark *c, lctx *d) { de_finfo *fi = NULL; if(!d->attachmentctx) goto done; if(d->attachmentctx->data_pos==0) goto done; fi = de_finfo_create(c); // TODO: We could do a better job of constructing filenames in various // situations. if(d->attachmentctx->filename && (d->attachmentctx->filename->len > 0) && c->filenames_from_file) { de_finfo_set_name_from_ucstring(c, fi, d->attachmentctx->filename, 0); } else { de_finfo_set_name_from_sz(c, fi, "bin", 0, DE_ENCODING_UTF8); } dbuf_create_file_from_slice(c->infile, d->attachmentctx->data_pos, d->attachmentctx->data_len, NULL, fi, DE_CREATEFLAG_IS_AUX); done: de_finfo_destroy(c, fi); destroy_attachment_data(c, d); }
static void handler_iccp(deark *c, lctx *d, struct handler_params *hp) { u8 cmpr_type; dbuf *f = NULL; struct de_stringreaderdata *prof_name_srd = NULL; de_finfo *fi = NULL; char prof_name2[100]; size_t prof_name2_strlen; i64 pos = hp->dpos; prof_name_srd = dbuf_read_string(c->infile, pos, 80, 80, DE_CONVFLAG_STOP_AT_NUL, DE_ENCODING_LATIN1); if(!prof_name_srd->found_nul) goto done; de_dbg(c, "profile name: \"%s\"", ucstring_getpsz_d(prof_name_srd->str)); pos += prof_name_srd->bytes_consumed; // Our working copy, to use as part of the filename. de_strlcpy(prof_name2, prof_name_srd->sz, sizeof(prof_name2)); if(!de_strcasecmp(prof_name2, "icc") || !de_strcasecmp(prof_name2, "icc profile")) { prof_name2[0] = '\0'; // Ignore generic name. } prof_name2_strlen = de_strlen(prof_name2); if(prof_name2_strlen>=5) { if(de_sz_has_ext(prof_name2, "icc")) { // If the name already ends in ".icc", chop it off so that we don't end // up with a double ".icc.icc" file extension. prof_name2[prof_name2_strlen-4] = '\0'; } } cmpr_type = de_getbyte_p(&pos); if(cmpr_type!=0) return; fi = de_finfo_create(c); if(c->filenames_from_file && prof_name2[0]) de_finfo_set_name_from_sz(c, fi, prof_name2, 0, DE_ENCODING_LATIN1); f = dbuf_create_output_file(c, "icc", fi, DE_CREATEFLAG_IS_AUX); de_decompress_deflate(c->infile, pos, hp->dlen - pos, f, 0, NULL, d->is_CgBI ? 0 : DE_DEFLATEFLAG_ISZLIB); done: dbuf_close(f); de_finfo_destroy(c, fi); de_destroy_stringreaderdata(c, prof_name_srd); }
static void read_face_name(deark *c, lctx *d) { char buf[50]; char buf2[50]; if(d->dfFace<1) return; if(!c->filenames_from_file) return; // The facename is terminated with a NUL byte. // There seems to be no defined limit to its length, but Windows font face // names traditionally have to be quite short. dbuf_read_sz(c->infile, d->dfFace, buf, sizeof(buf)); de_snprintf(buf2, sizeof(buf2), "%s-%d", buf, (int)d->dfPoints); d->fi = de_finfo_create(c); de_finfo_set_name_from_sz(c, d->fi, buf2, DE_ENCODING_ASCII); }
static void do_decode_image(deark *c, lctx *d, struct tgaimginfo *imginfo, dbuf *unc_pixels, const char *token, unsigned int createflags) { de_finfo *fi = NULL; fi = de_finfo_create(c); if(token) { de_finfo_set_name_from_sz(c, fi, token, 0, DE_ENCODING_LATIN1); } if(d->mod_time.is_valid) { fi->image_mod_time = d->mod_time; } do_decode_image_default(c, d, imginfo, unc_pixels, fi, createflags); de_finfo_destroy(c, fi); }
static void de_run_rpm(deark *c, de_module_params *mparams) { lctx *d = NULL; i64 pos; u8 buf[8]; const char *ext; i64 section_size = 0; de_finfo *fi = NULL; char filename[128]; d = de_malloc(c, sizeof(lctx)); if(!do_lead_section(c, d)) { goto done; } pos = 96; if(!do_header_structure(c, d, 1, pos, §ion_size)) { goto done; } pos += section_size; // Header structures are 8-byte aligned. The first one always starts at // offset 96, so we don't have to worry about it. But we need to make // sure the second one is aligned. pos = ((pos + 7)/8)*8; if(!do_header_structure(c, d, 0, pos, §ion_size)) { goto done; } pos += section_size; de_dbg(c, "data pos: %d", (int)pos); if(pos > c->infile->len) goto done; // There is usually a tag that indicates the compression format, but we // primarily figure out the format by sniffing its magic number, on the // theory that that's more reliable. // TODO: I think it's also theoretically possible that it could use an archive // format other than cpio. de_read(buf, pos, 8); if(buf[0]==0x1f && buf[1]==0x8b) { ext = "cpio.gz"; } else if(buf[0]==0x42 && buf[1]==0x5a && buf[2]==0x68) { ext = "cpio.bz2"; } else if(buf[0]==0xfd && buf[1]==0x37 && buf[2]==0x7a) { ext = "cpio.xz"; } else if(d->cmpr_type==DE_RPM_CMPR_LZMA || buf[0]==0x5d) { ext = "cpio.lzma"; } else { de_warn(c, "Unidentified compression or archive format"); ext = "cpio.bin"; } if(d->name_srd && c->filenames_from_file) { const char *version2 = "x"; const char *release2 = "x"; if(d->version_srd) version2 = d->version_srd->sz; if(d->release_srd) release2 = d->release_srd->sz; fi = de_finfo_create(c); de_snprintf(filename, sizeof(filename), "%s-%s.%s", d->name_srd->sz, version2, release2); de_finfo_set_name_from_sz(c, fi, filename, 0, DE_ENCODING_ASCII); } dbuf_create_file_from_slice(c->infile, pos, c->infile->len - pos, ext, fi, 0); done: de_finfo_destroy(c, fi); if(d) { de_destroy_stringreaderdata(c, d->name_srd); de_destroy_stringreaderdata(c, d->release_srd); de_destroy_stringreaderdata(c, d->version_srd); de_free(c, d); } }