bintools/petools/pefile/pe_tran.cpp
author lorewang
Thu, 11 Nov 2010 12:38:08 +0800
changeset 678 f0d451bf8bcb
parent 600 6d08f4a05d93
permissions -rw-r--r--
update version info
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
// All rights reserved.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
// This component and the accompanying materials are made available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
// which accompanies this distribution, and is available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
// Initial Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
// Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
// Description:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
#include <time.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
#include <malloc.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
#include <string.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
#include "e32image.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#include <e32std.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include <e32std_private.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
#include "pe_defs.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
#include "pe_file.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
#include "h_ver.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
#include "h_utl.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
int gAlignConstSection=FALSE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
TUint gConstSectionAddressMask=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
static TUint gRequiredConstPadding;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
extern char* gX86imp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
extern int gX86num_imp_dlls;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
extern int gX86imp_size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
extern int gX86num_imports;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
E32ImageFile* E32ImageFile::New()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
	return new E32ImageFile_PE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
E32ImageFile_PE::E32ImageFile_PE()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
E32ImageFile_PE::~E32ImageFile_PE()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
TUint E32ImageFile_PE::ImportAddressTableOffset()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
// Return the offset of the iat
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
	return iHdr->iTextSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
TUint E32ImageFile_PE::ConstOffset()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
// return the offset of the const data
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
	return iConstOffset;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
void E32ImageFile_PE::CreateExportDirectory(char *aPtr, PEFile &aPeFile)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
// create a new format export directory
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
	if (iHdr->iExportDirCount==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
		return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
	TUint *src=(TUint *)aPeFile.iSectionData[KExportSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
	TUint *dst=(TUint *)aPtr;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
	PIMAGE_EXPORT_DIRECTORY dir=(PIMAGE_EXPORT_DIRECTORY)src;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
	src+=(((TInt)dir->AddressOfFunctions)-((TInt)aPeFile.iSectionHeader[KExportSection]->VirtualAddress))/4;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
	TUint i;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
	for (i=0; i<dir->NumberOfFunctions; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
		TUint va=*src++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
		dst[i]=va;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
	FixExportDirectory(dst, aPeFile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
void E32ImageFile_PE::FixExportDirectory(TUint *aExportDir, PEFile &aPeFile)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
// Fix the export directory
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
	TUint lb = aPeFile.iLinkedBase;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
	TUint *exportdir=aExportDir;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
	TInt n;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
	for (n=0; n<(TInt)iHdr->iExportDirCount; n++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
		TUint va=*exportdir;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
		if (!gLittleEndian) ByteSwap(va);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
		// va is the address of an exported item, so assume it can't have been offset
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
		TInt i=aPeFile.FindSectionByVa(va+lb);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
		if (i==KTextSection)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
			va=va-aPeFile.iSectionHeader[i]->VirtualAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
		else if (i==KConstSection)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
			va=va-aPeFile.iSectionHeader[i]->VirtualAddress+ConstOffset();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
		else if (i==KDataSection)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
			va=va-aPeFile.iSectionHeader[i]->VirtualAddress+DataOffset();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
		else if (i==KBssSection)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
			va=va-aPeFile.iSectionHeader[i]->VirtualAddress+BssOffset();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
		else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
			if (va == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
				Print(EWarning, "No export specified for ordinal %d\n", n+1, va);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
			else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
				Print(EError, "Export %d (address %08x) is not from .text, .rdata, or data sections\n", n+1, va);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
		if (!gLittleEndian) ByteSwap(va);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
		*exportdir++=va;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
TInt E32ImageFile_PE::DoCodeHeader(PEFile &aPeFile)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
// Calculate the code parts of the pefile
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
	// .text
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
	TInt size=ALIGN4(aPeFile.iSectionHeader[KTextSection]->Misc.VirtualSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
	// .rdata
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
	iConstOffset=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
	if (gAlignConstSection)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
	    // Compute the amount of padding to put before the
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
	    // const section to align it correctly
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
	    TUint   oldAddressBits = aPeFile.iSectionHeader[KConstSection]->VirtualAddress & gConstSectionAddressMask;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
	    TUint   oldConstAddress = size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
	    TUint   newConstAddress = oldConstAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
	    // slow but sure
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
	    while ((newConstAddress & gConstSectionAddressMask) != oldAddressBits)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
	    	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
			newConstAddress++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
	    gRequiredConstPadding = newConstAddress - oldConstAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
	    size += gRequiredConstPadding;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
	if (aPeFile.iSectionHeader[KConstSection])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
		iConstOffset = size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
		size += ALIGN4(aPeFile.iSectionHeader[KConstSection]->Misc.VirtualSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
	// .crt
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
	iCrtOffset=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
	if (aPeFile.iSectionHeader[KCrtSection])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
		iCrtOffset = size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
		size += ALIGN4(aPeFile.iSectionHeader[KCrtSection]->Misc.VirtualSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
	iHdr->iTextSize=size; // The "text" part of the E32 code section combines PE's .text + .rdata + .crt.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
						  // The remainder of the E32 code section is the IAT + export directory.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
	// Import Address Table (IAT)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
	TInt nimports=gX86imp?gX86num_imports:aPeFile.NumberOfImports();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
	if (nimports!=0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
		size+=nimports*4+4; // null terminated
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
	// Export Dir
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
	if (iHdr->iExportDirCount)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
		iHdr->iExportDirOffset = iHdr->iCodeOffset + size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
		size += ALIGN4(iHdr->iExportDirCount*4);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
	iHdr->iCodeSize=size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
	return size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
TInt E32ImageFile_PE::DoDataHeader(PEFile &aPeFile, TUint aDataBase)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
	if (aDataBase == (TUint)0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
		aDataBase=iHdr->iCodeBase+iHdr->iCodeSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
	TInt size=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
	if (PEFile::HasInitialisedData(aPeFile.iSectionHeader[KDataSection]))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
		size=ALIGN4(aPeFile.iSectionHeader[KDataSection]->Misc.VirtualSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
		iHdr->iDataBase=aDataBase;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
		iHdr->iDataOffset = iHdr->iCodeOffset + iHdr->iCodeSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
		TInt bsssize=aPeFile.iSectionHeader[KDataSection]->Misc.VirtualSize-aPeFile.iSectionHeader[KDataSection]->SizeOfRawData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
		// drop any uninitialised data
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
		if (bsssize>0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
			iHdr->iBssSize+=bsssize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
			size=ALIGN4(aPeFile.iSectionHeader[KDataSection]->SizeOfRawData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
		iHdr->iDataSize=size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
	else if (aPeFile.iSectionHeader[KDataSection])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
		{ // just .bss
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
		iHdr->iDataBase=aDataBase;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
		TInt bsssize=aPeFile.iSectionHeader[KDataSection]->Misc.VirtualSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
		iHdr->iBssSize+=bsssize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
	if (aPeFile.iSectionHeader[KBssSection])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
		iHdr->iBssSize+=ALIGN4(aPeFile.iSectionHeader[KBssSection]->Misc.VirtualSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
		if (iHdr->iDataBase==0) // .bss but no .data
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
			iHdr->iDataBase=aDataBase;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
	return size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
TInt E32ImageFile_PE::CopyCode(char *p, PEFile &aPeFile)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
// Copies the files code sections to p
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
// returns the number of bytes copied or KErrGeneral
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
	// text
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
	TInt size=aPeFile.iSectionHeader[KTextSection]->Misc.VirtualSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
	memcpy(p, aPeFile.iSectionData[KTextSection], size);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
	TInt text_offset=ALIGN4(size);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
	p+=text_offset;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
	// rdata
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
	if (aPeFile.iSectionData[KConstSection])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
		if (gAlignConstSection)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   236
			// add padding ahead of const section
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   237
			p += gRequiredConstPadding;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   238
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   239
		TInt size=ALIGN4(aPeFile.iSectionHeader[KConstSection]->Misc.VirtualSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   240
		memcpy(p, aPeFile.iSectionData[KConstSection], size);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   241
		p+=size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   242
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   243
	if (aPeFile.iSectionData[KCrtSection])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   244
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   245
		TInt size=ALIGN4(aPeFile.iSectionHeader[KCrtSection]->Misc.VirtualSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   246
		memcpy(p, aPeFile.iSectionData[KCrtSection], size);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   247
		p+=size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   248
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   249
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   250
	// iat
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   251
	TInt nimports=gX86imp?gX86num_imports:aPeFile.NumberOfImports();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   252
//	TInt nimports=aPeFile.NumberOfImports();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   253
	if (nimports)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   254
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   255
		if (gX86imp)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   256
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   257
			TUint *rdata=(TUint*)aPeFile.iSectionData[KConstSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   258
			int i;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   259
			int* s=(int*)gX86imp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   260
			s++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   261
			for (i=0; i<gX86num_imp_dlls; ++i)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   262
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   263
				++s;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   264
				int n=*s++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   265
				while (n--)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   266
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   267
					*(int*)p=rdata[(*s)>>2]&0x7fffffffu;	// rdata offset to ordinal
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   268
					++s;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   269
					p+=4;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   270
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   271
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   272
			*(int*)p=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   273
			p+=4;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   274
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   275
		else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   276
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   277
			TInt r=CopyImportAddrTable(p, aPeFile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   278
			p+=ALIGN4(nimports*4+4);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   279
			if (r!=KErrNone)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   280
				return Print(EError, "%s is importing symbols by name.\n", iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   281
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   282
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   283
	// export dir
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   284
	CreateExportDirectory(p, aPeFile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   285
	p+=iHdr->iExportDirCount*4;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   286
	return iHdr->iCodeSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   287
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   288
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   289
TInt E32ImageFile_PE::CopyData(char *p, PEFile &aPeFile)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   290
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   291
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   292
	if (iHdr->iDataSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   293
		memcpy(p, aPeFile.iSectionData[KDataSection], iHdr->iDataSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   294
	return iHdr->iDataSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   295
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   296
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   297
TInt E32ImageFile_PE::Translate(const char* aFileName, TUint aDataBase, TBool aAllowDllData, TBool /*aSymLkupEnabled*/)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   298
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   299
// Translate a PE format file to a E32Image file
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   300
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   301
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   302
	iSource = EPeFile;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   303
	PEFile pefile;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   304
	if (!pefile.Init((const char * const)aFileName))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   305
		return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   306
	TInt r=pefile.ReadSectionHeaders();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   307
	if (r!=KErrNone) return r;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   308
	r=pefile.ReadData();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   309
	if (r!=KErrNone) return r;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   310
	pefile.Close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   311
	r=pefile.Normalise();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   312
	if (r!=KErrNone) return r;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   313
	iFileName = strdup(aFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   314
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   315
	Adjust(ALIGN4(sizeof(E32ImageHeaderV)));	// fixed for now because holes not supported
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   316
	SetDefaultHeader();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   317
	if (gX86imp)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   318
		iHdr->iDllRefTableCount=gX86num_imp_dlls;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   319
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   320
		iHdr->iDllRefTableCount=pefile.NumberOfImportDlls();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   321
	iHdr->iExportDirCount=pefile.NumberOfExports();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   322
	iHdr->iCodeBase=pefile.iLinkedBase;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   323
	TInt nimports=gX86imp?gX86num_imports:pefile.NumberOfImports();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   324
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   325
	TInt importSectionSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   326
	char *newImportSection=CreateImportSection(pefile, importSectionSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   327
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   328
	TInt size = ALIGN4(sizeof(E32ImageHeaderV));	// fixed for now because holes not supported
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   329
	iHdr->iCodeOffset = size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   330
	TInt pos = size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   331
	size+=DoCodeHeader(pefile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   332
	TInt t=DoDataHeader(pefile, aDataBase);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   333
	if (t>0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   334
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   335
		iHdr->iDataOffset = size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   336
		size += t;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   337
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   338
	if (importSectionSize!=0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   339
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   340
		iHdr->iImportOffset = size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   341
		size += importSectionSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   342
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   343
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   344
	char *newCodeRelocs=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   345
	char *newDataRelocs=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   346
	TInt codeRelocSize=0, dataRelocSize=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   347
	TInt nrelocs=pefile.NumberOfRelocs();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   348
	if (nrelocs)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   349
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   350
		TUint *relocs=new TUint [nrelocs];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   351
		TUint *relocsection=new TUint [nrelocs];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   352
		pefile.GetRelocs(relocs, relocsection, nrelocs);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   353
		FixRelocs(pefile, relocs, relocsection, nrelocs);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   354
		newCodeRelocs=CreateCodeRelocs(relocs, relocsection, nrelocs, codeRelocSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   355
		newDataRelocs=CreateDataRelocs(relocs, relocsection, nrelocs, dataRelocSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   356
		if (codeRelocSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   357
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   358
			iHdr->iCodeRelocOffset = size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   359
			size += codeRelocSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   360
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   361
		if (dataRelocSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   362
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   363
			iHdr->iDataRelocOffset = size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   364
			size += dataRelocSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   365
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   366
		delete [] relocs;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   367
		delete [] relocsection;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   368
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   369
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   370
	Adjust(size);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   371
	t=CopyCode(iData + pos, pefile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   372
	if (t<0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   373
		return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   374
	pos += t;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   375
	pos += CopyData(iData + pos, pefile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   376
	if (nimports)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   377
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   378
		memcpy(iData + pos, newImportSection, importSectionSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   379
		pos += importSectionSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   380
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   381
	if (codeRelocSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   382
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   383
		memcpy(iData + pos, newCodeRelocs, codeRelocSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   384
		pos += codeRelocSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   385
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   386
	if (dataRelocSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   387
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   388
		memcpy(iData + pos, newDataRelocs, dataRelocSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   389
		pos += dataRelocSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   390
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   391
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   392
	// locate the entry point
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   393
	// entry point must be in the text section
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   394
	TInt entryPointSectionIndex=pefile.FindSectionByVa(pefile.iEntryPoint+pefile.iLinkedBase);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   395
	TUint entryPointOffset=pefile.iEntryPoint-pefile.iSectionHeader[entryPointSectionIndex]->VirtualAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   396
	if (entryPointSectionIndex!=KTextSection)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   397
		return Print(EError, "Entry Point not in code section\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   398
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   399
	// Arrange a header for this E32 Image
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   400
	switch (pefile.iCpu)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   401
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   402
	case IMAGE_FILE_MACHINE_I386:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   403
		iHdr->iCpuIdentifier = (TUint16)ECpuX86;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   404
		break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   405
	case 0x0a00:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   406
		iHdr->iCpuIdentifier = (TUint16)ECpuArmV4;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   407
		break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   408
	case 0x0b00:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   409
		iHdr->iCpuIdentifier = (TUint16)ECpuMCore;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   410
		break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   411
	default:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   412
		iHdr->iCpuIdentifier = (TUint16)ECpuUnknown;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   413
		break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   414
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   415
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   416
	// Import format is PE-derived without redundant ordinal lists
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   417
	// ABI is GCC98r2 ABI (on ARM)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   418
	iHdr->iFlags |= KImageImpFmt_PE2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   419
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   420
	if (pefile.iImageIsDll)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   421
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   422
		iHdr->iFlags|=KImageDll;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   423
		if (iHdr->iDataSize && !aAllowDllData)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   424
			return Print(EError, "Dll '%s' has initialised data.\n", iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   425
		if (iHdr->iBssSize  && !aAllowDllData)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   426
			return Print(EError, "Dll '%s' has uninitialised data.\n", iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   427
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   428
	iHdr->iHeapSizeMin=pefile.iHeapCommittedSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   429
	iHdr->iHeapSizeMax=pefile.iHeapReservedSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   430
	iHdr->iStackSize=pefile.iStackCommittedSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   431
	iHdr->iEntryPoint=entryPointOffset;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   432
	r = DetermineEntryPointType();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   433
	if (r == KErrCorrupt)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   434
		return Print(EError, "File '%s': Bad Entry Point.\n", iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   435
	else if (r == KErrNotSupported)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   436
		return Print(EError, "File '%s': Bad Entry Point Type.\n", iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   437
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   438
	delete [] newImportSection;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   439
	delete [] newCodeRelocs;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   440
	delete [] newDataRelocs;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   441
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   442
	return KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   443
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   444
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   445
TBool E32ImageFile_PE::Translate(PEFile &aPeFile)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   446
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   447
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   448
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   449
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   450
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   451
	return Translate((const char*)aPeFile.iFileName, (TUint)0, EFalse, EFalse);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   452
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   453