paludis  Version 2.6.0
elf_sections.hh
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 /*
4  * Copyright (c) 2007 Tiziano Müller
5  * Copyright (c) 2007 David Leverton
6  *
7  * This file is part of the Paludis package manager. Paludis is free software;
8  * you can redistribute it and/or modify it under the terms of the GNU General
9  * Public License version 2, as published by the Free Software Foundation.
10  *
11  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18  * Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_ELF_SECTIONS_HH
22 #define PALUDIS_GUARD_PALUDIS_UTIL_ELF_SECTIONS_HH 1
23 
24 #include <string>
25 #include <iosfwd>
26 #include <paludis/util/visitor.hh>
27 #include <paludis/util/type_list.hh>
28 
29 namespace paludis
30 {
31  template <typename ElfType_> class ElfObject;
32  template <typename ElfType_> class Section;
33  template <typename ElfType_> class StringSection;
34  template <typename ElfType_> class DynamicSection;
35  template <typename ElfType_> class SymbolSection;
36  template <typename ElfType_> class GenericSection;
37  template <typename ElfType_, class RelocationType_> class RelocationSection;
38 
39  template <typename ElfType_> struct Relocation;
40  template <typename ElfType_> struct RelocationA;
41 
42  namespace littlelf_internals
43  {
44  template <typename ElfType_> class SectionNameResolvingVisitor;
45  }
46 
47  template <typename ElfType_>
48  class Section :
49  public virtual paludis::DeclareAbstractAcceptMethods<Section<ElfType_>, typename paludis::MakeTypeList<
50  StringSection<ElfType_>,
51  DynamicSection<ElfType_>,
52  SymbolSection<ElfType_>,
53  GenericSection<ElfType_>,
54  RelocationSection<ElfType_, Relocation<ElfType_> >,
55  RelocationSection<ElfType_, RelocationA<ElfType_> >
56  >::Type>
57  {
59 
60  private:
61  typename ElfType_::Word _index;
62  typename ElfType_::SectionHeader _shdr;
63  std::string _name;
64 
65  protected:
66  void resolve_section_name(std::string name)
67  {
68  _name = name;
69  }
70 
71  typename ElfType_::Word get_name_index() const
72  {
73  return _shdr.sh_name;
74  }
75 
76  public:
77  Section(typename ElfType_::Word, const typename ElfType_::SectionHeader &);
78  virtual ~Section();
79 
80  virtual typename ElfType_::Offset get_data_offset() const
81  {
82  return _shdr.sh_offset;
83  }
84 
85  virtual std::string get_name() const
86  {
87  return _name;
88  }
89  virtual std::string get_type() const = 0;
90  typename ElfType_::Word get_index() const
91  {
92  return _index;
93  }
94 
95  typename ElfType_::Word get_link_index() const
96  {
97  return _shdr.sh_link;
98  }
99 
100  typename ElfType_::Address get_virtual_address() const
101  {
102  return _shdr.sh_addr;
103  }
104 
105  typename ElfType_::SectionSize get_size() const
106  {
107  return _shdr.sh_size;
108  }
109 
110  std::string description() const;
111  };
112 
113 
114  template <typename ElfType_>
115  class GenericSection :
116  public Section<ElfType_>,
117  public paludis::ImplementAcceptMethods<Section<ElfType_>, GenericSection<ElfType_> >
118  {
119  public:
120  GenericSection(typename ElfType_::Word, const typename ElfType_::SectionHeader &);
121  virtual ~GenericSection();
122  virtual std::string get_type() const;
123  };
124 
125  template <typename ElfType_>
126  class StringSection :
127  public Section<ElfType_>,
128  public paludis::ImplementAcceptMethods<Section<ElfType_>, StringSection<ElfType_> >
129  {
130  private:
131  std::string _stringTable;
132 
133  public:
134  StringSection(typename ElfType_::Word, const typename ElfType_::SectionHeader &, std::istream &, bool);
135  virtual ~StringSection();
136 
137  std::string get_string(typename ElfType_::Word) const;
138  typename ElfType_::Word get_max_string() const
139  {
140  return _stringTable.length();
141  }
142 
143  virtual std::string get_type() const;
144  };
145 }
146 
147 #endif
Definition: about_metadata-fwd.hh:23
Definition: elf_dynamic_section.hh:197
Definition: visitor-fwd.hh:52
Definition: elf_sections.hh:33
Definition: elf_relocation_section.hh:99
Definition: elf_sections.hh:32
Definition: elf_relocation_section.hh:88
Definition: elf_relocation_section.hh:80
Definition: visitor-fwd.hh:49
Definition: elf_sections.hh:36
Definition: elf_sections.hh:35