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