1 /*
2
3 File: wbfs.c
4
5 Copyright (C) 2012 Christophe GRENIER <grenier@cgsecurity.org>
6
7 This software is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write the Free Software Foundation, Inc., 51
19 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 */
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 #ifdef HAVE_STDLIB_H
26 #include <stdlib.h>
27 #endif
28 #ifdef HAVE_STRING_H
29 #include <string.h>
30 #endif
31 #include <stdio.h>
32 #include "types.h"
33 #include "common.h"
34 #include "fnctdsk.h"
35 #include "log.h"
36 #include "wbfs.h"
37
38 static int test_WBFS(disk_t *disk, const struct wbfs_head *sb, const partition_t *partition, const int dump_ind);
39
set_WBFS_info(partition_t * partition)40 static void set_WBFS_info(partition_t *partition)
41 {
42 partition->upart_type=UP_WBFS;
43 memcpy(partition->info,"WBFS",5);
44 }
45
check_WBFS(disk_t * disk,partition_t * partition)46 int check_WBFS(disk_t *disk,partition_t *partition)
47 {
48 unsigned char *buffer=(unsigned char*)MALLOC(2*DEFAULT_SECTOR_SIZE);
49 if(disk->pread(disk, buffer, 2*DEFAULT_SECTOR_SIZE, partition->part_offset+0x100000) != DEFAULT_SECTOR_SIZE)
50 {
51 free(buffer);
52 return 1;
53 }
54 if(test_WBFS(disk, (struct wbfs_head*)buffer, partition, 0)!=0)
55 {
56 free(buffer);
57 return 1;
58 }
59 set_WBFS_info(partition);
60 free(buffer);
61 return 0;
62 }
63
recover_WBFS(disk_t * disk,const struct wbfs_head * sb,partition_t * partition,const int verbose,const int dump_ind)64 int recover_WBFS(disk_t *disk, const struct wbfs_head *sb, partition_t *partition, const int verbose, const int dump_ind)
65 {
66 if(test_WBFS(disk, sb, partition, dump_ind)!=0)
67 return 1;
68 if(partition==NULL)
69 return 0;
70 set_WBFS_info(partition);
71 partition->part_type_i386=P_NTFS;
72 partition->part_size=(uint64_t)be32(sb->n_hd_sec)<<(sb->hd_sec_sz_s);
73 partition->blocksize=0;
74 partition->sborg_offset=0;
75 partition->sb_offset=0;
76 if(verbose>0)
77 {
78 log_info("\n");
79 }
80 return 0;
81 }
82
test_WBFS(disk_t * disk,const struct wbfs_head * sb,const partition_t * partition,const int dump_ind)83 static int test_WBFS(disk_t *disk, const struct wbfs_head *sb, const partition_t *partition, const int dump_ind)
84 {
85 if(be32(sb->magic)!=WBFS_MAGIC)
86 return 1;
87 if(dump_ind!=0)
88 {
89 if(partition!=NULL && disk!=NULL)
90 log_info("\nWBFS magic value at %u/%u/%u\n",
91 offset2cylinder(disk,partition->part_offset),
92 offset2head(disk,partition->part_offset),
93 offset2sector(disk,partition->part_offset));
94 dump_log(sb,DEFAULT_SECTOR_SIZE);
95 }
96 return 0;
97 }
98