PhotoRec: Better signature for Mac Picture .pct

This commit is contained in:
Christophe Grenier 2008-05-30 18:07:34 +02:00
parent 03921e92a3
commit 6c28be2d43

View file

@ -28,6 +28,7 @@
#include <stdio.h>
#include "types.h"
#include "filegen.h"
#include "common.h"
#include "log.h"
static void register_header_check_pct(file_stat_t *file_stat);
@ -51,6 +52,34 @@ static const unsigned char pct_header[6]= { 0x00, 0x11, 0x02, 0xff, 0x0c, 0x00};
SHORT Version number (0x02ff)
SHORT Header opcode for Version 2 (0C00)
*/
struct pct_file_entry {
uint16_t filesize; /* 0x00 */
uint16_t XMin; /* 0x02 72 DPI */
uint16_t YMin; /* 0x04 */
uint16_t XMax; /* 0x06 */
uint16_t YMax; /* 0x08 */
uint16_t VersionOperator; /* 0x0A 0x0011 */
uint16_t VersionNumber; /* 0x0C 0x02ff */
uint16_t HeaderOpcode; /* 0x0E 0x0C00 */
uint16_t Val; /* 0x10 0xFFEF or 0xFFEE */
uint16_t Reserved; /* 0x12 0x0000 */
uint32_t HDPI; /* 0x14 */
uint32_t VDPI; /* 0x18 */
#if 0
uint16_t OYMax; // pbmplus format
uint16_t OYMin;
uint16_t OXMax;
uint16_t OXMin;
#else
uint16_t OXMin;
uint16_t OYMin;
uint16_t OXMax;
uint16_t OYMax;
#endif
uint32_t Reserved2; /* 0x24 */
} __attribute__ ((__packed__));
static void register_header_check_pct(file_stat_t *file_stat)
{
register_header_check(0x20a, pct_header,sizeof(pct_header), &header_check_pct, file_stat);
@ -58,13 +87,29 @@ static void register_header_check_pct(file_stat_t *file_stat)
static int header_check_pct(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(memcmp(&buffer[0x20a],pct_header,sizeof(pct_header))==0)
const struct pct_file_entry *pct=(const struct pct_file_entry *)(&buffer[0x200]);
if(memcmp(&buffer[0x20a],pct_header,sizeof(pct_header))==0 &&
be16(pct->XMin) <= be16(pct->XMax) &&
be16(pct->YMin) <= be16(pct->YMax) &&
((be16(pct->OXMin) <= be16(pct->OXMax) &&
be16(pct->OYMin) <= be16(pct->OYMax)) ||
(be16(pct->OYMax) <= be16(pct->OXMax) && /* pbmplus creates boggus files */
be16(pct->OYMin) <= be16(pct->OXMin))) &&
be16(pct->XMin)==0 && /* Reject some valid but uncommon files */
be16(pct->YMin)==0 &&
be16(pct->OYMin)==0)
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_pct.extension;
/* We only have the low 16bits of the filesystem */
file_recovery_new->min_filesize=0x200+(buffer[0x200]<<8)+buffer[0x201];
file_recovery_new->file_check=&file_check_pct;
log_info("X %u-%u, Y %u-%u\n",
be16(pct->XMin), be16(pct->XMax),
be16(pct->YMin), be16(pct->YMax));
log_info("X %u-%u, Y %u-%u\n",
be16(pct->OXMin), be16(pct->OXMax),
be16(pct->OYMin), be16(pct->OYMax));
return 1;
}
return 0;