-
Notifications
You must be signed in to change notification settings - Fork 3
/
PltList.C
62 lines (49 loc) · 1.22 KB
/
PltList.C
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
#include "PltList.h"
#include "Common.h"
#ifdef HAVE_LIBBFD
#include <bfd.h>
#endif
bool PltList::AddPlt (const MemoryMappings::Mapping& mapping)
{
#ifndef HAVE_LIBBFD
return false;
#else
DEBUG("looking for PLT section in '%s'", mapping.name.c_str());
bfd_init();
bfd* abfd = bfd_openr(mapping.name.c_str(), NULL);
if (!abfd)
{
return false;
}
const int formatOk = bfd_check_format(abfd, bfd_object);
if (!formatOk)
{
bfd_close(abfd);
return false;
}
const asection* pltSectionPtr = bfd_get_section_by_name(abfd, ".plt");
if (!pltSectionPtr)
{
bfd_close(abfd);
return false;
}
Section newSection;
newSection.start = mapping.start + pltSectionPtr->filepos;
newSection.end = newSection.start + pltSectionPtr->size;
this->sections.push_back(newSection);
bfd_close(abfd);
return true;
#endif
}
const PltList::Section* PltList::FindContainingPlt (const unsigned long addr) const
{
for (vector<Section>::const_iterator it = this->sections.begin();
it != this->sections.end(); ++it)
{
if (addr >= it->start && addr <= it->end)
{
return &(*it);
}
}
return NULL;
}