summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
-rw-r--r--.whitesource11
-rw-r--r--README.md4
-rwxr-xr-xautogen.sh3
-rw-r--r--blacklist_cfi.txt5
-rw-r--r--configure.ac2
m---------doc0
-rw-r--r--doc/favicon.icobin2238 -> 0 bytes
-rw-r--r--doc/photorec.icobin2238 -> 0 bytes
-rw-r--r--src/Makefile.am52
-rw-r--r--src/addpart.h8
-rw-r--r--src/adv.h10
-rw-r--r--src/alignio.h64
-rw-r--r--src/analyse.c2
-rw-r--r--src/analyse.h2
-rw-r--r--src/askloc.h4
-rw-r--r--src/autoset.h4
-rw-r--r--src/bfs.c2
-rw-r--r--src/bfs.h13
-rw-r--r--src/bsd.h18
-rw-r--r--src/chgarch.h5
-rw-r--r--src/common.c40
-rw-r--r--src/common.h32
-rw-r--r--src/crc.c1
-rw-r--r--src/crc.h5
-rw-r--r--src/dfxml.c6
-rw-r--r--src/dfxml.h2
-rw-r--r--src/dir.c2
-rw-r--r--src/dir.h103
-rw-r--r--src/dir_common.h123
-rw-r--r--src/ewf.c243
-rw-r--r--src/ext2_dir.c1
-rw-r--r--src/fat.c16
-rw-r--r--src/fat.h230
-rw-r--r--src/fat1x.c2
-rw-r--r--src/fat_common.c1
-rw-r--r--src/fat_common.h110
-rw-r--r--src/fat_dir.c1
-rw-r--r--src/fat_dir.h1
-rw-r--r--src/fatn.c1
-rw-r--r--src/fidentify.c25
-rw-r--r--src/file_1cd.c4
-rw-r--r--src/file_3dm.c8
-rw-r--r--src/file_3ds.c76
-rw-r--r--src/file_7z.c5
-rw-r--r--src/file_DB.c2
-rw-r--r--src/file_a.c2
-rw-r--r--src/file_ab.c15
-rw-r--r--src/file_abr.c15
-rw-r--r--src/file_acb.c2
-rw-r--r--src/file_ace.c130
-rw-r--r--src/file_ado.c2
-rw-r--r--src/file_afdesign.c2
-rw-r--r--src/file_ahn.c2
-rw-r--r--src/file_aif.c2
-rw-r--r--src/file_all.c2
-rw-r--r--src/file_als.c2
-rw-r--r--src/file_amd.c2
-rw-r--r--src/file_amr.c15
-rw-r--r--src/file_apa.c2
-rw-r--r--src/file_ape.c2
-rw-r--r--src/file_apple.c2
-rw-r--r--src/file_ari.c2
-rw-r--r--src/file_arj.c2
-rw-r--r--src/file_asf.c2
-rw-r--r--src/file_asl.c2
-rw-r--r--src/file_asm.c19
-rw-r--r--src/file_atd.c2
-rw-r--r--src/file_au.c2
-rw-r--r--src/file_axp.c15
-rw-r--r--src/file_axx.c17
-rw-r--r--src/file_bac.c38
-rw-r--r--src/file_bdm.c2
-rw-r--r--src/file_berkeley.c2
-rw-r--r--src/file_bfa.c78
-rw-r--r--src/file_bim.c2
-rw-r--r--src/file_bin.c2
-rw-r--r--src/file_binvox.c2
-rw-r--r--src/file_bkf.c52
-rw-r--r--src/file_bld.c85
-rw-r--r--src/file_bmp.c2
-rw-r--r--src/file_bpg.c52
-rw-r--r--src/file_bvr.c5
-rw-r--r--src/file_bz2.c2
-rw-r--r--src/file_c4d.c2
-rw-r--r--src/file_cab.c2
-rw-r--r--src/file_caf.c9
-rw-r--r--src/file_cam.c2
-rw-r--r--src/file_catdrawing.c2
-rw-r--r--src/file_cdt.c2
-rw-r--r--src/file_che.c2
-rw-r--r--src/file_chm.c2
-rw-r--r--src/file_class.c2
-rw-r--r--src/file_cm.c2
-rw-r--r--src/file_compress.c2
-rw-r--r--src/file_cow.c2
-rw-r--r--src/file_cpi.c2
-rw-r--r--src/file_crw.c2
-rw-r--r--src/file_csh.c2
-rw-r--r--src/file_ctg.c2
-rw-r--r--src/file_cwk.c2
-rw-r--r--src/file_d2s.c4
-rw-r--r--src/file_dad.c5
-rw-r--r--src/file_dar.c2
-rw-r--r--src/file_dat.c2
-rw-r--r--src/file_dbf.c2
-rw-r--r--src/file_dbn.c2
-rw-r--r--src/file_dcm.c2
-rw-r--r--src/file_ddf.c2
-rw-r--r--src/file_dex.c2
-rw-r--r--src/file_dim.c2
-rw-r--r--src/file_dir.c32
-rw-r--r--src/file_djv.c2
-rw-r--r--src/file_dmp.c3
-rw-r--r--src/file_doc.c121
-rw-r--r--src/file_dpx.c2
-rw-r--r--src/file_drw.c2
-rw-r--r--src/file_ds2.c2
-rw-r--r--src/file_ds_store.c2
-rw-r--r--src/file_dsc.c2
-rw-r--r--src/file_dss.c2
-rw-r--r--src/file_dst.c2
-rw-r--r--src/file_dta.c2
-rw-r--r--src/file_dump.c2
-rw-r--r--src/file_dv.c23
-rw-r--r--src/file_dvi.c2
-rw-r--r--src/file_dvr.c2
-rw-r--r--src/file_dwg.c2
-rw-r--r--src/file_dxf.c5
-rw-r--r--src/file_e01.c29
-rw-r--r--src/file_ecryptfs.c2
-rw-r--r--src/file_edb.c2
-rw-r--r--src/file_elf.c2
-rw-r--r--src/file_emf.c2
-rw-r--r--src/file_ess.c2
-rw-r--r--src/file_evt.c9
-rw-r--r--src/file_evtx.c2
-rw-r--r--src/file_exe.c2
-rw-r--r--src/file_exr.c2
-rw-r--r--src/file_exs.c4
-rw-r--r--src/file_ext.c3
-rw-r--r--src/file_ext2.c4
-rw-r--r--src/file_fat.c16
-rw-r--r--src/file_fbf.c2
-rw-r--r--src/file_fbk.c2
-rw-r--r--src/file_fcp.c2
-rw-r--r--src/file_fcs.c87
-rw-r--r--src/file_fdb.c2
-rw-r--r--src/file_fds.c2
-rw-r--r--src/file_fh10.c2
-rw-r--r--src/file_fh5.c2
-rw-r--r--src/file_filevault.c2
-rw-r--r--src/file_fit.c2
-rw-r--r--src/file_fits.c36
-rw-r--r--src/file_flac.c9
-rw-r--r--src/file_flp.c2
-rw-r--r--src/file_flv.c5
-rw-r--r--src/file_fm.c4
-rw-r--r--src/file_fob.c2
-rw-r--r--src/file_fos.c2
-rw-r--r--src/file_fp5.c2
-rw-r--r--src/file_fp7.c2
-rw-r--r--src/file_freeway.c2
-rw-r--r--src/file_frm.c2
-rw-r--r--src/file_fs.c5
-rw-r--r--src/file_fwd.c2
-rw-r--r--src/file_gam.c2
-rw-r--r--src/file_gct.c2
-rw-r--r--src/file_gho.c2
-rw-r--r--src/file_gi.c4
-rw-r--r--src/file_gif.c111
-rw-r--r--src/file_gm6.c2
-rw-r--r--src/file_gp2.c2
-rw-r--r--src/file_gp5.c2
-rw-r--r--src/file_gpg.c16
-rw-r--r--src/file_gpx.c2
-rw-r--r--src/file_gsm.c25
-rw-r--r--src/file_gz.c43
-rw-r--r--src/file_hdf.c36
-rw-r--r--src/file_hdr.c2
-rw-r--r--src/file_hds.c2
-rw-r--r--src/file_hfsp.c2
-rw-r--r--src/file_hm.c2
-rw-r--r--src/file_hr9.c2
-rw-r--r--src/file_http.c2
-rw-r--r--src/file_ibd.c4
-rw-r--r--src/file_icc.c2
-rw-r--r--src/file_icns.c14
-rw-r--r--src/file_ico.c2
-rw-r--r--src/file_idx.c2
-rw-r--r--src/file_ifo.c2
-rw-r--r--src/file_imb.c2
-rw-r--r--src/file_indd.c15
-rw-r--r--src/file_info.c2
-rw-r--r--src/file_iso.c16
-rw-r--r--src/file_it.c2
-rw-r--r--src/file_itu.c2
-rw-r--r--src/file_jks.c2
-rw-r--r--src/file_jpg.c409
-rw-r--r--src/file_jsonlz4.c2
-rw-r--r--src/file_kdb.c2
-rw-r--r--src/file_kdbx.c2
-rw-r--r--src/file_key.c2
-rw-r--r--src/file_ldf.c2
-rw-r--r--src/file_list.c709
-rw-r--r--src/file_lit.c2
-rw-r--r--src/file_lnk.c37
-rw-r--r--src/file_logic.c2
-rw-r--r--src/file_lso.c2
-rw-r--r--src/file_luks.c2
-rw-r--r--src/file_lxo.c4
-rw-r--r--src/file_lzh.c11
-rw-r--r--src/file_lzo.c2
-rw-r--r--src/file_m2ts.c2
-rw-r--r--src/file_mat.c2
-rw-r--r--src/file_max.c2
-rw-r--r--src/file_mb.c2
-rw-r--r--src/file_mcd.c2
-rw-r--r--src/file_mdb.c2
-rw-r--r--src/file_mdf.c2
-rw-r--r--src/file_mdp.c69
-rw-r--r--src/file_mfa.c2
-rw-r--r--src/file_mfg.c2
-rw-r--r--src/file_mft.c4
-rw-r--r--src/file_mid.c2
-rw-r--r--src/file_mig.c2
-rw-r--r--src/file_mk5.c2
-rw-r--r--src/file_mkv.c2
-rw-r--r--src/file_mlv.c43
-rw-r--r--src/file_mobi.c2
-rw-r--r--src/file_mov.c11
-rw-r--r--src/file_mp3.c14
-rw-r--r--src/file_mpg.c2
-rw-r--r--src/file_mpl.c2
-rw-r--r--src/file_mrw.c2
-rw-r--r--src/file_msa.c2
-rw-r--r--src/file_mus.c2
-rw-r--r--src/file_mxf.c2
-rw-r--r--src/file_myo.c2
-rw-r--r--src/file_mysql.c2
-rw-r--r--src/file_nd2.c2
-rw-r--r--src/file_nds.c2
-rw-r--r--src/file_nes.c2
-rw-r--r--src/file_njx.c2
-rw-r--r--src/file_nk2.c2
-rw-r--r--src/file_nsf.c2
-rw-r--r--src/file_oci.c2
-rw-r--r--src/file_ogg.c2
-rw-r--r--src/file_one.c2
-rw-r--r--src/file_orf.c2
-rw-r--r--src/file_paf.c2
-rw-r--r--src/file_pap.c2
-rw-r--r--src/file_par2.c2
-rw-r--r--src/file_pcap.c2
-rw-r--r--src/file_pcb.c2
-rw-r--r--src/file_pct.c2
-rw-r--r--src/file_pcx.c3
-rw-r--r--src/file_pdb.c2
-rw-r--r--src/file_pdf.c2
-rw-r--r--src/file_pds.c2
-rw-r--r--src/file_pf.c2
-rw-r--r--src/file_pfx.c2
-rw-r--r--src/file_pgdump.c2
-rw-r--r--src/file_plist.c2
-rw-r--r--src/file_plr.c2
-rw-r--r--src/file_plt.c2
-rw-r--r--src/file_png.c2
-rw-r--r--src/file_pnm.c2
-rw-r--r--src/file_prc.c2
-rw-r--r--src/file_prd.c2
-rw-r--r--src/file_prt.c2
-rw-r--r--src/file_ps.c2
-rw-r--r--src/file_psb.c2
-rw-r--r--src/file_psd.c2
-rw-r--r--src/file_psf.c2
-rw-r--r--src/file_psp.c2
-rw-r--r--src/file_pst.c2
-rw-r--r--src/file_ptb.c2
-rw-r--r--src/file_ptf.c2
-rw-r--r--src/file_pyc.c2
-rw-r--r--src/file_pzf.c2
-rw-r--r--src/file_pzh.c2
-rw-r--r--src/file_qbb.c9
-rw-r--r--src/file_qdf.c6
-rw-r--r--src/file_qkt.c2
-rw-r--r--src/file_qxd.c2
-rw-r--r--src/file_r3d.c2
-rw-r--r--src/file_ra.c2
-rw-r--r--src/file_raf.c2
-rw-r--r--src/file_rar.c2
-rw-r--r--src/file_raw.c2
-rw-r--r--src/file_rdc.c2
-rw-r--r--src/file_reg.c2
-rw-r--r--src/file_res.c2
-rw-r--r--src/file_rfp.c2
-rw-r--r--src/file_riff.c2
-rw-r--r--src/file_rlv.c2
-rw-r--r--src/file_rm.c2
-rw-r--r--src/file_rns.c2
-rw-r--r--src/file_rpm.c2
-rw-r--r--src/file_rw2.c2
-rw-r--r--src/file_rx2.c2
-rw-r--r--src/file_save.c2
-rw-r--r--src/file_sdsk.c2
-rw-r--r--src/file_ses.c2
-rw-r--r--src/file_sgcta.c2
-rw-r--r--src/file_shn.c2
-rw-r--r--src/file_sib.c2
-rw-r--r--src/file_sig.c7
-rw-r--r--src/file_sit.c2
-rw-r--r--src/file_skd.c2
-rw-r--r--src/file_skp.c2
-rw-r--r--src/file_snag.c2
-rw-r--r--src/file_sp3.c2
-rw-r--r--src/file_spe.c2
-rw-r--r--src/file_spf.c2
-rw-r--r--src/file_spss.c2
-rw-r--r--src/file_sql.c2
-rw-r--r--src/file_sqm.c2
-rw-r--r--src/file_steuer2014.c2
-rw-r--r--src/file_stl.c2
-rw-r--r--src/file_stu.c2
-rw-r--r--src/file_studio.c2
-rw-r--r--src/file_swf.c2
-rw-r--r--src/file_tar.c14
-rw-r--r--src/file_tax.c2
-rw-r--r--src/file_template.c2
-rw-r--r--src/file_tg.c2
-rw-r--r--src/file_tib.c2
-rw-r--r--src/file_tiff.c6
-rw-r--r--src/file_tiff.h50
-rw-r--r--src/file_tiff_be.c17
-rw-r--r--src/file_tiff_le.c36
-rw-r--r--src/file_tivo.c2
-rw-r--r--src/file_torrent.c2
-rw-r--r--src/file_tph.c2
-rw-r--r--src/file_tpl.c2
-rw-r--r--src/file_ttf.c2
-rw-r--r--src/file_txt.c41
-rw-r--r--src/file_tz.c2
-rw-r--r--src/file_v2i.c2
-rw-r--r--src/file_vault.c2
-rw-r--r--src/file_vdi.c2
-rw-r--r--src/file_vdj.c2
-rw-r--r--src/file_veg.c2
-rw-r--r--src/file_vfb.c2
-rw-r--r--src/file_vib.c2
-rw-r--r--src/file_vmdk.c2
-rw-r--r--src/file_vmg.c2
-rw-r--r--src/file_wallet.c2
-rw-r--r--src/file_wdp.c2
-rw-r--r--src/file_wee.c2
-rw-r--r--src/file_wim.c2
-rw-r--r--src/file_win.c2
-rw-r--r--src/file_wks.c2
-rw-r--r--src/file_wld.c2
-rw-r--r--src/file_wmf.c2
-rw-r--r--src/file_wnk.c2
-rw-r--r--src/file_woff.c2
-rw-r--r--src/file_wpb.c2
-rw-r--r--src/file_wpd.c2
-rw-r--r--src/file_wtv.c2
-rw-r--r--src/file_wv.c2
-rw-r--r--src/file_x3f.c2
-rw-r--r--src/file_x3i.c2
-rw-r--r--src/file_x4a.c2
-rw-r--r--src/file_xar.c2
-rw-r--r--src/file_xcf.c2
-rw-r--r--src/file_xfi.c2
-rw-r--r--src/file_xfs.c2
-rw-r--r--src/file_xm.c2
-rw-r--r--src/file_xml.c2
-rw-r--r--src/file_xpt.c2
-rw-r--r--src/file_xsv.c2
-rw-r--r--src/file_xv.c2
-rw-r--r--src/file_xz.c2
-rw-r--r--src/file_z2d.c2
-rw-r--r--src/file_zcode.c2
-rw-r--r--src/file_zip.c384
-rw-r--r--src/file_zpr.c2
-rw-r--r--src/filegen.c166
-rw-r--r--src/filegen.h21
-rw-r--r--src/fnctdsk.c28
-rw-r--r--src/fnctdsk.h163
-rw-r--r--src/geometry.c1
-rw-r--r--src/geometry.h21
-rw-r--r--src/gfs2.c2
-rw-r--r--src/gfs2.h2
-rw-r--r--src/guid_cmp.h4
-rw-r--r--src/guid_cpy.h9
-rw-r--r--src/hdaccess.c6
-rw-r--r--src/hdaccess.h78
-rw-r--r--src/hdcache.c91
-rw-r--r--src/hdcache.h4
-rw-r--r--src/hfs.c4
-rw-r--r--src/hfs.h26
-rw-r--r--src/hfsp.c2
-rw-r--r--src/hfsp.h2
-rw-r--r--src/hpfs.c4
-rw-r--r--src/hpfs.h2
-rw-r--r--src/intrf.c4
-rw-r--r--src/intrf.h11
-rw-r--r--src/iso.c24
-rw-r--r--src/iso.h11
-rw-r--r--src/iso9660.h6
-rw-r--r--src/jfs.h14
-rw-r--r--src/list.h4
-rw-r--r--src/log.c11
-rw-r--r--src/log.h21
-rw-r--r--src/lvm.h30
-rw-r--r--src/md.c4
-rw-r--r--src/md.h20
-rw-r--r--src/misc.c7
-rw-r--r--src/misc.h5
-rw-r--r--src/msdos.c16
-rw-r--r--src/netware.h12
-rw-r--r--src/ntfs_udl.c4
-rw-r--r--src/ntfs_utl.c6
-rw-r--r--src/partauto.c14
-rw-r--r--src/partauto.h5
-rw-r--r--src/partgpt.c63
-rw-r--r--src/partgpt.h15
-rw-r--r--src/parthumax.c68
-rw-r--r--src/parti386.c208
-rw-r--r--src/parti386.h21
-rw-r--r--src/partmac.c67
-rw-r--r--src/partmac.h2
-rw-r--r--src/partnone.c72
-rw-r--r--src/partsun.c76
-rw-r--r--src/partxbox.c71
-rw-r--r--src/pdiskseln.h8
-rw-r--r--src/phcli.c5
-rw-r--r--src/phcli.h6
-rw-r--r--src/phmain.c18
-rw-r--r--src/phnc.h6
-rw-r--r--src/photorec.c11
-rw-r--r--src/photorec.h24
-rw-r--r--src/photorec_check_header.h55
-rw-r--r--src/poptions.c1
-rw-r--r--src/poptions.h10
-rw-r--r--src/psearchn.c62
-rw-r--r--src/qpsearch.cpp56
-rw-r--r--src/rfs.h16
-rw-r--r--src/sun.h16
-rw-r--r--src/suspend_no.c3
-rw-r--r--src/swap.h11
-rw-r--r--src/ufs.h15
-rw-r--r--src/win32.c6
-rw-r--r--src/xfs.h15
-rw-r--r--src/zfs.h17
450 files changed, 5601 insertions, 1197 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..8d98afa
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "doc"]
+ path = doc
+ url = https://github.com/cgsecurity/testdisk_documentation.git
diff --git a/.whitesource b/.whitesource
new file mode 100644
index 0000000..004ba82
--- /dev/null
+++ b/.whitesource
@@ -0,0 +1,11 @@
+{
+ "scanSettings": {
+ "baseBranches": []
+ },
+ "checkRunSettings": {
+ "vulnerableCheckRunConclusionLevel": "failure"
+ },
+ "issueSettings": {
+ "minSeverityLevel": "LOW"
+ }
+} \ No newline at end of file
diff --git a/README.md b/README.md
index a139291..f1a6577 100644
--- a/README.md
+++ b/README.md
@@ -66,6 +66,10 @@ TestDisk and PhotoRec run under:
Both are under GNU General Public License.
+To build from source, read [INSTALL](INSTALL)
+
+See also [latest documentation](https://github.com/cgsecurity/testdisk_documentation)
+
Christophe GRENIER
[grenier@cgsecurity.org](mailto:grenier@cgsecurity.org)
[https://www.cgsecurity.org/](https://www.cgsecurity.org/)
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..9022bc3
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+mkdir config
+autoreconf --install -W all -I config
diff --git a/blacklist_cfi.txt b/blacklist_cfi.txt
new file mode 100644
index 0000000..e785280
--- /dev/null
+++ b/blacklist_cfi.txt
@@ -0,0 +1,5 @@
+# https://clang.llvm.org/docs/ControlFlowIntegrity.html
+# export CC="clang -flto -fsanitize=cfi -fvisibility=default -fsanitize-blacklist=blacklist_cfi.txt"
+# export CXX="clang++ -flto -fsanitize=cfi -fvisibility=default -fsanitize-blacklist=blacklist_cfi.txt"
+[cfi-icall]
+fun:jpeg_testdisk_alloc_src
diff --git a/configure.ac b/configure.ac
index 7769464..0c006eb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6,7 +6,7 @@ AC_INIT([testdisk],[7.2-WIP],[grenier@cgsecurity.org])
AC_LANG(C)
sinclude(acx_pthread.m4)
sinclude(mkdir.m4)
-TESTDISKDATE="May 2020"
+TESTDISKDATE="September 2020"
AC_SUBST(TESTDISKDATE)
AC_DEFINE_UNQUOTED([TESTDISKDATE],"$TESTDISKDATE",[Date of release])
AC_CONFIG_AUX_DIR(config)
diff --git a/doc b/doc
new file mode 160000
+Subproject becbcc35956102e064fc603720182113d887a18
diff --git a/doc/favicon.ico b/doc/favicon.ico
deleted file mode 100644
index d9c1441..0000000
--- a/doc/favicon.ico
+++ /dev/null
Binary files differ
diff --git a/doc/photorec.ico b/doc/photorec.ico
deleted file mode 100644
index 74aa854..0000000
--- a/doc/photorec.ico
+++ /dev/null
Binary files differ
diff --git a/src/Makefile.am b/src/Makefile.am
index aea1b3b..a9736d2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-.PRECIOUS: session_%.framac
+.PRECIOUS: session_%.framac session_fidentify-%.framac
FRAMA_C_FLAGS=-machdep x86_64 \
-warn-left-shift-negative \
-warn-right-shift-negative \
@@ -16,7 +16,7 @@ FRAMA_C_FLAGS=-machdep x86_64 \
-wp-dynamic \
-wp-steps 100000 \
-wp-split -wp-literals \
- -wp-timeout 10 -pp-annot \
+ -wp-timeout 5 -pp-annot \
-kernel-msg-key pp
.rc.o:
@@ -44,12 +44,13 @@ fs_H = analyse.h bfs.h bsd.h btrfs.h cramfs.h exfat.h ext2.h ext2_common.h fat
testdisk_ncurses_C = addpart.c addpartn.c adv.c askloc.c chgarch.c chgarchn.c chgtype.c chgtypen.c dimage.c dirn.c dirpart.c diskacc.c diskcapa.c edit.c ext2_sb.c ext2_sbn.c fat1x.c fat32.c fat_adv.c fat_cluster.c fatn.c geometry.c geometryn.c godmode.c hiddenn.c intrface.c intrfn.c nodisk.c ntfs_adv.c ntfs_fix.c ntfs_udl.c parti386n.c partgptn.c partmacn.c partsunn.c partxboxn.c tanalyse.c tbanner.c tdelete.c tdiskop.c tdisksel.c testdisk.c texfat.c thfs.c tload.c tlog.c tmbrcode.c tntfs.c toptions.c tpartwr.c
testdisk_ncurses_H = addpart.h addpartn.h adv.h askloc.h chgarch.h chgarchn.h chgtype.h chgtypen.h dimage.h dirn.h dirpart.h diskacc.h diskcapa.h edit.h ext2_sb.h ext2_sbn.h fat1x.h fat32.h fat_adv.h fat_cluster.h fatn.h geometry.h geometryn.h godmode.h hiddenn.h intrface.h intrfn.h nodisk.h ntfs_fix.h ntfs_udl.h partgptn.h parti386n.h partmacn.h partsunn.h partxboxn.h tanalyse.h tdelete.h tdiskop.h tdisksel.h texfat.h thfs.h tload.h tlog.h tmbrcode.h tntfs.h toptions.h tpartwr.h
-testdisk_SOURCES = $(base_C) $(base_H) $(fs_C) $(fs_H) $(testdisk_ncurses_C) $(testdisk_ncurses_H) dir.c dir.h exfat_dir.c exfat_dir.h ext2_dir.c ext2_dir.h ext2_inc.h fat_dir.c fat_dir.h ntfs_dir.c ntfs_dir.h ntfs_inc.h partgptw.c rfs_dir.c rfs_dir.h setdate.c setdate.h $(ICON_TESTDISK) next.c next.h
+testdisk_SOURCES = $(base_C) $(base_H) $(fs_C) $(fs_H) $(testdisk_ncurses_C) $(testdisk_ncurses_H) dir.c dir.h dir_common.h exfat_dir.c exfat_dir.h ext2_dir.c ext2_dir.h ext2_inc.h fat_dir.c fat_dir.h ntfs_dir.c ntfs_dir.h ntfs_inc.h partgptw.c rfs_dir.c rfs_dir.h setdate.c setdate.h $(ICON_TESTDISK) next.c next.h
file_C = filegen.c \
file_list.c \
file_1cd.c \
file_3dm.c \
+ file_3ds.c \
file_7z.c \
file_DB.c \
file_a.c \
@@ -80,6 +81,7 @@ file_C = filegen.c \
file_bac.c \
file_bdm.c \
file_berkeley.c \
+ file_bfa.c \
file_bim.c \
file_bin.c \
file_binvox.c \
@@ -224,6 +226,7 @@ file_C = filegen.c \
file_mcd.c \
file_mdb.c \
file_mdf.c \
+ file_mdp.c \
file_mfa.c \
file_mfg.c \
file_mft.c \
@@ -386,7 +389,7 @@ file_H = ext2.h ext2_common.h filegen.h file_doc.h file_jpg.h file_gz.h file_s
photorec_C = photorec.c phcfg.c addpart.c chgarch.c dir.c exfatp.c ext2grp.c ext2_dir.c ext2p.c fat_dir.c fatp.c file_found.c geometry.c ntfs_dir.c ntfsp.c pdisksel.c poptions.c sessionp.c setdate.c dfxml.c
-photorec_H = photorec.h phcfg.h addpart.h chgarch.h dir.h exfatp.h ext2grp.h ext2p.h ext2_dir.h ext2_inc.h fat_dir.h fatp.h file_found.h geometry.h memmem.h ntfs_dir.h ntfsp.h ntfs_inc.h pdisksel.h poptions.h sessionp.h setdate.h dfxml.h
+photorec_H = photorec.h phcfg.h addpart.h chgarch.h dir_common.h dir.h exfatp.h ext2grp.h ext2p.h ext2_dir.h ext2_inc.h fat_dir.h fatp.h file_found.h geometry.h memmem.h ntfs_dir.h ntfsp.h ntfs_inc.h pdisksel.h poptions.h sessionp.h setdate.h dfxml.h
photorec_ncurses_C = addpartn.c askloc.c chgarchn.c chgtype.c chgtypen.c fat_cluster.c fat_unformat.c geometryn.c hiddenn.c intrfn.c nodisk.c parti386n.c partgptn.c partmacn.c partsunn.c partxboxn.c pbanner.c pblocksize.c pdiskseln.c pfree_whole.c phbf.c phbs.c phcli.c phnc.c phrecn.c ppartseln.c psearchn.c
photorec_ncurses_H = addpartn.h askloc.h chgarchn.h chgtype.h chgtypen.h fat_cluster.h fat_unformat.h geometryn.h hiddenn.h intrfn.h nodisk.h parti386n.h partgptn.h partmacn.h partsunn.h partxboxn.h pblocksize.h pdiskseln.h pfree_whole.h pnext.h phbf.h phbs.h phcli.h phnc.h phrecn.h ppartseln.h psearch.h psearchn.h photorec_check_header.h
@@ -411,10 +414,13 @@ qphotorec_SOURCES = qmainrec.cpp qphotorec.cpp qphotorec.h qphotorec.qrc qphotor
nodist_qphotorec_SOURCES = moc_qphotorec.cpp rcc_qphotorec.cpp rcc_qphotorec_locale.cpp
-fidentify_SOURCES = fidentify.c common.c common.h misc.c misc.h phcfg.c phcfg.h setdate.c setdate.h $(file_C) $(file_H) log.c log.h crc.c crc.h ext2_common.c fat_common.c fat_common.h suspend_no.c
+fidentify_C_SOURCES = fidentify.c common.c misc.c phcfg.c setdate.c $(file_C) log.c crc.c ext2_common.c fat_common.c suspend_no.c
+fidentify_H_SOURCES = common.h misc.h phcfg.h setdate.h $(file_H) log.h crc.h fat_common.h
+fidentify_SOURCES = $(fidentify_C_SOURCES) $(fidentify_H_SOURCES)
fuzzerfidentify_SOURCES = fuzzerfidentify.cpp common.c common.h misc.c misc.h phcfg.c phcfg.h setdate.c setdate.h $(file_C) $(file_H) log.c log.h crc.c crc.h ext2_common.c fat_common.c fat_common.h suspend_no.c
+
QT_QM=$(QT_TS:.ts=.qm)
SECONDARY: $(QT_QM)
@@ -430,29 +436,41 @@ frama-c-%: session_%.framac
frama-c-gui -load $^
session_doc.framac: file_doc.c common.c filegen.c log.c setdate.c
- gcc $(CFLAGS) -DMAIN_doc -DHAVE_CONFIG_H -O -o demo -I.. $^
- frama-c $^ -cpp-extra-args="-DMAIN_doc -DHAVE_CONFIG_H -D__x86_64__ -I.." $(FRAMA_C_FLAGS) -save $@
+ gcc $(CFLAGS) -DMAIN_doc -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_doc -O -o demo -I.. $^
+ frama-c $^ -cpp-extra-args="-DMAIN_doc -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_doc -D__x86_64__ -I.." $(FRAMA_C_FLAGS) -save $@
session_jpg.framac: file_jpg.c file_tiff.c file_tiff_be.c file_tiff_le.c common.c filegen.c log.c suspend_no.c setdate.c
- gcc $(CFLAGS) -DMAIN_jpg -DHAVE_CONFIG_H -O -o demo -I.. $^ -ljpeg
- frama-c $^ -cpp-extra-args="-DMAIN_jpg -DHAVE_CONFIG_H -D__x86_64__ -I/usr/include -I.. -I $(frama-c -print-path)/libc" $(FRAMA_C_FLAGS) -save $@ 2>&1 | tee session_jpg.log
+ gcc $(CFLAGS) -DMAIN_jpg -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_jpg -O -o demo -I.. $^ -ljpeg
+ frama-c $^ -cpp-extra-args="-DMAIN_jpg -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_jpg -D__x86_64__ -I/usr/include -I.. -I $(frama-c -print-path)/libc" $(FRAMA_C_FLAGS) -save $@
+
+session_swf.framac: file_swf.c common.c filegen.c log.c
+ gcc $(CFLAGS) -DMAIN_swf -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_swf -O -o demo -I.. $^ -lz
+ frama-c $^ -cpp-extra-args="-DMAIN_swf -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_swf -D__x86_64__ -I.." $(FRAMA_C_FLAGS) -save $@
session_tiff_be.framac: file_tiff.c file_tiff_be.c file_tiff_le.c common.c filegen.c log.c
- gcc $(CFLAGS) -DMAIN_tiff_le -DHAVE_CONFIG_H -O -o demo -I.. $^
- frama-c $^ -cpp-extra-args="-DMAIN_tiff_be -DHAVE_CONFIG_H -D__x86_64__ -I.." $(FRAMA_C_FLAGS) -save $@
+ gcc $(CFLAGS) -DMAIN_tiff_le -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_tiff -O -o demo -I.. $^
+ frama-c $^ -cpp-extra-args="-DMAIN_tiff_be -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_tiff -D__x86_64__ -I.." $(FRAMA_C_FLAGS) -save $@
session_tiff_le.framac: file_tiff.c file_tiff_be.c file_tiff_le.c common.c filegen.c log.c
- gcc $(CFLAGS) -DMAIN_tiff_le -DHAVE_CONFIG_H -O -o demo -I.. $^
- frama-c $^ -cpp-extra-args="-DMAIN_tiff_le -DHAVE_CONFIG_H -D__x86_64__ -I.." $(FRAMA_C_FLAGS) -save $@
+ gcc $(CFLAGS) -DMAIN_tiff_le -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_tiff -O -o demo -I.. $^
+ frama-c $^ -cpp-extra-args="-DMAIN_tiff_le -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_tiff -D__x86_64__ -I.." $(FRAMA_C_FLAGS) -save $@
session_%.framac: file_%.c common.c filegen.c log.c
- gcc $(CFLAGS) -DMAIN_$* -DHAVE_CONFIG_H -O -o demo -I.. $^
- frama-c $^ -cpp-extra-args="-DMAIN_$* -DHAVE_CONFIG_H -D__x86_64__ -I.." $(FRAMA_C_FLAGS) -save $@
+ gcc $(CFLAGS) -DMAIN_$* -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_$* -O -o demo -I.. $^
+ frama-c $^ -cpp-extra-args="-DMAIN_$* -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_$* -D__x86_64__ -I.." $(FRAMA_C_FLAGS) -save $@
-session_fidentify.framac: fidentify.c common.c misc.c filegen.c log.c setdate.c file_bmp.c file_list.c
- gcc $(CFLAGS) -DMAIN_fidentify -DHAVE_CONFIG_H -O -o demo -I.. $^
+session_fidentify-%.framac: $(fidentify_C_SOURCES)
+ gcc -o fidentify_$* -O -DMAIN_fidentify -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_$* -D__x86_64__ -I.. $^
+ frama-c $^ -cpp-extra-args="-DMAIN_fidentify -DHAVE_CONFIG_H -DSINGLE_FORMAT -DSINGLE_FORMAT_$* -D__x86_64__ -I.." $(FRAMA_C_FLAGS) -save $@
+
+session_fidentify.framac: fidentify.c common.c misc.c log.c setdate.c filegen.c file_list.c file_gz.c
+ gcc -O $(CFLAGS) -DMAIN_fidentify -DHAVE_CONFIG_H -O -o demo -I.. $^
frama-c $^ -cpp-extra-args="-DMAIN_fidentify -DHAVE_CONFIG_H -D__x86_64__ -I.." $(FRAMA_C_FLAGS) -save $@
+session_photorec.framac: phmain.c $(photorec_C) filegen.c file_list.c file_bmp.c file_tar.c $(base_C) partgptro.c $(fs_C) chgtype.c pdiskseln.c phcli.c ppartseln.c askloc.c phrecn.c psearchn.c phbs.c phbf.c fat_unformat.c fat_cluster.c intrfn.c file_dir.c
+# gcc $(CFLAGS) -DMAIN_photorec -DHAVE_CONFIG_H -O -o demo -I.. $^
+ frama-c $^ -cpp-extra-args="-DMAIN_photorec -DHAVE_CONFIG_H -D__x86_64__ -I.." $(FRAMA_C_FLAGS) -save $@
+
moc_qphotorec.cpp: qphotorec.h
$(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(MOC) $< -o $@
diff --git a/src/addpart.h b/src/addpart.h
index ab66262..cae5f1c 100644
--- a/src/addpart.h
+++ b/src/addpart.h
@@ -20,4 +20,12 @@
*/
+/*@
+ @ requires \valid(disk);
+ @ requires list_part == \null || \valid_read(list_part);
+ @ requires \valid(current_cmd);
+ @ requires valid_read_string(*current_cmd);
+ @ requires separation: \separated(disk, list_part, current_cmd);
+ @ ensures valid_read_string(*current_cmd);
+ @*/
list_part_t *add_partition_cli(disk_t *disk, list_part_t *list_part, char **current_cmd);
diff --git a/src/adv.h b/src/adv.h
index 339ecf5..b62033e 100644
--- a/src/adv.h
+++ b/src/adv.h
@@ -23,7 +23,17 @@
extern "C" {
#endif
+/*@
+ @ requires \valid(disk_car);
+ @ requires \valid(current_cmd);
+ @ requires valid_string(*current_cmd);
+ @*/
void interface_adv(disk_t *disk_car, const int verbose,const int dump_ind, const unsigned int expert, char**current_cmd);
+
+/*@
+ @ requires \valid_read(partition);
+ @ assigns \nothing;
+ @*/
int is_part_linux(const partition_t *partition);
#ifdef __cplusplus
diff --git a/src/alignio.h b/src/alignio.h
index 8bd1344..0541f6b 100644
--- a/src/alignio.h
+++ b/src/alignio.h
@@ -19,11 +19,26 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-static int align_pread(int (*fnct_pread)(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset),
+
+/*@
+ @ requires \valid_function(fnct_pread);
+ @ requires \valid(disk_car);
+ @ requires disk_car->sector_size > 0;
+ @ requires disk_car->offset < 0x8000000000000000;
+ @ requires 0 < count < 0x8000000000000000;
+ @ requires offset < 0x8000000000000000;
+ @ requires \valid((char *)buf + (0 .. count -1));
+ @ requires disk_car->rbuffer == \null || (\freeable(disk_car->rbuffer) && disk_car->rbuffer_size > 0);
+ @ ensures disk_car->rbuffer == \null || (\freeable(disk_car->rbuffer) && disk_car->rbuffer_size > 0);
+ @*/
+static int align_pread(int (*fnct_pread)(const disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset),
disk_t *disk_car, void*buf, const unsigned int count, const uint64_t offset)
{
const uint64_t offset_new=offset+disk_car->offset;
const unsigned int count_new=((offset_new%disk_car->sector_size)+count+disk_car->sector_size-1)/disk_car->sector_size*disk_car->sector_size;
+ /*@ assert count_new >= count; */
+ /*@ assert count_new >= disk_car->sector_size; */
+ /*@ assert count_new > 0; */
if(count!=count_new ||
((disk_car->access_mode&TESTDISK_O_DIRECT)!=0 &&
(((size_t)(buf) & (disk_car->sector_size-1))!=0) &&
@@ -31,24 +46,44 @@ static int align_pread(int (*fnct_pread)(disk_t *disk_car, void *buf, const unsi
)
{
int res;
- if(disk_car->rbuffer==NULL)
- disk_car->rbuffer_size=128*512;
- while(disk_car->rbuffer_size < count_new)
+ if(disk_car->rbuffer_size < count_new)
{
free(disk_car->rbuffer);
disk_car->rbuffer=NULL;
- disk_car->rbuffer_size*=2;
}
if(disk_car->rbuffer==NULL)
+ {
+ disk_car->rbuffer_size=128*512;
+ /*@ loop assigns disk_car->rbuffer_size; */
+ while(disk_car->rbuffer_size < count_new)
+ {
+ disk_car->rbuffer_size*=2;
+ }
+ /*@ assert disk_car->rbuffer_size >= count_new; */
disk_car->rbuffer=(char*)MALLOC(disk_car->rbuffer_size);
+ }
+ /*@ assert \freeable(disk_car->rbuffer); */
res=fnct_pread(disk_car, disk_car->rbuffer, count_new, offset_new/disk_car->sector_size*disk_car->sector_size);
memcpy(buf,(char*)disk_car->rbuffer+(offset_new%disk_car->sector_size),count);
+ /*@ assert \freeable(disk_car->rbuffer) && disk_car->rbuffer_size > 0; */
return (res < (signed)count ? res : (signed)count );
}
return fnct_pread(disk_car, buf, count, offset_new);
}
-static int align_pwrite(int (*fnct_pread)(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset),
+/*@
+ @ requires \valid_function(fnct_pread);
+ @ requires \valid_function(fnct_pwrite);
+ @ requires \valid(disk_car);
+ @ requires disk_car->sector_size > 0;
+ @ requires disk_car->offset < 0x8000000000000000;
+ @ requires 0 < count < 0x8000000000000000;
+ @ requires offset < 0x8000000000000000;
+ @ requires \valid_read((char *)buf + (0 .. count -1));
+ @ requires disk_car->wbuffer == \null || \freeable(disk_car->wbuffer);
+ @ ensures disk_car->wbuffer == \null || \freeable(disk_car->wbuffer);
+ @*/
+static int align_pwrite(int (*fnct_pread)(const disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset),
int (*fnct_pwrite)(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset),
disk_t *disk_car, const void*buf, const unsigned int count, const uint64_t offset)
{
@@ -60,16 +95,23 @@ static int align_pwrite(int (*fnct_pread)(disk_t *disk_car, void *buf, const uns
)
{
int tmp;
- if(disk_car->wbuffer==NULL)
- disk_car->wbuffer_size=128*512;
- while(disk_car->wbuffer_size < count_new)
+ if(disk_car->wbuffer_size < count_new)
{
free(disk_car->wbuffer);
disk_car->wbuffer=NULL;
- disk_car->wbuffer_size*=2;
}
if(disk_car->wbuffer==NULL)
+ {
+ disk_car->wbuffer_size=128*512;
+ /*@ loop assigns disk_car->wbuffer_size; */
+ while(disk_car->wbuffer_size < count_new)
+ {
+ disk_car->wbuffer_size*=2;
+ }
+ /*@ assert disk_car->wbuffer_size >= count_new; */
disk_car->wbuffer=(char*)MALLOC(disk_car->wbuffer_size);
+ }
+ /*@ assert \freeable(disk_car->wbuffer); */
if(fnct_pread(disk_car, disk_car->wbuffer, count_new, offset_new/disk_car->sector_size*disk_car->sector_size)<0)
{
log_error("read failed but trying to write anyway");
@@ -77,8 +119,8 @@ static int align_pwrite(int (*fnct_pread)(disk_t *disk_car, void *buf, const uns
}
memcpy((char*)disk_car->wbuffer+(offset_new%disk_car->sector_size),buf,count);
tmp=fnct_pwrite(disk_car, disk_car->wbuffer, count_new, offset_new/disk_car->sector_size*disk_car->sector_size);
+ /*@ assert \freeable(disk_car->wbuffer) && disk_car->wbuffer_size > 0; */
return (tmp < (signed)count ? tmp : (signed)count);
}
return fnct_pwrite(disk_car, buf, count, offset_new);
}
-
diff --git a/src/analyse.c b/src/analyse.c
index b121986..46cf036 100644
--- a/src/analyse.c
+++ b/src/analyse.c
@@ -220,7 +220,7 @@ int search_type_0(const unsigned char *buffer, disk_t *disk, partition_t *partit
return 0;
}
-int search_type_1(const unsigned char *buffer, disk_t *disk, partition_t *partition, const int verbose, const int dump_ind)
+int search_type_1(const unsigned char *buffer, const disk_t *disk, partition_t *partition, const int verbose, const int dump_ind)
{
const struct disklabel *bsd_header=(const struct disklabel *)(buffer+0x200);
const struct disk_super_block *beos_block=(const struct disk_super_block*)(buffer+0x200);
diff --git a/src/analyse.h b/src/analyse.h
index 82c1b61..aaf1002 100644
--- a/src/analyse.h
+++ b/src/analyse.h
@@ -24,7 +24,7 @@ extern "C" {
#endif
int search_type_0(const unsigned char *buffer, disk_t *disk_car,partition_t *partition,const int verbose, const int dump_ind);
-int search_type_1(const unsigned char *buffer, disk_t *disk_car,partition_t *partition,const int verbose, const int dump_ind);
+int search_type_1(const unsigned char *buffer, const disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind);
int search_type_2(const unsigned char *buffer, disk_t *disk_car,partition_t *partition,const int verbose, const int dump_ind);
int search_type_8(unsigned char *buffer, disk_t *disk_car,partition_t *partition,const int verbose, const int dump_ind);
int search_type_16(unsigned char *buffer, disk_t *disk_car,partition_t *partition,const int verbose, const int dump_ind);
diff --git a/src/askloc.h b/src/askloc.h
index 7671883..5dcc8d4 100644
--- a/src/askloc.h
+++ b/src/askloc.h
@@ -24,6 +24,10 @@ extern "C" {
#endif
char *ask_location(const char*msg, const char *src_dir, const char *dst_org);
+
+/*@
+ @ ensures \result == \null || (\result != \null && \freeable(\result) && valid_string(\result));
+ @*/
char *get_default_location(void);
#ifdef __cplusplus
diff --git a/src/autoset.h b/src/autoset.h
index 8f9e150..a5b4a56 100644
--- a/src/autoset.h
+++ b/src/autoset.h
@@ -19,5 +19,9 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+/*@
+ @ requires \valid(disk_car);
+ @ assigns disk_car->unit;
+ @*/
void autoset_unit(disk_t *disk_car);
diff --git a/src/bfs.c b/src/bfs.c
index 7b740cb..fb8f35d 100644
--- a/src/bfs.c
+++ b/src/bfs.c
@@ -86,5 +86,7 @@ int recover_BeFS(const disk_t *disk_car, const struct disk_super_block *beos_blo
set_BeFS_info(beos_block, partition);
partition->part_size=le64(beos_block->num_blocks) << le32(beos_block->block_shift);
partition->part_type_i386=(unsigned char)P_BEOS;
+ partition->part_type_mac=PMAC_BEOS;
+ partition->part_type_gpt=GPT_ENT_TYPE_BEOS_BFS;
return 0;
}
diff --git a/src/bfs.h b/src/bfs.h
index 9e78446..7117d4c 100644
--- a/src/bfs.h
+++ b/src/bfs.h
@@ -82,7 +82,20 @@ struct disk_super_block /* super block as it is on disk */
/* this is stored in the fs_byte_order field... it's kind of dumb */
#define BFS_BIG_ENDIAN 0x42494745 /* BIGE */
/* int test_beos(struct disk_super_block *,partition_t); */
+
+/*@
+ @ requires \valid(disk_car);
+ @ requires \valid(partition);
+ @ requires separation: \separated(disk_car, partition);
+ @*/
int check_BeFS(disk_t *disk_car, partition_t *partition);
+
+/*@
+ @ requires \valid_read(disk_car);
+ @ requires \valid_read(beos_block);
+ @ requires \valid(partition);
+ @ requires separation: \separated(disk_car, beos_block, partition);
+ @*/
int recover_BeFS(const disk_t *disk_car, const struct disk_super_block *beos_block, partition_t *partition, const int dump_ind);
#ifdef __cplusplus
diff --git a/src/bsd.h b/src/bsd.h
index bd94e54..4554864 100644
--- a/src/bsd.h
+++ b/src/bsd.h
@@ -168,8 +168,22 @@ struct disklabel {
#define TST_FS_VINUM 14 /* Vinum drive */
#define TST_FS_RAID 15 /* RAIDFrame drive */
#define TST_FS_JFS2 21 /* IBM JFS2 */
-int check_BSD(disk_t *disk_car,partition_t *partition,const int verbose,const unsigned int max_partitions);
-int recover_BSD(const disk_t *disk_car, const struct disklabel*bsd_header,partition_t *partition,const int verbose, const int dump_ind);
+
+/*@
+ @ requires \valid(disk_car);
+ @ requires \valid(partition);
+ @ requires separation: \separated(disk_car, partition);
+ @*/
+int check_BSD(disk_t *disk_car, partition_t *partition, const int verbose, const unsigned int max_partitions);
+
+/*@
+ @ requires \valid_read(disk_car);
+ @ requires \valid_read(bsd_header);
+ @ requires \valid(partition);
+ @ requires separation: \separated(disk_car, bsd_header, partition);
+ @*/
+int recover_BSD(const disk_t *disk_car, const struct disklabel*bsd_header, partition_t *partition, const int verbose, const int dump_ind);
+
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/chgarch.h b/src/chgarch.h
index 5324933..e1b459e 100644
--- a/src/chgarch.h
+++ b/src/chgarch.h
@@ -24,6 +24,11 @@
extern "C" {
#endif
+/*@
+ @ requires \valid(disk);
+ @ requires current_cmd == \null || valid_read_string(*current_cmd);
+ @ ensures current_cmd == \null || valid_read_string(*current_cmd);
+ @*/
int change_arch_type_cli(disk_t *disk, const int verbose, char**current_cmd);
#ifdef __cplusplus
diff --git a/src/common.c b/src/common.c
index 3e93f19..6d78832 100644
--- a/src/common.c
+++ b/src/common.c
@@ -217,9 +217,15 @@ char* strip_dup(char* str)
{
unsigned int i;
char *end;
+ /*@
+ @ loop assigns str;
+ @*/
while(isspace(*str))
str++;
end=str;
+ /*@
+ @ loop assigns i, end;
+ @*/
for (i = 0; str[i] != 0; i++)
if (!isspace (str[i]))
end=&str[i];
@@ -257,14 +263,31 @@ time_t date_dos2unix(const unsigned short f_time, const unsigned short f_date)
unsigned long int day,leap_day,month,year,days;
unsigned long int secs;
year = f_date >> 9;
+ /*@ assert 0 <= year <= 127; */
month = td_max(1, (f_date >> 5) & 0xf);
+ /*@ assert 1 <= month <= 15; */
day = td_max(1, f_date & 0x1f) - 1;
+ /*@ assert 0 <= day <= 30; */
leap_day = (year + 3) / 4;
+ /*@ assert 0 <= leap_day <= 32; */
if (year > YEAR_2100) /* 2100 isn't leap year */
+ {
+ /*@ assert year > YEAR_2100; */
+ leap_day = (year + 3) / 4;
+ /*@ assert (YEAR_2100 + 3)/4 < leap_day <= 32; */
leap_day--;
+ /*@ assert (YEAR_2100 + 3)/4 <= leap_day < 32; */
+ }
+ else
+ {
+ /*@ assert year <= YEAR_2100; */
+ /*@ assert 0 <= leap_day <= (YEAR_2100 + 3)/4; */
+ }
+ /*@ assert 0 <= leap_day < 32; */
if (IS_LEAP_YEAR(year) && month > 2)
leap_day++;
+ /*@ assert 0 <= leap_day <= 32; */
days = days_in_year[month];
/*@ assert days <= 334; */
days += year * 365 + leap_day + day + DAYS_DELTA;
@@ -280,7 +303,7 @@ time_t date_dos2unix(const unsigned short f_time, const unsigned short f_date)
void set_secwest(void)
{
const time_t t = time(NULL);
-#if defined(__MINGW32__)
+#if defined(__MINGW32__) || defined(__FRAMAC__)
const struct tm *tmptr = localtime(&t);
#else
struct tm tmp;
@@ -320,26 +343,39 @@ time_t td_ntfs2utc (int64_t ntfstime)
return (ntfstime - (NTFS_TIME_OFFSET)) / 10000000;
}
-int check_command(char **current_cmd, const char *cmd, size_t n)
+int check_command(char **current_cmd, const char *cmd, const size_t n)
{
const int res=strncmp(*current_cmd, cmd, n);
if(res==0)
{
(*current_cmd)+=n;
+ /*@ assert valid_read_string(*current_cmd); */
return 0;
}
+ /*@ assert valid_read_string(*current_cmd); */
return res;
}
void skip_comma_in_command(char **current_cmd)
{
+ /*@
+ loop invariant valid_read_string(*current_cmd);
+ loop assigns *current_cmd;
+ */
while(*current_cmd[0]==',')
+ {
(*current_cmd)++;
+ }
+ /*@ assert valid_read_string(*current_cmd); */
}
uint64_t get_int_from_command(char **current_cmd)
{
uint64_t tmp=0;
+ /*@
+ loop invariant valid_read_string(*current_cmd);
+ loop assigns *current_cmd, tmp;
+ */
while(*current_cmd[0] >='0' && *current_cmd[0] <= '9')
{
tmp = tmp * 10 + *current_cmd[0] - '0';
diff --git a/src/common.h b/src/common.h
index aeecaf5..886d4dd 100644
--- a/src/common.h
+++ b/src/common.h
@@ -111,6 +111,7 @@ struct efi_guid_s
#define PMAC_FWDRIVER 5
#define PMAC_SWAP 0x82
#define PMAC_LINUX 0x83
+#define PMAC_BEOS 0xEB
#define PMAC_HFS 0xAF
#define PMAC_MAP 6
#define PMAC_PATCHES 7
@@ -232,6 +233,9 @@ struct efi_guid_s
#define GPT_ENT_TYPE_SOLARIS_RESERVED5 \
((const efi_guid_t){le32(0x6a8d2ac7),le16(0x1dd2),le16(0x11b2),0x96,0xa6,{0x08,0x00,0x20,0x73,0x66,0x31}})
+#define GPT_ENT_TYPE_BEOS_BFS \
+ ((const efi_guid_t){le32(0x42465331),le16(0x3ba3),le16(0x10f1),0x80,0x2a,{0x48,0x61,0x69,0x6b,0x75,0x21}})
+
#define TESTDISK_O_RDONLY 00
#define TESTDISK_O_RDWR 02
#define TESTDISK_O_DIRECT 040000
@@ -363,7 +367,7 @@ struct arch_fnct_struct
int (*write_MBR_code)(disk_t *disk);
void (*set_prev_status)(const disk_t *disk, partition_t *partition);
void (*set_next_status)(const disk_t *disk, partition_t *partition);
- int (*test_structure)(list_part_t *list_part);
+ int (*test_structure)(const list_part_t *list_part);
unsigned int (*get_part_type)(const partition_t *partition);
int (*set_part_type)(partition_t *partition, unsigned int part_type);
void (*init_structure)(const disk_t *disk,list_part_t *list_part, const int verbose);
@@ -472,6 +476,10 @@ void set_part_name(partition_t *partition, const char *src, const unsigned int m
@*/
void set_part_name_chomp(partition_t *partition, const unsigned char *src, const unsigned int max_size);
+/*@
+ @ requires valid_read_string(str);
+ @ ensures \result == \null || valid_read_string(\result);
+ @*/
char* strip_dup(char* str);
/*@ assigns \nothing; */
@@ -570,21 +578,31 @@ struct tm *localtime_r(const time_t *timep, struct tm *result);
/*@
@ requires \valid(current_cmd);
- @ requires valid_string(*current_cmd);
- @ requires valid_read_string((char *)*cmd);
+ @ requires valid_read_string(*current_cmd);
+ @ requires valid_read_string(cmd);
+ @ requires \separated(cmd+(..), current_cmd);
+ @ requires strlen(cmd) == n;
+ @ assigns *current_cmd;
+ @ assigns \result \from indirect:(*current_cmd)[0 .. n-1], indirect:cmd[0 ..n-1], indirect:n;
+ @ ensures valid_read_string(*current_cmd);
+ @ ensures \result == 0 ==> *current_cmd == \old(*current_cmd) + n;
+ @ ensures \result != 0 ==> *current_cmd == \old(*current_cmd);
@*/
- // requires strlen(cmd) == n;
-int check_command(char **current_cmd, const char *cmd, size_t n);
+int check_command(char **current_cmd, const char *cmd, const size_t n);
/*@
@ requires \valid(current_cmd);
- @ requires valid_string(*current_cmd);
+ @ requires valid_read_string(*current_cmd);
+ @ assigns *current_cmd;
+ @ ensures valid_read_string(*current_cmd);
@*/
void skip_comma_in_command(char **current_cmd);
/*@
@ requires \valid(current_cmd);
- @ requires valid_string(*current_cmd);
+ @ requires valid_read_string(*current_cmd);
+ @ assigns *current_cmd;
+ @ ensures valid_read_string(*current_cmd);
@*/
uint64_t get_int_from_command(char **current_cmd);
#ifdef __cplusplus
diff --git a/src/crc.c b/src/crc.c
index 0d1b268..10dd8bd 100644
--- a/src/crc.c
+++ b/src/crc.c
@@ -91,6 +91,7 @@ unsigned int get_crc32(const void*buf, const unsigned int len, const uint32_t se
register uint32_t crc32val;
const unsigned char *s=(const unsigned char *)buf;
crc32val = seed;
+ /*@ loop assigns i, crc32val; */
for (i = 0; i < len; i ++)
{
crc32val = crc32_tab[(crc32val ^ s[i]) & 0xff] ^ (crc32val >> 8);
diff --git a/src/crc.h b/src/crc.h
index 50b6667..846fa14 100644
--- a/src/crc.h
+++ b/src/crc.h
@@ -28,6 +28,11 @@ extern "C" {
uint32_t* make_crc32_table(uint32_t poly);
unsigned int get_crc32_gen(const unsigned char *s, const unsigned int len, const uint32_t seed, const uint32_t *crctab);
#endif
+/*@
+ @ requires \valid_read((const char *)s + (0 .. len-1));
+ @ requires \initialized((const char *)s + (0 .. len-1));
+ @ assigns \nothing;
+ @*/
unsigned int get_crc32(const void *s, const unsigned int len, const uint32_t seed);
#ifdef __cplusplus
diff --git a/src/dfxml.c b/src/dfxml.c
index 142d066..4f02702 100644
--- a/src/dfxml.c
+++ b/src/dfxml.c
@@ -250,8 +250,12 @@ void xml_add_DFXML_creator(const char *package, const char *version)
{
char outstr[200];
const time_t t = time(NULL);
+#if defined(__MINGW32__) || defined(__FRAMAC__)
+ const struct tm *tmp = localtime(&t);
+#else
struct tm tm_tmp;
const struct tm *tmp = localtime_r(&t,&tm_tmp);
+#endif
if (tmp != NULL &&
strftime(outstr, sizeof(outstr), "%Y-%m-%dT%H:%M:%S%z", tmp) != 0)
{
@@ -263,7 +267,7 @@ void xml_add_DFXML_creator(const char *package, const char *version)
xml_pop("creator");
}
-void xml_setup(disk_t *disk, const partition_t *partition)
+void xml_setup(const disk_t *disk, const partition_t *partition)
{
if(xml_handle==NULL)
return;
diff --git a/src/dfxml.h b/src/dfxml.h
index 9f0b16c..c6cd34b 100644
--- a/src/dfxml.h
+++ b/src/dfxml.h
@@ -35,7 +35,7 @@ void xml_push(const char *tag, const char *attribute);
void xml_pop(const char *tag);
void xml_out2s(const char *tag, const char *value);
void xml_out2i(const char *tag, const uint64_t value);
-void xml_setup(disk_t *disk, const partition_t *partition);
+void xml_setup(const disk_t *disk, const partition_t *partition);
void xml_set_command_line(const int argc, char **argv);
void xml_clear_command_line(void);
void xml_add_DFXML_creator(const char *package, const char *version);
diff --git a/src/dir.c b/src/dir.c
index 06bd544..7501627 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -168,7 +168,7 @@ int set_datestr(char *datestr, size_t n, const time_t timev)
strncpy(datestr, " ", n);
return 0;
}
-#if defined(__MINGW32__)
+#if defined(__MINGW32__) || defined(__FRAMAC__)
tm_p=localtime(&timev);
#else
tm_p=localtime_r(&timev, &tmp);
diff --git a/src/dir.h b/src/dir.h
index b2d4f7a..ca67255 100644
--- a/src/dir.h
+++ b/src/dir.h
@@ -24,59 +24,19 @@
#ifdef __cplusplus
extern "C" {
#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-#include "list.h"
-#define DIR_NAME_LEN 1024
-#define FLAG_LIST_DELETED 1
-#define FLAG_LIST_MASK12 2
-#define FLAG_LIST_MASK16 4
-#define FLAG_LIST_PATHNAME 8
-#define FLAG_LIST_ADS 16
-#define FLAG_LIST_SYSTEM 32
-/* capabilities */
-#define CAPA_LIST_DELETED 1
-#define CAPA_LIST_ADS 2
-
-typedef enum { DIR_PART_ENOIMP=-3, DIR_PART_ENOSYS=-2, DIR_PART_EIO=-1, DIR_PART_OK=0} dir_partition_t;
-typedef struct dir_data dir_data_t;
-typedef struct
-{
- struct td_list_head list;
- char *name;
- uint32_t st_ino;
- uint32_t st_mode;
- uint32_t st_uid;
- uint32_t st_gid;
- uint64_t st_size;
- time_t td_atime; /* time of last access */
- time_t td_mtime; /* time of last modification */
- time_t td_ctime; /* time of last status change */
- unsigned int status;
-} file_info_t;
-
-struct dir_data
-{
- void *display;
- char current_directory[DIR_NAME_LEN];
- unsigned long int current_inode;
- int verbose;
- unsigned int param;
- unsigned int capabilities;
- int(*get_dir)(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int first_inode, file_info_t*list);
- int (*copy_file)(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const file_info_t *file);
- void (*close)(dir_data_t *dir_data);
- char *local_dir;
- void *private_dir_data;
-};
-
-#define FILE_STATUS_DELETED 1
-#define FILE_STATUS_MARKED 2
-#define FILE_STATUS_ADS 4
+#include "dir_common.h"
+/*@
+ @ requires \valid(datestr);
+ @*/
int set_datestr(char *datestr, size_t n, const time_t timev);
+
+/*@
+ @ requires \valid_read(dir_data);
+ @ requires \valid_read(dir_list);
+ @*/
int dir_aff_log(const dir_data_t *dir_data, const file_info_t*dir_list);
+
void log_list_file(const disk_t *disk_car, const partition_t *partition, const dir_data_t *dir_data, const file_info_t*list);
unsigned int delete_list_file(file_info_t *list);
int dir_whole_partition_log(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int inode);
@@ -87,49 +47,6 @@ FILE *fopen_local(char **localfilename, const char *localroot, const char *filen
char *gen_local_filename(const char *filename);
char *mkdir_local(const char *localroot, const char *pathname);
void mkdir_local_for_file(const char *filename);
-
-#define LINUX_S_IFMT 00170000
-#define LINUX_S_IFSOCK 0140000
-#define LINUX_S_IFLNK 0120000
-#define LINUX_S_IFREG 0100000
-#define LINUX_S_IFBLK 0060000
-#define LINUX_S_IFDIR 0040000
-#define LINUX_S_IFCHR 0020000
-#define LINUX_S_IFIFO 0010000
-#define LINUX_S_ISUID 0004000
-#define LINUX_S_ISGID 0002000
-#define LINUX_S_ISVTX 0001000
-
-
-#define LINUX_S_IRWXU 00700
-#define LINUX_S_IRUSR 00400
-#define LINUX_S_IWUSR 00200
-#define LINUX_S_IXUSR 00100
-
-#define LINUX_S_IRWXG 00070
-#define LINUX_S_IRGRP 00040
-#define LINUX_S_IWGRP 00020
-#define LINUX_S_IXGRP 00010
-
-#define LINUX_S_IRWXO 00007
-#define LINUX_S_IROTH 00004
-#define LINUX_S_IWOTH 00002
-#define LINUX_S_IXOTH 00001
-
-#define LINUX_S_IRWXUGO (LINUX_S_IRWXU|LINUX_S_IRWXG|LINUX_S_IRWXO)
-#define LINUX_S_IALLUGO (LINUX_S_ISUID|LINUX_S_ISGID|LINUX_S_ISVTX|LINUX_S_IRWXUGO)
-#define LINUX_S_IRUGO (LINUX_S_IRUSR|LINUX_S_IRGRP|LINUX_S_IROTH)
-#define LINUX_S_IWUGO (LINUX_S_IWUSR|LINUX_S_IWGRP|LINUX_S_IWOTH)
-#define LINUX_S_IXUGO (LINUX_S_IXUSR|LINUX_S_IXGRP|LINUX_S_IXOTH)
-
-#define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
-#define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
-#define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
-#define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
-#define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
-#define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
-#define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
-
int filesort(const struct td_list_head *a, const struct td_list_head *b);
#ifdef __cplusplus
} /* closing brace for extern "C" */
diff --git a/src/dir_common.h b/src/dir_common.h
new file mode 100644
index 0000000..8463d67
--- /dev/null
+++ b/src/dir_common.h
@@ -0,0 +1,123 @@
+/*
+
+ File: dir_common.h
+
+ Copyright (C) 2020 Christophe GRENIER <grenier@cgsecurity.org>
+
+ This software is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write the Free Software Foundation, Inc., 51
+ Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ */
+#ifndef _DIR_COMMON_H
+#define _DIR_COMMON_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#include "list.h"
+#define DIR_NAME_LEN 1024
+#define FLAG_LIST_DELETED 1
+#define FLAG_LIST_MASK12 2
+#define FLAG_LIST_MASK16 4
+#define FLAG_LIST_PATHNAME 8
+#define FLAG_LIST_ADS 16
+#define FLAG_LIST_SYSTEM 32
+/* capabilities */
+#define CAPA_LIST_DELETED 1
+#define CAPA_LIST_ADS 2
+
+typedef enum { DIR_PART_ENOIMP=-3, DIR_PART_ENOSYS=-2, DIR_PART_EIO=-1, DIR_PART_OK=0} dir_partition_t;
+typedef struct dir_data dir_data_t;
+typedef struct
+{
+ struct td_list_head list;
+ char *name;
+ uint32_t st_ino;
+ uint32_t st_mode;
+ uint32_t st_uid;
+ uint32_t st_gid;
+ uint64_t st_size;
+ time_t td_atime; /* time of last access */
+ time_t td_mtime; /* time of last modification */
+ time_t td_ctime; /* time of last status change */
+ unsigned int status;
+} file_info_t;
+
+struct dir_data
+{
+ void *display;
+ char current_directory[DIR_NAME_LEN];
+ unsigned long int current_inode;
+ int verbose;
+ unsigned int param;
+ unsigned int capabilities;
+ int(*get_dir)(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int first_inode, file_info_t*list);
+ int (*copy_file)(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const file_info_t *file);
+ void (*close)(dir_data_t *dir_data);
+ char *local_dir;
+ void *private_dir_data;
+};
+
+#define FILE_STATUS_DELETED 1
+#define FILE_STATUS_MARKED 2
+#define FILE_STATUS_ADS 4
+
+#define LINUX_S_IFMT 00170000
+#define LINUX_S_IFSOCK 0140000
+#define LINUX_S_IFLNK 0120000
+#define LINUX_S_IFREG 0100000
+#define LINUX_S_IFBLK 0060000
+#define LINUX_S_IFDIR 0040000
+#define LINUX_S_IFCHR 0020000
+#define LINUX_S_IFIFO 0010000
+#define LINUX_S_ISUID 0004000
+#define LINUX_S_ISGID 0002000
+#define LINUX_S_ISVTX 0001000
+
+
+#define LINUX_S_IRWXU 00700
+#define LINUX_S_IRUSR 00400
+#define LINUX_S_IWUSR 00200
+#define LINUX_S_IXUSR 00100
+
+#define LINUX_S_IRWXG 00070
+#define LINUX_S_IRGRP 00040
+#define LINUX_S_IWGRP 00020
+#define LINUX_S_IXGRP 00010
+
+#define LINUX_S_IRWXO 00007
+#define LINUX_S_IROTH 00004
+#define LINUX_S_IWOTH 00002
+#define LINUX_S_IXOTH 00001
+
+#define LINUX_S_IRWXUGO (LINUX_S_IRWXU|LINUX_S_IRWXG|LINUX_S_IRWXO)
+#define LINUX_S_IALLUGO (LINUX_S_ISUID|LINUX_S_ISGID|LINUX_S_ISVTX|LINUX_S_IRWXUGO)
+#define LINUX_S_IRUGO (LINUX_S_IRUSR|LINUX_S_IRGRP|LINUX_S_IROTH)
+#define LINUX_S_IWUGO (LINUX_S_IWUSR|LINUX_S_IWGRP|LINUX_S_IWOTH)
+#define LINUX_S_IXUGO (LINUX_S_IXUSR|LINUX_S_IXGRP|LINUX_S_IXOTH)
+
+#define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
+#define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
+#define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
+#define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
+#define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
+#define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
+#define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
+
+#ifdef __cplusplus
+} /* closing brace for extern "C" */
+#endif
+#endif
diff --git a/src/ewf.c b/src/ewf.c
index 7bf502c..e7c6391 100644
--- a/src/ewf.c
+++ b/src/ewf.c
@@ -23,6 +23,10 @@
#include <config.h>
#endif
+#if defined(__FRAMAC__) || defined(MAIN_photorec)
+#undef HAVE_LIBEWF
+#endif
+
#ifdef HAVE_STRING_H
#include <string.h>
#endif
@@ -96,34 +100,30 @@ struct info_fewf_struct
unsigned int buffer_size;
};
+#if defined( HAVE_LIBEWF_V2_API )
disk_t *fewf_init(const char *device, const int mode)
{
unsigned int num_files=0;
char **filenames= NULL;
disk_t *disk=NULL;
struct info_fewf_struct *data;
-#if !defined( HAVE_LIBEWF_V2_API ) && defined( HAVE_GLOB_H )
- glob_t globbuf;
-#endif
-#if defined( HAVE_LIBEWF_V2_API )
libewf_error_t *ewf_error = NULL;
-#endif
data=(struct info_fewf_struct *)MALLOC(sizeof(struct info_fewf_struct));
- memset(data, 0, sizeof(struct info_fewf_struct));
+ memset(data, 0, sizeof(struct info_fewf_struct));
data->file_name = strdup(device);
+ if(data->file_name==NULL)
+ {
+ free(data);
+ return NULL;
+ }
data->handle=NULL;
data->mode = mode;
#ifdef DEBUG_EWF
-#if defined( HAVE_LIBEWF_V2_API )
libewf_notify_set_stream( stderr, NULL );
libewf_notify_set_verbose( 1 );
-#else
- libewf_set_notify_values( stderr, 1 );
-#endif
#endif
-#if defined( HAVE_LIBEWF_V2_API )
if( libewf_glob(
data->file_name,
strlen(data->file_name),
@@ -140,36 +140,9 @@ disk_t *fewf_init(const char *device, const int mode)
free(data);
return NULL;
}
-#elif defined( HAVE_GLOB_H )
- {
- globbuf.gl_offs = 0;
- glob(data->file_name, GLOB_DOOFFS, NULL, &globbuf);
- if(globbuf.gl_pathc>0)
- {
- filenames=(char **)MALLOC(globbuf.gl_pathc * sizeof(*filenames));
- for (num_files=0; num_files<globbuf.gl_pathc; num_files++) {
- filenames[num_files]=globbuf.gl_pathv[num_files];
- }
- }
- }
- if(filenames==NULL)
- {
- globfree(&globbuf);
- free(data->file_name);
- free(data);
- return NULL;
- }
-#else
- {
- filenames=(char **)MALLOC(1*sizeof(*filenames));
- filenames[num_files] = data->file_name;
- num_files++;
- }
-#endif
if((mode&TESTDISK_O_RDWR)==TESTDISK_O_RDWR)
{
-#if defined( HAVE_LIBEWF_V2_API )
if( libewf_handle_initialize(
&( data->handle ),
&ewf_error) != 1 )
@@ -209,18 +182,10 @@ disk_t *fewf_init(const char *device, const int mode)
NULL );
data->handle=NULL;
}
-#else
- data->handle=libewf_open(filenames, num_files, LIBEWF_OPEN_READ_WRITE);
- if(data->handle==NULL)
- {
- log_error("libewf_open(%s) in RW mode failed\n", device);
- }
-#endif /* defined( HAVE_LIBEWF_V2_API ) */
}
if(data->handle==NULL)
{
data->mode&=~TESTDISK_O_RDWR;
-#if defined( HAVE_LIBEWF_V2_API )
if( libewf_handle_initialize(
&( data->handle ),
&ewf_error) != 1 )
@@ -261,7 +226,140 @@ disk_t *fewf_init(const char *device, const int mode)
free(data);
return NULL;
}
+ }
+ if( libewf_handle_set_header_values_date_format(
+ data->handle,
+ LIBEWF_DATE_FORMAT_DAYMONTH,
+ NULL ) != 1 )
+ {
+ log_error("%s Unable to set header values date format\n", device);
+ }
+ disk=(disk_t *)MALLOC(sizeof(*disk));
+ init_disk(disk);
+ disk->arch=&arch_none;
+ disk->device=strdup(device);
+ if(disk->device==NULL)
+ {
+ free(disk);
+ libewf_glob_free(
+ filenames,
+ num_files,
+ NULL );
+ free(data->file_name);
+ free(data);
+ return NULL;
+ }
+ disk->data=data;
+ disk->description=&fewf_description;
+ disk->description_short=&fewf_description_short;
+ disk->pread=&fewf_pread;
+ disk->pwrite=((data->mode&TESTDISK_O_RDWR)?&fewf_pwrite:&fewf_nopwrite);
+ disk->sync=&fewf_sync;
+ disk->access_mode=(data->mode&TESTDISK_O_RDWR);
+ disk->clean=&fewf_clean;
+ {
+ uint32_t bytes_per_sector = 0;
+ if( libewf_handle_get_bytes_per_sector(
+ data->handle,
+ &bytes_per_sector,
+ NULL ) != 1 )
+ {
+ disk->sector_size=DEFAULT_SECTOR_SIZE;
+ }
+ else
+ {
+ disk->sector_size=bytes_per_sector;
+ }
+ }
+// printf("libewf_get_bytes_per_sector %u\n",disk->sector_size);
+ if(disk->sector_size==0)
+ disk->sector_size=DEFAULT_SECTOR_SIZE;
+ /* Set geometry */
+ disk->geom.cylinders=0;
+ disk->geom.heads_per_cylinder=1;
+ disk->geom.sectors_per_head=1;
+ disk->geom.bytes_per_sector=disk->sector_size;
+ {
+ size64_t media_size = 0;
+ if( libewf_handle_get_media_size(
+ data->handle,
+ &media_size,
+ NULL ) != 1 )
+ {
+ disk->disk_real_size=0;
+ }
+ disk->disk_real_size=media_size;
+ }
+ update_disk_car_fields(disk);
+ libewf_glob_free(
+ filenames,
+ num_files,
+ NULL );
+ return disk;
+}
+#else
+disk_t *fewf_init(const char *device, const int mode)
+{
+ unsigned int num_files=0;
+ char **filenames= NULL;
+ disk_t *disk=NULL;
+ struct info_fewf_struct *data;
+#if defined( HAVE_GLOB_H )
+ glob_t globbuf;
+#endif
+ data=(struct info_fewf_struct *)MALLOC(sizeof(struct info_fewf_struct));
+ memset(data, 0, sizeof(struct info_fewf_struct));
+ data->file_name = strdup(device);
+ if(data->file_name==NULL)
+ {
+ free(data);
+ return NULL;
+ }
+ data->handle=NULL;
+ data->mode = mode;
+
+#ifdef DEBUG_EWF
+ libewf_set_notify_values( stderr, 1 );
+#endif
+
+#if defined( HAVE_GLOB_H )
+ {
+ globbuf.gl_offs = 0;
+ glob(data->file_name, GLOB_DOOFFS, NULL, &globbuf);
+ if(globbuf.gl_pathc>0)
+ {
+ filenames=(char **)MALLOC(globbuf.gl_pathc * sizeof(*filenames));
+ for (num_files=0; num_files<globbuf.gl_pathc; num_files++) {
+ filenames[num_files]=globbuf.gl_pathv[num_files];
+ }
+ }
+ }
+ if(filenames==NULL)
+ {
+ globfree(&globbuf);
+ free(data->file_name);
+ free(data);
+ return NULL;
+ }
#else
+ {
+ filenames=(char **)MALLOC(1*sizeof(*filenames));
+ filenames[num_files] = data->file_name;
+ num_files++;
+ }
+#endif
+
+ if((mode&TESTDISK_O_RDWR)==TESTDISK_O_RDWR)
+ {
+ data->handle=libewf_open(filenames, num_files, LIBEWF_OPEN_READ_WRITE);
+ if(data->handle==NULL)
+ {
+ log_error("libewf_open(%s) in RW mode failed\n", device);
+ }
+ }
+ if(data->handle==NULL)
+ {
+ data->mode&=~TESTDISK_O_RDWR;
data->handle=libewf_open(filenames, num_files, LIBEWF_OPEN_READ);
if(data->handle==NULL)
{
@@ -274,27 +372,27 @@ disk_t *fewf_init(const char *device, const int mode)
free(data);
return NULL;
}
-#endif /* defined( HAVE_LIBEWF_V2_API ) */
}
-#if defined( HAVE_LIBEWF_V2_API )
- if( libewf_handle_set_header_values_date_format(
- data->handle,
- LIBEWF_DATE_FORMAT_DAYMONTH,
- NULL ) != 1 )
- {
- log_error("%s Unable to set header values date format\n", device);
- }
-#else
if( libewf_parse_header_values( data->handle, LIBEWF_DATE_FORMAT_DAYMONTH) != 1 )
{
log_error("%s Unable to parse EWF header values\n", device);
}
-#endif
disk=(disk_t *)MALLOC(sizeof(*disk));
init_disk(disk);
disk->arch=&arch_none;
disk->device=strdup(device);
+ if(disk->device==NULL)
+ {
+ free(disk);
+#if defined( HAVE_GLOB_H )
+ globfree(&globbuf);
+#endif
+ free(filenames);
+ free(data->file_name);
+ free(data);
+ return NULL;
+ }
disk->data=data;
disk->description=&fewf_description;
disk->description_short=&fewf_description_short;
@@ -303,18 +401,10 @@ disk_t *fewf_init(const char *device, const int mode)
disk->sync=&fewf_sync;
disk->access_mode=(data->mode&TESTDISK_O_RDWR);
disk->clean=&fewf_clean;
-#if defined( HAVE_LIBEWF_V2_API ) || defined( LIBEWF_GET_BYTES_PER_SECTOR_HAVE_TWO_ARGUMENTS )
+#if defined( LIBEWF_GET_BYTES_PER_SECTOR_HAVE_TWO_ARGUMENTS )
{
uint32_t bytes_per_sector = 0;
-
-#if defined( HAVE_LIBEWF_V2_API )
- if( libewf_handle_get_bytes_per_sector(
- data->handle,
- &bytes_per_sector,
- NULL ) != 1 )
-#else
if( libewf_get_bytes_per_sector(data->handle, &bytes_per_sector)<0)
-#endif
{
disk->sector_size=DEFAULT_SECTOR_SIZE;
}
@@ -326,7 +416,6 @@ disk_t *fewf_init(const char *device, const int mode)
#else
disk->sector_size=libewf_get_bytes_per_sector(data->handle);
#endif
-
// printf("libewf_get_bytes_per_sector %u\n",disk->sector_size);
if(disk->sector_size==0)
disk->sector_size=DEFAULT_SECTOR_SIZE;
@@ -335,19 +424,10 @@ disk_t *fewf_init(const char *device, const int mode)
disk->geom.heads_per_cylinder=1;
disk->geom.sectors_per_head=1;
disk->geom.bytes_per_sector=disk->sector_size;
- /* Get disk_real_size */
-#if defined( HAVE_LIBEWF_V2_API ) || defined( LIBEWF_GET_MEDIA_SIZE_HAVE_TWO_ARGUMENTS )
+#if defined( LIBEWF_GET_MEDIA_SIZE_HAVE_TWO_ARGUMENTS )
{
size64_t media_size = 0;
-
-#if defined( HAVE_LIBEWF_V2_API )
- if( libewf_handle_get_media_size(
- data->handle,
- &media_size,
- NULL ) != 1 )
-#else
if(libewf_get_media_size(data->handle, &media_size)<0)
-#endif
{
disk->disk_real_size=0;
}
@@ -360,19 +440,13 @@ disk_t *fewf_init(const char *device, const int mode)
disk->disk_real_size=libewf_get_media_size(data->handle);
#endif
update_disk_car_fields(disk);
-#if defined( HAVE_LIBEWF_V2_API )
- libewf_glob_free(
- filenames,
- num_files,
- NULL );
-#else
#if defined( HAVE_GLOB_H )
globfree(&globbuf);
#endif
free(filenames);
-#endif
return disk;
}
+#endif
static const char *fewf_description(disk_t *disk)
{
@@ -529,4 +603,3 @@ const char*td_ewf_version(void)
return "none";
}
#endif /* defined(HAVE_LIBEWF_H) && defined(HAVE_LIBEWF) */
-
diff --git a/src/ext2_dir.c b/src/ext2_dir.c
index 82106c1..efc19a3 100644
--- a/src/ext2_dir.c
+++ b/src/ext2_dir.c
@@ -96,7 +96,6 @@ static struct struct_io_manager my_struct_manager = {
.write_blk64=&my_write_blk64,
#endif
};
-static int ext2_dir(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int cluster, file_info_t *dir_list);
static io_channel shared_ioch=NULL;
/*
diff --git a/src/fat.c b/src/fat.c
index cc41a9e..667c778 100644
--- a/src/fat.c
+++ b/src/fat.c
@@ -43,7 +43,6 @@
#include "intrf.h"
#include "log.h"
#include "log_part.h"
-#include "fat_common.h"
#include "dir.h"
#include "fat_dir.h"
@@ -52,8 +51,23 @@ extern const arch_fnct_t arch_mac;
static int log_fat_info(const struct fat_boot_sector*fh1, const upart_type_t upart_type, const unsigned int sector_size);
static int test_OS2MB(const disk_t *disk, const struct fat_boot_sector *fat_header, const partition_t *partition, const int verbose, const int dump_ind);
+
+/*@
+ @ requires \valid_read(partition);
+ @ assigns \nothing;
+ @*/
static int is_fat12(const partition_t *partition);
+
+/*@
+ @ requires \valid_read(partition);
+ @ assigns \nothing;
+ @*/
static int is_fat16(const partition_t *partition);
+
+/*@
+ @ requires \valid_read(partition);
+ @ assigns \nothing;
+ @*/
static int is_fat32(const partition_t *partition);
static int fat32_set_part_name(disk_t *disk_car, partition_t *partition, const struct fat_boot_sector*fat_header)
diff --git a/src/fat.h b/src/fat.h
index 11d0871..ea63cd7 100644
--- a/src/fat.h
+++ b/src/fat.h
@@ -26,139 +26,135 @@
extern "C" {
#endif
-#define FAT1X_PART_NAME 0x2B
-#define FAT32_PART_NAME 0x47
-#define FAT_NAME1 0x36
-#define FAT_NAME2 0x52 /* FAT32 only */
-#define NTFS_NAME 0x03
-#define OS2_NAME 0x03
-
-/*
- * FAT partition boot sector information, taken from the Linux
- * kernel sources.
- */
-
-struct fat_boot_sector {
- uint8_t ignored[3]; /* 0x00 Boot strap short or near jump */
- int8_t system_id[8]; /* 0x03 Name - can be used to special case
- partition manager volumes */
- uint8_t sector_size[2]; /* 0x0B bytes per logical sector */
- uint8_t sectors_per_cluster; /* 0x0D sectors/cluster */
- uint16_t reserved; /* 0x0E reserved sectors */
- uint8_t fats; /* 0x10 number of FATs */
- uint8_t dir_entries[2]; /* 0x11 root directory entries */
- uint8_t sectors[2]; /* 0x13 number of sectors */
- uint8_t media; /* 0x15 media code (unused) */
- uint16_t fat_length; /* 0x16 sectors/FAT */
- uint16_t secs_track; /* 0x18 sectors per track */
- uint16_t heads; /* 0x1A number of heads */
- uint32_t hidden; /* 0x1C hidden sectors (unused) */
- uint32_t total_sect; /* 0x20 number of sectors (if sectors == 0) */
-
- /* The following fields are only used by FAT32 */
- uint32_t fat32_length; /* 0x24=36 sectors/FAT */
- uint16_t flags; /* 0x28 bit 8: fat mirroring, low 4: active fat */
- uint8_t version[2]; /* 0x2A major, minor filesystem version */
- uint32_t root_cluster; /* 0x2C first cluster in root directory */
- uint16_t info_sector; /* 0x30 filesystem info sector */
- uint16_t backup_boot; /* 0x32 backup boot sector */
- uint8_t BPB_Reserved[12]; /* 0x34 Unused */
- uint8_t BS_DrvNum; /* 0x40 */
- uint8_t BS_Reserved1; /* 0x41 */
- uint8_t BS_BootSig; /* 0x42 */
- uint8_t BS_VolID[4]; /* 0x43 */
- uint8_t BS_VolLab[11]; /* 0x47 */
- uint8_t BS_FilSysType[8]; /* 0x52=82*/
-
- /* */
- uint8_t nothing[420]; /* 0x5A */
- uint16_t marker;
-} __attribute__ ((gcc_struct, __packed__));
-
-struct fat_fsinfo {
- uint32_t leadsig; /* 0x41615252 */
- uint8_t reserved1[480];
- uint32_t strucsig; /* 0x61417272 */
- uint32_t freecnt; /* free clusters 0xfffffffff if unknown */
- uint32_t nextfree; /* next free cluster */
- uint8_t reserved3[12];
- uint32_t magic3; /* 0xAA550000 */
-} __attribute__ ((gcc_struct, __packed__));
-
-struct msdos_dir_entry {
- int8_t name[8]; /* 00 name and extension */
- int8_t ext[3];
- uint8_t attr; /* 0B attribute bits */
- uint8_t lcase; /* 0C Case for base and extension */
- uint8_t ctime_ms; /* 0D Creation time, milliseconds */
- uint16_t ctime; /* 0E Creation time */
- uint16_t cdate; /* 10 Creation date */
- uint16_t adate; /* 12 Last access date */
- uint16_t starthi; /* 14 High 16 bits of cluster in FAT32 */
- uint16_t time; /* 16 time, date and first cluster */
- uint16_t date; /* 18 */
- uint16_t start; /* 1A */
- uint32_t size; /* 1C file size (in bytes) */
-} __attribute__ ((gcc_struct, __packed__));
-
-/* Up to 13 characters of the name */
-struct msdos_dir_slot {
- uint8_t id; /* 00 sequence number for slot */
- uint8_t name0_4[10]; /* 01 first 5 characters in name */
- uint8_t attr; /* 0B attribute byte */
- uint8_t reserved; /* 0C always 0 */
- uint8_t alias_checksum; /* 0D checksum for 8.3 alias */
- uint8_t name5_10[12]; /* 0E 6 more characters in name */
- uint16_t start; /* 1A starting cluster number, 0 in long slots */
- uint8_t name11_12[4]; /* 1C last 2 characters in name */
-};
-
-
-int comp_FAT(disk_t *disk,const partition_t *partition, const unsigned long int fat_size, const unsigned long int sect_res);
+#include "fat_common.h"
+/*@
+ @ requires \valid(disk);
+ @ requires \valid_read(partition);
+ @ requires separation: \separated(disk, partition);
+ @*/
+int comp_FAT(disk_t *disk, const partition_t *partition, const unsigned long int fat_size, const unsigned long int sect_res);
+
+/*@
+ @ requires \valid_read(fh1);
+ @ requires \valid_read(fh2);
+ @*/
int log_fat2_info(const struct fat_boot_sector*fh1, const struct fat_boot_sector*fh2, const upart_type_t upart_type, const unsigned int sector_size);
-unsigned int get_next_cluster(disk_t *disk,const partition_t *partition, const upart_type_t upart_type,const int offset, const unsigned int cluster);
-int set_next_cluster(disk_t *disk,const partition_t *partition, const upart_type_t upart_type,const int offset, const unsigned int cluster, const unsigned int next_cluster);
-
+/*@
+ @ requires \valid(disk);
+ @ requires \valid_read(partition);
+ @ requires separation: \separated(disk, partition);
+ @*/
+unsigned int get_next_cluster(disk_t *disk, const partition_t *partition, const upart_type_t upart_type, const int offset, const unsigned int cluster);
+
+/*@
+ @ requires \valid(disk);
+ @ requires \valid_read(partition);
+ @ requires separation: \separated(disk, partition);
+ @*/
+int set_next_cluster(disk_t *disk, const partition_t *partition, const upart_type_t upart_type, const int offset, const unsigned int cluster, const unsigned int next_cluster);
+
+/*@
+ @ requires \valid_read(partition);
+ @ assigns \nothing;
+ @*/
int is_fat(const partition_t *partition);
+
+/*@
+ @ requires \valid_read(partition);
+ @ assigns \nothing;
+ @*/
int is_part_fat(const partition_t *partition);
+
+/*@
+ @ requires \valid_read(partition);
+ @ assigns \nothing;
+ @*/
int is_part_fat12(const partition_t *partition);
+
+/*@
+ @ requires \valid_read(partition);
+ @ assigns \nothing;
+ @*/
int is_part_fat16(const partition_t *partition);
+
+/*@
+ @ requires \valid_read(partition);
+ @ assigns \nothing;
+ @*/
int is_part_fat32(const partition_t *partition);
-unsigned int fat32_get_prev_cluster(disk_t *disk,const partition_t *partition, const unsigned int fat_offset, const unsigned int cluster, const unsigned int no_of_cluster);
-int fat32_free_info(disk_t *disk,const partition_t *partition, const unsigned int fat_offset, const unsigned int no_of_cluster, unsigned int *next_free, unsigned int*free_count);
+
+/*@
+ @ requires \valid(disk);
+ @ requires \valid_read(partition);
+ @ requires separation: \separated(disk, partition);
+ @*/
+unsigned int fat32_get_prev_cluster(disk_t *disk, const partition_t *partition, const unsigned int fat_offset, const unsigned int cluster, const unsigned int no_of_cluster);
+
+/*@
+ @ requires \valid(disk);
+ @ requires \valid_read(partition);
+ @ requires separation: \separated(disk, partition);
+ @ requires \valid(next_free);
+ @ requires \valid(free_count);
+ @*/
+int fat32_free_info(disk_t *disk, const partition_t *partition, const unsigned int fat_offset, const unsigned int no_of_cluster, unsigned int *next_free, unsigned int *free_count);
+
+/*@
+ @ requires \valid_read(boot_fat32 + (0 .. sector_size-1));
+ @ assigns \nothing;
+ @*/
unsigned long int fat32_get_free_count(const unsigned char *boot_fat32, const unsigned int sector_size);
-unsigned long int fat32_get_next_free(const unsigned char *boot_fat32, const unsigned int sector_size);
-#define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
-#define IS_FREE(n) (!*(n) || *(const unsigned char *) (n) == DELETED_FLAG)
-#define ATTR_RO 1 /* read-only */
-#define ATTR_HIDDEN 2 /* hidden */
-#define ATTR_SYS 4 /* system */
-#define ATTR_VOLUME 8 /* volume label */
-#define ATTR_DIR 16 /* directory */
-#define ATTR_ARCH 32 /* archived */
-
-#define ATTR_NONE 0 /* no attribute bits */
-#define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
- /* attribute bits that are copied "as is" */
-#define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
-#define ATTR_EXT_MASK (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME | ATTR_DIR | ATTR_ARCH)
- /* bits that are used by the Windows 95/Windows NT extended FAT */
-#define FAT12_BAD 0x0FF7
-#define FAT12_EOC 0x0FF8
-#define FAT16_BAD 0xFFF7
-#define FAT16_EOC 0xFFF8
-#define FAT32_BAD 0x0FFFFFF7
-#define FAT32_EOC 0x0FFFFFF8
-#define FAT1x_BOOT_SECTOR_SIZE 0x200
+/*@
+ @ requires \valid_read(boot_fat32 + (0 .. sector_size-1));
+ @ assigns \nothing;
+ @*/
+unsigned long int fat32_get_next_free(const unsigned char *boot_fat32, const unsigned int sector_size);
+/*@
+ @ requires \valid(disk);
+ @ requires \valid_read(fat_header);
+ @ requires \valid(partition);
+ @ requires separation: \separated(disk, partition, fat_header);
+ @*/
int recover_FAT(disk_t *disk, const struct fat_boot_sector*fat_header, partition_t *partition, const int verbose, const int dump_ind, const int backup);
+
+/*@
+ @ requires \valid(disk);
+ @ requires \valid(partition);
+ @ requires separation: \separated(disk, partition);
+ @*/
int check_FAT(disk_t *disk, partition_t *partition, const int verbose);
+
+/*@
+ @ requires \valid(disk);
+ @ requires \valid_read(fat_header);
+ @ requires \valid(partition);
+ @ requires separation: \separated(disk, partition, fat_header);
+ @*/
int test_FAT(disk_t *disk, const struct fat_boot_sector *fat_header, const partition_t *partition, const int verbose, const int dump_ind);
+
+/*@
+ @ requires \valid(disk);
+ @ requires \valid_read(fat_header);
+ @ requires \valid(partition);
+ @ requires separation: \separated(disk, partition, fat_header);
+ @*/
int recover_OS2MB(const disk_t *disk, const struct fat_boot_sector*fat_header, partition_t *partition, const int verbose, const int dump_ind);
+
+/*@
+ @ requires \valid(disk);
+ @ requires \valid(partition);
+ @ requires separation: \separated(disk, partition);
+ @*/
int check_OS2MB(disk_t *disk, partition_t *partition, const int verbose);
+
+/*@
+ @ requires \valid_read(name);
+ @*/
int check_VFAT_volume_name(const char *name, const unsigned int max_size);
+
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/fat1x.c b/src/fat1x.c
index baa6b94..43d8950 100644
--- a/src/fat1x.c
+++ b/src/fat1x.c
@@ -62,7 +62,7 @@ static void dump_fat1x_ncurses(disk_t *disk_car, const partition_t *partition, c
}
#endif
-static void dump_fat1x(disk_t *disk_car, partition_t *partition, const unsigned char *buffer_bs, char **current_cmd)
+static void dump_fat1x(disk_t *disk_car, const partition_t *partition, const unsigned char *buffer_bs, char **current_cmd)
{
log_info("Boot sector\n");
dump_log(buffer_bs, FAT1x_BOOT_SECTOR_SIZE);
diff --git a/src/fat_common.c b/src/fat_common.c
index ab1f181..2546026 100644
--- a/src/fat_common.c
+++ b/src/fat_common.c
@@ -28,7 +28,6 @@
#endif
#include "types.h"
#include "common.h"
-#include "fat.h"
#include "fat_common.h"
unsigned int fat_sector_size(const struct fat_boot_sector *fat_header)
diff --git a/src/fat_common.h b/src/fat_common.h
index 780b5cc..67fcc6b 100644
--- a/src/fat_common.h
+++ b/src/fat_common.h
@@ -24,6 +24,116 @@
#ifdef __cplusplus
extern "C" {
#endif
+
+#define FAT1X_PART_NAME 0x2B
+#define FAT32_PART_NAME 0x47
+#define FAT_NAME1 0x36
+#define FAT_NAME2 0x52 /* FAT32 only */
+
+#define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
+#define IS_FREE(n) (!*(n) || *(const unsigned char *) (n) == DELETED_FLAG)
+#define ATTR_RO 1 /* read-only */
+#define ATTR_HIDDEN 2 /* hidden */
+#define ATTR_SYS 4 /* system */
+#define ATTR_VOLUME 8 /* volume label */
+#define ATTR_DIR 16 /* directory */
+#define ATTR_ARCH 32 /* archived */
+
+#define ATTR_NONE 0 /* no attribute bits */
+#define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
+ /* attribute bits that are copied "as is" */
+#define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
+#define ATTR_EXT_MASK (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME | ATTR_DIR | ATTR_ARCH)
+ /* bits that are used by the Windows 95/Windows NT extended FAT */
+#define FAT12_BAD 0x0FF7
+#define FAT12_EOC 0x0FF8
+#define FAT16_BAD 0xFFF7
+#define FAT16_EOC 0xFFF8
+#define FAT32_BAD 0x0FFFFFF7
+#define FAT32_EOC 0x0FFFFFF8
+#define FAT1x_BOOT_SECTOR_SIZE 0x200
+
+/*
+ * FAT partition boot sector information, taken from the Linux
+ * kernel sources.
+ */
+
+struct fat_boot_sector {
+ uint8_t ignored[3]; /* 0x00 Boot strap short or near jump */
+ int8_t system_id[8]; /* 0x03 Name - can be used to special case
+ partition manager volumes */
+ uint8_t sector_size[2]; /* 0x0B bytes per logical sector */
+ uint8_t sectors_per_cluster; /* 0x0D sectors/cluster */
+ uint16_t reserved; /* 0x0E reserved sectors */
+ uint8_t fats; /* 0x10 number of FATs */
+ uint8_t dir_entries[2]; /* 0x11 root directory entries */
+ uint8_t sectors[2]; /* 0x13 number of sectors */
+ uint8_t media; /* 0x15 media code (unused) */
+ uint16_t fat_length; /* 0x16 sectors/FAT */
+ uint16_t secs_track; /* 0x18 sectors per track */
+ uint16_t heads; /* 0x1A number of heads */
+ uint32_t hidden; /* 0x1C hidden sectors (unused) */
+ uint32_t total_sect; /* 0x20 number of sectors (if sectors == 0) */
+
+ /* The following fields are only used by FAT32 */
+ uint32_t fat32_length; /* 0x24=36 sectors/FAT */
+ uint16_t flags; /* 0x28 bit 8: fat mirroring, low 4: active fat */
+ uint8_t version[2]; /* 0x2A major, minor filesystem version */
+ uint32_t root_cluster; /* 0x2C first cluster in root directory */
+ uint16_t info_sector; /* 0x30 filesystem info sector */
+ uint16_t backup_boot; /* 0x32 backup boot sector */
+ uint8_t BPB_Reserved[12]; /* 0x34 Unused */
+ uint8_t BS_DrvNum; /* 0x40 */
+ uint8_t BS_Reserved1; /* 0x41 */
+ uint8_t BS_BootSig; /* 0x42 */
+ uint8_t BS_VolID[4]; /* 0x43 */
+ uint8_t BS_VolLab[11]; /* 0x47 */
+ uint8_t BS_FilSysType[8]; /* 0x52=82*/
+
+ /* */
+ uint8_t nothing[420]; /* 0x5A */
+ uint16_t marker;
+} __attribute__ ((gcc_struct, __packed__));
+
+struct fat_fsinfo {
+ uint32_t leadsig; /* 0x41615252 */
+ uint8_t reserved1[480];
+ uint32_t strucsig; /* 0x61417272 */
+ uint32_t freecnt; /* free clusters 0xfffffffff if unknown */
+ uint32_t nextfree; /* next free cluster */
+ uint8_t reserved3[12];
+ uint32_t magic3; /* 0xAA550000 */
+} __attribute__ ((gcc_struct, __packed__));
+
+struct msdos_dir_entry {
+ int8_t name[8]; /* 00 name and extension */
+ int8_t ext[3];
+ uint8_t attr; /* 0B attribute bits */
+ uint8_t lcase; /* 0C Case for base and extension */
+ uint8_t ctime_ms; /* 0D Creation time, milliseconds */
+ uint16_t ctime; /* 0E Creation time */
+ uint16_t cdate; /* 10 Creation date */
+ uint16_t adate; /* 12 Last access date */
+ uint16_t starthi; /* 14 High 16 bits of cluster in FAT32 */
+ uint16_t time; /* 16 time, date and first cluster */
+ uint16_t date; /* 18 */
+ uint16_t start; /* 1A */
+ uint32_t size; /* 1C file size (in bytes) */
+} __attribute__ ((gcc_struct, __packed__));
+
+/* Up to 13 characters of the name */
+struct msdos_dir_slot {
+ uint8_t id; /* 00 sequence number for slot */
+ uint8_t name0_4[10]; /* 01 first 5 characters in name */
+ uint8_t attr; /* 0B attribute byte */
+ uint8_t reserved; /* 0C always 0 */
+ uint8_t alias_checksum; /* 0D checksum for 8.3 alias */
+ uint8_t name5_10[12]; /* 0E 6 more characters in name */
+ uint16_t start; /* 1A starting cluster number, 0 in long slots */
+ uint8_t name11_12[4]; /* 1C last 2 characters in name */
+};
+
+
/*@
@ requires \valid_read(entry);
@ assigns \nothing;
diff --git a/src/fat_dir.c b/src/fat_dir.c
index 3c9c171..02a327b 100644
--- a/src/fat_dir.c
+++ b/src/fat_dir.c
@@ -57,7 +57,6 @@ struct fat_dir_struct
static int fat1x_rootdir(disk_t *disk_car, const partition_t *partition, const dir_data_t *dir_data, const struct fat_boot_sector*fat_header, file_info_t *dir_list);
-static int fat_dir(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int first_cluster, file_info_t *dir_list);
static inline void fat16_towchar(wchar_t *dst, const uint8_t *src, size_t len);
static int fat_copy(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const file_info_t *file);
static void dir_partition_fat_close(dir_data_t *dir_data);
diff --git a/src/fat_dir.h b/src/fat_dir.h
index 4988260..c6cd24b 100644
--- a/src/fat_dir.h
+++ b/src/fat_dir.h
@@ -22,6 +22,7 @@
#ifdef __cplusplus
extern "C" {
#endif
+#include "dir_common.h"
int dir_fat_aux(const unsigned char*buffer, const unsigned int size, const unsigned int param, file_info_t *dir_list);
dir_partition_t dir_partition_fat_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose);
diff --git a/src/fatn.c b/src/fatn.c
index f86a704..c1ccf4f 100644
--- a/src/fatn.c
+++ b/src/fatn.c
@@ -32,7 +32,6 @@
#include "intrfn.h"
#include "fat.h"
#include "fatn.h"
-#include "fat_common.h"
int dump_fat_info_ncurses(const struct fat_boot_sector*fh1, const upart_type_t upart_type, const unsigned int sector_size)
{
diff --git a/src/fidentify.c b/src/fidentify.c
index 883e76a..e345273 100644
--- a/src/fidentify.c
+++ b/src/fidentify.c
@@ -129,10 +129,14 @@ static int file_identify(const char *filename, const unsigned int options)
if(file_recovery_new.file_stat!=NULL &&
file_recovery_new.file_stat->file_hint!=NULL &&
file_recovery_new.file_check!=NULL &&
+#ifdef __FRAMAC__
+ file_recovery_new.extension != NULL &&
+#endif
((options&OPT_CHECK)!=0 || ((options&OPT_TIME)!=0 && file_recovery_new.time==0))
)
{
off_t file_size;
+ /*@ assert valid_read_string(file_recovery_new.extension); */
file_recovery_new.handle=file;
my_fseek(file_recovery_new.handle, 0, SEEK_END);
#if defined(HAVE_FTELLO)
@@ -155,8 +159,25 @@ static int file_identify(const char *filename, const unsigned int options)
file_recovery_new.extension:file_recovery_new.file_stat->file_hint->description));
if((options&OPT_CHECK)!=0 && file_recovery_new.file_check!=NULL)
printf(" file_size=%llu", (long long unsigned)file_recovery_new.file_size);
- if((options&OPT_TIME)!=0 && file_recovery_new.time!=0)
- printf(" time=%llu", (long long unsigned)file_recovery_new.time);
+ if((options&OPT_TIME)!=0 && file_recovery_new.time!=0 && file_recovery_new.time!=(time_t)-1)
+#ifdef __FRAMAC__
+ {
+ printf(" time=%lld", (long long)file_recovery_new.time);
+ }
+#else
+ {
+ char outstr[200];
+#if defined(__MINGW32__) || defined(__FRAMAC__)
+ const struct tm *tmp = localtime(&file_recovery_new.time);
+#else
+ struct tm tm_tmp;
+ const struct tm *tmp = localtime_r(&file_recovery_new.time,&tm_tmp);
+#endif
+ if(tmp != NULL &&
+ strftime(outstr, sizeof(outstr), "%Y-%m-%dT%H:%M:%S%z", tmp) != 0)
+ printf(" time=%s", &outstr[0]);
+ }
+#endif
printf("\n");
}
else
diff --git a/src/file_1cd.c b/src/file_1cd.c
index 24a5487..af153d8 100644
--- a/src/file_1cd.c
+++ b/src/file_1cd.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_1cd)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,7 +57,7 @@ static int header_check_1cd(const unsigned char *buffer, const unsigned int buff
return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_1cd.extension;
- file_recovery_new->calculated_file_size=le32(hdr->size)<<12;
+ file_recovery_new->calculated_file_size=((uint64_t)le32(hdr->size))<<12;
file_recovery_new->data_check=&data_check_size;
file_recovery_new->file_check=&file_check_size;
return 1;
@@ -67,3 +68,4 @@ static void register_header_check_1cd(file_stat_t *file_stat)
static const unsigned char header_1cd[9]= { '1', 'C', 'D', 'B', 'M', 'S', 'V', '8', 0x08 };
register_header_check(0, header_1cd, sizeof(header_1cd), &header_check_1cd, file_stat);
}
+#endif
diff --git a/src/file_3dm.c b/src/file_3dm.c
index dc1241e..1c9957b 100644
--- a/src/file_3dm.c
+++ b/src/file_3dm.c
@@ -3,23 +3,24 @@
File: file_3dm.c
Copyright (C) 2013 Christophe GRENIER <grenier@cgsecurity.org>
-
+
This software is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License along
with this program; if not, write the Free Software Foundation, Inc., 51
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_3dm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,3 +59,4 @@ static void register_header_check_3dm(file_stat_t *file_stat)
{
register_header_check(0, "3D Geometry File Format ", 24, &header_check_3dm, file_stat);
}
+#endif
diff --git a/src/file_3ds.c b/src/file_3ds.c
new file mode 100644
index 0000000..ee23943
--- /dev/null
+++ b/src/file_3ds.c
@@ -0,0 +1,76 @@
+/*
+
+ File: file_3ds.c
+
+ Copyright (C) 2019 Christophe GRENIER <grenier@cgsecurity.org>
+
+ This software is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write the Free Software Foundation, Inc., 51
+ Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ */
+
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_3ds)
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include <stdio.h>
+#include "types.h"
+#include "filegen.h"
+#include "common.h"
+
+static void register_header_check_3ds(file_stat_t *file_stat);
+
+const file_hint_t file_hint_3ds= {
+ .extension="3ds",
+ .description="3d Studio",
+ .max_filesize=PHOTOREC_MAX_FILE_SIZE,
+ .recover=1,
+ .enable_by_default=1,
+ .register_header_check=&register_header_check_3ds
+};
+
+struct chunk_3ds
+{
+ uint16_t chunk_id;
+ uint32_t next_chunk;
+} __attribute__ ((gcc_struct, __packed__));
+
+static int header_check_3ds(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
+{
+ uint64_t fs;
+ const struct chunk_3ds *hdr=(const struct chunk_3ds *)buffer;
+ if(buffer_size < 0x12)
+ return 0;
+ if(buffer[0]!=0x4d || buffer[1]!=0x4d || buffer[0x10]!=0x3d || buffer[0x11]!=0x3d)
+ return 0;
+ fs=le32(hdr->next_chunk);
+ if(fs <= 0x12)
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_3ds.extension;
+ file_recovery_new->calculated_file_size=fs;
+ file_recovery_new->data_check=&data_check_size;
+ file_recovery_new->file_check=&file_check_size;
+ return 1;
+}
+
+static void register_header_check_3ds(file_stat_t *file_stat)
+{
+ static const unsigned char header_3ds[4]= { 0x02, 0x00, 0x0a, 0x00 };
+ register_header_check(6, header_3ds, sizeof(header_3ds), &header_check_3ds, file_stat);
+}
+#endif
diff --git a/src/file_7z.c b/src/file_7z.c
index bb9675d..583586d 100644
--- a/src/file_7z.c
+++ b/src/file_7z.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_7z)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,6 +59,9 @@ static int header_check_7z(const unsigned char *buffer, const unsigned int buffe
if(buffer_7z->majorversion!=0 ||
le64(buffer_7z->nextHeaderSize)==0)
return 0;
+ if( le64(buffer_7z->nextHeaderOffset) > 0x7000000000000000 ||
+ le64(buffer_7z->nextHeaderSize) > 0x7000000000000000)
+ return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_7z.extension;
file_recovery_new->min_filesize=31;
@@ -74,3 +78,4 @@ static void register_header_check_7z(file_stat_t *file_stat)
static const unsigned char header_7z[6] = {'7','z', 0xbc, 0xaf, 0x27, 0x1c};
register_header_check(0, header_7z, sizeof(header_7z), &header_check_7z, file_stat);
}
+#endif
diff --git a/src/file_DB.c b/src/file_DB.c
index c9a7a42..46d6bca 100644
--- a/src/file_DB.c
+++ b/src/file_DB.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_DB)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_DB(file_stat_t *file_stat)
};
register_header_check(0, DB_header,sizeof(DB_header), &header_check_DB, file_stat);
}
+#endif
diff --git a/src/file_a.c b/src/file_a.c
index 47a606c..f0cac6e 100644
--- a/src/file_a.c
+++ b/src/file_a.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_a)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -73,3 +74,4 @@ static void register_header_check_a(file_stat_t *file_stat)
static const unsigned char a_header[8] = { '!','<','a','r','c','h','>','\n'};
register_header_check(0, a_header,sizeof(a_header), &header_check_a, file_stat);
}
+#endif
diff --git a/src/file_ab.c b/src/file_ab.c
index e6e7381..011e675 100644
--- a/src/file_ab.c
+++ b/src/file_ab.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_addressbook)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -46,8 +47,21 @@ struct ab_header
uint32_t size;
} __attribute__ ((gcc_struct, __packed__));
+/*@
+ @ requires buffer_size > 0;
+ @ requires (buffer_size&1)==0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid(file_recovery);
+ @ requires file_recovery->data_check==&data_check_ab;
+ @ requires \separated(buffer, file_recovery);
+ @ ensures \result == DC_CONTINUE || \result == DC_STOP;
+ @ assigns file_recovery->calculated_file_size;
+ @*/
static data_check_t data_check_addressbook(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
{
@@ -92,3 +106,4 @@ static void register_header_check_ab(file_stat_t *file_stat)
static const unsigned char ab_header[2]={ 'L', 'J' };
register_header_check(0, ab_header,sizeof(ab_header), &header_check_addressbook, file_stat);
}
+#endif
diff --git a/src/file_abr.c b/src/file_abr.c
index 5d07f92..6d243ac 100644
--- a/src/file_abr.c
+++ b/src/file_abr.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_abr)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -49,8 +50,21 @@ const file_hint_t file_hint_abr= {
.register_header_check=&register_header_check_abr
};
+/*@
+ @ requires buffer_size > 0;
+ @ requires (buffer_size&1)==0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid(file_recovery);
+ @ requires file_recovery->data_check==&data_check_abr;
+ @ requires \separated(buffer, file_recovery);
+ @ ensures \result == DC_CONTINUE || \result == DC_STOP;
+ @ assigns file_recovery->calculated_file_size;
+ @*/
static data_check_t data_check_abr(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 12 < file_recovery->file_size + buffer_size/2)
{
@@ -94,3 +108,4 @@ static void register_header_check_abr(file_stat_t *file_stat)
};
register_header_check(2, abr_header, sizeof(abr_header), &header_check_abr, file_stat);
}
+#endif
diff --git a/src/file_acb.c b/src/file_acb.c
index f791fe5..0a0d4a9 100644
--- a/src/file_acb.c
+++ b/src/file_acb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_acb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,3 +60,4 @@ static void register_header_check_acb(file_stat_t *file_stat)
};
register_header_check(0, acb_header, sizeof(acb_header), &header_check_acb, file_stat);
}
+#endif
diff --git a/src/file_ace.c b/src/file_ace.c
index 582e6ca..075dfde 100644
--- a/src/file_ace.c
+++ b/src/file_ace.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ace)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -32,9 +33,15 @@
#include "common.h"
#include "log.h"
#include "crc.h"
+#if defined(__FRAMAC__)
+#include "__fc_builtin.h"
+#endif
/* #define DEBUG_ACE */
+/*@
+ @ requires \valid(file_stat);
+ @*/
static void register_header_check_ace(file_stat_t *file_stat);
const file_hint_t file_hint_ace= {
@@ -61,34 +68,62 @@ struct header_ace {
typedef struct header_ace ace_header_t;
#define BUF_SIZE 4096
+/*@
+ @ requires \valid(handle);
+ @ requires \separated(handle, &errno, &Frama_C_entropy_source);
+ @ assigns *handle, errno;
+ @ assigns Frama_C_entropy_source;
+ @*/
static int check_ace_crc(FILE *handle, const unsigned int len, const unsigned int crc32_low)
{
- unsigned char buffer[BUF_SIZE];
+ char buffer[BUF_SIZE];
uint32_t crc32=0xFFFFFFFF;
unsigned int remaining=len;
+ /*@
+ @ loop assigns *handle, errno;
+ @ loop assigns Frama_C_entropy_source;
+ @ loop assigns buffer[0 .. BUF_SIZE-1], crc32, remaining;
+ @*/
while (remaining>0)
{
const unsigned int count = ((remaining>BUF_SIZE) ? BUF_SIZE : remaining);
if(fread(buffer, 1, count, handle) != count)
{
#ifdef DEBUG_ACE
- log_trace("file_ace: truncated file\n");
+ log_info("file_ace: truncated file\n");
#endif
return 1;
}
+#ifdef __FRAMAC__
+ Frama_C_make_unknown(&buffer, sizeof(buffer));
+#endif
crc32=get_crc32(buffer, count, crc32);
remaining -= count;
}
if (crc32_low != (crc32&0xFFFF))
{
#ifdef DEBUG_ACE
- log_trace("file_ace: bad CRC: %04X vs %04X\n", crc32_low, crc32&0xFFFF);
+ log_info("file_ace: bad CRC: %04X vs %04X\n", crc32_low, crc32&0xFFFF);
#endif
return 1;
}
return 0;
}
+/*@
+ @ requires \valid(file_recovery);
+ @ requires \valid(file_recovery->handle);
+ @ requires \valid_read(&file_recovery->extension);
+ @ requires valid_read_string(file_recovery->extension);
+ @ requires \separated(file_recovery, file_recovery->handle, file_recovery->extension, &errno, &Frama_C_entropy_source);
+ @ requires \initialized(&file_recovery->time);
+ @
+ @ requires file_recovery->file_check == &file_check_ace;
+ @ assigns *file_recovery->handle, errno, file_recovery->file_size, file_recovery->offset_error, file_recovery->offset_ok;
+ @ assigns Frama_C_entropy_source;
+ @
+ @ ensures \valid(file_recovery->handle);
+ @*/
static void file_check_ace(file_recovery_t *file_recovery)
{
file_recovery->offset_error = 0;
@@ -96,58 +131,52 @@ static void file_check_ace(file_recovery_t *file_recovery)
file_recovery->file_size = 0;
if(my_fseek(file_recovery->handle, 0, SEEK_SET)<0)
return ;
-#ifdef DEBUG_ACE
- log_trace("file_check_ace\n");
-#endif
+ /*@
+ @ loop assigns *file_recovery->handle, errno, file_recovery->file_size, file_recovery->offset_error;
+ @ loop assigns Frama_C_entropy_source;
+ @*/
while (!feof(file_recovery->handle))
{
- ace_header_t h;
- size_t res;
- memset(&h, 0, sizeof(h));
- res=fread(&h, 1, sizeof(h), file_recovery->handle);
- if(res==0)
- return ;
- if(res != sizeof(h))
+ char buffer[sizeof(ace_header_t)];
+ const ace_header_t *h=(const ace_header_t *)&buffer;
+ if(fread(&buffer, sizeof(buffer), 1, file_recovery->handle)!= 1)
{
- file_recovery->offset_error=file_recovery->file_size;
- file_recovery->file_size=0;
return ;
}
+#ifdef __FRAMAC__
+ Frama_C_make_unknown(&buffer, sizeof(buffer));
+#endif
#ifdef DEBUG_ACE
- log_trace("file_ace: Block header at 0x%08lx: CRC16=0x%04X size=%u type=%u"
+ log_info("file_ace: Block header at 0x%08lx: CRC16=0x%04X size=%u type=%u"
" flags=0x%04X addsize=%u\n",
(long unsigned) file_recovery->file_size,
- le16(h.crc16), le16(h.size), h.type, le16(h.flags),
- (le16(h.flags)&1) ? le32(h.addsize):0);
+ le16(h->crc16), le16(h->size), h->type, le16(h->flags),
+ (le16(h->flags)&1) ? le32(h->addsize):0);
#endif
/* Type 0=Archive header, 1=File block, 2=Recovery Record, 5 new_recovery ? */
- if (h.type==0 && le16(h.size)==0)
+ if (h->type==0 && le16(h->size)==0)
{
return ;
}
- if (h.type!=0 && h.type!=1 && h.type!=2 && h.type!=5)
+ if (h->type!=0 && h->type!=1 && h->type!=2 && h->type!=5)
{
#ifdef DEBUG_ACE
- log_trace("file_ace: Invalid block type %u\n", h.type);
+ log_info("file_ace: Invalid block type %u\n", h->type);
#endif
- file_recovery->offset_error=file_recovery->file_size;
- file_recovery->file_size=0;
return ;
}
/* Minimal size is type+flags */
- if (le16(h.size) < 1U + 2U)
+ if (le16(h->size) < 1U + 2U)
{
#ifdef DEBUG_ACE
- log_trace("file_ace: Invalid block size %u\n", le16(h.size));
+ log_info("file_ace: Invalid block size %u\n", le16(h->size));
#endif
- file_recovery->offset_error=file_recovery->file_size;
- file_recovery->file_size=0;
return ;
}
- if(my_fseek(file_recovery->handle, -sizeof(h)+4, SEEK_CUR)<0 ||
- check_ace_crc(file_recovery->handle, le16(h.size), le16(h.crc16)) != 0)
+ if(my_fseek(file_recovery->handle, -(off_t)sizeof(ace_header_t)+(off_t)4, SEEK_CUR)<0 ||
+ check_ace_crc(file_recovery->handle, le16(h->size), le16(h->crc16)) != 0)
{
file_recovery->offset_error=file_recovery->file_size;
file_recovery->file_size=0;
@@ -155,11 +184,17 @@ static void file_check_ace(file_recovery_t *file_recovery)
}
/* Add its header size */
- file_recovery->file_size += (uint64_t)4 + le16(h.size); /* +2: CRC16, +2: size */
+ file_recovery->file_size += (uint64_t)4 + le16(h->size); /* +2: CRC16, +2: size */
+
+ if(file_recovery->file_size >= 0x8000000000000000-0x100000000)
+ {
+ file_recovery->file_size=0;
+ return ;
+ }
/* If addsize flag, add complementary size */
- if (le16(h.flags)&1)
+ if (le16(h->flags)&1)
{
- file_recovery->file_size += le32(h.addsize);
+ file_recovery->file_size += le32(h->addsize);
if(my_fseek(file_recovery->handle, file_recovery->file_size, SEEK_SET)<0)
{
file_recovery->offset_error=file_recovery->file_size;
@@ -170,6 +205,36 @@ static void file_check_ace(file_recovery_t *file_recovery)
}
}
+/*@
+ @ requires buffer_size > 0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid_read(file_recovery);
+ @ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
+ @ requires \valid(file_recovery_new);
+ @ requires file_recovery_new->blocksize > 0;
+ @
+ @ requires buffer_size >= sizeof(ace_header_t);
+ @ requires separation: \separated(&file_hint_ace, buffer+(..), file_recovery, file_recovery_new);
+ @
+ @ ensures \result == 0 || \result == 1;
+ @ ensures (\result == 1) ==> (file_recovery_new->file_stat == \null);
+ @ ensures (\result == 1) ==> (file_recovery_new->handle == \null);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->time);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->calculated_file_size);
+ @ ensures (\result == 1) ==> file_recovery_new->file_size == 0;
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->min_filesize);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null || \valid_function(file_recovery_new->data_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == \null || \valid_function(file_recovery_new->file_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename == \null || \valid_function(file_recovery_new->file_rename));
+ @ ensures (\result != 0) ==> file_recovery_new->extension != \null;
+ @ ensures (\result == 1) ==> (valid_read_string(file_recovery_new->extension));
+ @ ensures (\result == 1) ==> \separated(file_recovery_new, file_recovery_new->extension);
+ @
+ @ ensures (\result == 1) ==> (file_recovery_new->time == 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->calculated_file_size == 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->extension == file_hint_ace.extension);
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == &file_check_ace);
+ @*/
static int header_check_ace(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const ace_header_t *h=(const ace_header_t *)buffer;
@@ -193,3 +258,4 @@ static void register_header_check_ace(file_stat_t *file_stat)
static const unsigned char ace_header[7] = { '*','*','A','C','E','*','*'};
register_header_check(7, ace_header,sizeof(ace_header), &header_check_ace, file_stat);
}
+#endif
diff --git a/src/file_ado.c b/src/file_ado.c
index 74c9632..6739505 100644
--- a/src/file_ado.c
+++ b/src/file_ado.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ado)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_ado(file_stat_t *file_stat)
{
register_header_check(0x2c, "\5Black\0\0", 8, &header_check_ado, file_stat);
}
+#endif
diff --git a/src/file_afdesign.c b/src/file_afdesign.c
index af93b7c..c13d6b5 100644
--- a/src/file_afdesign.c
+++ b/src/file_afdesign.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_afdesign)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -76,3 +77,4 @@ static void register_header_check_afdesign(file_stat_t *file_stat)
static const unsigned char afdesign_header[4]= { 0x00, 0xff, 'K' , 'A' };
register_header_check(0, afdesign_header, sizeof(afdesign_header), &header_check_afdesign, file_stat);
}
+#endif
diff --git a/src/file_ahn.c b/src/file_ahn.c
index 8112322..f490ee5 100644
--- a/src/file_ahn.c
+++ b/src/file_ahn.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ahn)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_ahn(file_stat_t *file_stat)
static const unsigned char ahn_magic[10] = {'A','H','N','E','N','B','L','A','T','T'};
register_header_check(8, ahn_magic, sizeof(ahn_magic), &header_check_ahn, file_stat);
}
+#endif
diff --git a/src/file_aif.c b/src/file_aif.c
index 5504f22..69a06d4 100644
--- a/src/file_aif.c
+++ b/src/file_aif.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_aif)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -79,3 +80,4 @@ static void register_header_check_aif(file_stat_t *file_stat)
{
register_header_check(0, "FORM", 4, &header_check_aif, file_stat);
}
+#endif
diff --git a/src/file_all.c b/src/file_all.c
index de7b0ac..9972f25 100644
--- a/src/file_all.c
+++ b/src/file_all.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_all)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_all(file_stat_t *file_stat)
static const unsigned char all_header[8]= { 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x06, 0x04};
register_header_check(0, all_header,sizeof(all_header), &header_check_all, file_stat);
}
+#endif
diff --git a/src/file_als.c b/src/file_als.c
index 5082331..c915341 100644
--- a/src/file_als.c
+++ b/src/file_als.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_als)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -76,3 +77,4 @@ static void register_header_check_als(file_stat_t *file_stat)
};
register_header_check(0, als_header,sizeof(als_header), &header_check_als, file_stat);
}
+#endif
diff --git a/src/file_amd.c b/src/file_amd.c
index 53f6885..cf7d203 100644
--- a/src/file_amd.c
+++ b/src/file_amd.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_amd)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -84,3 +85,4 @@ static void register_header_check_amd(file_stat_t *file_stat)
register_header_check(0, amd_header,sizeof(amd_header), &header_check_amd, file_stat);
register_header_check(0, amt_header,sizeof(amt_header), &header_check_amt, file_stat);
}
+#endif
diff --git a/src/file_amr.c b/src/file_amr.c
index a5ec01c..ac1c132 100644
--- a/src/file_amr.c
+++ b/src/file_amr.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_amr)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -43,8 +44,21 @@ const file_hint_t file_hint_amr= {
.register_header_check=&register_header_check_amr
};
+/*@
+ @ requires buffer_size > 0;
+ @ requires (buffer_size&1)==0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid(file_recovery);
+ @ requires file_recovery->data_check==&data_check_amr;
+ @ requires \separated(buffer, file_recovery);
+ @ ensures \result == DC_CONTINUE || \result == DC_STOP;
+ @ assigns file_recovery->calculated_file_size;
+ @*/
static data_check_t data_check_amr(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 4 < file_recovery->file_size + buffer_size/2)
{
@@ -94,3 +108,4 @@ static void register_header_check_amr(file_stat_t *file_stat)
static const unsigned char amr_header[6]= {'#','!','A','M','R','\n'};
register_header_check(0, amr_header,sizeof(amr_header), &header_check_amr, file_stat);
}
+#endif
diff --git a/src/file_apa.c b/src/file_apa.c
index fc47582..88648fb 100644
--- a/src/file_apa.c
+++ b/src/file_apa.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_apa)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -62,3 +63,4 @@ static int header_check_apa(const unsigned char *buffer, const unsigned int buff
}
return 0;
}
+#endif
diff --git a/src/file_ape.c b/src/file_ape.c
index c013880..b30c52a 100644
--- a/src/file_ape.c
+++ b/src/file_ape.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ape)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -139,3 +140,4 @@ static void register_header_check_ape(file_stat_t *file_stat)
static const unsigned char ape_header[4]= { 'M', 'A', 'C', ' '};
register_header_check(0, ape_header,sizeof(ape_header), &header_check_ape, file_stat);
}
+#endif
diff --git a/src/file_apple.c b/src/file_apple.c
index de63f33..1612ebc 100644
--- a/src/file_apple.c
+++ b/src/file_apple.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_apple)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_apple(file_stat_t *file_stat)
};
register_header_check(0, apple_header,sizeof(apple_header), &header_check_apple, file_stat);
}
+#endif
diff --git a/src/file_ari.c b/src/file_ari.c
index fbe99b6..cc17ef1 100644
--- a/src/file_ari.c
+++ b/src/file_ari.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ari)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -74,3 +75,4 @@ static void register_header_check_ari(file_stat_t *file_stat)
0x00, 0x10, 0x00, 0x00};
register_header_check(0, ari_header, sizeof(ari_header), &header_check_ari, file_stat);
}
+#endif
diff --git a/src/file_arj.c b/src/file_arj.c
index 9bf2c1e..62bf5d0 100644
--- a/src/file_arj.c
+++ b/src/file_arj.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_arj)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -162,3 +163,4 @@ static void register_header_check_arj(file_stat_t *file_stat)
static const unsigned char arj_header[2]={0x60, 0xEA};
register_header_check(0, arj_header,sizeof(arj_header), &header_check_arj, file_stat);
}
+#endif
diff --git a/src/file_asf.c b/src/file_asf.c
index a9a7650..0598f1e 100644
--- a/src/file_asf.c
+++ b/src/file_asf.c
@@ -32,6 +32,7 @@
#include "common.h"
#include "log.h"
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_asf)
static void register_header_check_asf(file_stat_t *file_stat);
static int header_check_asf(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
@@ -156,3 +157,4 @@ static void register_header_check_asf(file_stat_t *file_stat)
};
register_header_check(0, asf_header,sizeof(asf_header), &header_check_asf, file_stat);
}
+#endif
diff --git a/src/file_asl.c b/src/file_asl.c
index 7c541c2..c70b26d 100644
--- a/src/file_asl.c
+++ b/src/file_asl.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_asl)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_asl(file_stat_t *file_stat)
};
register_header_check(0, asl_header, sizeof(asl_header), &header_check_asl, file_stat);
}
+#endif
diff --git a/src/file_asm.c b/src/file_asm.c
index 6026c74..71ef2f8 100644
--- a/src/file_asm.c
+++ b/src/file_asm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_asm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -31,10 +32,7 @@
#include "types.h"
#include "filegen.h"
-
static void register_header_check_asm(file_stat_t *file_stat);
-static int header_check_asm(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
-static void file_check_asm(file_recovery_t *file_recovery);
const file_hint_t file_hint_asm= {
.extension="asm",
@@ -49,9 +47,12 @@ static const unsigned char asm_header[16]= {
'#', 'U', 'G', 'C', ':', '2', ' ', 'A',
'S', 'S', 'E', 'M', 'B', 'L', 'Y', ' '};
-static void register_header_check_asm(file_stat_t *file_stat)
+static void file_check_asm(file_recovery_t *file_recovery)
{
- register_header_check(0, asm_header,sizeof(asm_header), &header_check_asm, file_stat);
+ const unsigned char asm_footer[11]= {
+ '#', 'E', 'N', 'D', '_', 'O', 'F', '_',
+ 'U', 'G', 'C'};
+ file_search_footer(file_recovery, asm_footer, sizeof(asm_footer), 1);
}
static int header_check_asm(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
@@ -64,10 +65,8 @@ static int header_check_asm(const unsigned char *buffer, const unsigned int buff
return 1;
}
-static void file_check_asm(file_recovery_t *file_recovery)
+static void register_header_check_asm(file_stat_t *file_stat)
{
- const unsigned char asm_footer[11]= {
- '#', 'E', 'N', 'D', '_', 'O', 'F', '_',
- 'U', 'G', 'C'};
- file_search_footer(file_recovery, asm_footer, sizeof(asm_footer), 1);
+ register_header_check(0, asm_header,sizeof(asm_header), &header_check_asm, file_stat);
}
+#endif
diff --git a/src/file_atd.c b/src/file_atd.c
index 5478354..409ecb3 100644
--- a/src/file_atd.c
+++ b/src/file_atd.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_atd)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_atd(file_stat_t *file_stat)
'D' ,'A' ,'T' ,'A' ,'B' ,'A' ,'S' ,'E' };
register_header_check(0, atd_header,sizeof(atd_header), &header_check_atd, file_stat);
}
+#endif
diff --git a/src/file_au.c b/src/file_au.c
index bab248b..9d51a78 100644
--- a/src/file_au.c
+++ b/src/file_au.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_au)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -85,3 +86,4 @@ static void register_header_check_au(file_stat_t *file_stat)
static const unsigned char au_header[4]= {'.','s','n','d'};
register_header_check(0, au_header,sizeof(au_header), &header_check_au, file_stat);
}
+#endif
diff --git a/src/file_axp.c b/src/file_axp.c
index 349dc5a..3a8d290 100644
--- a/src/file_axp.c
+++ b/src/file_axp.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_axp)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -41,6 +42,16 @@ const file_hint_t file_hint_axp= {
.register_header_check=&register_header_check_axp
};
+/*@
+ @ requires buffer_size > 0;
+ @ requires (buffer_size&1)==0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid(file_recovery);
+ @ requires file_recovery->data_check==&data_check_axp;
+ @ requires \separated(buffer, file_recovery);
+ @ ensures \result == DC_CONTINUE || \result == DC_STOP;
+ @ assigns file_recovery->calculated_file_size;
+ @*/
static data_check_t data_check_axp(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
const unsigned char axp_footer[34]= {
@@ -51,6 +62,9 @@ static data_check_t data_check_axp(const unsigned char *buffer, const unsigned i
0x0a, 0
};
unsigned int j;
+ /*@
+ @ loop assigns j;
+ @*/
for(j=(buffer_size/2>sizeof(axp_footer)?buffer_size/2-sizeof(axp_footer):0);
j+sizeof(axp_footer) < buffer_size;
j++)
@@ -94,3 +108,4 @@ static void register_header_check_axp(file_stat_t *file_stat)
};
register_header_check(0, axp_header, sizeof(axp_header), &header_check_axp, file_stat);
}
+#endif
diff --git a/src/file_axx.c b/src/file_axx.c
index bc6bc4a..a1d2a1b 100644
--- a/src/file_axx.c
+++ b/src/file_axx.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_axx)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -52,7 +53,7 @@ struct SHeader
static void file_check_axx(file_recovery_t *fr)
{
uint64_t offset=0x10;
- while(1)
+ while(offset < 0x8000000000000000)
{
struct SHeader header;
unsigned int len;
@@ -60,6 +61,9 @@ static void file_check_axx(file_recovery_t *fr)
return ;
if (fread(&header, sizeof(header), 1, fr->handle)!=1)
return ;
+#if defined(__FRAMAC__)
+ Frama_C_make_unknown(&header, sizeof(header));
+#endif
len=le32(header.aoLength);
#ifdef DEBUG_AAX
log_info("axx 0x%llx 0x%x 0x%x/%d\n", (long long int)offset, len, header.oType, header.oType);
@@ -67,6 +71,8 @@ static void file_check_axx(file_recovery_t *fr)
if(len<5)
return ;
offset+=len;
+ if(offset >= 0x8000000000000000)
+ break;
if(header.oType==63) // eData
{
uint64_t fsize;
@@ -74,12 +80,18 @@ static void file_check_axx(file_recovery_t *fr)
return ;
if (fread(&fsize, sizeof(fsize), 1, fr->handle)!=1)
return ;
+#if defined(__FRAMAC__)
+ Frama_C_make_unknown(&fsize, sizeof(fsize));
+#endif
fsize=le64(fsize);
+ if(fsize >= 0x8000000000000000)
+ break;
offset+=fsize;
fr->file_size=(fr->file_size < offset ? 0 : offset);
return ;
}
}
+ fr->file_size=0;
}
static int header_check_axx(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
@@ -90,7 +102,7 @@ static int header_check_axx(const unsigned char *buffer, const unsigned int buff
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_axx.extension;
file_recovery_new->file_check=&file_check_axx;
- file_recovery_new->min_filesize=0x25+le32(header->aoLength);
+ file_recovery_new->min_filesize=(uint64_t)0x25+le32(header->aoLength);
return 1;
}
@@ -104,3 +116,4 @@ static void register_header_check_axx(file_stat_t *file_stat)
};
register_header_check(0, axx_header, sizeof(axx_header), &header_check_axx, file_stat);
}
+#endif
diff --git a/src/file_bac.c b/src/file_bac.c
index e9aada3..c4514f2 100644
--- a/src/file_bac.c
+++ b/src/file_bac.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bac)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -33,6 +34,9 @@
#include "log.h"
#include "memmem.h"
+/*@
+ @ requires \valid(file_stat);
+ @*/
static void register_header_check_bac(file_stat_t *file_stat);
const file_hint_t file_hint_bac= {
@@ -54,6 +58,16 @@ struct block_header
uint32_t VolSessionTime; /* Session Time for Job */
} __attribute__ ((gcc_struct, __packed__));
+/*@
+ @ requires buffer_size >= 2*0x18;
+ @ requires (buffer_size&1)==0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid(file_recovery);
+ @ requires file_recovery->data_check==&data_check_bac;
+ @ requires \separated(buffer, file_recovery);
+ @ ensures \result == DC_CONTINUE || \result == DC_STOP;
+ @ assigns file_recovery->calculated_file_size;
+ @*/
static data_check_t data_check_bac(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
if(buffer_size < 2*0x18)
@@ -62,6 +76,9 @@ static data_check_t data_check_bac(const unsigned char *buffer, const unsigned i
file_recovery->file_check=NULL;
return DC_CONTINUE;
}
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 0x18 < file_recovery->file_size + buffer_size/2)
{
@@ -76,8 +93,10 @@ static data_check_t data_check_bac(const unsigned char *buffer, const unsigned i
#endif
if(memcmp(hdr->ID, "BB02", 4)!=0 || block_size<0x18)
{
+#ifndef __FRAMAC__
log_error("file_bac.c: invalid block at %llu\n",
(long long unsigned)file_recovery->calculated_file_size);
+#endif
return DC_STOP;
}
file_recovery->calculated_file_size+=(uint64_t)block_size;
@@ -89,6 +108,24 @@ static data_check_t data_check_bac(const unsigned char *buffer, const unsigned i
return DC_CONTINUE;
}
+/*@
+ @ requires buffer_size >= sizeof(struct block_header);
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid_read(file_recovery);
+ @ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
+ @ requires \valid(file_recovery_new);
+ @ requires file_recovery_new->blocksize > 0;
+ @ requires separation: \separated(&file_hint_bac, buffer, file_recovery, file_recovery_new);
+ @ ensures \result == 0 || \result == 1;
+ @ ensures (\result == 1) ==> (file_recovery_new->file_stat == \null);
+ @ ensures (\result == 1) ==> (file_recovery_new->handle == \null);
+ @ ensures (\result == 1) ==> (file_recovery_new->time == 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->file_size == 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->calculated_file_size == 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null || file_recovery_new->data_check == &data_check_bac);
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == \null || file_recovery_new->file_check == &file_check_size);
+ @ ensures (\result == 1) ==> (file_recovery_new->extension == file_hint_bac.extension);
+ @*/
static int header_check_bac(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const struct block_header *hdr=(const struct block_header *)buffer;
@@ -111,3 +148,4 @@ static void register_header_check_bac(file_stat_t *file_stat)
static const unsigned char bac_header[8]={ 0, 0, 0, 0, 'B', 'B', '0', '2' };
register_header_check(8, bac_header, sizeof(bac_header), &header_check_bac, file_stat);
}
+#endif
diff --git a/src/file_bdm.c b/src/file_bdm.c
index 84512e8..cd5066d 100644
--- a/src/file_bdm.c
+++ b/src/file_bdm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bdm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_bdm(file_stat_t *file_stat)
register_header_check(0, "INDX0100", 8, &header_check_bdm, file_stat);
register_header_check(0, "MOBJ0100", 8, &header_check_bdm, file_stat);
}
+#endif
diff --git a/src/file_berkeley.c b/src/file_berkeley.c
index 3f5452a..67dbd1f 100644
--- a/src/file_berkeley.c
+++ b/src/file_berkeley.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_berkeley)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -72,3 +73,4 @@ static void register_header_check_berkeley_le(file_stat_t *file_stat)
register_header_check(0xC, berkeley_db_btree_8, 8, &header_check_berkeley_le, file_stat);
register_header_check(0xC, berkeley_db_btree_9, 8, &header_check_berkeley_le, file_stat);
}
+#endif
diff --git a/src/file_bfa.c b/src/file_bfa.c
new file mode 100644
index 0000000..573b9ec
--- /dev/null
+++ b/src/file_bfa.c
@@ -0,0 +1,78 @@
+/*
+
+ File: file_bfa.c
+
+ Copyright (C) 2019 Christophe GRENIER <grenier@cgsecurity.org>
+
+ This software is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write the Free Software Foundation, Inc., 51
+ Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ */
+
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bfa)
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include <stdio.h>
+#include "types.h"
+#include "filegen.h"
+#include "common.h"
+
+static void register_header_check_bfa(file_stat_t *file_stat);
+
+const file_hint_t file_hint_bfa= {
+ .extension="bfa",
+ .description="Blowfish Advanced CS",
+ .max_filesize=PHOTOREC_MAX_FILE_SIZE,
+ .recover=1,
+ .enable_by_default=1,
+ .register_header_check=&register_header_check_bfa
+};
+
+struct bfa_header
+{
+ uint32_t lMagic;
+ uint16_t wSizeOfHeader;
+ uint16_t wVersion;
+ uint64_t lLength;
+ uint16_t wCipherInitDataSize;
+ uint16_t wCipherBlockSize;
+ uint8_t salt[11];
+ uint32_t lKeyHash;
+} __attribute__ ((gcc_struct, __packed__));
+
+static int header_check_bfa(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
+{
+ const struct bfa_header *header=(const struct bfa_header*)buffer;
+ uint64_t size=le64(header->lLength);
+ if(size > PHOTOREC_MAX_FILE_SIZE)
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_bfa.extension;
+ file_recovery_new->calculated_file_size=size + le16(header->wSizeOfHeader);
+ file_recovery_new->file_check=&file_check_size_min;
+ return 1;
+}
+
+static void register_header_check_bfa(file_stat_t *file_stat)
+{
+ static const unsigned char bfa_header[8]= {
+ 0x24, 0x08, 0x19, 0x92, 0x23, 0x00, 0x15, 0x01
+ };
+ register_header_check(0, bfa_header, sizeof(bfa_header), &header_check_bfa, file_stat);
+}
+#endif
diff --git a/src/file_bim.c b/src/file_bim.c
index 7fbc9b3..10ebb23 100644
--- a/src/file_bim.c
+++ b/src/file_bim.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bim)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,3 +59,4 @@ static void register_header_check_bim(file_stat_t *file_stat)
};
register_header_check(0, bim_header, sizeof(bim_header), &header_check_bim, file_stat);
}
+#endif
diff --git a/src/file_bin.c b/src/file_bin.c
index 5dabdb2..7be6a4c 100644
--- a/src/file_bin.c
+++ b/src/file_bin.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bin)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -72,3 +73,4 @@ static void register_header_check_bin(file_stat_t *file_stat)
'i' , 'c' , 'k' , 'e' , 't' , 's' };
register_header_check(6, bin_header, sizeof(bin_header), &header_check_bin, file_stat);
}
+#endif
diff --git a/src/file_binvox.c b/src/file_binvox.c
index b4ac7d8..4d6886c 100644
--- a/src/file_binvox.c
+++ b/src/file_binvox.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_binvox)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -52,3 +53,4 @@ static void register_header_check_binvox(file_stat_t *file_stat)
{
register_header_check(0, "#binvox 1\ndim ", 14, &header_check_binvox, file_stat);
}
+#endif
diff --git a/src/file_bkf.c b/src/file_bkf.c
index bebc131..5aac25c 100644
--- a/src/file_bkf.c
+++ b/src/file_bkf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bkf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -32,12 +33,15 @@
#include "common.h"
#include "log.h"
+/*@
+ @ requires \valid(file_stat);
+ @*/
static void register_header_check_bkf(file_stat_t *file_stat);
const file_hint_t file_hint_bkf= {
.extension="bkf",
.description="MS Backup file",
- .max_filesize=-1,
+ .max_filesize=PHOTOREC_MAX_FILE_SIZE,
.recover=1,
.enable_by_default=1,
.register_header_check=&register_header_check_bkf
@@ -62,12 +66,57 @@ struct mtf_db_hdr
uint16_t check; /* header checksum */
} __attribute__ ((gcc_struct, __packed__));
+/*@
+ @ requires \valid(file_recovery);
+ @ requires \valid(file_recovery->handle);
+ @ requires \valid_read(&file_recovery->extension);
+ @ requires valid_read_string(file_recovery->extension);
+ @ requires \separated(file_recovery, file_recovery->handle, file_recovery->extension, &errno, &Frama_C_entropy_source);
+ @ requires \initialized(&file_recovery->time);
+ @
+ @ requires file_recovery->file_check == &file_check_bkf;
+ @ assigns *file_recovery->handle, errno, file_recovery->file_size;
+ @ assigns Frama_C_entropy_source;
+ @
+ @ ensures \valid(file_recovery->handle);
+ @*/
static void file_check_bkf(file_recovery_t *file_recovery)
{
const unsigned char bkf_footer[4]= { 'S', 'F', 'M', 'B'};
file_search_footer(file_recovery, bkf_footer, sizeof(bkf_footer), 0x400-4);
}
+/*@
+ @ requires buffer_size > 0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid_read(file_recovery);
+ @ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
+ @ requires \valid(file_recovery_new);
+ @ requires file_recovery_new->blocksize > 0;
+ @
+ @ requires buffer_size >= sizeof(struct mtf_db_hdr);
+ @ requires separation: \separated(&file_hint_bkf, buffer+(..), file_recovery, file_recovery_new);
+ @
+ @ ensures \result == 0 || \result == 1;
+ @ ensures (\result == 1) ==> (file_recovery_new->file_stat == \null);
+ @ ensures (\result == 1) ==> (file_recovery_new->handle == \null);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->time);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->calculated_file_size);
+ @ ensures (\result == 1) ==> file_recovery_new->file_size == 0;
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->min_filesize);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null || \valid_function(file_recovery_new->data_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == \null || \valid_function(file_recovery_new->file_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename == \null || \valid_function(file_recovery_new->file_rename));
+ @ ensures (\result != 0) ==> file_recovery_new->extension != \null;
+ @ ensures (\result == 1) ==> (valid_read_string(file_recovery_new->extension));
+ @ ensures (\result == 1) ==> \separated(file_recovery_new, file_recovery_new->extension);
+ @
+ @ ensures (\result == 1) ==> (file_recovery_new->time == 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->calculated_file_size == 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->min_filesize == 52);
+ @ ensures (\result == 1) ==> (file_recovery_new->extension == file_hint_bkf.extension);
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == &file_check_bkf);
+ @*/
static int header_check_bkf(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const struct mtf_db_hdr *hdr=(const struct mtf_db_hdr *)buffer;
@@ -94,3 +143,4 @@ static void register_header_check_bkf(file_stat_t *file_stat)
static const unsigned char bkf_header[4]= { 'T','A','P','E'};
register_header_check(0, bkf_header,sizeof(bkf_header), &header_check_bkf, file_stat);
}
+#endif
diff --git a/src/file_bld.c b/src/file_bld.c
index 3fc5b26..5653189 100644
--- a/src/file_bld.c
+++ b/src/file_bld.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_blend)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -31,6 +32,9 @@
#include "filegen.h"
#include "log.h"
+/*@
+ @ requires \valid(file_stat);
+ @*/
static void register_header_check_blend(file_stat_t *file_stat);
const file_hint_t file_hint_blend= {
@@ -44,8 +48,19 @@ const file_hint_t file_hint_blend= {
static const unsigned char blend_header_footer[4] = { 'E', 'N', 'D', 'B'};
+/*@
+ @ requires buffer_size > 0;
+ @ requires (buffer_size&1)==0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid(file_recovery);
+ @ requires file_recovery->data_check==&data_check_blend4le;
+ @ requires \separated(buffer, file_recovery);
+ @ ensures \result == DC_CONTINUE || \result == DC_STOP;
+ @ assigns file_recovery->calculated_file_size;
+ @*/
static data_check_t data_check_blend4le(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@ loop assigns file_recovery->calculated_file_size; */
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 0x14 < file_recovery->file_size + buffer_size/2)
{
@@ -68,8 +83,19 @@ static data_check_t data_check_blend4le(const unsigned char *buffer, const unsig
return DC_CONTINUE;
}
+/*@
+ @ requires buffer_size > 0;
+ @ requires (buffer_size&1)==0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid(file_recovery);
+ @ requires file_recovery->data_check==&data_check_blend8le;
+ @ requires \separated(buffer, file_recovery);
+ @ ensures \result == DC_CONTINUE || \result == DC_STOP;
+ @ assigns file_recovery->calculated_file_size;
+ @*/
static data_check_t data_check_blend8le(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@ loop assigns file_recovery->calculated_file_size; */
while(file_recovery->calculated_file_size + 0x18 < file_recovery->file_size + buffer_size/2)
{
const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
@@ -91,8 +117,19 @@ static data_check_t data_check_blend8le(const unsigned char *buffer, const unsig
return DC_CONTINUE;
}
+/*@
+ @ requires buffer_size > 0;
+ @ requires (buffer_size&1)==0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid(file_recovery);
+ @ requires file_recovery->data_check==&data_check_blend4be;
+ @ requires \separated(buffer, file_recovery);
+ @ ensures \result == DC_CONTINUE || \result == DC_STOP;
+ @ assigns file_recovery->calculated_file_size;
+ @*/
static data_check_t data_check_blend4be(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@ loop assigns file_recovery->calculated_file_size; */
while(file_recovery->calculated_file_size + 0x14 < file_recovery->file_size + buffer_size/2)
{
const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
@@ -114,8 +151,19 @@ static data_check_t data_check_blend4be(const unsigned char *buffer, const unsig
return DC_CONTINUE;
}
+/*@
+ @ requires buffer_size > 0;
+ @ requires (buffer_size&1)==0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid(file_recovery);
+ @ requires file_recovery->data_check==&data_check_blend8be;
+ @ requires \separated(buffer, file_recovery);
+ @ ensures \result == DC_CONTINUE || \result == DC_STOP;
+ @ assigns file_recovery->calculated_file_size;
+ @*/
static data_check_t data_check_blend8be(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@ loop assigns file_recovery->calculated_file_size; */
while(file_recovery->calculated_file_size + 0x18 < file_recovery->file_size + buffer_size/2)
{
const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
@@ -137,6 +185,42 @@ static data_check_t data_check_blend8be(const unsigned char *buffer, const unsig
return DC_CONTINUE;
}
+/*@
+ @ requires buffer_size > 0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid_read(file_recovery);
+ @ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
+ @ requires \valid(file_recovery_new);
+ @ requires file_recovery_new->blocksize > 0;
+ @
+ @ requires buffer_size >= 8;
+ @ requires separation: \separated(&file_hint_blend, buffer+(..), file_recovery, file_recovery_new);
+ @
+ @ ensures \result == 0 || \result == 1;
+ @ ensures (\result == 1) ==> (file_recovery_new->file_stat == \null);
+ @ ensures (\result == 1) ==> (file_recovery_new->handle == \null);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->time);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->calculated_file_size);
+ @ ensures (\result == 1) ==> file_recovery_new->file_size == 0;
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->min_filesize);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null || \valid_function(file_recovery_new->data_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == \null || \valid_function(file_recovery_new->file_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename == \null || \valid_function(file_recovery_new->file_rename));
+ @ ensures (\result != 0) ==> file_recovery_new->extension != \null;
+ @ ensures (\result == 1) ==> (valid_read_string(file_recovery_new->extension));
+ @ ensures (\result == 1) ==> \separated(file_recovery_new, file_recovery_new->extension);
+ @
+ @ ensures (\result == 1) ==> (file_recovery_new->time == 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->calculated_file_size == 12);
+ @ ensures (\result == 1) ==> (file_recovery_new->extension == file_hint_blend.extension);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == &data_check_blend4be ||
+ file_recovery_new->data_check == &data_check_blend4le ||
+ file_recovery_new->data_check == &data_check_blend8be ||
+ file_recovery_new->data_check == &data_check_blend8le
+ );
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == &file_check_size);
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename == \null);
+ @*/
static int header_check_blend(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
if(buffer[7]!='_' && buffer[7]!='-')
@@ -169,3 +253,4 @@ static void register_header_check_blend(file_stat_t *file_stat)
static const unsigned char blend_header[7] = { 'B', 'L', 'E', 'N', 'D', 'E', 'R'};
register_header_check(0, blend_header,sizeof(blend_header), &header_check_blend, file_stat);
}
+#endif
diff --git a/src/file_bmp.c b/src/file_bmp.c
index afef52b..b2d56b0 100644
--- a/src/file_bmp.c
+++ b/src/file_bmp.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bmp)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -144,6 +145,7 @@ static void register_header_check_bmp(file_stat_t *file_stat)
{
register_header_check(0, bmp_header,sizeof(bmp_header), &header_check_bmp, file_stat);
}
+#endif
#if defined(MAIN_bmp)
#define BLOCKSIZE 65536u
diff --git a/src/file_bpg.c b/src/file_bpg.c
index bc16eb5..e6dbaa1 100644
--- a/src/file_bpg.c
+++ b/src/file_bpg.c
@@ -6,7 +6,7 @@
Copyright (C) 2016 Dmitry Brant <me@dmitrybrant.com>
BPG specification can be found at:
- http://bellard.org/bpg/bpg_spec.txt
+ https://bellard.org/bpg/bpg_spec.txt
This software is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bpg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -47,10 +48,22 @@ const file_hint_t file_hint_bpg= {
.register_header_check=&register_header_check_bpg
};
+/*@
+ @ requires buffer_size > 0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid(buf_ptr);
+ @ requires \separated(buffer+(..), buf_ptr);
+ @*/
static unsigned int getue32(const unsigned char *buffer, const unsigned int buffer_size, unsigned int *buf_ptr)
{
- unsigned int value = 0;
+ uint64_t value = 0;
int bitsRead = 0;
+ /*@
+ @ loop invariant bitsRead <= 35;
+ @ loop invariant value < (bitsRead == 0 ? 1: (0x80 << (bitsRead-7)));
+ @ loop assigns value, bitsRead, *buf_ptr;
+ @ loop variant 35 - bitsRead;
+ @ */
while (*buf_ptr < buffer_size)
{
const unsigned int b = buffer[*buf_ptr];
@@ -63,9 +76,39 @@ static unsigned int getue32(const unsigned char *buffer, const unsigned int buff
if (bitsRead >= 32)
break;
}
- return value;
+ return value&0xffffffff;
}
+/*@
+ @ requires buffer_size > 0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid_read(file_recovery);
+ @ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
+ @ requires \valid(file_recovery_new);
+ @ requires file_recovery_new->blocksize > 0;
+ @
+ @ requires buffer_size >= 6+3*5;
+ @ requires separation: \separated(&file_hint_bpg, buffer+(..), file_recovery, file_recovery_new);
+ @
+ @ ensures \result == 0 || \result == 1;
+ @ ensures (\result == 1) ==> (file_recovery_new->file_stat == \null);
+ @ ensures (\result == 1) ==> (file_recovery_new->handle == \null);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->time);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->calculated_file_size);
+ @ ensures (\result == 1) ==> file_recovery_new->file_size == 0;
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->min_filesize);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null || \valid_function(file_recovery_new->data_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == \null || \valid_function(file_recovery_new->file_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename == \null || \valid_function(file_recovery_new->file_rename));
+ @ ensures (\result != 0) ==> file_recovery_new->extension != \null;
+ @ ensures (\result == 1) ==> (valid_read_string(file_recovery_new->extension));
+ @ ensures (\result == 1) ==> \separated(file_recovery_new, file_recovery_new->extension);
+ @
+ @ ensures (\result == 1) ==> (file_recovery_new->time == 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->extension == file_hint_bpg.extension);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check== &data_check_size);
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == &file_check_size);
+ @*/
static int header_check_bpg(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
unsigned int buf_ptr = 6;
@@ -73,7 +116,7 @@ static int header_check_bpg(const unsigned char *buffer, const unsigned int buff
const unsigned int picture_width = getue32(buffer, buffer_size, &buf_ptr);
// get image height
const unsigned int picture_height = getue32(buffer, buffer_size, &buf_ptr);
- unsigned int size = getue32(buffer, buffer_size, &buf_ptr);
+ uint64_t size = getue32(buffer, buffer_size, &buf_ptr);
if(picture_width==0 || picture_height==0)
return 0;
if (size == 0) {
@@ -94,3 +137,4 @@ static void register_header_check_bpg(file_stat_t *file_stat)
static const unsigned char bpg_header[4]= {'B','P','G',0xFB};
register_header_check(0, bpg_header,sizeof(bpg_header), &header_check_bpg, file_stat);
}
+#endif
diff --git a/src/file_bvr.c b/src/file_bvr.c
index 1b4a43d..ca02620 100644
--- a/src/file_bvr.c
+++ b/src/file_bvr.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bvr)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -43,6 +44,9 @@ const file_hint_t file_hint_bvr= {
static data_check_t data_check_bvr(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 16 < file_recovery->file_size + buffer_size/2)
{
@@ -77,3 +81,4 @@ static void register_header_check_bvr(file_stat_t *file_stat)
static const unsigned char bvrheader[8]= { 'B', 'L', 'U', 'E', 0x20, 0x00, 0x10, 0x00};
register_header_check(0, bvrheader, sizeof(bvrheader), &header_check_bvr, file_stat);
}
+#endif
diff --git a/src/file_bz2.c b/src/file_bz2.c
index 191bcd6..7aba0e9 100644
--- a/src/file_bz2.c
+++ b/src/file_bz2.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bz2)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,3 +60,4 @@ static int header_check_bz2(const unsigned char *buffer, const unsigned int buff
}
return 0;
}
+#endif
diff --git a/src/file_c4d.c b/src/file_c4d.c
index aafaded..48681ca 100644
--- a/src/file_c4d.c
+++ b/src/file_c4d.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_c4d)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -52,3 +53,4 @@ static void register_header_check_c4d(file_stat_t *file_stat)
{
register_header_check(0, "QC4DC4D6", 8, &header_check_c4d, file_stat);
}
+#endif
diff --git a/src/file_cab.c b/src/file_cab.c
index 16db328..0e9bda4 100644
--- a/src/file_cab.c
+++ b/src/file_cab.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cab)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -77,3 +78,4 @@ static void register_header_check_cab(file_stat_t *file_stat)
static const unsigned char cab_header[4] = { 'M','S','C','F'};
register_header_check(0, cab_header,sizeof(cab_header), &header_check_cab, file_stat);
}
+#endif
diff --git a/src/file_caf.c b/src/file_caf.c
index 521a0b9..fbde9e3 100644
--- a/src/file_caf.c
+++ b/src/file_caf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_caf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -46,7 +47,7 @@ const file_hint_t file_hint_caf= {
.register_header_check=&register_header_check_caf
};
-/* http://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CAFSpec/CAF_spec/CAF_spec.html */
+/* https://developer.apple.com/library/archive/documentation/MusicAudio/Reference/CAFSpec/CAF_spec/CAF_spec.html */
struct chunk_struct
{
@@ -56,6 +57,9 @@ struct chunk_struct
static data_check_t data_check_caf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 12 < file_recovery->file_size + buffer_size/2)
{
@@ -97,7 +101,7 @@ static data_check_t data_check_caf(const unsigned char *buffer, const unsigned i
static int header_check_caf(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const struct chunk_struct *chunk=(const struct chunk_struct*)&buffer[8];
- const int64_t chunk_size=be64(chunk->size);
+ const int64_t chunk_size=(int64_t)be64(chunk->size);
if(chunk_size < 0)
return 0;
reset_file_recovery(file_recovery_new);
@@ -120,3 +124,4 @@ static void register_header_check_caf(file_stat_t *file_stat)
};
register_header_check(0, caf_header, sizeof(caf_header), &header_check_caf, file_stat);
}
+#endif
diff --git a/src/file_cam.c b/src/file_cam.c
index b62431d..ad6f804 100644
--- a/src/file_cam.c
+++ b/src/file_cam.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cam)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_cam(file_stat_t *file_stat)
static const unsigned char cam_header[4]= {0x07, 0x20, 'M', 'M'};
register_header_check(0, cam_header,sizeof(cam_header), &header_check_cam, file_stat);
}
+#endif
diff --git a/src/file_catdrawing.c b/src/file_catdrawing.c
index a76b775..3748397 100644
--- a/src/file_catdrawing.c
+++ b/src/file_catdrawing.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_catdrawing)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_catdrawing(file_stat_t *file_stat)
};
register_header_check(0, catdrawing_header, sizeof(catdrawing_header), &header_check_catdrawing, file_stat);
}
+#endif
diff --git a/src/file_cdt.c b/src/file_cdt.c
index 3a90db5..1a2c7b8 100644
--- a/src/file_cdt.c
+++ b/src/file_cdt.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cdt)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -62,3 +63,4 @@ static void register_header_check_cdt(file_stat_t *file_stat)
};
register_header_check(12, cdt_header, sizeof(cdt_header), &header_check_cdt, file_stat);
}
+#endif
diff --git a/src/file_che.c b/src/file_che.c
index 17a2641..b290e5d 100644
--- a/src/file_che.c
+++ b/src/file_che.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_che)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -97,3 +98,4 @@ static void register_header_check_che(file_stat_t *file_stat)
{
register_header_check(0, "Compucon EOS Design File", 24, &header_check_che, file_stat);
}
+#endif
diff --git a/src/file_chm.c b/src/file_chm.c
index cc4b65a..597ffe9 100644
--- a/src/file_chm.c
+++ b/src/file_chm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_chm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -60,3 +61,4 @@ static void register_header_check_chm(file_stat_t *file_stat)
0x60, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
register_header_check(0, chm_header,sizeof(chm_header), &header_check_chm, file_stat);
}
+#endif
diff --git a/src/file_class.c b/src/file_class.c
index 91f446e..38e23e4 100644
--- a/src/file_class.c
+++ b/src/file_class.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_class)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -71,3 +72,4 @@ static int header_check_class(const unsigned char *buffer, const unsigned int bu
}
return 0;
}
+#endif
diff --git a/src/file_cm.c b/src/file_cm.c
index 0f25a05..c8a6b26 100644
--- a/src/file_cm.c
+++ b/src/file_cm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_cm(file_stat_t *file_stat)
static const unsigned char cm_header[8] = { 'f','L','m','C','0','0','0','1'};
register_header_check(0x0, cm_header,sizeof(cm_header), &header_check_cm, file_stat);
}
+#endif
diff --git a/src/file_compress.c b/src/file_compress.c
index 7722128..fcdf338 100644
--- a/src/file_compress.c
+++ b/src/file_compress.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_compress)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_compress(file_stat_t *file_stat)
static const unsigned char compress_header[9] = {'S', 'Z', 'D', 'D', 0x88, 0xf0, 0x27, 0x33, 'A'};
register_header_check(0, compress_header, sizeof(compress_header), &header_check_compress, file_stat);
}
+#endif
diff --git a/src/file_cow.c b/src/file_cow.c
index b0de7cb..b1f5b72 100644
--- a/src/file_cow.c
+++ b/src/file_cow.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cow)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -127,3 +128,4 @@ static void register_header_check_cow(file_stat_t *file_stat)
register_header_check(0, cow_header2,sizeof(cow_header2), &header_check_qcow2, file_stat);
register_header_check(0, cow_header3,sizeof(cow_header3), &header_check_qcow2, file_stat);
}
+#endif
diff --git a/src/file_cpi.c b/src/file_cpi.c
index 8d7ad5c..54f8a76 100644
--- a/src/file_cpi.c
+++ b/src/file_cpi.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cpi)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -52,3 +53,4 @@ static void register_header_check_cpi(file_stat_t *file_stat)
{
register_header_check(0, "HDMV0100", 8, &header_check_cpi, file_stat);
}
+#endif
diff --git a/src/file_crw.c b/src/file_crw.c
index 6db052d..7fc5c97 100644
--- a/src/file_crw.c
+++ b/src/file_crw.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_crw)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -71,3 +72,4 @@ static void file_check_crw(file_recovery_t *file_recovery)
const unsigned char crw_footer[2]= { 0x0A, 0x30};
file_search_footer(file_recovery, crw_footer, sizeof(crw_footer), 12);
}
+#endif
diff --git a/src/file_csh.c b/src/file_csh.c
index 50c20a7..73fc76c 100644
--- a/src/file_csh.c
+++ b/src/file_csh.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_csh)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_csh(file_stat_t *file_stat)
};
register_header_check(0, csh_header, sizeof(csh_header), &header_check_csh, file_stat);
}
+#endif
diff --git a/src/file_ctg.c b/src/file_ctg.c
index 991c31b..d661aaf 100644
--- a/src/file_ctg.c
+++ b/src/file_ctg.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ctg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_ctg(file_stat_t *file_stat)
static const unsigned char ctg_header[7]= {':','\\','D','C','I','M','\\'};
register_header_check(1, ctg_header,sizeof(ctg_header), &header_check_ctg, file_stat);
}
+#endif
diff --git a/src/file_cwk.c b/src/file_cwk.c
index cba78e6..6b9f1b2 100644
--- a/src/file_cwk.c
+++ b/src/file_cwk.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cwk)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -86,3 +87,4 @@ static void register_header_check_cwk(file_stat_t *file_stat)
static const unsigned char cwk_header[4]= {'B','O','B','O'};
register_header_check(4, cwk_header,sizeof(cwk_header), &header_check_cwk, file_stat);
}
+#endif
diff --git a/src/file_d2s.c b/src/file_d2s.c
index 9a3779a..3aa8954 100644
--- a/src/file_d2s.c
+++ b/src/file_d2s.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_d2s)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -46,7 +47,7 @@ struct d2s_header {
uint32_t size;
uint32_t unk1;
uint32_t unk2;
- char name[0];
+// char name[0];
} __attribute__ ((gcc_struct, __packed__));
static void file_rename_d2s(file_recovery_t *file_recovery)
@@ -82,3 +83,4 @@ static void register_header_check_d2s(file_stat_t *file_stat)
};
register_header_check(0, d2s_header,sizeof(d2s_header), &header_check_d2s, file_stat);
}
+#endif
diff --git a/src/file_dad.c b/src/file_dad.c
index f4e5794..b99bf43 100644
--- a/src/file_dad.c
+++ b/src/file_dad.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dad)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,6 +54,9 @@ struct dad_header
static data_check_t data_check_dad(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 16 <= file_recovery->file_size + buffer_size/2)
{
@@ -98,3 +102,4 @@ static void register_header_check_dad(file_stat_t *file_stat)
{
register_header_check(0, "DHAV", 4, &header_check_dad, file_stat);
}
+#endif
diff --git a/src/file_dar.c b/src/file_dar.c
index f642493..52ce361 100644
--- a/src/file_dar.c
+++ b/src/file_dar.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dar)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -61,3 +62,4 @@ static void register_header_check_dar(file_stat_t *file_stat)
};
register_header_check(0, dar_header, sizeof(dar_header), &header_check_dar, file_stat);
}
+#endif
diff --git a/src/file_dat.c b/src/file_dat.c
index 3618323..370fbed 100644
--- a/src/file_dat.c
+++ b/src/file_dat.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dat)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -93,3 +94,4 @@ static void register_header_check_dat(file_stat_t *file_stat)
register_header_check(4, dat_history, sizeof(dat_history), &header_check_dat_history4, file_stat);
register_header_check(10, dat_history, sizeof(dat_history), &header_check_dat_history10, file_stat);
}
+#endif
diff --git a/src/file_dbf.c b/src/file_dbf.c
index 19b30b6..085dc20 100644
--- a/src/file_dbf.c
+++ b/src/file_dbf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dbf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -66,3 +67,4 @@ static int header_check_dbf(const unsigned char *buffer, const unsigned int buff
}
return 0;
}
+#endif
diff --git a/src/file_dbn.c b/src/file_dbn.c
index 44a8575..e857051 100644
--- a/src/file_dbn.c
+++ b/src/file_dbn.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dbn)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,3 +60,4 @@ static void register_header_check_dbn(file_stat_t *file_stat)
};
register_header_check(0, dbn_header, sizeof(dbn_header), &header_check_dbn, file_stat);
}
+#endif
diff --git a/src/file_dcm.c b/src/file_dcm.c
index 81a62a7..f0eb886 100644
--- a/src/file_dcm.c
+++ b/src/file_dcm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dcm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_dcm(file_stat_t *file_stat)
'U' , 'L' };
register_header_check(0x80, dcm_header, sizeof(dcm_header), &header_check_dcm, file_stat);
}
+#endif
diff --git a/src/file_ddf.c b/src/file_ddf.c
index 805c95c..401d97d 100644
--- a/src/file_ddf.c
+++ b/src/file_ddf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ddf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -138,3 +139,4 @@ static void register_header_check_ddf(file_stat_t *file_stat)
register_header_check(0, ddf4_header, sizeof(ddf4_header), &header_check_ddf4, file_stat);
register_header_check(0, ddf5_header, sizeof(ddf5_header), &header_check_ddf5, file_stat);
}
+#endif
diff --git a/src/file_dex.c b/src/file_dex.c
index a79e864..3c1b229 100644
--- a/src/file_dex.c
+++ b/src/file_dex.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dex)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -93,3 +94,4 @@ static void register_header_check_dex(file_stat_t *file_stat)
static const unsigned char dex_header[4]= {'d','e','x','\n'};
register_header_check(0, dex_header,sizeof(dex_header), &header_check_dex, file_stat);
}
+#endif
diff --git a/src/file_dim.c b/src/file_dim.c
index 02a3731..dae7824 100644
--- a/src/file_dim.c
+++ b/src/file_dim.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dim)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_dim(file_stat_t *file_stat)
static const unsigned char dim_header[4]= { 'S', 'P','C','I'};
register_header_check(0x0c, dim_header,sizeof(dim_header), &header_check_dim, file_stat);
}
+#endif
diff --git a/src/file_dir.c b/src/file_dir.c
index 09a5b96..9d445e8 100644
--- a/src/file_dir.c
+++ b/src/file_dir.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dir)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -33,10 +34,8 @@
#include "types.h"
#include "filegen.h"
#include "common.h"
-#include "fat.h"
-#include "dir.h"
-#include "fat_dir.h"
#include "fat_common.h"
+#include "fat_dir.h"
static void register_header_check_dir(file_stat_t *file_stat);
static int header_check_dir(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
@@ -50,6 +49,11 @@ const file_hint_t file_hint_dir= {
.register_header_check=&register_header_check_dir
};
+/*@
+ @ requires \valid(file_recovery);
+ @ requires valid_read_string((char*)&file_recovery->filename);
+ @ requires file_recovery->file_rename==&file_rename_fatdir;
+ @*/
static void file_rename_fatdir(file_recovery_t *file_recovery)
{
unsigned char buffer[512];
@@ -68,6 +72,15 @@ static void file_rename_fatdir(file_recovery_t *file_recovery)
file_rename(file_recovery, buffer_cluster, strlen(buffer_cluster), 0, NULL, 1);
}
+/*@
+ @ requires buffer_size >= 2;
+ @ requires (buffer_size&1)==0;
+ @ requires \valid_read((char *)buffer+(0..buffer_size-1));
+ @ requires \valid(file_recovery);
+ @ requires file_recovery->data_check == &data_check_fatdir;
+ @ ensures \result == DC_STOP;
+ @ assigns file_recovery->calculated_file_size;
+ @*/
static data_check_t data_check_fatdir(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
/* Save only one cluster */
@@ -75,6 +88,15 @@ static data_check_t data_check_fatdir(const unsigned char *buffer, const unsigne
return DC_STOP;
}
+/*@
+ @ requires buffer_size >= sizeof(struct msdos_dir_entry);
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid_read(file_recovery);
+ @ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
+ @ requires \valid(file_recovery_new);
+ @ requires file_recovery_new->blocksize > 0;
+ @ requires separation: \separated(&file_hint_dir, buffer+(..), file_recovery, file_recovery_new);
+ @*/
static int header_check_dir(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const struct msdos_dir_entry *de=(const struct msdos_dir_entry*)buffer;
@@ -89,7 +111,11 @@ static int header_check_dir(const unsigned char *buffer, const unsigned int buff
return 1;
}
+/*@
+ @ requires \valid(file_stat);
+ @*/
static void register_header_check_dir(file_stat_t *file_stat)
{
register_header_check(0, ". ", 8+3, &header_check_dir, file_stat);
}
+#endif
diff --git a/src/file_djv.c b/src/file_djv.c
index 3e4300d..2d3731b 100644
--- a/src/file_djv.c
+++ b/src/file_djv.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_djv)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -68,3 +69,4 @@ static void register_header_check_djv(file_stat_t *file_stat)
static const unsigned char djv_header[8]= { 'A','T','&','T','F','O','R','M'};
register_header_check(0, djv_header,sizeof(djv_header), &header_check_djv, file_stat);
}
+#endif
diff --git a/src/file_dmp.c b/src/file_dmp.c
index 95aa021..f53e615 100644
--- a/src/file_dmp.c
+++ b/src/file_dmp.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dmp)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,4 +59,4 @@ static void register_header_check_dmp(file_stat_t *file_stat)
};
register_header_check(0, dmp_header, sizeof(dmp_header), &header_check_dmp, file_stat);
}
-
+#endif
diff --git a/src/file_doc.c b/src/file_doc.c
index a0361f9..33c471a 100644
--- a/src/file_doc.c
+++ b/src/file_doc.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_doc)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -43,6 +44,9 @@
#include "__fc_builtin.h"
#endif
+/*@
+ @ requires \valid(file_stat);
+ @*/
static void register_header_check_doc(file_stat_t *file_stat);
const file_hint_t file_hint_doc= {
@@ -109,10 +113,14 @@ const char WilcomDesignInformationDDD[56]=
@ requires \valid(IN);
@ requires (9 == uSectorShift) || (12 == uSectorShift);
@ requires \valid( buf + (0 .. (1<<uSectorShift)-1));
+ @ requires separation: \separated(buf+(..), IN, &errno, &Frama_C_entropy_source);
+ @ assigns \result, *IN, errno;
+ @ assigns *((char *)buf + (0 .. (1 << uSectorShift) - 1));
+ @ assigns Frama_C_entropy_source;
@ ensures \result == -1 || \result == 0;
@*/
/* TODO: ensures \result == 0 ==> \initialized(buf + (0 .. (1<<uSectorShift)-1)); */
-static int OLE_read_block(FILE *IN, unsigned char *buf, const unsigned int uSectorShift, const unsigned int block, const uint64_t offset)
+static int OLE_read_block(FILE *IN, char *buf, const unsigned int uSectorShift, const unsigned int block, const uint64_t offset)
{
const size_t size=1<<uSectorShift;
if(block==0xFFFFFFFF || block==0xFFFFFFFE)
@@ -126,15 +134,16 @@ static int OLE_read_block(FILE *IN, unsigned char *buf, const unsigned int uSect
return -1;
}
#if defined(__FRAMAC__)
- Frama_C_make_unknown((char *)buf, size);
+ Frama_C_make_unknown(buf, size);
#endif
- /* TODO: assert \initialized((char *)buf + (0 .. size-1)); */
+ /* TODO: assert \initialized(buf + (0 .. size-1)); */
return 0;
}
/*@
@ requires \valid_read(dir_entry);
@ requires \initialized(dir_entry);
+ @ assigns \nothing;
@ ensures \result == \null || valid_read_string(\result);
@*/
static const char *entry2ext(const struct OLE_DIR *dir_entry)
@@ -279,6 +288,10 @@ static const char *ole_get_file_extension(const struct OLE_HDR *header, const un
/*@ assert \valid_read(dir_entries + (0 .. 512/sizeof(struct OLE_DIR)-1)); */
const char *ext=NULL;
int is_db=0;
+ /*@
+ @ loop invariant ext == \null || ext == extension_xls || ext == extension_psmodel || ext == extension_snt;
+ @ loop assigns ext, is_db, sid;
+ @*/
for(sid=0;
sid<512/sizeof(struct OLE_DIR);
sid++)
@@ -378,6 +391,7 @@ static const char *ole_get_file_extension(const struct OLE_HDR *header, const un
@ requires 0 <= le32(header->num_extra_FAT_blocks)<= 50;
@ requires 9 == le16(header->uSectorShift) || 12 == le16(header->uSectorShift);
@ requires le32(header->num_FAT_blocks) <= 109+le32(header->num_extra_FAT_blocks)*((1<<le16(header->uSectorShift))/4-1);
+ @ requires \separated(IN, header);
@ ensures \result==\null || \valid_read((const char *)\result + ( 0 .. (le32(header->num_FAT_blocks)<<le16(header->uSectorShift))-1));
@*/
static uint32_t *OLE_load_FAT(FILE *IN, const struct OLE_HDR *header, const uint64_t offset)
@@ -386,6 +400,7 @@ static uint32_t *OLE_load_FAT(FILE *IN, const struct OLE_HDR *header, const uint
uint32_t *dif;
const unsigned int uSectorShift=le16(header->uSectorShift);
const unsigned int num_FAT_blocks=le32(header->num_FAT_blocks);
+ const unsigned int num_extra_FAT_blocks=le32(header->num_extra_FAT_blocks);
/*@ assert uSectorShift == le16(header->uSectorShift); */
/*@ assert num_FAT_blocks==le32(header->num_FAT_blocks); */
/*@ assert num_FAT_blocks <= 109+le32(header->num_extra_FAT_blocks)*((1<<uSectorShift)/4-1); */
@@ -398,7 +413,7 @@ static uint32_t *OLE_load_FAT(FILE *IN, const struct OLE_HDR *header, const uint
#endif
/*@ assert \valid((char *)dif+(0..dif_size-1)); */
memcpy(dif,(header+1),109*4);
- if(le32(header->num_extra_FAT_blocks)>0)
+ if(num_extra_FAT_blocks > 0)
{ /* Load DIF*/
unsigned long int i;
for(i=0; i<le32(header->num_extra_FAT_blocks); i++)
@@ -423,7 +438,7 @@ static uint32_t *OLE_load_FAT(FILE *IN, const struct OLE_HDR *header, const uint
unsigned int j;
for(j=0; j<num_FAT_blocks; j++)
{
- if(OLE_read_block(IN, (unsigned char*)fat + (j<<uSectorShift), uSectorShift, le32(dif[j]), offset)<0)
+ if(OLE_read_block(IN, (char*)fat + (j<<uSectorShift), uSectorShift, le32(dif[j]), offset)<0)
{
free(dif);
free(fat);
@@ -439,6 +454,7 @@ static uint32_t *OLE_load_FAT(FILE *IN, const struct OLE_HDR *header, const uint
/*@
@ requires \valid(file_recovery);
@ requires \valid(file_recovery->handle);
+ @ requires \separated(file_recovery, file_recovery->handle);
@ ensures \valid(file_recovery->handle);
@*/
void file_check_doc_aux(file_recovery_t *file_recovery, const uint64_t offset)
@@ -553,7 +569,7 @@ void file_check_doc_aux(file_recovery_t *file_recovery, const uint64_t offset)
#else
dir_entries=(struct OLE_DIR *)MALLOC(1<<uSectorShift);
#endif
- if(OLE_read_block(file_recovery->handle, (unsigned char *)dir_entries, uSectorShift, block, offset)<0)
+ if(OLE_read_block(file_recovery->handle, (char *)dir_entries, uSectorShift, block, offset)<0)
{
#ifdef DEBUG_OLE
log_info("OLE_read_block failed\n");
@@ -596,6 +612,7 @@ void file_check_doc_aux(file_recovery_t *file_recovery, const uint64_t offset)
/*@
@ requires \valid(file_recovery);
@ requires \valid(file_recovery->handle);
+ @ requires \separated(file_recovery, file_recovery->handle);
@ requires file_recovery->file_check == &file_check_doc;
@ ensures \valid(file_recovery->handle);
@*/
@@ -609,6 +626,7 @@ static void file_check_doc(file_recovery_t *file_recovery)
@ requires \valid_read(fat + (0 .. fat_entries-1));
@ requires 9 == uSectorShift || 12 == uSectorShift;
@ requires 0 < len <= 1024*1024;
+ @ requires \separated(IN, fat + (..), &errno, &Frama_C_entropy_source);
@ ensures \result!=\null ==> \valid((char *)\result + (0 .. len - 1));
@*/
static void *OLE_read_stream(FILE *IN,
@@ -616,14 +634,14 @@ static void *OLE_read_stream(FILE *IN,
const unsigned int block_start, const unsigned int len, const uint64_t offset)
{
//@ split uSectorShift;
- unsigned char *dataPt;
+ char *dataPt;
unsigned int block;
unsigned int i;
const unsigned int i_max=((len+(1<<uSectorShift)-1) >> uSectorShift);
#ifdef __FRAMAC__
- dataPt=(unsigned char *)MALLOC(((1024*1024+(1<<uSectorShift)-1) >> uSectorShift) << uSectorShift);
+ dataPt=(char *)MALLOC(((1024*1024+(1<<uSectorShift)-1) >> uSectorShift) << uSectorShift);
#else
- dataPt=(unsigned char *)MALLOC(i_max << uSectorShift);
+ dataPt=(char *)MALLOC(i_max << uSectorShift);
#endif
/*@ assert \valid(dataPt + ( 0 .. len-1)); */
for(i=0, block=block_start;
@@ -641,6 +659,7 @@ static void *OLE_read_stream(FILE *IN,
return NULL;
}
}
+ /*@ assert \valid(dataPt + (0 .. len - 1)); */
return dataPt;
}
@@ -672,13 +691,13 @@ static uint32_t *OLE_load_MiniFAT(FILE *IN, const struct OLE_HDR *header, const
block=le32(header->MiniFat_block);
for(i=0; i < csectMiniFat; i++)
{
- unsigned char*minifat_pos=(unsigned char*)minifat + (i << uSectorShift);
+ char *minifat_pos=(char*)minifat + (i << uSectorShift);
if(block >= fat_entries)
{
free(minifat);
return NULL;
}
- if(OLE_read_block(IN, (unsigned char *)minifat_pos, uSectorShift, block, offset)<0)
+ if(OLE_read_block(IN, minifat_pos, uSectorShift, block, offset)<0)
{
free(minifat);
return NULL;
@@ -695,7 +714,12 @@ static uint32_t *OLE_load_MiniFAT(FILE *IN, const struct OLE_HDR *header, const
@*/
static uint32_t get32u(const void *buffer, const unsigned int offset)
{
- const uint32_t *val=(const uint32_t *)((const unsigned char *)buffer+offset);
+ /*@ assert \valid_read((char *)buffer + offset + (0 .. 4-1)); */
+ /*@ assert \initialized((char *)buffer + offset + (0 .. 4-1)); */
+ const char *ptr=(const char *)buffer+offset;
+ /*@ assert \valid_read(ptr + (0 .. 4-1)); */
+ /*@ assert \initialized(ptr + (0 .. 4-1)); */
+ const uint32_t *val=(const uint32_t *)ptr;
return le32(*val);
}
@@ -718,7 +742,7 @@ static uint64_t get64u(const void *buffer, const unsigned int offset)
@ ensures *ext == \null || valid_read_string(*ext);
@ assigns *ext;
@*/
-static void software2ext(const char **ext, const unsigned char *software, const unsigned int count)
+static void software2ext(const char **ext, const char *software, const unsigned int count)
{
/*@ assert *ext == \null || valid_read_string(*ext); */
if(count>=12)
@@ -805,7 +829,7 @@ static void software2ext(const char **ext, const unsigned char *software, const
@ ensures \result == \null || valid_read_string(\result);
@ assigns \nothing;
@*/
-static const char *software_uni2ext(const unsigned char *software, const unsigned int count)
+static const char *software_uni2ext(const char *software, const unsigned int count)
{
if(count>=15)
{
@@ -843,7 +867,7 @@ struct summary_entry
@ ensures *ext == \null || valid_read_string(*ext);
@ assigns *ext;
@*/
-static void OLE_parse_software_entry(const unsigned char *buffer, const unsigned int size, const unsigned int offset, const char **ext)
+static void OLE_parse_software_entry(const char *buffer, const unsigned int size, const unsigned int offset, const char **ext)
{
if(offset >= size - 8)
{
@@ -867,6 +891,14 @@ static void OLE_parse_software_entry(const unsigned char *buffer, const unsigned
return ;
}
/*@ assert offset_soft + count <= size; */
+ /*@ assert \valid_read(buffer + (0 .. size-1)); */
+ /*@ assert \forall int j; (0 <= j < size ) ==> \valid_read(buffer + j + (0 .. size-1-j)); */
+ /*@ assert 0 <= offset_soft < size; */
+ /*@ assert \valid_read(buffer + offset_soft + (0 .. size - offset_soft -1)); */
+ /*@ assert 0 < count <= size - offset_soft; */
+ /*@ assert \valid_read(buffer + offset_soft + (0 .. count -1)); */
+
+ /*@ assert offset_soft + count <= size; */
/*@ assert count <= size - offset_soft; */
/*@ assert \valid_read(buffer + (0 .. size-1)); */
/*@ assert \valid_read(buffer + (0 .. offset_soft + count -1)); */
@@ -900,7 +932,7 @@ static void OLE_parse_software_entry(const unsigned char *buffer, const unsigned
@ ensures *ext == \null || valid_read_string(*ext);
@ assigns *ext;
@*/
-static void OLE_parse_uni_software_entry(const unsigned char *buffer, const unsigned int size, const unsigned int offset, const char **ext)
+static void OLE_parse_uni_software_entry(const char *buffer, const unsigned int size, const unsigned int offset, const char **ext)
{
if(offset >= size - 8)
{
@@ -959,7 +991,7 @@ static void OLE_parse_uni_software_entry(const unsigned char *buffer, const unsi
@ ensures valid_string(title);
@ assigns *(title + (0 .. 1023));
@*/
-static void OLE_parse_title_entry(const unsigned char *buffer, const unsigned int size, const unsigned int offset, char *title)
+static void OLE_parse_title_entry(const char *buffer, const unsigned int size, const unsigned int offset, char *title)
{
if(offset + 8 > size)
{
@@ -1022,7 +1054,7 @@ static void OLE_parse_title_entry(const unsigned char *buffer, const unsigned in
@ requires \valid(file_time);
@ assigns *file_time;
@*/
-static void OLE_parse_filetime_entry(const unsigned char *buffer, const unsigned int size, const unsigned int offset, time_t *file_time)
+static void OLE_parse_filetime_entry(const char *buffer, const unsigned int size, const unsigned int offset, time_t *file_time)
{
uint64_t tmp;
if(offset + 12 > size)
@@ -1054,7 +1086,7 @@ static void OLE_parse_filetime_entry(const unsigned char *buffer, const unsigned
@ ensures valid_string(title);
@ assigns *ext, *(title + (0..1023)), *file_time;
@*/
-static void OLE_parse_PropertySet_entry(const unsigned char *buffer, const unsigned int size, const struct summary_entry *entry, const char **ext, char *title, time_t *file_time)
+static void OLE_parse_PropertySet_entry(const char *buffer, const unsigned int size, const struct summary_entry *entry, const char **ext, char *title, time_t *file_time)
{
/*@ assert *ext == \null || valid_read_string(*ext); */
/*@ assert valid_read_string(title); */
@@ -1120,6 +1152,7 @@ static void OLE_parse_PropertySet_entry(const unsigned char *buffer, const unsig
/*@
@ requires 8 <= size <= 1024*1024;
@ requires \valid_read(buffer+ (0 .. size-1));
+ @ requires \initialized(buffer+ (0 .. size-1));
@ requires \valid(ext);
@ requires \valid(title + (0 .. 1024-1));
@ requires \valid(file_time);
@@ -1128,10 +1161,9 @@ static void OLE_parse_PropertySet_entry(const unsigned char *buffer, const unsig
@ requires separation: \separated(buffer+(..), ext, title + (0 .. 1023), file_time);
@ ensures *ext == \null || valid_read_string(*ext);
@ ensures valid_string(title);
+ @ assigns *ext, *(title + (0..1023)), *file_time;
@*/
-/*X TODO assigns *ext, *(title + (0..1023)), *file_time; */
-/*X TODO requires \initialized(buffer+ (0 .. size-1)); */
-static void OLE_parse_PropertySet(const unsigned char *buffer, const unsigned int size, const char **ext, char *title, time_t *file_time)
+static void OLE_parse_PropertySet(const char *buffer, const unsigned int size, const char **ext, char *title, time_t *file_time)
{
const struct summary_entry *entries=(const struct summary_entry *)&buffer[8];
const unsigned int numEntries=get32u(buffer, 4);
@@ -1157,7 +1189,7 @@ static void OLE_parse_PropertySet(const unsigned char *buffer, const unsigned in
/*@ assert 8 + numEntries * 8 <= size; */
/*@ assert numEntries * 8 <= size - 8; */
/*@ assert numEntries < size/8; */
- if((const unsigned char *)&entries[numEntries] > &buffer[size])
+ if((const char *)&entries[numEntries] > &buffer[size])
{
/*@ assert *ext == \null || valid_read_string(*ext); */
/*@ assert valid_string(title); */
@@ -1171,9 +1203,9 @@ static void OLE_parse_PropertySet(const unsigned char *buffer, const unsigned in
@ loop invariant *ext == \null || valid_read_string(*ext);
@ loop invariant valid_string(title);
@ loop invariant 0 <= i <= numEntries;
+ @ loop assigns i, *ext, *(title + (0..1023)), *file_time;
@ loop variant numEntries-i;
@*/
- /*X TODO loop assigns *ext, *(title + (0..1023)), *file_time; */
for(i=0; i<numEntries; i++)
{
const struct summary_entry *entry;
@@ -1212,16 +1244,17 @@ static void OLE_parse_PropertySet(const unsigned char *buffer, const unsigned in
@ ensures valid_string(title);
@*/
/*X TODO assigns *ext, *(title + (0..1023)), *file_time; */
-static void OLE_parse_summary_aux(const unsigned char *dataPt, const unsigned int dirLen, const char **ext, char *title, time_t *file_time)
+static void OLE_parse_summary_aux(const char *dataPt, const unsigned int dirLen, const char **ext, char *title, time_t *file_time)
{
unsigned int pos;
+ const unsigned char *udataPt=(const unsigned char *)dataPt;
assert(dirLen >= 48 && dirLen<=1024*1024);
/*@ assert *ext == \null || valid_read_string(*ext); */
/*@ assert valid_string(title); */
#ifdef DEBUG_OLE
dump_log(dataPt, dirLen);
#endif
- if(dataPt[0]!=0xfe || dataPt[1]!=0xff)
+ if(udataPt[0]!=0xfe || udataPt[1]!=0xff)
return ;
pos=get32u(dataPt, 44);
if(pos > dirLen - 8)
@@ -1230,7 +1263,7 @@ static void OLE_parse_summary_aux(const unsigned char *dataPt, const unsigned in
/*@ assert valid_string(title); */
return ;
}
- /*@ assert pos <= dirLen - 8; */
+ /*@ assert 0 <= pos <= dirLen - 8; */
{
/* PropertySet */
const unsigned int size=get32u(dataPt, pos);
@@ -1240,18 +1273,26 @@ static void OLE_parse_summary_aux(const unsigned char *dataPt, const unsigned in
/*@ assert valid_string(title); */
return ;
}
- /*@ assert 8 < size; */
- /*@ assert size <= dirLen; */
- /*@ assert dirLen <=1024*1024; */
+ /*@ assert size > 8 && size <= dirLen && pos + size <= dirLen; */
+
+ /*@ assert 0 < dirLen <=1024*1024; */
/*@ assert \valid_read(dataPt + (0 .. dirLen-1)); */
/*@ assert pos + size <= dirLen; */
/*@ assert \valid_read(dataPt + (0 .. pos+size-1)); */
+ /*@ assert \valid_read(dataPt + pos + (0 .. size-1)); */
+
+ /*@ assert 0 < dirLen <=1024*1024; */
/*@ assert \initialized(dataPt + (0 .. dirLen-1)); */
/*@ assert pos + size <= dirLen; */
- /*X TODO assert \initialized(dataPt + (0 .. pos+size-1)); */
+ /*@ ghost int small_dirLen = pos + size; */
+ /*@ assert small_dirLen <= dirLen; */
+ /*@ assert \initialized(dataPt + (0 .. small_dirLen-1)); */
+
+#ifndef __FRAMAC__
/*@ assert *ext == \null || valid_read_string(*ext); */
/*@ assert valid_string(title); */
OLE_parse_PropertySet(&dataPt[pos], size, ext, title, file_time);
+#endif
}
/*@ assert *ext == \null || valid_read_string(*ext); */
/*@ assert valid_string(title); */
@@ -1322,7 +1363,7 @@ static void OLE_parse_summary(FILE *file, const uint32_t *fat, const unsigned in
const uint64_t offset)
{
const unsigned int uSectorShift=le16(header->uSectorShift);
- unsigned char *summary=NULL;
+ char *summary=NULL;
/*@ assert *ext == \null || valid_read_string(*ext); */
/*@ assert valid_string(title); */
if(len < 48 || len>1024*1024)
@@ -1362,7 +1403,7 @@ static void OLE_parse_summary(FILE *file, const uint32_t *fat, const unsigned in
ministream_block, ministream_size, offset);
if(ministream != NULL)
{
- summary=(unsigned char*)OLE_read_ministream(ministream,
+ summary=(char*)OLE_read_ministream(ministream,
minifat, mini_fat_entries, le16(header->uMiniSectorShift),
block, len, ministream_size);
free(ministream);
@@ -1371,7 +1412,7 @@ static void OLE_parse_summary(FILE *file, const uint32_t *fat, const unsigned in
}
}
else
- summary=(unsigned char *)OLE_read_stream(file,
+ summary=(char *)OLE_read_stream(file,
fat, fat_entries, uSectorShift,
block, len, offset);
#if defined(__FRAMAC__)
@@ -1380,12 +1421,8 @@ static void OLE_parse_summary(FILE *file, const uint32_t *fat, const unsigned in
summary=MALLOC(4096);
Frama_C_make_unknown((char *)summary, 4096);
/*@ assert \initialized((char *)summary + (0 .. 4096 - 1)); */
-#if 0
- OLE_parse_summary_aux(summary, 4096, ext, title, file_time);
- /*@ assert valid_string(title); */
-#else
OLE_parse_PropertySet(summary, 4096, ext, title, file_time);
-#endif
+ OLE_parse_summary_aux(summary, 4096, ext, title, file_time);
/*@ assert valid_string(title); */
free(summary);
}
@@ -1495,7 +1532,7 @@ static void file_rename_doc(file_recovery_t *file_recovery)
#else
dir_entries=(struct OLE_DIR *)MALLOC(1<<uSectorShift);
#endif
- if(OLE_read_block(file, (unsigned char *)dir_entries, uSectorShift, block, 0)<0)
+ if(OLE_read_block(file, (char *)dir_entries, uSectorShift, block, 0)<0)
{
free(fat);
free(dir_entries);
@@ -1774,14 +1811,12 @@ static int header_check_doc(const unsigned char *buffer, const unsigned int buff
return 1;
}
-/*@
- @ requires \valid(file_stat);
- @*/
static void register_header_check_doc(file_stat_t *file_stat)
{
static const unsigned char doc_header[]= { 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1};
register_header_check(0, doc_header,sizeof(doc_header), &header_check_doc, file_stat);
}
+#endif
#if defined(MAIN_doc)
#define BLOCKSIZE 65536u
diff --git a/src/file_dpx.c b/src/file_dpx.c
index b764efe..89368cc 100644
--- a/src/file_dpx.c
+++ b/src/file_dpx.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dpx)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -89,3 +90,4 @@ static void register_header_check_dpx(file_stat_t *file_stat)
register_header_check(0, "SDPX", 4, &header_check_dpx, file_stat);
register_header_check(0, "XPDS", 4, &header_check_dpx, file_stat);
}
+#endif
diff --git a/src/file_drw.c b/src/file_drw.c
index 05c9924..2c7cb95 100644
--- a/src/file_drw.c
+++ b/src/file_drw.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_drw)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -67,3 +68,4 @@ static void register_header_check_drw(file_stat_t *file_stat)
'R', 'A', 'W', 'I', 'N', 'G'};
register_header_check(0, drw_header,sizeof(drw_header), &header_check_drw, file_stat);
}
+#endif
diff --git a/src/file_ds2.c b/src/file_ds2.c
index 73b1116..754d8e7 100644
--- a/src/file_ds2.c
+++ b/src/file_ds2.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ds2)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -74,3 +75,4 @@ static void register_header_check_ds2(file_stat_t *file_stat)
static const unsigned char ds2_header[4]= { 0x03, 'd','s','2'};
register_header_check(0, ds2_header,sizeof(ds2_header), &header_check_ds2, file_stat);
}
+#endif
diff --git a/src/file_ds_store.c b/src/file_ds_store.c
index ba23b46..c4d4431 100644
--- a/src/file_ds_store.c
+++ b/src/file_ds_store.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ds_store)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -70,3 +71,4 @@ static void register_header_check_ds_store(file_stat_t *file_stat)
};
register_header_check(0, ds_store_header, sizeof(ds_store_header), &header_check_ds_store, file_stat);
}
+#endif
diff --git a/src/file_dsc.c b/src/file_dsc.c
index 398ae6e..002cd84 100644
--- a/src/file_dsc.c
+++ b/src/file_dsc.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dsc)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_dsc(file_stat_t *file_stat)
static const unsigned char dsc_header[3]= { 'M','L','T'};
register_header_check(588, dsc_header,sizeof(dsc_header), &header_check_dsc, file_stat);
}
+#endif
diff --git a/src/file_dss.c b/src/file_dss.c
index 8f6de2b..6e4db8e 100644
--- a/src/file_dss.c
+++ b/src/file_dss.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dss)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -78,3 +79,4 @@ static void register_header_check_dss(file_stat_t *file_stat)
static const unsigned char dss_header[4]= { 0x02, 'd','s','s'};
register_header_check(0, dss_header,sizeof(dss_header), &header_check_dss, file_stat);
}
+#endif
diff --git a/src/file_dst.c b/src/file_dst.c
index 38a2e5e..3267bae 100644
--- a/src/file_dst.c
+++ b/src/file_dst.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dst)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -62,3 +63,4 @@ static void register_header_check_dst(file_stat_t *file_stat)
{
register_header_check(0x13, "\rST:", 4, &header_check_dst, file_stat);
}
+#endif
diff --git a/src/file_dta.c b/src/file_dta.c
index ce52423..8fe774a 100644
--- a/src/file_dta.c
+++ b/src/file_dta.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dta)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -66,3 +67,4 @@ static void register_header_check_dta(file_stat_t *file_stat)
register_header_check(0, dta_header_71le,sizeof(dta_header_71le), &header_check_dta, file_stat);
register_header_check(0, dta_header_72le,sizeof(dta_header_72le), &header_check_dta, file_stat);
}
+#endif
diff --git a/src/file_dump.c b/src/file_dump.c
index 38c77f3..f21b9c6 100644
--- a/src/file_dump.c
+++ b/src/file_dump.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dump)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -145,3 +146,4 @@ static void register_header_check_dump(file_stat_t *file_stat)
register_header_check(0x18, dump_header_le_old_fs,sizeof(dump_header_le_old_fs), &header_check_dump, file_stat);
register_header_check(0x18, dump_header_le_new_fs,sizeof(dump_header_le_new_fs), &header_check_dump, file_stat);
}
+#endif
diff --git a/src/file_dv.c b/src/file_dv.c
index 6aabd81..bc45ce3 100644
--- a/src/file_dv.c
+++ b/src/file_dv.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dv)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -29,6 +30,9 @@
#include <stdio.h>
#include "types.h"
#include "filegen.h"
+#if defined(__FRAMAC__)
+#include "__fc_builtin.h"
+#endif
static void register_header_check_dv(file_stat_t *file_stat);
@@ -43,6 +47,9 @@ const file_hint_t file_hint_dv= {
static data_check_t data_check_NTSC(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
{
@@ -64,6 +71,9 @@ static void file_check_dv_NTSC(file_recovery_t *fr)
if(my_fseek(fr->handle, 0, SEEK_SET) < 0 ||
fread(&buffer_header, sizeof(buffer_header), 1, fr->handle) != 1)
return ;
+#if defined(__FRAMAC__)
+ Frama_C_make_unknown((char *)&buffer_header, sizeof(buffer_header));
+#endif
if(fs > 0)
fs-=120000;
if(fs > 0)
@@ -73,6 +83,9 @@ static void file_check_dv_NTSC(file_recovery_t *fr)
fread(&buffer, sizeof(buffer), 1, fr->handle) == 1)
{
unsigned int i;
+#if defined(__FRAMAC__)
+ Frama_C_make_unknown((char *)&buffer, sizeof(buffer));
+#endif
for(i=1; i<sizeof(buffer); i+=0x50)
if((buffer[i]&0x0f)!=(buffer_header[1]&0x0f))
{
@@ -86,6 +99,9 @@ static void file_check_dv_NTSC(file_recovery_t *fr)
static data_check_t data_check_PAL(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
{
@@ -107,6 +123,9 @@ static void file_check_dv_PAL(file_recovery_t *fr)
if(my_fseek(fr->handle, 0, SEEK_SET) < 0 ||
fread(&buffer_header, sizeof(buffer_header), 1, fr->handle) != 1)
return ;
+#if defined(__FRAMAC__)
+ Frama_C_make_unknown((char *)&buffer_header, sizeof(buffer_header));
+#endif
if(fs > 0)
fs-=144000;
if(fs > 0)
@@ -116,6 +135,9 @@ static void file_check_dv_PAL(file_recovery_t *fr)
fread(&buffer, sizeof(buffer), 1, fr->handle) == 1)
{
unsigned int i;
+#if defined(__FRAMAC__)
+ Frama_C_make_unknown((char *)&buffer, sizeof(buffer));
+#endif
for(i=1; i<sizeof(buffer); i+=0x50)
if((buffer[i]&0x0f)!=(buffer_header[1]&0x0f))
{
@@ -159,3 +181,4 @@ static void register_header_check_dv(file_stat_t *file_stat)
static const unsigned char dv_header[3]= {0x1f, 0x07, 0x00};
register_header_check(0, dv_header,sizeof(dv_header), &header_check_dv, file_stat);
}
+#endif
diff --git a/src/file_dvi.c b/src/file_dvi.c
index 0458f67..48570ae 100644
--- a/src/file_dvi.c
+++ b/src/file_dvi.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dvi)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -65,3 +66,4 @@ static void register_header_check_dvi(file_stat_t *file_stat)
};
register_header_check(0, dvi_header, sizeof(dvi_header), &header_check_dvi, file_stat);
}
+#endif
diff --git a/src/file_dvr.c b/src/file_dvr.c
index 4adbbb7..3b9aa4b 100644
--- a/src/file_dvr.c
+++ b/src/file_dvr.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dvr)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -60,3 +61,4 @@ static void register_header_check_dvr(file_stat_t *file_stat)
{
register_header_check(0, "RT60", 4, &header_check_dvr, file_stat);
}
+#endif
diff --git a/src/file_dwg.c b/src/file_dwg.c
index 9eb30e3..09abae4 100644
--- a/src/file_dwg.c
+++ b/src/file_dwg.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dwg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -69,3 +70,4 @@ static void register_header_check_dwg(file_stat_t *file_stat)
register_header_check(0, dwg_header_24,sizeof(dwg_header_24), &header_check_dwg, file_stat);
register_header_check(0, dwg_header_27,sizeof(dwg_header_27), &header_check_dwg, file_stat);
}
+#endif
diff --git a/src/file_dxf.c b/src/file_dxf.c
index fb0ed16..9308d3b 100644
--- a/src/file_dxf.c
+++ b/src/file_dxf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dxf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,6 +60,9 @@ static int header_check_dxf(const unsigned char *buffer, const unsigned int buff
static data_check_t data_check_dxf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
unsigned int i;
+ /*@
+ @ loop assigns i, file_recovery->calculated_file_size;
+ @*/
for(i=(buffer_size/2)-3;i+4<buffer_size;i++)
{
if(buffer[i]=='\n' && buffer[i+1]=='E' && buffer[i+2]=='O' && buffer[i+3]=='F')
@@ -94,3 +98,4 @@ static void register_header_check_dxf(file_stat_t *file_stat)
register_header_check(0, header_dxflib, sizeof(header_dxflib), &header_check_dxf, file_stat);
register_header_check(0, header_dxflib_dos, sizeof(header_dxflib_dos), &header_check_dxf, file_stat);
}
+#endif
diff --git a/src/file_e01.c b/src/file_e01.c
index ed219a3..2c746c7 100644
--- a/src/file_e01.c
+++ b/src/file_e01.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_e01)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -86,12 +87,29 @@ static void file_check_e01(file_recovery_t *file_recovery)
static int header_check_e01(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const struct ewf_file_header *ewf=(const struct ewf_file_header *)buffer;
- static char ext[4];
+ static char ext[10];
+ uint16_t fields_segment=le16(ewf->fields_segment);
reset_file_recovery(file_recovery_new);
- ext[0]='E'+le16(ewf->fields_segment)/100;
- ext[1]='0'+(le16(ewf->fields_segment)%100)/10;
- ext[2]='0'+(le16(ewf->fields_segment)%10);
- ext[3]='\0';
+ if(fields_segment > ('Z'-'E') * 100 + 99)
+ {
+ ext[0]='E';
+ ext[1]='0';
+ ext[2]='1';
+ ext[3]='_';
+ ext[4]='0'+(fields_segment/10000)%10;
+ ext[5]='0'+(fields_segment/1000)%10;
+ ext[6]='0'+(fields_segment/100)%10;
+ ext[7]='0'+(fields_segment/10)%10;
+ ext[8]='0'+fields_segment%10;
+ ext[9]='\0';
+ }
+ else
+ {
+ ext[0]='E'+fields_segment/100;
+ ext[1]='0'+(fields_segment/10)%10;
+ ext[2]='0'+(fields_segment%10);
+ ext[3]='\0';
+ }
file_recovery_new->extension=(const char*)&ext;
file_recovery_new->file_check=&file_check_e01;
return 1;
@@ -105,3 +123,4 @@ static void register_header_check_e01(file_stat_t *file_stat)
};
register_header_check(0, e01_header, sizeof(e01_header), &header_check_e01, file_stat);
}
+#endif
diff --git a/src/file_ecryptfs.c b/src/file_ecryptfs.c
index a43b9a4..5f5741b 100644
--- a/src/file_ecryptfs.c
+++ b/src/file_ecryptfs.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ecryptfs)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -87,3 +88,4 @@ static int header_check_ecryptfs(const unsigned char *buffer, const unsigned int
file_recovery_new->file_check=&file_check_ecryptfs;
return 1;
}
+#endif
diff --git a/src/file_edb.c b/src/file_edb.c
index e09d61b..ad07bda 100644
--- a/src/file_edb.c
+++ b/src/file_edb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_edb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -65,3 +66,4 @@ static void register_header_check_edb(file_stat_t *file_stat)
};
register_header_check(4, edb_magic, sizeof(edb_magic), &header_check_edb, file_stat);
}
+#endif
diff --git a/src/file_elf.c b/src/file_elf.c
index f9ff9a0..2bdbcb2 100644
--- a/src/file_elf.c
+++ b/src/file_elf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_elf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -152,3 +153,4 @@ static void register_header_check_elf(file_stat_t *file_stat)
register_header_check(0, elf_header16, sizeof(elf_header16), &header_check_elf, file_stat);
register_header_check(0, elf_header32, sizeof(elf_header32), &header_check_elf, file_stat);
}
+#endif
diff --git a/src/file_emf.c b/src/file_emf.c
index b4a10d0..39ff7ac 100644
--- a/src/file_emf.c
+++ b/src/file_emf.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_emf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -422,6 +423,7 @@ static void register_header_check_emf(file_stat_t *file_stat)
static const unsigned char emf_sign[4]= { ' ','E', 'M','F'};
register_header_check(0x28, emf_sign,sizeof(emf_sign), &header_check_emf, file_stat);
}
+#endif
#if defined(MAIN_emf)
#define BLOCKSIZE 65536u
diff --git a/src/file_ess.c b/src/file_ess.c
index 9ed99f2..dd316e8 100644
--- a/src/file_ess.c
+++ b/src/file_ess.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ess)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -52,3 +53,4 @@ static void register_header_check_ess(file_stat_t *file_stat)
{
register_header_check(0, "TESV_SAVEGAME", 13, &header_check_ess, file_stat);
}
+#endif
diff --git a/src/file_evt.c b/src/file_evt.c
index 6eb621f..a06f356 100644
--- a/src/file_evt.c
+++ b/src/file_evt.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_evt)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -34,7 +35,6 @@
static void register_header_check_evt(file_stat_t *file_stat);
static int header_check_evt(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
-static data_check_t data_check_evt(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_evt= {
.extension="evt",
@@ -52,6 +52,9 @@ struct evt_chunk {
static data_check_t data_check_evt(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
{
@@ -84,9 +87,10 @@ static data_check_t data_check_evt(const unsigned char *buffer, const unsigned i
static int header_check_evt(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const struct evt_chunk *chunk=(const struct evt_chunk *)buffer;
- const struct evt_chunk *chunk2=(const struct evt_chunk *)&buffer[le32(chunk->size)];
+ const struct evt_chunk *chunk2;
if(le32(chunk->size) != 0x30)
return 0;
+ chunk2=(const struct evt_chunk *)&buffer[le32(chunk->size)];
if(le32(chunk2->size) < 8)
return 0;
reset_file_recovery(file_recovery_new);
@@ -105,3 +109,4 @@ static void register_header_check_evt(file_stat_t *file_stat)
static const unsigned char evt_header[8]= {0x30, 0x00, 0x00, 0x00, 'L', 'f', 'L', 'e'};
register_header_check(0, evt_header,sizeof(evt_header), &header_check_evt, file_stat);
}
+#endif
diff --git a/src/file_evtx.c b/src/file_evtx.c
index 68f884f..6f19ad9 100644
--- a/src/file_evtx.c
+++ b/src/file_evtx.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_evtx)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -78,3 +79,4 @@ static void register_header_check_evtx(file_stat_t *file_stat)
{
register_header_check(0, "ElfFile", 8, &header_check_evtx, file_stat);
}
+#endif
diff --git a/src/file_exe.c b/src/file_exe.c
index 2050e21..8aa1a6f 100644
--- a/src/file_exe.c
+++ b/src/file_exe.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_exe)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -913,6 +914,7 @@ static void register_header_check_exe(file_stat_t *file_stat)
{
register_header_check(0, exe_header,sizeof(exe_header), &header_check_exe, file_stat);
}
+#endif
#if defined(MAIN_exe)
#define BLOCKSIZE 65536u
diff --git a/src/file_exr.c b/src/file_exr.c
index f0df6ba..886fa6e 100644
--- a/src/file_exr.c
+++ b/src/file_exr.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_exr)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_exr(file_stat_t *file_stat)
static const unsigned char exr_header[5]= { 'v' , 0x2f, '1' , 0x01, 0x02 };
register_header_check(0, exr_header, sizeof(exr_header), &header_check_exr, file_stat);
}
+#endif
diff --git a/src/file_exs.c b/src/file_exs.c
index 921d596..26913ec 100644
--- a/src/file_exs.c
+++ b/src/file_exs.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_exs)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -70,5 +71,4 @@ static void register_header_check_exs(file_stat_t *file_stat)
};
register_header_check(0, exs_header, sizeof(exs_header), &header_check_exs, file_stat);
}
-
-
+#endif
diff --git a/src/file_ext.c b/src/file_ext.c
index b131fc7..cf55797 100644
--- a/src/file_ext.c
+++ b/src/file_ext.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ext2_sb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -32,6 +33,7 @@
#include "ext2.h"
#include "ext2_common.h"
#include "filegen.h"
+#include "log.h"
static void register_header_check_ext2_sb(file_stat_t *file_stat);
@@ -121,3 +123,4 @@ static void register_header_check_ext2_sb(file_stat_t *file_stat)
register_header_check(0x38, ext2_sb_header, sizeof(ext2_sb_header), &header_check_ext2_sb, file_stat);
register_header_check(0x4, ext2_ll_dir1, sizeof(ext2_ll_dir1), &header_check_ext2_dir, file_stat);
}
+#endif
diff --git a/src/file_ext2.c b/src/file_ext2.c
index 7bc31a9..cc672fe 100644
--- a/src/file_ext2.c
+++ b/src/file_ext2.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ext2_fs)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -37,7 +38,7 @@ static void register_header_check_ext2_fs(file_stat_t *file_stat);
static int header_check_ext2_fs(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
const file_hint_t file_hint_ext2_fs= {
- .extension="ext",
+ .extension="ext2",
.description="ext2/ext3/ext4 Filesystem",
.max_filesize=0,
.recover=1,
@@ -73,3 +74,4 @@ static int header_check_ext2_fs(const unsigned char *buffer, const unsigned int
file_recovery_new->file_check=&file_check_size;
return 1;
}
+#endif
diff --git a/src/file_fat.c b/src/file_fat.c
index 2904129..bd27eab 100644
--- a/src/file_fat.c
+++ b/src/file_fat.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fat)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -35,7 +36,6 @@
#include "filegen.h"
#include "log.h"
#include "memmem.h"
-#include "fat.h"
#include "fat_common.h"
static void register_header_check_fat(file_stat_t *file_stat);
@@ -62,13 +62,14 @@ static int header_check_fat(const unsigned char *buffer, const unsigned int buff
const struct fat_boot_sector *fat_header=(const struct fat_boot_sector *)buffer;
uint64_t start_fat1,start_data,part_size;
unsigned long int no_of_cluster,fat_length,fat_length_calc;
+ const unsigned int sector_size=fat_sector_size(fat_header);
if(!(le16(fat_header->marker)==0xAA55
&& (fat_header->ignored[0]==0xeb || fat_header->ignored[0]==0xe9)
&& (fat_header->fats==1 || fat_header->fats==2)))
return 0; /* Obviously not a FAT */
if(!((fat_header->ignored[0]==0xeb && fat_header->ignored[2]==0x90)||fat_header->ignored[0]==0xe9))
return 0;
- if(fat_sector_size(fat_header)==0 || fat_sector_size(fat_header)%512!=0)
+ if(sector_size==0 || sector_size%512!=0)
return 0;
switch(fat_header->sectors_per_cluster)
{
@@ -91,7 +92,7 @@ static int header_check_fat(const unsigned char *buffer, const unsigned int buff
fat_length=le16(fat_header->fat_length)>0?le16(fat_header->fat_length):le32(fat_header->fat32_length);
part_size=(fat_sectors(fat_header)>0?fat_sectors(fat_header):le32(fat_header->total_sect));
start_fat1=le16(fat_header->reserved);
- start_data=start_fat1+fat_header->fats*fat_length+(get_dir_entries(fat_header)*32+fat_sector_size(fat_header)-1)/fat_sector_size(fat_header);
+ start_data=start_fat1+fat_header->fats*fat_length+(get_dir_entries(fat_header)*32+sector_size-1)/sector_size;
if(part_size < start_data)
return 0;
no_of_cluster=(part_size-start_data)/fat_header->sectors_per_cluster;
@@ -102,7 +103,7 @@ static int header_check_fat(const unsigned char *buffer, const unsigned int buff
return 0;
if((le16(fat_header->fat_length)>256)||(le16(fat_header->fat_length)==0))
return 0;
- fat_length_calc=((no_of_cluster+2+fat_sector_size(fat_header)*2/3-1)*3/2/fat_sector_size(fat_header));
+ fat_length_calc=((no_of_cluster+2+sector_size*2/3-1)*3/2/sector_size);
}
else if(no_of_cluster<65525)
{
@@ -111,7 +112,7 @@ static int header_check_fat(const unsigned char *buffer, const unsigned int buff
return 0;
if((get_dir_entries(fat_header)==0)||(get_dir_entries(fat_header)%16!=0))
return 0;
- fat_length_calc=((no_of_cluster+2+fat_sector_size(fat_header)/2-1)*2/fat_sector_size(fat_header));
+ fat_length_calc=((no_of_cluster+2+sector_size/2-1)*2/sector_size);
}
else
{
@@ -122,7 +123,7 @@ static int header_check_fat(const unsigned char *buffer, const unsigned int buff
return 0;
if((le32(fat_header->root_cluster)<2) ||(le32(fat_header->root_cluster)>=2+no_of_cluster))
return 0;
- fat_length_calc=((no_of_cluster+2+fat_sector_size(fat_header)/4-1)*4/fat_sector_size(fat_header));
+ fat_length_calc=((no_of_cluster+2+sector_size/4-1)*4/sector_size);
}
if(fat_length<fat_length_calc)
return 0;
@@ -130,8 +131,9 @@ static int header_check_fat(const unsigned char *buffer, const unsigned int buff
file_recovery_new->extension=file_hint_fat.extension;
file_recovery_new->calculated_file_size=(uint64_t)
(fat_sectors(fat_header)>0?fat_sectors(fat_header):le32(fat_header->total_sect)) *
- fat_sector_size(fat_header);
+ sector_size;
file_recovery_new->data_check=&data_check_size;
file_recovery_new->file_check=&file_check_size;
return 1;
}
+#endif
diff --git a/src/file_fbf.c b/src/file_fbf.c
index 31c5747..addf7af 100644
--- a/src/file_fbf.c
+++ b/src/file_fbf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fbf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -57,3 +58,4 @@ static void register_header_check_fbf(file_stat_t *file_stat)
};
register_header_check(0, fbf_header, sizeof(fbf_header), &header_check_fbf, file_stat);
}
+#endif
diff --git a/src/file_fbk.c b/src/file_fbk.c
index 6efd490..c88994b 100644
--- a/src/file_fbk.c
+++ b/src/file_fbk.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fbk)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_fbk(file_stat_t *file_stat)
static const unsigned char fbk_header[10] = {'T','a','b','l','e','D','a','t','a',' '};
register_header_check(0, fbk_header, sizeof(fbk_header), &header_check_fbk, file_stat);
}
+#endif
diff --git a/src/file_fcp.c b/src/file_fcp.c
index 8d71e89..a5390a0 100644
--- a/src/file_fcp.c
+++ b/src/file_fcp.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fcp)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,3 +59,4 @@ static void register_header_check_fcp(file_stat_t *file_stat)
static const unsigned char fcp_header[5]= { 0xA2, 'K','e','y','G'};
register_header_check(0, fcp_header,sizeof(fcp_header), &header_check_fcp, file_stat);
}
+#endif
diff --git a/src/file_fcs.c b/src/file_fcs.c
index 05ce8ca..58c5a26 100644
--- a/src/file_fcs.c
+++ b/src/file_fcs.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fcs)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -31,8 +32,10 @@
#include "filegen.h"
#include "log.h"
+/*@
+ @ requires \valid(file_stat);
+ @*/
static void register_header_check_fcs(file_stat_t *file_stat);
-static int header_check_fcs(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
const file_hint_t file_hint_fcs= {
.extension="fcs",
@@ -43,13 +46,6 @@ const file_hint_t file_hint_fcs= {
.register_header_check=&register_header_check_fcs
};
-static const unsigned char fcs_signature[6]= {'F','C','S','3','.','0'};
-
-static void register_header_check_fcs(file_stat_t *file_stat)
-{
- register_header_check(0, fcs_signature, sizeof(fcs_signature), &header_check_fcs, file_stat);
-}
-
struct fcs_header
{
unsigned char magic[6];
@@ -62,36 +58,95 @@ struct fcs_header
unsigned char analysis_end[8]; /* 50 */
} __attribute__ ((gcc_struct, __packed__));
+/*@
+ @ requires \valid_read(string + (0 .. max_length-1));
+ @ assigns \nothing;
+ @*/
static uint64_t ascii2int(const unsigned char *string, const unsigned int max_length)
{
uint64_t res=0;
unsigned int i;
+ /*@
+ @ loop invariant res <= 0x1999999999999998;
+ @ loop assigns res,i;
+ @*/
for(i=0;i<max_length;i++)
{
if(string[i]>='0' && string[i]<='9')
+ {
res=res*10+(string[i]-'0');
+ if(res > 0x1999999999999998)
+ return 0xffffffffffffffff;
+ }
else if(!(string[i]==' ' && res==0))
return 0;
}
return res;
}
+/*@
+ @ requires \valid_read(string + (0 .. max_length-1));
+ @ assigns \nothing;
+ @*/
static uint64_t ascii2int2(const unsigned char *string, const unsigned int max_length, const unsigned int delimiter)
{
uint64_t res=0;
unsigned int i;
+ /*@
+ @ loop invariant res <= 0x1999999999999998;
+ @ loop assigns res,i;
+ @*/
for(i=0;i<max_length;i++)
+ {
if(string[i]>='0' && string[i]<='9')
+ {
res=res*10+(string[i]-'0');
+ if(res > 0x1999999999999998)
+ return res;
+ }
else if(string[i]==delimiter)
return res;
else if(string[i]==' ' && res>0)
return res;
else if(string[i]!=' ')
return 0;
+ }
return res;
}
+/*@
+ @ requires buffer_size > 0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid_read(file_recovery);
+ @ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
+ @ requires \valid(file_recovery_new);
+ @ requires file_recovery_new->blocksize > 0;
+ @
+ @ requires buffer_size >= sizeof(struct fcs_header);
+ @ requires separation: \separated(&file_hint_fcs, buffer+(..), file_recovery, file_recovery_new);
+ @
+ @ ensures \result == 0 || \result == 1;
+ @ ensures (\result == 1) ==> (file_recovery_new->file_stat == \null);
+ @ ensures (\result == 1) ==> (file_recovery_new->handle == \null);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->time);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->calculated_file_size);
+ @ ensures (\result == 1) ==> file_recovery_new->file_size == 0;
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->min_filesize);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null || \valid_function(file_recovery_new->data_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == \null || \valid_function(file_recovery_new->file_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename == \null || \valid_function(file_recovery_new->file_rename));
+ @ ensures (\result != 0) ==> file_recovery_new->extension != \null;
+ @ ensures (\result == 1) ==> (valid_read_string(file_recovery_new->extension));
+ @ ensures (\result == 1) ==> \separated(file_recovery_new, file_recovery_new->extension);
+ @
+ @ ensures (\result == 1) ==> (file_recovery_new->time == 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->min_filesize == 58);
+ @ ensures (\result == 1) ==> (file_recovery_new->calculated_file_size > 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->extension == file_hint_fcs.extension);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == &data_check_size);
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == &file_check_size);
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename == \null);
+ @*/
static int header_check_fcs(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const struct fcs_header *fcs=(const struct fcs_header*)buffer;
@@ -113,8 +168,11 @@ static int header_check_fcs(const unsigned char *buffer, const unsigned int buff
if((data_end==0 || analysis_end==0) && text_start < buffer_size)
{ /* Explore TEXT segment */
unsigned int i;
- const char delimiter=buffer[text_start];
+ const unsigned char delimiter=buffer[text_start];
const unsigned int smallest=(buffer_size < text_end ? buffer_size : text_end);
+ /*@
+ @ loop assigns i, data_end, stext_end, analysis_end;
+ @*/
for(i=0; i<smallest; i++)
{
if(buffer[i]==delimiter)
@@ -136,6 +194,10 @@ static int header_check_fcs(const unsigned char *buffer, const unsigned int buff
log_info("$ENDSTEXT %llu\n", (long long unsigned) stext_end);
log_info("$ENDANALYSIS %llu\n", (long long unsigned) analysis_end);
#endif
+ if( data_end >= 0x8000000000000000 - 9 ||
+ analysis_end >= 0x8000000000000000 - 9 ||
+ stext_end >= 0x8000000000000000 - 9)
+ return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_fcs.extension;
file_recovery_new->min_filesize=58;
@@ -148,3 +210,10 @@ static int header_check_fcs(const unsigned char *buffer, const unsigned int buff
file_recovery_new->file_check=&file_check_size;
return 1;
}
+
+static void register_header_check_fcs(file_stat_t *file_stat)
+{
+ static const unsigned char fcs_signature[6]= {'F','C','S','3','.','0'};
+ register_header_check(0, fcs_signature, sizeof(fcs_signature), &header_check_fcs, file_stat);
+}
+#endif
diff --git a/src/file_fdb.c b/src/file_fdb.c
index a827049..90bebda 100644
--- a/src/file_fdb.c
+++ b/src/file_fdb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fdb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,3 +59,4 @@ static void register_header_check_fdb(file_stat_t *file_stat)
static const unsigned char fdb_header[7] = { 0x00, 0x00, 0x00, 0x5c, 0xa0, 0x83, 0x02};
register_header_check(5, fdb_header, sizeof(fdb_header), &header_check_fdb, file_stat);
}
+#endif
diff --git a/src/file_fds.c b/src/file_fds.c
index 0217fb6..2ec3c4b 100644
--- a/src/file_fds.c
+++ b/src/file_fds.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fds)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -67,3 +68,4 @@ static void register_header_check_fds(file_stat_t *file_stat)
static const unsigned char fds_header[4]= {'F','D','S',0x1A};
register_header_check(0, fds_header,sizeof(fds_header), &header_check_fds, file_stat);
}
+#endif
diff --git a/src/file_fh10.c b/src/file_fh10.c
index f742f68..d350d8e 100644
--- a/src/file_fh10.c
+++ b/src/file_fh10.c
@@ -22,6 +22,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fh10)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -64,3 +65,4 @@ static void register_header_check_fh10(file_stat_t *file_stat)
};
register_header_check(0, fh10_header,sizeof(fh10_header), &header_check_fh10, file_stat);
}
+#endif
diff --git a/src/file_fh5.c b/src/file_fh5.c
index 63a39f0..1d29412 100644
--- a/src/file_fh5.c
+++ b/src/file_fh5.c
@@ -21,6 +21,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fh5)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -77,3 +78,4 @@ static void register_header_check_fh5(file_stat_t *file_stat)
static const unsigned char fh5_header[8] = { 0x41, 0x47, 0x44, 0x31, 0xbe, 0xb8, 0xbb, 0xce };
register_header_check(0, fh5_header,sizeof(fh5_header), &header_check_fh5, file_stat);
}
+#endif
diff --git a/src/file_filevault.c b/src/file_filevault.c
index b4bb498..afe45ee 100644
--- a/src/file_filevault.c
+++ b/src/file_filevault.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_filevault)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -60,3 +61,4 @@ static void register_header_check_filevault(file_stat_t *file_stat)
};
register_header_check(0, filevault_header, sizeof(filevault_header), &header_check_filevault, file_stat);
}
+#endif
diff --git a/src/file_fit.c b/src/file_fit.c
index 323beb7..3a1d317 100644
--- a/src/file_fit.c
+++ b/src/file_fit.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fit )
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -73,3 +74,4 @@ static void register_header_check_fit(file_stat_t *file_stat)
static const unsigned char fits_header[4]= { '.', 'F', 'I', 'T' };
register_header_check(8, fits_header, sizeof(fits_header), &header_check_fit, file_stat);
}
+#endif
diff --git a/src/file_fits.c b/src/file_fits.c
index 12065ec..b40be59 100644
--- a/src/file_fits.c
+++ b/src/file_fits.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fits)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -52,25 +53,45 @@ const file_hint_t file_hint_fits= {
* Image metadata is store in an ASCII header
* Specification can be found at http://fits.gsfc.nasa.gov/ */
+/*@
+ @ requires \valid_read(str + (0 .. 80-1));
+ @ assigns \nothing;
+ @*/
static uint64_t fits_get_val(const unsigned char *str)
{
unsigned int i;
uint64_t val=0;
+ /*@ loop assigns i; */
for(i=0;i<80 && str[i]!='=';i++);
i++;
+ /*@ loop assigns i; */
for(;i<80 && str[i]==' ';i++);
if(i<80 && str[i]=='-')
i++;
+ /*@ loop assigns i,val; */
for(;i<80 && str[i]>='0' && str[i]<='9';i++)
val=val*10+str[i]-'0';
return val;
}
+/*@
+ @ requires buffer_size > 0;
+ @ requires \valid_read(buffer + (0 .. buffer_size-1));
+ @ requires \valid(file_recovery);
+ @ requires \valid(i_pointer);
+ @ requires \separated(buffer+(..), file_recovery, i_pointer);
+ @*/
static uint64_t fits_info(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery, unsigned int *i_pointer)
{
uint64_t naxis_size=1;
unsigned int i=*i_pointer;
+ if( i+80 >= buffer_size)
+ return 1;
/* Header is composed of 80 character fixed-length strings */
+ /*@
+ @ loop invariant i < buffer_size + 80;
+ @ loop assigns i, naxis_size, file_recovery->time;
+ @*/
for(; i+80 < buffer_size &&
memcmp(&buffer[i], "END ", 4)!=0;
i+=80)
@@ -95,13 +116,14 @@ static uint64_t fits_info(const unsigned char *buffer, const unsigned int buffer
{
/* CREA_DAT= '2007-08-29T16:22:09' */
/* 0123456789012345678 */
- const char *date_asc;
unsigned int j;
- for(j=0,date_asc=(const char *)&buffer[i];j<80 && *date_asc!='\'';j++,date_asc++);
- if(j<60 && *date_asc=='\'')
+ /*@
+ @ loop assigns j;
+ @*/
+ for(j=0;j<80 && buffer[i+j]!='\'';j++);
+ if(j<60 && buffer[i+j]=='\'')
{
- date_asc++;
- file_recovery->time=get_time_from_YYYY_MM_DD_HH_MM_SS(date_asc);
+ file_recovery->time=get_time_from_YYYY_MM_DD_HH_MM_SS(&buffer[i+j+1]);
}
}
}
@@ -111,6 +133,9 @@ static uint64_t fits_info(const unsigned char *buffer, const unsigned int buffer
static data_check_t data_check_fits(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
{
@@ -171,3 +196,4 @@ static void register_header_check_fits(file_stat_t *file_stat)
{
register_header_check(0, "SIMPLE =", 9, &header_check_fits, file_stat);
}
+#endif
diff --git a/src/file_flac.c b/src/file_flac.c
index 2a3a863..f46bb6d 100644
--- a/src/file_flac.c
+++ b/src/file_flac.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_flac)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -90,8 +91,11 @@ static int header_check_flac(const unsigned char *buffer, const unsigned int buf
#endif
file_recovery_new->min_filesize=4+size;
#if 0
- file_recovery_new->calculated_file_size=4;
- file_recovery_new->data_check=&data_check_flac_metadata;
+ if(file_recovery_new->blocksize >= 4)
+ {
+ file_recovery_new->calculated_file_size=4;
+ file_recovery_new->data_check=&data_check_flac_metadata;
+ }
#endif
return 1;
}
@@ -104,3 +108,4 @@ static void register_header_check_flac(file_stat_t *file_stat)
register_header_check(0, flac_header,sizeof(flac_header), &header_check_flac, file_stat);
register_header_check(0, flac_header2,sizeof(flac_header2), &header_check_flac, file_stat);
}
+#endif
diff --git a/src/file_flp.c b/src/file_flp.c
index affebe4..a6d23dd 100644
--- a/src/file_flp.c
+++ b/src/file_flp.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_flp)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -76,3 +77,4 @@ static void register_header_check_flp(file_stat_t *file_stat)
static const unsigned char flp_header[8]= {'F', 'L', 'h', 'd', 0x06, 0x00, 0x00, 0x00};
register_header_check(0, flp_header,sizeof(flp_header), &header_check_flp, file_stat);
}
+#endif
diff --git a/src/file_flv.c b/src/file_flv.c
index 1adf12a..dd89350 100644
--- a/src/file_flv.c
+++ b/src/file_flv.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_flv)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -64,6 +65,9 @@ struct flv_tag
static data_check_t data_check_flv(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
static uint32_t datasize=0;
+ /*@
+ @ loop assigns file_recovery->calculated_file_size, datasize;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 15 < file_recovery->file_size + buffer_size/2)
{
@@ -113,3 +117,4 @@ static void register_header_check_flv(file_stat_t *file_stat)
static const unsigned char flv_header[4]= {'F', 'L', 'V', 0x01};
register_header_check(0, flv_header,sizeof(flv_header), &header_check_flv, file_stat);
}
+#endif
diff --git a/src/file_fm.c b/src/file_fm.c
index 240e15d..d5800c2 100644
--- a/src/file_fm.c
+++ b/src/file_fm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -51,6 +52,8 @@ struct fm_header
static int header_check_fm(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const struct fm_header *hdr=(const struct fm_header *)buffer;
+ if(le64(hdr->size) > PHOTOREC_MAX_FILE_SIZE)
+ return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_fm.extension;
file_recovery_new->calculated_file_size=(uint64_t)le64(hdr->size) + 12833;
@@ -67,3 +70,4 @@ static void register_header_check_fm(file_stat_t *file_stat)
};
register_header_check(0, fm_header, sizeof(fm_header), &header_check_fm, file_stat);
}
+#endif
diff --git a/src/file_fob.c b/src/file_fob.c
index c96f1bc..35b8362 100644
--- a/src/file_fob.c
+++ b/src/file_fob.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fob)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -72,3 +73,4 @@ static void register_header_check_fob(file_stat_t *file_stat)
register_header_check(0, "Table ", 6, &header_check_fob, file_stat);
register_header_check(0, "XMLport ", 8, &header_check_fob, file_stat);
}
+#endif
diff --git a/src/file_fos.c b/src/file_fos.c
index c2254a3..31be28f 100644
--- a/src/file_fos.c
+++ b/src/file_fos.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fos)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_fos(file_stat_t *file_stat)
{
register_header_check(0, "FO4_SAVEGAME", 11, &header_check_fos, file_stat);
}
+#endif
diff --git a/src/file_fp5.c b/src/file_fp5.c
index 5c762bc..a861201 100644
--- a/src/file_fp5.c
+++ b/src/file_fp5.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fp5)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_fp5(file_stat_t *file_stat)
};
register_header_check(0, fp5_header,sizeof(fp5_header), &header_check_fp5, file_stat);
}
+#endif
diff --git a/src/file_fp7.c b/src/file_fp7.c
index 8e54e54..0749ede 100644
--- a/src/file_fp7.c
+++ b/src/file_fp7.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fp7)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -69,3 +70,4 @@ static void register_header_check_fp7(file_stat_t *file_stat)
};
register_header_check(0, fp7_header,sizeof(fp7_header), &header_check_fp7, file_stat);
}
+#endif
diff --git a/src/file_freeway.c b/src/file_freeway.c
index bdbb419..8e07f46 100644
--- a/src/file_freeway.c
+++ b/src/file_freeway.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_freeway)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_freeway(file_stat_t *file_stat)
};
register_header_check(0x10, freeway_header, sizeof(freeway_header), &header_check_freeway, file_stat);
}
+#endif
diff --git a/src/file_frm.c b/src/file_frm.c
index 4b3f126..480c158 100644
--- a/src/file_frm.c
+++ b/src/file_frm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_frm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -70,3 +71,4 @@ static void register_header_check_frm(file_stat_t *file_stat)
'W', 'G', 'F', 'O', 'R', 'M'};
register_header_check(0, frm_header,sizeof(frm_header), &header_check_frm, file_stat);
}
+#endif
diff --git a/src/file_fs.c b/src/file_fs.c
index c8aa99f..dbd7e05 100644
--- a/src/file_fs.c
+++ b/src/file_fs.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fs)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,6 +59,9 @@ struct transaction_header
static data_check_t data_check_fs(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 0x11 < file_recovery->file_size + buffer_size/2)
{
@@ -102,3 +106,4 @@ static void register_header_check_fs(file_stat_t *file_stat)
static const unsigned char fs_header[4]={ 'F', 'S','2','1' };
register_header_check(0, fs_header,sizeof(fs_header), &header_check_fs, file_stat);
}
+#endif
diff --git a/src/file_fwd.c b/src/file_fwd.c
index 86c0ad8..195e2e7 100644
--- a/src/file_fwd.c
+++ b/src/file_fwd.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fwd)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -52,3 +53,4 @@ static void register_header_check_fwd(file_stat_t *file_stat)
{
register_header_check(0, "FRWD0120", 8, &header_check_fwd, file_stat);
}
+#endif
diff --git a/src/file_gam.c b/src/file_gam.c
index 95b9491..28c0d39 100644
--- a/src/file_gam.c
+++ b/src/file_gam.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gam)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_gam(file_stat_t *file_stat)
};
register_header_check(0, gam_header, sizeof(gam_header), &header_check_gam, file_stat);
}
+#endif
diff --git a/src/file_gct.c b/src/file_gct.c
index fd76bb9..727fbd5 100644
--- a/src/file_gct.c
+++ b/src/file_gct.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gct)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,3 +60,4 @@ static void register_header_check_gct(file_stat_t *file_stat)
};
register_header_check(0, gct_header, sizeof(gct_header), &header_check_gct, file_stat);
}
+#endif
diff --git a/src/file_gho.c b/src/file_gho.c
index cdd0de3..8e405df 100644
--- a/src/file_gho.c
+++ b/src/file_gho.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gho)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_gho(file_stat_t *file_stat)
static const unsigned char gho_header[3]= { 0xfe, 0xef, 0x01 };
register_header_check(0, gho_header,sizeof(gho_header), &header_check_db, file_stat);
}
+#endif
diff --git a/src/file_gi.c b/src/file_gi.c
index bd36fc7..9784612 100644
--- a/src/file_gi.c
+++ b/src/file_gi.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gi)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -51,6 +52,8 @@ struct header_gi
static int header_check_gi(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const struct header_gi *hdr=(const struct header_gi *)buffer;
+ if(le64(hdr->size) > PHOTOREC_MAX_FILE_SIZE)
+ return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_gi.extension;
file_recovery_new->calculated_file_size=le64(hdr->size)+20;
@@ -67,3 +70,4 @@ static void register_header_check_gi(file_stat_t *file_stat)
};
register_header_check(0, gi_header, sizeof(gi_header), &header_check_gi, file_stat);
}
+#endif
diff --git a/src/file_gif.c b/src/file_gif.c
index 6f093c5..75254be 100644
--- a/src/file_gif.c
+++ b/src/file_gif.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gif)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -32,8 +33,6 @@
#include "log.h"
static void register_header_check_gif(file_stat_t *file_stat);
-static int header_check_gif(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
-static void file_check_gif(file_recovery_t *file_recovery);
static data_check_t data_check_gif(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
static data_check_t data_check_gif2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
@@ -46,36 +45,36 @@ const file_hint_t file_hint_gif= {
.register_header_check=&register_header_check_gif
};
-static int header_check_gif(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
+/*@
+ @ requires \valid(file_recovery);
+ @ requires \valid(file_recovery->handle);
+ @ requires \valid_read(&file_recovery->extension);
+ @ requires valid_read_string(file_recovery->extension);
+ @ requires \separated(file_recovery, file_recovery->handle, file_recovery->extension, &errno, &Frama_C_entropy_source);
+ @ requires \initialized(&file_recovery->time);
+ @
+ @ requires file_recovery->file_check == &file_check_gif;
+ @ assigns *file_recovery->handle, errno, file_recovery->file_size;
+ @ assigns Frama_C_entropy_source;
+ @
+ @ ensures \valid(file_recovery->handle);
+ @*/
+static void file_check_gif(file_recovery_t *file_recovery)
{
- uint64_t offset;
- offset=6; /* Header */
- offset+=7; /* Logical Screen Descriptor */
- if((buffer[10]>>7)&0x1)
+ const char gif_footer[2]= {0x00, 0x3b};
+ char buffer[2];
+ /* file_recovery->calculated_file_size is always >= */
+ if(file_recovery->calculated_file_size < 2 ||
+ my_fseek(file_recovery->handle, file_recovery->calculated_file_size-2, SEEK_SET)<0 ||
+ fread(buffer, 2, 1, file_recovery->handle)!=1)
{
- /* Global Color Table */
- offset+=3<<((buffer[10]&7)+1);
+ file_recovery->file_size=0;
+ return;
}
- if(offset < buffer_size && buffer[offset]!=0x21 && buffer[offset]!=0x2c)
- return 0;
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_gif.extension;
- file_recovery_new->min_filesize=42;
- if(file_recovery_new->blocksize < 2)
- return 1;
- file_recovery_new->file_check=&file_check_gif;
- file_recovery_new->calculated_file_size=offset;
- file_recovery_new->data_check=&data_check_gif;
- return 1;
-}
-
-static void file_check_gif(file_recovery_t *file_recovery)
-{
- const unsigned char gif_footer[2]= {0x00, 0x3b};
- unsigned char buffer[2];
- if(my_fseek(file_recovery->handle, file_recovery->calculated_file_size-2, SEEK_SET)<0 ||
- fread(buffer, 2, 1, file_recovery->handle)!=1 ||
- memcmp(buffer, gif_footer, sizeof(gif_footer))!=0)
+#ifdef __FRAMAC__
+ Frama_C_make_unknown(&buffer, sizeof(buffer));
+#endif
+ if(memcmp(buffer, gif_footer, sizeof(gif_footer))!=0)
{
file_recovery->file_size=0;
return;
@@ -153,6 +152,59 @@ static data_check_t data_check_gif2(const unsigned char *buffer, const unsigned
return DC_CONTINUE;
}
+/*@
+ @ requires buffer_size > 0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid_read(file_recovery);
+ @ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
+ @ requires \valid(file_recovery_new);
+ @ requires file_recovery_new->blocksize > 0;
+ @
+ @ requires buffer_size >= 6+7+(3<<8)+1;
+ @ requires separation: \separated(&file_hint_gif, buffer+(..), file_recovery, file_recovery_new);
+ @
+ @ ensures \result == 0 || \result == 1;
+ @ ensures (\result == 1) ==> (file_recovery_new->file_stat == \null);
+ @ ensures (\result == 1) ==> (file_recovery_new->handle == \null);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->time);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->calculated_file_size);
+ @ ensures (\result == 1) ==> file_recovery_new->file_size == 0;
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->min_filesize);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null || \valid_function(file_recovery_new->data_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == \null || \valid_function(file_recovery_new->file_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename == \null || \valid_function(file_recovery_new->file_rename));
+ @ ensures (\result != 0) ==> file_recovery_new->extension != \null;
+ @ ensures (\result == 1) ==> (valid_read_string(file_recovery_new->extension));
+ @ ensures (\result == 1) ==> \separated(file_recovery_new, file_recovery_new->extension);
+ @
+ @ ensures (\result == 1) ==> (file_recovery_new->time == 0);
+ @ ensures (\result == 1 && file_recovery_new->blocksize>=2) ==> (file_recovery_new->calculated_file_size >= 6+7);
+ @ ensures (\result == 1 && file_recovery_new->blocksize>=2) ==> (file_recovery_new->extension == file_hint_gif.extension);
+ @ ensures (\result == 1 && file_recovery_new->blocksize>=2) ==> (file_recovery_new->file_check == &file_check_gif);
+ @*/
+static int header_check_gif(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
+{
+ uint64_t offset;
+ offset=6; /* Header */
+ offset+=7; /* Logical Screen Descriptor */
+ if((buffer[10]>>7)&0x1)
+ {
+ /* Global Color Table */
+ offset+=3<<((buffer[10]&7)+1);
+ }
+ if(offset < buffer_size && buffer[offset]!=0x21 && buffer[offset]!=0x2c)
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_gif.extension;
+ file_recovery_new->min_filesize=42;
+ if(file_recovery_new->blocksize < 2)
+ return 1;
+ file_recovery_new->calculated_file_size=offset;
+ file_recovery_new->file_check=&file_check_gif;
+ file_recovery_new->data_check=&data_check_gif;
+ return 1;
+}
+
static void register_header_check_gif(file_stat_t *file_stat)
{
static const unsigned char gif_header[6]= { 'G','I','F','8','7','a'};
@@ -160,3 +212,4 @@ static void register_header_check_gif(file_stat_t *file_stat)
register_header_check(0, gif_header,sizeof(gif_header), &header_check_gif, file_stat);
register_header_check(0, gif_header2,sizeof(gif_header2), &header_check_gif, file_stat);
}
+#endif
diff --git a/src/file_gm6.c b/src/file_gm6.c
index 536eeca..4445a6c 100644
--- a/src/file_gm6.c
+++ b/src/file_gm6.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gm6)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -140,3 +141,4 @@ static void register_header_check_gm6(file_stat_t *file_stat)
register_header_check(0, gm50_header, sizeof(gm50_header), &header_check_gmd, file_stat);
register_header_check(0, gm43_header, sizeof(gm43_header), &header_check_gmd, file_stat);
}
+#endif
diff --git a/src/file_gp2.c b/src/file_gp2.c
index a96e80d..407a4c5 100644
--- a/src/file_gp2.c
+++ b/src/file_gp2.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gp2)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -66,3 +67,4 @@ static void register_header_check_gp2(file_stat_t *file_stat)
};
register_header_check(0, gp2_header, sizeof(gp2_header), &header_check_gp2, file_stat);
}
+#endif
diff --git a/src/file_gp5.c b/src/file_gp5.c
index 4d9d156..fcd66d0 100644
--- a/src/file_gp5.c
+++ b/src/file_gp5.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gp5)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -77,3 +78,4 @@ static void register_header_check_gp5(file_stat_t *file_stat)
};
register_header_check(0, gp5_header, sizeof(gp5_header), &header_check_gp5, file_stat);
}
+#endif
diff --git a/src/file_gpg.c b/src/file_gpg.c
index 6492aed..225eaf0 100644
--- a/src/file_gpg.c
+++ b/src/file_gpg.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gpg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -281,20 +282,23 @@ static int is_valid_S2K(const unsigned int algo)
/*@
@ requires \valid(handle);
@ requires offset + tmp2 < 0x8000000000000000;
+ @ assigns *handle, errno;
+ @ assigns Frama_C_entropy_source;
@*/
static unsigned int file_check_gpg_pubkey(FILE *handle, const uint64_t offset, const uint64_t tmp2)
{
int len2;
- uint16_t mpi2;
+ char buffer[2];
+ const uint16_t *mpi2_ptr=(uint16_t *)&buffer;
if(my_fseek(handle, offset+tmp2, SEEK_SET) < 0 ||
- fread(&mpi2, sizeof(mpi2), 1, handle) != 1)
+ fread(buffer, sizeof(buffer), 1, handle) != 1)
return 0;
#ifdef __FRAMAC__
- Frama_C_make_unknown((char *)&mpi2, sizeof(mpi2));
+ Frama_C_make_unknown(&buffer, sizeof(buffer));
#endif
- len2=is_valid_mpi(mpi2);
+ len2=is_valid_mpi(*mpi2_ptr);
#ifdef DEBUG_GPG
- log_info(" data: [ %u bits]\n", be16(mpi2));
+ log_info(" data: [ %u bits]\n", be16(*mpi2_ptr));
#endif
if(len2 < 0)
return 0;
@@ -304,6 +308,7 @@ static unsigned int file_check_gpg_pubkey(FILE *handle, const uint64_t offset, c
/*@
@ requires \valid(file_recovery);
@ requires \valid(file_recovery->handle);
+ @ requires \separated(file_recovery, file_recovery->handle);
@ requires file_recovery->file_check == &file_check_gpg;
@*/
static void file_check_gpg(file_recovery_t *file_recovery)
@@ -778,6 +783,7 @@ static void register_header_check_gpg(file_stat_t *file_stat)
register_header_check(0, pgp_header, sizeof(pgp_header), &header_check_gpg, file_stat);
register_header_check(0, gpg_header_pkey, sizeof(gpg_header_pkey), &header_check_gpg, file_stat);
}
+#endif
#if defined(MAIN_gpg)
#define BLOCKSIZE 65536u
diff --git a/src/file_gpx.c b/src/file_gpx.c
index a1b91e7..7d7c5c9 100644
--- a/src/file_gpx.c
+++ b/src/file_gpx.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gpx)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_gpx(file_stat_t *file_stat)
{
register_header_check(0, "BCFZ", 4, &header_check_gpx, file_stat);
}
+#endif
diff --git a/src/file_gsm.c b/src/file_gsm.c
index 7955344..affa471 100644
--- a/src/file_gsm.c
+++ b/src/file_gsm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gsm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -52,6 +53,9 @@ struct block_header
static data_check_t data_check_gsm(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
+ /*@
+ @ loop assigns file_recovery->calculated_file_size;
+ @*/
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + sizeof(struct block_header) < file_recovery->file_size + buffer_size/2)
{
@@ -64,14 +68,26 @@ static data_check_t data_check_gsm(const unsigned char *buffer, const unsigned i
return DC_CONTINUE;
}
+/*@
+ @ requires buffer_size > 0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid_read(file_recovery);
+ @ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
+ @ requires \valid(file_recovery_new);
+ @ requires file_recovery_new->blocksize > 0;
+ @
+ @ requires file_recovery_new->blocksize <= buffer_size;
+ @ requires separation: \separated(&file_hint_gsm, buffer+(..), file_recovery, file_recovery_new);
+ @*/
static int header_check_gsm(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
- const struct block_header *hdr;
unsigned int i=0;
- for(i=0, hdr=(const struct block_header *)buffer;
- i * sizeof(struct block_header) < file_recovery_new->blocksize;
- i++, hdr++)
+ /*@ loop assigns i; */
+ for(i=0;
+ (i+1) * sizeof(struct block_header) <= file_recovery_new->blocksize;
+ i++)
{
+ const struct block_header *hdr=(const struct block_header *)&buffer[i*sizeof(struct block_header)];
if(hdr->marker < 0xd0 || hdr->marker > 0xdf)
return 0;
}
@@ -128,3 +144,4 @@ static void register_header_check_gsm(file_stat_t *file_stat)
register_header_check(0, gsm_header15, sizeof(gsm_header15), &header_check_gsm, file_stat);
register_header_check(0, gsm_header16, sizeof(gsm_header16), &header_check_gsm, file_stat);
}
+#endif
diff --git a/src/file_gz.c b/src/file_gz.c
index f67cb84..d75cfa9 100644
--- a/src/file_gz.c
+++ b/src/file_gz.c
@@ -20,12 +20,14 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gz)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
-#ifdef __FRAMAC__
+#if defined(MAIN_fidentify) || defined(MAIN_photorec) || defined(__FRAMAC__)
#undef HAVE_LIBZ
+#undef HAVE_ZLIB_H
#endif
#ifdef HAVE_STRING_H
@@ -42,7 +44,9 @@
static void register_header_check_gz(file_stat_t *file_stat);
static void file_rename_gz(file_recovery_t *file_recovery);
+#ifndef SINGLE_FORMAT
extern const file_hint_t file_hint_doc;
+#endif
const file_hint_t file_hint_gz= {
.extension="gz",
@@ -162,15 +166,20 @@ static int header_check_gz(const unsigned char *buffer, const unsigned int buffe
}
if(off >= 512 || off >= buffer_size)
return 0;
+ /*@ assert off < 512; */
+ /*@ assert off < buffer_size ; */
#if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ)
{
static const unsigned char schematic_header[12]={ 0x0a, 0x00, 0x09,
'S', 'c', 'h', 'e', 'm', 'a', 't', 'i', 'c'};
static const unsigned char tar_header_posix[8] = { 'u','s','t','a','r',' ',' ',0x00};
const unsigned char *buffer_compr=buffer+off;
- unsigned char buffer_uncompr[512];
- const unsigned int comprLen=(buffer_size<512?buffer_size:512)-off;
- const unsigned int uncomprLen=512-1;
+ unsigned char buffer_uncompr[4096];
+ const unsigned int uncomprLen=sizeof(buffer_uncompr)-1;
+ const unsigned int bs=td_max(512,file_recovery_new->blocksize);
+ /*@ assert bs >=512; */
+ const unsigned int comprLen=td_min(buffer_size,bs)-off;
+ /*@ assert comprLen > 0; */
int err;
z_stream d_stream; /* decompression stream */
d_stream.zalloc = (alloc_func)0;
@@ -201,12 +210,14 @@ static int header_check_gz(const unsigned char *buffer, const unsigned int buffe
/* Probably too small to be a file */
if(d_stream.total_out < 16)
return 0;
+#ifndef SINGLE_FORMAT
if(file_recovery->file_stat!=NULL &&
file_recovery->file_stat->file_hint==&file_hint_doc)
{
if(header_ignored_adv(file_recovery, file_recovery_new)==0)
return 0;
}
+#endif
if(file_recovery->file_check==&file_check_bgzf)
{
header_ignored(file_recovery_new);
@@ -221,6 +232,15 @@ static int header_check_gz(const unsigned char *buffer, const unsigned int buffe
file_recovery_new->min_filesize=22;
file_recovery_new->time=le32(gz->mtime);
file_recovery_new->file_rename=&file_rename_gz;
+ if(d_stream.avail_in==0 && d_stream.total_in < comprLen && d_stream.total_out < uncomprLen)
+ {
+ /* an 8-byte footer, containing a CRC-32 checksum and
+ * the length of the original uncompressed data, modulo 2^32
+ */
+ file_recovery_new->calculated_file_size=off+d_stream.total_in+8;
+ file_recovery_new->data_check=&data_check_size;
+ file_recovery_new->file_check=&file_check_size;
+ }
if(memcmp(buffer_uncompr, "PVP ", 4)==0)
{
/* php Video Pro */
@@ -302,12 +322,14 @@ static int header_check_gz(const unsigned char *buffer, const unsigned int buffe
}
}
#else
+#ifndef SINGLE_FORMAT
if(file_recovery->file_stat!=NULL &&
file_recovery->file_stat->file_hint==&file_hint_doc)
{
if(header_ignored_adv(file_recovery, file_recovery_new)==0)
return 0;
}
+#endif
if(file_recovery->file_check==&file_check_bgzf)
{
header_ignored(file_recovery_new);
@@ -350,6 +372,13 @@ static void file_rename_gz(file_recovery_t *file_recovery)
}
}
+static void register_header_check_gz(file_stat_t *file_stat)
+{
+ static const unsigned char gz_header_magic[3]= {0x1F, 0x8B, 0x08};
+ register_header_check(0, gz_header_magic,sizeof(gz_header_magic), &header_check_gz, file_stat);
+}
+#endif
+
const char*td_zlib_version(void)
{
#if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ)
@@ -358,9 +387,3 @@ const char*td_zlib_version(void)
return "none";
#endif
}
-
-static void register_header_check_gz(file_stat_t *file_stat)
-{
- static const unsigned char gz_header_magic[3]= {0x1F, 0x8B, 0x08};
- register_header_check(0, gz_header_magic,sizeof(gz_header_magic), &header_check_gz, file_stat);
-}
diff --git a/src/file_hdf.c b/src/file_hdf.c
index 378855c..a3014d7 100644
--- a/src/file_hdf.c
+++ b/src/file_hdf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hdf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -71,33 +72,49 @@ static void file_check_hdf(file_recovery_t *file_recovery)
do
{
struct ddh_struct ddh;
- const struct dd_struct *p;
unsigned int i;
unsigned int size;
if(my_fseek(file_recovery->handle, offset, SEEK_SET) < 0 ||
- fread(&ddh, sizeof(ddh), 1, file_recovery->handle) !=1 ||
- be16(ddh.size)==0 ||
- fread(dd, sizeof(struct dd_struct)*be16(ddh.size), 1, file_recovery->handle) !=1)
+ fread(&ddh, sizeof(ddh), 1, file_recovery->handle) !=1)
{
free(dd);
file_recovery->file_size=0;
return ;
}
+#ifdef __FRAMAC__
+ Frama_C_make_unknown(&ddh, sizeof(ddh));
+#endif
size=be16(ddh.size);
+ if(size==0 ||
+ fread(dd, sizeof(struct dd_struct)*size, 1, file_recovery->handle) !=1)
+ {
+ free(dd);
+ file_recovery->file_size=0;
+ return ;
+ }
+#ifdef __FRAMAC__
+ Frama_C_make_unknown(dd, sizeof(struct dd_struct)*size);
+#endif
if(file_size < offset + sizeof(struct dd_struct) * size)
file_size = offset + sizeof(struct dd_struct) * size;
#ifdef DEBUG_HDF
log_info("size=%u next=%lu\n", size, be32(ddh.next));
#endif
- for(i=0, p=dd; i < size; i++,p++)
+ /*@
+ @ loop assigns i, file_size;
+ @*/
+ for(i=0; i < size; i++)
{
+ const struct dd_struct *p=&dd[i];
+ const unsigned int p_offset=be32(p->offset);
+ const unsigned int p_length=be32(p->length);
#ifdef DEBUG_HDF
log_info("tag=0x%04x, ref=%u, offset=%lu, length=%lu\n",
- be16(p->tag), be16(p->ref), be32(p->offset), be32(p->length));
+ be16(p->tag), be16(p->ref), p_offset, p_length);
#endif
- if((unsigned)be32(p->offset)!=(unsigned)(-1) &&
- file_size < (uint64_t)be32(p->offset) + (uint64_t)be32(p->length))
- file_size = (uint64_t)be32(p->offset) + (uint64_t)be32(p->length);
+ if(p_offset!=0xffffffff &&
+ file_size < (uint64_t)p_offset + (uint64_t)p_length)
+ file_size = (uint64_t)p_offset + (uint64_t)p_length;
}
offset_old=offset;
offset=be32(ddh.next);
@@ -129,3 +146,4 @@ static void register_header_check_hdf(file_stat_t *file_stat)
static const unsigned char hdf_header[4]= { 0x0e, 0x03, 0x13, 0x01};
register_header_check(0, hdf_header, sizeof(hdf_header), &header_check_hdf, file_stat);
}
+#endif
diff --git a/src/file_hdr.c b/src/file_hdr.c
index 0e6e9e6..596d3bc 100644
--- a/src/file_hdr.c
+++ b/src/file_hdr.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hdr)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -79,3 +80,4 @@ static void register_header_check_hdr(file_stat_t *file_stat)
{
register_header_check(0, "ISc(", 4, &header_check_hdr, file_stat);
}
+#endif
diff --git a/src/file_hds.c b/src/file_hds.c
index 92664d2..4ada2f6 100644
--- a/src/file_hds.c
+++ b/src/file_hds.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hds)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -74,3 +75,4 @@ static void register_header_check_hds(file_stat_t *file_stat)
};
register_header_check(0, hds_header,sizeof(hds_header), &header_check_hds, file_stat);
}
+#endif
diff --git a/src/file_hfsp.c b/src/file_hfsp.c
index 8ed2504..0f7fc40 100644
--- a/src/file_hfsp.c
+++ b/src/file_hfsp.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hfsp)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,3 +60,4 @@ static void register_header_check_hfsp(file_stat_t *file_stat)
register_header_check(0, "HX\0\5", 4, &header_check_hfsp, file_stat);
}
+#endif
diff --git a/src/file_hm.c b/src/file_hm.c
index 2eaa559..ea2f07c 100644
--- a/src/file_hm.c
+++ b/src/file_hm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -57,3 +58,4 @@ static void register_header_check_hm(file_stat_t *file_stat)
};
register_header_check(0, hm_header, sizeof(hm_header), &header_check_hm, file_stat);
}
+#endif
diff --git a/src/file_hr9.c b/src/file_hr9.c
index 3f5045f..ace2b02 100644
--- a/src/file_hr9.c
+++ b/src/file_hr9.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hr9)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -63,3 +64,4 @@ static void register_header_check_hr9(file_stat_t *file_stat)
};
register_header_check(0, hr9_header,sizeof(hr9_header), &header_check_hr9, file_stat);
}
+#endif
diff --git a/src/file_http.c b/src/file_http.c
index 33e63fa..5baa99e 100644
--- a/src/file_http.c
+++ b/src/file_http.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_http)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -52,3 +53,4 @@ static void register_header_check_http(file_stat_t *file_stat)
{
register_header_check(0, "HTTP/1.1 200 OK\r\nDate:", 22, &header_check_http, file_stat);
}
+#endif
diff --git a/src/file_ibd.c b/src/file_ibd.c
index b26eb2b..0631e75 100644
--- a/src/file_ibd.c
+++ b/src/file_ibd.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ibd)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -49,7 +50,7 @@ const file_hint_t file_hint_ibd= {
#define DICT_TF_BITS 6 /* number of flag bits */
#define DICT_TF_FORMAT_SHIFT 5 /* file format */
#define DICT_TF_FORMAT_MASK \
- ((~(~0 << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT))) << DICT_TF_FORMAT_SHIFT)
+ ((~(~0U << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT))) << DICT_TF_FORMAT_SHIFT)
#define DICT_TF_FORMAT_ZIP 1 /* InnoDB plugin for 5.1: compressed tables */
@@ -104,3 +105,4 @@ static void register_header_check_ibd(file_stat_t *file_stat)
{
register_header_check(0xc063, "infimum", 7, &header_check_ibd, file_stat);
}
+#endif
diff --git a/src/file_icc.c b/src/file_icc.c
index 9d22646..f540091 100644
--- a/src/file_icc.c
+++ b/src/file_icc.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_icc)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -65,3 +66,4 @@ static void register_header_check_icc(file_stat_t *file_stat)
static const unsigned char icc_header[4]= { 'a', 'c', 's', 'p' };
register_header_check(36, icc_header,sizeof(icc_header), &header_check_icc, file_stat);
}
+#endif
diff --git a/src/file_icns.c b/src/file_icns.c
index 20d5d12..2216369 100644
--- a/src/file_icns.c
+++ b/src/file_icns.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_icns)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -52,7 +53,7 @@ struct icon_data
{
char type[4];
uint32_t size;
- uint8_t data[0];
+// uint8_t data[0];
};
static int check_icon_type(const char *type)
@@ -100,17 +101,19 @@ static int header_check_icns(const unsigned char *buffer, const unsigned int buf
{
const struct icns_header *hdr=(const struct icns_header *)buffer;
const struct icon_data *icon=(const struct icon_data *)&buffer[8];
- if(be32(hdr->size) < sizeof(struct icns_header))
+ const unsigned int hdr_size=be32(hdr->size);
+ const unsigned int icon_size=be32(icon->size);
+ if(hdr_size < sizeof(struct icns_header))
return 0;
- if(be32(icon->size) < sizeof(struct icon_data))
+ if(icon_size < sizeof(struct icon_data))
return 0;
- if(8 + be32(icon->size) > be32(hdr->size))
+ if(icon_size > hdr_size - 8)
return 0;
if(!check_icon_type(icon->type))
return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_icns.extension;
- file_recovery_new->calculated_file_size=be32(hdr->size);
+ file_recovery_new->calculated_file_size=hdr_size;
file_recovery_new->data_check=&data_check_size;
file_recovery_new->file_check=&file_check_size;
return 1;
@@ -120,3 +123,4 @@ static void register_header_check_icns(file_stat_t *file_stat)
{
register_header_check(0, "icns", 4, &header_check_icns, file_stat);
}
+#endif
diff --git a/src/file_ico.c b/src/file_ico.c
index af2ae41..4d63a7a 100644
--- a/src/file_ico.c
+++ b/src/file_ico.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ico)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -155,3 +156,4 @@ static void register_header_check_ico(file_stat_t *file_stat)
register_header_check(0, header_ico8, sizeof(header_ico8), &header_check_ico, file_stat);
register_header_check(0, header_ico9, sizeof(header_ico9), &header_check_ico, file_stat);
}
+#endif
diff --git a/src/file_idx.c b/src/file_idx.c
index 66f9cee..83934f6 100644
--- a/src/file_idx.c
+++ b/src/file_idx.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_idx)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -71,3 +72,4 @@ static void register_header_check_idx(file_stat_t *file_stat)
{
register_header_check(0, "RT60", 4, &header_check_idx, file_stat);
}
+#endif
diff --git a/src/file_ifo.c b/src/file_ifo.c
index a55ec66..1577ec4 100644
--- a/src/file_ifo.c
+++ b/src/file_ifo.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ifo)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -67,3 +68,4 @@ static void register_header_check_ifo(file_stat_t *file_stat)
register_header_check(0, ifo_header_vmg, sizeof(ifo_header_vmg), &header_check_ifo, file_stat);
register_header_check(0, ifo_header_vts, sizeof(ifo_header_vts), &header_check_ifo, file_stat);
}
+#endif
diff --git a/src/file_imb.c b/src/file_imb.c
index d21be56..3d35bf6 100644
--- a/src/file_imb.c
+++ b/src/file_imb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_imb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_imb(file_stat_t *file_stat)
static const unsigned char imb_header[15]= { 0x00, 0x00, 0x00, 'I','n','c','r','e','d','i','m','a','i','l',' '};
register_header_check(1, imb_header,sizeof(imb_header), &header_check_imb, file_stat);
}
+#endif
diff --git a/src/file_indd.c b/src/file_indd.c
index 5d16702..638a321 100644
--- a/src/file_indd.c
+++ b/src/file_indd.c
@@ -21,6 +21,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_indd)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -94,8 +95,17 @@ static void file_check_indd(file_recovery_t *file_recovery)
file_recovery->file_size=0;
return ;
}
- if(fread(&hdr, sizeof(hdr), 1, file_recovery->handle) != 1 ||
- memcmp(hdr.fGUID, kINDDContigObjHeaderGUID, sizeof(kINDDContigObjHeaderGUID))!=0)
+ if(fread(&hdr, sizeof(hdr), 1, file_recovery->handle) != 1)
+ {
+ file_recovery->file_size=(offset+4096-1)/4096*4096;
+ if(file_recovery->file_size>file_size_org)
+ file_recovery->file_size=0;
+ return ;
+ }
+#ifdef __FRAMAC__
+ Frama_C_make_unknown(&hdr, sizeof(hdr));
+#endif
+ if(memcmp(hdr.fGUID, kINDDContigObjHeaderGUID, sizeof(kINDDContigObjHeaderGUID))!=0)
{
file_recovery->file_size=(offset+4096-1)/4096*4096;
if(file_recovery->file_size>file_size_org)
@@ -150,3 +160,4 @@ static void register_header_check_indd(file_stat_t *file_stat)
0x44, 0x4f, 0x43, 0x55, 0x4d, 0x45, 0x4e, 0x54 };
register_header_check(0, indd_header,sizeof(indd_header), &header_check_indd, file_stat);
}
+#endif
diff --git a/src/file_info.c b/src/file_info.c
index 1b4d3e9..360394b 100644
--- a/src/file_info.c
+++ b/src/file_info.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_info)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -57,3 +58,4 @@ static void register_header_check_info(file_stat_t *file_stat)
};
register_header_check(0, info_header, sizeof(info_header), &header_check_info, file_stat);
}
+#endif
diff --git a/src/file_iso.c b/src/file_iso.c
index 0483809..49c5dbe 100644
--- a/src/file_iso.c
+++ b/src/file_iso.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_iso)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -28,6 +29,7 @@
#endif
#include <stdio.h>
#include "types.h"
+#include "common.h"
#include "filegen.h"
#include "iso9660.h"
@@ -49,13 +51,13 @@ static int header_check_db(const unsigned char *buffer, const unsigned int buffe
return 0;
{
const struct iso_primary_descriptor *iso1=(const struct iso_primary_descriptor*)&buffer[0x8000];
- const unsigned int volume_space_size=iso1->volume_space_size[0] | (iso1->volume_space_size[1]<<8) | (iso1->volume_space_size[2]<<16) | (iso1->volume_space_size[3]<<24);
- const unsigned int volume_space_size2=iso1->volume_space_size[7] | (iso1->volume_space_size[6]<<8) | (iso1->volume_space_size[5]<<16) | (iso1->volume_space_size[4]<<24);
- const unsigned int logical_block_size=iso1->logical_block_size[0] | (iso1->logical_block_size[1]<<8);
- const unsigned int logical_block_size2=iso1->logical_block_size[3] | (iso1->logical_block_size[2]<<8);
- if(volume_space_size==volume_space_size2 && logical_block_size==logical_block_size2)
+ const unsigned int volume_space_size_le=le32(iso1->volume_space_size_le);
+ const unsigned int volume_space_size_be=be32(iso1->volume_space_size_be);
+ const unsigned int logical_block_size_le=le16(iso1->logical_block_size_le);
+ const unsigned int logical_block_size_be=be16(iso1->logical_block_size_be);
+ if(volume_space_size_le==volume_space_size_be && logical_block_size_le==logical_block_size_be)
{ /* ISO 9660 */
- const uint64_t size=(uint64_t)volume_space_size * logical_block_size;
+ const uint64_t size=(uint64_t)volume_space_size_le * logical_block_size_le;
if(size < 0x8000+512)
return 0;
reset_file_recovery(file_recovery_new);
@@ -78,4 +80,4 @@ static void register_header_check_iso(file_stat_t *file_stat)
static const unsigned char iso_header[6]= { 0x01, 'C', 'D', '0', '0', '1'};
register_header_check(0x8000, iso_header,sizeof(iso_header), &header_check_db, file_stat);
}
-
+#endif
diff --git a/src/file_it.c b/src/file_it.c
index 3f8925f..4aa14ed 100644
--- a/src/file_it.c
+++ b/src/file_it.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_it)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -82,3 +83,4 @@ static void register_header_check_it(file_stat_t *file_stat)
{
register_header_check(0, "IMPM", 4, &header_check_it, file_stat);
}
+#endif
diff --git a/src/file_itu.c b/src/file_itu.c
index 6033e6a..1c00342 100644
--- a/src/file_itu.c
+++ b/src/file_itu.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_itunes)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -63,3 +64,4 @@ static void register_header_check_itunes(file_stat_t *file_stat)
static const unsigned char itunes_header[8]= {'m', 'h', 'b', 'd', 0x68, 0x00, 0x00, 0x00};
register_header_check(0, itunes_header,sizeof(itunes_header), &header_check_itunes, file_stat);
}
+#endif
diff --git a/src/file_jks.c b/src/file_jks.c
index 9539db1..3ca16b7 100644
--- a/src/file_jks.c
+++ b/src/file_jks.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_jks)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -68,3 +69,4 @@ static void register_header_check_jks(file_stat_t *file_stat)
};
register_header_check(0, jks_header, sizeof(jks_header), &header_check_jks, file_stat);
}
+#endif
diff --git a/src/file_jpg.c b/src/file_jpg.c
index 518173d..a807a48 100644
--- a/src/file_jpg.c
+++ b/src/file_jpg.c
@@ -20,13 +20,15 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_jpg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
-#ifdef __FRAMAC__
+#if defined(__FRAMAC__) || defined(SINGLE_FORMAT)
#undef HAVE_LIBJPEG
#undef DEBUG_JPEG
+#undef HAVE_JPEGLIB_H
#endif
#ifdef HAVE_STRING_H
@@ -71,6 +73,12 @@ extern data_check_t data_check_avi_stream(const unsigned char *buffer, const uns
static void register_header_check_jpg(file_stat_t *file_stat);
static void file_check_jpg(file_recovery_t *file_recovery);
static data_check_t data_check_jpg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+
+/*@
+ @ requires i < buffer_size;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ assigns \nothing;
+ @*/
static int jpg_check_dht(const unsigned char *buffer, const unsigned int buffer_size, const unsigned i, const unsigned int size);
const file_hint_t file_hint_jpg= {
@@ -435,7 +443,6 @@ static int is_marker_valid(const unsigned int marker)
{
switch(marker)
{
- case 0x02 ... 0xbf: /* Reserved */
case 0xc0: /* SOF0 Start of Frame */
case 0xc1: /* SOF1 Extended sequential */
case 0xc2: /* SOF2 Progressive */
@@ -452,19 +459,22 @@ static int is_marker_valid(const unsigned int marker)
case 0xcd: /* SOF13 Differential sequential, arithmetic coding */
case 0xce: /* SOF14 Differential progressive, arithmetic coding */
case 0xcf: /* SOF15 Differential lossless, arithmetic coding */
- case 0xd0 ... 0xd7: /* JPEG_RST0 .. JPEG_RST7 markers */
-// case 0xd8: /* SOI Start of Image */
-// case 0xd9: /* EOI End of Image */
-// case 0xda: /* SOS: Start Of Scan */
case 0xdb: /* DQT: Define Quantization Table */
- case 0xdc: /* DNL: Define Number of Lines */
case 0xdd: /* DRI: define restart interval */
- case 0xde: /* DHP: define hierarchical progression */
case 0xe0 ... 0xef: /* APP0 - APP15 */
- case 0xf0 ... 0xfd: /* Reserved for JPEG extensions */
case 0xfe: /* COM */
case 0xff:
return 1;
+#if 0
+ case 0x02 ... 0xbf: /* Reserved */
+ case 0xd0 ... 0xd7: /* JPEG_RST0 .. JPEG_RST7 markers */
+ case 0xd8: /* SOI Start of Image */
+ case 0xd9: /* EOI End of Image */
+ case 0xda: /* SOS: Start Of Scan */
+ case 0xdc: /* DNL: Define Number of Lines */
+ case 0xde: /* DHP: define hierarchical progression */
+ case 0xf0 ... 0xfd: /* Reserved for JPEG extensions */
+#endif
default:
return 0;
}
@@ -498,26 +508,37 @@ static time_t jpg_get_date(const unsigned char *buffer, const unsigned int buffe
/*@
- @ requires buffer_size >= 10;
+ @ requires buffer_size > 0;
@ requires \valid_read(buffer+(0..buffer_size-1));
@ requires \valid_read(file_recovery);
@ requires file_recovery->file_stat==\null || valid_read_string((char*)&file_recovery->filename);
@ requires \valid(file_recovery_new);
@ requires file_recovery_new->blocksize > 0;
+ @
+ @ requires buffer_size >= 10;
@ requires separation: \separated(&file_hint_jpg, buffer+(..), file_recovery, file_recovery_new);
+ @
@ ensures \result == 0 || \result == 1;
@ ensures (\result == 1) ==> (file_recovery_new->file_stat == \null);
@ ensures (\result == 1) ==> (file_recovery_new->handle == \null);
- @ ensures \result == 1 ==> file_recovery_new->extension == file_hint_jpg.extension;
@ ensures \result == 1 ==> \initialized(&file_recovery_new->time);
- @ ensures \result == 1 ==> file_recovery_new->calculated_file_size == 0;
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->calculated_file_size);
@ ensures \result == 1 ==> file_recovery_new->file_size == 0;
- @ ensures \result == 1 ==> file_recovery_new->min_filesize > 0;
- @ ensures \result == 1 ==> file_recovery_new->offset_ok == 0;
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->min_filesize);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null || \valid_function(file_recovery_new->data_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == \null || \valid_function(file_recovery_new->file_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename == \null || \valid_function(file_recovery_new->file_rename));
+ @ ensures (\result == 1) ==> (file_recovery_new->extension != \null);
+ @ ensures (\result == 1) ==> valid_read_string(file_recovery_new->extension);
+ @ ensures (\result == 1) ==> \separated(file_recovery_new, file_recovery_new->extension);
+ @
+ @ ensures \result == 1 ==> file_recovery_new->calculated_file_size == 0;
@ ensures \result == 1 && buffer_size >= 4 ==> file_recovery_new->data_check == data_check_jpg;
@ ensures \result == 1 ==> file_recovery_new->file_check == file_check_jpg;
@ ensures \result == 1 ==> file_recovery_new->file_rename == \null;
- @ ensures \result == 1 ==> valid_read_string(file_recovery_new->extension);
+ @ ensures \result == 1 ==> file_recovery_new->extension == file_hint_jpg.extension;
+ @ ensures \result == 1 ==> file_recovery_new->min_filesize > 0;
+ @ ensures \result == 1 ==> file_recovery_new->offset_ok == 0;
@*/
static int header_check_jpg(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
@@ -543,10 +564,21 @@ static int header_check_jpg(const unsigned char *buffer, const unsigned int buff
i+=2+size;
}
}
+ if(i < file_recovery_new->blocksize && buffer[i]!=0xff)
+ return 0;
if(i+1 < file_recovery_new->blocksize && buffer[i+1]!=0xda)
return 0;
+ if(i < 512 && buffer[i]!=0xff)
+ return 0;
if(i+1 < 512 && buffer[i+1]!=0xda)
return 0;
+ if(file_recovery->file_stat==NULL)
+ {
+ if(i < buffer_size && buffer[i]!=0xff)
+ return 0;
+ if(i+1 < buffer_size && buffer[i+1]!=0xda)
+ return 0;
+ }
if(file_recovery->file_stat!=NULL)
{
static const unsigned char jpg_header_app0_avi[0x0c]= {
@@ -629,30 +661,32 @@ static int header_check_jpg(const unsigned char *buffer, const unsigned int buff
return 0;
}
#endif
- if(buffer[3]==0xdb) /* DQT */
- {
- header_ignored(file_recovery_new);
- return 0;
- }
- if(buffer[3]==0xc4) /* DHT - needed to recover .cr2 */
- {
- header_ignored(file_recovery_new);
- return 0;
- }
- if(buffer[3]==0xe0 && (buffer[6]!='J' || buffer[7]!='F')) /* Should be JFIF/JFXX */
- {
- header_ignored(file_recovery_new);
- return 0;
- }
- if(buffer[3]==0xe1 && (buffer[6]!='E' || buffer[7]!='x' || buffer[8]!='i'|| buffer[9]!='f')) /* Should be EXIF */
- {
- header_ignored(file_recovery_new);
- return 0;
- }
- if(buffer[3]==0xfe && (!isprint(buffer[6]) || !isprint(buffer[7])))
+ switch(buffer[3])
{
- header_ignored(file_recovery_new);
- return 0;
+ case 0xe0: /* APP0 */
+ if(buffer[6]!='J' || buffer[7]!='F') /* Should be JFIF/JFXX */
+ {
+ header_ignored(file_recovery_new);
+ return 0;
+ }
+ break;
+ case 0xe1: /* APP1 */
+ if(buffer[6]!='E' || buffer[7]!='x' || buffer[8]!='i'|| buffer[9]!='f') /* Should be Exif */
+ {
+ header_ignored(file_recovery_new);
+ return 0;
+ }
+ break;
+ case 0xfe: /* COM */
+ if(!isprint(buffer[6]) || !isprint(buffer[7]))
+ {
+ header_ignored(file_recovery_new);
+ return 0;
+ }
+ break;
+ default:
+ header_ignored(file_recovery_new);
+ return 0;
}
}
reset_file_recovery(file_recovery_new);
@@ -888,13 +922,25 @@ static void jpg_term_source (j_decompress_ptr cinfo)
}
+/* WARNING: This function must be listed in clang Control Flow Integrity (CFI) function blacklist, section cfi-icall */
+static void jpeg_testdisk_alloc_src (j_decompress_ptr cinfo, const unsigned int blocksize)
+{
+ my_source_mgr *src= (my_source_mgr *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ sizeof(my_source_mgr));
+ cinfo->src = (struct jpeg_source_mgr *) src;
+ src->buffer = (JOCTET *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ blocksize * sizeof(JOCTET));
+}
+
/*
* Prepare for input from a stdio stream.
* The caller must have already opened the stream, and is responsible
* for closing it after finishing decompression.
*/
-static void jpeg_testdisk_src (j_decompress_ptr cinfo, FILE * infile, uint64_t offset, const unsigned int blocksize)
+static void jpeg_testdisk_src (j_decompress_ptr cinfo, FILE * infile, const uint64_t offset, const unsigned int blocksize)
{
my_source_mgr * src;
@@ -906,13 +952,7 @@ static void jpeg_testdisk_src (j_decompress_ptr cinfo, FILE * infile, uint64_t o
* manager serially with the same JPEG object. Caveat programmer.
*/
if (cinfo->src == NULL) { /* first time for this JPEG object? */
- cinfo->src = (struct jpeg_source_mgr *)
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
- sizeof(my_source_mgr));
- src = (my_source_mgr *) cinfo->src;
- src->buffer = (JOCTET *)
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
- blocksize * sizeof(JOCTET));
+ jpeg_testdisk_alloc_src(cinfo, blocksize);
}
src = (my_source_mgr *) cinfo->src;
@@ -1473,11 +1513,6 @@ static void jpg_check_picture(file_recovery_t *file_recovery)
}
#endif
-/*@
- @ requires i < buffer_size;
- @ requires \valid_read(buffer+(0..buffer_size-1));
- @ assigns \nothing;
- @*/
static int jpg_check_dht(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int i, const unsigned int size)
{
unsigned int j=i+4;
@@ -1541,16 +1576,18 @@ static int jpg_check_sof0(const unsigned char *buffer, const unsigned int buffer
return 0;
{
const struct sof_header *h=(const struct sof_header *)&buffer[i];
- if(be16(h->length) < sizeof(struct sof_header)-2)
+ const unsigned int length=be16(h->length);
+ if(length < sizeof(struct sof_header)-2)
return 1;
}
if(i+2+8 > buffer_size)
return 0;
{
const struct sof_header *h=(const struct sof_header *)&buffer[i];
+ const unsigned int length=be16(h->length);
if(h->precision!=8 || be16(h->width)==0 || h->nbr==0)
return 1;
- if(be16(h->length) < 8+h->nbr*3)
+ if(length < 8+h->nbr*3)
return 1;
}
// if(i+2+be16(h->length) > buffer_size)
@@ -1561,14 +1598,18 @@ static int jpg_check_sof0(const unsigned char *buffer, const unsigned int buffer
/*@
@ requires \valid_read(file_recovery);
@ requires \valid(file_recovery->handle);
- @ requires file_recovery->blocksize <= 1048576;
+ @ requires 0 < file_recovery->blocksize <= 1048576;
@ requires file_recovery->offset_error <= (1<<63) - 1;
+ @ requires separation: \separated(file_recovery, file_recovery->handle, &errno);
@ ensures \valid(file_recovery->handle);
+ @ assigns *file_recovery->handle, errno;
+ @ assigns Frama_C_entropy_source;
+ @ assigns file_recovery->extra;
@*/
static void jpg_search_marker(file_recovery_t *file_recovery)
{
FILE* infile=file_recovery->handle;
- unsigned char buffer[40*8192];
+ char sbuffer[40*8192];
size_t nbytes;
const uint64_t offset_error=file_recovery->offset_error;
uint64_t offset_test=offset_error;
@@ -1582,15 +1623,21 @@ static void jpg_search_marker(file_recovery_t *file_recovery)
/*@ assert offset_test == offset_error; */
/*@
@ loop invariant offset_test >= offset_error;
+ @ loop assigns nbytes, sbuffer[ 0 .. sizeof(sbuffer)-1];
+ @ loop assigns *infile, errno;
+ @ loop assigns Frama_C_entropy_source;
+ @ loop assigns offset, offset_test;
+ @ loop assigns file_recovery->extra;
@*/
- while((nbytes=fread(&buffer, 1, sizeof(buffer), infile))>0)
+ while((nbytes=fread(&sbuffer, 1, sizeof(sbuffer), infile))>0)
{
unsigned int i;
- /*@ assert 0 < nbytes <= sizeof(buffer); */
+ const unsigned char *buffer=(const unsigned char *)sbuffer;
+ /*@ assert 0 < nbytes <= sizeof(sbuffer); */
if(offset_test > 0x80000000)
return ;
#if defined(__FRAMAC__)
- Frama_C_make_unknown((char *)&buffer, sizeof(buffer));
+ Frama_C_make_unknown(&sbuffer, sizeof(sbuffer));
#endif
/*@ assert offset_test >= offset_error; */
offset=offset_test / file_recovery->blocksize * file_recovery->blocksize;
@@ -1639,23 +1686,81 @@ static void jpg_search_marker(file_recovery_t *file_recovery)
}
/*@
+ @ requires \valid_read(file_recovery);
+ @ requires \valid_read(buffer + (0 .. nbytes-1));
+ @ requires thumb_offset < nbytes;
+ @ requires thumb_size > 0;
+ @ requires thumb_offset + thumb_size <= nbytes;
+ @*/
+static void jpg_save_thumbnail(const file_recovery_t *file_recovery, const char *buffer, const uint64_t nbytes, const uint64_t thumb_offset, const unsigned int thumb_size)
+{
+ char thumbname[2048];
+ char *sep;
+ /*@ assert sizeof(thumbname) == sizeof(file_recovery->filename); */
+ /*@ assert valid_read_string((char *)&file_recovery->filename); */
+ memcpy(thumbname,file_recovery->filename, sizeof(thumbname));
+ thumbname[sizeof(thumbname)-1]='\0';
+ /*@ assert valid_read_string(&thumbname[0]); */
+ sep=strrchr(thumbname,'/');
+ if(sep!=NULL
+#ifndef __FRAMAC__
+ && *(sep+1)=='f'
+#endif
+ )
+ {
+ FILE *out;
+#ifndef __FRAMAC__
+ *(sep+1)='t';
+#endif
+ if((out=fopen(thumbname,"wb"))!=NULL)
+ {
+ /*@ assert \valid_read(buffer + (0 .. nbytes - 1)); */
+ /*@ assert 0 <= thumb_offset < nbytes; */
+ /*@ assert \valid_read(buffer + (thumb_offset .. nbytes - 1)); */
+ /*@ assert \valid_read(buffer + thumb_offset + (0 .. nbytes - 1 - thumb_offset)); */
+ /*@ ghost const char *thumb_char=&buffer[thumb_offset]; */
+ /*@ assert \valid_read(thumb_char + (0 .. nbytes - thumb_offset - 1)); */
+ /*@ assert 0 < thumb_size <= nbytes - thumb_offset; */
+ /*@ ghost uint64_t tmp_size=nbytes - thumb_offset; */
+ /*@ assert 0 < thumb_size <= tmp_size; */
+ /*@ assert \valid_read(thumb_char + (0 .. tmp_size - 1)); */
+ /*@ assert \valid_read(thumb_char + (0 .. thumb_size - 1)); */
+ if(fwrite(&buffer[thumb_offset], thumb_size, 1, out) < 1)
+ {
+ log_error("Can't write to %s: %s\n", thumbname, strerror(errno));
+ }
+ fclose(out);
+ if(file_recovery->time!=0 && file_recovery->time!=(time_t)-1)
+ set_date(thumbname, file_recovery->time, file_recovery->time);
+ }
+ else
+ {
+ log_error("fopen %s failed\n", thumbname);
+ }
+ }
+}
+
+/*@
@ requires \valid(file_recovery);
@ requires \valid(file_recovery->handle);
- @ requires \valid(thumb_offset);
+ @ requires \valid(thumb_offset_ptr);
@ requires valid_read_string((char *)&file_recovery->filename);
@ requires file_recovery->blocksize > 0;
+ @ requires nbytes > 4;
@ requires \valid_read(buffer + (0 .. nbytes-1));
@ requires \initialized(&file_recovery->time);
+ @ requires separation: \separated(file_recovery, file_recovery->handle, buffer+(..), thumb_offset_ptr, &errno);
@ ensures \valid(file_recovery->handle);
@*/
-static int jpg_check_app1(file_recovery_t *file_recovery, const unsigned int extract_thumb, const unsigned char *buffer, const unsigned int i, const unsigned int offset, const unsigned int size, const size_t nbytes, uint64_t *thumb_offset)
+static int jpg_check_app1(file_recovery_t *file_recovery, const unsigned int extract_thumb, const unsigned char *buffer, const unsigned int i, const unsigned int offset, const unsigned int size, const uint64_t nbytes, uint64_t *thumb_offset_ptr)
{ /* APP1 Exif information */
const unsigned int tiff_offset=i+2+8;
const unsigned char *potential_error=NULL;
- const unsigned char *thumb_data=NULL;
const unsigned char *tiff;
unsigned int thumb_size=0;
unsigned int tiff_size;
+ uint64_t thumb_offset;
+ *thumb_offset_ptr=0;
if(tiff_offset >= nbytes || size <= 8)
return 1;
/*@ assert tiff_offset < nbytes; */
@@ -1683,40 +1788,65 @@ static int jpg_check_app1(file_recovery_t *file_recovery, const unsigned int ext
/*@ assert \valid_read(tiff+ (0 .. tiff_size-1)); */
file_recovery->time=get_date_from_tiff_header(tiff, tiff_size);
}
- *thumb_offset=find_tag_from_tiff_header(tiff, tiff_size, TIFFTAG_JPEGIFOFFSET, &potential_error);
- if(*thumb_offset!=0)
+ thumb_offset=find_tag_from_tiff_header(tiff, tiff_size, TIFFTAG_JPEGIFOFFSET, &potential_error);
+ if(potential_error!=NULL)
{
- *thumb_offset+=tiff_offset;
- thumb_data=buffer+ (*thumb_offset);
- thumb_size=find_tag_from_tiff_header(tiff, tiff_size, TIFFTAG_JPEGIFBYTECOUNT, &potential_error);
+ file_recovery->offset_error=potential_error-buffer;
+ return 0;
}
+ if(thumb_offset==0)
+ return 1;
+ /*@ assert 0 < thumb_offset; */
+ thumb_offset+=tiff_offset;
+ thumb_size=find_tag_from_tiff_header(tiff, tiff_size, TIFFTAG_JPEGIFBYTECOUNT, &potential_error);
if(potential_error!=NULL)
{
file_recovery->offset_error=potential_error-buffer;
return 0;
}
+ if(thumb_size==0)
+ return 1;
+ /*@ assert 0 < thumb_size; */
+ *thumb_offset_ptr=thumb_offset;
if(file_recovery->offset_ok<i)
file_recovery->offset_ok=i;
- if(thumb_data!=0 && thumb_size!=0 && *thumb_offset < nbytes - 1)
+ if(thumb_offset + 6 >= nbytes)
+ return 1;
+ /*@ assert 0 < thumb_offset < nbytes - 6; */
+ /*@ assert thumb_offset < nbytes; */
{
- unsigned int j=*thumb_offset+2;
+ unsigned int j=thumb_offset+2;
unsigned int thumb_sos_found=0;
#ifdef DEBUG_JPEG
unsigned int j_old=j;
#endif
- if(buffer[*thumb_offset]!=0xff)
+ if(buffer[thumb_offset]!=0xff)
{
- file_recovery->offset_error=*thumb_offset;
+ file_recovery->offset_error=thumb_offset;
jpg_search_marker(file_recovery);
return 0;
}
- if(buffer[*thumb_offset+1]!=0xd8)
+ if(buffer[thumb_offset+1]!=0xd8)
{
- file_recovery->offset_error=*thumb_offset+1;
+ file_recovery->offset_error=thumb_offset+1;
return 0;
}
+ /*@ assert j == thumb_offset + 2; */
+ /*@ assert j < nbytes - 4; */
+ /*@
+ @ loop invariant 0 < thumb_size;
+ @ loop invariant 0 < thumb_offset < nbytes - 1;
+ @*/
+ /*X
+ X loop assigns j, thumb_sos_found;
+ X loop assigns errno, *file_recovery->handle,Frama_C_entropy_source;
+ X loop assigns file_recovery->offset_ok;
+ X loop assigns file_recovery->offset_error;
+ X loop assigns file_recovery->extra;
+ X*/
while(j+4<nbytes && thumb_sos_found==0)
{
+ /*@ assert j + 4 < nbytes; */
if(buffer[j]!=0xff)
{
file_recovery->offset_error=j;
@@ -1737,7 +1867,9 @@ static int jpg_check_app1(file_recovery_t *file_recovery, const unsigned int ext
log_info("%s thumb marker 0x%02x at 0x%x\n", file_recovery->filename, buffer[j+1], j);
#endif
if(buffer[j+1]==0xda) /* Thumb SOS: Start Of Scan */
+ {
thumb_sos_found=1;
+ }
else if(buffer[j+1]==0xc4) /* DHT */
{
if(jpg_check_dht(buffer, nbytes, j, 2+(buffer[j+2]<<8)+buffer[j+3])!=0)
@@ -1759,7 +1891,9 @@ static int jpg_check_app1(file_recovery_t *file_recovery, const unsigned int ext
}
else
{
+#ifndef __FRAMAC__
log_info("%s thumb unknown marker 0x%02x at 0x%x\n", file_recovery->filename, buffer[j+1], j);
+#endif
file_recovery->offset_error=j;
return 0;
}
@@ -1768,54 +1902,26 @@ static int jpg_check_app1(file_recovery_t *file_recovery, const unsigned int ext
#ifdef DEBUG_JPEG
j_old=j;
#endif
- j+=2U+(buffer[j+2]<<8)+buffer[j+3];
- }
- if(thumb_sos_found>0 && extract_thumb>0
- && offset < nbytes && buffer[offset]==0xff &&
- *thumb_offset+thumb_size < nbytes)
- {
- char thumbname[2048];
- char *sep;
- /*@ assert sizeof(thumbname) == sizeof(file_recovery->filename); */
- /*@ assert valid_read_string((char *)&file_recovery->filename); */
- memcpy(thumbname,file_recovery->filename, sizeof(thumbname));
- thumbname[sizeof(thumbname)-1]='\0';
- /*@ assert valid_read_string(&thumbname[0]); */
- sep=strrchr(thumbname,'/');
- if(sep!=NULL
-#ifndef __FRAMAC__
- && *(sep+1)=='f'
-#endif
- )
{
- FILE *out;
-#ifndef __FRAMAC__
- *(sep+1)='t';
-#endif
- if((out=fopen(thumbname,"wb"))!=NULL)
- {
- const char *buffer_char=(const char *)buffer;
- /*@ assert \valid_read(buffer_char + (0 .. nbytes - 1)); */
- /*@ assert *thumb_offset + thumb_size < nbytes; */
- /*@ assert \valid_read(buffer_char + (0 .. *thumb_offset + thumb_size - 1)); */
- /*@ assert \valid_read(buffer_char + *thumb_offset + (0 .. thumb_size - 1)); */
- const char *thumb_char=&buffer_char[*thumb_offset];
- /*@ assert \valid_read(thumb_char + (0 .. thumb_size - 1)); */
- if(fwrite(thumb_char, thumb_size, 1, out) < 1)
- {
- log_error("Can't write to %s: %s\n", thumbname, strerror(errno));
- }
- fclose(out);
- if(file_recovery->time!=0 && file_recovery->time!=(time_t)-1)
- set_date(thumbname, file_recovery->time, file_recovery->time);
- }
- else
- {
- log_error("fopen %s failed\n", thumbname);
- }
+ const unsigned int tmp=(buffer[j+2]<<8)+buffer[j+3];
+ /*@ assert 0 <= tmp <= 65535; */
+ j+=2U+tmp;
}
}
+ if(thumb_sos_found==0)
+ return 1;
}
+ if(extract_thumb==0)
+ return 1;
+ /* APP1 must be followed by a valid marker, this avoids many corrupted thumbnails */
+ if(offset >= nbytes || buffer[offset]!=0xff)
+ return 1;
+ if(thumb_offset+thumb_size > nbytes)
+ return 1;
+ /*@ assert thumb_offset + thumb_size <= nbytes; */
+ /*@ assert 0 < thumb_size; */
+ /*@ assert thumb_offset < nbytes; */
+ jpg_save_thumbnail(file_recovery, (const char *)buffer, nbytes, thumb_offset, thumb_size);
return 1;
}
@@ -1854,19 +1960,12 @@ static uint64_t jpg_check_structure(file_recovery_t *file_recovery, const unsign
}
}
offset=2;
- while(offset + 4 < nbytes && (file_recovery->offset_error==0 || offset < file_recovery->offset_error))
+ while(offset + 4 < nbytes && buffer[offset]==0xff && is_marker_valid(buffer[offset+1]) && (file_recovery->offset_error==0 || offset < file_recovery->offset_error))
{
const unsigned int i=offset;
+ /*@ assert i + 4 < nbytes; */
+ /*@ assert i < nbytes; */
const unsigned int size=(buffer[i+2]<<8)+buffer[i+3];
- if(buffer[i]!=0xff)
- {
-#if defined(DEBUG_JPEG)
- log_info("%s no marker at 0x%x\n", file_recovery->filename, i);
-#endif
- file_recovery->offset_error=i;
- jpg_search_marker(file_recovery);
- return thumb_offset;
- }
if(buffer[i+1]==0xff)
{
/* See B.1.1.2 Markers in http://www.w3.org/Graphics/JPEG/itu-t81.pdf*/
@@ -1877,12 +1976,7 @@ static uint64_t jpg_check_structure(file_recovery_t *file_recovery, const unsign
log_info("%s marker 0x%02x at 0x%x\n", file_recovery->filename, buffer[i+1], i);
#endif
offset+=(uint64_t)2+size;
- if(buffer[i+1]==0xda) /* SOS: Start Of Scan */
- {
- file_recovery->offset_ok=i+1;
- return thumb_offset;
- }
- else if(buffer[i+1]==0xe1)
+ if(buffer[i+1]==0xe1)
{ /* APP1 Exif information */
if(jpg_check_app1(file_recovery, extract_thumb, buffer, i, offset, size, nbytes, &thumb_offset)==0)
return 0;
@@ -1894,26 +1988,26 @@ static uint64_t jpg_check_structure(file_recovery_t *file_recovery, const unsign
file_recovery->offset_error=i+2;
return thumb_offset;
}
- if(file_recovery->offset_ok<i+1)
- file_recovery->offset_ok=i+1;
- }
- else if(buffer[i+1]==0xdb || /* DQT */
- (buffer[i+1]>=0xc0 && buffer[i+1]<=0xcf) || /* SOF0 - SOF15 */
- buffer[i+1]==0xdd || /* DRI */
- (buffer[i+1]>=0xe0 && buffer[i+1]<=0xef) || /* APP0 - APP15 */
- buffer[i+1]==0xfe) /* COM */
- {
- if(file_recovery->offset_ok<i+1)
- file_recovery->offset_ok=i+1;
}
- else
- {
-#ifndef __FRAMAC__
- log_info("%s unknown marker 0x%02x at 0x%x\n", file_recovery->filename, buffer[i+1], i+1);
+ if(file_recovery->offset_ok<i+1)
+ file_recovery->offset_ok=i+1;
+ }
+ if(offset < nbytes && buffer[offset]!=0xff)
+ {
+#if defined(DEBUG_JPEG)
+ log_info("%s no marker at 0x%x\n", file_recovery->filename, offset);
#endif
- file_recovery->offset_error=i+1;
- return thumb_offset;
- }
+ file_recovery->offset_error=offset;
+ jpg_search_marker(file_recovery);
+ return thumb_offset;
+ }
+ if(offset + 4 < nbytes)
+ {
+ if(buffer[offset+1]==0xda) /* SOS: Start Of Scan */
+ file_recovery->offset_ok=offset+1;
+ else
+ file_recovery->offset_error=offset+1;
+ return thumb_offset;
}
if(offset > nbytes && nbytes < sizeof(buffer))
{
@@ -2005,6 +2099,7 @@ static void file_check_jpg(file_recovery_t *file_recovery)
@ requires file_recovery->calculated_file_size >= 2;
@ requires \valid_read(buffer + ( 0 .. buffer_size-1));
@ requires file_recovery->data_check == &data_check_jpg2;
+ @ requires separation: \separated(buffer+(..), file_recovery);
@ ensures \result == DC_CONTINUE || \result == DC_STOP;
@ ensures file_recovery->data_check == &data_check_jpg2 || file_recovery->data_check == \null;
@ ensures file_recovery->data_check == &data_check_jpg2 ==> file_recovery->calculated_file_size >= 2;
@@ -2016,6 +2111,7 @@ static void file_check_jpg(file_recovery_t *file_recovery)
static data_check_t data_check_jpg2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
/*@
+ @ loop invariant file_recovery->data_check == \null ==> file_recovery->calculated_file_size == 0;
@ loop assigns file_recovery->calculated_file_size;
@ loop assigns file_recovery->data_check;
@ loop assigns file_recovery->offset_error;
@@ -2032,6 +2128,8 @@ static data_check_t data_check_jpg2(const unsigned char *buffer, const unsigned
/* JPEG_EOI */
file_recovery->calculated_file_size++;
/*@ assert file_recovery->data_check == &data_check_jpg2; */
+ /*@ assert file_recovery->calculated_file_size >= 2; */
+ /*@ assert file_recovery->data_check == \null ==> file_recovery->calculated_file_size == 0; */
return DC_STOP;
}
else if(buffer[i] >= 0xd0 && buffer[i] <= 0xd7)
@@ -2051,12 +2149,16 @@ static data_check_t data_check_jpg2(const unsigned char *buffer, const unsigned
old_marker=buffer[i];
#endif
/*@ assert file_recovery->data_check == &data_check_jpg2; */
+ /*@ assert file_recovery->calculated_file_size >= 2; */
}
else if(buffer[i] == 0xda || buffer[i] == 0xc4)
{
/* SOS and DHT may be embedded by progressive jpg */
file_recovery->data_check=NULL;
file_recovery->calculated_file_size=0;
+ /*@ assert file_recovery->data_check == \null; */
+ /*@ assert file_recovery->calculated_file_size == 0; */
+ /*@ assert file_recovery->data_check == \null ==> file_recovery->calculated_file_size == 0; */
return DC_CONTINUE;
}
else if(buffer[i]!=0x00)
@@ -2067,12 +2169,17 @@ static data_check_t data_check_jpg2(const unsigned char *buffer, const unsigned
#endif
file_recovery->offset_error=file_recovery->calculated_file_size;
/*@ assert file_recovery->data_check == &data_check_jpg2; */
+ /*@ assert file_recovery->calculated_file_size >= 2; */
+ /*@ assert file_recovery->data_check == \null ==> file_recovery->calculated_file_size == 0; */
return DC_STOP;
}
}
/*@ assert file_recovery->data_check == &data_check_jpg2; */
file_recovery->calculated_file_size++;
}
+ /*@ assert file_recovery->data_check == &data_check_jpg2; */
+ /*@ assert file_recovery->calculated_file_size >= 2; */
+ /*@ assert file_recovery->data_check == \null ==> file_recovery->calculated_file_size == 0; */
return DC_CONTINUE;
}
@@ -2083,6 +2190,7 @@ static data_check_t data_check_jpg2(const unsigned char *buffer, const unsigned
@ requires buffer_size >= 4;
@ requires \valid_read(buffer + ( 0 .. buffer_size-1));
@ requires file_recovery->data_check == &data_check_jpg;
+ @ requires separation: \separated(buffer+(..), file_recovery);
@ ensures \result == DC_CONTINUE || \result == DC_STOP;
@ ensures file_recovery->data_check == &data_check_jpg2 || file_recovery->data_check == &data_check_jpg || file_recovery->data_check == &data_check_size || file_recovery->data_check == \null;
@ ensures file_recovery->data_check == &data_check_jpg2 ==> file_recovery->calculated_file_size >= 2;
@@ -2260,6 +2368,7 @@ static void register_header_check_jpg(file_stat_t *file_stat)
static const unsigned char jpg_header[3]= { 0xff,0xd8,0xff};
register_header_check(0, jpg_header, sizeof(jpg_header), &header_check_jpg, file_stat);
}
+#endif
#if defined(MAIN_jpg)
#define BLOCKSIZE 65536u
diff --git a/src/file_jsonlz4.c b/src/file_jsonlz4.c
index 8d3390e..0035816 100644
--- a/src/file_jsonlz4.c
+++ b/src/file_jsonlz4.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_jsonlz4)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,3 +60,4 @@ static void register_header_check_jsonlz4(file_stat_t *file_stat)
{
register_header_check(0, "mozLz40", 8, &header_check_jsonlz4, file_stat);
}
+#endif
diff --git a/src/file_kdb.c b/src/file_kdb.c
index 5f07b82..3b37bab 100644
--- a/src/file_kdb.c
+++ b/src/file_kdb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_kdb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_kdb(file_stat_t *file_stat)
static const unsigned char kdb_header[8]= {0x03, 0xd9, 0xa2, 0x9a, 0x65, 0xfb, 0x4b, 0xb5};
register_header_check(0, kdb_header,sizeof(kdb_header), &header_check_kdb, file_stat);
}
+#endif
diff --git a/src/file_kdbx.c b/src/file_kdbx.c
index c47e3ca..f388137 100644
--- a/src/file_kdbx.c
+++ b/src/file_kdbx.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_kdbx)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_kdbx(file_stat_t *file_stat)
static const unsigned char kdbx_header[8]= {0x03, 0xd9, 0xa2, 0x9a, 0x67, 0xfb, 0x4b, 0xb5};
register_header_check(0, kdbx_header,sizeof(kdbx_header), &header_check_kdbx, file_stat);
}
+#endif
diff --git a/src/file_key.c b/src/file_key.c
index 8a396a9..534685f 100644
--- a/src/file_key.c
+++ b/src/file_key.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_key)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_key(file_stat_t *file_stat)
{
register_header_check(0, "323382b3c4f1c6d2", 16, &header_check_key, file_stat);
}
+#endif
diff --git a/src/file_ldf.c b/src/file_ldf.c
index e3acfe5..937120b 100644
--- a/src/file_ldf.c
+++ b/src/file_ldf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ldf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -65,3 +66,4 @@ static int header_check_ldf(const unsigned char *buffer, const unsigned int buff
}
return 0;
}
+#endif
diff --git a/src/file_list.c b/src/file_list.c
index 6e3685a..36dc8b6 100644
--- a/src/file_list.c
+++ b/src/file_list.c
@@ -24,11 +24,13 @@
#endif
#include <stdio.h>
+#include <assert.h>
#include "types.h"
#include "filegen.h"
extern const file_hint_t file_hint_1cd;
extern const file_hint_t file_hint_3dm;
+extern const file_hint_t file_hint_3ds;
extern const file_hint_t file_hint_7z;
extern const file_hint_t file_hint_DB;
extern const file_hint_t file_hint_a;
@@ -60,6 +62,7 @@ extern const file_hint_t file_hint_axx;
extern const file_hint_t file_hint_bac;
extern const file_hint_t file_hint_bdm;
extern const file_hint_t file_hint_berkeley;
+extern const file_hint_t file_hint_bfa;
extern const file_hint_t file_hint_bim;
extern const file_hint_t file_hint_bin;
extern const file_hint_t file_hint_binvox;
@@ -205,6 +208,7 @@ extern const file_hint_t file_hint_mb;
extern const file_hint_t file_hint_mcd;
extern const file_hint_t file_hint_mdb;
extern const file_hint_t file_hint_mdf;
+extern const file_hint_t file_hint_mdp;
extern const file_hint_t file_hint_mfa;
extern const file_hint_t file_hint_mfg;
extern const file_hint_t file_hint_mft;
@@ -366,346 +370,1047 @@ extern const file_hint_t file_hint_zpr;
file_enable_t array_file_enable[]=
{
-#ifndef MAIN_fidentify
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sig)
{ .enable=0, .file_hint=&file_hint_sig },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_1cd)
{ .enable=0, .file_hint=&file_hint_1cd },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_3dm)
{ .enable=0, .file_hint=&file_hint_3dm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_3ds)
+ { .enable=0, .file_hint=&file_hint_3ds },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_7z)
{ .enable=0, .file_hint=&file_hint_7z },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_DB)
{ .enable=0, .file_hint=&file_hint_DB },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_a)
{ .enable=0, .file_hint=&file_hint_a },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_abr)
{ .enable=0, .file_hint=&file_hint_abr },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_acb)
{ .enable=0, .file_hint=&file_hint_acb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_accdb)
{ .enable=0, .file_hint=&file_hint_accdb},
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ace)
{ .enable=0, .file_hint=&file_hint_ace },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_addressbook)
{ .enable=0, .file_hint=&file_hint_addressbook},
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ado)
{ .enable=0, .file_hint=&file_hint_ado },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_afdesign)
{ .enable=0, .file_hint=&file_hint_afdesign },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ahn)
{ .enable=0, .file_hint=&file_hint_ahn },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_aif)
{ .enable=0, .file_hint=&file_hint_aif },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_all)
{ .enable=0, .file_hint=&file_hint_all },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_als)
{ .enable=0, .file_hint=&file_hint_als },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_amd)
{ .enable=0, .file_hint=&file_hint_amd },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_amr)
{ .enable=0, .file_hint=&file_hint_amr },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_apa)
{ .enable=0, .file_hint=&file_hint_apa },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ape)
{ .enable=0, .file_hint=&file_hint_ape },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_apple)
{ .enable=0, .file_hint=&file_hint_apple },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ari)
{ .enable=0, .file_hint=&file_hint_ari },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_arj)
{ .enable=0, .file_hint=&file_hint_arj },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_asf)
{ .enable=0, .file_hint=&file_hint_asf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_asl)
{ .enable=0, .file_hint=&file_hint_asl },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_asm)
{ .enable=0, .file_hint=&file_hint_asm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_atd)
{ .enable=0, .file_hint=&file_hint_atd },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_au)
{ .enable=0, .file_hint=&file_hint_au },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_axp)
{ .enable=0, .file_hint=&file_hint_axp },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_axx)
{ .enable=0, .file_hint=&file_hint_axx },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bac)
{ .enable=0, .file_hint=&file_hint_bac },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bdm)
{ .enable=0, .file_hint=&file_hint_bdm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_berkeley)
{ .enable=0, .file_hint=&file_hint_berkeley },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bfa)
+ { .enable=0, .file_hint=&file_hint_bfa },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bim)
{ .enable=0, .file_hint=&file_hint_bim },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bin)
{ .enable=0, .file_hint=&file_hint_bin },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_binvox)
{ .enable=0, .file_hint=&file_hint_binvox },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bkf)
{ .enable=0, .file_hint=&file_hint_bkf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_blend)
{ .enable=0, .file_hint=&file_hint_blend },
#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bmp)
{ .enable=0, .file_hint=&file_hint_bmp },
-#ifndef MAIN_fidentify
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bpg)
{ .enable=0, .file_hint=&file_hint_bpg },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bvr)
{ .enable=0, .file_hint=&file_hint_bvr },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_bz2)
{ .enable=0, .file_hint=&file_hint_bz2 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_c4d)
{ .enable=0, .file_hint=&file_hint_c4d },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cab)
{ .enable=0, .file_hint=&file_hint_cab },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_caf)
{ .enable=0, .file_hint=&file_hint_caf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cam)
{ .enable=0, .file_hint=&file_hint_cam },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_catdrawing)
{ .enable=0, .file_hint=&file_hint_catdrawing },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cdt)
{ .enable=0, .file_hint=&file_hint_cdt },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_che)
{ .enable=0, .file_hint=&file_hint_che },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_chm)
{ .enable=0, .file_hint=&file_hint_chm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_class)
{ .enable=0, .file_hint=&file_hint_class },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cm)
{ .enable=0, .file_hint=&file_hint_cm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_compress)
{ .enable=0, .file_hint=&file_hint_compress },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cow)
{ .enable=0, .file_hint=&file_hint_cow },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cpi)
{ .enable=0, .file_hint=&file_hint_cpi },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_crw)
{ .enable=0, .file_hint=&file_hint_crw },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_csh)
{ .enable=0, .file_hint=&file_hint_csh },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ctg)
{ .enable=0, .file_hint=&file_hint_ctg },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_cwk)
{ .enable=0, .file_hint=&file_hint_cwk },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_d2s)
{ .enable=0, .file_hint=&file_hint_d2s },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dad)
{ .enable=0, .file_hint=&file_hint_dad },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dar)
{ .enable=0, .file_hint=&file_hint_dar },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dat)
{ .enable=0, .file_hint=&file_hint_dat },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dbf)
{ .enable=0, .file_hint=&file_hint_dbf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dbn)
{ .enable=0, .file_hint=&file_hint_dbn },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dcm)
{ .enable=0, .file_hint=&file_hint_dcm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ddf)
{ .enable=0, .file_hint=&file_hint_ddf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dex)
{ .enable=0, .file_hint=&file_hint_dex },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dim)
{ .enable=0, .file_hint=&file_hint_dim },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dir)
{ .enable=0, .file_hint=&file_hint_dir },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_djv)
{ .enable=0, .file_hint=&file_hint_djv },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dmp)
{ .enable=0, .file_hint=&file_hint_dmp },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_drw)
{ .enable=0, .file_hint=&file_hint_drw },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_doc)
{ .enable=0, .file_hint=&file_hint_doc },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dpx)
{ .enable=0, .file_hint=&file_hint_dpx },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ds2)
{ .enable=0, .file_hint=&file_hint_ds2 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ds_store)
{ .enable=0, .file_hint=&file_hint_ds_store },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dsc)
{ .enable=0, .file_hint=&file_hint_dsc },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dss)
{ .enable=0, .file_hint=&file_hint_dss },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dst)
{ .enable=0, .file_hint=&file_hint_dst },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dta)
{ .enable=0, .file_hint=&file_hint_dta },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dump)
{ .enable=0, .file_hint=&file_hint_dump },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dv)
{ .enable=0, .file_hint=&file_hint_dv },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dvi)
{ .enable=0, .file_hint=&file_hint_dvi },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dvr)
{ .enable=0, .file_hint=&file_hint_dvr },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dwg)
{ .enable=0, .file_hint=&file_hint_dwg },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dxf)
{ .enable=0, .file_hint=&file_hint_dxf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_e01)
{ .enable=0, .file_hint=&file_hint_e01 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ecryptfs)
{ .enable=0, .file_hint=&file_hint_ecryptfs },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_edb)
{ .enable=0, .file_hint=&file_hint_edb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_elf)
{ .enable=0, .file_hint=&file_hint_elf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_emf)
{ .enable=0, .file_hint=&file_hint_emf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ess)
{ .enable=0, .file_hint=&file_hint_ess },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_evt)
{ .enable=0, .file_hint=&file_hint_evt },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_evtx)
{ .enable=0, .file_hint=&file_hint_evtx },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_exe)
{ .enable=0, .file_hint=&file_hint_exe },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_exr)
{ .enable=0, .file_hint=&file_hint_exr },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_exs)
{ .enable=0, .file_hint=&file_hint_exs },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ext2_sb)
{ .enable=0, .file_hint=&file_hint_ext2_sb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ext2_fs)
{ .enable=0, .file_hint=&file_hint_ext2_fs },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fat)
{ .enable=0, .file_hint=&file_hint_fat },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fbf)
{ .enable=0, .file_hint=&file_hint_fbf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fbk)
{ .enable=0, .file_hint=&file_hint_fbk },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fcp)
{ .enable=0, .file_hint=&file_hint_fcp },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fcs)
{ .enable=0, .file_hint=&file_hint_fcs },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fdb)
{ .enable=0, .file_hint=&file_hint_fdb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fds)
{ .enable=0, .file_hint=&file_hint_fds },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fh10)
{ .enable=0, .file_hint=&file_hint_fh10 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fh5)
{ .enable=0, .file_hint=&file_hint_fh5 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_filevault)
{ .enable=0, .file_hint=&file_hint_filevault },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fits)
{ .enable=0, .file_hint=&file_hint_fits },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fit)
{ .enable=0, .file_hint=&file_hint_fit },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_flac)
{ .enable=0, .file_hint=&file_hint_flac },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_flp)
{ .enable=0, .file_hint=&file_hint_flp },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_flv)
{ .enable=0, .file_hint=&file_hint_flv },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fm)
{ .enable=0, .file_hint=&file_hint_fm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fob)
{ .enable=0, .file_hint=&file_hint_fob },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fos)
{ .enable=0, .file_hint=&file_hint_fos },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fp5)
{ .enable=0, .file_hint=&file_hint_fp5 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fp7)
{ .enable=0, .file_hint=&file_hint_fp7 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_freeway)
{ .enable=0, .file_hint=&file_hint_freeway },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_frm)
{ .enable=0, .file_hint=&file_hint_frm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fs)
{ .enable=0, .file_hint=&file_hint_fs },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fwd)
{ .enable=0, .file_hint=&file_hint_fwd },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gam)
{ .enable=0, .file_hint=&file_hint_gam },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gct)
{ .enable=0, .file_hint=&file_hint_gct },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gho)
{ .enable=0, .file_hint=&file_hint_gho },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gi)
{ .enable=0, .file_hint=&file_hint_gi },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gif)
{ .enable=0, .file_hint=&file_hint_gif },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gm6)
{ .enable=0, .file_hint=&file_hint_gm6 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gp2)
{ .enable=0, .file_hint=&file_hint_gp2 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gp5)
{ .enable=0, .file_hint=&file_hint_gp5 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gpg)
{ .enable=0, .file_hint=&file_hint_gpg },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gpx)
{ .enable=0, .file_hint=&file_hint_gpx },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gsm)
{ .enable=0, .file_hint=&file_hint_gsm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_gz)
{ .enable=0, .file_hint=&file_hint_gz },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hdf)
{ .enable=0, .file_hint=&file_hint_hdf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hdr)
{ .enable=0, .file_hint=&file_hint_hdr },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hds)
{ .enable=0, .file_hint=&file_hint_hds },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hfsp)
{ .enable=0, .file_hint=&file_hint_hfsp },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hm)
{ .enable=0, .file_hint=&file_hint_hm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hr9)
{ .enable=0, .file_hint=&file_hint_hr9 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_http)
{ .enable=0, .file_hint=&file_hint_http },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ibd)
{ .enable=0, .file_hint=&file_hint_ibd },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_icc)
{ .enable=0, .file_hint=&file_hint_icc },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_icns)
{ .enable=0, .file_hint=&file_hint_icns },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ico)
{ .enable=0, .file_hint=&file_hint_ico },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_idx)
{ .enable=0, .file_hint=&file_hint_idx },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ifo)
{ .enable=0, .file_hint=&file_hint_ifo },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_imb)
{ .enable=0, .file_hint=&file_hint_imb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_indd)
{ .enable=0, .file_hint=&file_hint_indd },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_info)
{ .enable=0, .file_hint=&file_hint_info },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_iso)
{ .enable=0, .file_hint=&file_hint_iso },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_it)
{ .enable=0, .file_hint=&file_hint_it },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_itunes)
{ .enable=0, .file_hint=&file_hint_itunes },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_jks)
{ .enable=0, .file_hint=&file_hint_jks },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_jpg)
{ .enable=0, .file_hint=&file_hint_jpg },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_jsonlz4)
{ .enable=0, .file_hint=&file_hint_jsonlz4 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_kdb)
{ .enable=0, .file_hint=&file_hint_kdb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_kdbx)
{ .enable=0, .file_hint=&file_hint_kdbx },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_key)
{ .enable=0, .file_hint=&file_hint_key },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ldf)
{ .enable=0, .file_hint=&file_hint_ldf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lit)
{ .enable=0, .file_hint=&file_hint_lit },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_logic)
{ .enable=0, .file_hint=&file_hint_logic},
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lnk)
{ .enable=0, .file_hint=&file_hint_lnk },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lso)
{ .enable=0, .file_hint=&file_hint_lso },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_luks)
{ .enable=0, .file_hint=&file_hint_luks },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lxo)
{ .enable=0, .file_hint=&file_hint_lxo },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lzh)
{ .enable=0, .file_hint=&file_hint_lzh },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lzo)
{ .enable=0, .file_hint=&file_hint_lzo },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_m2ts)
{ .enable=0, .file_hint=&file_hint_m2ts },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mat)
{ .enable=0, .file_hint=&file_hint_mat },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_max)
{ .enable=0, .file_hint=&file_hint_max },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mb)
{ .enable=0, .file_hint=&file_hint_mb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mcd)
{ .enable=0, .file_hint=&file_hint_mcd },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mdb)
{ .enable=0, .file_hint=&file_hint_mdb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mdf)
{ .enable=0, .file_hint=&file_hint_mdf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mdp)
+ { .enable=0, .file_hint=&file_hint_mdp },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mfa)
{ .enable=0, .file_hint=&file_hint_mfa },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mfg)
{ .enable=0, .file_hint=&file_hint_mfg },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mft)
{ .enable=0, .file_hint=&file_hint_mft },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mid)
{ .enable=0, .file_hint=&file_hint_mid },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mig)
{ .enable=0, .file_hint=&file_hint_mig },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mk5)
{ .enable=0, .file_hint=&file_hint_mk5 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mkv)
{ .enable=0, .file_hint=&file_hint_mkv },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mlv)
{ .enable=0, .file_hint=&file_hint_mlv },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mobi)
{ .enable=0, .file_hint=&file_hint_mobi },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mov_mdat)
{ .enable=0, .file_hint=&file_hint_mov_mdat },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mov)
{ .enable=0, .file_hint=&file_hint_mov },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mp3)
{ .enable=0, .file_hint=&file_hint_mp3 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mpg)
{ .enable=0, .file_hint=&file_hint_mpg },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mpl)
{ .enable=0, .file_hint=&file_hint_mpl },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mrw)
{ .enable=0, .file_hint=&file_hint_mrw },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_msa)
{ .enable=0, .file_hint=&file_hint_msa },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mus)
{ .enable=0, .file_hint=&file_hint_mus },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_myo)
{ .enable=0, .file_hint=&file_hint_myo },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mysql)
{ .enable=0, .file_hint=&file_hint_mysql },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mxf)
{ .enable=0, .file_hint=&file_hint_mxf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_nd2)
{ .enable=0, .file_hint=&file_hint_nd2 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_nds)
{ .enable=0, .file_hint=&file_hint_nds },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_nes)
{ .enable=0, .file_hint=&file_hint_nes },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_njx)
{ .enable=0, .file_hint=&file_hint_njx },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_nk2)
{ .enable=0, .file_hint=&file_hint_nk2 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_nsf)
{ .enable=0, .file_hint=&file_hint_nsf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_oci)
{ .enable=0, .file_hint=&file_hint_oci },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ogg)
{ .enable=0, .file_hint=&file_hint_ogg },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_one)
{ .enable=0, .file_hint=&file_hint_one },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_orf)
{ .enable=0, .file_hint=&file_hint_orf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_paf)
{ .enable=0, .file_hint=&file_hint_paf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pap)
{ .enable=0, .file_hint=&file_hint_pap },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_par2)
{ .enable=0, .file_hint=&file_hint_par2 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pcap)
{ .enable=0, .file_hint=&file_hint_pcap },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pcb)
{ .enable=0, .file_hint=&file_hint_pcb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pct)
{ .enable=0, .file_hint=&file_hint_pct },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pcx)
{ .enable=0, .file_hint=&file_hint_pcx },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pdb)
{ .enable=0, .file_hint=&file_hint_pdb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pdf)
{ .enable=0, .file_hint=&file_hint_pdf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pds)
{ .enable=0, .file_hint=&file_hint_pds },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pf)
{ .enable=0, .file_hint=&file_hint_pf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pfx)
{ .enable=0, .file_hint=&file_hint_pfx },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pgdump)
{ .enable=0, .file_hint=&file_hint_pgdump },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_plist)
{ .enable=0, .file_hint=&file_hint_plist },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_plr)
{ .enable=0, .file_hint=&file_hint_plr },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_plt)
{ .enable=0, .file_hint=&file_hint_plt },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_png)
{ .enable=0, .file_hint=&file_hint_png },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pnm)
{ .enable=0, .file_hint=&file_hint_pnm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_prc)
{ .enable=0, .file_hint=&file_hint_prc },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_prd)
{ .enable=0, .file_hint=&file_hint_prd },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_prt)
{ .enable=0, .file_hint=&file_hint_prt },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ps)
{ .enable=0, .file_hint=&file_hint_ps },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_psb)
{ .enable=0, .file_hint=&file_hint_psb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_psd)
{ .enable=0, .file_hint=&file_hint_psd },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_psf)
{ .enable=0, .file_hint=&file_hint_psf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_psp)
{ .enable=0, .file_hint=&file_hint_psp },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pst)
{ .enable=0, .file_hint=&file_hint_pst },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ptb)
{ .enable=0, .file_hint=&file_hint_ptb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ptf)
{ .enable=0, .file_hint=&file_hint_ptf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pyc)
{ .enable=0, .file_hint=&file_hint_pyc },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pzf)
{ .enable=0, .file_hint=&file_hint_pzf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pzh)
{ .enable=0, .file_hint=&file_hint_pzh },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_qbb)
{ .enable=0, .file_hint=&file_hint_qbb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_qdf)
{ .enable=0, .file_hint=&file_hint_qdf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_qkt)
{ .enable=0, .file_hint=&file_hint_qkt },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_qxd)
{ .enable=0, .file_hint=&file_hint_qxd },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_r3d)
{ .enable=0, .file_hint=&file_hint_r3d },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ra)
{ .enable=0, .file_hint=&file_hint_ra },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_raf)
{ .enable=0, .file_hint=&file_hint_raf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rar)
{ .enable=0, .file_hint=&file_hint_rar },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_raw)
{ .enable=0, .file_hint=&file_hint_raw },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rdc)
{ .enable=0, .file_hint=&file_hint_rdc },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_reg)
{ .enable=0, .file_hint=&file_hint_reg },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_res)
{ .enable=0, .file_hint=&file_hint_res },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rfp)
{ .enable=0, .file_hint=&file_hint_rfp },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_riff)
{ .enable=0, .file_hint=&file_hint_riff },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rlv)
{ .enable=0, .file_hint=&file_hint_rlv },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rm)
{ .enable=0, .file_hint=&file_hint_rm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rns)
{ .enable=0, .file_hint=&file_hint_rns },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rpm)
{ .enable=0, .file_hint=&file_hint_rpm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rw2)
{ .enable=0, .file_hint=&file_hint_rw2 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rx2)
{ .enable=0, .file_hint=&file_hint_rx2 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_save)
{ .enable=0, .file_hint=&file_hint_save },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sdsk)
{ .enable=0, .file_hint=&file_hint_sdsk },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ses)
{ .enable=0, .file_hint=&file_hint_ses },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sgcta)
{ .enable=0, .file_hint=&file_hint_sgcta },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_shn)
{ .enable=0, .file_hint=&file_hint_shn },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sib)
{ .enable=0, .file_hint=&file_hint_sib },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sit)
{ .enable=0, .file_hint=&file_hint_sit },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_skd)
{ .enable=0, .file_hint=&file_hint_skd },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_skp)
{ .enable=0, .file_hint=&file_hint_skp },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_snag)
{ .enable=0, .file_hint=&file_hint_snag },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_snz)
{ .enable=0, .file_hint=&file_hint_snz },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sp3)
{ .enable=0, .file_hint=&file_hint_sp3 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_spe)
{ .enable=0, .file_hint=&file_hint_spe },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_spf)
{ .enable=0, .file_hint=&file_hint_spf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_spss)
{ .enable=0, .file_hint=&file_hint_spss },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sqlite)
{ .enable=0, .file_hint=&file_hint_sqlite },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sqm)
{ .enable=0, .file_hint=&file_hint_sqm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_steuer2014)
{ .enable=0, .file_hint=&file_hint_steuer2014 },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_stl)
{ .enable=0, .file_hint=&file_hint_stl },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_studio)
{ .enable=0, .file_hint=&file_hint_studio },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_stuffit)
{ .enable=0, .file_hint=&file_hint_stuffit },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_swf)
{ .enable=0, .file_hint=&file_hint_swf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tar)
{ .enable=0, .file_hint=&file_hint_tar },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tax)
{ .enable=0, .file_hint=&file_hint_tax },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tg)
{ .enable=0, .file_hint=&file_hint_tg },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tib)
{ .enable=0, .file_hint=&file_hint_tib },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tiff)
{ .enable=0, .file_hint=&file_hint_tiff },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tivo)
{ .enable=0, .file_hint=&file_hint_tivo },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_torrent)
{ .enable=0, .file_hint=&file_hint_torrent },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tph)
{ .enable=0, .file_hint=&file_hint_tph },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tpl)
{ .enable=0, .file_hint=&file_hint_tpl },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ts)
{ .enable=0, .file_hint=&file_hint_ts },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ttf)
{ .enable=0, .file_hint=&file_hint_ttf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fasttxt)
{ .enable=0, .file_hint=&file_hint_fasttxt },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_txt)
{ .enable=0, .file_hint=&file_hint_txt },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tz)
{ .enable=0, .file_hint=&file_hint_tz },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_v2i)
{ .enable=0, .file_hint=&file_hint_v2i },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vault)
{ .enable=0, .file_hint=&file_hint_vault },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vdj)
{ .enable=0, .file_hint=&file_hint_vdj },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vfb)
{ .enable=0, .file_hint=&file_hint_vfb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vdi)
{ .enable=0, .file_hint=&file_hint_vdi },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_veg)
{ .enable=0, .file_hint=&file_hint_veg },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vib)
{ .enable=0, .file_hint=&file_hint_vib },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vmdk)
{ .enable=0, .file_hint=&file_hint_vmdk },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vmg)
{ .enable=0, .file_hint=&file_hint_vmg },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wallet)
{ .enable=0, .file_hint=&file_hint_wallet },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wdp)
{ .enable=0, .file_hint=&file_hint_wdp },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wee)
{ .enable=0, .file_hint=&file_hint_wee },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wim)
{ .enable=0, .file_hint=&file_hint_wim },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_win)
{ .enable=0, .file_hint=&file_hint_win },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wks)
{ .enable=0, .file_hint=&file_hint_wks },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wld)
{ .enable=0, .file_hint=&file_hint_wld },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wmf)
{ .enable=0, .file_hint=&file_hint_wmf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wnk)
{ .enable=0, .file_hint=&file_hint_wnk },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_woff)
{ .enable=0, .file_hint=&file_hint_woff },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wpb)
{ .enable=0, .file_hint=&file_hint_wpb },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wpd)
{ .enable=0, .file_hint=&file_hint_wpd },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wtv)
{ .enable=0, .file_hint=&file_hint_wtv },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wv)
{ .enable=0, .file_hint=&file_hint_wv },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_x3f)
{ .enable=0, .file_hint=&file_hint_x3f },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_x3i)
{ .enable=0, .file_hint=&file_hint_x3i },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_x4a)
{ .enable=0, .file_hint=&file_hint_x4a },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xar)
{ .enable=0, .file_hint=&file_hint_xar },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xcf)
{ .enable=0, .file_hint=&file_hint_xcf },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xfi)
{ .enable=0, .file_hint=&file_hint_xfi },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xfs)
{ .enable=0, .file_hint=&file_hint_xfs },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xm)
{ .enable=0, .file_hint=&file_hint_xm },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xml)
{ .enable=0, .file_hint=&file_hint_xml },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xsv)
{ .enable=0, .file_hint=&file_hint_xsv },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xpt)
{ .enable=0, .file_hint=&file_hint_xpt },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xv)
{ .enable=0, .file_hint=&file_hint_xv },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xz)
{ .enable=0, .file_hint=&file_hint_xz },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_z2d)
{ .enable=0, .file_hint=&file_hint_z2d },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_zcode)
{ .enable=0, .file_hint=&file_hint_zcode },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_zip)
{ .enable=0, .file_hint=&file_hint_zip },
+#endif
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_zpr)
{ .enable=0, .file_hint=&file_hint_zpr },
#endif
{ .enable=0, .file_hint=NULL }
};
+#ifdef SINGLE_FORMAT
+#ifdef __OPTIMIZE__
+#define __compiletime_error(message) __attribute__((__error__(message)))
+# define __compiletime_assert(condition, msg, prefix, suffix) \
+ do { \
+ extern void prefix ## suffix(void) __compiletime_error(msg); \
+ if (!(condition)) \
+ prefix ## suffix(); \
+ } while (0)
+#else
+# define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0)
+#endif
+
+#define _compiletime_assert(condition, msg, prefix, suffix) \
+ __compiletime_assert(condition, msg, prefix, suffix)
+
+#define compiletime_assert(condition, msg) \
+ _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
+
+static void check_array_file_enable()
+{
+ compiletime_assert(sizeof(file_enable_t) != sizeof(array_file_enable), "No file format has been enabled");
+}
+#endif
diff --git a/src/file_lit.c b/src/file_lit.c
index e0db1ab..8b2095d 100644
--- a/src/file_lit.c
+++ b/src/file_lit.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lit)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -57,3 +58,4 @@ static void register_header_check_lit(file_stat_t *file_stat)
};
register_header_check(0, lit_header, sizeof(lit_header), &header_check_lit, file_stat);
}
+#endif
diff --git a/src/file_lnk.c b/src/file_lnk.c
index 3624623..57662f0 100644
--- a/src/file_lnk.c
+++ b/src/file_lnk.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lnk)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -86,7 +87,8 @@ static unsigned int lnk_get_size(const unsigned char *buffer, const unsigned int
unsigned int len;
if((flags&SCF_PIDL)!=0)
{ /* The Shell Item Id List */
- len=buffer[i]+(buffer[i+1]<<8);
+ const uint16_t *ptr=(const uint16_t *)&buffer[i];
+ len=le16(*ptr);
#ifdef DEBUG_LNK
log_debug("LNK Shell Item Id List at 0x%04x=%04x\n",
i, len);
@@ -99,10 +101,14 @@ static unsigned int lnk_get_size(const unsigned char *buffer, const unsigned int
return 0;
if((flags&SCF_LOCATION)!=0)
{ /* File location info */
- len=buffer[i] + (buffer[i+1]<<8) + (buffer[i+2]<<16) + (buffer[i+3]<<24);
+ const uint32_t *ptr=(const uint32_t *)&buffer[i];
+ len=le32(*ptr);
#ifdef DEBUG_LNK
log_debug("LNK File location info at 0x%04x=%04x\n", i, len);
#endif
+ /* Discard too big files, avoid overflow */
+ if(len >= 0x10000000)
+ return 0;
i+=2;
i+=len;
}
@@ -111,7 +117,8 @@ static unsigned int lnk_get_size(const unsigned char *buffer, const unsigned int
return 0;
if((flags&SCF_DESCRIPTION)!=0)
{ /* Description string */
- len=buffer[i]+(buffer[i+1]<<8);
+ const uint16_t *ptr=(const uint16_t *)&buffer[i];
+ len=le16(*ptr);
#ifdef DEBUG_LNK
log_debug("LNK description string at 0x%04x=%04x\n", i, len);
#endif
@@ -125,7 +132,8 @@ static unsigned int lnk_get_size(const unsigned char *buffer, const unsigned int
return 0;
if((flags&SCF_RELATIVE)!=0)
{ /* Relative path */
- len=buffer[i]+(buffer[i+1]<<8);
+ const uint16_t *ptr=(const uint16_t *)&buffer[i];
+ len=le16(*ptr);
#ifdef DEBUG_LNK
log_debug("LNK relative path at 0x%04x=%04x\n", i, len);
#endif
@@ -139,7 +147,8 @@ static unsigned int lnk_get_size(const unsigned char *buffer, const unsigned int
return 0;
if((flags&SCF_WORKDIR)!=0)
{ /* Working directory */
- len=buffer[i]+(buffer[i+1]<<8);
+ const uint16_t *ptr=(const uint16_t *)&buffer[i];
+ len=le16(*ptr);
#ifdef DEBUG_LNK
log_debug("LNK Working directory at 0x%04x=%04x\n", i, len);
#endif
@@ -153,7 +162,8 @@ static unsigned int lnk_get_size(const unsigned char *buffer, const unsigned int
return 0;
if((flags&SCF_ARGS)!=0)
{ /* Command line string */
- len=buffer[i]+(buffer[i+1]<<8);
+ const uint16_t *ptr=(const uint16_t *)&buffer[i];
+ len=le16(*ptr);
#ifdef DEBUG_LNK
log_debug("LNK Command line string at 0x%04x=%04x\n", i, len);
#endif
@@ -167,7 +177,8 @@ static unsigned int lnk_get_size(const unsigned char *buffer, const unsigned int
return 0;
if((flags&SCF_CUSTOMICON)!=0)
{ /* Icon filename string */
- len=buffer[i]+(buffer[i+1]<<8);
+ const uint16_t *ptr=(const uint16_t *)&buffer[i];
+ len=le16(*ptr);
#ifdef DEBUG_LNK
log_debug("LNK Icon filename string at 0x%04x=%04x\n", i, len);
#endif
@@ -181,7 +192,8 @@ static unsigned int lnk_get_size(const unsigned char *buffer, const unsigned int
return 0;
if((flags&SCF_PRODUCT)!=0)
{
- len=buffer[i]+(buffer[i+1]<<8);
+ const uint16_t *ptr=(const uint16_t *)&buffer[i];
+ len=le16(*ptr);
#ifdef DEBUG_LNK
log_debug("LNK Icon product at 0x%04x=%04x\n", i, len);
#endif
@@ -193,7 +205,8 @@ static unsigned int lnk_get_size(const unsigned char *buffer, const unsigned int
return 0;
if((flags&SCF_COMPONENT)!=0)
{
- len=buffer[i]+(buffer[i+1]<<8);
+ const uint16_t *ptr=(const uint16_t *)&buffer[i];
+ len=le16(*ptr);
#ifdef DEBUG_LNK
log_debug("LNK Icon component at 0x%04x=%04x\n", i, len);
#endif
@@ -204,7 +217,10 @@ static unsigned int lnk_get_size(const unsigned char *buffer, const unsigned int
if(i >= buffer_size - 4)
return 0;
/* Extra stuff */
- len=buffer[i] + (buffer[i+1]<<8) + (buffer[i+2]<<16) + (buffer[i+3]<<24);
+ {
+ const uint32_t *ptr=(const uint32_t *)&buffer[i];
+ len=le32(*ptr);
+ }
#ifdef DEBUG_LNK
log_debug("LNK extra stuff at 0x%04x=%04x\n", i, len);
#endif
@@ -246,3 +262,4 @@ static void register_header_check_lnk(file_stat_t *file_stat)
};
register_header_check(0, lnk_header,sizeof(lnk_header), &header_check_lnk, file_stat);
}
+#endif
diff --git a/src/file_logic.c b/src/file_logic.c
index ab0c663..fc597e0 100644
--- a/src/file_logic.c
+++ b/src/file_logic.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_logic)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_logic(file_stat_t *file_stat)
};
register_header_check(0, logic_header,sizeof(logic_header), &header_check_logic, file_stat);
}
+#endif
diff --git a/src/file_lso.c b/src/file_lso.c
index 2aac251..2fd3e80 100644
--- a/src/file_lso.c
+++ b/src/file_lso.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lso)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -63,3 +64,4 @@ static void register_header_check_lso(file_stat_t *file_stat)
};
register_header_check(0, lso_header, sizeof(lso_header), &header_check_lso, file_stat);
}
+#endif
diff --git a/src/file_luks.c b/src/file_luks.c
index 01db685..e29d838 100644
--- a/src/file_luks.c
+++ b/src/file_luks.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_luks)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -65,3 +66,4 @@ static void register_header_check_luks(file_stat_t *file_stat)
{
register_header_check(0, luks_header, sizeof(luks_header), &header_check_luks, file_stat);
}
+#endif
diff --git a/src/file_lxo.c b/src/file_lxo.c
index 2360e5d..611e161 100644
--- a/src/file_lxo.c
+++ b/src/file_lxo.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lxo)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -52,7 +53,7 @@ struct lxo_header
static int header_check_lxo(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const struct lxo_header *header=(const struct lxo_header *)buffer;
- const uint64_t size=be32(header->size) + 8;
+ const uint64_t size=(uint64_t)be32(header->size) + 8;
if(size < sizeof(struct lxo_header))
return 0;
if(buffer[8]=='L' && buffer[9]=='X' && buffer[10]=='O')
@@ -83,3 +84,4 @@ static void register_header_check_lxo(file_stat_t *file_stat)
};
register_header_check(0, lxo_header, sizeof(lxo_header), &header_check_lxo, file_stat);
}
+#endif
diff --git a/src/file_lzh.c b/src/file_lzh.c
index 80a75cc..38a3d4b 100644
--- a/src/file_lzh.c
+++ b/src/file_lzh.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lzh)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,7 +55,8 @@ struct lzh_level0
uint8_t attrib;
uint8_t level;
uint8_t filename_len;
- uint8_t filename[0];
+ /* Size should be 0, be carefull when using sizeof to decrement */
+ uint8_t filename[1];
} __attribute__ ((gcc_struct, __packed__));
struct lzh_level1
@@ -68,7 +70,9 @@ struct lzh_level1
uint8_t reserved_20;
uint8_t level;
uint8_t filename_len;
+#ifndef __FRAMAC__
uint8_t filename[0];
+#endif
} __attribute__ ((gcc_struct, __packed__));
struct lzh_level2
@@ -96,9 +100,9 @@ static void file_rename_level0(file_recovery_t *file_recovery)
return;
buffer_size=fread(buffer, 1, sizeof(buffer), file);
fclose(file);
- if(buffer_size < sizeof(struct lzh_level0))
+ if(buffer_size < sizeof(struct lzh_level0) - 1)
return;
- if(buffer_size < sizeof(struct lzh_level0) + hdr->filename_len)
+ if(buffer_size < sizeof(struct lzh_level0) - 1 + hdr->filename_len)
return;
for(i=0; i< hdr->filename_len && hdr->filename[i]!=0 && hdr->filename[i]!='.'; i++);
file_rename(file_recovery, hdr->filename, i, 0, NULL, 1);
@@ -155,3 +159,4 @@ static void register_header_check_lzh(file_stat_t *file_stat)
register_header_check(2, "-lzs-", 5, &header_check_lzh, file_stat);
register_header_check(2, "-lz4-", 5, &header_check_lzh, file_stat);
}
+#endif
diff --git a/src/file_lzo.c b/src/file_lzo.c
index 7b17f56..40299bf 100644
--- a/src/file_lzo.c
+++ b/src/file_lzo.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lzo)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_lzo(file_stat_t *file_stat)
};
register_header_check(0, lzo_header, sizeof(lzo_header), &header_check_lzo, file_stat);
}
+#endif
diff --git a/src/file_m2ts.c b/src/file_m2ts.c
index 3a8a456..505d308 100644
--- a/src/file_m2ts.c
+++ b/src/file_m2ts.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_m2ts)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -203,3 +204,4 @@ static void register_header_check_ts(file_stat_t *file_stat)
register_header_check(0, "G", 1, &header_check_m2t, file_stat);
register_header_check(4, "G", 1, &header_check_m2ts, file_stat);
}
+#endif
diff --git a/src/file_mat.c b/src/file_mat.c
index 4e27306..a5e6f2d 100644
--- a/src/file_mat.c
+++ b/src/file_mat.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mat)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -60,3 +61,4 @@ static void register_header_check_mat(file_stat_t *file_stat)
static const unsigned char mat_header[7]= {'M', 'A', 'T', 'L', 'A', 'B', ' '};
register_header_check(0, mat_header,sizeof(mat_header), &header_check_mat, file_stat);
}
+#endif
diff --git a/src/file_max.c b/src/file_max.c
index 5d2dd3b..4a03e63 100644
--- a/src/file_max.c
+++ b/src/file_max.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_max)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_max(file_stat_t *file_stat)
{
register_header_check(0, "ViGFk", 5, &header_check_max, file_stat);
}
+#endif
diff --git a/src/file_mb.c b/src/file_mb.c
index b730062..860bc05 100644
--- a/src/file_mb.c
+++ b/src/file_mb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -79,3 +80,4 @@ static void register_header_check_mb(file_stat_t *file_stat)
register_header_check(8, "MAYAFOR4", 8, &header_check_mb, file_stat);
register_header_check(8, "MPLEFOR4", 8, &header_check_mp, file_stat);
}
+#endif
diff --git a/src/file_mcd.c b/src/file_mcd.c
index 1d8ce77..bcbf46d 100644
--- a/src/file_mcd.c
+++ b/src/file_mcd.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mcd)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_mcd(file_stat_t *file_stat)
static const unsigned char mcd_header[11]= { 'V', 'e','c','t','o','r','W','o','r','k','s'};
register_header_check(0x0e, mcd_header,sizeof(mcd_header), &header_check_mcd, file_stat);
}
+#endif
diff --git a/src/file_mdb.c b/src/file_mdb.c
index f7aad9e..a77c27f 100644
--- a/src/file_mdb.c
+++ b/src/file_mdb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mdb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -76,3 +77,4 @@ static void register_header_check_accdb(file_stat_t *file_stat)
static const unsigned char accdb_header[]= { 0x00, 0x01, 0x00, 0x00, 'S', 't', 'a', 'n', 'd','a','r','d',' ','A','C','E',' ', 'D','B', 0x00};
register_header_check(0, accdb_header,sizeof(accdb_header), &header_check_accdb, file_stat);
}
+#endif
diff --git a/src/file_mdf.c b/src/file_mdf.c
index a1020eb..188944c 100644
--- a/src/file_mdf.c
+++ b/src/file_mdf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mdf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -65,3 +66,4 @@ static int header_check_mdf(const unsigned char *buffer, const unsigned int buff
}
return 0;
}
+#endif
diff --git a/src/file_mdp.c b/src/file_mdp.c
new file mode 100644
index 0000000..f15c955
--- /dev/null
+++ b/src/file_mdp.c
@@ -0,0 +1,69 @@
+/*
+
+ File: file_mdp.c
+
+ Copyright (C) 2020 Christophe GRENIER <grenier@cgsecurity.org>
+
+ This software is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write the Free Software Foundation, Inc., 51
+ Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ */
+
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mdp)
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include <stdio.h>
+#include "types.h"
+#include "filegen.h"
+#include "common.h"
+
+static void register_header_check_mdp(file_stat_t *file_stat);
+
+const file_hint_t file_hint_mdp= {
+ .extension="mdp",
+ .description="MediBang Paint Pro",
+ .max_filesize=PHOTOREC_MAX_FILE_SIZE,
+ .recover=1,
+ .enable_by_default=1,
+ .register_header_check=&register_header_check_mdp
+};
+
+struct mdp_header
+{
+ char magic[8];
+ uint32_t val0; /* 0 in the sample files I have */
+ uint32_t val1;
+ uint32_t val2;
+} __attribute__ ((gcc_struct, __packed__));
+
+static int header_check_mdp(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
+{
+ const struct mdp_header *header=(const struct mdp_header *)buffer;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_mdp.extension;
+ file_recovery_new->calculated_file_size=(uint64_t)le32(header->val1) + le32(header->val2) + 20;
+ file_recovery_new->data_check=&data_check_size;
+ file_recovery_new->file_check=&file_check_size;
+ return 1;
+}
+
+static void register_header_check_mdp(file_stat_t *file_stat)
+{
+ register_header_check(0, "mdipack", 8, &header_check_mdp, file_stat);
+}
+#endif
diff --git a/src/file_mfa.c b/src/file_mfa.c
index 0d9d1a4..c63d999 100644
--- a/src/file_mfa.c
+++ b/src/file_mfa.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mfa)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,3 +60,4 @@ static void register_header_check_mfa(file_stat_t *file_stat)
static const unsigned char mfa_header[8]= { 'M', 'M', 'F', '2', 0x04, 0x00, 0x00, 0x00};
register_header_check(0, mfa_header,sizeof(mfa_header), &header_check_mfa, file_stat);
}
+#endif
diff --git a/src/file_mfg.c b/src/file_mfg.c
index 6c2aca2..f3c9f2f 100644
--- a/src/file_mfg.c
+++ b/src/file_mfg.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mfg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -65,3 +66,4 @@ static void register_header_check_mfg(file_stat_t *file_stat)
register_header_check(0, mfg_header,sizeof(mfg_header), &header_check_mfg, file_stat);
}
+#endif
diff --git a/src/file_mft.c b/src/file_mft.c
index 8802672..99e8735 100644
--- a/src/file_mft.c
+++ b/src/file_mft.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mft)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -78,7 +79,7 @@ static int header_check_mft(const unsigned char *buffer, const unsigned int buff
return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_mft.extension;
- file_recovery_new->calculated_file_size=bytes_allocated;
+ file_recovery_new->calculated_file_size=td_max(file_recovery_new->blocksize, bytes_allocated);
file_recovery_new->data_check=&data_check_size;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->file_rename=&file_rename_mft;
@@ -89,3 +90,4 @@ static void register_header_check_mft(file_stat_t *file_stat)
{
register_header_check(0, "FILE", 4, &header_check_mft, file_stat);
}
+#endif
diff --git a/src/file_mid.c b/src/file_mid.c
index c7f8255..c013e03 100644
--- a/src/file_mid.c
+++ b/src/file_mid.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mid)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -121,3 +122,4 @@ static void register_header_check_mid(file_stat_t *file_stat)
static const unsigned char mid_header[8] = { 'M','T','h','d', 0, 0, 0, 0x6};
register_header_check(0, mid_header,sizeof(mid_header), &header_check_mid, file_stat);
}
+#endif
diff --git a/src/file_mig.c b/src/file_mig.c
index b60a8b9..ca45ac5 100644
--- a/src/file_mig.c
+++ b/src/file_mig.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mig)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -111,3 +112,4 @@ static void register_header_check_mig(file_stat_t *file_stat)
};
register_header_check(0, mig_header, sizeof(mig_header), &header_check_mig, file_stat);
}
+#endif
diff --git a/src/file_mk5.c b/src/file_mk5.c
index a23636d..ea6952d 100644
--- a/src/file_mk5.c
+++ b/src/file_mk5.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mk5)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_mk5(file_stat_t *file_stat)
static const unsigned char mk5_header[4]= { 0x36, 0xff, 0xff, 0xff };
register_header_check(0, mk5_header,sizeof(mk5_header), &header_check_mk5, file_stat);
}
+#endif
diff --git a/src/file_mkv.c b/src/file_mkv.c
index be34cda..91701a2 100644
--- a/src/file_mkv.c
+++ b/src/file_mkv.c
@@ -21,6 +21,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mkv)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -183,3 +184,4 @@ static int header_check_mkv(const unsigned char *buffer, const unsigned int buff
}
return 1;
}
+#endif
diff --git a/src/file_mlv.c b/src/file_mlv.c
index 5d53760..f9436fb 100644
--- a/src/file_mlv.c
+++ b/src/file_mlv.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mlv)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -31,6 +32,9 @@
#include "filegen.h"
#include "common.h"
#include "log.h"
+#if defined(__FRAMAC__)
+#include "__fc_builtin.h"
+#endif
static void register_header_check_mlv(file_stat_t *file_stat);
@@ -66,9 +70,15 @@ typedef struct {
uint64_t timestamp;
} __attribute__ ((gcc_struct, __packed__)) mlv_hdr_t;
+/*@
+ @ requires \valid_read(hdr);
+ @ requires \initialized(hdr);
+ @ assigns \nothing;
+ @*/
static int is_valid_type(const mlv_hdr_t *hdr)
{
unsigned int i;
+ /*@ loop assigns i; */
for(i=0; i<4; i++)
{
const uint8_t c=hdr->blockType[i];
@@ -80,6 +90,9 @@ static int is_valid_type(const mlv_hdr_t *hdr)
static data_check_t data_check_mlv(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *fr)
{
+ /*@
+ @ loop assigns fr->calculated_file_size;
+ @*/
while(fr->calculated_file_size + buffer_size/2 >= fr->file_size &&
fr->calculated_file_size + 8 < fr->file_size + buffer_size/2)
{
@@ -94,13 +107,20 @@ static data_check_t data_check_mlv(const unsigned char *buffer, const unsigned i
static void file_check_mlv(file_recovery_t *file_recovery)
{
- mlv_hdr_t hdr;
uint64_t fs=0;
- do
+ while(fs < 0x8000000000000000)
{
+ mlv_hdr_t hdr;
if(my_fseek(file_recovery->handle, fs, SEEK_SET)<0 ||
- fread(&hdr, sizeof(hdr), 1, file_recovery->handle)!=1 ||
- le32(hdr.blockSize)<0x10 ||
+ fread(&hdr, sizeof(hdr), 1, file_recovery->handle)!=1)
+ {
+ file_recovery->file_size=(fs <= file_recovery->blocksize ? 0 : fs);
+ return;
+ }
+#if defined(__FRAMAC__)
+ Frama_C_make_unknown(&hdr, sizeof(mlv_hdr_t));
+#endif
+ if(le32(hdr.blockSize)<0x10 ||
!is_valid_type(&hdr) ||
fs + le32(hdr.blockSize) > file_recovery->file_size)
{
@@ -108,7 +128,8 @@ static void file_check_mlv(file_recovery_t *file_recovery)
return;
}
fs+=le32(hdr.blockSize);
- } while(1);
+ }
+ file_recovery->file_size=0;
}
static void file_rename_mlv(file_recovery_t *file_recovery)
@@ -129,6 +150,17 @@ static void file_rename_mlv(file_recovery_t *file_recovery)
file_rename(file_recovery, NULL, 0, 0, ext, 1);
}
+/*@
+ @ requires buffer_size > 0;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid_read(file_recovery);
+ @ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
+ @ requires \valid(file_recovery_new);
+ @ requires file_recovery_new->blocksize > 0;
+ @
+ @ requires buffer_size >= sizeof(mlv_file_hdr_t);
+ @ requires separation: \separated(&file_hint_mlv, buffer+(..), file_recovery, file_recovery_new);
+ @*/
static int header_check_mlv(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const mlv_file_hdr_t *hdr=(const mlv_file_hdr_t *)buffer;
@@ -163,3 +195,4 @@ static void register_header_check_mlv(file_stat_t *file_stat)
{
register_header_check(0, "MLVI", 4, &header_check_mlv, file_stat);
}
+#endif
diff --git a/src/file_mobi.c b/src/file_mobi.c
index 3d9e59a..ef48467 100644
--- a/src/file_mobi.c
+++ b/src/file_mobi.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mobi)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -68,3 +69,4 @@ static void register_header_check_mobi(file_stat_t *file_stat)
{
register_header_check(0x3c, "BOOKMOBI", 8, &header_check_mobi, file_stat);
}
+#endif
diff --git a/src/file_mov.c b/src/file_mov.c
index a403eb9..52574a6 100644
--- a/src/file_mov.c
+++ b/src/file_mov.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mov) || defined(SINGLE_FORMAT_mov_mdat)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,7 +59,7 @@ const file_hint_t file_hint_mov_mdat= {
};
static const char *extension_mp4="mp4";
-static const char *extension_m4p="m4p";
+static const char *extension_m4a="m4a";
static const char *extension_3gp="3gp";
static const char *extension_3g2="3g2";
static const char *extension_heic="heic";
@@ -214,7 +215,7 @@ static data_check_t data_check_mov(const unsigned char *buffer, const unsigned i
file_recovery_new->extension == extension_cr3 ||
file_recovery_new->extension == extension_heic ||
file_recovery_new->extension == extension_jp2 ||
- file_recovery_new->extension == extension_m4p ||
+ file_recovery_new->extension == extension_m4a ||
file_recovery_new->extension == extension_mp4);
@ ensures (\result == 1) ==> (file_recovery_new->time == 0);
@ ensures (\result == 1) ==> (valid_read_string(file_recovery_new->extension));
@@ -339,8 +340,7 @@ static int header_check_mov_aux(const unsigned char *buffer, const unsigned int
else if(memcmp(&buffer[i+8], "M4A ", 4)==0)
{
reset_file_recovery(file_recovery_new);
- /* acc ? */
- file_recovery_new->extension=extension_m4p;
+ file_recovery_new->extension=extension_m4a;
if(file_recovery->blocksize < 16)
{
file_recovery_new->min_filesize=calculated_file_size;
@@ -477,7 +477,7 @@ static int header_check_mov_aux(const unsigned char *buffer, const unsigned int
file_recovery_new->extension == extension_cr3 ||
file_recovery_new->extension == extension_heic ||
file_recovery_new->extension == extension_jp2 ||
- file_recovery_new->extension == extension_m4p ||
+ file_recovery_new->extension == extension_m4a ||
file_recovery_new->extension == extension_mp4);
@ ensures (\result == 1) ==> (valid_read_string(file_recovery_new->extension));
@ ensures (\result == 1) ==> (file_recovery_new->file_rename == &file_rename_mov || file_recovery_new->file_rename == \null);
@@ -529,6 +529,7 @@ static void register_header_check_mov(file_stat_t *file_stat)
register_header_check(4, (const unsigned char*)"wide",4, &header_check_mov, file_stat);
register_header_check(4, (const unsigned char*)"jP ",4, &header_check_mov, file_stat);
}
+#endif
#if defined(MAIN_mov)
#define BLOCKSIZE 65536u
diff --git a/src/file_mp3.c b/src/file_mp3.c
index 11431da..7760545 100644
--- a/src/file_mp3.c
+++ b/src/file_mp3.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mp3)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -35,7 +36,7 @@
#include "__fc_builtin.h"
#endif
-#if !defined(MAIN_mp3)
+#if !defined(SINGLE_FORMAT)
extern const file_hint_t file_hint_mkv;
extern const file_hint_t file_hint_tiff;
#endif
@@ -536,12 +537,12 @@ static int header_check_mp3(const unsigned char *buffer, const unsigned int buff
return 0;
/*@ assert nbr == 0; */
/*@
- @ loop invariant 0 <= nbr <= potential_frame_offset <= 2048 + 8065;
+ @ loop invariant 0 <= nbr <= potential_frame_offset <= 8192 + 8065;
@ loop assigns potential_frame_offset,nbr;
- @ loop variant 2048 - potential_frame_offset;
+ @ loop variant 8192 - potential_frame_offset;
@*/
while(potential_frame_offset+1 < buffer_size &&
- potential_frame_offset+1 < 2048)
+ potential_frame_offset+1 < 8192)
{
if(buffer[potential_frame_offset+0]!=0xFF)
return 0;
@@ -587,7 +588,7 @@ static int header_check_mp3(const unsigned char *buffer, const unsigned int buff
if(file_recovery->file_stat!=NULL)
{
if(file_recovery->file_stat->file_hint==&file_hint_mp3
-#if !defined(MAIN_mp3)
+#if !defined(SINGLE_FORMAT)
|| file_recovery->file_stat->file_hint==&file_hint_mkv
#endif
)
@@ -595,7 +596,7 @@ static int header_check_mp3(const unsigned char *buffer, const unsigned int buff
header_ignored(file_recovery_new);
return 0;
}
-#if !defined(MAIN_mp3)
+#if !defined(SINGLE_FORMAT)
/* RGV values from TIFF may be similar to the beginning of an mp3 */
if(file_recovery->file_stat->file_hint==&file_hint_tiff &&
buffer[0]==buffer[3] && buffer[1]==buffer[4] && buffer[2]==buffer[5])
@@ -644,6 +645,7 @@ static void register_header_check_mp3(file_stat_t *file_stat)
register_header_check(0, mpeg25_L3_header1, sizeof(mpeg25_L3_header1), &header_check_mp3, file_stat);
register_header_check(0, mpeg25_L3_header2, sizeof(mpeg25_L3_header2), &header_check_mp3, file_stat);
}
+#endif
#if defined(MAIN_mp3)
#define BLOCKSIZE 65536u
diff --git a/src/file_mpg.c b/src/file_mpg.c
index 03b61d3..7a3fb68 100644
--- a/src/file_mpg.c
+++ b/src/file_mpg.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mpg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -341,3 +342,4 @@ static void register_header_check_mpg(file_stat_t *file_stat)
register_header_check(0, mpg_header_BA,sizeof(mpg_header_BA), &header_check_mpg_Pack, file_stat);
register_header_check(0, mpg_header_BB,sizeof(mpg_header_BB), &header_check_mpg_System, file_stat);
}
+#endif
diff --git a/src/file_mpl.c b/src/file_mpl.c
index 011a315..c28235c 100644
--- a/src/file_mpl.c
+++ b/src/file_mpl.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mpl)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -52,3 +53,4 @@ static void register_header_check_mpl(file_stat_t *file_stat)
{
register_header_check(0, "MPLS0100", 8, &header_check_mpl, file_stat);
}
+#endif
diff --git a/src/file_mrw.c b/src/file_mrw.c
index 498c216..5c30f8d 100644
--- a/src/file_mrw.c
+++ b/src/file_mrw.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mrw)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -96,3 +97,4 @@ static void register_header_check_mrw(file_stat_t *file_stat)
static const unsigned char mrw_header[4]= { 0x00,'M','R','M'}; /* Minolta Raw */
register_header_check(0, mrw_header,sizeof(mrw_header), &header_check_mrw, file_stat);
}
+#endif
diff --git a/src/file_msa.c b/src/file_msa.c
index 7d9f558..07e6d23 100644
--- a/src/file_msa.c
+++ b/src/file_msa.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_msa)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -72,3 +73,4 @@ static void register_header_check_msa(file_stat_t *file_stat)
register_header_check(0, msa_header_fb, sizeof(msa_header_fb), &header_check_msa, file_stat);
register_header_check(0, msa_header_fc, sizeof(msa_header_fc), &header_check_msa, file_stat);
}
+#endif
diff --git a/src/file_mus.c b/src/file_mus.c
index 1e46612..7d004b4 100644
--- a/src/file_mus.c
+++ b/src/file_mus.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mus)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -61,3 +62,4 @@ static void register_header_check_mus(file_stat_t *file_stat)
static const unsigned char mus_header[18] = { 'E','N','I','G','M','A',' ','B','I','N','A','R','Y',' ','F','I','L','E' };
register_header_check(0, mus_header,sizeof(mus_header), &header_check_mus, file_stat);
}
+#endif
diff --git a/src/file_mxf.c b/src/file_mxf.c
index d6715bb..c73af64 100644
--- a/src/file_mxf.c
+++ b/src/file_mxf.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mxf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -155,3 +156,4 @@ static void register_header_check_mxf(file_stat_t *file_stat)
};
register_header_check(0, mxf_header,sizeof(mxf_header), &header_check_mxf, file_stat);
}
+#endif
diff --git a/src/file_myo.c b/src/file_myo.c
index 25af8e0..839ddc7 100644
--- a/src/file_myo.c
+++ b/src/file_myo.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_myo)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -67,3 +68,4 @@ static void register_header_check_myo(file_stat_t *file_stat)
{
register_header_check(0x9ce, "FC!DEF", 6, &header_check_myo, file_stat);
}
+#endif
diff --git a/src/file_mysql.c b/src/file_mysql.c
index 2052b7a..8d9dfd0 100644
--- a/src/file_mysql.c
+++ b/src/file_mysql.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_mysql)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -70,3 +71,4 @@ static int header_check_mysql(const unsigned char *buffer, const unsigned int bu
}
return 0;
}
+#endif
diff --git a/src/file_nd2.c b/src/file_nd2.c
index 3dd9f84..feeaca0 100644
--- a/src/file_nd2.c
+++ b/src/file_nd2.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_nd2)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_nd2(file_stat_t *file_stat)
{
register_header_check(0x10, "ND2 FILE SIGNATURE CHUNK NAME01!Ver", 0x23, &header_check_nd2, file_stat);
}
+#endif
diff --git a/src/file_nds.c b/src/file_nds.c
index 7bc302e..3786452 100644
--- a/src/file_nds.c
+++ b/src/file_nds.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_nds)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -74,3 +75,4 @@ static void register_header_check_nds(file_stat_t *file_stat)
};
register_header_check(0xc0, nds_header, sizeof(nds_header), &header_check_nds, file_stat);
}
+#endif
diff --git a/src/file_nes.c b/src/file_nes.c
index 5e6601f..0c7e156 100644
--- a/src/file_nes.c
+++ b/src/file_nes.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_nes)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -67,3 +68,4 @@ static void register_header_check_nes(file_stat_t *file_stat)
static const unsigned char nes_header[4]= {'N','E','S',0x1A};
register_header_check(0, nes_header,sizeof(nes_header), &header_check_nes, file_stat);
}
+#endif
diff --git a/src/file_njx.c b/src/file_njx.c
index 57be6b8..f4c8158 100644
--- a/src/file_njx.c
+++ b/src/file_njx.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_njx)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -69,3 +70,4 @@ static void file_check_njx(file_recovery_t *file_recovery)
const unsigned char njx_footer[4]= {'N', 'J', '*', 0x04};
file_search_footer(file_recovery, njx_footer, sizeof(njx_footer), 0);
}
+#endif
diff --git a/src/file_nk2.c b/src/file_nk2.c
index 4e2a44a..f97a279 100644
--- a/src/file_nk2.c
+++ b/src/file_nk2.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_nk2)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -190,3 +191,4 @@ static void register_header_check_nk2(file_stat_t *file_stat)
static const unsigned char nk2_header[8]= { 0x0d, 0xf0, 0xad, 0xba, 0x0a, 0x00, 0x00, 0x00 };
register_header_check(0, nk2_header, sizeof(nk2_header), &header_check_nk2, file_stat);
}
+#endif
diff --git a/src/file_nsf.c b/src/file_nsf.c
index af3269b..65ccd43 100644
--- a/src/file_nsf.c
+++ b/src/file_nsf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_nsf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,3 +60,4 @@ static void register_header_check_nsf(file_stat_t *file_stat)
register_header_check(0, nsf_header, sizeof(nsf_header), &header_check_nsf, file_stat);
}
+#endif
diff --git a/src/file_oci.c b/src/file_oci.c
index 94145aa..2d2048b 100644
--- a/src/file_oci.c
+++ b/src/file_oci.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_oci)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -111,3 +112,4 @@ static void register_header_check_oci(file_stat_t *file_stat)
};
register_header_check(0, oci_header, sizeof(oci_header), &header_check_oci, file_stat);
}
+#endif
diff --git a/src/file_ogg.c b/src/file_ogg.c
index fb9d43d..1184f6b 100644
--- a/src/file_ogg.c
+++ b/src/file_ogg.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ogg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -113,3 +114,4 @@ static void register_header_check_ogg(file_stat_t *file_stat)
{
register_header_check(0, ogg_header,sizeof(ogg_header), &header_check_ogg, file_stat);
}
+#endif
diff --git a/src/file_one.c b/src/file_one.c
index 31664c0..9fe0343 100644
--- a/src/file_one.c
+++ b/src/file_one.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_one)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -62,3 +63,4 @@ static void register_header_check_one(file_stat_t *file_stat)
0xae, 0xb1, 0x53, 0x78, 0xd0, 0x29, 0x96, 0xd3 };
register_header_check(0, one_header,sizeof(one_header), &header_check_one, file_stat);
}
+#endif
diff --git a/src/file_orf.c b/src/file_orf.c
index 15531a5..1637893 100644
--- a/src/file_orf.c
+++ b/src/file_orf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_orf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -65,3 +66,4 @@ static void register_header_check_orf(file_stat_t *file_stat)
register_header_check(0, orf_header_IIRS, sizeof(orf_header_IIRS), &header_check_orf_IIRS, file_stat);
register_header_check(0, orf_header_IIRO, sizeof(orf_header_IIRO), &header_check_orf_IIRO, file_stat);
}
+#endif
diff --git a/src/file_paf.c b/src/file_paf.c
index 6e956d9..00ada90 100644
--- a/src/file_paf.c
+++ b/src/file_paf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_paf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_paf(file_stat_t *file_stat)
static const unsigned char paf_header[11]= {'5', '0', '0', '\0', '5', '0', '0', '\0', 'P','A','F'};
register_header_check(0, paf_header,sizeof(paf_header), &header_check_paf, file_stat);
}
+#endif
diff --git a/src/file_pap.c b/src/file_pap.c
index 9f51490..7834c69 100644
--- a/src/file_pap.c
+++ b/src/file_pap.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pap)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_pap(file_stat_t *file_stat)
static const unsigned char pap_header[] = {'P','A','P','1'};
register_header_check(0, pap_header,sizeof(pap_header), &header_check_pap, file_stat);
}
+#endif
diff --git a/src/file_par2.c b/src/file_par2.c
index 2cb5fa0..ddfb5f6 100644
--- a/src/file_par2.c
+++ b/src/file_par2.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_par2)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -131,3 +132,4 @@ static void register_header_check_par2(file_stat_t *file_stat)
{
register_header_check(0, par2_header, sizeof(par2_header), &header_check_par2, file_stat);
}
+#endif
diff --git a/src/file_pcap.c b/src/file_pcap.c
index 337a4da..174d571 100644
--- a/src/file_pcap.c
+++ b/src/file_pcap.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pcap)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,3 +60,4 @@ static void register_header_check_pcap(file_stat_t *file_stat)
register_header_check(0, pcap_le_header1, sizeof(pcap_le_header1), &header_check_pcap, file_stat);
register_header_check(0, pcap_le_header2, sizeof(pcap_le_header2), &header_check_pcap, file_stat);
}
+#endif
diff --git a/src/file_pcb.c b/src/file_pcb.c
index 9d788db..9b2c571 100644
--- a/src/file_pcb.c
+++ b/src/file_pcb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pcb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_pcb(file_stat_t *file_stat)
};
register_header_check(0, pcb_header, sizeof(pcb_header), &header_check_pcb, file_stat);
}
+#endif
diff --git a/src/file_pct.c b/src/file_pct.c
index 4983705..ae5589f 100644
--- a/src/file_pct.c
+++ b/src/file_pct.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pct)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -134,3 +135,4 @@ static void register_header_check_pct(file_stat_t *file_stat)
static const unsigned char pct_header[6]= { 0x00, 0x11, 0x02, 0xff, 0x0c, 0x00};
register_header_check(0x20a, pct_header,sizeof(pct_header), &header_check_pct, file_stat);
}
+#endif
diff --git a/src/file_pcx.c b/src/file_pcx.c
index 4f351e8..c51c1d9 100644
--- a/src/file_pcx.c
+++ b/src/file_pcx.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pcx)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -110,4 +111,4 @@ static int header_check_pcx(const unsigned char *buffer, const unsigned int buff
}
return 0;
}
-
+#endif
diff --git a/src/file_pdb.c b/src/file_pdb.c
index 4a9ec33..d104fac 100644
--- a/src/file_pdb.c
+++ b/src/file_pdb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pdb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -96,3 +97,4 @@ static void register_header_check_pdb(file_stat_t *file_stat)
{
register_header_check(0, "HEADER ", 10, &header_check_pdb, file_stat);
}
+#endif
diff --git a/src/file_pdf.c b/src/file_pdf.c
index 1311539..1644697 100644
--- a/src/file_pdf.c
+++ b/src/file_pdf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pdf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -316,3 +317,4 @@ static void register_header_check_pdf(file_stat_t *file_stat)
static const unsigned char pdf_header[] = { '%','P','D','F','-','1'};
register_header_check(0, pdf_header,sizeof(pdf_header), &header_check_pdf, file_stat);
}
+#endif
diff --git a/src/file_pds.c b/src/file_pds.c
index f16641e..866fb41 100644
--- a/src/file_pds.c
+++ b/src/file_pds.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pds)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,3 +59,4 @@ static void register_header_check_pds(file_stat_t *file_stat)
};
register_header_check(0, pds_header, sizeof(pds_header), &header_check_pds, file_stat);
}
+#endif
diff --git a/src/file_pf.c b/src/file_pf.c
index d01b99d..fef0cdd 100644
--- a/src/file_pf.c
+++ b/src/file_pf.c
@@ -21,6 +21,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -128,6 +129,7 @@ static void register_header_check_pf(file_stat_t *file_stat)
static const unsigned char pf_header[7] = {0x00, 0x00, 0x00, 'S', 'C', 'C', 'A'};
register_header_check(1, pf_header,sizeof(pf_header), &header_check_pf, file_stat);
}
+#endif
#if defined(MAIN_pf)
#define BLOCKSIZE 65536u
diff --git a/src/file_pfx.c b/src/file_pfx.c
index 2151bd6..b338c09 100644
--- a/src/file_pfx.c
+++ b/src/file_pfx.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pfx)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -90,3 +91,4 @@ static void register_header_check_pfx(file_stat_t *file_stat)
};
register_header_check(11, pfx_header,sizeof(pfx_header), &header_check_pfx, file_stat);
}
+#endif
diff --git a/src/file_pgdump.c b/src/file_pgdump.c
index 3acaffe..4d53804 100644
--- a/src/file_pgdump.c
+++ b/src/file_pgdump.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pgdump)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -107,3 +108,4 @@ static void register_header_check_pgdump(file_stat_t *file_stat)
{
register_header_check(0, "PGDMP", 5, &header_check_pgdump, file_stat);
}
+#endif
diff --git a/src/file_plist.c b/src/file_plist.c
index 63e5767..a738a2c 100644
--- a/src/file_plist.c
+++ b/src/file_plist.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_plist)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -64,3 +65,4 @@ static void register_header_check_plist(file_stat_t *file_stat)
{
register_header_check(0, "bplist00", 8, &header_check_plist, file_stat);
}
+#endif
diff --git a/src/file_plr.c b/src/file_plr.c
index 50b9866..e851f53 100644
--- a/src/file_plr.c
+++ b/src/file_plr.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_plr)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,3 +60,4 @@ static void register_header_check_plr(file_stat_t *file_stat)
};
register_header_check(0, plr_header, sizeof(plr_header), &header_check_plr, file_stat);
}
+#endif
diff --git a/src/file_plt.c b/src/file_plt.c
index 7ad9334..5d09a41 100644
--- a/src/file_plt.c
+++ b/src/file_plt.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_plt)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -60,3 +61,4 @@ static void register_header_check_plt(file_stat_t *file_stat)
};
register_header_check(2, plt_header, sizeof(plt_header), &header_check_plt, file_stat);
}
+#endif
diff --git a/src/file_png.c b/src/file_png.c
index 3d3b31f..00be0be 100644
--- a/src/file_png.c
+++ b/src/file_png.c
@@ -26,6 +26,7 @@
http://www.libpng.org/pub/mng/spec/
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_png)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -262,3 +263,4 @@ static void register_header_check_png(file_stat_t *file_stat)
register_header_check(0, mng_header, sizeof(mng_header), &header_check_mng, file_stat);
register_header_check(0, jng_header, sizeof(jng_header), &header_check_jng, file_stat);
}
+#endif
diff --git a/src/file_pnm.c b/src/file_pnm.c
index 569defb..7790919 100644
--- a/src/file_pnm.c
+++ b/src/file_pnm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pnm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -79,3 +80,4 @@ static void register_header_check_pnm(file_stat_t *file_stat)
register_header_check(0, "P5\n# ", 5, &header_check_pgm, file_stat);
register_header_check(0, "P6\n# ", 5, &header_check_ppm, file_stat);
}
+#endif
diff --git a/src/file_prc.c b/src/file_prc.c
index 5679ff5..26639c5 100644
--- a/src/file_prc.c
+++ b/src/file_prc.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_prc)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -76,3 +77,4 @@ static void register_header_check_prc(file_stat_t *file_stat)
static const unsigned char prc_header[16]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'a','p','p','l'};
register_header_check(0x30, prc_header,sizeof(prc_header), &header_check_prc, file_stat);
}
+#endif
diff --git a/src/file_prd.c b/src/file_prd.c
index a355162..124306a 100644
--- a/src/file_prd.c
+++ b/src/file_prd.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_prd)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,3 +59,4 @@ static void register_header_check_prd(file_stat_t *file_stat)
};
register_header_check(0, prd_header, sizeof(prd_header), &header_check_prd, file_stat);
}
+#endif
diff --git a/src/file_prt.c b/src/file_prt.c
index 18b45f4..71067a6 100644
--- a/src/file_prt.c
+++ b/src/file_prt.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_prt)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -64,3 +65,4 @@ static void register_header_check_prt(file_stat_t *file_stat)
'A', 'R', 'T', ' '};
register_header_check(0, prt_header,sizeof(prt_header), &header_check_prt, file_stat);
}
+#endif
diff --git a/src/file_ps.c b/src/file_ps.c
index f9cfb6c..934cb77 100644
--- a/src/file_ps.c
+++ b/src/file_ps.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ps)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -100,3 +101,4 @@ static data_check_t data_check_ps(const unsigned char *buffer, const unsigned in
file_recovery->calculated_file_size=file_recovery->file_size+(buffer_size/2);
return DC_CONTINUE;
}
+#endif
diff --git a/src/file_psb.c b/src/file_psb.c
index 4a27ac4..82e3934 100644
--- a/src/file_psb.c
+++ b/src/file_psb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_psb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -176,3 +177,4 @@ static void register_header_check_psb(file_stat_t *file_stat)
static const unsigned char psb_header[6]={'8', 'B', 'P', 'S', 0x00, 0x02};
register_header_check(0, psb_header,sizeof(psb_header), &header_check_psb, file_stat);
}
+#endif
diff --git a/src/file_psd.c b/src/file_psd.c
index ab275d1..b1f6a89 100644
--- a/src/file_psd.c
+++ b/src/file_psd.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_psd)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -176,3 +177,4 @@ static void register_header_check_psd(file_stat_t *file_stat)
static const unsigned char psd_header[6]={'8', 'B', 'P', 'S', 0x00, 0x01};
register_header_check(0, psd_header,sizeof(psd_header), &header_check_psd, file_stat);
}
+#endif
diff --git a/src/file_psf.c b/src/file_psf.c
index e30308f..28c817d 100644
--- a/src/file_psf.c
+++ b/src/file_psf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_psf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -61,3 +62,4 @@ static void register_header_check_psf(file_stat_t *file_stat)
{
register_header_check(12, "PSD5RDOC", 8, &header_check_psf, file_stat);
}
+#endif
diff --git a/src/file_psp.c b/src/file_psp.c
index a219467..effe5aa 100644
--- a/src/file_psp.c
+++ b/src/file_psp.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_psp)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -85,3 +86,4 @@ static int header_check_psp(const unsigned char *buffer, const unsigned int buff
}
return 1;
}
+#endif
diff --git a/src/file_pst.c b/src/file_pst.c
index 464f329..3152a4a 100644
--- a/src/file_pst.c
+++ b/src/file_pst.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pst)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -146,3 +147,4 @@ static void register_header_check_pst(file_stat_t *file_stat)
register_header_check(0, dbx_header,sizeof(dbx_header), &header_check_dbx, file_stat);
register_header_check(0, wab_header,sizeof(wab_header), &header_check_wab, file_stat);
}
+#endif
diff --git a/src/file_ptb.c b/src/file_ptb.c
index 13837d1..284af10 100644
--- a/src/file_ptb.c
+++ b/src/file_ptb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ptb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,3 +59,4 @@ static void register_header_check_ptb(file_stat_t *file_stat)
static const unsigned char ptb_header[4]= {'p', 't', 'a', 'b'};
register_header_check(0, ptb_header,sizeof(ptb_header), &header_check_ptb, file_stat);
}
+#endif
diff --git a/src/file_ptf.c b/src/file_ptf.c
index 358fc48..b12c3f3 100644
--- a/src/file_ptf.c
+++ b/src/file_ptf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ptf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -69,3 +70,4 @@ static void register_header_check_ptf(file_stat_t *file_stat)
};
register_header_check(0, ptf_header, sizeof(ptf_header), &header_check_ptf, file_stat);
}
+#endif
diff --git a/src/file_pyc.c b/src/file_pyc.c
index ed70e83..faff089 100644
--- a/src/file_pyc.c
+++ b/src/file_pyc.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pyc)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -94,3 +95,4 @@ static void register_header_check_pyc(file_stat_t *file_stat)
register_header_check(0, pyc_33_magic, sizeof(pyc_33_magic), &header_check_pyc, file_stat);
register_header_check(0, pyc_34_magic, sizeof(pyc_34_magic), &header_check_pyc, file_stat);
}
+#endif
diff --git a/src/file_pzf.c b/src/file_pzf.c
index a7e5a9f..649131b 100644
--- a/src/file_pzf.c
+++ b/src/file_pzf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pzf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -66,3 +67,4 @@ static void register_header_check_pzf(file_stat_t *file_stat)
};
register_header_check(0, pzf_header, sizeof(pzf_header), &header_check_pzf, file_stat);
}
+#endif
diff --git a/src/file_pzh.c b/src/file_pzh.c
index 03bcbab..3fcedc5 100644
--- a/src/file_pzh.c
+++ b/src/file_pzh.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_pzh)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -79,3 +80,4 @@ static void register_header_check_pzh(file_stat_t *file_stat)
{
register_header_check(0x9c4, pzh_header, sizeof(pzh_header), &header_check_pzh, file_stat);
}
+#endif
diff --git a/src/file_qbb.c b/src/file_qbb.c
index 076b6ae..c6d5971 100644
--- a/src/file_qbb.c
+++ b/src/file_qbb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_qbb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -51,7 +52,9 @@ struct qbb_header
uint16_t type;
uint16_t data_len;
uint16_t unk1;
+#if 0
unsigned char data[0];
+#endif
} __attribute__ ((gcc_struct, __packed__));
struct qbb_header02
@@ -64,7 +67,9 @@ struct qbb_header02
uint32_t size;
uint8_t unk3[10];
uint16_t title_len;
+#if 0
uint8_t title[0];
+#endif
} __attribute__ ((gcc_struct, __packed__));
static void file_rename_qbb(file_recovery_t *file_recovery)
@@ -85,9 +90,10 @@ static void file_rename_qbb(file_recovery_t *file_recovery)
if(le16(hdr->type)==2)
{
const struct qbb_header02 *hdr2=(const struct qbb_header02 *)hdr;
+ /* FIXME */
if(sizeof(struct qbb_header02)+le16(hdr2->title_len) <= sizeof(struct qbb_header)+le16(hdr2->data_len) &&
i+sizeof(struct qbb_header)+le16(hdr->data_len) < lu)
- file_rename(file_recovery, hdr2->title, le16(hdr2->title_len), 0, NULL, 1);
+ file_rename(file_recovery, (const char *)hdr2 + sizeof(struct qbb_header02), le16(hdr2->title_len), 0, NULL, 1);
return ;
}
i+=sizeof(struct qbb_header)+le16(hdr->data_len);
@@ -171,3 +177,4 @@ static void register_header_check_qbb(file_stat_t *file_stat)
register_header_check(4, qbw_header,sizeof(qbw_header), &header_check_qbw, file_stat);
register_header_check(0x14, qbw2_header,sizeof(qbw2_header), &header_check_qbw2, file_stat);
}
+#endif
diff --git a/src/file_qdf.c b/src/file_qdf.c
index 5f5e80d..983e243 100644
--- a/src/file_qdf.c
+++ b/src/file_qdf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_qdf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -45,8 +46,8 @@ const file_hint_t file_hint_qdf= {
static int header_check_qdf(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
if(file_recovery->file_stat != NULL &&
- file_recovery->file_stat->file_hint==&file_hint_doc &&
- strstr(file_recovery->filename, ".qdf-backup")!=NULL)
+ file_recovery->file_stat->file_hint==&file_hint_doc)
+// && strstr(file_recovery->filename, ".qdf-backup")!=NULL)
{
if(header_ignored_adv(file_recovery, file_recovery_new)==0)
return 0;
@@ -61,3 +62,4 @@ static void register_header_check_qdf(file_stat_t *file_stat)
static const unsigned char qdf_header[6] = { 0xAC, 0x9E, 0xBD, 0x8F, 0x00, 0x00};
register_header_check(0, qdf_header, sizeof(qdf_header), &header_check_qdf, file_stat);
}
+#endif
diff --git a/src/file_qkt.c b/src/file_qkt.c
index 37475e1..4a34223 100644
--- a/src/file_qkt.c
+++ b/src/file_qkt.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_qkt)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_qkt(file_stat_t *file_stat)
};
register_header_check(0, qkt_header, sizeof(qkt_header), &header_check_qkt, file_stat);
}
+#endif
diff --git a/src/file_qxd.c b/src/file_qxd.c
index 7d8fc7c..8d9f3b4 100644
--- a/src/file_qxd.c
+++ b/src/file_qxd.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_qxd)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -69,3 +70,4 @@ static void register_header_check_qxd(file_stat_t *file_stat)
register_header_check(2, qxp_header_be,sizeof(qxp_header_be), &header_check_qxp, file_stat);
register_header_check(2, qxp_header_le,sizeof(qxp_header_le), &header_check_qxp, file_stat);
}
+#endif
diff --git a/src/file_r3d.c b/src/file_r3d.c
index d465e31..cfd0ceb 100644
--- a/src/file_r3d.c
+++ b/src/file_r3d.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_r3d)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -149,3 +150,4 @@ static void register_header_check_r3d(file_stat_t *file_stat)
register_header_check(4, r3d_header1, sizeof(r3d_header1), &header_check_r3d, file_stat);
register_header_check(4, r3d_header2, sizeof(r3d_header2), &header_check_r3d_v2, file_stat);
}
+#endif
diff --git a/src/file_ra.c b/src/file_ra.c
index b1b6e90..a027b4e 100644
--- a/src/file_ra.c
+++ b/src/file_ra.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ra)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -111,3 +112,4 @@ static void register_header_check_ra(file_stat_t *file_stat)
static const unsigned char ra_header[4] = { '.', 'r', 'a', 0xfd};
register_header_check(0, ra_header,sizeof(ra_header), &header_check_ra, file_stat);
}
+#endif
diff --git a/src/file_raf.c b/src/file_raf.c
index e171c9e..6927922 100644
--- a/src/file_raf.c
+++ b/src/file_raf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_raf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -92,3 +93,4 @@ static void register_header_check_raf(file_stat_t *file_stat)
{
register_header_check(0, "FUJIFILMCCD-RAW ", 16, &header_check_raf, file_stat);
}
+#endif
diff --git a/src/file_rar.c b/src/file_rar.c
index e51ce88..9f0dd49 100644
--- a/src/file_rar.c
+++ b/src/file_rar.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rar)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -83,3 +84,4 @@ static void register_header_check_rar(file_stat_t *file_stat)
register_header_check(0, rar15fmt_header,sizeof(rar15fmt_header), &header_check_rar15fmt, file_stat);
register_header_check(0, rar50fmt_header,sizeof(rar50fmt_header), &header_check_rar50fmt, file_stat);
}
+#endif
diff --git a/src/file_raw.c b/src/file_raw.c
index 8368f93..c99a181 100644
--- a/src/file_raw.c
+++ b/src/file_raw.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_raw)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_raw(file_stat_t *file_stat)
static const unsigned char raw_header_contax[7]= {'A','R','E','C','O','Y','K'};
register_header_check(25, raw_header_contax,sizeof(raw_header_contax), &header_check_raw, file_stat);
}
+#endif
diff --git a/src/file_rdc.c b/src/file_rdc.c
index 3414097..3f79ac1 100644
--- a/src/file_rdc.c
+++ b/src/file_rdc.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rdc)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_rdc(file_stat_t *file_stat)
static const unsigned char rdc_header[9]= {'D','S','C','-','I','m','a','g','e'};
register_header_check(0, rdc_header,sizeof(rdc_header), &header_check_rdc, file_stat);
}
+#endif
diff --git a/src/file_reg.c b/src/file_reg.c
index 73bf7b4..98afdf4 100644
--- a/src/file_reg.c
+++ b/src/file_reg.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_reg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -125,3 +126,4 @@ static void register_header_check_reg(file_stat_t *file_stat)
register_header_check(0, reg_header_nt,sizeof(reg_header_nt), &header_check_reg_nt, file_stat);
register_header_check(0, reg_header_9x,sizeof(reg_header_9x), &header_check_reg_9x, file_stat);
}
+#endif
diff --git a/src/file_res.c b/src/file_res.c
index 2b536bd..204ea6a 100644
--- a/src/file_res.c
+++ b/src/file_res.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_res)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_res(file_stat_t *file_stat)
0xFF, 0xFF, 0, 0, 0xFF, 0xFF};
register_header_check(0, MS_res_header,sizeof(MS_res_header), &header_check_res, file_stat);
}
+#endif
diff --git a/src/file_rfp.c b/src/file_rfp.c
index 1778b2a..9a0c4bb 100644
--- a/src/file_rfp.c
+++ b/src/file_rfp.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rfp)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_rfp(file_stat_t *file_stat)
};
register_header_check(0, rfp_header, sizeof(rfp_header), &header_check_rfp, file_stat);
}
+#endif
diff --git a/src/file_riff.c b/src/file_riff.c
index dedc297..40b6d07 100644
--- a/src/file_riff.c
+++ b/src/file_riff.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_riff)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -333,3 +334,4 @@ static void register_header_check_riff(file_stat_t *file_stat)
register_header_check(0, "RIFF", 4, &header_check_riff, file_stat);
register_header_check(0, "RIFX", 4, &header_check_rifx, file_stat);
}
+#endif
diff --git a/src/file_rlv.c b/src/file_rlv.c
index 9adba92..367eae3 100644
--- a/src/file_rlv.c
+++ b/src/file_rlv.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rlv)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,3 +60,4 @@ static void register_header_check_rlv(file_stat_t *file_stat)
static const unsigned char rlv_header[4]= { 'r' , 'v' , 'l' , 0x00 };
register_header_check(0, rlv_header, sizeof(rlv_header), &header_check_rlv, file_stat);
}
+#endif
diff --git a/src/file_rm.c b/src/file_rm.c
index 3ac1e47..e8e3b50 100644
--- a/src/file_rm.c
+++ b/src/file_rm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -67,3 +68,4 @@ static void register_header_check_rm(file_stat_t *file_stat)
static const unsigned char rm_header[9] = { '.', 'R', 'M', 'F', 0x00, 0x00, 0x00, 0x12, 0x00};
register_header_check(0, rm_header,sizeof(rm_header), &header_check_rm, file_stat);
}
+#endif
diff --git a/src/file_rns.c b/src/file_rns.c
index b1455b4..a567365 100644
--- a/src/file_rns.c
+++ b/src/file_rns.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rns)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_rns(file_stat_t *file_stat)
static const unsigned char rns_header[] = "Propellerheads Reason Song File";
register_header_check(0, rns_header,sizeof(rns_header)-1, &header_check_rns, file_stat);
}
+#endif
diff --git a/src/file_rpm.c b/src/file_rpm.c
index 4ec95b5..5fc0883 100644
--- a/src/file_rpm.c
+++ b/src/file_rpm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rpm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -99,3 +100,4 @@ static void register_header_check_rpm(file_stat_t *file_stat)
static const unsigned char rpm_header[5]= {0xed, 0xab, 0xee, 0xdb, 0x3};
register_header_check(0, rpm_header,sizeof(rpm_header), &header_check_rpm, file_stat);
}
+#endif
diff --git a/src/file_rw2.c b/src/file_rw2.c
index 639a036..587fe24 100644
--- a/src/file_rw2.c
+++ b/src/file_rw2.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rw2)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -62,3 +63,4 @@ static void register_header_check_rw2(file_stat_t *file_stat)
static const unsigned char rw2_header_panasonic[4]= {'I','I','U','\0'};
register_header_check(0, rw2_header_panasonic, sizeof(rw2_header_panasonic), &header_check_rw2, file_stat);
}
+#endif
diff --git a/src/file_rx2.c b/src/file_rx2.c
index ab184aa..eed9c4e 100644
--- a/src/file_rx2.c
+++ b/src/file_rx2.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_rx2)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -67,3 +68,4 @@ static void register_header_check_rx2(file_stat_t *file_stat)
{
register_header_check(0, rx2_header, sizeof(rx2_header), &header_check_rx2, file_stat);
}
+#endif
diff --git a/src/file_save.c b/src/file_save.c
index 205bf4c..1645e07 100644
--- a/src/file_save.c
+++ b/src/file_save.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_save)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_save(file_stat_t *file_stat)
};
register_header_check(8, save_header, sizeof(save_header), &header_check_save, file_stat);
}
+#endif
diff --git a/src/file_sdsk.c b/src/file_sdsk.c
index 0d0ec6a..fd35de1 100644
--- a/src/file_sdsk.c
+++ b/src/file_sdsk.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sdsk)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -64,3 +65,4 @@ static void register_header_check_sdsk(file_stat_t *file_stat)
};
register_header_check(0, sdsk_header, sizeof(sdsk_header), &header_check_sdsk, file_stat);
}
+#endif
diff --git a/src/file_ses.c b/src/file_ses.c
index 5739eee..c24dae8 100644
--- a/src/file_ses.c
+++ b/src/file_ses.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ses)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_ses(file_stat_t *file_stat)
{
register_header_check(0, "COOLNESS", 8, &header_check_ses, file_stat);
}
+#endif
diff --git a/src/file_sgcta.c b/src/file_sgcta.c
index 3bc866e..bc39d5e 100644
--- a/src/file_sgcta.c
+++ b/src/file_sgcta.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sgcta)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_sgcta(file_stat_t *file_stat)
};
register_header_check(0, sgcta_header, sizeof(sgcta_header), &header_check_sgcta, file_stat);
}
+#endif
diff --git a/src/file_shn.c b/src/file_shn.c
index c0fd732..8fc9d00 100644
--- a/src/file_shn.c
+++ b/src/file_shn.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_shn)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_shn(file_stat_t *file_stat)
static const unsigned char shn_header[5]= { 'a' , 'j' , 'k' , 'g' , 0x02 };
register_header_check(0, shn_header, sizeof(shn_header), &header_check_shn, file_stat);
}
+#endif
diff --git a/src/file_sib.c b/src/file_sib.c
index bd29dc3..2e54efc 100644
--- a/src/file_sib.c
+++ b/src/file_sib.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sib)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_sib(file_stat_t *file_stat)
static const unsigned char sib_header[9]= {0x0F, 'S', 'I', 'B', 'E', 'L', 'I', 'U', 'S'};
register_header_check(0, sib_header,sizeof(sib_header), &header_check_sib, file_stat);
}
+#endif
diff --git a/src/file_sig.c b/src/file_sig.c
index 41207e4..3c8ae48 100644
--- a/src/file_sig.c
+++ b/src/file_sig.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sig)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -73,7 +74,10 @@ static signature_t signatures={
.list = TD_LIST_HEAD_INIT(signatures.list)
};
-static int signature_cmp(const struct td_list_head *a, const struct td_list_head *b)
+#ifndef __FRAMAC__
+static
+#endif
+int signature_cmp(const struct td_list_head *a, const struct td_list_head *b)
{
const signature_t *sig_a=td_list_entry_const(a, const signature_t, list);
const signature_t *sig_b=td_list_entry_const(b, const signature_t, list);
@@ -457,3 +461,4 @@ static void register_header_check_sig(file_stat_t *file_stat)
}
free(buffer);
}
+#endif
diff --git a/src/file_sit.c b/src/file_sit.c
index ec64e6f..f1e79d8 100644
--- a/src/file_sit.c
+++ b/src/file_sit.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sit)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_sit(file_stat_t *file_stat)
static const unsigned char sit_header[14] = { '7','1','0','0',' ','3','.','3','D',' ','7','1','0','0'};
register_header_check(0, sit_header,sizeof(sit_header), &header_check_sit, file_stat);
}
+#endif
diff --git a/src/file_skd.c b/src/file_skd.c
index c01e5c1..383932e 100644
--- a/src/file_skd.c
+++ b/src/file_skd.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_skd)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -57,3 +58,4 @@ static void register_header_check_skd(file_stat_t *file_stat)
};
register_header_check(0, skd_header,sizeof(skd_header), &header_check_skd, file_stat);
}
+#endif
diff --git a/src/file_skp.c b/src/file_skp.c
index 0ffc00b..612db4d 100644
--- a/src/file_skp.c
+++ b/src/file_skp.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_skp)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_skp(file_stat_t *file_stat)
'U', 0x00, 'p', 0x00, ' ', 0x00, 'M', 0x00, 'o', 0x00, 'd', 0x00, 'e', 0x00, 'l', 0x00 };
register_header_check(0, skp_header,sizeof(skp_header), &header_check_skp, file_stat);
}
+#endif
diff --git a/src/file_snag.c b/src/file_snag.c
index a867077..b6d143b 100644
--- a/src/file_snag.c
+++ b/src/file_snag.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_snag)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -63,3 +64,4 @@ static void register_header_check_snag(file_stat_t *file_stat)
};
register_header_check(0, snag_header, sizeof(snag_header), &header_check_snag, file_stat);
}
+#endif
diff --git a/src/file_sp3.c b/src/file_sp3.c
index 4d3336d..30df9d1 100644
--- a/src/file_sp3.c
+++ b/src/file_sp3.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sp3)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -118,3 +119,4 @@ static void register_header_check_sp3(file_stat_t *file_stat)
register_header_check(0, sp31_header, sizeof(sp31_header), &header_check_sp3, file_stat);
register_header_check(0, sp32_header, sizeof(sp32_header), &header_check_sp3, file_stat);
}
+#endif
diff --git a/src/file_spe.c b/src/file_spe.c
index 0e79aab..c1bd112 100644
--- a/src/file_spe.c
+++ b/src/file_spe.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_spe)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -319,6 +320,7 @@ static void register_header_check_spe(file_stat_t *file_stat)
static const unsigned char spe_header[4]= {0x67, 0x45, 0x23, 0x01};
register_header_check(0xbb4, spe_header,sizeof(spe_header), &header_check_spe, file_stat);
}
+#endif
#if defined(MAIN_spe)
#define BLOCKSIZE 65536u
diff --git a/src/file_spf.c b/src/file_spf.c
index c235082..f0df65c 100644
--- a/src/file_spf.c
+++ b/src/file_spf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_spf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -98,3 +99,4 @@ static void register_header_check_spf(file_stat_t *file_stat)
};
register_header_check(0, spf_header,sizeof(spf_header), &header_check_spf, file_stat);
}
+#endif
diff --git a/src/file_spss.c b/src/file_spss.c
index a837adb..9838bc9 100644
--- a/src/file_spss.c
+++ b/src/file_spss.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_spss)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_spss(file_stat_t *file_stat)
/* Check record type + beginning of product name*/
register_header_check(0, "$FL2@(#) SPSS DATA FILE", 23, &header_check_spss, file_stat);
}
+#endif
diff --git a/src/file_sql.c b/src/file_sql.c
index d139463..ddc8569 100644
--- a/src/file_sql.c
+++ b/src/file_sql.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sqlite)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -100,3 +101,4 @@ static void register_header_check_sqlite(file_stat_t *file_stat)
{
register_header_check(0, "SQLite format 3", 16, &header_check_sqlite, file_stat);
}
+#endif
diff --git a/src/file_sqm.c b/src/file_sqm.c
index f72dee2..ce0bf3c 100644
--- a/src/file_sqm.c
+++ b/src/file_sqm.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_sqm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_sqm(file_stat_t *file_stat)
static const unsigned char sqm_header[6]= { 'M', 'S', 'Q', 'M', 'x', 0x00};
register_header_check(0, sqm_header, sizeof(sqm_header), &header_check_sqm, file_stat);
}
+#endif
diff --git a/src/file_steuer2014.c b/src/file_steuer2014.c
index eba0702..e8857ed 100644
--- a/src/file_steuer2014.c
+++ b/src/file_steuer2014.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_steuer2014)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -104,3 +105,4 @@ static void register_header_check_steuer(file_stat_t *file_stat)
};
register_header_check(0, steuer_header, sizeof(steuer_header), &header_check_steuer, file_stat);
}
+#endif
diff --git a/src/file_stl.c b/src/file_stl.c
index d05c4a8..cc1200b 100644
--- a/src/file_stl.c
+++ b/src/file_stl.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_stl)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -68,3 +69,4 @@ static void register_header_check_stl(file_stat_t *file_stat)
/* Note: STL Ascii format is recovered in file_txt.c */
register_header_check(0, "solid ", 6, &header_check_stl, file_stat);
}
+#endif
diff --git a/src/file_stu.c b/src/file_stu.c
index fe914df..f3d8829 100644
--- a/src/file_stu.c
+++ b/src/file_stu.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_stuffit)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_stuffit(file_stat_t *file_stat)
static const unsigned char stuffit_header[7] = { 'S', 't', 'u', 'f', 'f', 'I', 't'};
register_header_check(0, stuffit_header,sizeof(stuffit_header), &header_check_stuffit, file_stat);
}
+#endif
diff --git a/src/file_studio.c b/src/file_studio.c
index d6b84da..15ddf63 100644
--- a/src/file_studio.c
+++ b/src/file_studio.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_studio)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -65,3 +66,4 @@ static void register_header_check_studio(file_stat_t *file_stat)
{
register_header_check(0, "silhouette04;", 13, &header_check_studio, file_stat);
}
+#endif
diff --git a/src/file_swf.c b/src/file_swf.c
index 17d743a..c85160b 100644
--- a/src/file_swf.c
+++ b/src/file_swf.c
@@ -19,6 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_swf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -296,6 +297,7 @@ static void register_header_check_swf(file_stat_t *file_stat)
register_header_check(0, "FWS", 3, &header_check_swf, file_stat);
register_header_check(0, "ZWS", 3, &header_check_swfz, file_stat);
}
+#endif
#if defined(MAIN_swf)
#define BLOCKSIZE 65536u
diff --git a/src/file_tar.c b/src/file_tar.c
index 424b314..1056584 100644
--- a/src/file_tar.c
+++ b/src/file_tar.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tar)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -64,6 +65,15 @@ struct posix_header
/* 500 */
};
+/*@
+ @ requires buffer_size >= 512;
+ @ requires \valid_read(buffer+(0..buffer_size-1));
+ @ requires \valid_read(file_recovery);
+ @ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
+ @ requires \valid(file_recovery_new);
+ @ requires file_recovery_new->blocksize > 0;
+ @ requires separation: \separated(&file_hint_tar, buffer+(..), file_recovery, file_recovery_new);
+ @*/
int header_check_tar(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const struct posix_header *h=(const struct posix_header *)buffer;
@@ -80,6 +90,9 @@ int header_check_tar(const unsigned char *buffer, const unsigned int buffer_size
return 1;
}
+/*@
+ @ requires \valid(file_stat);
+ @*/
static void register_header_check_tar(file_stat_t *file_stat)
{
static const unsigned char tar_header_gnu[6] = { 'u','s','t','a','r',0x00};
@@ -87,3 +100,4 @@ static void register_header_check_tar(file_stat_t *file_stat)
register_header_check(0x101, tar_header_gnu,sizeof(tar_header_gnu), &header_check_tar, file_stat);
register_header_check(0x101, tar_header_posix,sizeof(tar_header_posix), &header_check_tar, file_stat);
}
+#endif
diff --git a/src/file_tax.c b/src/file_tax.c
index 66515b9..48b6b82 100644
--- a/src/file_tax.c
+++ b/src/file_tax.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tax)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_tax(file_stat_t *file_stat)
static const unsigned char tax_header[6]= { 'T', 'T', 'F', 'N', 0x01, 0x01};
register_header_check(0, tax_header, sizeof(tax_header), &header_check_tax, file_stat);
}
+#endif
diff --git a/src/file_template.c b/src/file_template.c
index 190207e..eb1f052 100644
--- a/src/file_template.c
+++ b/src/file_template.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_EXTENSION)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -64,3 +65,4 @@ static void register_header_check_EXTENSION(file_stat_t *file_stat)
};
register_header_check(HEADER_LOC, EXTENSION_header, sizeof(EXTENSION_header), &header_check_EXTENSION, file_stat);
}
+#endif
diff --git a/src/file_tg.c b/src/file_tg.c
index fb93a9b..0091231 100644
--- a/src/file_tg.c
+++ b/src/file_tg.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -61,3 +62,4 @@ static void register_header_check_tg(file_stat_t *file_stat)
};
register_header_check(0, tg_header, sizeof(tg_header), &header_check_tg, file_stat);
}
+#endif
diff --git a/src/file_tib.c b/src/file_tib.c
index 0fc9ab5..bdbe08e 100644
--- a/src/file_tib.c
+++ b/src/file_tib.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tib)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -125,3 +126,4 @@ static void register_header_check_tib(file_stat_t *file_stat)
register_header_check(0, tib_header,sizeof(tib_header), &header_check_tib, file_stat);
register_header_check(0, tib2_header,sizeof(tib2_header), &header_check_tib2, file_stat);
}
+#endif
diff --git a/src/file_tiff.c b/src/file_tiff.c
index b30064f..00bc828 100644
--- a/src/file_tiff.c
+++ b/src/file_tiff.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tiff) || defined(SINGLE_FORMAT_jpg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,8 +54,6 @@ const file_hint_t file_hint_tiff= {
.register_header_check=&register_header_check_tiff
};
-/* @ ensures \result == 1 || \result == 2 || \result == 4 || \result == 8;
- */
unsigned int tiff_type2size(const unsigned int type)
{
switch(type)
@@ -185,10 +184,13 @@ static void register_header_check_tiff(file_stat_t *file_stat)
{
static const unsigned char tiff_header_be[4]= { 'M','M',0x00, 0x2a};
static const unsigned char tiff_header_le[4]= { 'I','I',0x2a, 0x00};
+#if !defined(SINGLE_FORMAT_jpg)
#if !defined(MAIN_tiff_le) && !defined(MAIN_jpg)
register_header_check(0, tiff_header_be, sizeof(tiff_header_be), &header_check_tiff_be, file_stat);
#endif
#if !defined(MAIN_tiff_be) && !defined(MAIN_jpg)
register_header_check(0, tiff_header_le, sizeof(tiff_header_le), &header_check_tiff_le, file_stat);
#endif
+#endif
}
+#endif
diff --git a/src/file_tiff.h b/src/file_tiff.h
index fa9af03..7420461 100644
--- a/src/file_tiff.h
+++ b/src/file_tiff.h
@@ -71,6 +71,7 @@ struct ifd_header {
/*@
@ requires \valid_read(buffer+(0..buffer_size-1));
@ ensures \valid_read(buffer+(0..buffer_size-1));
+ @ assigns \nothing;
@*/
time_t get_date_from_tiff_header(const unsigned char*buffer, const unsigned int buffer_size);
@@ -93,7 +94,7 @@ unsigned int find_tag_from_tiff_header(const unsigned char *buffer, const unsign
unsigned int find_tag_from_tiff_header_le(const unsigned char *buffer, const unsigned int tiff_size, const unsigned int tag, const unsigned char**potential_error);
#endif
-#if !defined(MAIN_tiff_be) && !defined(MAIN_jpg)
+#if !defined(MAIN_tiff_be) && !defined(MAIN_jpg) && !defined(SINGLE_FORMAT_jpg)
/*@
@ requires \valid(fr);
@ requires \valid(fr->handle);
@@ -106,24 +107,33 @@ unsigned int find_tag_from_tiff_header_le(const unsigned char *buffer, const uns
void file_check_tiff_le(file_recovery_t *fr);
/*@
- @ requires buffer_size >= 15;
+ @ requires buffer_size > 0;
@ requires \valid_read(buffer+(0..buffer_size-1));
@ requires \valid_read(file_recovery);
@ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
@ requires \valid(file_recovery_new);
@ requires file_recovery_new->blocksize > 0;
+ @
+ @ requires buffer_size >= 15;
+ @
@ ensures \result == 0 || \result == 1;
@ ensures (\result == 1) ==> (file_recovery_new->file_stat == \null);
@ ensures (\result == 1) ==> (file_recovery_new->handle == \null);
- @ ensures \result == 1 ==> \initialized(&file_recovery_new->time);
- @ ensures (\result == 1) ==> (file_recovery_new->calculated_file_size == 0);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->time);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->calculated_file_size);
@ ensures (\result == 1) ==> (file_recovery_new->file_size == 0);
- @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null);
- @ ensures (\result == 1) ==> (file_recovery_new->file_check == &file_check_tiff_le);
- @ ensures (\result == 1) ==> (file_recovery_new->file_rename== \null);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->min_filesize);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null || \valid_function(file_recovery_new->data_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == \null || \valid_function(file_recovery_new->file_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename == \null || \valid_function(file_recovery_new->file_rename));
@ ensures (\result == 1) ==> (file_recovery_new->extension != \null);
@ ensures (\result == 1) ==> valid_read_string(file_recovery_new->extension);
@ ensures (\result == 1) ==> \separated(file_recovery_new, file_recovery_new->extension);
+ @
+ @ ensures (\result == 1) ==> (file_recovery_new->calculated_file_size == 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null);
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == &file_check_tiff_le);
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename== \null);
@*/
int header_check_tiff_le(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
#endif
@@ -140,30 +150,44 @@ int header_check_tiff_le(const unsigned char *buffer, const unsigned int buffer_
unsigned int find_tag_from_tiff_header_be(const unsigned char*buffer, const unsigned int tiff_size, const unsigned int tag, const unsigned char**potential_error);
#endif
-#if !defined(MAIN_tiff_le) && !defined(MAIN_jpg)
+#if !defined(MAIN_tiff_le) && !defined(MAIN_jpg) && !defined(SINGLE_FORMAT_jpg)
/*@
- @ requires buffer_size >= 15;
+ @ requires buffer_size > 0;
@ requires \valid_read(buffer+(0..buffer_size-1));
@ requires \valid_read(file_recovery);
@ requires file_recovery->file_stat==\null || valid_read_string((char*)file_recovery->filename);
@ requires \valid(file_recovery_new);
@ requires file_recovery_new->blocksize > 0;
+ @
+ @ requires buffer_size >= 15;
+ @
@ ensures \result == 0 || \result == 1;
@ ensures (\result == 1) ==> (file_recovery_new->file_stat == \null);
@ ensures (\result == 1) ==> (file_recovery_new->handle == \null);
- @ ensures \result == 1 ==> \initialized(&file_recovery_new->time);
- @ ensures (\result == 1) ==> (file_recovery_new->calculated_file_size == 0);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->time);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->calculated_file_size);
@ ensures (\result == 1) ==> (file_recovery_new->file_size == 0);
- @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null);
- @ ensures (\result == 1) ==> (file_recovery_new->file_rename== \null);
+ @ ensures (\result == 1) ==> \initialized(&file_recovery_new->min_filesize);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null || \valid_function(file_recovery_new->data_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_check == \null || \valid_function(file_recovery_new->file_check));
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename == \null || \valid_function(file_recovery_new->file_rename));
@ ensures (\result == 1) ==> (file_recovery_new->extension != \null);
@ ensures (\result == 1) ==> valid_read_string(file_recovery_new->extension);
@ ensures (\result == 1) ==> \separated(file_recovery_new, file_recovery_new->extension);
+ @
+ @ ensures (\result == 1) ==> (file_recovery_new->calculated_file_size == 0);
+ @ ensures (\result == 1) ==> (file_recovery_new->data_check == \null);
+ @ ensures (\result == 1) ==> (file_recovery_new->file_rename== \null);
@*/
int header_check_tiff_be(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
#endif
+/*@
+ @ ensures \result == 1 || \result == 2 || \result == 4 || \result == 8;
+ @ assigns \nothing;
+ @*/
unsigned int tiff_type2size(const unsigned int type);
+
#ifdef DEBUG_TIFF
const char *tag_name(unsigned int tag);
#endif
diff --git a/src/file_tiff_be.c b/src/file_tiff_be.c
index 74bc61e..4cfeb69 100644
--- a/src/file_tiff_be.c
+++ b/src/file_tiff_be.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tiff) || defined(SINGLE_FORMAT_jpg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -42,7 +43,7 @@
#include "__fc_builtin.h"
#endif
-#if (!defined(MAIN_tiff_be) && !defined(MAIN_tiff_le)) || defined(MAIN_jpg)
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_jpg)
extern const file_hint_t file_hint_jpg;
#endif
extern const file_hint_t file_hint_tiff;
@@ -149,7 +150,6 @@ unsigned int find_tag_from_tiff_header_be(const unsigned char *buffer, const uns
return 0;
/*@ assert \valid_read(buffer+(0..tiff_size-1)); */
/*@ assert offset_ifd0 + sizeof(struct ifd_header) <= tiff_size; */
- /*X assert \valid_read(buffer+(0..offset_ifd0 + sizeof(struct ifd_header)-1)); */
{
const unsigned int tmp=find_tag_from_tiff_header_be_aux(buffer, tiff_size, tag, potential_error, offset_ifd0);
/*@ assert \valid_read(buffer+(0..tiff_size-1)); */
@@ -196,6 +196,7 @@ unsigned int find_tag_from_tiff_header_be(const unsigned char *buffer, const uns
@ requires \valid(handle);
@ requires \valid_read(entry_strip_offsets);
@ requires \valid_read(entry_strip_bytecounts);
+ @ requires \separated(handle, &errno, &Frama_C_entropy_source, &__fc_heap_status, \union(entry_strip_offsets, entry_strip_bytecounts));
@*/
static uint64_t parse_strip_be(FILE *handle, const TIFFDirEntry *entry_strip_offsets, const TIFFDirEntry *entry_strip_bytecounts)
{
@@ -235,8 +236,8 @@ static uint64_t parse_strip_be(FILE *handle, const TIFFDirEntry *entry_strip_off
if(fseek(handle, be32(entry_strip_bytecounts->tdir_offset), SEEK_SET) < 0 ||
fread(sizep, sizeof(*sizep), nbr, handle) != nbr)
{
- free(offsetp);
free(sizep);
+ free(offsetp);
return TIFF_ERROR;
}
#if defined(__FRAMAC__)
@@ -249,8 +250,8 @@ static uint64_t parse_strip_be(FILE *handle, const TIFFDirEntry *entry_strip_off
if(max_offset < tmp)
max_offset=tmp;
}
- free(offsetp);
free(sizep);
+ free(offsetp);
return max_offset;
}
@@ -258,6 +259,7 @@ static uint64_t parse_strip_be(FILE *handle, const TIFFDirEntry *entry_strip_off
@ requires type != 1 || \valid_read((const char *)val);
@ requires type != 3 || \valid_read((const char *)val + ( 0 .. 2));
@ requires type != 4 || \valid_read((const char *)val + ( 0 .. 4));
+ @ assigns \nothing;
@*/
static unsigned int tiff_be_read(const void *val, const unsigned int type)
{
@@ -380,7 +382,7 @@ static uint64_t tiff_be_makernote(FILE *in, const uint32_t tiff_diroff)
#endif
#endif
-#if !defined(MAIN_tiff_le) && !defined(MAIN_jpg)
+#if !defined(MAIN_tiff_le) && !defined(MAIN_jpg) && !defined(SINGLE_FORMAT_jpg)
static uint64_t file_check_tiff_be_aux(file_recovery_t *fr, const uint32_t tiff_diroff, const unsigned int depth, const unsigned int count);
/*@
@@ -743,9 +745,7 @@ static void file_check_tiff_be(file_recovery_t *fr)
strcmp(fr->extension,"wdp")==0)
fr->file_size=calculated_file_size;
}
-#endif
-#if !defined(MAIN_tiff_le) && !defined(MAIN_jpg)
/*@
@ requires separation: \separated(&file_hint_tiff, buffer+(..), file_recovery, file_recovery_new);
@ ensures (\result == 1) ==> (file_recovery_new->file_check == &file_check_tiff_be);
@@ -761,7 +761,7 @@ int header_check_tiff_be(const unsigned char *buffer, const unsigned int buffer_
const TIFFHeader *header=(const TIFFHeader *)buffer;
if((uint32_t)be32(header->tiff_diroff) < sizeof(TIFFHeader))
return 0;
-#if (!defined(MAIN_tiff_be) && !defined(MAIN_tiff_le)) || defined(MAIN_jpg)
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_jpg)
if(file_recovery->file_stat!=NULL &&
file_recovery->file_stat->file_hint==&file_hint_jpg)
{
@@ -795,6 +795,7 @@ int header_check_tiff_be(const unsigned char *buffer, const unsigned int buffer_
return 1;
}
#endif
+#endif
#if defined(MAIN_tiff_be)
#define BLOCKSIZE 65536u
diff --git a/src/file_tiff_le.c b/src/file_tiff_le.c
index 196e4c3..034e075 100644
--- a/src/file_tiff_le.c
+++ b/src/file_tiff_le.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tiff) || defined(SINGLE_FORMAT_jpg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -42,10 +43,10 @@
#include "__fc_builtin.h"
#endif
-#if !defined(MAIN_tiff_be) && !defined(MAIN_tiff_le) && !defined(MAIN_jpg)
+#if !defined(SINGLE_FORMAT)
extern const file_hint_t file_hint_raf;
#endif
-#if (!defined(MAIN_tiff_be) && !defined(MAIN_tiff_le)) || defined(MAIN_jpg)
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_jpg)
extern const file_hint_t file_hint_jpg;
#endif
extern const file_hint_t file_hint_tiff;
@@ -173,6 +174,7 @@ unsigned int find_tag_from_tiff_header_le(const unsigned char *buffer, const uns
const unsigned int nbr_fields=get_nbr_fields_le(buffer, tiff_size, offset_ifd0);
unsigned int offset_tiff_next_diroff;
offset_tiff_next_diroff=offset_ifd0 + 2 + nbr_fields * sizeof(TIFFDirEntry);
+ /*@ assert tiff_size >= 4; */
if(offset_tiff_next_diroff < tiff_size - 4)
{
const unsigned char *ptr_hdr;
@@ -198,6 +200,7 @@ unsigned int find_tag_from_tiff_header_le(const unsigned char *buffer, const uns
@ requires \valid(handle);
@ requires \valid_read(entry_strip_offsets);
@ requires \valid_read(entry_strip_bytecounts);
+ @ requires \separated(handle, &errno, &Frama_C_entropy_source, &__fc_heap_status, \union(entry_strip_offsets, entry_strip_bytecounts));
@*/
static uint64_t parse_strip_le(FILE *handle, const TIFFDirEntry *entry_strip_offsets, const TIFFDirEntry *entry_strip_bytecounts)
{
@@ -237,22 +240,25 @@ static uint64_t parse_strip_le(FILE *handle, const TIFFDirEntry *entry_strip_off
if(fseek(handle, le32(entry_strip_bytecounts->tdir_offset), SEEK_SET) < 0 ||
fread(sizep, sizeof(*sizep), nbr, handle) != nbr)
{
- free(offsetp);
free(sizep);
+ free(offsetp);
return TIFF_ERROR;
}
#if defined(__FRAMAC__)
Frama_C_make_unknown((char *)offsetp, nbr*sizeof(*offsetp));
Frama_C_make_unknown((char *)sizep, nbr*sizeof(*sizep));
#endif
+ /*@
+ @ loop assigns i, max_offset;
+ @*/
for(i=0; i<nbr; i++)
{
const uint64_t tmp=(uint64_t)le32(offsetp[i]) + le32(sizep[i]);
if(max_offset < tmp)
max_offset=tmp;
}
- free(offsetp);
free(sizep);
+ free(offsetp);
return max_offset;
}
@@ -260,6 +266,7 @@ static uint64_t parse_strip_le(FILE *handle, const TIFFDirEntry *entry_strip_off
@ requires type != 1 || \valid_read((const char *)val);
@ requires type != 3 || \valid_read((const char *)val + ( 0 .. 2));
@ requires type != 4 || \valid_read((const char *)val + ( 0 .. 4));
+ @ assigns \nothing;
@*/
static unsigned int tiff_le_read(const void *val, const unsigned int type)
{
@@ -382,7 +389,7 @@ static uint64_t tiff_le_makernote(FILE *in, const uint32_t tiff_diroff)
#endif
#endif
-#if !defined(MAIN_tiff_be) && !defined(MAIN_jpg)
+#if !defined(MAIN_tiff_be) && !defined(MAIN_jpg) && !defined(SINGLE_FORMAT_jpg)
static uint64_t file_check_tiff_le_aux(file_recovery_t *fr, const uint32_t tiff_diroff, const unsigned int depth, const unsigned int count);
/*@
@@ -437,17 +444,17 @@ static uint64_t file_check_tiff_le_aux(file_recovery_t *fr, const uint32_t tiff_
unsigned char buffer[8192];
unsigned int i,n;
int data_read;
- uint64_t max_offset=0;
- uint64_t alphaoffset=0;
uint64_t alphabytecount=0;
- uint64_t imageoffset=0;
+ uint64_t alphaoffset=0;
uint64_t imagebytecount=0;
- uint64_t jpegifoffset=0;
+ uint64_t imageoffset=0;
uint64_t jpegifbytecount=0;
- uint64_t strip_offsets=0;
+ uint64_t jpegifoffset=0;
+ uint64_t max_offset=0;
uint64_t strip_bytecounts=0;
- uint64_t tile_offsets=0;
+ uint64_t strip_offsets=0;
uint64_t tile_bytecounts=0;
+ uint64_t tile_offsets=0;
unsigned int tdir_tag_old=0;
unsigned int sorted_tag_error=0;
const TIFFDirEntry *entries=(const TIFFDirEntry *)&buffer[2];
@@ -748,7 +755,7 @@ void file_check_tiff_le(file_recovery_t *fr)
}
#endif
-#if !defined(MAIN_tiff_be) && !defined(MAIN_jpg)
+#if !defined(MAIN_tiff_be) && !defined(MAIN_jpg) && !defined(SINGLE_FORMAT_jpg)
/*@
@ requires separation: \separated(&file_hint_tiff, buffer+(..), file_recovery, file_recovery_new);
@ ensures (\result == 1) ==> (file_recovery_new->extension == file_hint_tiff.extension ||
@@ -767,7 +774,7 @@ int header_check_tiff_le(const unsigned char *buffer, const unsigned int buffer_
return 0;
/* Avoid a false positiv with some RAF files */
if(file_recovery->file_stat!=NULL &&
-#if !defined(MAIN_tiff_be) && !defined(MAIN_tiff_le) && !defined(MAIN_jpg)
+#if !defined(SINGLE_FORMAT)
file_recovery->file_stat->file_hint==&file_hint_raf &&
#endif
memcmp(buffer, raf_fp, 15)==0)
@@ -775,7 +782,7 @@ int header_check_tiff_le(const unsigned char *buffer, const unsigned int buffer_
header_ignored(file_recovery_new);
return 0;
}
-#if (!defined(MAIN_tiff_be) && !defined(MAIN_tiff_le)) || defined(MAIN_jpg)
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_jpg)
if(file_recovery->file_stat!=NULL &&
file_recovery->file_stat->file_hint==&file_hint_jpg)
{
@@ -814,6 +821,7 @@ int header_check_tiff_le(const unsigned char *buffer, const unsigned int buffer_
return 1;
}
#endif
+#endif
#if defined(MAIN_tiff_le)
#define BLOCKSIZE 65536u
diff --git a/src/file_tivo.c b/src/file_tivo.c
index dad23d8..7cd6f36 100644
--- a/src/file_tivo.c
+++ b/src/file_tivo.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tivo)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -66,3 +67,4 @@ static void register_header_check_tivo(file_stat_t *file_stat)
};
register_header_check(0, tivo_header, sizeof(tivo_header), &header_check_tivo, file_stat);
}
+#endif
diff --git a/src/file_torrent.c b/src/file_torrent.c
index 6f116ce..d7e03ed 100644
--- a/src/file_torrent.c
+++ b/src/file_torrent.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_torrent)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_torrent(file_stat_t *file_stat)
{
register_header_check(0, "d8:announce", 11, &header_check_torrent, file_stat);
}
+#endif
diff --git a/src/file_tph.c b/src/file_tph.c
index d8ad62b..cdb2f94 100644
--- a/src/file_tph.c
+++ b/src/file_tph.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tph)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -71,3 +72,4 @@ static void register_header_check_tph(file_stat_t *file_stat)
'P', 'A', 'T', 'H'};
register_header_check(0, tph_header,sizeof(tph_header), &header_check_tph, file_stat);
}
+#endif
diff --git a/src/file_tpl.c b/src/file_tpl.c
index 5e4d1f0..4cd08c8 100644
--- a/src/file_tpl.c
+++ b/src/file_tpl.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tpl)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_tpl(file_stat_t *file_stat)
};
register_header_check(0, tpl_header, sizeof(tpl_header), &header_check_tpl, file_stat);
}
+#endif
diff --git a/src/file_ttf.c b/src/file_ttf.c
index 7ed7ffa..be30c9e 100644
--- a/src/file_ttf.c
+++ b/src/file_ttf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_ttf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -113,3 +114,4 @@ static void register_header_check_ttf(file_stat_t *file_stat)
static const unsigned char header_ttf[5]= {0x00 , 0x01, 0x00, 0x00, 0x00};
register_header_check(0, header_ttf, sizeof(header_ttf), &header_check_ttf, file_stat);
}
+#endif
diff --git a/src/file_txt.c b/src/file_txt.c
index 52484d8..dc258f0 100644
--- a/src/file_txt.c
+++ b/src/file_txt.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_txt)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -659,7 +660,9 @@ int UTFsize(const unsigned char *buffer, const unsigned int buf_len)
/* Reject some invalid UTF-8 sequences */
if(*p==0xc0 || *p==0xc1 || *p==0xf7 || *p>=0xfd)
return i;
- if((*p & 0xf0)==0xe0 && (i+2 >= buf_len || ((*(p+1) & 0xc0)==0x80 && (*(p+2) & 0xc0)==0x80)))
+ if((*p & 0xf0)==0xe0 &&
+ (i+1 >= buf_len || (*(p+1) & 0xc0)==0x80) &&
+ (i+2 >= buf_len || (*(p+2) & 0xc0)==0x80))
{ /* UTF8 l=3 */
#ifdef DEBUG_TXT
log_info("UTFsize i=%u l=3\n", i);
@@ -667,7 +670,8 @@ int UTFsize(const unsigned char *buffer, const unsigned int buf_len)
p+=3;
i+=3;
}
- else if((*p & 0xe0)==0xc0 && (i+1 >= buf_len || (*(p+1) & 0xc0)==0x80))
+ else if((*p & 0xe0)==0xc0 &&
+ (i+1 >= buf_len || (*(p+1) & 0xc0)==0x80))
{ /* UTF8 l=2 */
#ifdef DEBUG_TXT
log_info("UTFsize i=%u l=2\n", i);
@@ -1797,6 +1801,34 @@ static int header_check_txt(const unsigned char *buffer, const unsigned int buff
if(strstr(file_recovery->filename,".html")==NULL)
return 0;
}
+ /* DFRWS 2006 Forensics Challenge: recover recup_dir.1/f0034288.doc
+ */
+#if 0
+ if(file_recovery->file_stat->file_hint == &file_hint_doc)
+ {
+ if(strstr(file_recovery->filename,".doc")==NULL)
+ return 0;
+ }
+#endif
+ /* Useful for DFRWS 2006 Forensics Challenge */
+#if 0
+ else if(file_recovery->file_stat->file_hint == &file_hint_jpg)
+ {
+ /* Don't search text at the beginning of JPG */
+ if(file_recovery->file_size < file_recovery->min_filesize)
+ return 0;
+ /* Text should not be found in JPEG */
+ if(td_memmem(buffer, buffer_size_test, "8BIM", 4)!=NULL ||
+ td_memmem(buffer, buffer_size_test, "adobe", 5)!=NULL ||
+ td_memmem(buffer, buffer_size_test, "exif:", 5)!=NULL ||
+ td_memmem(buffer, buffer_size_test, "<rdf:", 5)!=NULL ||
+ td_memmem(buffer, buffer_size_test, "<?xpacket", 9)!=NULL ||
+ td_memmem(buffer, buffer_size_test, "<dict>", 6)!=NULL ||
+ td_memmem(buffer, buffer_size_test, "xmp:CreatorTool>", 16)!=NULL ||
+ td_memmem(buffer, buffer_size_test, "[camera info]", 13)!=NULL)
+ return 0;
+ }
+#endif
else
return 0;
}
@@ -2281,7 +2313,9 @@ static void register_header_check_fasttxt(file_stat_t *file_stat)
}
register_header_check(4, "SC V10", 6, &header_check_dc, file_stat);
register_header_check(0, "DatasetHeader Begin", 19, &header_check_ers, file_stat);
-// register_header_check(0, "\n<!DOCTYPE html", 15, &header_check_html, file_stat);
+ /* DFRWS 2006 Forensics Challenge */
+ register_header_check(0, "\n<!DOCTYPE html", 15, &header_check_html, file_stat);
+//
register_header_check(0, "<!DOCTYPE html", 14, &header_check_html, file_stat);
register_header_check(0, "<!DOCTYPE HTML", 14, &header_check_html, file_stat);
// register_header_check(0, "<html", 5, &header_check_html, file_stat);
@@ -2336,6 +2370,7 @@ static void register_header_check_txt(file_stat_t *file_stat)
register_header_check(1, &ascii_char[0], 1, &header_check_le16_txt, file_stat);
#endif
}
+#endif
#if defined(MAIN_txt)
#define BLOCKSIZE 65536u
diff --git a/src/file_tz.c b/src/file_tz.c
index c7ff41f..1a27ec2 100644
--- a/src/file_tz.c
+++ b/src/file_tz.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_tz)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -75,3 +76,4 @@ static void register_header_check_tz(file_stat_t *file_stat)
register_header_check(0, tz_header, sizeof(tz_header), &header_check_tz, file_stat);
register_header_check(0, tz2_header, sizeof(tz2_header), &header_check_tz, file_stat);
}
+#endif
diff --git a/src/file_v2i.c b/src/file_v2i.c
index cb655fe..63a87fb 100644
--- a/src/file_v2i.c
+++ b/src/file_v2i.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_v2i)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -57,3 +58,4 @@ static void register_header_check_v2i(file_stat_t *file_stat)
{
register_header_check(0, "$CAN", 4, &header_check_v2i, file_stat);
}
+#endif
diff --git a/src/file_vault.c b/src/file_vault.c
index 7943e6b..d8a9fc1 100644
--- a/src/file_vault.c
+++ b/src/file_vault.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vault)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -82,3 +83,4 @@ static void register_header_check_vault(file_stat_t *file_stat)
};
register_header_check(0, vault_header, sizeof(vault_header), &header_check_vault, file_stat);
}
+#endif
diff --git a/src/file_vdi.c b/src/file_vdi.c
index 7c7b2be..0d4d88e 100644
--- a/src/file_vdi.c
+++ b/src/file_vdi.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vdi)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -103,3 +104,4 @@ static void register_header_check_vdi(file_stat_t *file_stat)
static const unsigned char vdi_header[4]= {0x7f, 0x10, 0xda, 0xbe};
register_header_check(0x40, vdi_header,sizeof(vdi_header), &header_check_vdi, file_stat);
}
+#endif
diff --git a/src/file_vdj.c b/src/file_vdj.c
index 4ae5cbb..b579be3 100644
--- a/src/file_vdj.c
+++ b/src/file_vdj.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vdj)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_vdj(file_stat_t *file_stat)
};
register_header_check(0, vdj_header, sizeof(vdj_header), &header_check_vdj, file_stat);
}
+#endif
diff --git a/src/file_veg.c b/src/file_veg.c
index 8000754..a854ba6 100644
--- a/src/file_veg.c
+++ b/src/file_veg.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_veg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -60,3 +61,4 @@ static void register_header_check_veg(file_stat_t *file_stat)
static const unsigned char veg_header[5]= {'r','i','f','f', '.'};
register_header_check(0, veg_header,sizeof(veg_header), &header_check_veg, file_stat);
}
+#endif
diff --git a/src/file_vfb.c b/src/file_vfb.c
index bad108e..676f3fb 100644
--- a/src/file_vfb.c
+++ b/src/file_vfb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vfb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -66,3 +67,4 @@ static void register_header_check_vfb(file_stat_t *file_stat)
register_header_check(0, vfb_header, sizeof(vfb_header), &header_check_vfb, file_stat);
}
+#endif
diff --git a/src/file_vib.c b/src/file_vib.c
index 575add6..27a9810 100644
--- a/src/file_vib.c
+++ b/src/file_vib.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vib)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_vib(file_stat_t *file_stat)
};
register_header_check(4, vib_header, sizeof(vib_header), &header_check_vib, file_stat);
}
+#endif
diff --git a/src/file_vmdk.c b/src/file_vmdk.c
index 0071a06..a7dcf42 100644
--- a/src/file_vmdk.c
+++ b/src/file_vmdk.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vmdk)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -118,3 +119,4 @@ static void register_header_check_vmdk(file_stat_t *file_stat)
register_header_check(0, vmdk_header4_2,sizeof(vmdk_header4_2), &header_check_vmdk4, file_stat);
register_header_check(0, vmdk_header4_3,sizeof(vmdk_header4_3), &header_check_vmdk4, file_stat);
}
+#endif
diff --git a/src/file_vmg.c b/src/file_vmg.c
index 46e42b8..4d17693 100644
--- a/src/file_vmg.c
+++ b/src/file_vmg.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_vmg)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -70,3 +71,4 @@ static void register_header_check_vmg(file_stat_t *file_stat)
};
register_header_check(0, vmg_header, sizeof(vmg_header), &header_check_vmg, file_stat);
}
+#endif
diff --git a/src/file_wallet.c b/src/file_wallet.c
index 55f5f90..39578fc 100644
--- a/src/file_wallet.c
+++ b/src/file_wallet.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wallet)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_wallet(file_stat_t *file_stat)
};
register_header_check(0, wallet_header, sizeof(wallet_header), &header_check_wallet, file_stat);
}
+#endif
diff --git a/src/file_wdp.c b/src/file_wdp.c
index 0be5694..a965ece 100644
--- a/src/file_wdp.c
+++ b/src/file_wdp.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wdp)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -61,3 +62,4 @@ static void register_header_check_wdp(file_stat_t *file_stat)
static const unsigned char wdp_header[4]= {'I', 'I', 0xbc, 0x01};
register_header_check(0, wdp_header, sizeof(wdp_header), &header_check_wdp, file_stat);
}
+#endif
diff --git a/src/file_wee.c b/src/file_wee.c
index 5f4059c..3bb653d 100644
--- a/src/file_wee.c
+++ b/src/file_wee.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wee)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -66,3 +67,4 @@ static void register_header_check_wee(file_stat_t *file_stat)
};
register_header_check(0, wee_header, sizeof(wee_header), &header_check_wee, file_stat);
}
+#endif
diff --git a/src/file_wim.c b/src/file_wim.c
index c0d4748..be2c702 100644
--- a/src/file_wim.c
+++ b/src/file_wim.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wim)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -109,3 +110,4 @@ static void register_header_check_wim(file_stat_t *file_stat)
{
register_header_check(0, "MSWIM\0\0\0", 8, &header_check_wim, file_stat);
}
+#endif
diff --git a/src/file_win.c b/src/file_win.c
index 9e8b726..3d7cfe9 100644
--- a/src/file_win.c
+++ b/src/file_win.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_win)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -82,3 +83,4 @@ static void register_header_check_win(file_stat_t *file_stat)
};
register_header_check(0, win_header, sizeof(win_header), &header_check_win, file_stat);
}
+#endif
diff --git a/src/file_wks.c b/src/file_wks.c
index c613239..82e3a2a 100644
--- a/src/file_wks.c
+++ b/src/file_wks.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wks)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -74,3 +75,4 @@ static void register_header_check_wks(file_stat_t *file_stat)
register_header_check(0, wks_header,sizeof(wks_header), &header_check_wks, file_stat);
register_header_check(0, wk4_header,sizeof(wk4_header), &header_check_wk4, file_stat);
}
+#endif
diff --git a/src/file_wld.c b/src/file_wld.c
index 5f4c366..7d503d3 100644
--- a/src/file_wld.c
+++ b/src/file_wld.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wld)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -91,3 +92,4 @@ static void register_header_check_wld(file_stat_t *file_stat)
'r' , 'e' , 'l' , 'o' , 'g' , 'i' , 'c' };
register_header_check(1, wld_header, sizeof(wld_header), &header_check_wld, file_stat);
}
+#endif
diff --git a/src/file_wmf.c b/src/file_wmf.c
index 554fdca..23bbb1f 100644
--- a/src/file_wmf.c
+++ b/src/file_wmf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wmf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -119,3 +120,4 @@ static void register_header_check_wmf(file_stat_t *file_stat)
register_header_check(0, apm_header,sizeof(apm_header), &header_check_wmf_placeable, file_stat);
register_header_check(0, wmf_header,sizeof(wmf_header), &header_check_wmf, file_stat);
}
+#endif
diff --git a/src/file_wnk.c b/src/file_wnk.c
index 0605ee1..dcc01db 100644
--- a/src/file_wnk.c
+++ b/src/file_wnk.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wnk)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -53,3 +54,4 @@ static void register_header_check_wnk(file_stat_t *file_stat)
static const unsigned char wnk_header[6]= {'R','P','K','W','I',0x02};
register_header_check(0, wnk_header,sizeof(wnk_header), &header_check_wnk, file_stat);
}
+#endif
diff --git a/src/file_woff.c b/src/file_woff.c
index de3bb7f..b21d82a 100644
--- a/src/file_woff.c
+++ b/src/file_woff.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_woff)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -86,3 +87,4 @@ static void register_header_check_woff(file_stat_t *file_stat)
{
register_header_check(0, "wOFF", 4, &header_check_woff, file_stat);
}
+#endif
diff --git a/src/file_wpb.c b/src/file_wpb.c
index 42caa6d..c3a735d 100644
--- a/src/file_wpb.c
+++ b/src/file_wpb.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wpb)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_wpb(file_stat_t *file_stat)
};
register_header_check(0, wpb_header, sizeof(wpb_header), &header_check_wpb, file_stat);
}
+#endif
diff --git a/src/file_wpd.c b/src/file_wpd.c
index 3d46653..a6e3995 100644
--- a/src/file_wpd.c
+++ b/src/file_wpd.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wpd)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -103,3 +104,4 @@ static void register_header_check_wpd(file_stat_t *file_stat)
static const unsigned char wpd_header[4]= {0xff, 'W','P','C'};
register_header_check(0, wpd_header,sizeof(wpd_header), &header_check_wpd, file_stat);
}
+#endif
diff --git a/src/file_wtv.c b/src/file_wtv.c
index 5b8e9bb..fd61343 100644
--- a/src/file_wtv.c
+++ b/src/file_wtv.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wtv)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -72,3 +73,4 @@ static void register_header_check_wtv(file_stat_t *file_stat)
};
register_header_check(0, wtv_header, sizeof(wtv_header), &header_check_wtv, file_stat);
}
+#endif
diff --git a/src/file_wv.c b/src/file_wv.c
index a061cff..652c816 100644
--- a/src/file_wv.c
+++ b/src/file_wv.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_wv)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -116,3 +117,4 @@ static void register_header_check_wv(file_stat_t *file_stat)
{
register_header_check(0, wv_header, sizeof(wv_header), &header_check_wv, file_stat);
}
+#endif
diff --git a/src/file_x3f.c b/src/file_x3f.c
index 0cba13f..e92a2c4 100644
--- a/src/file_x3f.c
+++ b/src/file_x3f.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_x3f)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -81,3 +82,4 @@ static void register_header_check_x3f(file_stat_t *file_stat)
static const unsigned char x3f_header[4]= {'F','O','V','b'};
register_header_check(0, x3f_header,sizeof(x3f_header), &header_check_x3f, file_stat);
}
+#endif
diff --git a/src/file_x3i.c b/src/file_x3i.c
index c1a001f..6571f53 100644
--- a/src/file_x3i.c
+++ b/src/file_x3i.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_x3i)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -56,3 +57,4 @@ static void register_header_check_x3i(file_stat_t *file_stat)
};
register_header_check(0, x3i_header, sizeof(x3i_header), &header_check_x3i, file_stat);
}
+#endif
diff --git a/src/file_x4a.c b/src/file_x4a.c
index 9122044..e0d5eba 100644
--- a/src/file_x4a.c
+++ b/src/file_x4a.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_x4a)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -102,3 +103,4 @@ static void register_header_check_ysfc100(file_stat_t *file_stat)
};
register_header_check(0x30, ysfc100_header, sizeof(ysfc100_header), &header_check_ysfc100, file_stat);
}
+#endif
diff --git a/src/file_xar.c b/src/file_xar.c
index 54ed675..29aabf7 100644
--- a/src/file_xar.c
+++ b/src/file_xar.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xar)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -76,3 +77,4 @@ static void register_header_check_xar(file_stat_t *file_stat)
{
register_header_check(0, "xar!", 4, &header_check_xar, file_stat);
}
+#endif
diff --git a/src/file_xcf.c b/src/file_xcf.c
index 584a2a7..c8092fa 100644
--- a/src/file_xcf.c
+++ b/src/file_xcf.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xcf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -74,3 +75,4 @@ static void register_header_check_xcf(file_stat_t *file_stat)
register_header_check(0, "gimp xcf v001", 13, &header_check_xcf, file_stat);
register_header_check(0, "gimp xcf v002", 13, &header_check_xcf, file_stat);
}
+#endif
diff --git a/src/file_xfi.c b/src/file_xfi.c
index 3c85490..69a0fc3 100644
--- a/src/file_xfi.c
+++ b/src/file_xfi.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xfi)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,3 +59,4 @@ static void register_header_check_xfi(file_stat_t *file_stat)
};
register_header_check(0x10, xfi_header, sizeof(xfi_header), &header_check_xfi, file_stat);
}
+#endif
diff --git a/src/file_xfs.c b/src/file_xfs.c
index e607e09..9de879d 100644
--- a/src/file_xfs.c
+++ b/src/file_xfs.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xfs)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -148,3 +149,4 @@ static void register_header_check_xfs(file_stat_t *file_stat)
register_header_check(0, iabt, 8, &header_save_xfs, file_stat);
register_header_check(0, "IN", 2, &header_check_xfs_inode, file_stat);
}
+#endif
diff --git a/src/file_xm.c b/src/file_xm.c
index 8a32d96..caf48c6 100644
--- a/src/file_xm.c
+++ b/src/file_xm.c
@@ -21,6 +21,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xm)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -192,3 +193,4 @@ static void register_header_check_xm(file_stat_t *file_stat)
static const unsigned char xm_header[17] = { 'E','x','t','e','n','d','e','d',' ','M','o','d','u','l','e',':',' '};
register_header_check(0, xm_header,sizeof(xm_header), &header_check_xm, file_stat);
}
+#endif
diff --git a/src/file_xml.c b/src/file_xml.c
index 62fd28f..bf19026 100644
--- a/src/file_xml.c
+++ b/src/file_xml.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xml)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -111,3 +112,4 @@ static void register_header_check_xml(file_stat_t *file_stat)
};
register_header_check(0, xml_header, sizeof(xml_header), &header_check_xml, file_stat);
}
+#endif
diff --git a/src/file_xpt.c b/src/file_xpt.c
index 0f45c25..6b06401 100644
--- a/src/file_xpt.c
+++ b/src/file_xpt.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xpt)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -75,3 +76,4 @@ static void register_header_check_xpt(file_stat_t *file_stat)
};
register_header_check(0, xpt_header,sizeof(xpt_header), &header_check_xpt, file_stat);
}
+#endif
diff --git a/src/file_xsv.c b/src/file_xsv.c
index 67f8735..01add82 100644
--- a/src/file_xsv.c
+++ b/src/file_xsv.c
@@ -21,6 +21,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xsv)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,3 +59,4 @@ static void register_header_check_xsv(file_stat_t *file_stat)
static const unsigned char xsv_header[9]= {'B','L','O','C', 'K', 'L', 0xDC, 0x1D, 'd'};
register_header_check(20, xsv_header,sizeof(xsv_header), &header_check_xsv, file_stat);
}
+#endif
diff --git a/src/file_xv.c b/src/file_xv.c
index be8a257..fc54905 100644
--- a/src/file_xv.c
+++ b/src/file_xv.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xv)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -59,3 +60,4 @@ static void register_header_check_xv(file_stat_t *file_stat)
register_header_check(0, xv_header, sizeof(xv_header), &header_check_xv, file_stat);
}
+#endif
diff --git a/src/file_xz.c b/src/file_xz.c
index d4e936e..3729e80 100644
--- a/src/file_xz.c
+++ b/src/file_xz.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_xz)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -65,3 +66,4 @@ static void register_header_check_xz(file_stat_t *file_stat)
};
register_header_check(0, xz_header, sizeof(xz_header), &header_check_xz, file_stat);
}
+#endif
diff --git a/src/file_z2d.c b/src/file_z2d.c
index 2e8b585..5d5557f 100644
--- a/src/file_z2d.c
+++ b/src/file_z2d.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_z2d)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -62,3 +63,4 @@ static void register_header_check_z2d(file_stat_t *file_stat)
{
register_header_check(0x28, z2d_header, sizeof(z2d_header), &header_check_z2d, file_stat);
}
+#endif
diff --git a/src/file_zcode.c b/src/file_zcode.c
index 8d5ff0f..4c24c8f 100644
--- a/src/file_zcode.c
+++ b/src/file_zcode.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_zcode)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -55,3 +56,4 @@ static void register_header_check_zcode(file_stat_t *file_stat)
};
register_header_check(0, zcode_header, sizeof(zcode_header), &header_check_zcode, file_stat);
}
+#endif
diff --git a/src/file_zip.c b/src/file_zip.c
index c80ea59..c4486a6 100644
--- a/src/file_zip.c
+++ b/src/file_zip.c
@@ -22,6 +22,7 @@
Information about ZIP file format: http://www.info-zip.org/doc/appnote-iz-latest.zip
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_zip)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,6 +59,35 @@ const file_hint_t file_hint_zip= {
.register_header_check=&register_header_check_zip
};
+static const char *extension_apk="apk";
+static const char *extension_celtx="celtx";
+static const char *extension_docx="docx";
+static const char *extension_epub="epub";
+static const char *extension_jar="jar";
+static const char *extension_kmz="kmz";
+static const char *extension_kra="kra";
+static const char *extension_mmap="mmap";
+static const char *extension_notebook="notebook";
+static const char *extension_numbers="numbers";
+static const char *extension_odg="odg";
+static const char *extension_odp="odp";
+static const char *extension_ods="ods";
+static const char *extension_odt="odt";
+static const char *extension_ora="ora";
+static const char *extension_pages="pages";
+static const char *extension_pptx="pptx";
+static const char *extension_sh3d="sh3d";
+static const char *extension_sketch="sketch";
+static const char *extension_sxc="sxc";
+static const char *extension_sxd="sxd";
+static const char *extension_sxi="sxi";
+static const char *extension_sxw="sxw";
+static const char *extension_vsdx="vsdx";
+static const char *extension_xd="xd";
+static const char *extension_xlsx="xlsx";
+static const char *extension_xpi="xpi";
+static const char *extension_xrns="xrns";
+
static const unsigned char zip_header[4] = { 'P', 'K', 0x03, 0x04};
#define ZIP_CENTRAL_DIR 0x02014B50
#define ZIP_FILE_ENTRY 0x04034B50
@@ -111,59 +141,69 @@ static uint64_t expected_compressed_size=0;
@ requires \valid(f);
@ requires 0 < size <= 4096;
@ requires \valid_read((const char *)needle + (0 .. size-1));
+ @ requires \separated(f,(const char *)needle+(..));
+ @ assigns *f,errno;
+ @ assigns Frama_C_entropy_source;
@*/
static int64_t file_get_pos(FILE *f, const void* needle, const unsigned int size)
{
- char *buffer =(char *)MALLOC(4096);
+ char buffer[4096];
int64_t total = 0;
#ifdef DEBUG_ZIP
log_trace("zip: file_get_pos(f, needle, %u)\n", size);
#endif
+ /*@
+ @ loop assigns total, *f, errno, buffer[0..4096-1];
+ @ loop assigns Frama_C_entropy_source;
+ @*/
while (!feof(f))
{
- const size_t read_size=fread(buffer, 1, 4096, f);
+ const size_t read_size=fread(&buffer, 1, 4096, f);
if(read_size <= 0 || total > (0x7fffffffffffffff - 4096))
{
- free(buffer);
return -1;
}
/*@ assert 0 < read_size <= 4096; */
/*@ assert total <= 0x8000000000000000 - 4096; */
#if defined(__FRAMAC__)
- Frama_C_make_unknown(buffer, 4096);
+ Frama_C_make_unknown(&buffer, 4096);
#endif
if(read_size >= size)
{
/*@ assert read_size >= size; */
+ const unsigned int count_max=read_size - size;
unsigned int count = 0;
+ // TODO loop invariant 0 <= count <= count_max + 1;
/*@
- @ loop invariant 0 <= count <= read_size - size + 1;
- @ loop variant read_size - size - count;
+ @ loop assigns count, *f, errno;
+ @ loop variant count_max - count;
@*/
- for(count=0; count <= read_size - size; count++)
+ for(count=0; count <= count_max; count++)
{
+ /*@ assert count <= count_max; */
if (buffer[count]==*(const char *)needle && memcmp(buffer+count, needle, size)==0)
{
- free(buffer);
if(my_fseek(f, (off_t)count-(off_t)read_size, SEEK_CUR)<0)
{
+#if !defined(__FRAMAC__)
log_trace("zip: file_get_pos count-read failed\n");
+#endif
return -1;
}
return total+count;
}
}
- total+=count;
+ total+=count_max+1;
}
if(feof(f) || my_fseek(f, (off_t)1-size, SEEK_CUR)<0)
{
+#if !defined(__FRAMAC__)
log_trace("zip: file_get_pos 1-size failed\n");
- free(buffer);
+#endif
return -1;
}
}
- free(buffer);
return -1;
}
@@ -174,28 +214,84 @@ static int64_t file_get_pos(FILE *f, const void* needle, const unsigned int size
@ requires \valid(krita);
@ requires fr->file_size < 0x8000000000000000 - 65535;
@ requires 0 < len <= 65535;
+ @ requires \separated(fr, fr->handle, ext, krita, file, &first_filename[0 .. 256]);
+ @ requires *ext == \null ||
+ *ext == extension_apk ||
+ *ext == extension_celtx ||
+ *ext == extension_docx ||
+ *ext == extension_epub ||
+ *ext == extension_jar ||
+ *ext == extension_kmz ||
+ *ext == extension_kra ||
+ *ext == extension_mmap ||
+ *ext == extension_notebook ||
+ *ext == extension_numbers ||
+ *ext == extension_odg ||
+ *ext == extension_odp ||
+ *ext == extension_ods ||
+ *ext == extension_odt ||
+ *ext == extension_ora ||
+ *ext == extension_pages ||
+ *ext == extension_pptx ||
+ *ext == extension_sh3d ||
+ *ext == extension_sketch ||
+ *ext == extension_sxc ||
+ *ext == extension_sxd ||
+ *ext == extension_sxi ||
+ *ext == extension_sxw ||
+ *ext == extension_vsdx ||
+ *ext == extension_xd ||
+ *ext == extension_xlsx ||
+ *ext == extension_xpi ||
+ *ext == extension_xrns ||
+ *ext == file_hint_zip.extension;
+ @ ensures *ext == \null ||
+ *ext == extension_apk ||
+ *ext == extension_celtx ||
+ *ext == extension_docx ||
+ *ext == extension_epub ||
+ *ext == extension_jar ||
+ *ext == extension_kmz ||
+ *ext == extension_kra ||
+ *ext == extension_mmap ||
+ *ext == extension_notebook ||
+ *ext == extension_numbers ||
+ *ext == extension_odg ||
+ *ext == extension_odp ||
+ *ext == extension_ods ||
+ *ext == extension_odt ||
+ *ext == extension_ora ||
+ *ext == extension_pages ||
+ *ext == extension_pptx ||
+ *ext == extension_sh3d ||
+ *ext == extension_sketch ||
+ *ext == extension_sxc ||
+ *ext == extension_sxd ||
+ *ext == extension_sxi ||
+ *ext == extension_sxw ||
+ *ext == extension_vsdx ||
+ *ext == extension_xd ||
+ *ext == extension_xlsx ||
+ *ext == extension_xpi ||
+ *ext == extension_xrns ||
+ *ext == file_hint_zip.extension;
@ ensures fr->file_size < 0x8000000000000000;
@ ensures \result == -1 || \result == 0;
@ ensures *krita==0 || *krita==19;
@*/
-static int zip_parse_file_entry_fn(file_recovery_t *fr, const char **ext, const unsigned int file_nbr, const zip_file_entry_t file, const uint64_t len, unsigned int *krita)
+static int zip_parse_file_entry_fn(file_recovery_t *fr, const char **ext, const unsigned int file_nbr, const zip_file_entry_t *file, const uint64_t len, unsigned int *krita)
{
-#ifdef __FRAMAC__
- char *filename=(char *)MALLOC(65535+1);
-#else
- char *filename=(char *)MALLOC(len+1);
-#endif
+ char filename[65535+1];
*krita=0;
if (fread(filename, len, 1, fr->handle) != 1)
{
#ifdef DEBUG_ZIP
log_trace("zip: Unexpected EOF in file_entry header: %lu bytes expected\n", len);
#endif
- free(filename);
return -1;
}
#if defined(__FRAMAC__)
- Frama_C_make_unknown(filename, len);
+ Frama_C_make_unknown(filename, 65535+1);
#endif
fr->file_size += len;
/*@ assert fr->file_size < 0x8000000000000000; */
@@ -203,6 +299,7 @@ static int zip_parse_file_entry_fn(file_recovery_t *fr, const char **ext, const
if(first_filename[0]=='\0')
{
const unsigned int len_tmp=(len<255?len:255);
+ /*@ assert 0 <= len_tmp <= 255; */
strncpy(first_filename, filename, len_tmp);
first_filename[len_tmp]='\0';
}
@@ -224,10 +321,10 @@ static int zip_parse_file_entry_fn(file_recovery_t *fr, const char **ext, const
msoffice=1;
else if(file_nbr==0)
{
- if(len==8 && memcmp(filename, "mimetype", 8)==0 && le16(file.extra_length)==0)
+ if(len==8 && memcmp(filename, "mimetype", 8)==0 && le16(file->extra_length)==0)
{
unsigned char buffer[128];
- const unsigned int compressed_size=le32(file.compressed_size);
+ const unsigned int compressed_size=le32(file->compressed_size);
const int to_read=(compressed_size < 128 ? compressed_size: 128);
if( fread(buffer, to_read, 1, fr->handle)!=1)
{
@@ -235,7 +332,6 @@ static int zip_parse_file_entry_fn(file_recovery_t *fr, const char **ext, const
log_trace("zip: Unexpected EOF in file_entry data: %u bytes expected\n",
compressed_size);
#endif
- free(filename);
return -1;
}
#if defined(__FRAMAC__)
@@ -244,63 +340,62 @@ static int zip_parse_file_entry_fn(file_recovery_t *fr, const char **ext, const
if (my_fseek(fr->handle, -to_read, SEEK_CUR) < 0)
{
log_info("fseek failed\n");
- free(filename);
return -1;
}
if(compressed_size==16 && memcmp(buffer,"image/openraster",16)==0)
- *ext="ora";
+ *ext=extension_ora;
else if(compressed_size==20 && memcmp(buffer,"application/epub+zip",20)==0)
- *ext="epub";
+ *ext=extension_epub;
else if(compressed_size==28 && memcmp(buffer,"application/vnd.sun.xml.calc",28)==0)
- *ext="sxc";
+ *ext=extension_sxc;
else if(compressed_size==28 && memcmp(buffer,"application/vnd.sun.xml.draw",28)==0)
- *ext="sxd";
+ *ext=extension_sxd;
else if(compressed_size==31 && memcmp(buffer,"application/vnd.sun.xml.impress",31)==0)
- *ext="sxi";
+ *ext=extension_sxi;
else if(compressed_size==30 && memcmp(buffer,"application/vnd.sun.xml.writer",30)==0)
- *ext="sxw";
+ *ext=extension_sxw;
else if(compressed_size==39 && memcmp(buffer,"application/vnd.oasis.opendocument.text",39)==0)
- *ext="odt";
+ *ext=extension_odt;
else if(compressed_size==43 && memcmp(buffer,"application/vnd.oasis.opendocument.graphics",43)==0)
- *ext="odg";
+ *ext=extension_odg;
else if(compressed_size==46 && memcmp(buffer,"application/vnd.oasis.opendocument.spreadsheet",46)==0)
- *ext="ods";
+ *ext=extension_ods;
else if(compressed_size==47 && memcmp(buffer,"application/vnd.oasis.opendocument.presentation",47)==0)
- *ext="odp";
+ *ext=extension_odp;
else if(memcmp(buffer,"application/x-krita",19)==0)
{
- *ext="kra";
+ *ext=extension_kra;
*krita=19;
}
else
{ /* default to writer */
- *ext="sxw";
+ *ext=extension_sxw;
}
}
/* Zipped Keyhole Markup Language (KML) used by Google Earth */
else if(len==7 && memcmp(filename, "doc.kml", 7)==0)
- *ext="kmz";
+ *ext=extension_kmz;
else if(len==4 && memcmp(filename, "Home", 4)==0)
sh3d=1;
/* Celtx, Screenwriting & Media Pre-production file */
else if(len==9 && memcmp(filename, "local.rdf", 9)==0)
- *ext="celtx";
+ *ext=extension_celtx;
else if(len==13 && memcmp(filename, "document.json", 13)==0)
- *ext="sketch";
+ *ext=extension_sketch;
}
else if(file_nbr==1 && sh3d==1)
{
if(len==1 && filename[0]=='0')
- *ext="sh3d";
+ *ext=extension_sh3d;
}
if(strncmp(filename, "word/", 5)==0)
- ext_msoffice="docx";
+ ext_msoffice=extension_docx;
else if(strncmp(filename, "xl/", 3)==0)
- ext_msoffice="xlsx";
+ ext_msoffice=extension_xlsx;
else if(strncmp(filename, "ppt/", 4)==0)
- ext_msoffice="pptx";
+ ext_msoffice=extension_pptx;
else if(strncmp(filename, "visio/", 6)==0)
- ext_msoffice="vsdx";
+ ext_msoffice=extension_vsdx;
if(msoffice && ext_msoffice!=NULL)
*ext=ext_msoffice;
}
@@ -308,23 +403,22 @@ static int zip_parse_file_entry_fn(file_recovery_t *fr, const char **ext, const
{
/* iWork */
if(len==23 && memcmp(filename, "QuickLook/Thumbnail.jpg", 23)==0)
- *ext="pages";
+ *ext=extension_pages;
else if(len==20 && strncasecmp(filename, "META-INF/MANIFEST.MF", 20)==0)
- *ext="jar";
+ *ext=extension_jar;
else if(len==15 && strncasecmp(filename, "chrome.manifest", 15)==0)
- *ext="xpi";
+ *ext=extension_xpi;
/* SMART Notebook */
else if(len==15 && memcmp(filename, "imsmanifest.xml", 15)==0)
- *ext="notebook";
+ *ext=extension_notebook;
/* Apple Numbers */
else if(len==18 && memcmp(filename, "Index/Document.iwa", 18)==0)
- *ext="numbers";
+ *ext=extension_numbers;
else if(len==19 && memcmp(filename, "AndroidManifest.xml", 19)==0)
- *ext="apk";
+ *ext=extension_apk;
else if(len==30 && memcmp(filename, "xsd/MindManagerApplication.xsd", 30)==0)
- *ext="mmap";
+ *ext=extension_mmap;
}
- free(filename);
return 0;
}
@@ -333,7 +427,67 @@ static int zip_parse_file_entry_fn(file_recovery_t *fr, const char **ext, const
@ requires \valid(fr->handle);
@ requires \valid(ext);
@ requires fr->file_size < 0x8000000000000000 + 4;
- @ requires \separated(fr, ext);
+ @ requires \separated(fr, fr->handle, ext, &first_filename);
+ @ requires *ext == \null ||
+ *ext == extension_apk ||
+ *ext == extension_celtx ||
+ *ext == extension_docx ||
+ *ext == extension_epub ||
+ *ext == extension_jar ||
+ *ext == extension_kmz ||
+ *ext == extension_kra ||
+ *ext == extension_mmap ||
+ *ext == extension_notebook ||
+ *ext == extension_numbers ||
+ *ext == extension_odg ||
+ *ext == extension_odp ||
+ *ext == extension_ods ||
+ *ext == extension_odt ||
+ *ext == extension_ora ||
+ *ext == extension_pages ||
+ *ext == extension_pptx ||
+ *ext == extension_sh3d ||
+ *ext == extension_sketch ||
+ *ext == extension_sxc ||
+ *ext == extension_sxd ||
+ *ext == extension_sxi ||
+ *ext == extension_sxw ||
+ *ext == extension_vsdx ||
+ *ext == extension_xd ||
+ *ext == extension_xlsx ||
+ *ext == extension_xpi ||
+ *ext == extension_xrns ||
+ *ext == file_hint_zip.extension;
+ @ ensures *ext == \null ||
+ *ext == extension_apk ||
+ *ext == extension_celtx ||
+ *ext == extension_docx ||
+ *ext == extension_epub ||
+ *ext == extension_jar ||
+ *ext == extension_kmz ||
+ *ext == extension_kra ||
+ *ext == extension_mmap ||
+ *ext == extension_notebook ||
+ *ext == extension_numbers ||
+ *ext == extension_odg ||
+ *ext == extension_odp ||
+ *ext == extension_ods ||
+ *ext == extension_odt ||
+ *ext == extension_ora ||
+ *ext == extension_pages ||
+ *ext == extension_pptx ||
+ *ext == extension_sh3d ||
+ *ext == extension_sketch ||
+ *ext == extension_sxc ||
+ *ext == extension_sxd ||
+ *ext == extension_sxi ||
+ *ext == extension_sxw ||
+ *ext == extension_vsdx ||
+ *ext == extension_xd ||
+ *ext == extension_xlsx ||
+ *ext == extension_xpi ||
+ *ext == extension_xrns ||
+ *ext == file_hint_zip.extension;
@*/
static int zip_parse_file_entry(file_recovery_t *fr, const char **ext, const unsigned int file_nbr)
{
@@ -349,7 +503,7 @@ static int zip_parse_file_entry(file_recovery_t *fr, const char **ext, const uns
return -1;
}
#if defined(__FRAMAC__)
- Frama_C_make_unknown((char *)&file, sizeof(file));
+ Frama_C_make_unknown(&file, sizeof(file));
#endif
fr->file_size += sizeof(file);
#ifdef DEBUG_ZIP
@@ -377,8 +531,9 @@ static int zip_parse_file_entry(file_recovery_t *fr, const char **ext, const uns
if (len)
{
/*@ assert 0 < len <= 65535; */
- if(zip_parse_file_entry_fn(fr, ext, file_nbr, file, len, &krita) < 0)
+ if(zip_parse_file_entry_fn(fr, ext, file_nbr, &file, len, &krita) < 0)
return -1;
+ /*@ assert krita==0 || krita==19; */
/*@ assert fr->file_size < 0x8000000000000000; */
}
/*@ assert fr->file_size < 0x8000000000000000; */
@@ -422,15 +577,22 @@ static int zip_parse_file_entry(file_recovery_t *fr, const char **ext, const uns
len = le64(extra.compressed_size);
if(len >= 0x8000000000000000)
return -1;
+ /*@ assert len < 0x8000000000000000; */
/* Avoid endless loop */
if( fr->file_size + len < fr->file_size)
return -1;
}
+ /*@ assert len < 0x8000000000000000; */
if(krita>0)
+ {
+ /*@ assert krita==19; */
len=krita;
+ /*@ assert len==19; */
+ }
if (len>0)
{
- /*@ assert len < 0x8000000000000000; */
+ /*@ assert fr->file_size < 0x8000000000000000; */
+ /*@ assert 0 < len < 0x8000000000000000; */
if(fr->file_size + len >= 0x8000000000000000)
return -1;
/*@ assert fr->file_size + len < 0x8000000000000000; */
@@ -469,9 +631,10 @@ static int zip_parse_file_entry(file_recovery_t *fr, const char **ext, const uns
{
if(fr->file_size + pos > 0x7fffffffffffffff)
return -1;
+ /*@ assert fr->file_size + pos < 0x8000000000000000; */
fr->file_size += pos;
- expected_compressed_size=pos;
/*@ assert fr->file_size < 0x8000000000000000; */
+ expected_compressed_size=pos;
}
}
/*@ assert fr->file_size < 0x8000000000000000; */
@@ -481,6 +644,7 @@ static int zip_parse_file_entry(file_recovery_t *fr, const char **ext, const uns
/*@
@ requires \valid(fr);
@ requires \valid(fr->handle);
+ @ requires \separated(fr,fr->handle);
@ ensures \result == -1 || \result == 0;
@*/
static int zip_parse_central_dir(file_recovery_t *fr)
@@ -550,6 +714,7 @@ static int zip_parse_central_dir(file_recovery_t *fr)
/*@
@ requires \valid(fr);
@ requires \valid(fr->handle);
+ @ requires \separated(fr,fr->handle);
@ requires fr->file_size < 0x8000000000000000;
@ ensures \result == -1 || \result == 0;
@*/
@@ -606,6 +771,7 @@ static int zip64_parse_end_central_dir(file_recovery_t *fr)
/*@
@ requires \valid(fr);
@ requires \valid(fr->handle);
+ @ requires \separated(fr,fr->handle);
@ ensures \result == -1 || \result == 0;
@*/
static int zip_parse_end_central_dir(file_recovery_t *fr)
@@ -653,6 +819,7 @@ static int zip_parse_end_central_dir(file_recovery_t *fr)
/*@
@ requires \valid(fr);
@ requires \valid(fr->handle);
+ @ requires \separated(fr,fr->handle);
@ ensures \result == -1 || \result == 0;
@*/
static int zip_parse_data_desc(file_recovery_t *fr)
@@ -689,6 +856,7 @@ static int zip_parse_data_desc(file_recovery_t *fr)
/*@
@ requires \valid(fr);
@ requires \valid(fr->handle);
+ @ requires \separated(fr,fr->handle);
@ ensures \result == -1 || \result == 0;
@*/
static int zip_parse_signature(file_recovery_t *fr)
@@ -726,6 +894,7 @@ static int zip_parse_signature(file_recovery_t *fr)
/*@
@ requires \valid(fr);
@ requires \valid(fr->handle);
+ @ requires \separated(fr,fr->handle);
@ ensures \result == -1 || \result == 0;
@*/
static int zip64_parse_end_central_dir_locator(file_recovery_t *fr)
@@ -762,6 +931,8 @@ static void file_check_zip(file_recovery_t *fr)
fr->file_size = 0;
fr->offset_error=0;
fr->offset_ok=0;
+ /* fr->time is already set to 0 but it helps frama-c */
+ fr->time=0;
first_filename[0]='\0';
if(my_fseek(fr->handle, 0, SEEK_SET) < 0)
return ;
@@ -962,6 +1133,9 @@ static void file_rename_zip(file_recovery_t *file_recovery)
{
unsigned int len;
fclose(fr.handle);
+ /*@
+ @ loop assigns len;
+ @*/
for(len=0; len<32 &&
first_filename[len]!='\0' &&
first_filename[len]!='.' &&
@@ -993,8 +1167,28 @@ static void file_rename_zip(file_recovery_t *file_recovery)
@ ensures (\result == 1) ==> (file_recovery_new->calculated_file_size == 0);
@ ensures (\result == 1) ==> (file_recovery_new->file_size == 0);
@ ensures (\result == 1) ==> (file_recovery_new->data_check == \null);
- @ ensures (\result == 1) ==> (file_recovery_new->file_check == &file_check_zip || file_recovery_new->file_check == \null);
+ @ ensures (\result == 1) ==> file_recovery_new->file_check == &file_check_zip;
@ ensures (\result == 1) ==> (file_recovery_new->file_rename == &file_rename_zip || file_recovery_new->file_rename == \null);
+ @ ensures (\result == 1) ==> (file_recovery_new->extension == file_hint_zip.extension ||
+ file_recovery_new->extension == extension_docx ||
+ file_recovery_new->extension == extension_epub ||
+ file_recovery_new->extension == extension_kra ||
+ file_recovery_new->extension == extension_numbers ||
+ file_recovery_new->extension == extension_odg ||
+ file_recovery_new->extension == extension_odp ||
+ file_recovery_new->extension == extension_ods ||
+ file_recovery_new->extension == extension_odt ||
+ file_recovery_new->extension == extension_ora ||
+ file_recovery_new->extension == extension_pptx ||
+ file_recovery_new->extension == extension_sh3d ||
+ file_recovery_new->extension == extension_sxc ||
+ file_recovery_new->extension == extension_sxd ||
+ file_recovery_new->extension == extension_sxi ||
+ file_recovery_new->extension == extension_sxw ||
+ file_recovery_new->extension == extension_vsdx ||
+ file_recovery_new->extension == extension_xd ||
+ file_recovery_new->extension == extension_xlsx ||
+ file_recovery_new->extension == extension_xrns );
@ ensures (\result == 1) ==> (valid_read_string(file_recovery_new->extension));
@ ensures (\result == 1) ==> \separated(file_recovery_new, file_recovery_new->extension);
@*/
@@ -1019,10 +1213,12 @@ static int header_check_zip(const unsigned char *buffer, const unsigned int buff
#endif
/* A zip file begins by ZIP_FILE_ENTRY, this signature can also be
* found for each compressed file */
- if(file_recovery->file_stat!=NULL &&
- file_recovery->file_stat->file_hint==&file_hint_zip &&
+ if(file_recovery->file_check == &file_check_zip &&
+ file_recovery->file_stat!=NULL &&
+// file_recovery->file_stat->file_hint==&file_hint_zip &&
safe_header_only==0)
{
+ /*@ assert file_recovery->file_check == file_check_zip; */
if(header_ignored_adv(file_recovery, file_recovery_new)==0)
return 0;
}
@@ -1034,56 +1230,56 @@ static int header_check_zip(const unsigned char *buffer, const unsigned int buff
const unsigned int compressed_size=le32(file->compressed_size);
/* Mypaint .ora */
if(compressed_size==16 && memcmp(&buffer[38],"image/openraster",16)==0)
- file_recovery_new->extension="ora";
+ file_recovery_new->extension=extension_ora;
else if(compressed_size==20 && memcmp(&buffer[38],"application/epub+zip",20)==0)
- file_recovery_new->extension="epub";
+ file_recovery_new->extension=extension_epub;
else if(compressed_size==28 && memcmp(&buffer[38],"application/vnd.sun.xml.calc",28)==0)
- file_recovery_new->extension="sxc";
+ file_recovery_new->extension=extension_sxc;
else if(compressed_size==28 && memcmp(&buffer[38],"application/vnd.sun.xml.draw",28)==0)
- file_recovery_new->extension="sxd";
+ file_recovery_new->extension=extension_sxd;
else if(compressed_size==31 && memcmp(&buffer[38],"application/vnd.sun.xml.impress",31)==0)
- file_recovery_new->extension="sxi";
+ file_recovery_new->extension=extension_sxi;
else if(compressed_size==30 && memcmp(&buffer[38],"application/vnd.sun.xml.writer",30)==0)
- file_recovery_new->extension="sxw";
+ file_recovery_new->extension=extension_sxw;
else if(compressed_size==39 && memcmp(&buffer[38],"application/vnd.oasis.opendocument.text",39)==0)
- file_recovery_new->extension="odt";
+ file_recovery_new->extension=extension_odt;
else if(compressed_size==43 && memcmp(&buffer[38],"application/vnd.oasis.opendocument.graphics",43)==0)
- file_recovery_new->extension="odg";
+ file_recovery_new->extension=extension_odg;
else if(compressed_size==45 && memcmp(&buffer[38],"application/vnd.adobe.sparkler.project+dcxucf",45)==0)
- file_recovery_new->extension="xd";
+ file_recovery_new->extension=extension_xd;
else if(compressed_size==46 && memcmp(&buffer[38],"application/vnd.oasis.opendocument.spreadsheet",46)==0)
- file_recovery_new->extension="ods";
+ file_recovery_new->extension=extension_ods;
else if(compressed_size==47 && memcmp(&buffer[38],"application/vnd.oasis.opendocument.presentation",47)==0)
- file_recovery_new->extension="odp";
+ file_recovery_new->extension=extension_odp;
else if(memcmp(&buffer[38],"application/x-krita",19)==0)
- file_recovery_new->extension="kra";
+ file_recovery_new->extension=extension_kra;
else
{ /* default to writer */
- file_recovery_new->extension="sxw";
+ file_recovery_new->extension=extension_sxw;
}
}
else if(len==19 && memcmp(&buffer[30],"[Content_Types].xml",19)==0)
{
if(pos_in_mem(&buffer[0], buffer_size, (const unsigned char*)"word/", 5)!=0)
- file_recovery_new->extension="docx";
+ file_recovery_new->extension=extension_docx;
else if(pos_in_mem(&buffer[0], 2000, (const unsigned char*)"xl/", 3)!=0)
- file_recovery_new->extension="xlsx";
+ file_recovery_new->extension=extension_xlsx;
else if(pos_in_mem(&buffer[0], buffer_size, (const unsigned char*)"ppt/", 4)!=0)
- file_recovery_new->extension="pptx";
+ file_recovery_new->extension=extension_pptx;
else if(pos_in_mem(&buffer[0], buffer_size, (const unsigned char*)"visio/", 6)!=0)
- file_recovery_new->extension="vsdx";
+ file_recovery_new->extension=extension_vsdx;
else
- file_recovery_new->extension="docx";
+ file_recovery_new->extension=extension_docx;
file_recovery_new->file_rename=&file_rename_zip;
}
/* Extended Renoise song file */
else if(len==8 && memcmp(&buffer[30], "Song.xml", 8)==0)
- file_recovery_new->extension="xrns";
+ file_recovery_new->extension=extension_xrns;
else if(len==4 && memcmp(&buffer[30], "Home", 4)==0)
- file_recovery_new->extension="sh3d";
+ file_recovery_new->extension=extension_sh3d;
/* Apple Numbers */
else if(len==18 && memcmp(&buffer[30], "Index/Document.iwa", 18)==0)
- file_recovery_new->extension="numbers";
+ file_recovery_new->extension=extension_numbers;
else
{
file_recovery_new->extension=file_hint_zip.extension;
@@ -1145,6 +1341,7 @@ static void register_header_check_zip(file_stat_t *file_stat)
register_header_check(0, zip_header,sizeof(zip_header), &header_check_zip, file_stat);
register_header_check(0, zip_header2,sizeof(zip_header2), &header_check_winzip, file_stat);
}
+#endif
#if defined(MAIN_zip)
#define BLOCKSIZE 65536u
@@ -1180,6 +1377,7 @@ int main()
register_header_check_zip(&file_stats);
if(header_check_zip(buffer, BLOCKSIZE, 0u, &file_recovery, &file_recovery_new)!=1)
return 0;
+ /*@ assert valid_read_string(file_recovery_new.extension); */
/*@ assert valid_read_string((char *)&fn); */
memcpy(file_recovery_new.filename, fn, sizeof(fn));
file_recovery_new.file_stat=&file_stats;
@@ -1187,6 +1385,7 @@ int main()
/*@ assert file_recovery_new.min_filesize == 30; */
/*@ assert file_recovery_new.file_check == &file_check_zip || file_recovery_new.file_check == \null; */
/*@ assert file_recovery_new.file_stat->file_hint!=NULL; */
+ /*@ assert file_recovery_new.time == 0; */
{
file_recovery_t file_recovery_new2;
file_recovery_new2.blocksize=BLOCKSIZE;
@@ -1194,18 +1393,43 @@ int main()
file_recovery_new2.file_check=NULL;
file_recovery_new2.location.start=BLOCKSIZE;
file_recovery_new.handle=NULL; /* In theory should be not null */
+ /*@ assert file_recovery_new.extension == file_hint_zip.extension ||
+ file_recovery_new.extension == extension_docx ||
+ file_recovery_new.extension == extension_epub ||
+ file_recovery_new.extension == extension_kra ||
+ file_recovery_new.extension == extension_numbers ||
+ file_recovery_new.extension == extension_odg ||
+ file_recovery_new.extension == extension_odp ||
+ file_recovery_new.extension == extension_ods ||
+ file_recovery_new.extension == extension_odt ||
+ file_recovery_new.extension == extension_ora ||
+ file_recovery_new.extension == extension_pptx ||
+ file_recovery_new.extension == extension_sh3d ||
+ file_recovery_new.extension == extension_sxc ||
+ file_recovery_new.extension == extension_sxd ||
+ file_recovery_new.extension == extension_sxi ||
+ file_recovery_new.extension == extension_sxw ||
+ file_recovery_new.extension == extension_vsdx ||
+ file_recovery_new.extension == extension_xd ||
+ file_recovery_new.extension == extension_xlsx ||
+ file_recovery_new.extension == extension_xrns; */
+ /*@ assert valid_read_string(file_recovery_new.extension); */
/*@ assert valid_read_string((char *)file_recovery_new.filename); */
#if defined(__FRAMAC__)
Frama_C_make_unknown((char *)buffer, BLOCKSIZE);
#endif
/*@ assert valid_read_string((char *)file_recovery_new.filename); */
+ /*@ assert valid_read_string(file_recovery_new.extension); */
header_check_zip(buffer, BLOCKSIZE, 0, &file_recovery_new, &file_recovery_new2);
}
+ /*@ assert file_recovery_new.time == 0; */
/*@ assert valid_read_string((char *)file_recovery_new.filename); */
+ /*@ assert valid_read_string(file_recovery_new.extension); */
file_recovery_new.handle=fopen(fn, "rb");
if(file_recovery_new.handle!=NULL && file_recovery_new.file_check !=NULL)
{
/*@ assert file_recovery_new.file_check == &file_check_zip; */
+ /*@ assert file_recovery_new.time == 0; */
file_check_zip(&file_recovery_new);
fclose(file_recovery_new.handle);
}
diff --git a/src/file_zpr.c b/src/file_zpr.c
index 040bf79..723e8ef 100644
--- a/src/file_zpr.c
+++ b/src/file_zpr.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_zpr)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -54,3 +55,4 @@ static void register_header_check_zpr(file_stat_t *file_stat)
{
register_header_check(0, "ZBrush File.", 12, &header_check_zpr, file_stat);
}
+#endif
diff --git a/src/filegen.c b/src/filegen.c
index 4952ee9..751b78f 100644
--- a/src/filegen.c
+++ b/src/filegen.c
@@ -45,9 +45,6 @@
#include "common.h"
#include "filegen.h"
#include "log.h"
-#if defined(__FRAMAC__)
-#include "__fc_builtin.h"
-#endif
static file_check_t file_check_plist={
.list = TD_LIST_HEAD_INIT(file_check_plist.list)
@@ -57,12 +54,17 @@ file_check_list_t file_check_list={
.list = TD_LIST_HEAD_INIT(file_check_list.list)
};
+uint64_t gpls_nbr=0;
+
+// X requires \valid_read(b);
/*@
@ requires \valid_read(a);
- @ requires \valid_read(b);
@ assigns \nothing;
@*/
-static int file_check_cmp(const struct td_list_head *a, const struct td_list_head *b)
+#ifndef __FRAMAC__
+static
+#endif
+int file_check_cmp(const struct td_list_head *a, const struct td_list_head *b)
{
const file_check_t *fc_a=td_list_entry_const(a, const file_check_t, list);
const file_check_t *fc_b=td_list_entry_const(b, const file_check_t, list);
@@ -70,19 +72,24 @@ static int file_check_cmp(const struct td_list_head *a, const struct td_list_hea
unsigned int min_length;
/*@ assert \valid_read(fc_a); */
/*@ assert \valid_read(fc_b); */
+ /*@ assert fc_a->length==0 ==> fc_a->offset == 0; */
+ /*@ assert fc_b->length==0 ==> fc_b->offset == 0; */
if(fc_a->length==0 && fc_b->length!=0)
return -1;
if(fc_a->length!=0 && fc_b->length==0)
return 1;
+ /*@ assert (fc_a->length > 0 && fc_b->length > 0) || (fc_a->length == 0 && fc_b->length == 0) ; */
res=fc_a->offset-fc_b->offset;
if(res!=0)
return res;
+ /*@ assert fc_a->offset == fc_b->offset; */
+ if(fc_a->length==0 && fc_b->length==0)
+ return 0;
+ /*@ assert fc_a->length > 0 && fc_b->length > 0; */
/*@ assert \valid_read((char *)fc_a->value + (0 .. fc_a->length - 1)); */
- /*@ assert \initialized((char *)fc_a->value + (0 .. fc_a->length - 1)); */
-#if 0
/*@ assert \valid_read((char *)fc_b->value + (0 .. fc_b->length - 1)); */
+ /*@ assert \initialized((char *)fc_a->value + (0 .. fc_a->length - 1)); */
/*@ assert \initialized((char *)fc_b->value + (0 .. fc_b->length - 1)); */
-#endif
min_length=fc_a->length<=fc_b->length?fc_a->length:fc_b->length;
res=memcmp(fc_a->value,fc_b->value, min_length);
if(res!=0)
@@ -93,6 +100,7 @@ static int file_check_cmp(const struct td_list_head *a, const struct td_list_hea
/*@
@ requires \valid(file_check_new);
@ requires \valid(pos);
+ @ requires initialization: \initialized(&file_check_new->offset) && \initialized(&file_check_new->length);
@*/
static void file_check_add_tail(file_check_t *file_check_new, file_check_list_t *pos)
{
@@ -103,24 +111,31 @@ static void file_check_add_tail(file_check_t *file_check_new, file_check_list_t
/*@
@ loop unroll 256;
@ loop invariant 0 <= i <= 256;
- @ loop assigns i, newe->file_checks[0 .. 255].list.prev, newe->file_checks[0 .. 255].list.next;
+ @ loop assigns i, newe->file_checks[0 .. i-1].list.prev, newe->file_checks[0 .. i-1].list.next;
@ loop variant 255-i;
@*/
for(i=0;i<256;i++)
{
- newe->file_checks[i].list.prev=&newe->file_checks[i].list;
- newe->file_checks[i].list.next=&newe->file_checks[i].list;
+ TD_INIT_LIST_HEAD(&newe->file_checks[i].list);
/*@ assert newe->file_checks[i].list.prev == &newe->file_checks[i].list; */
/*@ assert newe->file_checks[i].list.next == &newe->file_checks[i].list; */
}
+ /*@ assert 0 <= tmp <= 255; */
/*@ assert newe->file_checks[tmp].list.prev == &newe->file_checks[tmp].list; */
+ /*@ assert newe->file_checks[tmp].list.next == &newe->file_checks[tmp].list; */
td_list_add_tail(&file_check_new->list, &newe->file_checks[tmp].list);
td_list_add_tail(&newe->list, &pos->list);
}
-void register_header_check(const unsigned int offset, const void *value, const unsigned int length, int (*header_check)(const unsigned char *buffer, const unsigned int buffer_size,
+/*@
+ @ requires \valid_read((const char *)value + (0 .. length-1));
+ @ requires \valid_function(header_check);
+ @ requires separation: \separated(file_stat, &file_check_plist);
+ @*/
+void register_header_check(const unsigned int offset, const void *value, const unsigned int length,
+ int (*header_check)(const unsigned char *buffer, const unsigned int buffer_size,
const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new),
- file_stat_t *file_stat)
+ file_stat_t *file_stat)
{
file_check_t *file_check_new=(file_check_t *)MALLOC(sizeof(*file_check_new));
file_check_new->value=value;
@@ -133,9 +148,12 @@ void register_header_check(const unsigned int offset, const void *value, const u
/*@
@ requires \valid(file_check_new);
+ @ requires initialization: \initialized(&file_check_new->offset) && \initialized(&file_check_new->length);
+ @ requires \valid_function(file_check_new->header_check);
@*/
static void index_header_check_aux(file_check_t *file_check_new)
{
+ /* file_check_list is sorted by increasing offset */
if(file_check_new->length>0)
{
/*@ assert file_check_new->offset < 0x80000000; */
@@ -172,7 +190,9 @@ static unsigned int index_header_check(void)
{
file_check_t *current_check;
current_check=td_list_entry(tmp, file_check_t, list);
+ /* dettach current_check from file_check_plist */
td_list_del(tmp);
+ /*@ assert \initialized(&current_check->offset) && \initialized(&current_check->length); */
index_header_check_aux(current_check);
nbr++;
}
@@ -229,8 +249,14 @@ void file_allow_nl(file_recovery_t *file_recovery, const unsigned int nl_mode)
{
unsigned char buffer[4096];
int taille;
+ if(file_recovery->file_size >= 0x8000000000000000-2)
+ return ;
+ /*@ assert \valid(file_recovery->handle); */
if(my_fseek(file_recovery->handle, file_recovery->file_size,SEEK_SET)<0)
+ {
+ /*@ assert \valid(file_recovery->handle); */
return;
+ }
taille=fread(buffer,1, 4096,file_recovery->handle);
#ifdef __FRAMAC__
Frama_C_make_unknown((char *)&buffer, 4096);
@@ -241,20 +267,24 @@ void file_allow_nl(file_recovery_t *file_recovery, const unsigned int nl_mode)
file_recovery->file_size+=2;
else if(taille > 0 && buffer[0]=='\r' && (nl_mode&NL_BARECR)==NL_BARECR)
file_recovery->file_size++;
+ /*@ assert \valid(file_recovery->handle); */
}
uint64_t file_rsearch(FILE *handle, uint64_t offset, const void*footer, const unsigned int footer_length)
{
- unsigned char*buffer;
- assert(footer_length < 4096);
- /*@ assert 0 < footer_length < 4096; */
/*
* 4096+footer_length-1: required size
* 4096+footer_length: to avoid a Frama-C warning when footer_length==1
* 8192: maximum size
* */
- buffer=(unsigned char*)MALLOC(4096+footer_length);
- memset(buffer+4096,0,footer_length-1);
+ char buffer[8192];
+ assert(footer_length < 4096);
+ /*@ assert 0 < footer_length < 4096; */
+ memset(&buffer[4096],0,footer_length-1);
+ /*@
+ @ loop assigns errno, *handle, Frama_C_entropy_source;
+ @ loop assigns offset, buffer[0 .. 8192-1];
+ @*/
do
{
int i;
@@ -266,27 +296,24 @@ uint64_t file_rsearch(FILE *handle, uint64_t offset, const void*footer, const un
else
offset=offset-(offset%4096);
if(my_fseek(handle,offset,SEEK_SET)<0)
- {
- free(buffer);
return 0;
- }
- taille=fread(buffer, 1, 4096, handle);
+ taille=fread(&buffer, 1, 4096, handle);
if(taille <= 0)
- {
- free(buffer);
return 0;
- }
+ /*@ assert 0 < taille <= 4096; */
+#ifdef __FRAMAC__
+ Frama_C_make_unknown(&buffer, 4096);
+#endif
+ /*@ loop assigns i; */
for(i=taille-1;i>=0;i--)
{
- if(buffer[i]==*(const unsigned char *)footer && memcmp(buffer+i,footer,footer_length)==0)
+ if(buffer[i]==*(const char *)footer && memcmp(&buffer[i],footer,footer_length)==0)
{
- free(buffer);
return offset + i;
}
}
memcpy(buffer+4096,buffer,footer_length-1);
} while(offset>0);
- free(buffer);
return 0;
}
@@ -300,54 +327,6 @@ void file_search_footer(file_recovery_t *file_recovery, const void*footer, const
/*@ assert \valid(file_recovery->handle); */
}
-#if 0
-/*@
- @ requires \valid(file_recovery);
- @ requires footer_length > 0;
- @ requires \valid_read((char *)footer+(0..footer_length-1));
- @*/
-static void file_search_lc_footer(file_recovery_t *file_recovery, const unsigned char*footer, const unsigned int footer_length)
-{
- const unsigned int read_size=4096;
- unsigned char*buffer;
- int64_t file_size;
- if(footer_length==0)
- return ;
- buffer=(unsigned char*)MALLOC(read_size+footer_length-1);
- file_size=file_recovery->file_size;
- memset(buffer+read_size,0,footer_length-1);
- do
- {
- int i;
- int taille;
- if(file_size%read_size!=0)
- file_size=file_size-(file_size%read_size);
- else
- file_size-=read_size;
- if(my_fseek(file_recovery->handle,file_size,SEEK_SET)<0)
- {
- free(buffer);
- return;
- }
- taille=fread(buffer,1,read_size,file_recovery->handle);
- for(i=0;i<taille;i++)
- buffer[i]=tolower(buffer[i]);
- for(i=taille-1;i>=0;i--)
- {
- if(buffer[i]==footer[0] && memcmp(buffer+i,footer,footer_length)==0)
- {
- file_recovery->file_size=file_size+i+footer_length;
- free(buffer);
- return;
- }
- }
- memcpy(buffer+read_size,buffer,footer_length-1);
- } while(file_size>0);
- file_recovery->file_size=0;
- free(buffer);
-}
-#endif
-
data_check_t data_check_size(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
if(file_recovery->file_size + buffer_size/2 >= file_recovery->calculated_file_size)
@@ -408,24 +387,25 @@ file_stat_t * init_file_stats(file_enable_t *files_enable)
file_enable_t *file_enable;
unsigned int enable_count=1; /* Lists are terminated by NULL */
unsigned int sign_nbr;
+ /*@ loop assigns enable_count, file_enable; */
for(file_enable=files_enable;file_enable->file_hint!=NULL;file_enable++)
{
- if(file_enable->enable>0)
+ if(file_enable->enable>0 && file_enable->file_hint->register_header_check!=NULL)
{
enable_count++;
}
}
+ /*@ assert enable_count > 0; */
file_stats=(file_stat_t *)MALLOC(enable_count * sizeof(file_stat_t));
enable_count=0;
for(file_enable=files_enable;file_enable->file_hint!=NULL;file_enable++)
{
- if(file_enable->enable>0)
+ if(file_enable->enable>0 && file_enable->file_hint->register_header_check!=NULL)
{
file_stats[enable_count].file_hint=file_enable->file_hint;
file_stats[enable_count].not_recovered=0;
file_stats[enable_count].recovered=0;
- if(file_enable->file_hint->register_header_check!=NULL)
- file_enable->file_hint->register_header_check(&file_stats[enable_count]);
+ file_enable->file_hint->register_header_check(&file_stats[enable_count]);
enable_count++;
}
}
@@ -439,7 +419,8 @@ file_stat_t * init_file_stats(file_enable_t *files_enable)
@ requires \valid(file_recovery);
@ requires valid_read_string((const char*)&file_recovery->filename);
@ requires valid_read_string(new_ext);
- @ ensures valid_read_string((char*)&file_recovery->filename);
+ @ requires separation: \separated(file_recovery, new_ext);
+ @ ensures valid_read_string((const char*)&file_recovery->filename);
@*/
static int file_rename_aux(file_recovery_t *file_recovery, const char *new_ext)
{
@@ -451,14 +432,16 @@ static int file_rename_aux(file_recovery_t *file_recovery, const char *new_ext)
/*@ assert valid_read_string(&file_recovery->filename[0]); */
if(len > sizeof(file_recovery->filename))
{
+ /*@ assert valid_read_string((const char *)&file_recovery->filename); */
return -1;
}
/*@ assert len <= sizeof(file_recovery->filename); */
/*@ assert valid_read_string((char*)&file_recovery->filename); */
strcpy(new_filename, (char *)&file_recovery->filename);
- dst_dir_sep=strrchr(new_filename, '/');
#ifndef __FRAMAC__
- /*@ assert valid_read_string(dst_dir_sep); */
+ /*@ assert valid_string((char *)&new_filename); */
+ dst_dir_sep=strrchr(new_filename, '/');
+ /*@ assert valid_string(dst_dir_sep); */
dst=dst_dir_sep;
while(*dst!='.' && *dst!='\0')
dst++;
@@ -471,23 +454,25 @@ static int file_rename_aux(file_recovery_t *file_recovery, const char *new_ext)
*dst++ = *src++;
*dst='\0';
}
-#endif
- /*@ assert valid_read_string(&new_filename[0]); */
+ /*@ assert valid_string(&new_filename[0]); */
if(strlen(new_filename) >= sizeof(file_recovery->filename))
{
- /*@ assert valid_read_string(&file_recovery->filename[0]); */
+ /*@ assert valid_read_string((const char *)&file_recovery->filename); */
return -1;
}
/*@ assert valid_read_string(&new_filename[0]); */
if(rename(&file_recovery->filename[0], new_filename)<0)
{
/* Rename has failed */
- /*@ assert valid_read_string(&file_recovery->filename[0]); */
+ /*@ assert valid_read_string((const char *)&file_recovery->filename); */
return -1;
}
/*@ assert valid_read_string(&new_filename[0]); */
strcpy(file_recovery->filename, new_filename);
- /*@ assert valid_read_string(&file_recovery->filename[0]); */
+#else
+ file_recovery->filename[0]='/';
+#endif
+ /*@ assert valid_read_string((const char *)&file_recovery->filename); */
return 0;
}
@@ -816,6 +801,7 @@ void get_prev_location_smart(const alloc_data_t *list_search_space, alloc_data_t
alloc_data_t *file_space=*current_search_space;
if(offset_skipped_header==0)
return ;
+ gpls_nbr++;
while(1)
{
file_space=td_list_prev_entry(file_space, list);
@@ -876,7 +862,6 @@ int my_fseek(FILE *stream, off_t offset, int whence)
time_t get_time_from_YYMMDDHHMMSS(const char *date_asc)
{
struct tm tm_time;
- memset(&tm_time, 0, sizeof(tm_time));
tm_time.tm_sec=(date_asc[10]-'0')*10+(date_asc[11]-'0'); /* seconds 0-59 */
tm_time.tm_min=(date_asc[8]-'0')*10+(date_asc[9]-'0'); /* minutes 0-59 */
tm_time.tm_hour=(date_asc[6]-'0')*10+(date_asc[7]-'0'); /* hours 0-23*/
@@ -894,7 +879,6 @@ time_t get_time_from_YYYY_MM_DD_HH_MM_SS(const unsigned char *date_asc)
struct tm tm_time;
if(memcmp(date_asc, "0000", 4)==0)
return (time_t)0;
- memset(&tm_time, 0, sizeof(tm_time));
tm_time.tm_sec=(date_asc[17]-'0')*10+(date_asc[18]-'0'); /* seconds 0-59 */
tm_time.tm_min=(date_asc[14]-'0')*10+(date_asc[15]-'0'); /* minutes 0-59 */
tm_time.tm_hour=(date_asc[11]-'0')*10+(date_asc[12]-'0'); /* hours 0-23*/
@@ -911,7 +895,6 @@ time_t get_time_from_YYYY_MM_DD_HHMMSS(const char *date_asc)
struct tm tm_time;
if(memcmp(date_asc, "0000", 4)==0)
return (time_t)0;
- memset(&tm_time, 0, sizeof(tm_time));
tm_time.tm_sec=(date_asc[15]-'0')*10+(date_asc[16]-'0'); /* seconds 0-59 */
tm_time.tm_min=(date_asc[13]-'0')*10+(date_asc[14]-'0'); /* minutes 0-59 */
tm_time.tm_hour=(date_asc[11]-'0')*10+(date_asc[12]-'0'); /* hours 0-23*/
@@ -926,7 +909,6 @@ time_t get_time_from_YYYY_MM_DD_HHMMSS(const char *date_asc)
time_t get_time_from_YYYYMMDD_HHMMSS(const char *date_asc)
{
struct tm tm_time;
- memset(&tm_time, 0, sizeof(tm_time));
tm_time.tm_sec=(date_asc[13]-'0')*10+(date_asc[14]-'0'); /* seconds 0-59 */
tm_time.tm_min=(date_asc[11]-'0')*10+(date_asc[12]-'0'); /* minutes 0-59 */
tm_time.tm_hour=(date_asc[9]-'0')*10+(date_asc[10]-'0'); /* hours 0-23*/
diff --git a/src/filegen.h b/src/filegen.h
index 573997c..6dc76b4 100644
--- a/src/filegen.h
+++ b/src/filegen.h
@@ -24,6 +24,9 @@
#ifdef __cplusplus
extern "C" {
#endif
+#if defined(__FRAMAC__)
+#include "__fc_builtin.h"
+#endif
#include "list.h"
@@ -123,23 +126,29 @@ void free_header_check(void);
/*@
@ requires \valid(file_recovery);
@ requires \valid(file_recovery->handle);
+ @ requires \separated(file_recovery, file_recovery->handle);
@ ensures file_recovery->handle == \old(file_recovery->handle);
@*/
void file_allow_nl(file_recovery_t *file_recovery, const unsigned int nl_mode);
/*@
@ requires \valid(handle);
- @ requires footer_length > 0;
+ @ requires 0 < footer_length < 4096;
@ requires \valid_read((char *)footer+(0..footer_length-1));
+ @ requires \separated(handle, (char *)footer + (..), &errno, &Frama_C_entropy_source);
+ @ assigns *handle, errno, Frama_C_entropy_source;
@*/
uint64_t file_rsearch(FILE *handle, uint64_t offset, const void*footer, const unsigned int footer_length);
/*@
@ requires \valid(file_recovery);
@ requires \valid(file_recovery->handle);
- @ requires footer_length > 0;
+ @ requires 0 < footer_length < 4096;
@ requires \valid_read((char *)footer+(0..footer_length-1));
+ @ requires \separated(file_recovery, file_recovery->handle, file_recovery->extension, &errno, &Frama_C_entropy_source);
@ ensures \valid(file_recovery->handle);
+ @ assigns *file_recovery->handle, errno, file_recovery->file_size;
+ @ assigns Frama_C_entropy_source;
@*/
void file_search_footer(file_recovery_t *file_recovery, const void*footer, const unsigned int footer_length, const unsigned int extra_length);
@@ -269,8 +278,11 @@ void header_ignored(const file_recovery_t *file_recovery_new);
@ requires separation: \separated(file_recovery, file_recovery_new, &errno);
@ requires \valid_read(file_recovery);
@ requires \valid_read(file_recovery_new);
+ @ requires file_recovery->handle == \null || \valid(file_recovery->handle);
+ @ requires \valid_function(file_recovery->file_check);
@ requires \initialized(&file_recovery->file_check);
@ requires \initialized(&file_recovery->handle);
+ @ requires \separated(file_recovery, file_recovery->handle);
@ ensures \result == 0 || \result == 1;
@*/
int header_ignored_adv(const file_recovery_t *file_recovery, const file_recovery_t *file_recovery_new);
@@ -287,21 +299,25 @@ int my_fseek(FILE *stream, off_t offset, int whence);
/*@
@ requires \valid_read(date_asc + (0 .. 11));
+ @ assigns \nothing;
@*/
time_t get_time_from_YYMMDDHHMMSS(const char *date_asc);
/*@
@ requires \valid_read(date_asc + (0 .. 18));
+ @ assigns \nothing;
@*/
time_t get_time_from_YYYY_MM_DD_HH_MM_SS(const unsigned char *date_asc);
/*@
@ requires \valid_read(date_asc + (0 .. 16));
+ @ assigns \nothing;
@*/
time_t get_time_from_YYYY_MM_DD_HHMMSS(const char *date_asc);
/*@
@ requires \valid_read(date_asc + (0 .. 14));
+ @ assigns \nothing;
@*/
time_t get_time_from_YYYYMMDD_HHMMSS(const char *date_asc);
@@ -311,6 +327,7 @@ time_t get_time_from_YYYYMMDD_HHMMSS(const char *date_asc);
@ requires \valid(offset);
@*/
void get_prev_location_smart(const alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset, const uint64_t prev_location);
+
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/fnctdsk.c b/src/fnctdsk.c
index 0a766b2..f483ce2 100644
--- a/src/fnctdsk.c
+++ b/src/fnctdsk.c
@@ -38,8 +38,17 @@
#include "log_part.h"
#include "guid_cpy.h"
-static unsigned int get_geometry_from_list_part_aux(const disk_t *disk_car, const list_part_t *list_part, const int verbose);
-static list_part_t *element_new(partition_t *part);
+/*@
+ @ requires \valid(part);
+ @*/
+static list_part_t *element_new(partition_t *part)
+{
+ list_part_t *new_element=(list_part_t*)MALLOC(sizeof(*new_element));
+ new_element->part=part;
+ new_element->prev=new_element->next=NULL;
+ new_element->to_be_removed=0;
+ return new_element;
+}
unsigned long int C_H_S2LBA(const disk_t *disk_car,const unsigned int C, const unsigned int H, const unsigned int S)
{
@@ -318,19 +327,16 @@ partition_t *partition_new