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