| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include "global.h" |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
void detect_apple_partmap(SECTION *section, int level) |
| 35 |
{ |
| 36 |
int i, magic, count; |
| 37 |
char s[256], append[64]; |
| 38 |
unsigned char *buf; |
| 39 |
u8 start, size; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
if (get_buffer(section, 512, 512, (void **)&buf) < 512) |
| 54 |
return; |
| 55 |
|
| 56 |
magic = get_be_short(buf); |
| 57 |
if (magic == 0x5453) { |
| 58 |
print_line(level, "Old-style Apple partition map"); |
| 59 |
return; |
| 60 |
} |
| 61 |
if (magic != 0x504D) |
| 62 |
return; |
| 63 |
|
| 64 |
|
| 65 |
count = get_be_long(buf + 4); |
| 66 |
print_line(level, "Apple partition map, %d entries", count); |
| 67 |
|
| 68 |
for (i = 1; i <= count; i++) { |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
if (i > 1 && get_buffer(section, i * 512, 512, (void **)&buf) < 512) |
| 73 |
return; |
| 74 |
|
| 75 |
|
| 76 |
if (get_be_short(buf) != 0x504D) { |
| 77 |
print_line(level, "Partition %d: invalid signature, skipping", i); |
| 78 |
continue; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
start = get_be_long(buf + 8); |
| 83 |
size = get_be_long(buf + 12); |
| 84 |
sprintf(append, " from %llu", start); |
| 85 |
format_blocky_size(s, size, 512, "sectors", append); |
| 86 |
print_line(level, "Partition %d: %s", |
| 87 |
i, s); |
| 88 |
|
| 89 |
|
| 90 |
get_string(buf + 48, 32, s); |
| 91 |
print_line(level+1, "Type \"%s\"", s); |
| 92 |
|
| 93 |
|
| 94 |
if (start > count && size > 0) { |
| 95 |
analyze_recursive(section, level + 1, |
| 96 |
start * 512, size * 512, 0); |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
void detect_apple_volume(SECTION *section, int level) |
| 106 |
{ |
| 107 |
char s[256], t[514]; |
| 108 |
unsigned char *buf; |
| 109 |
u2 magic, version, volnamelen; |
| 110 |
u4 blocksize, blockstart; |
| 111 |
u8 blockcount, offset; |
| 112 |
u8 catalogstart, cataloglength; |
| 113 |
u4 firstleafnode, nodesize; |
| 114 |
|
| 115 |
if (get_buffer(section, 1024, 512, (void **)&buf) < 512) |
| 116 |
return; |
| 117 |
|
| 118 |
magic = get_be_short(buf); |
| 119 |
version = get_be_short(buf + 2); |
| 120 |
|
| 121 |
if (magic == 0xD2D7) { |
| 122 |
print_line(level, "MFS file system"); |
| 123 |
|
| 124 |
} else if (magic == 0x4244) { |
| 125 |
print_line(level, "HFS file system"); |
| 126 |
blockcount = get_be_short(buf + 18); |
| 127 |
blocksize = get_be_long(buf + 20); |
| 128 |
blockstart = get_be_short(buf + 28); |
| 129 |
|
| 130 |
get_pstring(buf + 36, s); |
| 131 |
format_ascii(s, t); |
| 132 |
print_line(level + 1, "Volume name \"%s\"", t); |
| 133 |
|
| 134 |
format_blocky_size(s, blockcount, blocksize, "blocks", NULL); |
| 135 |
print_line(level + 1, "Volume size %s", s); |
| 136 |
|
| 137 |
if (get_be_short(buf + 0x7c) == 0x482B) { |
| 138 |
print_line(level, "HFS wrapper for HFS Plus"); |
| 139 |
|
| 140 |
offset = (u8)get_be_short(buf + 0x7e) * blocksize + |
| 141 |
(u8)blockstart * 512; |
| 142 |
|
| 143 |
|
| 144 |
analyze_recursive(section, level + 1, |
| 145 |
offset, 0, 0); |
| 146 |
} |
| 147 |
|
| 148 |
} else if (magic == 0x482B) { |
| 149 |
print_line(level, "HFS Plus file system"); |
| 150 |
|
| 151 |
blocksize = get_be_long(buf + 40); |
| 152 |
blockcount = get_be_long(buf + 44); |
| 153 |
|
| 154 |
format_blocky_size(s, blockcount, blocksize, "blocks", NULL); |
| 155 |
print_line(level + 1, "Volume size %s", s); |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
catalogstart = get_be_long(buf + 288) * blocksize; |
| 167 |
cataloglength = get_be_long(buf + 292) * blocksize; |
| 168 |
|
| 169 |
if (cataloglength > get_be_quad(buf + 272)) |
| 170 |
cataloglength = get_be_quad(buf + 272); |
| 171 |
|
| 172 |
|
| 173 |
if (get_buffer(section, catalogstart, 4096, (void **)&buf) < 4096) |
| 174 |
return; |
| 175 |
firstleafnode = get_be_long(buf + 24); |
| 176 |
nodesize = get_be_short(buf + 32); |
| 177 |
if (nodesize < 4096) |
| 178 |
return; |
| 179 |
|
| 180 |
|
| 181 |
if ((firstleafnode + 1) * nodesize > cataloglength) |
| 182 |
return; |
| 183 |
if (get_buffer(section, catalogstart + firstleafnode * nodesize, |
| 184 |
nodesize, (void **)&buf) < nodesize) |
| 185 |
return; |
| 186 |
|
| 187 |
|
| 188 |
if (buf[8] != 0xff) |
| 189 |
return; |
| 190 |
if (get_be_short(buf + 14) <= 6) |
| 191 |
return; |
| 192 |
if (get_be_long(buf + 16) != 1) |
| 193 |
return; |
| 194 |
volnamelen = get_be_short(buf + 20); |
| 195 |
format_utf16_be(buf + 22, volnamelen * 2, t); |
| 196 |
print_line(level + 1, "Volume name \"%s\"", t); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
void detect_udif(SECTION *section, int level) |
| 205 |
{ |
| 206 |
u8 pos; |
| 207 |
unsigned char *buf; |
| 208 |
|
| 209 |
if (section->size < 1024 || section->source->sequential) |
| 210 |
return; |
| 211 |
|
| 212 |
pos = section->size - 512; |
| 213 |
if (get_buffer(section, pos, 512, (void **)&buf) < 512) |
| 214 |
return; |
| 215 |
|
| 216 |
if (memcmp(buf, "koly", 4) == 0) { |
| 217 |
print_line(level, "Apple UDIF disk image, content detection may or may not work..."); |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
|