]>
Commit | Line | Data |
---|---|---|
1 | //\r | |
2 | // Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r | |
3 | // \r | |
4 | // All rights reserved. This program and the accompanying materials\r | |
5 | // are licensed and made available under the terms and conditions of the BSD License\r | |
6 | // which accompanies this distribution. The full text of the license may be found at\r | |
7 | // http://opensource.org/licenses/bsd-license.php\r | |
8 | //\r | |
9 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | //\r | |
12 | \r | |
13 | define /R int compare_guid(guid1, guid2)\r | |
14 | unsigned char *guid1;\r | |
15 | unsigned char *guid2;\r | |
16 | {\r | |
17 | return strncmp(guid1, guid2, 16);\r | |
18 | }\r | |
19 | .\r | |
20 | \r | |
21 | define /R unsigned char * find_system_table(mem_start, mem_size)\r | |
22 | unsigned char *mem_start;\r | |
23 | unsigned long mem_size;\r | |
24 | {\r | |
25 | unsigned char *mem_ptr;\r | |
26 | \r | |
27 | mem_ptr = mem_start + mem_size;\r | |
28 | \r | |
29 | do\r | |
30 | {\r | |
31 | mem_ptr -= 0x400000; // 4 MB\r | |
32 | \r | |
33 | if (strncmp(mem_ptr, "IBI SYST", 8) == 0)\r | |
34 | {\r | |
35 | return *(unsigned long *)(mem_ptr + 8); // EfiSystemTableBase\r | |
36 | } \r | |
37 | \r | |
38 | } while (mem_ptr > mem_start);\r | |
39 | \r | |
40 | return 0;\r | |
41 | }\r | |
42 | .\r | |
43 | \r | |
44 | define /R unsigned char * find_debug_info_table_header(system_table)\r | |
45 | unsigned char *system_table;\r | |
46 | {\r | |
47 | unsigned long configuration_table_entries;\r | |
48 | unsigned char *configuration_table;\r | |
49 | unsigned long index;\r | |
50 | unsigned char debug_table_guid[16];\r | |
51 | \r | |
52 | // Fill in the debug table's guid\r | |
53 | debug_table_guid[ 0] = 0x77;\r | |
54 | debug_table_guid[ 1] = 0x2E;\r | |
55 | debug_table_guid[ 2] = 0x15;\r | |
56 | debug_table_guid[ 3] = 0x49;\r | |
57 | debug_table_guid[ 4] = 0xDA;\r | |
58 | debug_table_guid[ 5] = 0x1A;\r | |
59 | debug_table_guid[ 6] = 0x64;\r | |
60 | debug_table_guid[ 7] = 0x47;\r | |
61 | debug_table_guid[ 8] = 0xB7;\r | |
62 | debug_table_guid[ 9] = 0xA2;\r | |
63 | debug_table_guid[10] = 0x7A;\r | |
64 | debug_table_guid[11] = 0xFE;\r | |
65 | debug_table_guid[12] = 0xFE;\r | |
66 | debug_table_guid[13] = 0xD9;\r | |
67 | debug_table_guid[14] = 0x5E;\r | |
68 | debug_table_guid[15] = 0x8B;\r | |
69 | \r | |
70 | configuration_table_entries = *(unsigned long *)(system_table + 64);\r | |
71 | configuration_table = *(unsigned long *)(system_table + 68);\r | |
72 | \r | |
73 | for (index = 0; index < configuration_table_entries; index++)\r | |
74 | {\r | |
75 | if (compare_guid(configuration_table, debug_table_guid) == 0)\r | |
76 | {\r | |
77 | return *(unsigned long *)(configuration_table + 16);\r | |
78 | }\r | |
79 | \r | |
80 | configuration_table += 20;\r | |
81 | }\r | |
82 | \r | |
83 | return 0;\r | |
84 | }\r | |
85 | .\r | |
86 | \r | |
87 | define /R int valid_pe_header(header)\r | |
88 | unsigned char *header;\r | |
89 | {\r | |
90 | if ((header[0x00] == 'M') &&\r | |
91 | (header[0x01] == 'Z') &&\r | |
92 | (header[0x80] == 'P') &&\r | |
93 | (header[0x81] == 'E'))\r | |
94 | {\r | |
95 | return 1;\r | |
96 | }\r | |
97 | \r | |
98 | return 0;\r | |
99 | }\r | |
100 | .\r | |
101 | \r | |
102 | define /R unsigned long pe_headersize(header)\r | |
103 | unsigned char *header;\r | |
104 | {\r | |
105 | unsigned long *size;\r | |
106 | \r | |
107 | size = header + 0x00AC;\r | |
108 | \r | |
109 | return *size;\r | |
110 | }\r | |
111 | .\r | |
112 | \r | |
113 | define /R unsigned char *pe_filename(header)\r | |
114 | unsigned char *header;\r | |
115 | {\r | |
116 | unsigned long *debugOffset;\r | |
117 | unsigned char *stringOffset;\r | |
118 | \r | |
119 | if (valid_pe_header(header))\r | |
120 | {\r | |
121 | debugOffset = header + 0x0128;\r | |
122 | stringOffset = header + *debugOffset + 0x002C;\r | |
123 | \r | |
124 | return stringOffset;\r | |
125 | }\r | |
126 | \r | |
127 | return 0;\r | |
128 | }\r | |
129 | .\r | |
130 | \r | |
131 | define /R int char_is_valid(c)\r | |
132 | unsigned char c;\r | |
133 | {\r | |
134 | if (c >= 32 && c < 127)\r | |
135 | return 1;\r | |
136 | \r | |
137 | return 0;\r | |
138 | }\r | |
139 | .\r | |
140 | \r | |
141 | define /R write_symbols_file(filename, mem_start, mem_size)\r | |
142 | unsigned char *filename;\r | |
143 | unsigned char *mem_start;\r | |
144 | unsigned long mem_size; \r | |
145 | {\r | |
146 | unsigned char *system_table;\r | |
147 | unsigned char *debug_info_table_header;\r | |
148 | unsigned char *debug_info_table;\r | |
149 | unsigned long debug_info_table_size;\r | |
150 | unsigned long index;\r | |
151 | unsigned char *debug_image_info;\r | |
152 | unsigned char *loaded_image_protocol;\r | |
153 | unsigned char *image_base;\r | |
154 | unsigned char *debug_filename;\r | |
155 | unsigned long header_size;\r | |
156 | int status;\r | |
157 | \r | |
158 | system_table = find_system_table(mem_start, mem_size);\r | |
159 | if (system_table == 0)\r | |
160 | {\r | |
161 | return;\r | |
162 | }\r | |
163 | \r | |
164 | status = fopen(88, filename, "w");\r | |
165 | \r | |
166 | debug_info_table_header = find_debug_info_table_header(system_table);\r | |
167 | \r | |
168 | debug_info_table = *(unsigned long *)(debug_info_table_header + 8);\r | |
169 | debug_info_table_size = *(unsigned long *)(debug_info_table_header + 4);\r | |
170 | \r | |
171 | for (index = 0; index < (debug_info_table_size * 4); index += 4)\r | |
172 | {\r | |
173 | debug_image_info = *(unsigned long *)(debug_info_table + index); \r | |
174 | \r | |
175 | if (debug_image_info == 0)\r | |
176 | {\r | |
177 | break;\r | |
178 | }\r | |
179 | \r | |
180 | loaded_image_protocol = *(unsigned long *)(debug_image_info + 4);\r | |
181 | \r | |
182 | image_base = *(unsigned long *)(loaded_image_protocol + 32);\r | |
183 | \r | |
184 | debug_filename = pe_filename(image_base);\r | |
185 | header_size = pe_headersize(image_base);\r | |
186 | \r | |
187 | $fprintf 88, "%s 0x%08x\n", debug_filename, image_base + header_size$;\r | |
188 | }\r | |
189 | \r | |
190 | \r | |
191 | fclose(88);\r | |
192 | }\r | |
193 | .\r | |
194 | \r |