PhotoRec recover

- fbx: Kaydara 3D file
- hdf: Hierarchical Data Format 5
- lz: lzip compressed file
This commit is contained in:
Christophe Grenier 2022-03-24 13:31:17 +01:00
parent 4b93bbcc15
commit 1b8f211d4a
5 changed files with 238 additions and 0 deletions

View file

@ -158,6 +158,7 @@ file_C = filegen.c \
file_fat.c \
file_fbf.c \
file_fbk.c \
file_fbx.c \
file_fcp.c \
file_fcs.c \
file_fdb.c \
@ -192,6 +193,7 @@ file_C = filegen.c \
file_gsm.c \
file_gz.c \
file_hdf.c \
file_hdf5.c \
file_hdr.c \
file_hds.c \
file_hfsp.c \
@ -223,6 +225,7 @@ file_C = filegen.c \
file_lso.c \
file_luks.c \
file_lxo.c \
file_lz.c \
file_lzh.c \
file_lzo.c \
file_m2ts.c \

77
src/file_fbx.c Normal file
View file

@ -0,0 +1,77 @@
/*
File: file_fbx.c
Copyright (C) 2022 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_fbx)
#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"
/*@ requires valid_register_header_check(file_stat); */
static void register_header_check_fbx(file_stat_t *file_stat);
const file_hint_t file_hint_fbx= {
.extension="fbx",
.description="Kaydara 3D file",
.max_filesize=PHOTOREC_MAX_FILE_SIZE,
.recover=1,
.enable_by_default=1,
.register_header_check=&register_header_check_fbx
};
/*@
@ requires valid_file_check_param(file_recovery);
@ ensures valid_file_check_result(file_recovery);
@ assigns *file_recovery_new;
@*/
static void file_check_fbx(file_recovery_t *file_recovery)
{
const unsigned char fbx_footer[11]= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
};
file_search_footer(file_recovery, fbx_footer, sizeof(fbx_footer), 237);
}
/*@
@ requires valid_header_check_param(buffer, buffer_size, safe_header_only, file_recovery, file_recovery_new);
@ ensures valid_header_check_result(\result, file_recovery_new);
@*/
static int header_check_fbx(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)
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_fbx.extension;
file_recovery_new->file_check=&file_check_fbx;
return 1;
}
static void register_header_check_fbx(file_stat_t *file_stat)
{
/* Signature ends by two spaces and a NULL */
register_header_check(0, "Kaydara FBX Binary ", 20, &header_check_fbx, file_stat);
}
#endif

81
src/file_hdf5.c Normal file
View file

@ -0,0 +1,81 @@
/*
File: file_hdf5.c
Copyright (C) 2022 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_hdf)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <stdio.h>
#include "types.h"
#include "filegen.h"
#include "common.h"
#ifdef DEBUG_HDF
#include "log.h"
#endif
/*@ requires valid_register_header_check(file_stat); */
static void register_header_check_hdf5(file_stat_t *file_stat);
const file_hint_t file_hint_hdf5= {
.extension="hdf",
.description="Hierarchical Data Format 5",
.max_filesize=PHOTOREC_MAX_SIZE_32,
.recover=1,
.enable_by_default=1,
.register_header_check=&register_header_check_hdf5
};
struct hdf5_superblock
{
uint8_t signature[8];
uint8_t version;
};
/*@
@ requires buffer_size >= sizeof(struct hdf5_superblock);
@ requires separation: \separated(&file_hint_hdf5, buffer+(..), file_recovery, file_recovery_new);
@ requires valid_header_check_param(buffer, buffer_size, safe_header_only, file_recovery, file_recovery_new);
@ ensures valid_header_check_result(\result, file_recovery_new);
@ assigns *file_recovery_new;
@*/
static int header_check_hdf5(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 hdf5_superblock *sb=(const struct hdf5_superblock*)&buffer[0];
if(sb->version > 2)
return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_hdf5.extension;
return 1;
}
static void register_header_check_hdf5(file_stat_t *file_stat)
{
static const unsigned char hdf5_header[8]= { 0x89, 'H', 'D', 'F', '\r', '\n', 0x1a, '\n'};
register_header_check(0, hdf5_header, sizeof(hdf5_header), &header_check_hdf5, file_stat);
}
#endif

View file

@ -136,6 +136,7 @@ extern const file_hint_t file_hint_ext2_fs;
extern const file_hint_t file_hint_fat;
extern const file_hint_t file_hint_fbf;
extern const file_hint_t file_hint_fbk;
extern const file_hint_t file_hint_fbx;
extern const file_hint_t file_hint_fcp;
extern const file_hint_t file_hint_fcs;
extern const file_hint_t file_hint_fdb;
@ -171,6 +172,7 @@ extern const file_hint_t file_hint_gpx;
extern const file_hint_t file_hint_gsm;
extern const file_hint_t file_hint_gz;
extern const file_hint_t file_hint_hdf;
extern const file_hint_t file_hint_hdf5;
extern const file_hint_t file_hint_hdr;
extern const file_hint_t file_hint_hds;
extern const file_hint_t file_hint_hfsp;
@ -202,6 +204,7 @@ extern const file_hint_t file_hint_lnk;
extern const file_hint_t file_hint_lso;
extern const file_hint_t file_hint_luks;
extern const file_hint_t file_hint_lxo;
extern const file_hint_t file_hint_lz;
extern const file_hint_t file_hint_lzh;
extern const file_hint_t file_hint_lzo;
extern const file_hint_t file_hint_m2ts;
@ -701,6 +704,9 @@ file_enable_t array_file_enable[]=
#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fbk)
{ .enable=0, .file_hint=&file_hint_fbk },
#endif
#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fbx)
{ .enable=0, .file_hint=&file_hint_fbx },
#endif
#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fcp)
{ .enable=0, .file_hint=&file_hint_fcp },
#endif
@ -803,6 +809,9 @@ file_enable_t array_file_enable[]=
#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hdf)
{ .enable=0, .file_hint=&file_hint_hdf },
#endif
#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hdf5)
{ .enable=0, .file_hint=&file_hint_hdf5 },
#endif
#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_hdr)
{ .enable=0, .file_hint=&file_hint_hdr },
#endif
@ -897,6 +906,7 @@ file_enable_t array_file_enable[]=
{ .enable=0, .file_hint=&file_hint_lxo },
#endif
#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lzh)
{ .enable=0, .file_hint=&file_hint_lz },
{ .enable=0, .file_hint=&file_hint_lzh },
#endif
#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_lzo)

67
src/file_lz.c Normal file
View file

@ -0,0 +1,67 @@
/*
File: file_lz.c
Copyright (C) 2022 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_lz)
#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"
/*@ requires valid_register_header_check(file_stat); */
static void register_header_check_lz(file_stat_t *file_stat);
const file_hint_t file_hint_lz= {
.extension="lz",
.description="lzip compressed file",
.max_filesize=PHOTOREC_MAX_FILE_SIZE,
.recover=1,
.enable_by_default=1,
.register_header_check=&register_header_check_lz
};
/*@
@ requires separation: \separated(&file_hint_lz, buffer+(..), file_recovery, file_recovery_new);
@ requires valid_header_check_param(buffer, buffer_size, safe_header_only, file_recovery, file_recovery_new);
@ ensures valid_header_check_result(\result, file_recovery_new);
@ assigns *file_recovery_new;
@*/
static int header_check_lz(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)
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_lz.extension;
return 1;
}
static void register_header_check_lz(file_stat_t *file_stat)
{
static const unsigned char lz_header[5]= {
'L' , 'Z' , 'I' , 'P' , 0x01
};
register_header_check(0, lz_header, sizeof(lz_header), &header_check_lz, file_stat);
}
#endif