summaryrefslogtreecommitdiffstats
path: root/src/file_amr.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-08-13 08:30:18 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2014-08-13 08:30:18 +0200
commita1a32e76523423ae55896c00137587a0f3ef7429 (patch)
tree510848a9d47606ab864d4ab59efa2bbf4d80021a /src/file_amr.c
parent1643d9e65b28330eac72676f479b77d7e850f033 (diff)
PhotoRec: detect .amr file size
Diffstat (limited to 'src/file_amr.c')
-rw-r--r--src/file_amr.c73
1 files changed, 38 insertions, 35 deletions
diff --git a/src/file_amr.c b/src/file_amr.c
index ee3df23..02e0429 100644
--- a/src/file_amr.c
+++ b/src/file_amr.c
@@ -44,51 +44,54 @@ const file_hint_t file_hint_amr= {
.register_header_check=&register_header_check_amr
};
-/* AMR file format is described in
- * http://wiki.forum.nokia.com/index.php?title=Special:PdfPrint&page=AMR_format
- * ftp://ftp.rfc-editor.org/in-notes/rfc3267.txt */
-
-static const unsigned char amr_header[6]= {'#','!','A','M','R','\n'};
-
-static void register_header_check_amr(file_stat_t *file_stat)
-{
- register_header_check(0, amr_header,sizeof(amr_header), &header_check_amr, file_stat);
-}
-
-#if 0
static data_check_t data_check_amr(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
- file_recovery->calculated_file_size + 2 < file_recovery->file_size + buffer_size/2)
+ file_recovery->calculated_file_size + 4 < file_recovery->file_size + buffer_size/2)
{
const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
- switch(buffer[i]&0x70)
+#ifdef DEBUG_AMR
+ log_info("data_check_amr %04x %02x %u\n", file_recovery->calculated_file_size, buffer[i], (buffer[i]>>1)&7);
+#endif
+ if((buffer[i]&0x83)!=0)
+ return DC_STOP;
+ if(buffer[i]==0 && buffer[i+1]==0 && buffer[i+2]==0 && buffer[i+3]==0)
+ return DC_STOP;
+ switch((buffer[i]>>3)&0x7)
{
- case 0x00: file_recovery->calculated_file_size+=13; break;
- case 0x10: file_recovery->calculated_file_size+=14; break;
- case 0x20: file_recovery->calculated_file_size+=16; break;
- case 0x30: file_recovery->calculated_file_size+=18; break;
- case 0x40: file_recovery->calculated_file_size+=20; break;
- case 0x50: file_recovery->calculated_file_size+=21; break;
- case 0x60: file_recovery->calculated_file_size+=27; break;
- case 0x70: file_recovery->calculated_file_size+=32; break;
+ case 0: file_recovery->calculated_file_size+=13; break;
+ case 1: file_recovery->calculated_file_size+=14; break;
+ case 2: file_recovery->calculated_file_size+=16; break;
+ case 3: file_recovery->calculated_file_size+=18; break;
+ case 4: file_recovery->calculated_file_size+=20; break;
+ case 5: file_recovery->calculated_file_size+=21; break;
+ case 6: file_recovery->calculated_file_size+=27; break;
+ case 7: file_recovery->calculated_file_size+=32; break;
}
}
return DC_CONTINUE;
}
-#endif
+
static int header_check_amr(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,amr_header,sizeof(amr_header))==0)
- {
- reset_file_recovery(file_recovery_new);
-#if 0
- file_recovery_new->calculated_file_size=6;
- file_recovery_new->data_check=&data_check_amr;
- file_recovery_new->file_check=&file_check_size;
-#endif
- file_recovery_new->extension=file_hint_amr.extension;
- return 1;
- }
- return 0;
+ if((buffer[6]&0x83)!=0)
+ return 0;
+ if(buffer[6]==0 && buffer[6+1]==0 && buffer[6+2]==0 && buffer[6+3]==0)
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->calculated_file_size=6;
+ file_recovery_new->data_check=&data_check_amr;
+ file_recovery_new->file_check=&file_check_size;
+ file_recovery_new->extension=file_hint_amr.extension;
+ return 1;
+}
+
+/* AMR file format is described in
+ * http://developer.nokia.com/community/wiki/AMR_format
+ * ftp://ftp.rfc-editor.org/in-notes/rfc3267.txt */
+
+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);
}