| 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 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#include "global.h" |
| 36 |
|
| 37 |
|
| 38 |
static int probe_udf(SECTION *section, int level, int sector_size); |
| 39 |
static int validate_tag(unsigned char *buf, u4 sector); |
| 40 |
|
| 41 |
void detect_udf(SECTION *section, int level) |
| 42 |
{ |
| 43 |
unsigned char *buffer; |
| 44 |
unsigned char sig_bea[7] = {0x00, 0x42, 0x45, 0x41, 0x30, 0x31, 0x01}; |
| 45 |
|
| 46 |
unsigned char sig_nsr2[7] = {0x00, 0x4e, 0x53, 0x52, 0x30, 0x32, 0x01}; |
| 47 |
|
| 48 |
unsigned char sig_nsr3[7] = {0x00, 0x4e, 0x53, 0x52, 0x30, 0x33, 0x01}; |
| 49 |
|
| 50 |
unsigned char sig_tea[7] = {0x00, 0x54, 0x45, 0x41, 0x30, 0x31, 0x01}; |
| 51 |
|
| 52 |
|
| 53 |
int recog_state, sector; |
| 54 |
int detected = 0; |
| 55 |
int probe_result; |
| 56 |
int sizes[] = { 2048, 512, 1024, 4096, -1 }; |
| 57 |
int i; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
recog_state = 0; |
| 62 |
for (sector = 16; sector < 64; sector++) { |
| 63 |
if (get_buffer(section, sector * 2048, 2048, (void **)&buffer) < 2048) |
| 64 |
return; |
| 65 |
|
| 66 |
if (buffer[2] == buffer[1] && |
| 67 |
buffer[3] == buffer[1] && |
| 68 |
buffer[4] == buffer[1] && |
| 69 |
buffer[5] == buffer[1]) |
| 70 |
break; |
| 71 |
if (recog_state == 0 && memcmp(buffer, sig_bea, 7) == 0) |
| 72 |
recog_state = 1; |
| 73 |
if (recog_state == 1 && memcmp(buffer, sig_tea, 7) == 0) |
| 74 |
recog_state = 0; |
| 75 |
if (recog_state == 1 && (memcmp(buffer, sig_nsr2, 7) == 0 || |
| 76 |
memcmp(buffer, sig_nsr3, 7) == 0)) { |
| 77 |
detected = 1; |
| 78 |
break; |
| 79 |
} |
| 80 |
} |
| 81 |
if (!detected) |
| 82 |
return; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
for (i = 0; sizes[i] > 0; i++) { |
| 94 |
probe_result = probe_udf(section, level, sizes[i]); |
| 95 |
if (probe_result > 0) |
| 96 |
return; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
print_line(level, "UDF recognition sequence, unable to locate anchor descriptor"); |
| 102 |
} |
| 103 |
|
| 104 |
static int probe_udf(SECTION *section, int level, int sector_size) |
| 105 |
{ |
| 106 |
unsigned char *buffer; |
| 107 |
|
| 108 |
u4 count, addr, sect; |
| 109 |
int seen_primary = 0; |
| 110 |
int seen_logical = 0; |
| 111 |
int i; |
| 112 |
char s[256]; |
| 113 |
|
| 114 |
|
| 115 |
if (get_buffer(section, 256 * sector_size, 512, (void **)&buffer) < 512) |
| 116 |
return 0; |
| 117 |
if (!validate_tag(buffer, 256)) |
| 118 |
return 0; |
| 119 |
|
| 120 |
if (get_le_short(buffer) != 2) |
| 121 |
return 0; |
| 122 |
|
| 123 |
print_line(level, "UDF file system"); |
| 124 |
print_line(level + 1, "Sector size %d bytes", sector_size); |
| 125 |
|
| 126 |
|
| 127 |
count = get_le_long(buffer + 16) / sector_size; |
| 128 |
addr = get_le_long(buffer + 20); |
| 129 |
|
| 130 |
|
| 131 |
for (i = 0; i < count; i++) { |
| 132 |
sect = addr + i; |
| 133 |
if (get_buffer(section, (u8)sect * sector_size, 512, (void **)&buffer) < 512) |
| 134 |
break; |
| 135 |
if (!validate_tag(buffer, sect)) |
| 136 |
continue; |
| 137 |
|
| 138 |
|
| 139 |
switch (get_le_short(buffer)) { |
| 140 |
case 1: |
| 141 |
if (!seen_primary) { |
| 142 |
seen_primary = 1; |
| 143 |
|
| 144 |
if (buffer[24] == 8) { |
| 145 |
get_string(buffer + 25, 30, s); |
| 146 |
print_line(level+1, "Volume name \"%s\"", s); |
| 147 |
} else if (buffer[24] == 16) { |
| 148 |
format_utf16_le(buffer + 25, 30, s); |
| 149 |
print_line(level+1, "Volume name \"%s\"", s); |
| 150 |
} else { |
| 151 |
print_line(level+1, "Volume name encoding not supported"); |
| 152 |
} |
| 153 |
|
| 154 |
} |
| 155 |
break; |
| 156 |
|
| 157 |
case 6: |
| 158 |
if (!seen_logical) { |
| 159 |
seen_logical = 1; |
| 160 |
|
| 161 |
if (memcmp(buffer + 216+1, "*OSTA UDF Compliant", 19) == 0) { |
| 162 |
print_line(level+1, "UDF version %x.%02x", |
| 163 |
(int)buffer[216+25], (int)buffer[216+24]); |
| 164 |
} |
| 165 |
|
| 166 |
} |
| 167 |
break; |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
if (!seen_primary) { |
| 172 |
print_line(level + 1, "Primary Volume Descriptor missing"); |
| 173 |
} |
| 174 |
|
| 175 |
return 1; |
| 176 |
} |
| 177 |
|
| 178 |
static int validate_tag(unsigned char *buf, u4 sector) |
| 179 |
{ |
| 180 |
int cksum, i; |
| 181 |
|
| 182 |
|
| 183 |
cksum = 0; |
| 184 |
for (i = 0; i < 16; i++) |
| 185 |
if (i != 4) |
| 186 |
cksum += buf[i]; |
| 187 |
if ((cksum & 0xFF) != buf[4]) |
| 188 |
return 0; |
| 189 |
|
| 190 |
|
| 191 |
if (buf[5] != 0) |
| 192 |
return 0; |
| 193 |
|
| 194 |
|
| 195 |
if (get_le_long(buf + 12) != sector) |
| 196 |
return 0; |
| 197 |
|
| 198 |
return 1; |
| 199 |
} |
| 200 |
|
| 201 |
|