dbgsrv/coredumpserver/plugins/formatters/symbianelf/selflib/selflib.h
author ravikurupati
Tue, 02 Mar 2010 10:33:16 +0530
changeset 0 c6b0df440bee
permissions -rw-r--r--
Initial contribution of EPL licensed sources
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     1
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     2
// All rights reserved.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     3
// This component and the accompanying materials are made available
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     5
// which accompanies this distribution, and is available
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     7
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     8
// Initial Contributors:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    10
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    11
// Contributors:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    12
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    13
// Description:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    14
//	Classes that allow the editing and creation of Symbian ELF files
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    15
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    16
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    17
/**
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    18
 * @file
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    19
 * @publishedAll
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    20
 * @prototype
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    21
 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    22
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    23
#ifndef __SELF_LIB_H__
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    24
#define __SELF_LIB_H__
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    25
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    26
#include <e32base.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    27
#include <e32debug.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    28
#include <f32file.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    29
#include <elfdefs.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    30
#include <badesca.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    31
#include <symbianelfdefs.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    32
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    33
_LIT(KTempFileLocation, "C:\\"); //TODO: Investigate system drive
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    34
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    35
/** Reads a struct from a file
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    36
 *	@param t Type to read
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    37
 *	@param s the structure
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    38
 *	@param f RFile to read from
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    39
 *	@param r Point in the file from which to read
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    40
 * */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    41
#define READ_STRUCTL(t, s, f, r)\
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    42
	t s;\
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    43
	{\
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    44
	TPtr8 ptr((TUint8*)&s, sizeof(s), sizeof(s));\
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    45
	User::LeaveIfError(f.Read(r, ptr));\
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    46
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    47
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    48
/**
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    49
 * This represents a Symbian Note segment in an ELF file
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    50
 * It consits of a program header, descriptor header and
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    51
 * the Note specific segment.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    52
 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    53
struct TSELFSegment
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    54
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    55
	Elf32_Phdr iPhdr;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    56
	Sym32_dhdr iDhdr;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    57
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    58
	union TSegmentType
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    59
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    60
		Sym32_variant_spec_data iVarData;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    61
		//Other section types can live here - currently only support variant specific data
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    62
		};
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    63
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    64
	TSegmentType iType;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    65
	};
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    66
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    67
class CStringInfoTableV2;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    68
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    69
/**
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    70
 * This class is the interface to allow editing of SELF files
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    71
 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    72
class CSELFEditor : public CBase
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    73
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    74
	public:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    75
		IMPORT_C static CSELFEditor* NewL(const TDesC& aFilename);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    76
		IMPORT_C static CSELFEditor* NewLC(const TDesC& aFilename);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    77
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    78
		IMPORT_C void GetELFHeader(Elf32_Ehdr& aELFHeader);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    79
		IMPORT_C void InsertVariantSpecificDataL(const TDesC8& aVarData);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    80
		IMPORT_C void WriteELFUpdatesL();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    81
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    82
		virtual ~CSELFEditor();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    83
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    84
	private:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    85
		CSELFEditor();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    86
		void ConstructL(const TDesC& aFilename);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    87
		TBool IsValidELFFile();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    88
		TBool IsELFFileSupported();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    89
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    90
		TUint CopyFromELFFileL(TUint aStartPoint, TUint aSize, RFile aDestinationFile, TUint aDestWrite = 0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    91
		TUint CopyRegistersL(RFile aFile, TUint aSrcRead, TUint aDestWrite, TUint& aSizeWritten);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    92
		TUint CopyVariantDataL(RFile aFile, TUint aSrcRead, TUint aDestWrite, TUint& aSizeWritten);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    93
		void PutEmptySpaceAtEndOfFileL(RFile aFile, TUint aSize);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    94
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    95
		void CacheStringTableL();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    96
		void CacheProgramHeadersL();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    97
		void CacheELFHeaderL();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    98
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    99
		TUint WriteStringInfoL(RFile aFile, TUint& aOffset);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   100
		void SwapFilesL(const TDesC& aSrc, const TDesC& aDest);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   101
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   102
	private:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   103
		RFs iFsSession;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   104
		RFile iELFFile;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   105
		RArray<TSELFSegment> iNewSegments;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   106
		RArray<Elf32_Phdr> iProgramHeaders;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   107
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   108
		Elf32_Ehdr iELFHeader;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   109
		Sym32_dhdr iStringTableDhdr;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   110
		CStringInfoTableV2* iStringTable;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   111
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   112
		//Flat array of descriptors for data to be inserted to ELF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   113
		CDesC8Array* iRawData;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   114
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   115
	};
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   116
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   117
#endif