toolsandutils/e32tools/elf2e32/source/imgdump.cpp
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 // Copyright (c) 2005-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 // Implementation of the e32 image dump for the elf2e32 tool
       
    15 // @internalComponent
       
    16 // @released
       
    17 // 
       
    18 //
       
    19 
       
    20 #define __REFERENCE_CAPABILITY_NAMES__
       
    21 
       
    22 #include "e32imagefile.h"
       
    23 #include "pl_common.h"
       
    24 #include <string.h>
       
    25 #include <stdarg.h>
       
    26 #include <stdio.h>
       
    27 
       
    28 #ifdef __LINUX__ 
       
    29     #define VSNPRINTF vsnprintf
       
    30 #else 
       
    31     #define VSNPRINTF _vsnprintf
       
    32 #endif 
       
    33 
       
    34 using std::cout;
       
    35 
       
    36 const TInt KMaxStringLength=0x400;
       
    37 
       
    38 /**
       
    39 Variadic Function to print string.
       
    40 
       
    41 @internalComponent
       
    42 @released
       
    43 
       
    44 @param aFmt
       
    45 Formatted string.
       
    46 */
       
    47 void PrintString(const char *aFmt,...)
       
    48 {
       
    49 	TText imageText[KMaxStringLength];
       
    50 	va_list list;
       
    51 	va_start(list,aFmt);
       
    52 	VSNPRINTF((char *)imageText,KMaxStringLength,aFmt,list);
       
    53 	va_end(list);
       
    54 	cout << imageText;
       
    55 
       
    56 	cout.flush();
       
    57 }
       
    58 
       
    59 /**
       
    60 Function to set priority.
       
    61 
       
    62 @internalComponent
       
    63 @released
       
    64 
       
    65 @param aPri
       
    66 Priority Type passed in
       
    67 @param aStr
       
    68 The priority value corresponding to the appropriate priority type
       
    69 */
       
    70 void PriorityToStr(TProcessPriority aPri, char *aStr)
       
    71 {
       
    72 	if (aPri==EPrioritySupervisor)
       
    73 		strcpy(aStr,"Supervisor");
       
    74 
       
    75 	else if (aPri>EPriorityRealTimeServer)
       
    76 		sprintf(aStr, "RealTime+%d", aPri-EPriorityRealTimeServer);
       
    77 	else if (aPri==EPriorityRealTimeServer)
       
    78 		strcpy(aStr,"RealTime");
       
    79 
       
    80 	else if (aPri>EPriorityFileServer)
       
    81 		sprintf(aStr, "FileServer+%d", aPri-EPriorityFileServer);
       
    82 	else if (aPri==EPriorityFileServer)
       
    83 		strcpy(aStr,"FileServer");
       
    84 
       
    85 	else if (aPri>EPriorityWindowServer)
       
    86 		sprintf(aStr, "WindowServer+%d", aPri-EPriorityWindowServer);
       
    87 	else if (aPri==EPriorityWindowServer)
       
    88 		strcpy(aStr,"WindowServer");
       
    89 
       
    90 	else if (aPri>EPriorityHigh)
       
    91 		sprintf(aStr, "High+%d", aPri-EPriorityHigh);
       
    92 	else if (aPri==EPriorityHigh)
       
    93 		strcpy(aStr,"High");
       
    94 
       
    95 	else if (aPri>EPriorityForeground)
       
    96 		sprintf(aStr, "Foreground+%d", aPri-EPriorityForeground);
       
    97 	else if (aPri==EPriorityForeground)
       
    98 		strcpy(aStr,"Foreground");
       
    99 
       
   100 	else if (aPri>EPriorityBackground)
       
   101 		sprintf(aStr, "Background+%d", aPri-EPriorityBackground);
       
   102 	else if (aPri==EPriorityBackground)
       
   103 		strcpy(aStr,"Background");
       
   104 
       
   105 	else if (aPri>EPriorityLow)
       
   106 		sprintf(aStr, "Low+%d", aPri-EPriorityLow);
       
   107 	else if (aPri==EPriorityLow)
       
   108 		strcpy(aStr,"Low");
       
   109 
       
   110 	else
       
   111 		sprintf(aStr, "Illegal (%d)", aPri);
       
   112 }
       
   113 
       
   114 /**
       
   115 Function to dump e32 image.
       
   116 
       
   117 @internalComponent
       
   118 @released
       
   119 
       
   120 @param aFileName
       
   121 Name of the E32image to be dumped.
       
   122 @param aDumpFlags
       
   123 sub options passed to the 'dump' option
       
   124 */
       
   125 void E32ImageFile::Dump(TText *aFileName,TInt aDumpFlags)
       
   126 {
       
   127 	PrintString("E32ImageFile '%s'\n", aFileName);
       
   128 	DumpHeader(aDumpFlags);
       
   129 	DumpData(aDumpFlags);
       
   130 }
       
   131 
       
   132 /**
       
   133 Function to dump e32 image header.
       
   134 
       
   135 @internalComponent
       
   136 @released
       
   137 
       
   138 @param aDumpFlags
       
   139 The flags set based on the sub options provided to the program.
       
   140 */
       
   141 void E32ImageFile::DumpHeader(TInt aDumpFlags)
       
   142 {
       
   143 	TUint flags = iOrigHdr->iFlags;
       
   144 	TUint abi = E32ImageHeader::ABIFromFlags(flags);
       
   145 	TUint hdrfmt = E32ImageHeader::HdrFmtFromFlags(flags);
       
   146 	TUint impfmt = E32ImageHeader::ImpFmtFromFlags(flags);
       
   147 	TUint ept = E32ImageHeader::EptFromFlags(flags);
       
   148 	TBool isARM = EFalse;
       
   149 
       
   150 	if(aDumpFlags&EDumpHeader)
       
   151 	{
       
   152 		PrintString("V%d.%02d(%03d)", iOrigHdr->iToolsVersion.iMajor,iOrigHdr->iToolsVersion.iMinor,iOrigHdr->iToolsVersion.iBuild);
       
   153 		PrintString("\tTime Stamp: %08x,%08x\n", iOrigHdr->iTimeHi, iOrigHdr->iTimeLo);
       
   154 		char sig[5];
       
   155 		memcpy(sig, (const char*)&iOrigHdr->iSignature, 4);
       
   156 		sig[4]=0;
       
   157 		PrintString(sig);
       
   158 		if (iOrigHdr->iFlags&KImageDll)
       
   159 			PrintString(" Dll for ");
       
   160 		else
       
   161 			PrintString(" Exe for ");
       
   162 		switch (iOrigHdr->CpuIdentifier())
       
   163 		{
       
   164 		case ECpuX86:
       
   165 			PrintString("X86 CPU\n");
       
   166 			break;
       
   167 		case ECpuArmV4:
       
   168 			isARM = ETrue;
       
   169 			PrintString("ARMV4 CPU\n");
       
   170 			break;
       
   171 		case ECpuArmV5:
       
   172 			isARM = ETrue;
       
   173 			PrintString("ARMV5 CPU\n");
       
   174 			break;
       
   175 		case ECpuMCore:
       
   176 			PrintString("M*Core CPU\n");
       
   177 			break;
       
   178 		case ECpuUnknown:
       
   179 			PrintString("Unknown CPU\n");
       
   180 			break;
       
   181 		default:
       
   182 			PrintString("something or other\n");
       
   183 			break;
       
   184 		}
       
   185 		
       
   186 		PrintString("Flags:\t%08x\n", flags);
       
   187 
       
   188 		if (!(flags & KImageDll))
       
   189 		{
       
   190 			char str[80];
       
   191 			PriorityToStr(iOrigHdr->ProcessPriority(), str);
       
   192 			PrintString("Priority %s\n", str);
       
   193 			if (flags & KImageFixedAddressExe)
       
   194 				PrintString("Fixed process\n");
       
   195 		}
       
   196 		
       
   197 		if (flags & KImageNoCallEntryPoint)
       
   198 			PrintString("Entry points are not called\n");
       
   199 		
       
   200 		PrintString("Image header is format %d\n", hdrfmt>>24);
       
   201 		TUint compression = iOrigHdr->CompressionType();
       
   202 		
       
   203 		switch (compression)
       
   204 		{
       
   205 		case KFormatNotCompressed:
       
   206 			PrintString("Image is not compressed\n");
       
   207 			break;
       
   208 		case KUidCompressionDeflate:
       
   209 			PrintString("Image is compressed using the DEFLATE algorithm\n");
       
   210 			break;
       
   211 		case KUidCompressionBytePair:
       
   212 			PrintString("Image is compressed using the BYTEPAIR algorithm\n");
       
   213 			break;
       
   214 		default:
       
   215 			PrintString("Image compression type UNKNOWN (%08x)\n", compression);
       
   216 		}
       
   217 		
       
   218 		if (compression)
       
   219 		{
       
   220 			PrintString("Uncompressed size %08x\n", iOrigHdr->UncompressedFileSize());
       
   221 		}
       
   222 
       
   223 		TUint FPU = flags & KImageHWFloatMask;
       
   224 
       
   225 		if (FPU == KImageHWFloat_None)
       
   226 			PrintString("Image FPU support : Soft VFP\n");
       
   227 		else if (FPU == KImageHWFloat_VFPv2) 
       
   228 			PrintString("Image FPU support : VFPv2\n");
       
   229 		else
       
   230 			PrintString("Image FPU support : Unknown\n");
       
   231 
       
   232 		// Code paging.
       
   233 
       
   234 		if (flags & KImageCodeUnpaged)
       
   235 		{
       
   236 			PrintString("Code Paging : Unpaged\n");
       
   237 		}
       
   238 		else if (flags & KImageCodePaged)
       
   239 		{
       
   240 			PrintString("Code Paging : Paged\n");
       
   241 		}
       
   242 		else
       
   243 		{
       
   244 			PrintString("Code Paging : Default\n");
       
   245 		}
       
   246 
       
   247 		// Data paging.
       
   248 
       
   249 		if (flags & KImageDataUnpaged)
       
   250 		{
       
   251 			PrintString("Data Paging : Unpaged\n");
       
   252 		}
       
   253 		else if (flags & KImageDataPaged)
       
   254 		{
       
   255 			PrintString("Data Paging : Paged\n");
       
   256 		}
       
   257 		else
       
   258 		{
       
   259 			PrintString("Data Paging : Default\n");
       
   260 		}
       
   261 
       
   262 		if (iOrigHdr->iFlags & KImageDebuggable)
       
   263 		{
       
   264 			PrintString("Debuggable : True\n");
       
   265 		}
       
   266 		else
       
   267 		{
       
   268 			PrintString("Debuggable : False\n");
       
   269 		}
       
   270 		if (iOrigHdr->iFlags & KImageSMPSafe)
       
   271 		{
       
   272 			PrintString("SMP Safe : True\n");
       
   273 		}
       
   274 		else
       
   275 		{
       
   276 			PrintString("SMP Safe : False\n");
       
   277 		}
       
   278 	}
       
   279 
       
   280 	if (hdrfmt >= KImageHdrFmt_V && (aDumpFlags&(EDumpHeader|EDumpSecurityInfo)))
       
   281 	{
       
   282 		//
       
   283 		// Important. Don't change output format of following security info
       
   284 		// because this is relied on by used by "Symbian Signed".
       
   285 		//
       
   286 		E32ImageHeaderV* v = iHdr;
       
   287 		PrintString("Secure ID: %08x\n", v->iS.iSecureId);
       
   288 		PrintString("Vendor ID: %08x\n", v->iS.iVendorId);
       
   289 		PrintString("Capabilities: %08x %08x\n", v->iS.iCaps[1], v->iS.iCaps[0]);
       
   290 		if(aDumpFlags&EDumpSecurityInfo)
       
   291 		{
       
   292 			TInt i;
       
   293 			for(i=0; i<ECapability_Limit; i++)
       
   294 				if(v->iS.iCaps[i>>5]&(1<<(i&31)))
       
   295 					PrintString("              %s\n", CapabilityNames[i]);
       
   296 			PrintString("\n");
       
   297 		}
       
   298 	}
       
   299 
       
   300 	if(aDumpFlags&EDumpHeader)
       
   301 	{
       
   302 		if (hdrfmt >= KImageHdrFmt_V)
       
   303 		{
       
   304 			E32ImageHeaderV* v = iHdr;
       
   305 			TUint32 xd = v->iExceptionDescriptor;
       
   306 			if ((xd & 1) && (xd != 0xffffffffu))
       
   307 			{
       
   308 				xd &= ~1;
       
   309 				PrintString("Exception Descriptor Offset:  %08x\n", v->iExceptionDescriptor);
       
   310 				TExceptionDescriptor * aED = (TExceptionDescriptor * )(iData + v->iCodeOffset + xd);
       
   311 				PrintString("Exception Index Table Base: %08x\n", aED->iExIdxBase);
       
   312 				PrintString("Exception Index Table Limit: %08x\n", aED->iExIdxLimit);
       
   313 				PrintString("RO Segment Base: %08x\n", aED->iROSegmentBase);
       
   314 				PrintString("RO Segment Limit: %08x\n", aED->iROSegmentLimit);
       
   315 			}
       
   316 			else
       
   317 				PrintString("No Exception Descriptor\n");
       
   318 
       
   319 			PrintString("Export Description: Size=%03x, Type=%02x\n", v->iExportDescSize, v->iExportDescType);
       
   320 			
       
   321 			if (v->iExportDescType != KImageHdr_ExpD_NoHoles)
       
   322 			{
       
   323 				TInt nb = v->iExportDescSize;
       
   324 				TInt i;
       
   325 				TInt j = 0;
       
   326 				for (i=0; i<nb; ++i)
       
   327 				{
       
   328 					if (++j == 8)
       
   329 					{
       
   330 						j = 0;
       
   331 						PrintString("\n");
       
   332 					}
       
   333 					PrintString(" %02x", v->iExportDesc[i]);
       
   334 				}
       
   335 				PrintString("\n");
       
   336 			}
       
   337 			
       
   338 			TInt r = CheckExportDescription();
       
   339 			
       
   340 			if (r == KErrNone)
       
   341 				PrintString("Export description consistent\n");
       
   342 			else if (r == KErrNotSupported)
       
   343 				PrintString("Export description type not recognised\n");
       
   344 			else
       
   345 				PrintString("!! Export description inconsistent !!\n");
       
   346 		}
       
   347 
       
   348 		TUint32 mv = iOrigHdr->ModuleVersion();
       
   349 		PrintString("Module Version: %d.%d\n", mv>>16, mv&0xffff);
       
   350 		
       
   351 		if (impfmt == KImageImpFmt_PE)
       
   352 		{
       
   353 			PrintString("Imports are PE-style\n");
       
   354 		}
       
   355 		else if (impfmt == KImageImpFmt_ELF)
       
   356 		{
       
   357 			PrintString("Imports are ELF-style\n");
       
   358 		}
       
   359 		else if (impfmt == KImageImpFmt_PE2)
       
   360 		{
       
   361 			PrintString("Imports are PE-style without redundant ordinal lists\n");
       
   362 		}
       
   363 		
       
   364 		if (isARM)
       
   365 		{
       
   366 			if (abi == KImageABI_GCC98r2)
       
   367 			{
       
   368 				PrintString("GCC98r2 ABI\n");
       
   369 			}
       
   370 			else if (abi == KImageABI_EABI)
       
   371 			{
       
   372 				PrintString("ARM EABI\n");
       
   373 			}
       
   374 			if (ept == KImageEpt_Eka1)
       
   375 			{
       
   376 				PrintString("Built against EKA1\n");
       
   377 			}
       
   378 			else if (ept == KImageEpt_Eka2)
       
   379 			{
       
   380 				PrintString("Built against EKA2\n");
       
   381 			}
       
   382 		}
       
   383 
       
   384 		PrintString("Uids:\t\t%08x %08x %08x (%08x)\n", iOrigHdr->iUid1, iOrigHdr->iUid2, iOrigHdr->iUid3, iOrigHdr->iUidChecksum);
       
   385 		
       
   386 		if (hdrfmt >= KImageHdrFmt_V)
       
   387 			PrintString("Header CRC:\t%08x\n", iHdr->iHeaderCrc);
       
   388 		
       
   389 		PrintString("File Size:\t%08x\n", iSize);
       
   390 		PrintString("Code Size:\t%08x\n", iOrigHdr->iCodeSize);
       
   391 		PrintString("Data Size:\t%08x\n", iOrigHdr->iDataSize);
       
   392 		PrintString("Compression:\t%08x\n", iOrigHdr->iCompressionType);
       
   393 		PrintString("Min Heap Size:\t%08x\n", iOrigHdr->iHeapSizeMin);
       
   394 		PrintString("Max Heap Size:\t%08x\n", iOrigHdr->iHeapSizeMax);
       
   395 		PrintString("Stack Size:\t%08x\n", iOrigHdr->iStackSize);
       
   396 		PrintString("Code link addr:\t%08x\n", iOrigHdr->iCodeBase);
       
   397 		PrintString("Data link addr:\t%08x\n", iOrigHdr->iDataBase);
       
   398 		PrintString("Code reloc offset:\t%08x\n", OrigCodeRelocOffset());
       
   399 		PrintString("Data reloc offset:\t%08x\n", OrigDataRelocOffset());
       
   400 		PrintString("Dll ref table count: %d\n", iOrigHdr->iDllRefTableCount);
       
   401 
       
   402 		if (iOrigHdr->iCodeSize || iOrigHdr->iDataSize || iOrigHdr->iBssSize || iOrigHdr->iImportOffset)
       
   403 			PrintString("        Offset  Size  Relocs #Relocs\n");
       
   404 
       
   405 		PrintString("Code    %06x %06x", OrigCodeOffset(), iOrigHdr->iCodeSize);
       
   406 		
       
   407 		if (iOrigHdr->iCodeRelocOffset)
       
   408 		{
       
   409 			E32RelocSection *r=(E32RelocSection *)(iData + iOrigHdr->iCodeRelocOffset);
       
   410 			PrintString(" %06x %06x", OrigCodeRelocOffset(), r->iNumberOfRelocs);
       
   411 		}
       
   412 		else
       
   413 			PrintString("              ");
       
   414 		
       
   415 		PrintString("        +%06x (entry pnt)", iOrigHdr->iEntryPoint);
       
   416 		PrintString("\n");
       
   417 
       
   418 		PrintString("Data    %06x %06x", OrigDataOffset(), iOrigHdr->iDataSize);
       
   419 		
       
   420 		if (iOrigHdr->iDataRelocOffset)
       
   421 		{
       
   422 			E32RelocSection *r=(E32RelocSection *)(iData + iOrigHdr->iDataRelocOffset);
       
   423 			PrintString(" %06x %06x", OrigDataRelocOffset(), r->iNumberOfRelocs);
       
   424 		}
       
   425 		PrintString("\n");
       
   426 
       
   427 		PrintString("Bss            %06x\n", iOrigHdr->iBssSize);
       
   428 
       
   429 		if (iOrigHdr->iExportDirOffset)
       
   430 			PrintString("Export  %06x %06x                      (%d entries)\n", OrigExportDirOffset(), iOrigHdr->iExportDirCount*4, iOrigHdr->iExportDirCount);
       
   431 		
       
   432 		if (iOrigHdr->iImportOffset)
       
   433 			PrintString("Import  %06x\n", OrigImportOffset());
       
   434 	}
       
   435 }
       
   436 
       
   437 /**
       
   438 Function to dump e32 image.
       
   439 
       
   440 @internalComponent
       
   441 @released
       
   442 
       
   443 @param aData
       
   444 Data to be dumped
       
   445 @param aLength
       
   446 Length of the file
       
   447 */
       
   448 void dump(TUint *aData, TInt aLength)
       
   449 {
       
   450 	TUint *p=aData;
       
   451 	TInt i=0;
       
   452 	char line[256];
       
   453 	char *cp=(char*)aData;
       
   454 	TInt j=0;
       
   455 	memset(line,' ',sizeof(line));
       
   456 	while (i<aLength)
       
   457 	{
       
   458 		TInt ccount=0;
       
   459 		char* linep=&line[8*9+2];
       
   460 		PrintString("%06x:", i);
       
   461 		while (i<aLength && ccount<8)
       
   462 		{
       
   463 			PrintString(" %08x", *p++);
       
   464 			i+=4;
       
   465 			ccount++;
       
   466 			for (j=0; j<4; j++)
       
   467 			{
       
   468 				char c=*cp++;
       
   469 				if (c<32 || c>127)
       
   470 				{
       
   471 					c = '.';
       
   472 				}
       
   473 				*linep++ = c;
       
   474 			}
       
   475 		}
       
   476 		*linep='\0';
       
   477 		PrintString("%s", line+(ccount*9));
       
   478 		PrintString("\n");
       
   479 	}
       
   480 }
       
   481 
       
   482 /**
       
   483 Function to dump relocations.
       
   484 
       
   485 @internalComponent
       
   486 @released
       
   487 
       
   488 @param aRelocs
       
   489 Character pointer to relocations.
       
   490 */
       
   491 void dumprelocs(char *aRelocs)
       
   492 {
       
   493 
       
   494 	TInt num=((E32RelocSection *)aRelocs)->iNumberOfRelocs;
       
   495 	PrintString("%d relocs\n", num);
       
   496 	aRelocs+=sizeof(E32RelocSection);
       
   497 	TInt printed=0;
       
   498 	while (num>0)
       
   499 	{
       
   500 		TInt page=*(TUint *)aRelocs;
       
   501 		TInt size=*(TUint *)(aRelocs+4);
       
   502 		TInt pagesize=size;
       
   503 		size-=8;
       
   504 		TUint16 *p=(TUint16 *)(aRelocs+8);
       
   505 		while (size>0)
       
   506 		{
       
   507 			TUint a=*p++;
       
   508 			TUint relocType = (a & 0x3000) >> 12;
       
   509 			if ((relocType == 1) || (relocType == 3)) //only relocation type1 and type3
       
   510 			{
       
   511 				PrintString("%08x(%d) ", page + (a&0x0fff), relocType);
       
   512 				printed++;
       
   513 				if (printed>3)
       
   514 				{
       
   515 					PrintString("\n");
       
   516 					printed=0;
       
   517 				}
       
   518 			}
       
   519 			size-=2;
       
   520 			num--;
       
   521 		}
       
   522 		aRelocs+=pagesize;
       
   523 	}
       
   524 	PrintString("\n");
       
   525 }
       
   526 
       
   527 /**
       
   528 Function to dump e32 image data.
       
   529 
       
   530 @internalComponent
       
   531 @released
       
   532 
       
   533 @param aDumpFlags
       
   534 The flags set based on the sub options provided to the program.
       
   535 */
       
   536 void E32ImageFile::DumpData(TInt aDumpFlags)
       
   537 {
       
   538 	if(aDumpFlags&EDumpCode)
       
   539 	{
       
   540 		PrintString("\nCode (text size=%08x)\n", iOrigHdr->iTextSize);
       
   541 		dump((TUint *)(iData + iOrigHdr->iCodeOffset), iOrigHdr->iCodeSize);
       
   542 	
       
   543 		if (iOrigHdr->iCodeRelocOffset)
       
   544 			dumprelocs(iData + iOrigHdr->iCodeRelocOffset);
       
   545 	}
       
   546 
       
   547 	if((aDumpFlags&EDumpData) && iOrigHdr->iDataOffset)
       
   548 	{
       
   549 		PrintString("\nData\n");
       
   550 		dump((TUint *)(iData + iOrigHdr->iDataOffset), iOrigHdr->iDataSize);
       
   551 	
       
   552 		if (iOrigHdr->iDataRelocOffset)
       
   553 			dumprelocs(iData + iOrigHdr->iDataRelocOffset);
       
   554 	}
       
   555 
       
   556 	if(aDumpFlags&EDumpExports)
       
   557 	{
       
   558 		PrintString("\nNumber of exports = %d\n", iOrigHdr->iExportDirCount);
       
   559 		TInt i;
       
   560 		TUint* exports = (TUint*)(iData + iOrigHdr->iExportDirOffset);
       
   561 		TUint absoluteEntryPoint = iOrigHdr->iEntryPoint + iOrigHdr->iCodeBase;
       
   562 		TUint impfmt = iOrigHdr->ImportFormat();
       
   563 		TUint absentVal = (impfmt == KImageImpFmt_ELF) ? absoluteEntryPoint : iOrigHdr->iEntryPoint;
       
   564 		for (i=0; i<iOrigHdr->iExportDirCount; ++i)
       
   565 		{
       
   566 			TUint exp = exports[i];
       
   567 			if (exp == absentVal)
       
   568 				PrintString("\tOrdinal %5d:\tABSENT\n", i+1);
       
   569 			else
       
   570 				PrintString("\tOrdinal %5d:\t%08x\n", i+1, exp);
       
   571 		}
       
   572 	}
       
   573 
       
   574 	// Important. Don't change output format of following inport info
       
   575 	// because this is relied on by tools used by "Symbian Signed".
       
   576 	if((aDumpFlags&EDumpImports) && iOrigHdr->iImportOffset)
       
   577 	{
       
   578 		const E32ImportSection* isection = (const E32ImportSection*)(iData + iOrigHdr->iImportOffset);
       
   579 		TUint* iat = (TUint*)((TUint8*)iData + iOrigHdr->iCodeOffset + iOrigHdr->iTextSize);
       
   580 		PrintString("\nIdata\tSize=%08x\n", isection->iSize);
       
   581 		PrintString("Offset of import address table (relative to code section): %08x\n", iOrigHdr->iTextSize);
       
   582 		TInt d;
       
   583 		const E32ImportBlock* b = (const E32ImportBlock*)(isection + 1);
       
   584 		for (d=0; d<iOrigHdr->iDllRefTableCount; d++)
       
   585 		{
       
   586 			char* dllname = iData + iOrigHdr->iImportOffset + b->iOffsetOfDllName;
       
   587 			TInt n = b->iNumberOfImports;
       
   588 			PrintString("%d imports from %s\n", b->iNumberOfImports, dllname);
       
   589 			const TUint* p = b->Imports();
       
   590 			TUint impfmt = iOrigHdr->ImportFormat();
       
   591 			if (impfmt == KImageImpFmt_ELF)
       
   592 			{
       
   593 				while (n--)
       
   594 				{
       
   595 					TUint impd_offset = *p++;
       
   596 					TUint impd = *(TUint*)(iData + iOrigHdr->iCodeOffset + impd_offset);
       
   597 					TUint ordinal = impd & 0xffff;
       
   598 					TUint offset = impd >> 16;
       
   599 				
       
   600 					if (offset)
       
   601 						PrintString("%10d offset by %d\n", ordinal, offset);
       
   602 					else
       
   603 						PrintString("%10d\n", ordinal);
       
   604 				}
       
   605 			}
       
   606 			else
       
   607 			{
       
   608 				while (n--)
       
   609 					PrintString("\t%d\n", *iat++);
       
   610 			}
       
   611 			b = b->NextBlock(impfmt);
       
   612 		}
       
   613 	}
       
   614 	if((aDumpFlags & EDumpSymbols) && (iOrigHdr->iFlags & KImageNmdExpData))
       
   615 	{
       
   616 		TUint* aExpTbl = (TUint*)(iData + iOrigHdr->iExportDirOffset);
       
   617 		TUint* aZeroethOrd = aExpTbl - 1;
       
   618 
       
   619 		E32EpocExpSymInfoHdr *aSymInfoHdr = (E32EpocExpSymInfoHdr*)(iData + \
       
   620 					iOrigHdr->iCodeOffset + \
       
   621 					*aZeroethOrd - iOrigHdr->iCodeBase ) ;
       
   622 		DumpSymbolInfo(aSymInfoHdr);
       
   623 	}
       
   624 }
       
   625 
       
   626 void E32ImageFile::DumpSymbolInfo(E32EpocExpSymInfoHdr *aSymInfoHdr)
       
   627 {
       
   628 	if(!aSymInfoHdr)
       
   629 		return;
       
   630 	char	*aSymTblBase = (char*)aSymInfoHdr;
       
   631 	TUint	*aSymAddrTbl;
       
   632 	char	*aSymNameTbl;
       
   633 
       
   634 	char *aStrTable = aSymTblBase + aSymInfoHdr->iStringTableOffset;
       
   635 	aSymAddrTbl = (TUint*)(aSymTblBase + aSymInfoHdr->iSymbolTblOffset);
       
   636 	aSymNameTbl = (char*)(aSymAddrTbl + aSymInfoHdr->iSymCount);
       
   637 	
       
   638 	int aIdx;
       
   639 	char *aSymName;
       
   640 
       
   641 	PrintString("\n\n\t\tSymbol Info\n");
       
   642 	if(aSymInfoHdr->iSymCount)
       
   643 	{
       
   644 		PrintString("0x%x Symbols exported\n",aSymInfoHdr->iSymCount);
       
   645 		PrintString("  Addr\t\tName\n");
       
   646 		PrintString("----------------------------------------\n");
       
   647 		TUint aNameOffset = 0;
       
   648 		for(aIdx=0;aIdx<aSymInfoHdr->iSymCount ; aIdx++)
       
   649 		{
       
   650 			if(aSymInfoHdr->iFlags & 1)
       
   651 			{
       
   652 				TUint32* aOff = ((TUint32*)aSymNameTbl+aIdx);
       
   653 				aNameOffset = (*aOff) << 2;
       
   654 				aSymName = aStrTable + aNameOffset;
       
   655 			}
       
   656 			else
       
   657 			{
       
   658 				TUint16* aOff = ((TUint16*)aSymNameTbl+aIdx);
       
   659 				aNameOffset = (*aOff) << 2;
       
   660 				aSymName = aStrTable + aNameOffset;
       
   661 			}
       
   662 			PrintString("0x%08x \t%s\t\n",aSymAddrTbl[aIdx], aSymName);
       
   663 		}
       
   664 	}
       
   665 	else
       
   666 	{
       
   667 		PrintString("No Symbol exported\n");
       
   668 	}
       
   669 	PrintString("\n\n");
       
   670 
       
   671 	if(aSymInfoHdr->iDllCount)
       
   672 	{
       
   673 		// The import table orders the dependencies alphabetically...
       
   674 		// We need to list out in the link order...
       
   675 		PrintString("%d Static dependencies found\n", aSymInfoHdr->iDllCount);
       
   676 		TUint* aDepTbl = (TUint*)((char*)aSymInfoHdr + aSymInfoHdr->iDepDllZeroOrdTableOffset);
       
   677 		TUint* aDepOffset =  (TUint*)((char*)aDepTbl - iData);
       
   678 
       
   679 		const E32ImportSection* isection = (const E32ImportSection*)(iData + iOrigHdr->iImportOffset);
       
   680 		
       
   681 		TInt d;
       
   682 
       
   683 		/* The import table has offsets to the location (in code section) where the
       
   684 		 * import is required. For dependencies pointed by 0th ordinal, this offset
       
   685 		 * must be same as the offset of the dependency table entry (relative to 
       
   686 		 * the code section).
       
   687 		 */
       
   688 		bool aZerothFound;
       
   689 		for(int aDep = 0; aDep < aSymInfoHdr->iDllCount; aDep++)
       
   690 		{
       
   691 			const E32ImportBlock* b = (const E32ImportBlock*)(isection + 1);
       
   692 			aZerothFound = false;
       
   693 			for (d=0; d<iOrigHdr->iDllRefTableCount; d++)
       
   694 			{
       
   695 				char* dllname = iData + iOrigHdr->iImportOffset + b->iOffsetOfDllName;
       
   696 				TInt n = b->iNumberOfImports;
       
   697 
       
   698 				const TUint* p = b->Imports()+ (n - 1);//start from the end of the import table
       
   699 				TUint impfmt = iOrigHdr->ImportFormat();
       
   700 				if (impfmt == KImageImpFmt_ELF)
       
   701 				{
       
   702 					while (n--)
       
   703 					{
       
   704 						TUint impd_offset = *p--;
       
   705 						TUint impd = *(TUint*)(iData + iOrigHdr->iCodeOffset + impd_offset);
       
   706 						TUint ordinal = impd & 0xffff;
       
   707 					
       
   708 						if (ordinal == 0 )
       
   709 						{
       
   710 							if( impd_offset == ((TUint)aDepOffset - iOrigHdr->iCodeOffset))
       
   711 							{
       
   712 								/* The offset in import table is same as the offset of this 
       
   713 								 * dependency entry
       
   714 								 */
       
   715 								PrintString("\t%s\n", dllname);
       
   716 								aZerothFound = true;
       
   717 							}
       
   718 							break;
       
   719 						}
       
   720 					}
       
   721 				}
       
   722 				if(aZerothFound)
       
   723 					break;
       
   724 
       
   725 				b = b->NextBlock(impfmt);
       
   726 			}
       
   727 			if(!aZerothFound)
       
   728 			{
       
   729 				PrintString("!!Invalid dependency listed at %d\n",aDep );
       
   730 			}
       
   731 
       
   732 			aDepOffset++;
       
   733 		}
       
   734 	}
       
   735 }