2012-06-01 12:52:16 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2012-06-01 12:52:16 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-06-01 12:52:16 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2012-06-01 12:52:16 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2012-06-01 12:52:16 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "elfreader.h"
|
|
|
|
|
#include "qtcassert.h"
|
|
|
|
|
|
2012-07-30 17:31:06 +02:00
|
|
|
#include <QDir>
|
2012-06-01 12:52:16 +02:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
namespace Utils {
|
|
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
quint16 getHalfWord(const unsigned char *&s, const ElfData &context)
|
|
|
|
|
{
|
|
|
|
|
quint16 res;
|
|
|
|
|
if (context.endian == Elf_ELFDATA2MSB)
|
|
|
|
|
res = qFromBigEndian<quint16>(s);
|
|
|
|
|
else
|
|
|
|
|
res = qFromLittleEndian<quint16>(s);
|
|
|
|
|
s += 2;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2012-06-06 16:08:59 +02:00
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
quint32 getWord(const unsigned char *&s, const ElfData &context)
|
2012-06-06 16:08:59 +02:00
|
|
|
{
|
2012-06-08 17:16:27 +02:00
|
|
|
quint32 res;
|
|
|
|
|
if (context.endian == Elf_ELFDATA2MSB)
|
|
|
|
|
res = qFromBigEndian<quint32>(s);
|
2012-06-06 16:08:59 +02:00
|
|
|
else
|
2012-06-08 17:16:27 +02:00
|
|
|
res = qFromLittleEndian<quint32>(s);
|
|
|
|
|
s += 4;
|
|
|
|
|
return res;
|
2012-06-06 16:08:59 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
quint64 getAddress(const unsigned char *&s, const ElfData &context)
|
2012-06-04 17:23:16 +02:00
|
|
|
{
|
2012-06-08 17:16:27 +02:00
|
|
|
quint64 res;
|
|
|
|
|
if (context.elfclass == Elf_ELFCLASS32) {
|
|
|
|
|
if (context.endian == Elf_ELFDATA2MSB)
|
|
|
|
|
res = qFromBigEndian<quint32>(s);
|
|
|
|
|
else
|
|
|
|
|
res = qFromLittleEndian<quint32>(s);
|
|
|
|
|
s += 4;
|
|
|
|
|
} else {
|
|
|
|
|
if (context.endian == Elf_ELFDATA2MSB)
|
|
|
|
|
res = qFromBigEndian<quint64>(s);
|
|
|
|
|
else
|
|
|
|
|
res = qFromLittleEndian<quint64>(s);
|
|
|
|
|
s += 8;
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2012-06-04 17:23:16 +02:00
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
quint64 getOffset(const unsigned char *&s, const ElfData &context)
|
2012-06-06 16:08:59 +02:00
|
|
|
{
|
2012-06-08 17:16:27 +02:00
|
|
|
return getAddress(s, context);
|
2012-06-06 16:08:59 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
static void parseSectionHeader(const uchar *s, ElfSectionHeader *sh, const ElfData &context)
|
2012-06-06 16:08:59 +02:00
|
|
|
{
|
2012-06-08 17:16:27 +02:00
|
|
|
sh->index = getWord(s, context);
|
|
|
|
|
sh->type = getWord(s, context);
|
2012-06-08 17:27:37 +02:00
|
|
|
sh->flags = getOffset(s, context);
|
2012-06-08 17:16:27 +02:00
|
|
|
sh->addr = getAddress(s, context);
|
|
|
|
|
sh->offset = getOffset(s, context);
|
|
|
|
|
sh->size = getOffset(s, context);
|
|
|
|
|
}
|
2012-06-06 16:08:59 +02:00
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
static void parseProgramHeader(const uchar *s, ElfProgramHeader *sh, const ElfData &context)
|
2012-06-06 16:08:59 +02:00
|
|
|
{
|
2012-06-08 17:16:27 +02:00
|
|
|
sh->type = getWord(s, context);
|
|
|
|
|
sh->offset = getOffset(s, context);
|
|
|
|
|
/* p_vaddr = */ getAddress(s, context);
|
|
|
|
|
/* p_paddr = */ getAddress(s, context);
|
|
|
|
|
sh->filesz = getWord(s, context);
|
|
|
|
|
sh->memsz = getWord(s, context);
|
2012-06-06 16:08:59 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-05 19:55:32 +02:00
|
|
|
class ElfMapper
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ElfMapper(const ElfReader *reader) : file(reader->m_binary) {}
|
|
|
|
|
|
|
|
|
|
bool map()
|
|
|
|
|
{
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
fdlen = file.size();
|
2012-06-08 14:40:18 +02:00
|
|
|
ustart = file.map(0, fdlen);
|
|
|
|
|
if (ustart == 0) {
|
2012-06-05 19:55:32 +02:00
|
|
|
// Try reading the data into memory instead.
|
|
|
|
|
raw = file.readAll();
|
2012-06-08 14:40:18 +02:00
|
|
|
start = raw.constData();
|
2012-06-05 19:55:32 +02:00
|
|
|
fdlen = raw.size();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
QFile file;
|
|
|
|
|
QByteArray raw;
|
2012-06-08 14:40:18 +02:00
|
|
|
union { const char *start; const uchar *ustart; };
|
2012-06-05 19:55:32 +02:00
|
|
|
quint64 fdlen;
|
|
|
|
|
};
|
|
|
|
|
|
2012-06-01 12:52:16 +02:00
|
|
|
ElfReader::ElfReader(const QString &binary)
|
|
|
|
|
: m_binary(binary)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
ElfData ElfReader::readHeaders()
|
2012-06-01 12:52:16 +02:00
|
|
|
{
|
2012-06-06 16:08:59 +02:00
|
|
|
readIt();
|
|
|
|
|
return m_elfData;
|
2012-06-01 12:52:16 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-30 17:31:06 +02:00
|
|
|
static inline QString msgInvalidElfObject(const QString &binary, const QString &why)
|
|
|
|
|
{
|
2014-04-17 14:09:47 +02:00
|
|
|
return ElfReader::tr("\"%1\" is an invalid ELF object (%2)")
|
2012-07-30 17:31:06 +02:00
|
|
|
.arg(QDir::toNativeSeparators(binary), why);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-05 19:55:32 +02:00
|
|
|
ElfReader::Result ElfReader::readIt()
|
2012-06-01 12:52:16 +02:00
|
|
|
{
|
2012-06-06 16:08:59 +02:00
|
|
|
if (!m_elfData.sectionHeaders.isEmpty())
|
|
|
|
|
return Ok;
|
|
|
|
|
if (!m_elfData.programHeaders.isEmpty())
|
|
|
|
|
return Ok;
|
|
|
|
|
|
2012-06-05 19:55:32 +02:00
|
|
|
ElfMapper mapper(this);
|
|
|
|
|
if (!mapper.map())
|
|
|
|
|
return Corrupt;
|
|
|
|
|
|
|
|
|
|
const quint64 fdlen = mapper.fdlen;
|
|
|
|
|
|
2012-06-01 12:52:16 +02:00
|
|
|
if (fdlen < 64) {
|
2014-04-17 14:09:47 +02:00
|
|
|
m_errorString = tr("\"%1\" is not an ELF object (file too small)").arg(QDir::toNativeSeparators(m_binary));
|
2012-06-01 12:52:16 +02:00
|
|
|
return NotElf;
|
|
|
|
|
}
|
2012-06-05 19:55:32 +02:00
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
if (strncmp(mapper.start, "\177ELF", 4) != 0) {
|
2014-04-17 14:09:47 +02:00
|
|
|
m_errorString = tr("\"%1\" is not an ELF object").arg(QDir::toNativeSeparators(m_binary));
|
2012-06-01 12:52:16 +02:00
|
|
|
return NotElf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 32 or 64 bit
|
2012-06-08 17:16:27 +02:00
|
|
|
m_elfData.elfclass = ElfClass(mapper.start[4]);
|
|
|
|
|
const bool is64Bit = m_elfData.elfclass == Elf_ELFCLASS64;
|
|
|
|
|
if (m_elfData.elfclass != Elf_ELFCLASS32 && m_elfData.elfclass != Elf_ELFCLASS64) {
|
2012-07-30 17:31:06 +02:00
|
|
|
m_errorString = msgInvalidElfObject(m_binary, tr("odd cpu architecture"));
|
2012-06-01 12:52:16 +02:00
|
|
|
return Corrupt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// int bits = (data[4] << 5);
|
|
|
|
|
// If you remove this check to read ELF objects of a different arch,
|
|
|
|
|
// please make sure you modify the typedefs
|
|
|
|
|
// to match the _plugin_ architecture.
|
|
|
|
|
// if ((sizeof(void*) == 4 && bits != 32)
|
|
|
|
|
// || (sizeof(void*) == 8 && bits != 64)) {
|
|
|
|
|
// if (errorString)
|
2014-04-17 14:09:47 +02:00
|
|
|
// *errorString = QLibrary::tr("\"%1\" is an invalid ELF object (%2)")
|
2012-06-01 12:52:16 +02:00
|
|
|
// .arg(m_binary).arg(QLatin1String("wrong cpu architecture"));
|
|
|
|
|
// return Corrupt;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// Read Endianess.
|
2012-06-08 17:16:27 +02:00
|
|
|
m_elfData.endian = ElfEndian(mapper.ustart[5]);
|
|
|
|
|
if (m_elfData.endian != Elf_ELFDATA2LSB && m_elfData.endian != Elf_ELFDATA2MSB) {
|
2013-01-29 15:12:14 +01:00
|
|
|
m_errorString = msgInvalidElfObject(m_binary, tr("odd endianness"));
|
2012-06-01 12:52:16 +02:00
|
|
|
return Corrupt;
|
|
|
|
|
}
|
2012-06-08 14:40:18 +02:00
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
const uchar *data = mapper.ustart + 16; // e_ident
|
|
|
|
|
m_elfData.elftype = ElfType(getHalfWord(data, m_elfData));
|
|
|
|
|
m_elfData.elfmachine = ElfMachine(getHalfWord(data, m_elfData));
|
|
|
|
|
/* e_version = */ getWord(data, m_elfData);
|
|
|
|
|
m_elfData.entryPoint = getAddress(data, m_elfData);
|
2012-06-08 14:40:18 +02:00
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
quint64 e_phoff = getOffset(data, m_elfData);
|
|
|
|
|
quint64 e_shoff = getOffset(data, m_elfData);
|
|
|
|
|
/* e_flags = */ getWord(data, m_elfData);
|
2012-06-01 12:52:16 +02:00
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
quint32 e_shsize = getHalfWord(data, m_elfData);
|
2012-06-01 12:52:16 +02:00
|
|
|
|
|
|
|
|
if (e_shsize > fdlen) {
|
2012-07-30 17:31:06 +02:00
|
|
|
m_errorString = msgInvalidElfObject(m_binary, tr("unexpected e_shsize"));
|
2012-06-01 12:52:16 +02:00
|
|
|
return Corrupt;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
quint32 e_phentsize = getHalfWord(data, m_elfData);
|
2012-06-11 14:57:46 +02:00
|
|
|
QTC_CHECK(e_phentsize == (is64Bit ? 56 : 32));
|
2012-06-08 17:16:27 +02:00
|
|
|
quint32 e_phnum = getHalfWord(data, m_elfData);
|
2012-06-06 16:08:59 +02:00
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
quint32 e_shentsize = getHalfWord(data, m_elfData);
|
2012-06-01 12:52:16 +02:00
|
|
|
|
|
|
|
|
if (e_shentsize % 4) {
|
2012-07-30 17:31:06 +02:00
|
|
|
m_errorString = msgInvalidElfObject(m_binary, tr("unexpected e_shentsize"));
|
2012-06-01 12:52:16 +02:00
|
|
|
return Corrupt;
|
|
|
|
|
}
|
2012-06-06 16:08:59 +02:00
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
quint32 e_shnum = getHalfWord(data, m_elfData);
|
|
|
|
|
quint32 e_shtrndx = getHalfWord(data, m_elfData);
|
2012-06-11 14:57:46 +02:00
|
|
|
QTC_CHECK(data == mapper.ustart + (is64Bit ? 64 : 52));
|
2012-06-01 12:52:16 +02:00
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
if (quint64(e_shnum) * e_shentsize > fdlen) {
|
2012-07-31 16:26:10 +02:00
|
|
|
const QString reason = tr("announced %n sections, each %1 bytes, exceed file size", 0, e_shnum)
|
|
|
|
|
.arg(e_shentsize);
|
2012-07-30 17:31:06 +02:00
|
|
|
m_errorString = msgInvalidElfObject(m_binary, reason);
|
2012-06-01 12:52:16 +02:00
|
|
|
return Corrupt;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
quint64 soff = e_shoff + e_shentsize * e_shtrndx;
|
2012-06-01 12:52:16 +02:00
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
// if ((soff + e_shentsize) > fdlen || soff % 4 || soff == 0) {
|
2014-04-17 14:09:47 +02:00
|
|
|
// m_errorString = QLibrary::tr("\"%1\" is an invalid ELF object (%2)")
|
2012-06-06 16:08:59 +02:00
|
|
|
// .arg(m_binary)
|
|
|
|
|
// .arg(QLatin1String("shstrtab section header seems to be at %1"))
|
|
|
|
|
// .arg(QString::number(soff, 16));
|
|
|
|
|
// return Corrupt;
|
|
|
|
|
// }
|
2012-06-01 12:52:16 +02:00
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
if (e_shoff) {
|
2012-06-08 17:16:27 +02:00
|
|
|
ElfSectionHeader strtab;
|
|
|
|
|
parseSectionHeader(mapper.ustart + soff, &strtab, m_elfData);
|
|
|
|
|
const quint64 stringTableFileOffset = strtab.offset;
|
2012-06-01 12:52:16 +02:00
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
if (quint32(stringTableFileOffset + e_shentsize) >= fdlen
|
|
|
|
|
|| stringTableFileOffset == 0) {
|
2012-07-30 17:31:06 +02:00
|
|
|
const QString reason = tr("string table seems to be at 0x%1").arg(soff, 0, 16);
|
|
|
|
|
m_errorString = msgInvalidElfObject(m_binary, reason);
|
2012-06-01 12:52:16 +02:00
|
|
|
return Corrupt;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 15:39:45 +02:00
|
|
|
for (quint32 i = 0; i < e_shnum; ++i) {
|
2012-06-08 17:16:27 +02:00
|
|
|
const uchar *s = mapper.ustart + e_shoff + i * e_shentsize;
|
|
|
|
|
ElfSectionHeader sh;
|
|
|
|
|
parseSectionHeader(s, &sh, m_elfData);
|
2012-06-06 16:08:59 +02:00
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
if (stringTableFileOffset + sh.index > fdlen) {
|
2012-07-30 17:31:06 +02:00
|
|
|
const QString reason = tr("section name %1 of %2 behind end of file")
|
|
|
|
|
.arg(i).arg(e_shnum);
|
|
|
|
|
m_errorString = msgInvalidElfObject(m_binary, reason);
|
2012-06-06 16:08:59 +02:00
|
|
|
return Corrupt;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
sh.name = mapper.start + stringTableFileOffset + sh.index;
|
|
|
|
|
if (sh.name == ".gdb_index") {
|
2012-06-06 16:08:59 +02:00
|
|
|
m_elfData.symbolsType = FastSymbols;
|
2012-06-08 17:16:27 +02:00
|
|
|
} else if (sh.name == ".debug_info") {
|
2012-06-06 16:08:59 +02:00
|
|
|
m_elfData.symbolsType = PlainSymbols;
|
2012-06-08 17:16:27 +02:00
|
|
|
} else if (sh.name == ".gnu_debuglink") {
|
|
|
|
|
m_elfData.debugLink = QByteArray(mapper.start + sh.offset);
|
2012-06-06 16:08:59 +02:00
|
|
|
m_elfData.symbolsType = LinkedSymbols;
|
2012-06-08 17:16:27 +02:00
|
|
|
} else if (sh.name == ".note.gnu.build-id") {
|
2012-06-06 16:08:59 +02:00
|
|
|
m_elfData.symbolsType = BuildIdSymbols;
|
2012-06-08 17:16:27 +02:00
|
|
|
if (sh.size > 16)
|
|
|
|
|
m_elfData.buildId = QByteArray(mapper.start + sh.offset + 16,
|
|
|
|
|
sh.size - 16).toHex();
|
2012-06-06 16:08:59 +02:00
|
|
|
}
|
2012-06-08 17:16:27 +02:00
|
|
|
m_elfData.sectionHeaders.append(sh);
|
2012-06-06 16:08:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e_phoff) {
|
2012-06-12 15:39:45 +02:00
|
|
|
for (quint32 i = 0; i < e_phnum; ++i) {
|
2012-06-08 17:16:27 +02:00
|
|
|
const uchar *s = mapper.ustart + e_phoff + i * e_phentsize;
|
|
|
|
|
ElfProgramHeader ph;
|
|
|
|
|
parseProgramHeader(s, &ph, m_elfData);
|
|
|
|
|
m_elfData.programHeaders.append(ph);
|
2012-06-06 16:08:59 +02:00
|
|
|
}
|
2012-06-01 12:52:16 +02:00
|
|
|
}
|
|
|
|
|
return Ok;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-05 19:55:32 +02:00
|
|
|
QByteArray ElfReader::readSection(const QByteArray &name)
|
2012-06-01 12:52:16 +02:00
|
|
|
{
|
2012-06-06 16:08:59 +02:00
|
|
|
readIt();
|
|
|
|
|
int i = m_elfData.indexOf(name);
|
2012-06-05 19:55:32 +02:00
|
|
|
if (i == -1)
|
2012-06-06 16:08:59 +02:00
|
|
|
return QByteArray();
|
|
|
|
|
|
|
|
|
|
ElfMapper mapper(this);
|
|
|
|
|
if (!mapper.map())
|
|
|
|
|
return QByteArray();
|
|
|
|
|
|
|
|
|
|
const ElfSectionHeader §ion = m_elfData.sectionHeaders.at(i);
|
2012-06-08 17:16:27 +02:00
|
|
|
return QByteArray(mapper.start + section.offset, section.size);
|
2012-06-06 16:08:59 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-15 13:54:59 +02:00
|
|
|
static QByteArray cutout(const char *s)
|
|
|
|
|
{
|
|
|
|
|
QByteArray res(s, 80);
|
|
|
|
|
const int pos = res.indexOf('\0');
|
|
|
|
|
if (pos != -1)
|
|
|
|
|
res.resize(pos - 1);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 14:40:18 +02:00
|
|
|
QByteArray ElfReader::readCoreName(bool *isCore)
|
2012-06-06 16:08:59 +02:00
|
|
|
{
|
2012-06-08 14:40:18 +02:00
|
|
|
*isCore = false;
|
|
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
readIt();
|
2012-06-01 12:52:16 +02:00
|
|
|
|
2012-06-05 19:55:32 +02:00
|
|
|
ElfMapper mapper(this);
|
|
|
|
|
if (!mapper.map())
|
2012-06-06 16:08:59 +02:00
|
|
|
return QByteArray();
|
2012-06-01 12:52:16 +02:00
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
if (m_elfData.elftype != Elf_ET_CORE)
|
2012-06-08 14:40:18 +02:00
|
|
|
return QByteArray();
|
|
|
|
|
|
2012-06-08 17:16:27 +02:00
|
|
|
*isCore = true;
|
|
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
for (int i = 0, n = m_elfData.sectionHeaders.size(); i != n; ++i)
|
2012-06-08 17:16:27 +02:00
|
|
|
if (m_elfData.sectionHeaders.at(i).type == Elf_SHT_NOTE) {
|
2012-06-06 16:08:59 +02:00
|
|
|
const ElfSectionHeader &header = m_elfData.sectionHeaders.at(i);
|
2012-08-15 13:54:59 +02:00
|
|
|
return cutout(mapper.start + header.offset + 0x40);
|
2012-06-06 16:08:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0, n = m_elfData.programHeaders.size(); i != n; ++i)
|
2012-06-08 14:40:18 +02:00
|
|
|
if (m_elfData.programHeaders.at(i).type == Elf_PT_NOTE) {
|
2012-06-06 16:08:59 +02:00
|
|
|
const ElfProgramHeader &header = m_elfData.programHeaders.at(i);
|
2012-08-15 13:54:59 +02:00
|
|
|
return cutout(mapper.start + header.offset + 0xec);
|
2012-06-06 16:08:59 +02:00
|
|
|
}
|
2012-06-01 12:52:16 +02:00
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
return QByteArray();
|
2012-06-05 19:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
int ElfData::indexOf(const QByteArray &name) const
|
2012-06-05 19:55:32 +02:00
|
|
|
{
|
2012-06-06 16:08:59 +02:00
|
|
|
for (int i = 0, n = sectionHeaders.size(); i != n; ++i)
|
|
|
|
|
if (sectionHeaders.at(i).name == name)
|
2012-06-05 19:55:32 +02:00
|
|
|
return i;
|
|
|
|
|
return -1;
|
2012-06-01 12:52:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Utils
|