bintools/petools/pefile/pe_imp.cpp
author Ross Qin <ross.qin@nokia.com>
Thu, 28 Oct 2010 11:34:42 +0800
changeset 668 fb8810d63524
parent 600 6d08f4a05d93
permissions -rw-r--r--
remove the emulatorlauncher
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 <stdlib.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
#include <string.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
#include <e32std.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
#include <e32std_private.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#include "h_utl.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include "pe_file.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
TInt E32ImageFile_PE::CopyImportAddrTable(char *aPtr, PEFile &aPeFile)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
// Copy the import address table entries
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
	TUint *ptr=(TUint *)aPtr;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
	char *importsection=aPeFile.iSectionData[KImportSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
	TUint *src=(TUint *)importsection;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
	while (*src)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
		TUint vaoffset=src[4];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
		if (!gLittleEndian) ByteSwap(vaoffset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
		TUint offset=vaoffset-aPeFile.iSectionHeader[KImportSection]->VirtualAddress; // find the offset into the section of import addr table
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
		vaoffset=src[3];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
		if (!gLittleEndian) ByteSwap(vaoffset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
		TUint exportername=vaoffset-aPeFile.iSectionHeader[KImportSection]->VirtualAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
		TUint *p=(TUint *)(importsection+offset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
		while (*p)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
			if ((*p&0x80000000)==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
				Print(EError, "%s exporting symbol by name\n", importsection+exportername);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
				return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
			*ptr++=(*p++)&0x7fffffff; // mask out the high bit (- indicates export by ordinal)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
		src+=5;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
	*ptr++=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
	return KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
extern char* gX86imp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
extern int gX86num_imports;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
extern int gX86num_imp_dlls;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
extern int gX86imp_size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
int* gX86imp_relocs=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
TInt CrunchImportSection(TAny* aSection, TInt aNumImpDlls, TInt aNumImports)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
	// Remove lists of ordinals from import section
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
	TInt* d = (TInt*)aSection;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
	TInt orig_size = *d;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
	TInt offset_correction = aNumImports*sizeof(TUint);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
	*d -= offset_correction;	// reduce total section size
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
	TInt *dd = d+1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
	TInt *ss = d+1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
	TInt i;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
	for (i=0; i<aNumImpDlls; ++i)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
		*dd++ = *ss++ - offset_correction;	// copy name offset and reduce it appropriately
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
		TInt nimp = *ss++;					// number of imports from this DLL
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
		*dd++ = nimp;						// copy it
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
		ss += nimp;							// skip the ordinals in the original list
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
	TInt used_size = (ss - d) * sizeof(TInt);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
	memcpy(dd, ss, orig_size - used_size);	// copy name strings
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
	return *d;	// return new total section size
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
char *E32ImageFile_PE::CreateImportSection(const PEFile &aPeFile, TInt &aSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
// Create a new format import section
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
	int total_imports = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
	if (gX86imp)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
		TUint *rdata=(TUint*)aPeFile.iSectionData[KConstSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
		TInt bytecount=gX86imp_size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
		char* section=new char[bytecount];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
		memcpy(section,gX86imp,bytecount);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
		int i;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
		int j=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
		int* s=(int*)section;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
		s++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
		gX86imp_relocs=new int[gX86num_imports+gX86num_imp_dlls];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
		for (i=0; i<gX86num_imp_dlls; ++i)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
			++s;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
			int n=*s++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
			total_imports += n;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
			while (n--)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
				int rdata_int_offset=*s>>2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
				*s=rdata[rdata_int_offset]&0x7fffffffu;	// rdata offset to ordinal
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
				gX86imp_relocs[rdata_int_offset]=j<<2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
				++j;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
				++s;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
		*(TInt*)section = bytecount;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
		aSize = CrunchImportSection(section, gX86num_imp_dlls, total_imports);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
		return section;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
	PIMAGE_SECTION_HEADER aHeader=aPeFile.iSectionHeader[KImportSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
	TUint *aSrc=(TUint *)aPeFile.iSectionData[KImportSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
	TInt nimportdlls=aPeFile.NumberOfImportDlls();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
	if (nimportdlls==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
		aSize=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
	E32ImportBlock *block=new E32ImportBlock [nimportdlls];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
	char **name=new char* [nimportdlls];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
	TUint **import=new TUint* [nimportdlls];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
	TInt bytecount=sizeof(E32ImportSection)+sizeof(E32ImportBlock)*nimportdlls;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
	TUint *src=aSrc;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
	TInt i;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
	for (i=0; i<nimportdlls; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
		TUint vaoffset=src[4];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
		if (!gLittleEndian) ByteSwap(vaoffset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
		TUint offset=vaoffset-aHeader->VirtualAddress; // find the offset into the section of import addr table
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
		TUint *p=aSrc+offset/4;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
		block[i].iNumberOfImports=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
		while (*p++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
			block[i].iNumberOfImports++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
		total_imports += block[i].iNumberOfImports;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
		import[i]=new TUint [block[i].iNumberOfImports];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
		TInt j;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
		p=aSrc+offset/4;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
		for (j=0; j<block[i].iNumberOfImports; j++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
			import[i][j]=(*p++)&0x7fffffffu;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
			bytecount+=4;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
		// name
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
		vaoffset=src[3];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
		if (!gLittleEndian) ByteSwap(vaoffset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
		offset=vaoffset-aHeader->VirtualAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
		name[i]=((char *)aSrc)+offset;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
		bytecount+=strlen(name[i])+1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
		src+=5;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
	bytecount=ALIGN4(bytecount);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
	char *section=new char [bytecount];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
	char *s=section+sizeof(E32ImportSection);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
	for (i=0; i<nimportdlls; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
		memcpy(s, (char *)&block[i], sizeof(E32ImportBlock));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
		s+=sizeof(E32ImportBlock);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
		memcpy(s, (char *)import[i], block[i].iNumberOfImports*4);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
		s+=block[i].iNumberOfImports*4;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
	char *t=section+sizeof(E32ImportSection);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
	for (i=0; i<nimportdlls; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
		((E32ImportBlock *)t)->iOffsetOfDllName=s-section;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
		strcpy(s, name[i]);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
		s+=strlen(name[i])+1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
		t += ((E32ImportBlock *)t)->iNumberOfImports * sizeof(TUint) + sizeof(E32ImportBlock);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
	while ((s-section)<bytecount)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
		*s++=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
	// free mem
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
	for (i=0; i<nimportdlls; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
		delete import[i];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
	delete block;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
	delete import;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
	delete name;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
	*(TInt*)section = bytecount;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
	aSize = CrunchImportSection(section, nimportdlls, total_imports);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
	return section;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
TUint E32ImageFile_PE::FixImportThunk(PEFile &aPeFile, TUint va)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
// Fix an access to the import address table
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
	TUint *imports=(TUint *)aPeFile.iSectionData[KImportSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
	TUint n=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
	TUint importoffset=imports[4];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
	if (!gLittleEndian) ByteSwap(importoffset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
	TUint iat=importoffset-aPeFile.iSectionHeader[KImportSection]->VirtualAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
	while (iat<va)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
		if (*((TUint *)(aPeFile.iSectionData[KImportSection]+iat))==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
			imports+=5;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
			importoffset=imports[4];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
			if (!gLittleEndian) ByteSwap(importoffset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
			iat=importoffset-aPeFile.iSectionHeader[KImportSection]->VirtualAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
		else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
			n++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
			iat+=4;
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
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
	// Flag errors brought about by a corrupt input binary
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
	if (iat>va)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
		Print(EError, "%s is corrupt - problem processing import address table.\n", this->iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
		return (TUint)KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
	return iHdr->iTextSize+n*sizeof(TUint);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235