crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianImageLib/E32Image/Header/SIHeaderE32Image.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 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 "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 *
       
    16 */
       
    17 using System;
       
    18 using System.Collections.Generic;
       
    19 using System.Text;
       
    20 using System.IO;
       
    21 using SymbianUtils.Tracer;
       
    22 using SymbianUtils.Streams;
       
    23 using SymbianUtils.Strings;
       
    24 using SymbianStructuresLib.Version;
       
    25 using SymbianStructuresLib.Uids;
       
    26 using SymbianStructuresLib.Security;
       
    27 using SymbianStructuresLib.Compression.Common;
       
    28 using SymbianImageLib.Common.Header;
       
    29 using SymbianImageLib.Common.Image;
       
    30 using SymbianImageLib.E32Image.Exceptions;
       
    31 
       
    32 namespace SymbianImageLib.E32Image.Header
       
    33 {
       
    34     public class SIHeaderE32Image : SIHeader
       
    35     {
       
    36         #region Constructors
       
    37         internal SIHeaderE32Image( SIImage aImage, SymbianStreamReaderLE aReader )
       
    38             : base( aImage )
       
    39         {
       
    40             long startPos = aReader.Position;
       
    41             //
       
    42             iUids = new TCheckedUid( aReader );
       
    43             iSignature = aReader.ReadUInt32();
       
    44             //
       
    45             if ( iSignature != KExpectedSignatureUInt32 ) // 'EPOC'
       
    46             {
       
    47                 throw new E32ImageNotSupportedException( "Invalid signature" );
       
    48             }
       
    49             //
       
    50             iHeaderCrc = aReader.ReadUInt32();
       
    51             iModuleVersion = aReader.ReadUInt32();
       
    52             iCompressionType = SIHeaderE32Image.ReadCompressionType( aReader );
       
    53             iToolsVersion = new TVersion( aReader );
       
    54             iTimeLo = aReader.ReadUInt32();
       
    55             iTimeHi = aReader.ReadUInt32();
       
    56             iFlags = aReader.ReadUInt32();
       
    57             //
       
    58             iCodeSize = aReader.ReadInt32();
       
    59             iDataSize = aReader.ReadInt32();
       
    60             iHeapSizeMin = aReader.ReadInt32();
       
    61             iHeapSizeMax = aReader.ReadInt32();
       
    62             iStackSize = aReader.ReadInt32();
       
    63             iBssSize = aReader.ReadInt32();
       
    64             //
       
    65             iEntryPoint = aReader.ReadUInt32();
       
    66             iCodeBase = aReader.ReadUInt32();
       
    67             iDataBase = aReader.ReadUInt32();
       
    68             //
       
    69             iDllRefTableCount = aReader.ReadInt32();
       
    70             iExportDirOffset = aReader.ReadUInt32();
       
    71             iExportDirCount = aReader.ReadInt32();
       
    72             //
       
    73             iTextSize = aReader.ReadInt32();
       
    74             iCodeOffset = aReader.ReadUInt32();
       
    75             iDataOffset = aReader.ReadUInt32();
       
    76             iImportOffset = aReader.ReadUInt32();
       
    77             iCodeRelocOffset = aReader.ReadUInt32();
       
    78             iDataRelocOffset = aReader.ReadUInt32();
       
    79             //
       
    80             iProcessPriority = aReader.ReadInt16();
       
    81             //
       
    82             iCpuIdentifier = aReader.ReadUInt16();
       
    83             //
       
    84             iUncompressedSize = aReader.ReadUInt32();
       
    85             //
       
    86             iS = new SSecurityInfo( aReader );
       
    87             iExceptionDescriptor = aReader.ReadUInt32();
       
    88             iSpare2 = aReader.ReadUInt16();
       
    89             iExportDescSize = aReader.ReadUInt16();
       
    90             iExportDescType = aReader.ReadUInt8();
       
    91             //
       
    92             iHeaderSize = (uint) ( aReader.Position - startPos );
       
    93         }
       
    94         #endregion
       
    95 
       
    96         #region Constants
       
    97         public const int KMinimumSize = 16 + 4; // Enough to read UIDs + signature
       
    98         #endregion
       
    99 
       
   100         #region API
       
   101         public static bool IsSymbianImageHeader( byte[] aHeader )
       
   102         {
       
   103             // We expect to see 16 bytes (3 x UID, 1 x UID checksum) and then
       
   104             // the magic word EPOC
       
   105             bool ret = false;
       
   106             //
       
   107             if ( aHeader.Length >= KMinimumSize )
       
   108             {
       
   109                 // We expect 16 bytes are the UID + checksum. Next should be the signature.
       
   110                 string sig = StringParsingUtils.BytesToString( aHeader, 16, 20 );
       
   111                 ret = ( sig == KExpectedSignature );
       
   112             }
       
   113             //
       
   114             return ret;
       
   115         }
       
   116         #endregion
       
   117 
       
   118         #region Constants
       
   119         public const uint KExpectedSignatureUInt32 = 0x434f5045;
       
   120         public const string KExpectedSignature = "EPOC";
       
   121         #endregion
       
   122 
       
   123         #region Properties
       
   124         public TCheckedUid Uid
       
   125         {
       
   126             get
       
   127             {
       
   128                 return iUids;
       
   129             }
       
   130         }
       
   131 
       
   132         public int CodeSize
       
   133         {
       
   134             get { return iCodeSize; }
       
   135         }
       
   136 
       
   137         public int DataSize
       
   138         {
       
   139             get { return iDataSize; }
       
   140         }
       
   141 
       
   142         public uint CodeOffset
       
   143         {
       
   144             get { return iCodeOffset; }
       
   145         }
       
   146 
       
   147         public uint UncompressedSize
       
   148         {
       
   149             get { return iUncompressedSize; }
       
   150         }
       
   151 
       
   152         public uint TotalSize
       
   153         {
       
   154             // Just like in E32ImageHeader
       
   155             get { return CodeOffset; }
       
   156         }
       
   157         #endregion
       
   158 
       
   159         #region From SymbianImageHeader
       
   160         public override uint HeaderSize
       
   161         {
       
   162             get { return iHeaderSize; }
       
   163         }
       
   164 
       
   165         public override TSymbianCompressionType CompressionType
       
   166         {
       
   167             get { return iCompressionType; }
       
   168         }
       
   169         #endregion
       
   170 
       
   171         #region Internal methods
       
   172         private static TSymbianCompressionType ReadCompressionType( SymbianStreamReaderLE aReader )
       
   173         {
       
   174             TSymbianCompressionType ret = TSymbianCompressionType.ENone;
       
   175             //
       
   176             uint type = aReader.ReadUInt32();
       
   177             if ( type == (uint) TSymbianCompressionType.EBytePair )
       
   178             {
       
   179                 ret = TSymbianCompressionType.EBytePair;
       
   180             }
       
   181             else if ( type == (uint) TSymbianCompressionType.EDeflate )
       
   182             {
       
   183                 ret = TSymbianCompressionType.EDeflate;
       
   184             }
       
   185             else
       
   186             {
       
   187                 throw new E32ImageNotSupportedException( "Unsupported compression type" );
       
   188             }
       
   189             //
       
   190             return ret;
       
   191         }
       
   192         #endregion
       
   193 
       
   194         #region Data members
       
   195         private readonly TCheckedUid iUids;
       
   196         //
       
   197         private readonly uint iSignature;			                            // Contains 'EPOC'.
       
   198         private readonly uint iHeaderCrc;			                            // CRC-32 of entire header. @see #KImageCrcInitialiser.
       
   199         private readonly uint iModuleVersion;		                            // Version number for this executable (used in link resolution).
       
   200         private readonly TSymbianCompressionType iCompressionType;	        // Type of compression used for file contents located after the header. (UID or 0 for none).
       
   201         //
       
   202         private readonly TVersion iToolsVersion;		                        // Version number of tools which generated this file.
       
   203         //
       
   204         private readonly uint iTimeLo;			                                // Least significant 32 bits of the time of image creation, in milliseconds since since midnight Jan 1st, 2000.
       
   205         private readonly uint iTimeHi;			                                // Most significant 32 bits of the time of image creation, in milliseconds since since midnight Jan 1st, 2000.
       
   206         private readonly uint iFlags;				                            // Contains various bit-fields of attributes for the image.
       
   207         //
       
   208         private readonly int iCodeSize;				                            // Size of executables code. Includes import address table, constant data and export directory.
       
   209         private readonly int iDataSize;				                            // Size of executables initialised data.
       
   210         private readonly int iHeapSizeMin;			                            // Minimum size for an EXEs runtime heap memory.
       
   211         private readonly int iHeapSizeMax;			                            // Maximum size for an EXEs runtime heap memory.
       
   212         private readonly int iStackSize;			                            // Size for stack required by an EXEs initial thread.
       
   213         private readonly int iBssSize;				                            // Size of executables uninitialised data.
       
   214         //
       
   215         private readonly uint iEntryPoint;			                            // Offset into code of the entry point.
       
   216         private readonly uint iCodeBase;			                            // Virtual address that the executables code is linked for.
       
   217         private readonly uint iDataBase;			                            // Virtual address that the executables data is linked for.
       
   218         //
       
   219         private readonly int iDllRefTableCount;		                            // Number of executable against which this executable is linked. The number of files mention in the import section at iImportOffset.
       
   220         private readonly uint iExportDirOffset;		                            // Byte offset into file of the export directory.
       
   221         private readonly int iExportDirCount;		                            // Number of entries in the export directory.
       
   222         //
       
   223         private readonly int iTextSize;				                            // Size of just the text section, also doubles as the offset for the Import Address Table w.r.t. the code section.
       
   224         private readonly uint iCodeOffset;			                            // Offset into file of the code section. Also doubles the as header size.
       
   225         private readonly uint iDataOffset;			                            // Offset into file of the data section.
       
   226         private readonly uint iImportOffset;		                            // Offset into file of the import section (E32ImportSection).
       
   227         private readonly uint iCodeRelocOffset;		                            // Offset into file of the code relocation section (E32RelocSection).
       
   228         private readonly uint iDataRelocOffset;		                            // Offset into file of the data relocation section (E32RelocSection).
       
   229         private readonly short iProcessPriority; 	                            // Initial runtime process priorty for an EXE. (Value from enum TProcessPriority.)
       
   230         private readonly ushort iCpuIdentifier;		                            // Value from enum TCpu which indicates the CPU architecture for which the image was created
       
   231         //
       
   232         private readonly uint iUncompressedSize;	                            // Uncompressed size of file data after the header, or zero if file not compressed.
       
   233         //
       
   234 	    private readonly SSecurityInfo iS;				                        // Platform Security information of executable.
       
   235 	    private readonly uint iExceptionDescriptor;                             // Offset in bytes from start of code section to Exception Descriptor, bit 0 set if valid.
       
   236 	    private readonly ushort iSpare2;				                        // Reserved for future use. Set to zero.
       
   237 	    private readonly ushort iExportDescSize;		                        // Size of export description stored in iExportDesc.
       
   238 	    private readonly byte iExportDescType;		                            // Type of description of holes in export table
       
   239 
       
   240         // Not part of header
       
   241         private readonly uint iHeaderSize;
       
   242         #endregion
       
   243     }
       
   244 }