bintools/petools/pefile/pe_file.cpp
author marvin shi <marvin.shi@nokia.com>
Fri, 19 Nov 2010 13:37:08 +0800
changeset 698 e3ee96a3961c
parent 600 6d08f4a05d93
permissions -rw-r--r--
fix ou1cimx1#651819 rofsbiuld fails to generate correct log info when using multi-thread
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
// Copyright (c) 1995-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
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 <e32rom.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include "e32image.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_utl.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
TBool hadText, hadReloc = EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
TUint32 PEFile::iRomMemBase=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
TUint32 PEFile::iRomLinearBase=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
extern char* gX86imp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
extern int gX86num_imp_dlls;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
PEFile::PEFile()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
	:iMemBase(0),iEntryPoint(0),iImageSize(0),iCodeSize(0),iDataSize(0),
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
	iHeapReservedSize(0),iHeapCommittedSize(0),iStackReservedSize(0),iStackCommittedSize(0),
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
	iBssSize(0),iBssOffset(0),iSectionAlign(0),iExpDirectoryOffset(0),iDataOffset(0),
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
	iImageIsDll(EFalse),
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
	iHeader(0),iExpDirectory(0),iImpDescriptor(0),iFileName(0),iFileHandle(0),
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
	iLinkedBase(0),iStartOfHeaders(0),iSizeOfHeaders(0),iNumSections(0),
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
	iRomRunAddr(0),iRamRunAddr(0),iRomDelta(0),iRamDelta(0),iHadDataSection(EFalse),
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
	iBssSectionLinkedAddr(0),iBssSectionAddr(0),iBssSectionSize(0),
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
	iDataSectionLinkedAddr(0),iDataSectionAddr(0),iDataSectionSize(0),
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
	iCodeSectionAddr(0),iCodeSectionSize(0),
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
	iRDataSectionAddr(0),iRDataSectionSize(0),
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
	iCRTSectionAddr(0),iCRTSectionSize(0),
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
	iExportDataDir(0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
// Constructor
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
	for (TInt i=0; i<KNumberOfSections; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
		iSectionHeader[i]=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
		iSectionData[i]=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
PEFile::~PEFile()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
// Destructor
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
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
	delete [] iFileName;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
	for (TInt i=0; i<KNumberOfSections; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
		delete iSectionHeader[i];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
		delete iSectionData[i];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
TBool PEFile::Init(const char * const aFileName)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
// Reads the PE headers to fill in lots of nice instance variables with info about the file
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
 	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
 	delete [] iFileName;	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
	iFileName = new char[strlen((const char *)aFileName)+1];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
	strcpy ((char *)iFileName, (const char *)aFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
	iHeader = (PIMAGE_NT_HEADERS)(HMem::Alloc(0,sizeof(IMAGE_DOS_HEADER)+sizeof(IMAGE_NT_HEADERS)));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
	if (!iHeader)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
		Print(EPeError,"Failed to allocate memory for headers.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
		return EFalse;
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
	TInt error = HFile::Open(iFileName, &iFileHandle);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
	if (error!=0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
		return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
	if (!HFile::Read(iFileHandle,iHeader,sizeof(IMAGE_DOS_HEADER)))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
		Print(EPeError,"Unable to read file %s.\n",iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
		HFile::Close(iFileHandle);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
		return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
	if (IsValidDOSHeader((PIMAGE_DOS_HEADER)iHeader)) // read in the rest, overwriting the DOS header
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
		iStartOfHeaders = ((PIMAGE_DOS_HEADER)iHeader)->e_lfanew;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
		iStartOfHeaders = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
	if (!HFile::Seek(iFileHandle, iStartOfHeaders))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
		Print(EPeError,"File %s is not large enough to contain valid headers.\n",iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
		HFile::Close(iFileHandle);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
		return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
 	if (!HFile::Read(iFileHandle,iHeader,sizeof(IMAGE_NT_HEADERS)))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
		Print(EPeError,"Unable to read NT headers.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
		HFile::Close(iFileHandle);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
		return EFalse;
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
	if (!IsValidNTHeader(iHeader))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
		Print(EPeError,"Invalid NT header.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
		HFile::Close(iFileHandle);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
		return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
	if (!(IsValidFileHeader((PIMAGE_FILE_HEADER)&iHeader->FileHeader)))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
		Print(EPeError,"Invalid file header.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
		HFile::Close(iFileHandle);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
		return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
//	PIMAGE_NT_HEADERS pNTHeader = iHeader;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
	PIMAGE_FILE_HEADER pFileHeader = (PIMAGE_FILE_HEADER)&iHeader->FileHeader;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
	PIMAGE_OPTIONAL_HEADER pOptionalHeader = (PIMAGE_OPTIONAL_HEADER)&iHeader->OptionalHeader;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
//	PIMAGE_SECTION_HEADER pSectionHeader = (PIMAGE_SECTION_HEADER)(iHeader+1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
	iImageSize = pOptionalHeader->SizeOfImage;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
	iCodeSize = pOptionalHeader->SizeOfCode;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
	iDataSize = pOptionalHeader->SizeOfInitializedData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
	iEntryPoint = pOptionalHeader->AddressOfEntryPoint;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
	iHeapReservedSize = pOptionalHeader->SizeOfHeapReserve;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
	iHeapCommittedSize = pOptionalHeader->SizeOfHeapCommit;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
	iStackReservedSize = 0x2000;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
	iStackCommittedSize = 0x2000;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
	iBssSize = pOptionalHeader->SizeOfUninitializedData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
    iSectionAlign =	pOptionalHeader->SectionAlignment;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
 	if (pFileHeader->Characteristics & IMAGE_FILE_DLL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
		iImageIsDll = ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
		iImageIsDll = EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
 	iLinkedBase=pOptionalHeader->ImageBase;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
	iNumSections = pFileHeader->NumberOfSections;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
	iSizeOfHeaders = pOptionalHeader->SizeOfHeaders;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
	iExportDataDir=pOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
	iExportDirSize=pOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
	iCpu=pFileHeader->Machine;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
	HMem::Free(iHeader);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
	iHeader=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
	return ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
void PEFile::Close()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
// close the pe file
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
	HFile::Close(iFileHandle);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
TInt PEFile::ReadExportDirectory()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
// Read in just the export directory
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
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
	if (iExportDataDir==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
		return KErrNotFound;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
	TInt r=ReadSectionHeaders();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
	if (r!=KErrNone)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
		return r;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
	iSectionData[KConstSection]=ReadSectionData(iSectionHeader[KConstSection]);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
	iExpDirectoryOffset=iSectionHeader[KConstSection]->VirtualAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
	iExpDirectory=(PIMAGE_EXPORT_DIRECTORY)(iSectionData[KConstSection]+iExportDataDir-iExpDirectoryOffset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
	return KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
TInt PEFile::ReadSectionHeaders()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
// Read in the section headers
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
//
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
	TInt i;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
	for (i=0; i<KNumberOfSections; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
		iSectionHeader[i]=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
	HFile::Seek(iFileHandle, iStartOfHeaders+sizeof(IMAGE_NT_HEADERS));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
	for (i=0; i<(TInt)iNumSections; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
		PIMAGE_SECTION_HEADER header = new IMAGE_SECTION_HEADER;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
		if (!HFile::Read(iFileHandle, header, sizeof(IMAGE_SECTION_HEADER)))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
			return Print(EError, "Cannot read section header.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
		if (CmpSectionName(header, ".text"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
			iSectionHeader[KTextSection]=header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
		else if (CmpSectionName(header, ".rdata"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
			iSectionHeader[KConstSection]=header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
		else if (CmpSectionName(header, ".edata"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
			iSectionHeader[KExportSection]=header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
		else if (CmpSectionName(header, ".data"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
			iSectionHeader[KDataSection]=header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
		else if (CmpSectionName(header, ".bss"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
			iSectionHeader[KBssSection]=header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
		else if (CmpSectionName(header, ".idata"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
			iSectionHeader[KImportSection]=header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
		else if (CmpSectionName(header, ".reloc"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
			iSectionHeader[KRelocSection]=header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
		else if (CmpSectionName(header, ".CRT"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
			iSectionHeader[KCrtSection]=header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
		else if (CmpSectionName(header, ".stab"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
			delete header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
		else if (CmpSectionName(header, ".stabstr"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
			delete header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
		else if (CmpSectionName(header,".E32_UID"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
			delete header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
		else if (CmpSectionName(header,".rsrc"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
			delete header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
		else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
			Print(EWarning, "Section '%.8s' removed.\n", header->Name);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235
			delete header;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   236
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   237
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   238
	return KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   239
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   240
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   241
char *PEFile::ReadSectionData(PIMAGE_SECTION_HEADER aPeHeader)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   242
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   243
// Read in the data for this section
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   244
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   245
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   246
	char *section=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   247
	if (aPeHeader)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   248
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   249
		section=(char *)HMem::Alloc(NULL, aPeHeader->SizeOfRawData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   250
		if (section==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   251
			return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   252
		HFile::Seek(iFileHandle, aPeHeader->PointerToRawData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   253
		HFile::Read(iFileHandle, section, aPeHeader->SizeOfRawData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   254
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   255
	return section;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   256
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   257
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   258
TInt PEFile::ReadData()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   259
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   260
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   261
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   262
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   263
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   264
	TInt i;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   265
	for (i=0; i<KNumberOfSections; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   266
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   267
		if (iSectionHeader[i])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   268
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   269
			iSectionData[i]=ReadSectionData(iSectionHeader[i]);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   270
			if (iSectionData[i]==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   271
				return Print(EError, "Cannot read %s section data.\n", iSectionHeader[i]->Name);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   272
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   273
		else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   274
			iSectionData[i]=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   275
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   276
	return KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   277
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   278
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   279
TInt PEFile::NumberOfImports() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   280
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   281
// Count the total number of imports for this image
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   282
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   283
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   284
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   285
//	if (gX86imp)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   286
//		return gX86num_imp_dlls;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   287
	char *importData=iSectionData[KImportSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   288
	PIMAGE_SECTION_HEADER importHeader=iSectionHeader[KImportSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   289
	if (importData==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   290
		return 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   291
	TInt n=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   292
	TUint *src=(TUint *)importData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   293
	while (*src)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   294
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   295
		TUint vaoffset=src[4];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   296
		if (!gLittleEndian) ByteSwap(vaoffset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   297
		TUint offset=vaoffset-importHeader->VirtualAddress; // find the offset into the section of import addr table
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   298
		TUint *p=(TUint *)(importData+offset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   299
		while (*p++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   300
			n++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   301
		src+=5; // sizeof pe import block/4
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   302
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   303
	return n;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   304
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   305
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   306
TInt PEFile::NumberOfImportDlls() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   307
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   308
// Count the number of referenced Dlls
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   309
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   310
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   311
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   312
	char *importData=iSectionData[KImportSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   313
//	PIMAGE_SECTION_HEADER importHeader=iSectionHeader[KImportSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   314
	if (importData==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   315
		return 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   316
	TInt n=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   317
	while (*(TUint *)importData)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   318
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   319
		n++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   320
		importData+=5*4; // size of pe import block
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   321
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   322
	return n;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   323
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   324
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   325
TInt PEFile::NumberOfExports() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   326
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   327
// Count the number of exported symbols
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   328
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   329
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   330
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   331
	if (iExportDataDir==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   332
		return 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   333
	return ((PIMAGE_EXPORT_DIRECTORY)iSectionData[KExportSection])->NumberOfFunctions;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   334
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   335
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   336
TInt PEFile::NumberOfRelocs()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   337
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   338
// Count the number of reloctions
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   339
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   340
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   341
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   342
	if (iSectionData[KRelocSection]==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   343
		return 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   344
	char *relocs=iSectionData[KRelocSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   345
	TInt n=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   346
	TInt dudrelocs=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   347
	TInt blocksize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   348
	TUint page;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   349
	TInt size=iSectionHeader[KRelocSection]->Misc.VirtualSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   350
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   351
	TUint *rrelocs=(TUint *)relocs;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   352
	TUint ssize=size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   353
	if (!gLittleEndian) ByteSwap(rrelocs, ssize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   354
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   355
	while (size>0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   356
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   357
		page=*(TUint *)relocs;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   358
		blocksize=*(TInt *)(relocs+4);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   359
		if (blocksize==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   360
			break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   361
		size-=blocksize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   362
		TUint16 *p=(TUint16 *)(relocs+8);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   363
		relocs+=blocksize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   364
		blocksize-=8;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   365
		while (blocksize>0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   366
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   367
			TInt rtype=(*p&0xf000)>>12;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   368
			if (rtype==IMAGE_REL_BASED_HIGHLOW)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   369
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   370
				TUint va=page+(*p&0xfff);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   371
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   372
				// va is the address requiring relocation, so it must be in a section and can't have been offset
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   373
				TInt section=FindSectionByVa(va+iLinkedBase);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   374
				if (section==KTextSection || section==KConstSection || section==KDataSection || section==KCrtSection)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   375
					n++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   376
				else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   377
					dudrelocs++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   378
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   379
			else if (rtype!=IMAGE_REL_BASED_ABSOLUTE)	// used for padding
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   380
				Print(EWarning, "Relocation type other than IMAGE_REL_BASED_HIGHLOW has been ignored.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   381
			*p++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   382
			blocksize-=2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   383
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   384
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   385
#if defined(_DEBUG)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   386
	if (dudrelocs>0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   387
		Print(EWarning, "Image '%s' has %d relocations pointing at uninitialised data.\n", iFileName, dudrelocs);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   388
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   389
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   390
	if (!gLittleEndian) ByteSwap(rrelocs, ssize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   391
	return n;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   392
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   393
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   394
void PEFile::GetRelocs(TUint *aReloc, TUint *aRelocSection, TInt /*aNumberOfRelocs*/)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   395
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   396
// load the relocs from the reloc section into relocation and relocsection arrays
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   397
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   398
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   399
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   400
	TUint *relocation=aReloc;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   401
	TUint *relocsection=aRelocSection;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   402
	char *aRelocData=iSectionData[KRelocSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   403
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   404
	TUint16 *relocs=(TUint16 *)aRelocData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   405
	TInt relocsize=iSectionHeader[KRelocSection]->Misc.VirtualSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   406
	TUint offset;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   407
	TUint page;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   408
	TInt i=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   409
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   410
	TUint *rrelocs=(TUint *)aRelocData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   411
	TUint ssize=relocsize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   412
	if (!gLittleEndian) ByteSwap(rrelocs, ssize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   413
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   414
	while (relocsize>0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   415
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   416
		page=*(TUint *)relocs;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   417
		relocs+=2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   418
		TInt size=*(TUint *)relocs;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   419
		if (size==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   420
			break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   421
		relocsize-=size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   422
		relocs+=2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   423
		size-=8;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   424
		while (size>0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   425
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   426
			offset=*relocs++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   427
			TInt type=offset&0xf000;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   428
			if (type==0x3000)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   429
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   430
				TUint va=page+(offset&0xfff);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   431
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   432
				// va is the address requiring relocation, so it must be in a section and can't have been offset
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   433
				TInt section=FindSectionByVa(va+iLinkedBase);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   434
				if (section==KTextSection || section==KConstSection || section==KDataSection || section==KCrtSection)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   435
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   436
					relocsection[i]=section;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   437
					relocation[i++]=va;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   438
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   439
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   440
			size-=2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   441
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   442
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   443
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   444
	if (!gLittleEndian) ByteSwap(rrelocs, ssize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   445
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   446
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   447
TInt PEFile::Normalise()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   448
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   449
// Remove the MSVC anomalies
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   450
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   451
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   452
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   453
	// MSVC puts export data in with .rdata
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   454
	if (iExportDataDir && iSectionHeader[KExportSection]==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   455
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   456
		if (!PEFile::VirtualAddressInSection(iExportDataDir+iLinkedBase, iSectionHeader[KConstSection]))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   457
			return Print(EError, "Can't find exports in this PE file.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   458
		else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   459
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   460
			iSectionHeader[KExportSection]=new IMAGE_SECTION_HEADER;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   461
			iSectionHeader[KExportSection]->VirtualAddress=iExportDataDir;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   462
			iSectionHeader[KExportSection]->Misc.VirtualSize=iExportDirSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   463
			iSectionHeader[KExportSection]->SizeOfRawData=iExportDirSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   464
			iSectionData[KExportSection]=new char [iExportDirSize];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   465
			if (iSectionData[KExportSection]==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   466
				return Print(EError, "Out of memory.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   467
			memcpy(iSectionData[KExportSection], iSectionData[KConstSection]+iExportDataDir-iSectionHeader[KConstSection]->VirtualAddress, iExportDirSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   468
			// adjust .rdata so it does not include .edata
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   469
			iSectionHeader[KConstSection]->Misc.VirtualSize-=iExportDirSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   470
			iSectionHeader[KConstSection]->SizeOfRawData-=iExportDirSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   471
			char *c=new char [iSectionHeader[KConstSection]->SizeOfRawData];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   472
			if (c==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   473
				return Print(EError, "Out of memory.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   474
			memcpy(c, iSectionData[KConstSection], iSectionHeader[KConstSection]->SizeOfRawData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   475
			delete iSectionData[KConstSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   476
			iSectionData[KConstSection]=c;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   477
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   478
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   479
	// Stupid compilers generate .idata sections even when there are no imports
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   480
	if (iSectionHeader[KImportSection])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   481
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   482
		if (NumberOfImports()==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   483
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   484
			delete iSectionHeader[KImportSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   485
			delete iSectionData[KImportSection];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   486
			iSectionHeader[KImportSection]=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   487
			iSectionData[KImportSection]=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   488
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   489
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   490
	return KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   491
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   492
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   493
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   494
TInt PEFile::HasInitialisedData(PIMAGE_SECTION_HEADER aHeader)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   495
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   496
// Returns true if the pe file section contains any initialised data
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   497
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   498
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   499
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   500
	if (aHeader==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   501
		return FALSE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   502
	if (aHeader->SizeOfRawData==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   503
		return FALSE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   504
	return TRUE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   505
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   506
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   507
void PEFile::CopySectionData(TAny *source, TAny *dest, TUint32 fileLength, TUint32 memLength)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   508
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   509
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   510
	if (fileLength <= memLength)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   511
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   512
		Print(EScreen,"   Copying %08x bytes from file at %08x to memory at %08x\n", fileLength, source, dest);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   513
		HMem::Copy(dest,source,fileLength);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   514
		dest = (TAny *)((TUint32)dest + fileLength);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   515
		TUint32 remainingSize = memLength - fileLength;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   516
		Print(EScreen,"   Zeroing remaining %08x bytes at %08x\n", remainingSize, dest);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   517
		HMem::Set(dest, 0, remainingSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   518
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   519
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   520
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   521
		Print(EScreen,"   Copying %08x bytes from file at %08x to memory at %08x\n", memLength, source, dest);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   522
		HMem::Copy(dest,source,memLength);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   523
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   524
	}		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   525
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   526
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   527
TBool PEFile::ProcessRelocData(TAny *relocData,TInt dataSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   528
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   529
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   530
	TBool hadBadRelocs=EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   531
	PIMAGE_BASE_RELOCATION pRelocData = (PIMAGE_BASE_RELOCATION)((TUint32)relocData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   532
	Print(ELog,"   Info on .reloc section...\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   533
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   534
	while (pRelocData->SizeOfBlock != 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   535
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   536
		TUint16 relocType;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   537
		TUint32 relocOffset;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   538
		TUint32 *relocAddr;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   539
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   540
		Print(ELog,"      Virtual address: %08x  size: %08x\n",pRelocData->VirtualAddress, pRelocData->SizeOfBlock);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   541
			
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   542
		TUint numEntries = (pRelocData->SizeOfBlock-sizeof(*pRelocData))/sizeof(TUint16);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   543
		TUint16 *pEntry = (TUint16 *)((TUint32)pRelocData+sizeof(*pRelocData));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   544
		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   545
		for (TUint i=0; i<numEntries; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   546
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   547
			// Extract the top 4 bits of the relocation entry. This is the type
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   548
			relocType = (TUint16)((*pEntry & 0xF000)>>12);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   549
			// The rest of the field is the offset
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   550
			relocOffset = (*pEntry & 0x0FFF);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   551
			switch (relocType)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   552
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   553
				case 0: // Just padding
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   554
					pEntry++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   555
					break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   556
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   557
				case 1:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   558
				case 2:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   559
				case 4:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   560
				case 5:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   561
					Print(EPeError,".reloc section, relocation type not handled.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   562
					return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   563
					break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   564
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   565
				case 3:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   566
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   567
					if (pRelocData->VirtualAddress==0) // Defect in .reloc section of arm ekern.exe
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   568
						{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   569
						pEntry++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   570
						break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   571
						}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   572
					TUint thisReloc=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   573
					relocAddr = (TUint32 *)((TUint32)iMemBase + (TUint32)pRelocData->VirtualAddress + relocOffset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   574
					TUint32 reloc = *relocAddr;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   575
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   576
					if (IsInCode((TUint32)relocAddr) || IsInData((TUint32)relocAddr))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   577
						{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   578
						if (IsInDataReloc(reloc))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   579
					   		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   580
							if (iImageIsDll)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   581
								{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   582
								Print(EPeError,"Dlls should have no RAM (data) relocations.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   583
								return(EFalse);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   584
								}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   585
							thisReloc=reloc+iRamDelta;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   586
							}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   587
						else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   588
							thisReloc=reloc+iRomDelta;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   589
						*relocAddr = thisReloc; // this line here to enable breaking on values of thisReloc 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   590
						}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   591
					else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   592
						hadBadRelocs=ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   593
					pEntry++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   594
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   595
					break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   596
				default:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   597
					Print(EPeError,".reloc section, invalid relocation type.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   598
					return(EFalse);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   599
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   600
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   601
		dataSize-=pRelocData->SizeOfBlock;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   602
		if(dataSize<=0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   603
			break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   604
		pRelocData = (PIMAGE_BASE_RELOCATION)((TUint32)pRelocData+pRelocData->SizeOfBlock);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   605
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   606
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   607
	if (hadBadRelocs)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   608
		Print(EPeError,"File %s has relocation in invalid section\n",iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   609
	return(ETrue);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   610
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   611
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   612
TBool PEFile::IsInCode(TUint32 anAddr)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   613
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   614
	if ((anAddr>=iCodeSectionAddr) && (anAddr<(iCodeSectionAddr+iCodeSectionSize)))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   615
		return(ETrue);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   616
	if ((anAddr>=iRDataSectionAddr) && (anAddr<(iRDataSectionAddr+iRDataSectionSize)))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   617
		return(ETrue);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   618
	if ((anAddr>=iCRTSectionAddr) && (anAddr<(iCRTSectionAddr+iCRTSectionSize)))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   619
		return(ETrue);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   620
	return(EFalse);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   621
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   622
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   623
TBool PEFile::IsInData(TUint32 anAddr)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   624
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   625
	if ((anAddr>=iDataSectionAddr) && (anAddr<(iDataSectionAddr+iDataSectionSize)))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   626
		return(ETrue);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   627
	if ((anAddr>=iBssSectionAddr) && (anAddr<(iBssSectionAddr+iBssSectionSize)))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   628
		return(ETrue);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   629
	return(EFalse);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   630
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   631
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   632
TBool PEFile::IsInDataReloc(TUint32 anAddr)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   633
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   634
	if ((anAddr>=iDataSectionLinkedAddr) && (anAddr<(iDataSectionLinkedAddr+iDataSectionSize)))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   635
		return(ETrue);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   636
	if ((anAddr>=iBssSectionLinkedAddr) && (anAddr<(iBssSectionLinkedAddr+iBssSectionSize)))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   637
		return(ETrue);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   638
	return(EFalse);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   639
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   640
 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   641
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   642
TBool PEFile::IsValidDOSHeader(PIMAGE_DOS_HEADER aDOSHeader)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   643
 	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   644
	if (aDOSHeader->e_magic!=IMAGE_DOS_SIGNATURE)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   645
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   646
		Print(EPeError,"File does not have valid DOS MZ signature.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   647
		return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   648
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   649
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   650
		return ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   651
	}			  
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   652
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   653
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   654
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   655
TBool PEFile::IsValidNTHeader(PIMAGE_NT_HEADERS aNTHeader)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   656
 	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   657
 	if (aNTHeader->Signature != IMAGE_NT_SIGNATURE )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   658
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   659
		Print(EPeError,"File does not have valid NT PE signature.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   660
		return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   661
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   662
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   663
	 return ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   664
	}  
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   665
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   666
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   667
TBool PEFile::IsValidFileHeader(PIMAGE_FILE_HEADER aFileHeader)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   668
 	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   669
	if ((aFileHeader->Machine != IMAGE_FILE_MACHINE_I386) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   670
		&& (aFileHeader->Machine != 0xa00) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   671
		&& (aFileHeader->Machine != 0xb00) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   672
		&& (aFileHeader->Machine !=IMAGE_FILE_MACHINE_ALPHA))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   673
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   674
		Print(EPeError,"File is not a valid i386, ARM, M*Core or ALPHA executable.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   675
		return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   676
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   677
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   678
	if (aFileHeader->SizeOfOptionalHeader == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   679
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   680
		Print(EPeError,"Optional header is 0 bytes in length - this is probably an object, not an executable\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   681
		return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   682
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   683
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   684
  	if (!(aFileHeader->Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   685
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   686
		Print(EPeError,"File is not a valid executable - probably linker error\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   687
		return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   688
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   689
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   690
	return ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   691
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   692
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   693
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   694
// Get details of the next import to fix-up in the current file. Fill in the name of the dll 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   695
//it is imported from, the ordinal number and the address to write back to.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   696
#define ORDINAL_DONE 0x40000000
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   697
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   698
TImportStat PEFile::GetNextImport(char * &aDllName, TUint16 &aOrdinal, TUint32 * &aThunk)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   699
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   700
	PIMAGE_THUNK_DATA pLookupTable = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   701
	TUint32 *pThunk = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   702
	TUint32 rawOrdinal = ORDINAL_DONE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   703
	TImportStat res = EImpDone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   704
	PIMAGE_IMPORT_DESCRIPTOR impDesc = iImpDescriptor;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   705
	char *expDllName = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   706
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   707
	if (impDesc == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   708
		return EImpDone; // This file imports nothing
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   709
		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   710
 	while ((rawOrdinal & ORDINAL_DONE) && ((impDesc->TimeDateStamp!=0 ) || (impDesc->Name!=0)))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   711
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   712
		expDllName = (char *)(iMemBase + impDesc->Name);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   713
		pLookupTable = (PIMAGE_THUNK_DATA)(iMemBase + impDesc->Characteristics);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   714
 		pThunk = (TUint32 *)(iMemBase + (TUint32)impDesc->FirstThunk);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   715
		while ((rawOrdinal & ORDINAL_DONE) && (pLookupTable->u1.AddressOfData != 0))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   716
 			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   717
 			if (pLookupTable->u1.Ordinal & IMAGE_ORDINAL_FLAG )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   718
				rawOrdinal = pLookupTable->u1.Ordinal;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   719
			else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   720
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   721
				Print(EPeError,"in file %s\n",iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   722
				Print(EPeError,"It is importing a symbol by name from %s\n",expDllName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   723
				return EImpError;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   724
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   725
			pThunk++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   726
			pLookupTable++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   727
			}	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   728
		impDesc++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   729
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   730
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   731
	if (!(rawOrdinal & ORDINAL_DONE))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   732
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   733
		pThunk--;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   734
		pLookupTable--;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   735
		res = EImpSuccess;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   736
		aDllName = expDllName;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   737
		aThunk = pThunk;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   738
		aOrdinal = (TUint16)(rawOrdinal & 0xFFFF);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   739
		pLookupTable->u1.Ordinal |= ORDINAL_DONE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   740
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   741
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   742
	return res;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   743
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   744
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   745
TUint32 PEFile::GetFixUp(const TUint16 aOrdinal)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   746
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   747
// Look through export directory to find fix-up for given ordinal
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   748
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   749
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   750
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   751
	TUint32 ordBase = iExpDirectory->Base;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   752
	TUint32 *functions = (TUint32 *)((TUint32)iExpDirectory->AddressOfFunctions + iMemBase);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   753
	TUint32 fixupAddr = functions[aOrdinal-ordBase] + iRomRunAddr;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   754
	return fixupAddr;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   755
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   756
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   757
TUint PEFile::GetNumberOfExportedFunctions()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   758
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   759
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   760
	return iExpDirectory->NumberOfFunctions;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   761
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   762
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   763
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   764
TUint PEFile::GetOrdinalBase()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   765
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   766
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   767
	return iExpDirectory->Base;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   768
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   769
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   770
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   771
TBool PEFile::ExportSectionExists()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   772
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   773
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   774
	if (iExpDirectory)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   775
		return ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   776
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   777
		return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   778
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   779
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   780
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   781
TBool PEFile::ImportSectionExists()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   782
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   783
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   784
	if (iImpDescriptor)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   785
		return ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   786
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   787
		return EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   788
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   789
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   790
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   791
TUint PEFile::RoundToSectionSize(TUint aSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   792
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   793
// Round to the nearest size in sections
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   794
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   795
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   796
	TUint sAlign = iSectionAlign;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   797
	return ((aSize+sAlign-1)/sAlign)*sAlign ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   798
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   799
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   800
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   801
void PEFile::DumpPeHeaders()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   802
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   803
// Print out loads of stuff from the PE header
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   804
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   805
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   806
	TInt err = HFile::Open(iFileName, &iFileHandle);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   807
	if (err!=0) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   808
		return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   809
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   810
	iHeader = (PIMAGE_NT_HEADERS)(HMem::Alloc(0,iSizeOfHeaders-iStartOfHeaders));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   811
	if (!iHeader)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   812
		return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   813
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   814
	if (!HFile::Seek(iFileHandle, iStartOfHeaders))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   815
		return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   816
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   817
 	if (!HFile::Read(iFileHandle, iHeader, iSizeOfHeaders-iStartOfHeaders))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   818
		return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   819
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   820
	PIMAGE_FILE_HEADER pFileHeader = (PIMAGE_FILE_HEADER)&iHeader->FileHeader;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   821
	PIMAGE_OPTIONAL_HEADER pOptionalHeader = (PIMAGE_OPTIONAL_HEADER)&iHeader->OptionalHeader;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   822
	PIMAGE_SECTION_HEADER pSectionHeader = (PIMAGE_SECTION_HEADER)(iHeader+1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   823
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   824
 	printf("File header\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   825
 	printf("-----------\n\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   826
	char *szMachine=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   827
	switch( pFileHeader->Machine )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   828
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   829
		case 0xa00:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   830
			szMachine = (char *)"ARM"; break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   831
		case 0xb00:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   832
			szMachine = (char *)"M*Core"; break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   833
		case IMAGE_FILE_MACHINE_I386:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   834
			szMachine = (char *)"i386"; break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   835
		case IMAGE_FILE_MACHINE_I860:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   836
			szMachine = (char *)"i860"; break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   837
		case IMAGE_FILE_MACHINE_R3000:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   838
			szMachine = (char *)"R3000"; break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   839
		case IMAGE_FILE_MACHINE_R4000:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   840
			szMachine = (char *)"R4000"; break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   841
		case IMAGE_FILE_MACHINE_ALPHA:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   842
			szMachine = (char *)"Alpha"; break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   843
		case IMAGE_FILE_MACHINE_POWERPC:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   844
			szMachine = (char *)"IBM PowerPC"; break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   845
		default:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   846
			printf ("ERROR - machine not specified.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   847
			szMachine = (char *)"unknown";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   848
			break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   849
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   850
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   851
	printf("\n    Machine: %s (Id=%04x)",szMachine, pFileHeader->Machine);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   852
	if ((pFileHeader->Machine != 0xa00)		// ARM
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   853
		&& (pFileHeader->Machine != 0xb00))	// M*Core
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   854
		printf("..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   855
    printf("\n    Number of sections : %04x",pFileHeader->NumberOfSections);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   856
    printf("\n    Time date stamp : %08lx",pFileHeader->TimeDateStamp);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   857
	if (pFileHeader->TimeDateStamp == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   858
		printf("..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   859
    printf("\n    Pointer to symbol table : %08lx",pFileHeader->PointerToSymbolTable);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   860
    printf("\n    Number of symbols : %08lx",pFileHeader->NumberOfSymbols);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   861
    printf("\n    Size of optional header : %08x",pFileHeader->SizeOfOptionalHeader);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   862
	if (pFileHeader->SizeOfOptionalHeader == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   863
		printf("..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   864
    printf("\n    Characteristics : %08x\n",pFileHeader->Characteristics);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   865
	if (pFileHeader->Characteristics & IMAGE_FILE_RELOCS_STRIPPED)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   866
		printf("\n      Relocations stripped..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   867
	if (pFileHeader->Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   868
		printf("\n      Executable image.");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   869
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   870
		printf("\n      Not executable image..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   871
	if (pFileHeader->Characteristics & IMAGE_FILE_CHAR_REVERSED_LO)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   872
		printf("\n      Bytes reversed lo..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   873
 	if (pFileHeader->Characteristics & IMAGE_FILE_32BIT_MACHINE)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   874
		printf("\n      32bit image.");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   875
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   876
		printf("\n      Not 32bit image..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   877
 	if (pFileHeader->Characteristics & IMAGE_FILE_SYSTEM)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   878
		printf("\n      System file.");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   879
 	if (pFileHeader->Characteristics & IMAGE_FILE_DLL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   880
		printf("\n      Dll file.");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   881
	if (pFileHeader->Characteristics & IMAGE_FILE_CHAR_REVERSED_HI)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   882
		printf("\n      Bytes reversed hi..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   883
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   884
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   885
  	printf ("\n\n\nOptional Header\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   886
  	printf ("------------------");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   887
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   888
	printf("\n    Magic = %04x", pOptionalHeader->Magic);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   889
	printf("\n    Major Linker Version = %02x", pOptionalHeader->MajorLinkerVersion);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   890
	printf("\n    Minor Linker Version = %02x", pOptionalHeader->MinorLinkerVersion);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   891
	printf("\n    Size of code (bytes) = %08lx", pOptionalHeader->SizeOfCode);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   892
	printf("\n    Size of initialized data (bytes) = %08lx", pOptionalHeader->SizeOfInitializedData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   893
	printf("\n    Size of uninitialized data (bytes) = %08lx", pOptionalHeader->SizeOfUninitializedData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   894
	printf("\n    Entrypoint RVA = %08lx", pOptionalHeader->AddressOfEntryPoint);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   895
	if (pOptionalHeader->AddressOfEntryPoint & 0x80000000)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   896
		printf("..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   897
	printf("\n    Base of code = %08lx", pOptionalHeader->BaseOfCode);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   898
	if (pOptionalHeader->BaseOfCode & 0x80000000)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   899
		printf("..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   900
	printf("\n    Base of data = %08lx", pOptionalHeader->BaseOfData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   901
	if (pOptionalHeader->BaseOfData & 0x80000000)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   902
		printf("..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   903
	printf("\n    Image base = %08lx", pOptionalHeader->ImageBase);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   904
	if (pOptionalHeader->ImageBase & 0x80000000)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   905
		printf("..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   906
	printf("\n    Section alignment (bytes) = %08lx",pOptionalHeader->SectionAlignment);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   907
	if (pOptionalHeader->SectionAlignment & 0x80000000)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   908
		printf("..........ERROR!!\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   909
	printf("\n    File alignment (bytes) = %08lx", pOptionalHeader->FileAlignment);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   910
	if (pOptionalHeader->FileAlignment & 0x80000000)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   911
		printf("..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   912
	printf("\n    Major Operating System Version = %04x", pOptionalHeader->MajorOperatingSystemVersion);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   913
	printf("\n    Minor Operating System Version = %04x", pOptionalHeader->MinorOperatingSystemVersion);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   914
	printf("\n    Major Image Version = %04x", pOptionalHeader->MajorImageVersion);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   915
	printf("\n    Minor Image Version = %04x", pOptionalHeader->MinorImageVersion);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   916
	printf("\n    Major Subsystem Version = %04x", pOptionalHeader->MajorSubsystemVersion);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   917
	printf("\n    Minor Subsystem Version = %04x", pOptionalHeader->MinorSubsystemVersion);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   918
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   919
	printf("\n    Size of image (bytes) = %08lx", pOptionalHeader->SizeOfImage);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   920
	if (pOptionalHeader->SizeOfImage & 0x80000000)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   921
		printf("..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   922
	printf("\n    Size of headers (bytes) = %08lx",pOptionalHeader->SizeOfHeaders);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   923
	if (pOptionalHeader->SizeOfHeaders & 0x80000000)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   924
		printf("..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   925
	printf("\n    CheckSum = %04lx", pOptionalHeader->CheckSum);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   926
	printf("\n    Subsystem = %04x", pOptionalHeader->Subsystem);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   927
	printf("\n    Dll Characteristics = %04x", pOptionalHeader->DllCharacteristics);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   928
	printf("\n    Size Of Stack Reserve = %04lx", pOptionalHeader->SizeOfStackReserve);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   929
	printf("\n    Size Of Stack Commit = %04lx", pOptionalHeader->SizeOfStackCommit);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   930
	printf("\n    Size Of Heap Reserve = %04lx", pOptionalHeader->SizeOfHeapReserve);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   931
	printf("\n    Size Of Heap Commit = %04lx", pOptionalHeader->SizeOfHeapCommit);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   932
	printf("\n    Loader Flags = %04lx", pOptionalHeader->LoaderFlags);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   933
	printf("\n    Number Of Rva and Sizes = %04lx", pOptionalHeader->NumberOfRvaAndSizes);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   934
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   935
	printf("\n\n\nSection Headers\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   936
 	printf("---------------\n\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   937
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   938
 	for (TUint i=0;i<iNumSections;i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   939
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   940
		DumpNextSectionInFile(pSectionHeader);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   941
		pSectionHeader++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   942
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   943
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   944
	if (!hadText)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   945
 		printf("\nERROR - missing code section.");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   946
	if (!hadReloc)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   947
 		printf("\nERROR - missing reloc section. (All images must be relocatable.)");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   948
	HMem::Free(iHeader);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   949
 	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   950
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   951
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   952
void PEFile::DumpNextSectionInFile(PIMAGE_SECTION_HEADER pSectionHeader)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   953
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   954
// Print out loads of stuff from the section header
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   955
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   956
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   957
	printf("\nSection name %-8.8s\n",pSectionHeader->Name);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   958
	printf("\n    Virtual size            : %08lx", pSectionHeader->Misc.VirtualSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   959
	printf("\n    RVA of section data     : %08lx", pSectionHeader->VirtualAddress);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   960
	if (pSectionHeader->VirtualAddress & 0x80000000)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   961
		printf("..........ERROR!!");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   962
	printf("\n    Size of raw data        : %08lx", pSectionHeader->SizeOfRawData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   963
	printf("\n    Pointer to raw data     : %08lx", pSectionHeader->PointerToRawData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   964
	printf("\n    Characteristics: %08lx\n", pSectionHeader->Characteristics);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   965
 	if (pSectionHeader->Characteristics & IMAGE_SCN_LNK_REMOVE)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   966
		printf("\nERROR - Section should have been removed by linker.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   967
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   968
	// read the section in
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   969
	TUint32 filePos = pSectionHeader->PointerToRawData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   970
 	TUint32 fileLength = pSectionHeader->SizeOfRawData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   971
//	TUint32 memLength = pSectionHeader->Misc.VirtualSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   972
	TAny *sectionFile = HMem::Alloc((TAny *)0, fileLength); // get a buffer
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   973
	HFile::Seek(iFileHandle, filePos);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   974
	HFile::Read(iFileHandle, sectionFile, fileLength); // and read the file into the buffer
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   975
//	TAny *sectionMem = (TAny *)((TUint32)iMemBase + pSectionHeader->VirtualAddress);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   976
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   977
	if (strnicmp((const char *)pSectionHeader->Name, ".text", IMAGE_SIZEOF_SHORT_NAME) == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   978
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   979
		hadText = ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   980
		if (!(pSectionHeader->Characteristics & IMAGE_SCN_CNT_CODE))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   981
			printf("\nERROR - Code section has incorrect characteristics.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   982
		else if (!(pSectionHeader->Characteristics & IMAGE_SCN_MEM_EXECUTE))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   983
			printf("\nERROR - Code section has incorrect characteristics.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   984
		else if (!(pSectionHeader->Characteristics & IMAGE_SCN_MEM_READ))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   985
			printf("\nERROR - Code section has incorrect characteristics.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   986
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   987
	else if (strnicmp((const char *)pSectionHeader->Name, ".data", IMAGE_SIZEOF_SHORT_NAME) == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   988
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   989
		if (iImageIsDll)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   990
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   991
			printf ("\nERROR - DLL has data section.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   992
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   993
		else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   994
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   995
			if (!(pSectionHeader->Characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   996
				printf("\nERROR - data section has incorrect characteristics.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   997
			else if (!(pSectionHeader->Characteristics & IMAGE_SCN_MEM_WRITE))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   998
				printf("\nERROR - data section has incorrect characteristics.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   999
			else if (!(pSectionHeader->Characteristics & IMAGE_SCN_MEM_READ))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1000
				printf("\nERROR - data section has incorrect characteristics.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1001
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1002
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1003
	else if (strnicmp((const char *)pSectionHeader->Name, ".rdata", IMAGE_SIZEOF_SHORT_NAME) == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1004
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1005
		}							
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1006
	else if (strnicmp((const char *)pSectionHeader->Name, ".bss", IMAGE_SIZEOF_SHORT_NAME) == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1007
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1008
		if (iImageIsDll)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1009
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1010
			printf ("\nERROR - DLL has bss section.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1011
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1012
		else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1013
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1014
			if (!(pSectionHeader->Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1015
				printf("\nERROR - BSS section has incorrect characteristics.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1016
			else if (!(pSectionHeader->Characteristics & IMAGE_SCN_MEM_WRITE))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1017
				printf("\nERROR - BSS section has incorrect characteristics.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1018
			else if (!(pSectionHeader->Characteristics & IMAGE_SCN_MEM_READ))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1019
				printf("\nERROR - BSS section has incorrect characteristics.\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1020
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1021
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1022
 	else if (strnicmp((const char *)pSectionHeader->Name, ".reloc", IMAGE_SIZEOF_SHORT_NAME) == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1023
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1024
		hadReloc = ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1025
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1026
	else if (strnicmp((const char *)pSectionHeader->Name, ".idata", IMAGE_SIZEOF_SHORT_NAME) == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1027
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1028
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1029
	else if (strnicmp((const char *)pSectionHeader->Name, ".edata", IMAGE_SIZEOF_SHORT_NAME) == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1030
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1031
		iExpDirectory = (PIMAGE_EXPORT_DIRECTORY)(sectionFile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1032
		if (iImageIsDll)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1033
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1034
			printf("\n      Ordinal base = %08lx", iExpDirectory->Base);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1035
			printf("\n      Number of functions = %08lx", iExpDirectory->NumberOfFunctions);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1036
			printf("\n      Number of names = %08lx", iExpDirectory->NumberOfNames);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1037
			printf("\n      Export address table RVA = %08lx", (TUint32)iExpDirectory->AddressOfFunctions);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1038
			printf("\n      Name pointer RVA = %08lx", (TUint32)iExpDirectory->AddressOfNames);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1039
			printf("\n      Ordinal table RVA = %08lx", (TUint32)iExpDirectory->AddressOfNameOrdinals);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1040
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1041
		else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1042
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1043
			printf("\nERROR - non-DLL with export section.");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1044
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1045
 		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1046
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1047
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1048
		printf("\nERROR - unexpected section.");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1049
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1050
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1051
	HMem::Free(sectionFile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1052
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1053
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
  1054