1 //------------------------------------------------------------------------------
2 // Copyright (c) 2003, Ingo Weinhold
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
22 // File Name: ElfFile.h
23 // Author: Ingo Weinhold (bonefish@users.sf.net)
24 // Description: Interface declarations of classes for accessing ELF file,
25 // or more precisely for iterating through their relocation
27 //------------------------------------------------------------------------------
38 namespace SymbolPatcher
{
46 ElfSymbol(ElfSection
* section
= NULL
,
50 void SetTo(ElfSection
* section
, int32 index
);
53 const Elf32_Sym
* GetSymbolStruct();
54 const char* GetName();
57 uint32
GetTargetSectionIndex();
68 ElfRelocation(ElfSection
* section
= NULL
,
72 void SetTo(ElfSection
* section
, int32 index
);
75 Elf32_Rel
* GetRelocationStruct();
77 uint32
GetSymbolIndex();
78 Elf32_Addr
GetOffset();
79 status_t
GetSymbol(ElfSymbol
* symbol
);
84 Elf32_Rel
* fRelocation
;
87 // ElfRelocationIterator
88 class ElfRelocationIterator
{
90 ElfRelocationIterator(ElfFile
* file
);
91 ~ElfRelocationIterator();
93 bool GetNext(ElfRelocation
* relocation
);
96 ElfSection
* _FindNextSection();
109 status_t
SetTo(const char *filename
);
113 BFile
* GetFile() { return &fFile
; }
115 const char* GetSectionHeaderStrings(size_t* size
);
116 const char* GetStringSectionStrings(int32 index
,
119 int32
CountSections() const { return fSectionCount
; }
120 ElfSection
* SectionAt(int32 index
, bool load
= false);
125 status_t
_SetTo(const char *filename
);
127 Elf32_Shdr
* _SectionHeaderAt(int32 index
);
129 status_t
_LoadSection(int32 index
);
134 uint8
* fSectionHeaders
;
135 ElfSection
* fSections
;
137 size_t fSectionHeaderSize
;
140 } // namespace SymbolPatcher
142 using namespace SymbolPatcher
;