| 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 |
|
| 35 |
|
| 36 |
|
| 37 |
struct systypes { |
| 38 |
unsigned char type; |
| 39 |
char *name; |
| 40 |
}; |
| 41 |
|
| 42 |
struct systypes i386_sys_types[] = { |
| 43 |
{ 0x00, "Empty" }, |
| 44 |
{ 0x01, "FAT12" }, |
| 45 |
{ 0x02, "XENIX root" }, |
| 46 |
{ 0x03, "XENIX usr" }, |
| 47 |
{ 0x04, "FAT16 <32M" }, |
| 48 |
{ 0x05, "Extended" }, |
| 49 |
{ 0x06, "FAT16" }, |
| 50 |
{ 0x07, "HPFS/NTFS" }, |
| 51 |
{ 0x08, "AIX" }, |
| 52 |
{ 0x09, "AIX bootable" }, |
| 53 |
{ 0x0a, "OS/2 Boot Manager" }, |
| 54 |
{ 0x0b, "Win95 FAT32" }, |
| 55 |
{ 0x0c, "Win95 FAT32 (LBA)" }, |
| 56 |
{ 0x0e, "Win95 FAT16 (LBA)" }, |
| 57 |
{ 0x0f, "Win95 Ext'd (LBA)" }, |
| 58 |
{ 0x10, "OPUS" }, |
| 59 |
{ 0x11, "Hidden FAT12" }, |
| 60 |
{ 0x12, "Compaq diagnostics" }, |
| 61 |
{ 0x14, "Hidden FAT16 <32M" }, |
| 62 |
{ 0x16, "Hidden FAT16" }, |
| 63 |
{ 0x17, "Hidden HPFS/NTFS" }, |
| 64 |
{ 0x18, "AST SmartSleep" }, |
| 65 |
{ 0x1b, "Hidden Win95 FAT32" }, |
| 66 |
{ 0x1c, "Hidden Win95 FAT32 (LBA)" }, |
| 67 |
{ 0x1e, "Hidden Win95 FAT16 (LBA)" }, |
| 68 |
{ 0x24, "NEC DOS" }, |
| 69 |
{ 0x39, "Plan 9" }, |
| 70 |
{ 0x3c, "PartitionMagic recovery" }, |
| 71 |
{ 0x40, "Venix 80286" }, |
| 72 |
{ 0x41, "PPC PReP Boot" }, |
| 73 |
{ 0x42, "SFS / MS LDM" }, |
| 74 |
{ 0x4d, "QNX4.x" }, |
| 75 |
{ 0x4e, "QNX4.x 2nd part" }, |
| 76 |
{ 0x4f, "QNX4.x 3rd part" }, |
| 77 |
{ 0x50, "OnTrack DM" }, |
| 78 |
{ 0x51, "OnTrack DM6 Aux1" }, |
| 79 |
{ 0x52, "CP/M" }, |
| 80 |
{ 0x53, "OnTrack DM6 Aux3" }, |
| 81 |
{ 0x54, "OnTrackDM6" }, |
| 82 |
{ 0x55, "EZ-Drive" }, |
| 83 |
{ 0x56, "Golden Bow" }, |
| 84 |
{ 0x5c, "Priam Edisk" }, |
| 85 |
{ 0x61, "SpeedStor" }, |
| 86 |
{ 0x63, "GNU HURD or SysV" }, |
| 87 |
{ 0x64, "Novell Netware 286" }, |
| 88 |
{ 0x65, "Novell Netware 386" }, |
| 89 |
{ 0x70, "DiskSecure Multi-Boot" }, |
| 90 |
{ 0x75, "PC/IX" }, |
| 91 |
{ 0x78, "XOSL" }, |
| 92 |
{ 0x80, "Old Minix" }, |
| 93 |
{ 0x81, "Minix / old Linux" }, |
| 94 |
{ 0x82, "Linux swap / Solaris" }, |
| 95 |
{ 0x83, "Linux" }, |
| 96 |
{ 0x84, "OS/2 hidden C: drive" }, |
| 97 |
{ 0x85, "Linux extended" }, |
| 98 |
{ 0x86, "NTFS volume set" }, |
| 99 |
{ 0x87, "NTFS volume set" }, |
| 100 |
{ 0x8e, "Linux LVM" }, |
| 101 |
{ 0x93, "Amoeba" }, |
| 102 |
{ 0x94, "Amoeba BBT" }, |
| 103 |
{ 0x9f, "BSD/OS" }, |
| 104 |
{ 0xa0, "IBM Thinkpad hibernation" }, |
| 105 |
{ 0xa5, "FreeBSD" }, |
| 106 |
{ 0xa6, "OpenBSD" }, |
| 107 |
{ 0xa7, "NeXTSTEP" }, |
| 108 |
{ 0xa9, "NetBSD" }, |
| 109 |
{ 0xaf, "Mac OS X" }, |
| 110 |
{ 0xb7, "BSDI fs" }, |
| 111 |
{ 0xb8, "BSDI swap" }, |
| 112 |
{ 0xbb, "Boot Wizard hidden" }, |
| 113 |
{ 0xc1, "DRDOS/sec (FAT-12)" }, |
| 114 |
{ 0xc4, "DRDOS/sec (FAT-16 < 32M)" }, |
| 115 |
{ 0xc6, "DRDOS/sec (FAT-16)" }, |
| 116 |
{ 0xc7, "Syrinx" }, |
| 117 |
{ 0xda, "Non-FS data" }, |
| 118 |
{ 0xdb, "CP/M / CTOS / ..." }, |
| 119 |
{ 0xde, "Dell Utility" }, |
| 120 |
{ 0xdf, "BootIt" }, |
| 121 |
{ 0xe1, "DOS access" }, |
| 122 |
{ 0xe3, "DOS R/O" }, |
| 123 |
{ 0xe4, "SpeedStor" }, |
| 124 |
{ 0xeb, "BeOS fs" }, |
| 125 |
{ 0xee, "EFI GPT protective" }, |
| 126 |
{ 0xef, "EFI System (FAT)" }, |
| 127 |
{ 0xf0, "Linux/PA-RISC boot" }, |
| 128 |
{ 0xf1, "SpeedStor" }, |
| 129 |
{ 0xf4, "SpeedStor" }, |
| 130 |
{ 0xf2, "DOS secondary" }, |
| 131 |
{ 0xfd, "Linux raid autodetect" }, |
| 132 |
{ 0xfe, "LANstep" }, |
| 133 |
{ 0xff, "BBT" }, |
| 134 |
{ 0, 0 } |
| 135 |
}; |
| 136 |
|
| 137 |
|
| 138 |
char * get_name_for_mbrtype(int type) |
| 139 |
{ |
| 140 |
int i; |
| 141 |
|
| 142 |
for (i = 0; i386_sys_types[i].name; i++) |
| 143 |
if (i386_sys_types[i].type == type) |
| 144 |
return i386_sys_types[i].name; |
| 145 |
return "Unknown"; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
static void detect_dos_partmap_ext(SECTION *section, u8 extbase, |
| 153 |
int level, int *extpartnum); |
| 154 |
|
| 155 |
void detect_dos_partmap(SECTION *section, int level) |
| 156 |
{ |
| 157 |
unsigned char *buf; |
| 158 |
int i, off, used, type, types[4], bootflags[4]; |
| 159 |
u4 start, size, starts[4], sizes[4]; |
| 160 |
int extpartnum = 5; |
| 161 |
char s[256], append[64]; |
| 162 |
|
| 163 |
|
| 164 |
if (section->pos != 0) |
| 165 |
return; |
| 166 |
|
| 167 |
if (get_buffer(section, 0, 512, (void **)&buf) < 512) |
| 168 |
return; |
| 169 |
|
| 170 |
|
| 171 |
if (buf[510] != 0x55 || buf[511] != 0xAA) |
| 172 |
return; |
| 173 |
|
| 174 |
|
| 175 |
used = 0; |
| 176 |
for (off = 446, i = 0; i < 4; i++, off += 16) { |
| 177 |
|
| 178 |
bootflags[i] = buf[off]; |
| 179 |
types[i] = buf[off + 4]; |
| 180 |
starts[i] = get_le_long(buf + off + 8); |
| 181 |
sizes[i] = get_le_long(buf + off + 12); |
| 182 |
|
| 183 |
|
| 184 |
if (bootflags[i] != 0x00 && bootflags[i] != 0x80) |
| 185 |
return; |
| 186 |
|
| 187 |
if (starts[i] && sizes[i]) |
| 188 |
used = 1; |
| 189 |
} |
| 190 |
if (!used) |
| 191 |
return; |
| 192 |
|
| 193 |
|
| 194 |
print_line(level, "DOS/MBR partition map"); |
| 195 |
for (i = 0; i < 4; i++) { |
| 196 |
start = starts[i]; |
| 197 |
size = sizes[i]; |
| 198 |
type = types[i]; |
| 199 |
if (start == 0 || size == 0) |
| 200 |
continue; |
| 201 |
|
| 202 |
sprintf(append, " from %lu", start); |
| 203 |
if (bootflags[i] == 0x80) |
| 204 |
strcat(append, ", bootable"); |
| 205 |
format_blocky_size(s, size, 512, "sectors", append); |
| 206 |
print_line(level, "Partition %d: %s", |
| 207 |
i+1, s); |
| 208 |
|
| 209 |
print_line(level + 1, "Type 0x%02X (%s)", type, get_name_for_mbrtype(type)); |
| 210 |
|
| 211 |
if (type == 0x05 || type == 0x0f || type == 0x85) { |
| 212 |
|
| 213 |
detect_dos_partmap_ext(section, start, level + 1, &extpartnum); |
| 214 |
} else if (type != 0xee) { |
| 215 |
|
| 216 |
analyze_recursive(section, level + 1, |
| 217 |
(u8)start * 512, (u8)size * 512, 0); |
| 218 |
} |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
static void detect_dos_partmap_ext(SECTION *section, u8 extbase, |
| 223 |
int level, int *extpartnum) |
| 224 |
{ |
| 225 |
unsigned char *buf; |
| 226 |
u8 tablebase, nexttablebase; |
| 227 |
int i, off, type, types[4]; |
| 228 |
u4 start, size, starts[4], sizes[4]; |
| 229 |
char s[256], append[64]; |
| 230 |
|
| 231 |
for (tablebase = extbase; tablebase; tablebase = nexttablebase) { |
| 232 |
|
| 233 |
if (get_buffer(section, tablebase << 9, 512, (void **)&buf) < 512) |
| 234 |
return; |
| 235 |
|
| 236 |
|
| 237 |
if (buf[510] != 0x55 || buf[511] != 0xAA) { |
| 238 |
print_line(level, "Signature missing"); |
| 239 |
return; |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
for (off = 446, i = 0; i < 4; i++, off += 16) { |
| 244 |
types[i] = buf[off + 4]; |
| 245 |
starts[i] = get_le_long(buf + off + 8); |
| 246 |
sizes[i] = get_le_long(buf + off + 12); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
nexttablebase = 0; |
| 251 |
for (i = 0; i < 4; i++) { |
| 252 |
start = starts[i]; |
| 253 |
size = sizes[i]; |
| 254 |
type = types[i]; |
| 255 |
if (size == 0) |
| 256 |
continue; |
| 257 |
|
| 258 |
if (type == 0x05 || type == 0x85) { |
| 259 |
|
| 260 |
|
| 261 |
nexttablebase = extbase + start; |
| 262 |
|
| 263 |
} else { |
| 264 |
|
| 265 |
|
| 266 |
sprintf(append, " from %llu+%lu", tablebase, start); |
| 267 |
format_blocky_size(s, size, 512, "sectors", append); |
| 268 |
print_line(level, "Partition %d: %s", |
| 269 |
*extpartnum, s); |
| 270 |
(*extpartnum)++; |
| 271 |
print_line(level + 1, "Type 0x%02X (%s)", type, get_name_for_mbrtype(type)); |
| 272 |
|
| 273 |
|
| 274 |
if (type != 0xee) { |
| 275 |
analyze_recursive(section, level + 1, |
| 276 |
(tablebase + start) * 512, (u8)size * 512, 0); |
| 277 |
} |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
struct gpttypes { |
| 288 |
char *guid; |
| 289 |
char *name; |
| 290 |
}; |
| 291 |
|
| 292 |
struct gpttypes gpt_types[] = { |
| 293 |
{ "\x28\x73\x2A\xC1\x1F\xF8\xD2\x11\xBA\x4B\x00\xA0\xC9\x3E\xC9\x3B", "EFI System (FAT)" }, |
| 294 |
{ "\x41\xEE\x4D\x02\xE7\x33\xD3\x11\x9D\x69\x00\x08\xC7\x81\xF3\x9F", "MBR partition scheme" }, |
| 295 |
{ "\x16\xE3\xC9\xE3\x5C\x0B\xB8\x4D\x81\x7D\xF9\x2D\xF0\x02\x15\xAE", "MS Reserved" }, |
| 296 |
{ "\xA2\xA0\xD0\xEB\xE5\xB9\x33\x44\x87\xC0\x68\xB6\xB7\x26\x99\xC7", "Basic Data" }, |
| 297 |
{ "\xAA\xC8\x08\x58\x8F\x7E\xE0\x42\x85\xD2\xE1\xE9\x04\x34\xCF\xB3", "MS LDM Metadata" }, |
| 298 |
{ "\xA0\x60\x9B\xAF\x31\x14\x62\x4F\xBC\x68\x33\x11\x71\x4A\x69\xAD", "MS LDM Data" }, |
| 299 |
{ "\x1E\x4C\x89\x75\xEB\x3A\xD3\x11\xB7\xC1\x7B\x03\xA0\x00\x00\x00", "HP/UX Data" }, |
| 300 |
{ "\x28\xE7\xA1\xE2\xE3\x32\xD6\x11\xA6\x82\x7B\x03\xA0\x00\x00\x00", "HP/UX Service" }, |
| 301 |
{ "\x0F\x88\x9D\xA1\xFC\x05\x3B\x4D\xA0\x06\x74\x3F\x0F\x84\x91\x1E", "Linux RAID" }, |
| 302 |
{ "\x6D\xFD\x57\x06\xAB\xA4\xC4\x43\x84\xE5\x09\x33\xC8\x4B\x4F\x4F", "Linux Swap" }, |
| 303 |
{ "\x79\xD3\xD6\xE6\x07\xF5\xC2\x44\xA2\x3C\x23\x8F\x2A\x3D\xF9\x28", "Linux LVM" }, |
| 304 |
{ "\x39\x33\xA6\x8D\x07\x00\xC0\x60\xC4\x36\x08\x3A\xC8\x23\x09\x08", "Linux Reserved" }, |
| 305 |
{ "\xB4\x7C\x6E\x51\xCF\x6E\xD6\x11\x8F\xF8\x00\x02\x2D\x09\x71\x2B", "FreeBSD Data" }, |
| 306 |
{ "\xB5\x7C\x6E\x51\xCF\x6E\xD6\x11\x8F\xF8\x00\x02\x2D\x09\x71\x2B", "FreeBSD Swap" }, |
| 307 |
{ "\xB6\x7C\x6E\x51\xCF\x6E\xD6\x11\x8F\xF8\x00\x02\x2D\x09\x71\x2B", "FreeBSD UFS" }, |
| 308 |
{ "\xB8\x7C\x6E\x51\xCF\x6E\xD6\x11\x8F\xF8\x00\x02\x2D\x09\x71\x2B", "FreeBSD Vinum" }, |
| 309 |
{ "\x00\x53\x46\x48\x00\x00\xAA\x11\xAA\x11\x00\x30\x65\x43\xEC\xAC", "Mac HFS+" }, |
| 310 |
{ 0, 0 } |
| 311 |
}; |
| 312 |
|
| 313 |
static char * get_name_for_guid(void *guid) |
| 314 |
{ |
| 315 |
int i; |
| 316 |
|
| 317 |
for (i = 0; gpt_types[i].name; i++) |
| 318 |
if (memcmp(gpt_types[i].guid, guid, 16) == 0) |
| 319 |
return gpt_types[i].name; |
| 320 |
return "Unknown"; |
| 321 |
} |
| 322 |
|
| 323 |
void detect_gpt_partmap(SECTION *section, int level) |
| 324 |
{ |
| 325 |
unsigned char *buf; |
| 326 |
u8 diskblocks, partmap_start, start, end, size; |
| 327 |
u4 partmap_count, partmap_entry_size; |
| 328 |
u4 i; |
| 329 |
char s[256], append[64]; |
| 330 |
int last_unused; |
| 331 |
|
| 332 |
|
| 333 |
if (section->pos != 0) |
| 334 |
return; |
| 335 |
|
| 336 |
|
| 337 |
if (get_buffer(section, 512, 512, (void **)&buf) < 512) |
| 338 |
return; |
| 339 |
|
| 340 |
|
| 341 |
if (memcmp(buf, "EFI PART", 8) != 0) |
| 342 |
return; |
| 343 |
|
| 344 |
|
| 345 |
if (get_le_quad(buf + 0x18) != 1) |
| 346 |
return; |
| 347 |
diskblocks = get_le_quad(buf + 0x20) + 1; |
| 348 |
partmap_start = get_le_quad(buf + 0x48); |
| 349 |
partmap_count = get_le_long(buf + 0x50); |
| 350 |
partmap_entry_size = get_le_long(buf + 0x54); |
| 351 |
|
| 352 |
print_line(level, "GPT partition map, %d entries", (int)partmap_count); |
| 353 |
format_blocky_size(s, diskblocks, 512, "sectors", NULL); |
| 354 |
print_line(level+1, "Disk size %s", s); |
| 355 |
format_guid(buf + 0x38, s); |
| 356 |
print_line(level+1, "Disk GUID %s", s); |
| 357 |
|
| 358 |
|
| 359 |
last_unused = 0; |
| 360 |
for (i = 0; i < partmap_count; i++) { |
| 361 |
if (get_buffer(section, (partmap_start * 512) + i * partmap_entry_size, partmap_entry_size, (void **)&buf) < partmap_entry_size) |
| 362 |
return; |
| 363 |
|
| 364 |
if (memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) == 0) { |
| 365 |
if (last_unused == 0) |
| 366 |
print_line(level, "Partition %d: unused", i+1); |
| 367 |
last_unused = 1; |
| 368 |
continue; |
| 369 |
} |
| 370 |
last_unused = 0; |
| 371 |
|
| 372 |
|
| 373 |
start = get_le_quad(buf + 0x20); |
| 374 |
end = get_le_quad(buf + 0x28); |
| 375 |
size = end + 1 - start; |
| 376 |
|
| 377 |
sprintf(append, " from %llu", start); |
| 378 |
format_blocky_size(s, size, 512, "sectors", append); |
| 379 |
print_line(level, "Partition %d: %s", i+1, s); |
| 380 |
|
| 381 |
|
| 382 |
format_guid(buf, s); |
| 383 |
print_line(level+1, "Type %s (GUID %s)", get_name_for_guid(buf), s); |
| 384 |
|
| 385 |
|
| 386 |
format_utf16_le(buf + 0x38, 72, s); |
| 387 |
print_line(level+1, "Partition Name \"%s\"", s); |
| 388 |
|
| 389 |
|
| 390 |
format_guid(buf + 0x10, s); |
| 391 |
print_line(level+1, "Partition GUID %s", s); |
| 392 |
|
| 393 |
|
| 394 |
if (start > 0 && size > 0) { |
| 395 |
analyze_recursive(section, level + 1, |
| 396 |
start * 512, size * 512, 0); |
| 397 |
} |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
static char *fatnames[] = { "FAT12", "FAT16", "FAT32" }; |
| 406 |
|
| 407 |
void detect_fat(SECTION *section, int level) |
| 408 |
{ |
| 409 |
int i, score, fattype; |
| 410 |
u4 sectsize, clustersize, reserved, fatcount, dirsize, fatsize; |
| 411 |
u8 sectcount, clustercount; |
| 412 |
u2 atari_csum; |
| 413 |
unsigned char *buf; |
| 414 |
char s[256]; |
| 415 |
|
| 416 |
if (get_buffer(section, 0, 512, (void **)&buf) < 512) |
| 417 |
return; |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
sectsize = get_le_short(buf + 11); |
| 422 |
if (sectsize != 512 && sectsize != 1024 && |
| 423 |
sectsize != 2048 && sectsize != 4096) |
| 424 |
return; |
| 425 |
|
| 426 |
clustersize = buf[13]; |
| 427 |
if (clustersize == 0 || (clustersize & (clustersize - 1))) |
| 428 |
return; |
| 429 |
|
| 430 |
if (memcmp(buf + 3, "NTFS ", 8) == 0) |
| 431 |
return; |
| •432 |
if (memcmp(buf + 3, "EXFAT ", 8) == 0) |
| 433 |
return; |
| 434 |
|
| 435 |
|
| 436 |
score = 0; |
| 437 |
|
| 438 |
|
| 439 |
if ((buf[0] == 0xEB && buf[2] == 0x90) || |
| 440 |
buf[0] == 0xE9) |
| 441 |
score++; |
| 442 |
|
| 443 |
if (buf[510] == 0x55 && buf[511] == 0xAA) |
| 444 |
score++; |
| 445 |
|
| 446 |
reserved = get_le_short(buf + 14); |
| 447 |
if (reserved == 1 || reserved == 32) |
| 448 |
score++; |
| 449 |
|
| 450 |
fatcount = buf[16]; |
| 451 |
if (fatcount == 2) |
| 452 |
score++; |
| 453 |
|
| 454 |
dirsize = get_le_short(buf + 17); |
| 455 |
|
| 456 |
sectcount = get_le_short(buf + 19); |
| 457 |
if (sectcount == 0) |
| 458 |
sectcount = get_le_long(buf + 32); |
| 459 |
|
| 460 |
if (buf[21] == 0xF0 || buf[21] >= 0xF8) |
| 461 |
score++; |
| 462 |
|
| 463 |
fatsize = get_le_short(buf + 22); |
| 464 |
if (fatsize == 0) |
| 465 |
fatsize = get_le_long(buf + 36); |
| 466 |
|
| 467 |
|
| 468 |
dirsize = ((dirsize * 32) + (sectsize - 1)) / sectsize; |
| 469 |
clustercount = sectcount - (reserved + (fatcount * fatsize) + dirsize); |
| 470 |
clustercount /= clustersize; |
| 471 |
|
| 472 |
if (clustercount < 4085) |
| 473 |
fattype = 0; |
| 474 |
else if (clustercount < 65525) |
| 475 |
fattype = 1; |
| 476 |
else |
| 477 |
fattype = 2; |
| 478 |
|
| 479 |
|
| 480 |
atari_csum = 0; |
| 481 |
for (i = 0; i < 512; i += 2) |
| 482 |
atari_csum += get_be_short(buf + i); |
| 483 |
|
| 484 |
|
| 485 |
s[0] = 0; |
| 486 |
if (atari_csum == 0x1234) |
| 487 |
strcpy(s, ", ATARI ST bootable"); |
| 488 |
print_line(level, "%s file system (hints score %d of %d%s)", |
| 489 |
fatnames[fattype], score, 5, s); |
| 490 |
|
| 491 |
if (sectsize > 512) |
| 492 |
print_line(level + 1, "Unusual sector size %lu bytes", sectsize); |
| 493 |
|
| 494 |
format_blocky_size(s, clustercount, clustersize * sectsize, |
| 495 |
"clusters", NULL); |
| 496 |
print_line(level + 1, "Volume size %s", s); |
| 497 |
|
| 498 |
|
| 499 |
if (fattype < 2) { |
| 500 |
if (buf[38] == 0x29) { |
| 501 |
memcpy(s, buf + 43, 11); |
| 502 |
s[11] = 0; |
| 503 |
for (i = 10; i >= 0 && s[i] == ' '; i--) |
| 504 |
s[i] = 0; |
| 505 |
if (strcmp(s, "NO NAME") != 0) |
| 506 |
print_line(level + 1, "Volume name \"%s\"", s); |
| 507 |
} |
| 508 |
} else { |
| 509 |
if (buf[66] == 0x29) { |
| 510 |
memcpy(s, buf + 71, 11); |
| 511 |
s[11] = 0; |
| 512 |
for (i = 10; i >= 0 && s[i] == ' '; i--) |
| 513 |
s[i] = 0; |
| 514 |
if (strcmp(s, "NO NAME") != 0) |
| 515 |
print_line(level + 1, "Volume name \"%s\"", s); |
| 516 |
} |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
|
| •521 |
|
| 522 |
|
| 523 |
|
| 524 |
void detect_exfat(SECTION *section, int level) |
| 525 |
{ |
| 526 |
unsigned char *buf; |
| 527 |
|
| 528 |
if (get_buffer(section, 0, 512, (void **)&buf) < 512) |
| 529 |
return; |
| 530 |
|
| 531 |
|
| 532 |
if (memcmp(buf + 3, "EXFAT ", 8) != 0) |
| 533 |
return; |
| 534 |
|
| 535 |
|
| 536 |
print_line(level, "exFAT file system"); |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
void detect_ntfs(SECTION *section, int level) |
| 544 |
{ |
| 545 |
u4 sectsize, clustersize; |
| 546 |
u8 sectcount; |
| 547 |
unsigned char *buf; |
| 548 |
char s[256]; |
| 549 |
|
| 550 |
if (get_buffer(section, 0, 512, (void **)&buf) < 512) |
| 551 |
return; |
| 552 |
|
| 553 |
|
| 554 |
if (memcmp(buf + 3, "NTFS ", 8) != 0) |
| 555 |
return; |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
sectsize = get_le_short(buf + 11); |
| 563 |
if (sectsize < 512 || (sectsize & (sectsize - 1))) |
| 564 |
return; |
| 565 |
|
| 566 |
clustersize = buf[13]; |
| 567 |
if (clustersize == 0 || (clustersize & (clustersize - 1))) |
| 568 |
return; |
| 569 |
|
| 570 |
|
| 571 |
sectcount = get_le_quad(buf + 0x28); |
| 572 |
|
| 573 |
|
| 574 |
print_line(level, "NTFS file system"); |
| 575 |
|
| 576 |
format_blocky_size(s, sectcount, sectsize, "sectors", NULL); |
| 577 |
print_line(level + 1, "Volume size %s", s); |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
void detect_hpfs(SECTION *section, int level) |
| 585 |
{ |
| 586 |
unsigned char *buf; |
| 587 |
char s[256]; |
| 588 |
u8 sectcount; |
| 589 |
|
| 590 |
if (get_buffer(section, 16*512, 512, (void **)&buf) < 512) |
| 591 |
return; |
| 592 |
|
| 593 |
if (memcmp(buf, "\xF9\x95\xE8\x49\xFA\x53\xE9\xC5", 8) != 0) |
| 594 |
return; |
| 595 |
|
| 596 |
print_line(level, "HPFS file system (version %d, functional version %d)", |
| 597 |
(int)buf[8], (int)buf[9]); |
| 598 |
|
| 599 |
sectcount = get_le_long(buf + 16); |
| 600 |
format_blocky_size(s, sectcount, 512, "sectors", NULL); |
| 601 |
print_line(level + 1, "Volume size %s", s); |
| 602 |
|
| 603 |
|
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
void detect_dos_loader(SECTION *section, int level) |
| 611 |
{ |
| 612 |
int fill; |
| 613 |
unsigned char *buf; |
| 614 |
|
| 615 |
if (section->flags & FLAG_IN_DISKLABEL) |
| 616 |
return; |
| 617 |
|
| 618 |
fill = get_buffer(section, 0, 2048, (void **)&buf); |
| 619 |
if (fill < 512) |
| 620 |
return; |
| 621 |
|
| 622 |
if (find_memory(buf, fill, "NTLDR", 5) >= 0) |
| 623 |
print_line(level, "Windows NTLDR boot loader"); |
| 624 |
else if (find_memory(buf, 512, "WINBOOT SYS", 11) >= 0) |
| 625 |
print_line(level, "Windows 95/98/ME boot loader"); |
| 626 |
else if (find_memory(buf, 512, "MSDOS SYS", 11) >= 0) |
| 627 |
print_line(level, "Windows / MS-DOS boot loader"); |
| 628 |
} |
| 629 |
|
| 630 |
|