bintools/petools/pe_dump/pe_dump.cpp
author jjkang
Fri, 25 Jun 2010 19:56:45 +0800
changeset 604 b33dd54aaa52
parent 600 6d08f4a05d93
permissions -rw-r--r--
add cpptoolsplat
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
// All rights reserved.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
// This component and the accompanying materials are made available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
// which accompanies this distribution, and is available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
// Initial Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
// Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
// Description:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
#include <e32def.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
#include <e32def_private.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
#include <e32err.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#include "h_ver.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include "pe_defs.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
#include <sys/stat.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
#if defined(__MSVCDOTNET__) || defined (__TOOLS2__)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
 #include <iostream>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
 #include <iomanip>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
 #include <fstream>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
 #include <string>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
 using namespace std;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
#else //__MSVCDOTNET__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
 #include <iostream.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
 #include <iomanip.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
 #include <fstream.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
 #include <string.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
#endif //__MSVCDOTNET__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
#include <stdio.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
const int KDiffIdentical=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
const int KDiffDifferent=2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
class PeFile
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
	PeFile();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
	~PeFile();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
	int Open(char *aFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
	void Close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
	PIMAGE_DOS_HEADER DosHeader();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
	PIMAGE_NT_HEADERS Headers();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
	PIMAGE_SECTION_HEADER SectionHeaders();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
	char *LoadSection(PIMAGE_SECTION_HEADER aSectionHeader);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
	int NumberOfSections();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
	char *LoadExtraData(int aOffsetToExtraData, TUint aFileSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
	int Errno();  // Should be invoked only if previous call of PeFile's 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
	              // member function returns incorrectly
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
	int Errno(int aErrno);  // Assign error number for special purpose.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
	fstream iFile;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
	PIMAGE_DOS_HEADER iDosHeader;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
	PIMAGE_NT_HEADERS iHeaders;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
	PIMAGE_SECTION_HEADER iSectionHeaders;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
private:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
	int errnumber;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
	};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
PeFile::PeFile()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
	//: iDosHeader(NULL), iHeaders(NULL), iSectionHeaders(NULL), errno(KErrNone)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
	//commented out as SBSv2 reports error: anachronistic old-style base class initializer
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
	iDosHeader      = NULL    ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
	iHeaders        = NULL    ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
	iSectionHeaders = NULL    ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
	errnumber           = KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
	return;
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
PeFile::~PeFile()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
	delete iDosHeader;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
	delete iHeaders;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
	delete [] iSectionHeaders;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
int PeFile::Open(char *aFileName)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
#if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
	iFile.open(aFileName, ios::in | ios::binary);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
#else //!__MSVCDOTNET__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
	iFile.open(aFileName, ios::in | ios::binary | ios::nocreate);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
#endif //__MSVCDOTNET__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
	if (!iFile.is_open())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
		errnumber = KErrNotFound;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
		return KErrNotFound;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
	return KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
void PeFile::Close()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
	iFile.close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
PIMAGE_DOS_HEADER PeFile::DosHeader()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
	if (iDosHeader)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
		return iDosHeader;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
	iDosHeader=new IMAGE_DOS_HEADER;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
	if (!iDosHeader) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
		errnumber = KErrNoMemory;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
	memset(iDosHeader, 0, sizeof(IMAGE_DOS_HEADER));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
	iFile.seekg(0);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
	iFile.read((char *)iDosHeader, sizeof(IMAGE_DOS_HEADER));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
	if (iDosHeader->e_magic!=IMAGE_DOS_SIGNATURE) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
		errnumber = KErrCorrupt;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
	return iDosHeader;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
PIMAGE_NT_HEADERS PeFile::Headers()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
	if (iHeaders)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
		return iHeaders;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
	PIMAGE_DOS_HEADER d=DosHeader();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
	if (d==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
	iHeaders=new IMAGE_NT_HEADERS;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
	if (!iHeaders) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
		errnumber = KErrNoMemory;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
	memset(iHeaders, 0, sizeof(IMAGE_NT_HEADERS));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
	iFile.seekg(d->e_lfanew);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
	if (iFile.eof()) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
		errnumber = KErrCorrupt;  // File size is too small.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
	iFile.read((char *)iHeaders, sizeof(IMAGE_NT_HEADERS));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
	return iHeaders;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
PIMAGE_SECTION_HEADER PeFile::SectionHeaders()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
	if (iSectionHeaders)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
		return iSectionHeaders;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
	PIMAGE_NT_HEADERS h=Headers();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
	if (h==NULL) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
		errnumber = KErrNoMemory;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
	int numSec;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
	if ((numSec = NumberOfSections()) < 0) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
	else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
		iSectionHeaders=new IMAGE_SECTION_HEADER [numSec];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
		if (!iSectionHeaders) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
			errnumber = KErrNoMemory;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
			return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
	iFile.seekg(DosHeader()->e_lfanew+sizeof(IMAGE_NT_HEADERS));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
	int i=sizeof(IMAGE_SECTION_HEADER)*numSec;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
	iFile.read((char *)iSectionHeaders, i);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
	if (iFile.gcount() != i) {  // The size of header is incorrect.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
		printf("Error: Cannot load section headers in offset: 0x%x \n", 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
			(int) (DosHeader()->e_lfanew + sizeof(IMAGE_NT_HEADERS)));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
		errnumber = KErrCorrupt;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
	return iSectionHeaders;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
int PeFile::NumberOfSections()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
	if (Headers()) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
		return iHeaders->FileHeader.NumberOfSections;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
		return -1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
char *PeFile::LoadSection(PIMAGE_SECTION_HEADER h)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
	char *section=new char [h->SizeOfRawData];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
	if (section==NULL){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
		errnumber = KErrNoMemory;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
	try
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
	memset(section, 0, h->SizeOfRawData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
	catch(...)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
	iFile.seekg(h->PointerToRawData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
	iFile.read(section, h->SizeOfRawData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
	// Guarantee we have loaded the section correctly.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
	unsigned int actNum = iFile.gcount();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
	if (actNum != h->SizeOfRawData) { // The size of section is incorrect.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
		printf("Error: Cannot load section in offset: 0x%x \n", 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
			(int)h->PointerToRawData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
		errnumber = KErrCorrupt;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
	return section;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
char* PeFile::LoadExtraData(int aOffset, TUint aFileSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
	TUint sizeOfExtraData = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
	if(aFileSize >= (TUint)aOffset)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
		sizeOfExtraData=aFileSize-aOffset;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235
	if(sizeOfExtraData>0){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   236
		char* buffer=new char [sizeOfExtraData];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   237
		if (!buffer) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   238
			errnumber = KErrNoMemory;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   239
			return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   240
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   241
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   242
		memset(buffer, 0, sizeOfExtraData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   243
		iFile.seekg(aOffset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   244
		iFile.read(buffer, sizeOfExtraData); // Should be OK if the file size is correct.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   245
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   246
		// Guarantee we have loaded the data correctly.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   247
		unsigned int actNum = iFile.gcount();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   248
		if (actNum != sizeOfExtraData){ // Shouldn't be here is the file size is correct.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   249
			printf("Error: Cannot load extra section in offset: 0x%x \n", aOffset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   250
			errnumber = KErrCorrupt;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   251
			return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   252
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   253
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   254
		return buffer;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   255
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   256
	else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   257
		errnumber = KErrCorrupt;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   258
		return NULL;
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
int PeFile::Errno() {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   264
	return errnumber;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   265
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   266
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   267
int PeFile::Errno(int aErrno) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   268
	return (errnumber = aErrno);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   269
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   270
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   271
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   272
void dump(TUint *aData, TInt aLength)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   273
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   274
	TUint *p=aData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   275
	TInt i=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   276
	char line[256];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   277
	unsigned char *cp=(unsigned char*)aData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   278
	TInt j=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   279
	memset(line,' ',sizeof(line));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   280
	while (i<aLength)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   281
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   282
		TInt ccount=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   283
		char* linep=&line[8*9+2];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   284
		printf("%06x:", i);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   285
		while (i<aLength && ccount<8)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   286
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   287
			printf(" %08x", *p++);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   288
			i+=4;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   289
			ccount++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   290
			for (j=0; j<4; j++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   291
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   292
				unsigned char c=*cp++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   293
				if (c<32 || c>127)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   294
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   295
					c = '.';
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   296
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   297
				*linep++ = c;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   298
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   299
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   300
		*linep='\0';
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   301
		printf("%s\n", line+(ccount*9));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   302
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   303
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   304
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   305
int pecmp(char *aFileName)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   306
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   307
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   308
	PeFile peFile;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   309
	if (peFile.Open(aFileName)!=KErrNone)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   310
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   311
		cout << "Cannot open file '"<<aFileName<<"' for input.\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   312
		return KErrNotFound;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   313
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   314
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   315
	PIMAGE_DOS_HEADER dosHeader=peFile.DosHeader();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   316
	if (dosHeader==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   317
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   318
		switch(peFile.Errno()){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   319
		case KErrNoMemory:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   320
			cout << "Error:  Out of memory\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   321
			return KErrNoMemory;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   322
		default:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   323
			cout << aFileName << " does not have a valid DOS header.\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   324
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   325
		return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   326
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   327
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   328
	PIMAGE_NT_HEADERS headers=peFile.Headers();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   329
	if (headers==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   330
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   331
		switch(peFile.Errno()){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   332
		case KErrNoMemory:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   333
			cout << "Error:  Out of memory\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   334
			return KErrNoMemory;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   335
		default:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   336
			cout << aFileName << " is too small to be a PE file.\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   337
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   338
		return KErrGeneral;
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
	headers->FileHeader.TimeDateStamp=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   342
	headers->OptionalHeader.CheckSum = 0; // Fix for TOOLS2 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   343
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   344
	printf("NT Headers:\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   345
	dump((TUint*)headers, sizeof(IMAGE_NT_HEADERS));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   346
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   347
	int numberofsections=peFile.NumberOfSections();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   348
	if (numberofsections==-1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   349
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   350
		cout << "Not a valid PE file.\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   351
		return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   352
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   353
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   354
	PIMAGE_SECTION_HEADER sectionheaders=peFile.SectionHeaders();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   355
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   356
	printf("Section Headers:\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   357
	dump((TUint*)sectionheaders, sizeof(IMAGE_SECTION_HEADER)*peFile.NumberOfSections());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   358
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   359
	TUint exportDirVa=headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   360
	TUint debugDirVa=headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   361
	int SizeOfHeaders=headers->OptionalHeader.SizeOfHeaders;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   362
	int offsetToExtraData=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   363
	int i;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   364
	for (i=0; i<numberofsections; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   365
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   366
		PIMAGE_SECTION_HEADER h=&sectionheaders[i];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   367
		if(h->SizeOfRawData == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   368
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   369
			continue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   370
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   371
		char *section=peFile.LoadSection(h);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   372
		if (section==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   373
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   374
			switch(peFile.Errno()){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   375
			case KErrNoMemory:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   376
				cout << "Error:  Out of memory\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   377
				return KErrNoMemory;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   378
			default:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   379
				cout << "Not a valid PE file.\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   380
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   381
			return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   382
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   383
		char name[9];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   384
		for (int j=0; j<9; j++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   385
			name[j]=h->Name[j];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   386
		name[8]=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   387
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   388
		if (debugDirVa>=h->VirtualAddress && debugDirVa<h->VirtualAddress+h->SizeOfRawData)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   389
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   390
			// Debug data in this section
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   391
			PIMAGE_DEBUG_DIRECTORY dd=(PIMAGE_DEBUG_DIRECTORY)(section+debugDirVa-h->VirtualAddress);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   392
			TInt debugDirSize=headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   393
			while (debugDirSize>0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   394
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   395
				dd->TimeDateStamp=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   396
				// size & location in file of debug data is not significant
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   397
				// unless it's also mapped (AddressOfRawData != 0). If that's
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   398
				// true, then the data will be visible in one of the sections
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   399
				// anyway...
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   400
				dd->SizeOfData=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   401
				dd->PointerToRawData=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   402
				dd++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   403
				debugDirSize-=sizeof(IMAGE_DEBUG_DIRECTORY);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   404
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   405
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   406
		if (exportDirVa>=h->VirtualAddress && exportDirVa<h->VirtualAddress+h->SizeOfRawData)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   407
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   408
			// Export directory in this section
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   409
			PIMAGE_EXPORT_DIRECTORY ed=(PIMAGE_EXPORT_DIRECTORY)(section+exportDirVa-h->VirtualAddress);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   410
			ed->TimeDateStamp=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   411
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   412
		if (strcmp(".rsrc",name)==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   413
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   414
			int *t=(int *)(section+4);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   415
			*t=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   416
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   417
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   418
		offsetToExtraData=offsetToExtraData+h->SizeOfRawData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   419
		printf("Raw data:\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   420
		dump((TUint*)section, h->SizeOfRawData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   421
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   422
		delete section;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   423
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   424
	struct stat buf;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   425
	stat (aFileName,&buf);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   426
	TUint fileSize=buf.st_size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   427
	offsetToExtraData=offsetToExtraData+SizeOfHeaders;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   428
	TUint sizeOfExtraData = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   429
	if(buf.st_size >= offsetToExtraData)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   430
		sizeOfExtraData=buf.st_size-offsetToExtraData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   431
	char* extraData=peFile.LoadExtraData(offsetToExtraData, fileSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   432
	if(sizeOfExtraData>0){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   433
		char* nsisSign;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   434
		nsisSign=extraData+8;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   435
		if(strncmp (nsisSign,"NullsoftInst",12) == 0){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   436
			printf("\n\n Extra Data:\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   437
			dump((TUint*)extraData, sizeOfExtraData);
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
	peFile.Close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   441
	return KErrNone;
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
int main(int argc, char *argv[])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   445
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   446
	int r=KErrArgument;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   447
	if (argc==2)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   448
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   449
		r=pecmp(argv[1]);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   450
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   451
	if (r==KErrArgument)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   452
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   453
		cout << "\nPE_DUMP - PE file dumper V";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   454
		cout << MajorVersion << '.' << setfill('0') << setw(2) << MinorVersion;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   455
		cout << '(' << setw(3) << Build << ")\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   456
		cout << Copyright;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   457
		cout << "Syntax: "<<argv[0]<<" pefile\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   458
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   459
	return r;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   460
	}