|
1 /* |
|
2 * Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * e32tools/e32image/imgdump.cpp |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #define __REFERENCE_CAPABILITY_NAMES__ |
|
21 |
|
22 #include <e32image.h> |
|
23 #include <h_utl.h> |
|
24 #include <string.h> |
|
25 |
|
26 void PriorityToStr(TProcessPriority aPri, char *aStr) |
|
27 { |
|
28 |
|
29 if (aPri==EPrioritySupervisor) |
|
30 strcpy(aStr,"Supervisor"); |
|
31 |
|
32 else if (aPri>EPriorityRealTimeServer) |
|
33 sprintf(aStr, "RealTime+%d", aPri-EPriorityRealTimeServer); |
|
34 else if (aPri==EPriorityRealTimeServer) |
|
35 strcpy(aStr,"RealTime"); |
|
36 |
|
37 else if (aPri>EPriorityFileServer) |
|
38 sprintf(aStr, "FileServer+%d", aPri-EPriorityFileServer); |
|
39 else if (aPri==EPriorityFileServer) |
|
40 strcpy(aStr,"FileServer"); |
|
41 |
|
42 else if (aPri>EPriorityWindowServer) |
|
43 sprintf(aStr, "WindowServer+%d", aPri-EPriorityWindowServer); |
|
44 else if (aPri==EPriorityWindowServer) |
|
45 strcpy(aStr,"WindowServer"); |
|
46 |
|
47 else if (aPri>EPriorityHigh) |
|
48 sprintf(aStr, "High+%d", aPri-EPriorityHigh); |
|
49 else if (aPri==EPriorityHigh) |
|
50 strcpy(aStr,"High"); |
|
51 |
|
52 else if (aPri>EPriorityForeground) |
|
53 sprintf(aStr, "Foreground+%d", aPri-EPriorityForeground); |
|
54 else if (aPri==EPriorityForeground) |
|
55 strcpy(aStr,"Foreground"); |
|
56 |
|
57 else if (aPri>EPriorityBackground) |
|
58 sprintf(aStr, "Background+%d", aPri-EPriorityBackground); |
|
59 else if (aPri==EPriorityBackground) |
|
60 strcpy(aStr,"Background"); |
|
61 |
|
62 else if (aPri>EPriorityLow) |
|
63 sprintf(aStr, "Low+%d", aPri-EPriorityLow); |
|
64 else if (aPri==EPriorityLow) |
|
65 strcpy(aStr,"Low"); |
|
66 |
|
67 else |
|
68 sprintf(aStr, "Illegal (%d)", aPri); |
|
69 } |
|
70 |
|
71 void nl() |
|
72 { |
|
73 Print(EAlways, "\n"); |
|
74 } |
|
75 |
|
76 void E32ImageFile::Dump(TText *aFileName,TInt aDumpFlags) |
|
77 { |
|
78 if (IsValid()) |
|
79 { |
|
80 Print(EAlways, "E32ImageFile '%s'\n", aFileName); |
|
81 DumpHeader(aDumpFlags); |
|
82 DumpData(aDumpFlags); |
|
83 } |
|
84 else |
|
85 Print(EAlways, "This is not an E32 image file (error %d).\n", iError); |
|
86 } |
|
87 |
|
88 void E32ImageFile::DumpHeader(TInt aDumpFlags) |
|
89 { |
|
90 TUint flags = iOrigHdr->iFlags; |
|
91 TUint abi = E32ImageHeader::ABIFromFlags(flags); |
|
92 TUint hdrfmt = E32ImageHeader::HdrFmtFromFlags(flags); |
|
93 TUint impfmt = E32ImageHeader::ImpFmtFromFlags(flags); |
|
94 TUint ept = E32ImageHeader::EptFromFlags(flags); |
|
95 TBool isARM = EFalse; |
|
96 |
|
97 if(aDumpFlags&EDumpHeader) |
|
98 { |
|
99 Print(EAlways, "V%d.%02d(%03d)", iOrigHdr->iToolsVersion.iMajor,iOrigHdr->iToolsVersion.iMinor,iOrigHdr->iToolsVersion.iBuild); |
|
100 Print(EAlways, "\tTime Stamp: %08x,%08x\n", iOrigHdr->iTimeHi, iOrigHdr->iTimeLo); |
|
101 char sig[5]; |
|
102 memcpy(sig, (const char*)&iOrigHdr->iSignature, 4); |
|
103 sig[4]=0; |
|
104 Print(EAlways, sig); |
|
105 if (iOrigHdr->iFlags&KImageDll) |
|
106 Print(EAlways, " Dll for "); |
|
107 else |
|
108 Print(EAlways, " Exe for "); |
|
109 switch (iOrigHdr->CpuIdentifier()) |
|
110 { |
|
111 case ECpuX86: |
|
112 Print(EAlways, "X86 CPU\n"); |
|
113 break; |
|
114 case ECpuArmV4: |
|
115 isARM = ETrue; |
|
116 Print(EAlways, "ARMV4 CPU\n"); |
|
117 break; |
|
118 case ECpuArmV5: |
|
119 isARM = ETrue; |
|
120 Print(EAlways, "ARMV5 CPU\n"); |
|
121 break; |
|
122 case ECpuMCore: |
|
123 Print(EAlways, "M*Core CPU\n"); |
|
124 break; |
|
125 case ECpuUnknown: |
|
126 Print(EAlways, "Unknown CPU\n"); |
|
127 break; |
|
128 default: |
|
129 Print(EAlways, "something or other\n"); |
|
130 break; |
|
131 } |
|
132 |
|
133 Print(EAlways, "Flags:\t%08x\n", flags); |
|
134 |
|
135 if (!(flags & KImageDll)) |
|
136 { |
|
137 char str[80]; |
|
138 PriorityToStr(iOrigHdr->ProcessPriority(), str); |
|
139 Print(EAlways, "Priority %s\n", str); |
|
140 if (flags & KImageFixedAddressExe) |
|
141 Print(EAlways, "Fixed process\n"); |
|
142 } |
|
143 if (flags & KImageNoCallEntryPoint) |
|
144 Print(EAlways, "Entry points are not called\n"); |
|
145 Print(EAlways, "Image header is format %d\n", hdrfmt>>24); |
|
146 TUint compression = iOrigHdr->CompressionType(); |
|
147 switch (compression) |
|
148 { |
|
149 case KFormatNotCompressed: |
|
150 Print(EAlways, "Image is not compressed\n"); |
|
151 break; |
|
152 case KUidCompressionDeflate: |
|
153 Print(EAlways, "Image is compressed using the DEFLATE algorithm\n"); |
|
154 break; |
|
155 case KUidCompressionBytePair: |
|
156 Print(EAlways, "Image is compressed using the BYTEPAIR algorithm\n"); |
|
157 break; |
|
158 default: |
|
159 Print(EAlways, "Image compression type UNKNOWN (%08x)\n", compression); |
|
160 } |
|
161 if (compression) |
|
162 { |
|
163 Print(EAlways, "Uncompressed size %08x\n", iOrigHdr->UncompressedFileSize()); |
|
164 } |
|
165 |
|
166 TUint FPU = flags & KImageHWFloatMask; |
|
167 |
|
168 if (FPU == KImageHWFloat_None) |
|
169 Print(EAlways, "Image FPU support : Soft VFP\n"); |
|
170 else if (FPU == KImageHWFloat_VFPv2) |
|
171 Print(EAlways, "Image FPU support : VFPv2\n"); |
|
172 else |
|
173 Print(EAlways, "Image FPU support : Unknown\n"); |
|
174 |
|
175 if (flags & KImageCodeUnpaged) |
|
176 { |
|
177 Print(EAlways, "Code Paging : Unpaged\n"); |
|
178 } |
|
179 else if (flags & KImageCodePaged) |
|
180 { |
|
181 Print(EAlways, "Code Paging : Paged\n"); |
|
182 } |
|
183 else |
|
184 { |
|
185 Print(EAlways, "Code Paging : Default\n"); |
|
186 } |
|
187 |
|
188 if (flags & KImageDataUnpaged) |
|
189 { |
|
190 Print(EAlways, "Data Paging : Unpaged\n"); |
|
191 } |
|
192 else if (flags & KImageDataPaged) |
|
193 { |
|
194 Print(EAlways, "Data Paging : Paged\n"); |
|
195 } |
|
196 else |
|
197 { |
|
198 Print(EAlways, "Data Paging : Default\n"); |
|
199 } |
|
200 |
|
201 if(flags & KImageDebuggable) |
|
202 { |
|
203 Print(EAlways, "Debuggable : True\n"); |
|
204 } |
|
205 else |
|
206 { |
|
207 Print(EAlways, "Debuggable : False\n"); |
|
208 } |
|
209 |
|
210 if(flags & KImageSMPSafe) |
|
211 { |
|
212 Print(EAlways, "SMP Safe : True\n"); |
|
213 } |
|
214 else |
|
215 { |
|
216 Print(EAlways, "SMP Safe : False\n"); |
|
217 } |
|
218 } |
|
219 |
|
220 if (hdrfmt >= KImageHdrFmt_V && (aDumpFlags&(EDumpHeader|EDumpSecurityInfo))) |
|
221 { |
|
222 // |
|
223 // Important. Don't change output format of following security info |
|
224 // because this is relied on by used by "Symbian Signed". |
|
225 // |
|
226 E32ImageHeaderV* v = iHdr; |
|
227 Print(EAlways, "Secure ID: %08x\n", v->iS.iSecureId); |
|
228 Print(EAlways, "Vendor ID: %08x\n", v->iS.iVendorId); |
|
229 Print(EAlways, "Capabilities: %08x %08x\n", v->iS.iCaps[1], v->iS.iCaps[0]); |
|
230 if(aDumpFlags&EDumpSecurityInfo) |
|
231 { |
|
232 TInt i; |
|
233 for(i=0; i<ECapability_Limit; i++) |
|
234 if(v->iS.iCaps[i>>5]&(1<<(i&31))) |
|
235 Print(EAlways, " %s\n", CapabilityNames[i]); |
|
236 Print(EAlways, "\n"); |
|
237 } |
|
238 } |
|
239 |
|
240 if(aDumpFlags&EDumpHeader) |
|
241 { |
|
242 if (hdrfmt >= KImageHdrFmt_V) |
|
243 { |
|
244 E32ImageHeaderV* v = iHdr; |
|
245 TUint32 xd = v->iExceptionDescriptor; |
|
246 if ((xd & 1) && (xd != 0xffffffffu)) |
|
247 { |
|
248 xd &= ~1; |
|
249 Print(EAlways, "Exception Descriptor Offset: %08x\n", v->iExceptionDescriptor); |
|
250 TExceptionDescriptor * aED = (TExceptionDescriptor * )(iData + v->iCodeOffset + xd); |
|
251 Print(EAlways, "Exception Index Table Base: %08x\n", aED->iExIdxBase); |
|
252 Print(EAlways, "Exception Index Table Limit: %08x\n", aED->iExIdxLimit); |
|
253 Print(EAlways, "RO Segment Base: %08x\n", aED->iROSegmentBase); |
|
254 Print(EAlways, "RO Segment Limit: %08x\n", aED->iROSegmentLimit); |
|
255 } |
|
256 else |
|
257 Print(EAlways, "No Exception Descriptor\n"); |
|
258 |
|
259 Print(EAlways, "Export Description: Size=%03x, Type=%02x\n", v->iExportDescSize, v->iExportDescType); |
|
260 if (v->iExportDescType != KImageHdr_ExpD_NoHoles) |
|
261 { |
|
262 TInt nb = v->iExportDescSize; |
|
263 TInt i; |
|
264 TInt j = 0; |
|
265 for (i=0; i<nb; ++i) |
|
266 { |
|
267 if (++j == 8) |
|
268 { |
|
269 j = 0; |
|
270 Print(EAlways,"\n"); |
|
271 } |
|
272 Print(EAlways," %02x", v->iExportDesc[i]); |
|
273 } |
|
274 Print(EAlways,"\n"); |
|
275 } |
|
276 TInt r = CheckExportDescription(); |
|
277 if (r == KErrNone) |
|
278 Print(EAlways,"Export description consistent\n"); |
|
279 else if (r == KErrNotSupported) |
|
280 Print(EAlways,"Export description type not recognised\n"); |
|
281 else |
|
282 Print(EAlways,"!! Export description inconsistent !!\n"); |
|
283 } |
|
284 |
|
285 TUint32 mv = iOrigHdr->ModuleVersion(); |
|
286 Print(EAlways, "Module Version: %d.%d\n", mv>>16, mv&0xffff); |
|
287 if (impfmt == KImageImpFmt_PE) |
|
288 { |
|
289 Print(EAlways, "Imports are PE-style\n"); |
|
290 } |
|
291 else if (impfmt == KImageImpFmt_ELF) |
|
292 { |
|
293 Print(EAlways, "Imports are ELF-style\n"); |
|
294 } |
|
295 else if (impfmt == KImageImpFmt_PE2) |
|
296 { |
|
297 Print(EAlways, "Imports are PE-style without redundant ordinal lists\n"); |
|
298 } |
|
299 if (isARM) |
|
300 { |
|
301 if (abi == KImageABI_GCC98r2) |
|
302 { |
|
303 Print(EAlways, "GCC98r2 ABI\n"); |
|
304 } |
|
305 else if (abi == KImageABI_EABI) |
|
306 { |
|
307 Print(EAlways, "ARM EABI\n"); |
|
308 } |
|
309 if (ept == KImageEpt_Eka1) |
|
310 { |
|
311 Print(EAlways, "Built against EKA1\n"); |
|
312 } |
|
313 else if (ept == KImageEpt_Eka2) |
|
314 { |
|
315 Print(EAlways, "Built against EKA2\n"); |
|
316 } |
|
317 } |
|
318 |
|
319 Print(EAlways, "Uids:\t\t%08x %08x %08x (%08x)\n", iOrigHdr->iUid1, iOrigHdr->iUid2, iOrigHdr->iUid3, iOrigHdr->iUidChecksum); |
|
320 if (hdrfmt >= KImageHdrFmt_V) |
|
321 Print(EAlways, "Header CRC:\t%08x\n", iHdr->iHeaderCrc); |
|
322 Print(EAlways, "File Size:\t%08x\n", iSize); |
|
323 Print(EAlways, "Code Size:\t%08x\n", iOrigHdr->iCodeSize); |
|
324 Print(EAlways, "Data Size:\t%08x\n", iOrigHdr->iDataSize); |
|
325 Print(EAlways, "Compression:\t%08x\n", iOrigHdr->iCompressionType); |
|
326 Print(EAlways, "Min Heap Size:\t%08x\n", iOrigHdr->iHeapSizeMin); |
|
327 Print(EAlways, "Max Heap Size:\t%08x\n", iOrigHdr->iHeapSizeMax); |
|
328 Print(EAlways, "Stack Size:\t%08x\n", iOrigHdr->iStackSize); |
|
329 Print(EAlways, "Code link addr:\t%08x\n", iOrigHdr->iCodeBase); |
|
330 Print(EAlways, "Data link addr:\t%08x\n", iOrigHdr->iDataBase); |
|
331 Print(EAlways, "Code reloc offset:\t%08x\n", OrigCodeRelocOffset()); |
|
332 Print(EAlways, "Data reloc offset:\t%08x\n", OrigDataRelocOffset()); |
|
333 Print(EAlways, "Dll ref table count: %d\n", iOrigHdr->iDllRefTableCount); |
|
334 |
|
335 if (iOrigHdr->iCodeSize || iOrigHdr->iDataSize || iOrigHdr->iBssSize || iOrigHdr->iImportOffset) |
|
336 Print(EAlways, " Offset Size Relocs #Relocs\n"); |
|
337 |
|
338 Print(EAlways, "Code %06x %06x", OrigCodeOffset(), iOrigHdr->iCodeSize); |
|
339 if (iOrigHdr->iCodeRelocOffset) |
|
340 { |
|
341 E32RelocSection *r=(E32RelocSection *)(iData + iOrigHdr->iCodeRelocOffset); |
|
342 Print(EAlways, " %06x %06x", OrigCodeRelocOffset(), r->iNumberOfRelocs); |
|
343 } |
|
344 else |
|
345 Print(EAlways, " "); |
|
346 Print(EAlways, " +%06x (entry pnt)", iOrigHdr->iEntryPoint); |
|
347 nl(); |
|
348 |
|
349 Print(EAlways, "Data %06x %06x", OrigDataOffset(), iOrigHdr->iDataSize); |
|
350 if (iOrigHdr->iDataRelocOffset) |
|
351 { |
|
352 E32RelocSection *r=(E32RelocSection *)(iData + iOrigHdr->iDataRelocOffset); |
|
353 Print(EAlways, " %06x %06x", OrigDataRelocOffset(), r->iNumberOfRelocs); |
|
354 } |
|
355 nl(); |
|
356 |
|
357 Print(EAlways, "Bss %06x\n", iOrigHdr->iBssSize); |
|
358 |
|
359 if (iOrigHdr->iExportDirOffset) |
|
360 Print(EAlways, "Export %06x %06x (%d entries)\n", OrigExportDirOffset(), iOrigHdr->iExportDirCount*4, iOrigHdr->iExportDirCount); |
|
361 if (iOrigHdr->iImportOffset) |
|
362 Print(EAlways, "Import %06x\n", OrigImportOffset()); |
|
363 } |
|
364 } |
|
365 |
|
366 void dump(TUint *aData, TInt aLength) |
|
367 { |
|
368 TUint *p=aData; |
|
369 TInt i=0; |
|
370 char line[256]; |
|
371 char *cp=(char*)aData; |
|
372 TInt j=0; |
|
373 memset(line,' ',sizeof(line)); |
|
374 while (i<aLength) |
|
375 { |
|
376 TInt ccount=0; |
|
377 char* linep=&line[8*9+2]; |
|
378 Print(EAlways, "%06x:", i); |
|
379 while (i<aLength && ccount<8) |
|
380 { |
|
381 Print(EAlways," %08x", *p++); |
|
382 i+=4; |
|
383 ccount++; |
|
384 for (j=0; j<4; j++) |
|
385 { |
|
386 char c=*cp++; |
|
387 if (c<32 || c>127) |
|
388 { |
|
389 c = '.'; |
|
390 } |
|
391 *linep++ = c; |
|
392 } |
|
393 } |
|
394 *linep='\0'; |
|
395 Print(EAlways, "%s", line+(ccount*9)); |
|
396 nl(); |
|
397 } |
|
398 } |
|
399 |
|
400 void dumprelocs(char *aRelocs) |
|
401 { |
|
402 |
|
403 TInt num=((E32RelocSection *)aRelocs)->iNumberOfRelocs; |
|
404 Print(EAlways, "%d relocs\n", num); |
|
405 aRelocs+=sizeof(E32RelocSection); |
|
406 TInt printed=0; |
|
407 while (num>0) |
|
408 { |
|
409 TInt page=*(TUint *)aRelocs; |
|
410 TInt size=*(TUint *)(aRelocs+4); |
|
411 TInt pagesize=size; |
|
412 size-=8; |
|
413 TUint16 *p=(TUint16 *)(aRelocs+8); |
|
414 while (size>0) |
|
415 { |
|
416 TUint a=*p++; |
|
417 TUint relocType = a >> 12; |
|
418 if (relocType==3 || relocType==1) |
|
419 { |
|
420 Print(EAlways, "%08x(%1x) ", page+(a&0x0fff), relocType); |
|
421 printed++; |
|
422 if (printed>3) |
|
423 { |
|
424 nl(); |
|
425 printed=0; |
|
426 } |
|
427 } |
|
428 size-=2; |
|
429 num--; |
|
430 } |
|
431 aRelocs+=pagesize; |
|
432 } |
|
433 nl(); |
|
434 } |
|
435 |
|
436 |
|
437 void E32ImageFile::DumpData(TInt aDumpFlags) |
|
438 { |
|
439 if(aDumpFlags&EDumpCode) |
|
440 { |
|
441 Print(EAlways, "\nCode (text size=%08x)\n", iOrigHdr->iTextSize); |
|
442 dump((TUint *)(iData + iOrigHdr->iCodeOffset), iOrigHdr->iCodeSize); |
|
443 if (iOrigHdr->iCodeRelocOffset) |
|
444 dumprelocs(iData + iOrigHdr->iCodeRelocOffset); |
|
445 } |
|
446 |
|
447 if((aDumpFlags&EDumpData) && iOrigHdr->iDataOffset) |
|
448 { |
|
449 Print(EAlways, "\nData\n"); |
|
450 dump((TUint *)(iData + iOrigHdr->iDataOffset), iOrigHdr->iDataSize); |
|
451 if (iOrigHdr->iDataRelocOffset) |
|
452 dumprelocs(iData + iOrigHdr->iDataRelocOffset); |
|
453 } |
|
454 |
|
455 if(aDumpFlags&EDumpExports) |
|
456 { |
|
457 Print(EAlways, "\nNumber of exports = %d\n", iOrigHdr->iExportDirCount); |
|
458 TInt i; |
|
459 TUint* exports = (TUint*)(iData + iOrigHdr->iExportDirOffset); |
|
460 TUint absoluteEntryPoint = iOrigHdr->iEntryPoint + iOrigHdr->iCodeBase; |
|
461 TUint impfmt = iOrigHdr->ImportFormat(); |
|
462 TUint absentVal = (impfmt == KImageImpFmt_ELF) ? absoluteEntryPoint : iOrigHdr->iEntryPoint; |
|
463 for (i=0; i<iOrigHdr->iExportDirCount; ++i) |
|
464 { |
|
465 TUint exp = exports[i]; |
|
466 if (exp == absentVal) |
|
467 Print(EAlways, "\tOrdinal %5d:\tABSENT\n", i+1); |
|
468 else |
|
469 Print(EAlways, "\tOrdinal %5d:\t%08x\n", i+1, exp); |
|
470 } |
|
471 } |
|
472 |
|
473 // |
|
474 // Important. Don't change output format of following inport info |
|
475 // because this is relied on by tools used by "Symbian Signed". |
|
476 // |
|
477 if((aDumpFlags&EDumpImports) && iOrigHdr->iImportOffset) |
|
478 { |
|
479 const E32ImportSection* isection = (const E32ImportSection*)(iData + iOrigHdr->iImportOffset); |
|
480 TUint* iat = (TUint*)((TUint8*)iData + iOrigHdr->iCodeOffset + iOrigHdr->iTextSize); |
|
481 Print(EAlways, "\nIdata\tSize=%08x\n", isection->iSize); |
|
482 Print(EAlways, "Offset of import address table (relative to code section): %08x\n", iOrigHdr->iTextSize); |
|
483 TInt d; |
|
484 const E32ImportBlock* b = (const E32ImportBlock*)(isection + 1); |
|
485 for (d=0; d<iOrigHdr->iDllRefTableCount; d++) |
|
486 { |
|
487 char* dllname = iData + iOrigHdr->iImportOffset + b->iOffsetOfDllName; |
|
488 TInt n = b->iNumberOfImports; |
|
489 Print(EAlways, "%d imports from %s\n", b->iNumberOfImports, dllname); |
|
490 const TUint* p = b->Imports(); |
|
491 TUint impfmt = iOrigHdr->ImportFormat(); |
|
492 if (impfmt == KImageImpFmt_ELF) |
|
493 { |
|
494 while (n--) |
|
495 { |
|
496 TUint impd_offset = *p++; |
|
497 TUint impd = *(TUint*)(iData + iOrigHdr->iCodeOffset + impd_offset); |
|
498 TUint ordinal = impd & 0xffff; |
|
499 TUint offset = impd >> 16; |
|
500 if (offset) |
|
501 Print(EAlways, "%10d offset by %d\n", ordinal, offset); |
|
502 else |
|
503 Print(EAlways, "%10d\n", ordinal); |
|
504 } |
|
505 } |
|
506 else |
|
507 { |
|
508 while (n--) |
|
509 Print(EAlways, "\t%d\n", *iat++); |
|
510 } |
|
511 b = b->NextBlock(impfmt); |
|
512 } |
|
513 } |
|
514 } |