bintools/elftools/inc/elffile.h
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #if !defined(__ELFFILE_H__)
       
    20 #define __ELFFILE_H__
       
    21 #include <e32rom.h>
       
    22 #include "e32ldfmt.h"
       
    23 #include <elfdefs.h>
       
    24 
       
    25 #define ELFADDR(rtype, p, o) (rtype *)(((char *)p) + o)
       
    26 
       
    27 //
       
    28 enum TImportStat {EImpError, EImpSuccess, EImpDone};
       
    29 //
       
    30 class ELFFile
       
    31 	{
       
    32 public:
       
    33 	ELFFile();
       
    34 	~ELFFile();
       
    35 	TBool Init(const TText * const aFileName);
       
    36 	void Close(void);
       
    37 
       
    38 	char *CreateImportSection(TInt &aSize);
       
    39 
       
    40 	TBool GetRelocs(Elf32_Rel **aCodeRelocs, Elf32_Rel **aDataRelocs);
       
    41 	TUint16 GetRelocType(Elf32_Rel* aReloc);
       
    42 
       
    43 	TInt NumberOfImports() const;
       
    44 	TInt NumberOfImportDlls() const;
       
    45 	TInt NumberOfExports() const;
       
    46 	TInt NumberOfRelocs();
       
    47 
       
    48 	
       
    49 
       
    50 	TInt NumberOfCodeRelocs();
       
    51 	TInt NumberOfDataRelocs();
       
    52 	
       
    53 public:
       
    54 	TUint iCodeSize;
       
    55 	TUint iDataSize;
       
    56 	TUint iBssSize;
       
    57 
       
    58 
       
    59 	TUint GetCodeSize();
       
    60 	TBool HasInitialisedData();
       
    61 	TUint GetDataSize();
       
    62 	TBool HasBssData();
       
    63 	TUint GetBssSize();
       
    64 	
       
    65 
       
    66 	Elf32_Phdr * GetSegment(TInt idx) {return &iPhdr[idx];}
       
    67 	Elf32_Phdr * GetSegmentFromAddr(Elf32_Addr addr);
       
    68 
       
    69 	char * GetCode() { return ELFADDR(char, iElfFile, iCodeSegmentHdr->p_offset); }
       
    70 	char * GetData() { return ELFADDR(char, iElfFile, iDataSegmentHdr->p_offset); }
       
    71 	TBool CodeSegmentP(Elf32_Phdr * s) { return (TBool)(s == iCodeSegmentHdr); }
       
    72 	TBool CodeSegmentP(TInt idx) { return (TBool)(idx == iCodeSegmentIdx); }
       
    73 	TInt CodeSegmentIndex() {return iCodeSegmentIdx;}
       
    74 	TBool DataSegmentP(Elf32_Phdr * s) { return (TBool)(s == iDataSegmentHdr); }
       
    75 	TBool DataSegmentP(TInt idx) { return (TBool)(idx == iDataSegmentIdx); }
       
    76 	TInt DataSegmentIndex() {return iDataSegmentIdx;}
       
    77 
       
    78 	TUint * CodePtrFromAddr(Elf32_Addr addr) { return PtrInSegment(iCodeSegmentHdr, addr); }
       
    79 	TUint * DataPtrFromAddr(Elf32_Addr addr) { return PtrInSegment(iDataSegmentHdr, addr); }
       
    80 
       
    81 
       
    82 	char * ELFFileBase() { return (char *) iElfFile; }
       
    83 
       
    84 	TUint GetExportTableOffset(void);
       
    85 	TUint GetEntryPointOffset(void) { return iElfFile->e_entry - iCodeSegmentHdr->p_vaddr; }
       
    86 
       
    87 	TBool SymbolPresent(TText *s);
       
    88 	Elf32_Sym * FindSymbol(const TText *);
       
    89 
       
    90 	TBool GetExceptionIndexInfo(TUint32 &aOffset);
       
    91 	TBool SetUpLookupTable();
       
    92 	void SetLookupTblBase(TInt);
       
    93 	TInt GetLookupTblSize();
       
    94 	void GetExportSymInfoHeader(E32EpocExpSymInfoHdr& aSymInfoHdr);
       
    95 	TUint GetSymLookupSection(char* aBuff);
       
    96 private:
       
    97 	TBool InitHeaders(void);
       
    98 	TBool InitDllData(void);
       
    99 
       
   100 	TUint * PtrInSegment(Elf32_Phdr * phdr, Elf32_Addr addr) 
       
   101 	        { 
       
   102 		return ELFADDR(TUint, ELFADDR(TUint, iElfFile, phdr->p_offset), (addr - phdr->p_vaddr));
       
   103 		}
       
   104 
       
   105 
       
   106 	TBool IsValidFileHeader(Elf32_Ehdr * aElfHdr);
       
   107 	void CopySectionData(TAny *source, TAny *dest, TUint32 fileLength, TUint32 memLength);
       
   108 	TBool ProcessRelocData(TAny *relocData,TInt dataSize);
       
   109 	ELFFile(const ELFFile&);
       
   110 	const ELFFile & operator = (const ELFFile&);
       
   111 public:
       
   112 	TBool	iImageIsDll;
       
   113 	TBool	ImageIsDll() { return iImageIsDll; }
       
   114 	Elf32_Addr iLinkedBase;
       
   115 
       
   116 	TUint iEntryPoint;
       
   117 	TUint iHeapCommittedSize;
       
   118 	TUint iHeapReservedSize;
       
   119 	TUint iStackCommittedSize;
       
   120 	TUint iStackReservedSize;
       
   121 private:
       
   122 	friend class E32ImageFile;
       
   123 	friend class E32ImageFile_ELF;
       
   124 
       
   125 	TText * iFileName;
       
   126 	TInt32 iFileHandle;
       
   127 	Elf32_Ehdr * iElfFile;
       
   128 	Elf32_Phdr * iPhdr;
       
   129 	Elf32_Phdr * iDynamicSegmentHdr;
       
   130 	TInt iDynamicSegmentIdx;
       
   131 	Elf32_Phdr * iCodeSegmentHdr;
       
   132 	TInt iCodeSegmentIdx;
       
   133 	Elf32_Phdr * iDataSegmentHdr;
       
   134 	TInt iDataSegmentIdx;
       
   135 
       
   136 	Elf32_Shdr * iSectionHeaderTable;
       
   137 	TInt iSymIdx;
       
   138 	Elf32_Sym * iSymTab;
       
   139 
       
   140 	class ELFDllData;
       
   141 	ELFDllData * iDllData;
       
   142 
       
   143 	TCpu iCpu;
       
   144 
       
   145 
       
   146 	};
       
   147 #endif
       
   148 
       
   149 
       
   150 
       
   151 
       
   152 
       
   153 
       
   154 
       
   155 
       
   156 
       
   157 
       
   158 
       
   159 
       
   160