aboutsummaryrefslogtreecommitdiff
path: root/src/clients/reconcilio/littlelf/elf_sections.cc
blob: e93159bca3c934485fb09e042192e331677170b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2007 Tiziano Müller
 * Copyright (c) 2007 David Leverton
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "elf_sections.hh"
#include "elf_types.hh"

#include <paludis/util/visitor-impl.hh>

#include <istream>
#include <algorithm>

using namespace paludis;

template <typename ElfType_>
Section<ElfType_>::Section(const typename ElfType_::SectionHeader & shdr) :
    _shdr(shdr),
    _name("")
{
}

template <typename ElfType_>
Section<ElfType_>::~Section()
{
}

template <typename ElfType_>
GenericSection<ElfType_>::GenericSection(const typename ElfType_::SectionHeader & shdr) :
    Section<ElfType_>(shdr)
{
}

template <typename ElfType_>
GenericSection<ElfType_>::~GenericSection()
{
}

template <typename ElfType_>
std::string
GenericSection<ElfType_>::get_type() const
{
    static std::string type("generic");
    return type;
}

template <typename ElfType_>
StringSection<ElfType_>::StringSection(const typename ElfType_::SectionHeader & shdr, std::istream & stream, bool) :
    Section<ElfType_>(shdr),
    _stringTable(shdr.sh_size, ' ')
{
    std::string tmp_table(shdr.sh_size, '\0');
    stream.seekg(shdr.sh_offset, std::ios::beg);
    stream.read(&tmp_table[0], shdr.sh_size);
    std::copy(tmp_table.begin(), tmp_table.end(), _stringTable.begin());
}

template <typename ElfType_>
StringSection<ElfType_>::~StringSection()
{
}

template <typename ElfType_>
std::string
StringSection<ElfType_>::get_string(typename ElfType_::Word index) const
{
    typename ElfType_::Word end(_stringTable.find_first_of('\0', index));
    return _stringTable.substr(index, end-index);
}

template <typename ElfType_>
std::string
StringSection<ElfType_>::get_type() const
{
    static std::string type("STRTAB");
    return type;
}

template class Section<Elf32Type>;
template class Section<Elf64Type>;
template class GenericSection<Elf32Type>;
template class GenericSection<Elf64Type>;
template class StringSection<Elf32Type>;
template class StringSection<Elf64Type>;