HaikuDepot: notify work status from main window
[haiku.git] / src / tools / elfsymbolpatcher / ElfFile.h
blob52fafcaa3e3dea015ad311973af53fc718e6e6ac
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2003, Ingo Weinhold
3 //
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
26 // sections.
27 //------------------------------------------------------------------------------
29 #ifndef ELF_FILE_H
30 #define ELF_FILE_H
32 #include <File.h>
33 #include <image.h>
35 #include "Elf.h"
38 namespace SymbolPatcher {
40 class ElfFile;
41 class ElfSection;
43 // ElfSymbol
44 class ElfSymbol {
45 public:
46 ElfSymbol(ElfSection* section = NULL,
47 int32 index = -1);
48 ~ElfSymbol();
50 void SetTo(ElfSection* section, int32 index);
51 void Unset();
53 const Elf32_Sym* GetSymbolStruct();
54 const char* GetName();
55 uint32 GetBinding();
56 uint32 GetType();
57 uint32 GetTargetSectionIndex();
59 private:
60 ElfSection* fSection;
61 int32 fIndex;
62 Elf32_Sym* fSymbol;
65 // ElfRelocation
66 class ElfRelocation {
67 public:
68 ElfRelocation(ElfSection* section = NULL,
69 int32 index = -1);
70 ~ElfRelocation();
72 void SetTo(ElfSection* section, int32 index);
73 void Unset();
75 Elf32_Rel* GetRelocationStruct();
76 uint32 GetType();
77 uint32 GetSymbolIndex();
78 Elf32_Addr GetOffset();
79 status_t GetSymbol(ElfSymbol* symbol);
81 private:
82 ElfSection* fSection;
83 int32 fIndex;
84 Elf32_Rel* fRelocation;
87 // ElfRelocationIterator
88 class ElfRelocationIterator {
89 public:
90 ElfRelocationIterator(ElfFile* file);
91 ~ElfRelocationIterator();
93 bool GetNext(ElfRelocation* relocation);
95 private:
96 ElfSection* _FindNextSection();
98 private:
99 ElfFile* fFile;
100 int32 fSectionIndex;
101 int32 fEntryIndex;
104 // ElfFile
105 class ElfFile {
106 public:
107 ElfFile();
108 ~ElfFile();
109 status_t SetTo(const char *filename);
110 void Unset();
111 void Unload();
113 BFile* GetFile() { return &fFile; }
115 const char* GetSectionHeaderStrings(size_t* size);
116 const char* GetStringSectionStrings(int32 index,
117 size_t* size);
119 int32 CountSections() const { return fSectionCount; }
120 ElfSection* SectionAt(int32 index, bool load = false);
122 void Dump();
124 private:
125 status_t _SetTo(const char *filename);
127 Elf32_Shdr* _SectionHeaderAt(int32 index);
129 status_t _LoadSection(int32 index);
131 private:
132 BFile fFile;
133 Elf32_Ehdr fHeader;
134 uint8* fSectionHeaders;
135 ElfSection* fSections;
136 int32 fSectionCount;
137 size_t fSectionHeaderSize;
140 } // namespace SymbolPatcher
142 using namespace SymbolPatcher;
145 #endif // ELF_FILE_H