|
@@ -356,41 +356,50 @@ efi_pecoff_debug_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
|
356
|
356
|
EFI_IMAGE_OPTIONAL_HEADER64 *opt64;
|
357
|
357
|
EFI_IMAGE_DATA_DIRECTORY *datadir;
|
358
|
358
|
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *debug;
|
359
|
|
- EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY *codeview;
|
|
359
|
+ EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY *codeview_nb10;
|
|
360
|
+ EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY *codeview_rsds;
|
|
361
|
+ EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY *codeview_mtoc;
|
|
362
|
+ uint16_t dos_magic;
|
|
363
|
+ uint32_t pe_magic;
|
|
364
|
+ uint16_t opt_magic;
|
|
365
|
+ uint32_t codeview_magic;
|
360
|
366
|
size_t max_len;
|
361
|
367
|
char *name;
|
362
|
368
|
char *tmp;
|
363
|
369
|
|
364
|
370
|
/* Parse DOS header */
|
365
|
371
|
if ( ! dos ) {
|
366
|
|
- DBGC ( loaded, "Missing DOS header\n" );
|
|
372
|
+ DBG ( "[Missing DOS header]" );
|
367
|
373
|
return NULL;
|
368
|
374
|
}
|
369
|
|
- if ( dos->e_magic != EFI_IMAGE_DOS_SIGNATURE ) {
|
370
|
|
- DBGC ( loaded, "Bad DOS signature\n" );
|
|
375
|
+ dos_magic = dos->e_magic;
|
|
376
|
+ if ( dos_magic != EFI_IMAGE_DOS_SIGNATURE ) {
|
|
377
|
+ DBG ( "[Bad DOS signature %#04x]", dos_magic );
|
371
|
378
|
return NULL;
|
372
|
379
|
}
|
373
|
380
|
pe = ( loaded->ImageBase + dos->e_lfanew );
|
374
|
381
|
|
375
|
382
|
/* Parse PE header */
|
376
|
|
- if ( pe->Pe32.Signature != EFI_IMAGE_NT_SIGNATURE ) {
|
377
|
|
- DBGC ( loaded, "Bad PE signature\n" );
|
|
383
|
+ pe_magic = pe->Pe32.Signature;
|
|
384
|
+ if ( pe_magic != EFI_IMAGE_NT_SIGNATURE ) {
|
|
385
|
+ DBG ( "[Bad PE signature %#08x]", pe_magic );
|
378
|
386
|
return NULL;
|
379
|
387
|
}
|
380
|
388
|
opt32 = &pe->Pe32.OptionalHeader;
|
381
|
389
|
opt64 = &pe->Pe32Plus.OptionalHeader;
|
382
|
|
- if ( opt32->Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC ) {
|
|
390
|
+ opt_magic = opt32->Magic;
|
|
391
|
+ if ( opt_magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC ) {
|
383
|
392
|
datadir = opt32->DataDirectory;
|
384
|
|
- } else if ( opt64->Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC ) {
|
|
393
|
+ } else if ( opt_magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC ) {
|
385
|
394
|
datadir = opt64->DataDirectory;
|
386
|
395
|
} else {
|
387
|
|
- DBGC ( loaded, "Bad optional header signature\n" );
|
|
396
|
+ DBG ( "[Bad optional header signature %#04x]", opt_magic );
|
388
|
397
|
return NULL;
|
389
|
398
|
}
|
390
|
399
|
|
391
|
400
|
/* Parse data directory entry */
|
392
|
401
|
if ( ! datadir[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress ) {
|
393
|
|
- DBGC ( loaded, "Empty debug directory entry\n" );
|
|
402
|
+ DBG ( "[Empty debug directory entry]" );
|
394
|
403
|
return NULL;
|
395
|
404
|
}
|
396
|
405
|
debug = ( loaded->ImageBase +
|
|
@@ -398,22 +407,31 @@ efi_pecoff_debug_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
|
398
|
407
|
|
399
|
408
|
/* Parse debug directory entry */
|
400
|
409
|
if ( debug->Type != EFI_IMAGE_DEBUG_TYPE_CODEVIEW ) {
|
401
|
|
- DBGC ( loaded, "Not a CodeView debug directory entry\n" );
|
|
410
|
+ DBG ( "[Not a CodeView debug directory entry (type %d)]",
|
|
411
|
+ debug->Type );
|
402
|
412
|
return NULL;
|
403
|
413
|
}
|
404
|
|
- codeview = ( loaded->ImageBase + debug->RVA );
|
|
414
|
+ codeview_nb10 = ( loaded->ImageBase + debug->RVA );
|
|
415
|
+ codeview_rsds = ( loaded->ImageBase + debug->RVA );
|
|
416
|
+ codeview_mtoc = ( loaded->ImageBase + debug->RVA );
|
|
417
|
+ codeview_magic = codeview_nb10->Signature;
|
405
|
418
|
|
406
|
419
|
/* Parse CodeView entry */
|
407
|
|
- if ( codeview->Signature != CODEVIEW_SIGNATURE_NB10 ) {
|
408
|
|
- DBGC ( loaded, "Bad CodeView signature\n" );
|
|
420
|
+ if ( codeview_magic == CODEVIEW_SIGNATURE_NB10 ) {
|
|
421
|
+ name = ( ( void * ) ( codeview_nb10 + 1 ) );
|
|
422
|
+ } else if ( codeview_magic == CODEVIEW_SIGNATURE_RSDS ) {
|
|
423
|
+ name = ( ( void * ) ( codeview_rsds + 1 ) );
|
|
424
|
+ } else if ( codeview_magic == CODEVIEW_SIGNATURE_MTOC ) {
|
|
425
|
+ name = ( ( void * ) ( codeview_mtoc + 1 ) );
|
|
426
|
+ } else {
|
|
427
|
+ DBG ( "[Bad CodeView signature %#08x]", codeview_magic );
|
409
|
428
|
return NULL;
|
410
|
429
|
}
|
411
|
|
- name = ( ( ( void * ) codeview ) + sizeof ( *codeview ) );
|
412
|
430
|
|
413
|
431
|
/* Sanity check - avoid scanning endlessly through memory */
|
414
|
432
|
max_len = EFI_PAGE_SIZE; /* Reasonably sane */
|
415
|
433
|
if ( strnlen ( name, max_len ) == max_len ) {
|
416
|
|
- DBGC ( loaded, "Excessively long or invalid CodeView name\n" );
|
|
434
|
+ DBG ( "[Excessively long or invalid CodeView name]" );
|
417
|
435
|
return NULL;
|
418
|
436
|
}
|
419
|
437
|
|
|
@@ -528,20 +546,26 @@ const char * efi_handle_name ( EFI_HANDLE handle ) {
|
528
|
546
|
for ( i = 0 ; i < ( sizeof ( efi_handle_name_types ) /
|
529
|
547
|
sizeof ( efi_handle_name_types[0] ) ) ; i++ ) {
|
530
|
548
|
type = &efi_handle_name_types[i];
|
|
549
|
+ DBG2 ( "<%d", i );
|
531
|
550
|
|
532
|
551
|
/* Try to open the applicable protocol */
|
533
|
552
|
efirc = bs->OpenProtocol ( handle, type->protocol, &interface,
|
534
|
553
|
efi_image_handle, handle,
|
535
|
554
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL );
|
536
|
|
- if ( efirc != 0 )
|
|
555
|
+ if ( efirc != 0 ) {
|
|
556
|
+ DBG2 ( ">" );
|
537
|
557
|
continue;
|
|
558
|
+ }
|
538
|
559
|
|
539
|
560
|
/* Try to get name from this protocol */
|
|
561
|
+ DBG2 ( "-" );
|
540
|
562
|
name = type->name ( interface );
|
|
563
|
+ DBG2 ( "%c", ( name ? ( name[0] ? 'Y' : 'E' ) : 'N' ) );
|
541
|
564
|
|
542
|
565
|
/* Close protocol */
|
543
|
566
|
bs->CloseProtocol ( handle, type->protocol,
|
544
|
567
|
efi_image_handle, handle );
|
|
568
|
+ DBG2 ( ">" );
|
545
|
569
|
|
546
|
570
|
/* Use this name, if possible */
|
547
|
571
|
if ( name && name[0] )
|