summaryrefslogtreecommitdiffstats
path: root/src/file_pyc.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2016-02-21 10:24:17 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2016-02-21 10:24:17 +0100
commitf68cd0f314d2cb650d10cc5e53e9cae19eb74980 (patch)
tree103f9ebae21efe3e6f65f23c6c69a81160591fa6 /src/file_pyc.c
parentc566d9ade4d988f72b723b92765d0cc9117c772b (diff)
PhotoRec: recover python 3.3 and 3.4 .pyc
Diffstat (limited to 'src/file_pyc.c')
-rw-r--r--src/file_pyc.c69
1 files changed, 28 insertions, 41 deletions
diff --git a/src/file_pyc.c b/src/file_pyc.c
index c69232f..ed70e83 100644
--- a/src/file_pyc.c
+++ b/src/file_pyc.c
@@ -46,26 +46,39 @@ const file_hint_t file_hint_pyc= {
.register_header_check=&register_header_check_pyc
};
-static const unsigned char pyc_15_magic[4]= { 0x99, 0x4e, '\r', '\n'};
-static const unsigned char pyc_20_magic[4]= { 0x87, 0xc6, '\r', '\n'};
-static const unsigned char pyc_21_magic[4]= { 0x2a, 0xeb, '\r', '\n'};
-static const unsigned char pyc_22_magic[4]= { 0x2d, 0xed, '\r', '\n'};
-static const unsigned char pyc_23_magic[4]= { 0x3b, 0xf2, '\r', '\n'};
-static const unsigned char pyc_24_magic[4]= { 0x6d, 0xf2, '\r', '\n'};
-static const unsigned char pyc_25_magic[4]= { 0xb3, 0xf2, '\r', '\n'};
-static const unsigned char pyc_26_magic[4]= { 0xd1, 0xf2, '\r', '\n'};
-static const unsigned char pyc_27_magic[4]= { 0x03, 0xf3, '\r', '\n'};
-static const unsigned char pyc_30_magic[4]= { 0x3b, 0x0c, '\r', '\n'};
-static const unsigned char pyc_31_magic[4]= { 0x4f, 0x0c, '\r', '\n'};
-static const unsigned char pyc_32_magic[4]= { 0x6c, 0x0c, '\r', '\n'};
-
struct pyc_header {
uint32_t magic_number;
uint32_t modtime;
};
+static int header_check_pyc(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 pyc_header *pyc=(const struct pyc_header *)buffer;
+ /* marshalled code object must be of of type TYPE_CODE and argcount < 256 */
+ if(buffer[8]!='c' || buffer[9]!=0 || buffer[10]!=0 || buffer[11]!=0)
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_pyc.extension;
+ file_recovery_new->time=le32(pyc->modtime);
+ return 1;
+}
+
static void register_header_check_pyc(file_stat_t *file_stat)
{
+ static const unsigned char pyc_15_magic[4]= { 0x99, 0x4e, '\r', '\n'};
+ static const unsigned char pyc_20_magic[4]= { 0x87, 0xc6, '\r', '\n'};
+ static const unsigned char pyc_21_magic[4]= { 0x2a, 0xeb, '\r', '\n'};
+ static const unsigned char pyc_22_magic[4]= { 0x2d, 0xed, '\r', '\n'};
+ static const unsigned char pyc_23_magic[4]= { 0x3b, 0xf2, '\r', '\n'};
+ static const unsigned char pyc_24_magic[4]= { 0x6d, 0xf2, '\r', '\n'};
+ static const unsigned char pyc_25_magic[4]= { 0xb3, 0xf2, '\r', '\n'};
+ static const unsigned char pyc_26_magic[4]= { 0xd1, 0xf2, '\r', '\n'};
+ static const unsigned char pyc_27_magic[4]= { 0x03, 0xf3, '\r', '\n'};
+ static const unsigned char pyc_30_magic[4]= { 0x3b, 0x0c, '\r', '\n'};
+ static const unsigned char pyc_31_magic[4]= { 0x4f, 0x0c, '\r', '\n'};
+ static const unsigned char pyc_32_magic[4]= { 0x6c, 0x0c, '\r', '\n'};
+ static const unsigned char pyc_33_magic[4]= { 0x9e, 0x0c, '\r', '\n'};
+ static const unsigned char pyc_34_magic[4]= { 0xee, 0x0c, '\r', '\n'};
register_header_check(0, pyc_15_magic, sizeof(pyc_15_magic), &header_check_pyc, file_stat);
register_header_check(0, pyc_20_magic, sizeof(pyc_20_magic), &header_check_pyc, file_stat);
register_header_check(0, pyc_21_magic, sizeof(pyc_21_magic), &header_check_pyc, file_stat);
@@ -78,32 +91,6 @@ static void register_header_check_pyc(file_stat_t *file_stat)
register_header_check(0, pyc_30_magic, sizeof(pyc_30_magic), &header_check_pyc, file_stat);
register_header_check(0, pyc_31_magic, sizeof(pyc_31_magic), &header_check_pyc, file_stat);
register_header_check(0, pyc_32_magic, sizeof(pyc_32_magic), &header_check_pyc, file_stat);
-}
-
-static int header_check_pyc(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 pyc_header *pyc=(const struct pyc_header *)buffer;
- /* marshalled code object must be of of type TYPE_CODE and argcount < 256 */
- if(buffer[8]!='c' || buffer[9]!=0 || buffer[10]!=0 || buffer[11]!=0)
- return 0;
- switch(be32(pyc->magic_number))
- {
- case 0x994e0d0a: /* 1.5 */
- case 0x87c60d0a: /* 2.0 */
- case 0x2aeb0d0a: /* 2.1 */
- case 0x2ded0d0a: /* 2.2 */
- case 0x3bf20d0a: /* 2.3 */
- case 0x6df20d0a: /* 2.4 */
- case 0xb3f20d0a: /* 2.5 */
- case 0xd1f20d0a: /* 2.6 */
- case 0x03f30d0a: /* 2.7 */
- case 0x3b0c0d0a: /* 3.0 */
- case 0x4f0c0d0a: /* 3.1 */
- case 0x6c0c0d0a: /* 3.2 */
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_pyc.extension;
- file_recovery_new->time=le32(pyc->modtime);
- return 1;
- }
- return 0;
+ 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);
}