18
18
// set to 0 or 2
19
19
#define BLK_FIX 2
20
20
21
+ static void dump_bootinfo (disk_t * disk , uint64_t sector );
22
+
21
23
void dump_eltorito (disk_t * disk )
22
24
{
23
25
int i , j ;
@@ -132,7 +134,7 @@ void dump_eltorito(disk_t *disk)
132
134
le16toh (el -> entry .size ),
133
135
BLK_FIX ? "" : "/4"
134
136
);
135
- if ((s = iso_block_to_name (disk , le32toh (el -> entry .start ) << 2 ))) {
137
+ if ((s = iso_block_to_name (disk , le32toh (el -> entry .start ) << 2 , NULL ))) {
136
138
json_object_object_add (json_entry , "file_name" , json_object_new_string (s ));
137
139
log_info (", \"%s\"" , s );
138
140
}
@@ -143,6 +145,7 @@ void dump_eltorito(disk_t *disk)
143
145
disk -> json_current = json_entry ;
144
146
unsigned old_block_size = disk -> block_size ;
145
147
disk -> block_size = 512 ;
148
+ dump_bootinfo (disk , le32toh (el -> entry .start ) << BLK_FIX );
146
149
dump_fs (disk , 7 , le32toh (el -> entry .start ) << BLK_FIX );
147
150
disk -> block_size = old_block_size ;
148
151
disk -> json_current = disk -> json_disk ;
@@ -174,6 +177,74 @@ void dump_eltorito(disk_t *disk)
174
177
}
175
178
}
176
179
}
177
- #undef BLK_FIX
178
180
179
181
182
+ static void dump_bootinfo (disk_t * disk , uint64_t sector )
183
+ {
184
+ unsigned char buf [disk -> block_size ];
185
+ unsigned char pvd [disk -> block_size ];
186
+ unsigned char grub_info [disk -> block_size ];
187
+
188
+ if (disk -> block_size < 0x200 ) return ;
189
+
190
+ if (disk_read (disk , buf , sector , 1 )) return ;
191
+
192
+ unsigned bi_pvd = read_dword_le (buf + 8 ) << BLK_FIX ;
193
+ unsigned bi_start = read_dword_le (buf + 12 ) << BLK_FIX ;
194
+ unsigned bi_size = read_dword_le (buf + 16 );
195
+ unsigned bi_crc = read_dword_le (buf + 20 );
196
+
197
+ if ((uint64_t ) bi_pvd * disk -> block_size > disk -> size_in_bytes + disk -> block_size ) return ;
198
+ if (disk_read (disk , pvd , bi_pvd , 1 )) return ;
199
+ if (memcmp (pvd , ISO_MAGIC , sizeof ISO_MAGIC - 1 )) return ;
200
+
201
+ unsigned file_size = -1u ;
202
+ iso_block_to_name (disk , sector , & file_size );
203
+
204
+ unsigned crc = 0 ;
205
+
206
+ if (file_size == bi_size ) {
207
+ for (unsigned u = 64 , block_nr = sector ; u < file_size ; u += 4 ) {
208
+ if (u && !(u % disk -> block_size )) {
209
+ if (disk_read (disk , buf , ++ block_nr , 1 )) break ;
210
+ }
211
+ crc += read_dword_le (buf + u % disk -> block_size );
212
+ }
213
+ }
214
+
215
+ uint64_t grub_lba = 0 ;
216
+
217
+ if (disk -> grub_used && !disk_read (disk , grub_info , sector + 4 , 1 )) {
218
+ grub_lba = read_qword_le (grub_info + 0x1f4 );
219
+ }
220
+
221
+ log_info (" boot info table:\n" );
222
+ log_info (" volume descriptor %u\n" , bi_pvd );
223
+ log_info (" start %u (%s)\n" , bi_start , bi_start == sector ? "ok" : "wrong" );
224
+ log_info (" size %u (%s)\n" , bi_size , bi_size == file_size ? "ok" : "wrong" );
225
+ log_info (" crc 0x%08x (%s)\n" , bi_crc , bi_crc == crc ? "ok" : "wrong" );
226
+ if (disk -> grub_used ) {
227
+ log_info (" grub start %" PRIu64 " (%s)\n" , grub_lba , grub_lba == sector + 5 ? "ok" : "wrong" );
228
+ }
229
+
230
+ json_object * json_fs = json_object_new_object ();
231
+ json_object_object_add (disk -> json_current , "boot_info_table" , json_fs );
232
+
233
+ json_object_object_add (json_fs , "volume_descriptor_lba" , json_object_new_int64 (bi_pvd ));
234
+ json_object_object_add (json_fs , "file_lba" , json_object_new_int64 (bi_start ));
235
+ json_object_object_add (json_fs , "file_lba_ok" , json_object_new_boolean (bi_start == sector ));
236
+ json_object_object_add (json_fs , "file_size" , json_object_new_int64 (bi_size ));
237
+ json_object_object_add (json_fs , "file_size_ok" , json_object_new_boolean (bi_size == file_size ));
238
+ if (disk -> grub_used ) {
239
+ json_object_object_add (json_fs , "grub_lba" , json_object_new_int64 (grub_lba ));
240
+ json_object_object_add (json_fs , "grub_lba_ok" , json_object_new_boolean (grub_lba == sector + 5 ));
241
+ }
242
+
243
+ json_object * json_crc = json_object_new_object ();
244
+ json_object_object_add (json_fs , "crc" , json_crc );
245
+ json_object_object_add (json_crc , "stored" , json_object_new_format ("0x%08x" , bi_crc ));
246
+ json_object_object_add (json_crc , "calculated" , json_object_new_format ("0x%08x" , crc ));
247
+ json_object_object_add (json_crc , "ok" , json_object_new_boolean (bi_crc == crc ));
248
+ }
249
+
250
+ #undef BLK_FIX
0 commit comments