2009-12-06 02:57:05 +01:00
|
|
|
//
|
2010-04-29 14:24:22 +02:00
|
|
|
// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
2014-08-19 15:29:52 +02:00
|
|
|
//
|
2019-04-04 01:03:25 +02:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause-Patent
|
2009-12-06 02:57:05 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
define /R int compare_guid(guid1, guid2)
|
|
|
|
unsigned char *guid1;
|
|
|
|
unsigned char *guid2;
|
|
|
|
{
|
|
|
|
return strncmp(guid1, guid2, 16);
|
|
|
|
}
|
|
|
|
.
|
|
|
|
|
|
|
|
define /R unsigned char * find_system_table(mem_start, mem_size)
|
|
|
|
unsigned char *mem_start;
|
|
|
|
unsigned long mem_size;
|
|
|
|
{
|
|
|
|
unsigned char *mem_ptr;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
mem_ptr = mem_start + mem_size;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
mem_ptr -= 0x400000; // 4 MB
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
if (strncmp(mem_ptr, "IBI SYST", 8) == 0)
|
|
|
|
{
|
|
|
|
return *(unsigned long *)(mem_ptr + 8); // EfiSystemTableBase
|
2014-08-19 15:29:52 +02:00
|
|
|
}
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
} while (mem_ptr > mem_start);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
.
|
|
|
|
|
|
|
|
define /R unsigned char * find_debug_info_table_header(system_table)
|
|
|
|
unsigned char *system_table;
|
|
|
|
{
|
|
|
|
unsigned long configuration_table_entries;
|
|
|
|
unsigned char *configuration_table;
|
|
|
|
unsigned long index;
|
|
|
|
unsigned char debug_table_guid[16];
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
// Fill in the debug table's guid
|
|
|
|
debug_table_guid[ 0] = 0x77;
|
|
|
|
debug_table_guid[ 1] = 0x2E;
|
|
|
|
debug_table_guid[ 2] = 0x15;
|
|
|
|
debug_table_guid[ 3] = 0x49;
|
|
|
|
debug_table_guid[ 4] = 0xDA;
|
|
|
|
debug_table_guid[ 5] = 0x1A;
|
|
|
|
debug_table_guid[ 6] = 0x64;
|
|
|
|
debug_table_guid[ 7] = 0x47;
|
|
|
|
debug_table_guid[ 8] = 0xB7;
|
|
|
|
debug_table_guid[ 9] = 0xA2;
|
|
|
|
debug_table_guid[10] = 0x7A;
|
|
|
|
debug_table_guid[11] = 0xFE;
|
|
|
|
debug_table_guid[12] = 0xFE;
|
|
|
|
debug_table_guid[13] = 0xD9;
|
|
|
|
debug_table_guid[14] = 0x5E;
|
|
|
|
debug_table_guid[15] = 0x8B;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
configuration_table_entries = *(unsigned long *)(system_table + 64);
|
|
|
|
configuration_table = *(unsigned long *)(system_table + 68);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
for (index = 0; index < configuration_table_entries; index++)
|
|
|
|
{
|
|
|
|
if (compare_guid(configuration_table, debug_table_guid) == 0)
|
|
|
|
{
|
|
|
|
return *(unsigned long *)(configuration_table + 16);
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
configuration_table += 20;
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
.
|
|
|
|
|
|
|
|
define /R int valid_pe_header(header)
|
|
|
|
unsigned char *header;
|
|
|
|
{
|
|
|
|
if ((header[0x00] == 'M') &&
|
|
|
|
(header[0x01] == 'Z') &&
|
|
|
|
(header[0x80] == 'P') &&
|
|
|
|
(header[0x81] == 'E'))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
.
|
|
|
|
|
|
|
|
define /R unsigned long pe_headersize(header)
|
|
|
|
unsigned char *header;
|
|
|
|
{
|
|
|
|
unsigned long *size;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
size = header + 0x00AC;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
return *size;
|
|
|
|
}
|
|
|
|
.
|
|
|
|
|
|
|
|
define /R unsigned char *pe_filename(header)
|
|
|
|
unsigned char *header;
|
|
|
|
{
|
|
|
|
unsigned long *debugOffset;
|
|
|
|
unsigned char *stringOffset;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
if (valid_pe_header(header))
|
|
|
|
{
|
|
|
|
debugOffset = header + 0x0128;
|
|
|
|
stringOffset = header + *debugOffset + 0x002C;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
return stringOffset;
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
.
|
|
|
|
|
|
|
|
define /R int char_is_valid(c)
|
|
|
|
unsigned char c;
|
|
|
|
{
|
|
|
|
if (c >= 32 && c < 127)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
.
|
|
|
|
|
|
|
|
define /R write_symbols_file(filename, mem_start, mem_size)
|
|
|
|
unsigned char *filename;
|
|
|
|
unsigned char *mem_start;
|
2014-08-19 15:29:52 +02:00
|
|
|
unsigned long mem_size;
|
2009-12-06 02:57:05 +01:00
|
|
|
{
|
|
|
|
unsigned char *system_table;
|
|
|
|
unsigned char *debug_info_table_header;
|
|
|
|
unsigned char *debug_info_table;
|
|
|
|
unsigned long debug_info_table_size;
|
|
|
|
unsigned long index;
|
|
|
|
unsigned char *debug_image_info;
|
|
|
|
unsigned char *loaded_image_protocol;
|
|
|
|
unsigned char *image_base;
|
|
|
|
unsigned char *debug_filename;
|
|
|
|
unsigned long header_size;
|
|
|
|
int status;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
system_table = find_system_table(mem_start, mem_size);
|
|
|
|
if (system_table == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
status = fopen(88, filename, "w");
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
debug_info_table_header = find_debug_info_table_header(system_table);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
debug_info_table = *(unsigned long *)(debug_info_table_header + 8);
|
|
|
|
debug_info_table_size = *(unsigned long *)(debug_info_table_header + 4);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
for (index = 0; index < (debug_info_table_size * 4); index += 4)
|
|
|
|
{
|
2014-08-19 15:29:52 +02:00
|
|
|
debug_image_info = *(unsigned long *)(debug_info_table + index);
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
if (debug_image_info == 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
loaded_image_protocol = *(unsigned long *)(debug_image_info + 4);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
image_base = *(unsigned long *)(loaded_image_protocol + 32);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
debug_filename = pe_filename(image_base);
|
|
|
|
header_size = pe_headersize(image_base);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
$fprintf 88, "%s 0x%08x\n", debug_filename, image_base + header_size$;
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
fclose(88);
|
|
|
|
}
|
|
|
|
.
|
|
|
|
|