| 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 |
static void dump_boot_catalog(SECTION *section, u8 pos, int level); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
void detect_iso(SECTION *section, int level) |
| 41 |
{ |
| 42 |
char s[256], t[256]; |
| 43 |
int i, sector, type; |
| 44 |
u4 blocksize; |
| 45 |
u8 blocks, bcpos; |
| 46 |
unsigned char *buf; |
| 47 |
|
| 48 |
|
| 49 |
if (get_buffer(section, 32768, 2048, (void **)&buf) < 2048) |
| 50 |
return; |
| 51 |
|
| 52 |
|
| 53 |
if (memcmp(buf, "\001CD001", 6) != 0) |
| 54 |
return; |
| 55 |
|
| 56 |
print_line(level, "ISO9660 file system"); |
| 57 |
|
| 58 |
|
| 59 |
get_padded_string(buf + 40, 32, ' ', s); |
| 60 |
print_line(level+1, "Volume name \"%s\"", s); |
| 61 |
|
| 62 |
get_padded_string(buf + 318, 128, ' ', s); |
| 63 |
if (s[0]) |
| 64 |
print_line(level+1, "Publisher \"%s\"", s); |
| 65 |
|
| 66 |
get_padded_string(buf + 446, 128, ' ', s); |
| 67 |
if (s[0]) |
| 68 |
print_line(level+1, "Preparer \"%s\"", s); |
| 69 |
|
| 70 |
get_padded_string(buf + 574, 128, ' ', s); |
| 71 |
if (s[0]) |
| 72 |
print_line(level+1, "Application \"%s\"", s); |
| 73 |
|
| 74 |
|
| 75 |
blocks = get_le_long(buf + 80); |
| 76 |
blocksize = get_le_short(buf + 128); |
| 77 |
format_blocky_size(s, blocks, blocksize, "blocks", NULL); |
| 78 |
print_line(level+1, "Data size %s", s); |
| 79 |
|
| 80 |
for (sector = 17; ; sector++) { |
| 81 |
|
| 82 |
if (get_buffer(section, sector * 2048, 2048, (void **)&buf) < 2048) |
| 83 |
return; |
| 84 |
|
| 85 |
|
| 86 |
if (memcmp(buf + 1, "CD001", 5) != 0) { |
| 87 |
print_line(level+1, "Signature missing in sector %d", sector); |
| 88 |
return; |
| 89 |
} |
| 90 |
type = buf[0]; |
| 91 |
if (type == 255) |
| 92 |
break; |
| 93 |
|
| 94 |
switch (type) { |
| 95 |
|
| 96 |
case 0: |
| 97 |
|
| 98 |
if (memcmp(buf+7, "EL TORITO SPECIFICATION", 23) != 0) { |
| 99 |
print_line(level+1, "Boot record of unknown format"); |
| 100 |
break; |
| 101 |
} |
| 102 |
|
| 103 |
bcpos = get_le_long(buf + 0x47); |
| 104 |
print_line(level+1, "El Torito boot record, catalog at %llu", bcpos); |
| 105 |
|
| 106 |
|
| 107 |
dump_boot_catalog(section, bcpos * 2048, level + 2); |
| 108 |
|
| 109 |
break; |
| 110 |
|
| 111 |
case 1: |
| 112 |
print_line(level+1, "Additional Primary Volume Descriptor"); |
| 113 |
break; |
| 114 |
|
| 115 |
case 2: |
| 116 |
|
| 117 |
format_utf16_be(buf + 40, 32, t); |
| 118 |
for (i = strlen(t)-1; i >= 0 && t[i] == ' '; i--) |
| 119 |
t[i] = 0; |
| 120 |
print_line(level+1, "Joliet extension, volume name \"%s\"", t); |
| 121 |
break; |
| 122 |
|
| 123 |
case 3: |
| 124 |
print_line(level+1, "Volume Partition Descriptor"); |
| 125 |
break; |
| 126 |
|
| 127 |
default: |
| 128 |
print_line(level+1, "Descriptor type %d at sector %d", type, sector); |
| 129 |
break; |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
static char *media_types[16] = { |
| 139 |
"non-emulated", |
| 140 |
"1.2M floppy", |
| 141 |
"1.44M floppy", |
| 142 |
"2.88M floppy", |
| 143 |
"hard disk", |
| 144 |
"reserved type 5", "reserved type 6", "reserved type 7", |
| 145 |
"reserved type 8", "reserved type 9", "reserved type 10", |
| 146 |
"reserved type 11", "reserved type 12", "reserved type 13", |
| 147 |
"reserved type 14", "reserved type 15" |
| 148 |
}; |
| 149 |
|
| 150 |
static char * get_name_for_eltorito_platform(int id) |
| 151 |
{ |
| 152 |
if (id == 0) |
| 153 |
return "x86"; |
| 154 |
if (id == 1) |
| 155 |
return "PowerPC"; |
| 156 |
if (id == 2) |
| 157 |
return "Macintosh"; |
| 158 |
if (id == 0xEF) |
| 159 |
return "EFI"; |
| 160 |
return "unknown"; |
| 161 |
} |
| 162 |
|
| 163 |
static void dump_boot_catalog(SECTION *section, u8 pos, int level) |
| 164 |
{ |
| 165 |
unsigned char *buf; |
| 166 |
int bootable, media, platform, system_type; |
| 167 |
u4 start, preload; |
| 168 |
int entry, maxentry, off; |
| 169 |
char s[256]; |
| 170 |
|
| 171 |
|
| 172 |
if (get_buffer(section, pos, 2048, (void **)&buf) < 2048) |
| 173 |
return; |
| 174 |
|
| 175 |
|
| 176 |
if (buf[0] != 0x01 || buf[30] != 0x55 || buf[31] != 0xAA) { |
| 177 |
print_line(level, "Validation entry missing"); |
| 178 |
return; |
| 179 |
} |
| 180 |
|
| 181 |
platform = buf[1]; |
| 182 |
|
| 183 |
|
| 184 |
maxentry = 2; |
| 185 |
for (entry = 1; entry < maxentry + 1; entry++) { |
| 186 |
if ((entry & 63) == 0) { |
| 187 |
|
| 188 |
if (get_buffer(section, pos + (entry / 64) * 2048, 2048, (void **)&buf) < 2048) |
| 189 |
return; |
| 190 |
} |
| 191 |
off = (entry * 32) % 2048; |
| 192 |
|
| 193 |
if (entry >= maxentry) { |
| 194 |
if (buf[off] == 0x88) |
| 195 |
maxentry++; |
| 196 |
else |
| 197 |
break; |
| 198 |
} |
| 199 |
|
| 200 |
if (entry == 1) { |
| 201 |
if (!(buf[off] == 0x88 || buf[off] == 0x00)) { |
| 202 |
print_line(level, "Initial/Default entry missing"); |
| 203 |
break; |
| 204 |
} |
| 205 |
if (buf[off + 32] == 0x90 || buf[off + 32] == 0x91) |
| 206 |
maxentry = 3; |
| 207 |
} |
| 208 |
|
| 209 |
if (buf[off] == 0x88 || buf[off] == 0x00) { |
| 210 |
bootable = (buf[off] == 0x88) ? 1 : 0; |
| 211 |
media = buf[off + 1] & 15; |
| 212 |
system_type = buf[off + 4]; |
| 213 |
start = get_le_long(buf + off + 8); |
| 214 |
preload = get_le_short(buf + off + 6); |
| 215 |
|
| 216 |
|
| 217 |
format_size(s, preload * 512); |
| 218 |
print_line(level, "%s %s image, starts at %lu, preloads %s", |
| 219 |
bootable ? "Bootable" : "Non-bootable", |
| 220 |
media_types[media], start, s); |
| 221 |
print_line(level + 1, "Platform 0x%02X (%s), System Type 0x%02X (%s)", |
| 222 |
platform, get_name_for_eltorito_platform(platform), |
| 223 |
system_type, get_name_for_mbrtype(system_type)); |
| 224 |
if (start > 0) { |
| 225 |
analyze_recursive(section, level + 1, |
| 226 |
(u8)start * 2048, 0, 0); |
| 227 |
|
| 228 |
} |
| 229 |
|
| 230 |
} else if (buf[off] == 0x44) { |
| 231 |
maxentry++; |
| 232 |
|
| 233 |
} else if (buf[off] == 0x90 || buf[off] == 0x91) { |
| 234 |
platform = buf[off + 1]; |
| 235 |
maxentry = entry + 1 + get_le_short(buf + off + 2) |
| 236 |
+ ((buf[off] == 0x90) ? 1 : 0); |
| 237 |
|
| 238 |
|
| 239 |
} else { |
| 240 |
print_line(level, "Unknown entry type 0x%02X", buf[off]); |
| 241 |
break; |
| 242 |
} |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
void detect_cdrom_misc(SECTION *section, int level) |
| 251 |
{ |
| 252 |
unsigned char *buf; |
| 253 |
|
| 254 |
|
| 255 |
if (get_buffer(section, 0, 2048, (void **)&buf) < 2048) |
| 256 |
return; |
| 257 |
|
| 258 |
|
| 259 |
if (memcmp(buf, "SEGA SEGAKATANA SEGA ENTERPRISES", 32) == 0) { |
| 260 |
print_line(level, "Sega Dreamcast signature"); |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
if (memcmp(buf, "\x01\x5a\x5a\x5a\x5a\x5a\x01\x00", 8) == 0 && |
| 265 |
memcmp(buf + 0x28, "CD-ROM", 6) == 0) { |
| 266 |
print_line(level, "3DO CD-ROM file system"); |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
if (get_buffer(section, 32*2048, 2048, (void **)&buf) < 2048) |
| 271 |
return; |
| 272 |
|
| 273 |
|
| 274 |
if (memcmp(buf, "MICROSOFT*XBOX*MEDIA", 20) == 0 && |
| 275 |
memcmp(buf + 0x7ec, "MICROSOFT*XBOX*MEDIA", 20) == 0) { |
| 276 |
print_line(level, "Xbox DVD file system"); |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
|