diff --git a/src/common/common.pro b/src/common/common.pro --- a/src/common/common.pro +++ b/src/common/common.pro @@ -8,12 +8,12 @@ TARGET = socexplorercommon$${DEBUG_EXT} win32:CONFIG += dll win32:CONFIG -= static -win32:INCLUDEPATH += $${PWD}/elf/libelfWin32/include -win32:INCLUDEPATH += $${PWD}/elf/libelfWin32/include/libelf +win32:INCLUDEPATH += $${PWD}/genericBinaryFiles/elf/libelfWin32/include +win32:INCLUDEPATH += $${PWD}/genericBinaryFiles/elf/libelfWin32/include/libelf win32:DEFINES+=_ELF_WINDOWS_ DEFINES+=RS232_debug -win32:LIBS += $${PWD}/elf/libelfWin32/bin/libelf.a +win32:LIBS += $${PWD}/genericBinaryFiles/elf/libelfWin32/bin/libelf.a unix:LIBS += -lelf QMAKE_LFLAGS_RELEASE += --enable-auto-import @@ -35,33 +35,33 @@ header.files = \ QCustomPlot/qcustomplot.h \ SocExplorerPlot.h \ tcp_terminal_client.h \ - elf/elfinfowdgt.h \ - elf/elfparser.h \ - elf/elffile.h \ - elf/elffilewidget.h \ + genericBinaryFiles/elf/elfinfowdgt.h \ + genericBinaryFiles/elf/elfparser.h \ + genericBinaryFiles/elf/elffile.h \ + genericBinaryFiles/elf/elffilewidget.h \ qipdialogbox.h \ lppserial/src/RS232.h \ qtablewidgetintitem.h \ - srec/srecfile.h \ - srec/srecfilewidget.h \ - BinFile/binaryfile.h \ - BinFile/binaryfilewidget.h \ - abstractbinfile.h + genericBinaryFiles/srec/srecfile.h \ + genericBinaryFiles/srec/srecfilewidget.h \ + genericBinaryFiles/BinFile/binaryfile.h \ + genericBinaryFiles/BinFile/binaryfilewidget.h \ + genericBinaryFiles/abstractbinfile.h win32{ - elfheader.path = $$[QT_INSTALL_HEADERS]/SocExplorer/common/libelf + elfheader.path = $$[QT_INSTALL_HEADERS]/SocExplorer/common/genericBinaryFiles/libelf elfheader.files += \ - elf/libelfWin32/include/libelf/byteswap.h \ - elf/libelfWin32/include/libelf/errors.h \ - elf/libelfWin32/include/libelf/gelf.h \ - elf/libelfWin32/include/libelf/nlist.h \ - elf/libelfWin32/include/libelf/sys_elf.h \ - elf/libelfWin32/include/libelf/verneed.h \ - elf/libelfWin32/include/libelf/elf_repl.h \ - elf/libelfWin32/include/libelf/ext_types.h \ - elf/libelfWin32/include/libelf/libelf.h \ - elf/libelfWin32/include/libelf/private.h \ - elf/libelfWin32/include/libelf/verdef.h + genericBinaryFiles/elf/libelfWin32/include/libelf/byteswap.h \ + genericBinaryFiles/elf/libelfWin32/include/libelf/errors.h \ + genericBinaryFiles/elf/libelfWin32/include/libelf/gelf.h \ + genericBinaryFiles/elf/libelfWin32/include/libelf/nlist.h \ + genericBinaryFiles/elf/libelfWin32/include/libelf/sys_elf.h \ + genericBinaryFiles/elf/libelfWin32/include/libelf/verneed.h \ + genericBinaryFiles/elf/libelfWin32/include/libelf/elf_repl.h \ + genericBinaryFiles/elf/libelfWin32/include/libelf/ext_types.h \ + genericBinaryFiles/elf/libelfWin32/include/libelf/libelf.h \ + genericBinaryFiles/elf/libelfWin32/include/libelf/private.h \ + genericBinaryFiles/elf/libelfWin32/include/libelf/verdef.h INSTALLS += elfheader } @@ -72,7 +72,7 @@ isEmpty(header.path) { INSTALLS += target header -INCLUDEPATH += QCustomPlot qhexedit srec BinFile +INCLUDEPATH += QCustomPlot qhexedit genericBinaryFiles genericBinaryFiles/srec genericBinaryFiles/BinFile HEADERS += \ memsizewdgt.h \ @@ -84,19 +84,19 @@ HEADERS += \ qhexedit/commands.h \ QCustomPlot/qcustomplot.h \ tcp_terminal_client.h \ - elf/elfinfowdgt.h \ - elf/elfparser.h \ - elf/elffile.h \ + genericBinaryFiles/elf/elfinfowdgt.h \ + genericBinaryFiles/elf/elfparser.h \ + genericBinaryFiles/elf/elffile.h \ qipdialogbox.h \ PySocExplorer.h \ SocExplorerPlot.h \ - elf/elffilewidget.h \ + genericBinaryFiles/elf/elffilewidget.h \ qtablewidgetintitem.h \ - srec/srecfile.h \ - srec/srecfilewidget.h \ - abstractbinfile.h \ - BinFile/binaryfile.h \ - BinFile/binaryfilewidget.h + genericBinaryFiles/srec/srecfile.h \ + genericBinaryFiles/srec/srecfilewidget.h \ + genericBinaryFiles/abstractbinfile.h \ + genericBinaryFiles/BinFile/binaryfile.h \ + genericBinaryFiles/BinFile/binaryfilewidget.h SOURCES += \ @@ -109,23 +109,23 @@ SOURCES += \ qhexedit/commands.cpp \ QCustomPlot/qcustomplot.cpp \ tcp_terminal_client.cpp \ - elf/elfinfowdgt.cpp \ - elf/elfparser.cpp \ - elf/elffile.cpp \ + genericBinaryFiles/elf/elfinfowdgt.cpp \ + genericBinaryFiles/elf/elfparser.cpp \ + genericBinaryFiles/elf/elffile.cpp \ qipdialogbox.cpp \ SocExplorerPlot.cpp \ - elf/elffilewidget.cpp \ + genericBinaryFiles/elf/elffilewidget.cpp \ qtablewidgetintitem.cpp \ - srec/srecfile.cpp \ - srec/srecfilewidget.cpp \ - abstractbinfile.cpp \ - BinFile/binaryfile.cpp \ - BinFile/binaryfilewidget.cpp + genericBinaryFiles/srec/srecfile.cpp \ + genericBinaryFiles/srec/srecfilewidget.cpp \ + genericBinaryFiles/abstractbinfile.cpp \ + genericBinaryFiles/BinFile/binaryfile.cpp \ + genericBinaryFiles/BinFile/binaryfilewidget.cpp FORMS += \ - elf/elffilewidget.ui \ - srec/srecfilewidget.ui \ - BinFile/binaryfilewidget.ui + genericBinaryFiles/elf/elffilewidget.ui \ + genericBinaryFiles/srec/srecfilewidget.ui \ + genericBinaryFiles/BinFile/binaryfilewidget.ui OTHER_FILES += \ ./pythongenerator.sh \ diff --git a/src/common/genericBinaryFiles/abstractbinfile.cpp b/src/common/genericBinaryFiles/abstractbinfile.cpp new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/abstractbinfile.cpp @@ -0,0 +1,30 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#include "abstractbinfile.h" + + +codeFragment::codeFragment() +{ + data = NULL; + size = 0; + address = 0; +} diff --git a/src/common/genericBinaryFiles/abstractbinfile.h b/src/common/genericBinaryFiles/abstractbinfile.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/abstractbinfile.h @@ -0,0 +1,71 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#ifndef ABSTRACTBINFILE_H +#define ABSTRACTBINFILE_H + +#include +#include + +class codeFragment +{ +public: + codeFragment(); + codeFragment(char* data, quint64 size, quint64 address):data(data),size(size),address(address){} + ~codeFragment() + { + free(data); + } + QString header; + char* data; + quint64 size; + quint64 address; +}; + +class abstractBinFile : public QObject +{ + Q_OBJECT +public: + + virtual bool openFile(const QString& File)=0; + virtual bool isopened()=0; + virtual int closeFile()=0; + virtual QList getFragments()=0; + virtual bool toSrec(const QString& File)=0; + virtual bool toBinary(const QString& File)=0; +protected: + QString p_fileName; +}; + + +class abstractBinFileWidget : public QWidget +{ + Q_OBJECT + +public: + abstractBinFileWidget(QWidget* parent = 0):QWidget(parent){} + +public slots: + virtual void setFile(abstractBinFile* file)=0; + virtual void reloadFile()=0; +}; + +#endif // ABSTRACTBINFILE_H diff --git a/src/common/genericBinaryFiles/elf/elffile.cpp b/src/common/genericBinaryFiles/elf/elffile.cpp new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/elffile.cpp @@ -0,0 +1,1075 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : + Alexis Jeandet +-- Mail : + alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#include "elffile.h" +#include "srecfile.h" +#include "binaryfile.h" +#include + +ElfFile::ElfFile() + :abstractBinFile() +{ + this->opened = false; + this->type_elf = false; + this->elfFile = (int)NULL; + this->e = NULL; +} + +ElfFile::ElfFile(const QString &File) + :abstractBinFile() +{ + this->opened = false; + this->type_elf = false; + this->elfFile = (int)NULL; + this->e = NULL; + this->p_fileName = File; + openFile(File); +} + +ElfFile::~ElfFile() +{ + closeFile(); + if(scn)free(scn); + if(data)free(data); + for(int i=0;isections.count();i++) + { + delete this->sections.at(i); + } + this->sections.clear(); + for(int i=0;iSegments.count();i++) + { + free(this->Segments.at(i)); + } + this->Segments.clear(); + for(int i=0;isymbols.at(i); + } + this->symbols.clear(); +} + +bool ElfFile::openFile(const QString &File) +{ + this->p_fileName = File; + this->closeFile(); + if(elf_version(EV_CURRENT)==EV_NONE)return 0; +#ifdef _ELF_WINDOWS_ + this->elfFile = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0); +#else + this->elfFile = open(File.toStdString().c_str(),O_RDONLY ,0); +#endif + if(this->elfFile==(int)NULL)return 0; + this->e = elf_begin(this->elfFile,ELF_C_READ,NULL); + if(this->e==NULL)return 0; + this->ek = elf_kind(this->e); + gelf_getehdr (this->e, &this->ehdr ); + elf_getshdrstrndx (this->e, &this->shstrndx); + this->updateSegments(); + this->updateSections(); + this->updateSymbols(); + this->opened = true; + return 1; +} + +bool ElfFile::isopened() +{ + return this->opened; +} + +int ElfFile::closeFile() +{ + if(this->elfFile!=(int)NULL) + { + if(this->e!=NULL) + { + elf_end(this->e); + this->e = NULL; + } + close(this->elfFile); + this->elfFile = (int)NULL; + } + this->opened = false; + return 0; +} + + +QList ElfFile::getFragments(QStringList fragmentList) +{ + QList fragments; + if (isopened()) + { + for(int i =0;i ElfFile::getFragments() +{ + return getFragments(QStringList()<<".data"<<".text"); +} + +codeFragment *ElfFile::getFragment(const QString &name) +{ + codeFragment* fragment= new codeFragment(); + for(int i=0;idata =NULL; + fragment->size = getSectionDatasz(i); + fragment->address = getSectionPaddr(i); + getSectionData(i,&fragment->data); + } + } + return fragment; +} + + + + + + + +QString elfresolveMachine(Elf64_Half e_machine) +{ + QString machineName; + //Update from with bash script don't write it by yourself! + switch(e_machine) + { + case EM_NONE: + machineName = " No machine "; + break; + case EM_M32: + machineName = " AT&T WE 32100 "; + break; + case EM_SPARC: + machineName = " SUN SPARC "; + break; + case EM_386: + machineName = " Intel 80386 "; + break; + case EM_68K: + machineName = " Motorola m68k family "; + break; + case EM_88K: + machineName = " Motorola m88k family "; + break; + case EM_860: + machineName = " Intel 80860 "; + break; + case EM_MIPS: + machineName = " MIPS R3000 big-endian "; + break; + case EM_S370: + machineName = " IBM System/370 "; + break; + case EM_MIPS_RS3_LE: + machineName = " MIPS R3000 little-endian "; + break; + case EM_PARISC: + machineName = " HPPA "; + break; + case EM_VPP500: + machineName = " Fujitsu VPP500 "; + break; + case EM_SPARC32PLUS: + machineName = " Sun's \"v8plus\" "; + break; + case EM_960: + machineName = " Intel 80960 "; + break; + case EM_PPC: + machineName = " PowerPC "; + break; + case EM_PPC64: + machineName = " PowerPC 64-bit "; + break; + case EM_S390: + machineName = " IBM S390 "; + break; + case EM_V800: + machineName = " NEC V800 series "; + break; + case EM_FR20: + machineName = " Fujitsu FR20 "; + break; + case EM_RH32: + machineName = " TRW RH-32 "; + break; + case EM_RCE: + machineName = " Motorola RCE "; + break; + case EM_ARM: + machineName = " ARM "; + break; + case EM_FAKE_ALPHA: + machineName = " Digital Alpha "; + break; + case EM_SH: + machineName = " Hitachi SH "; + break; + case EM_SPARCV9: + machineName = " SPARC v9 64-bit "; + break; + case EM_TRICORE: + machineName = " Siemens Tricore "; + break; + case EM_ARC: + machineName = " Argonaut RISC Core "; + break; + case EM_H8_300: + machineName = " Hitachi H8/300 "; + break; + case EM_H8_300H: + machineName = " Hitachi H8/300H "; + break; + case EM_H8S: + machineName = " Hitachi H8S "; + break; + case EM_H8_500: + machineName = " Hitachi H8/500 "; + break; + case EM_IA_64: + machineName = " Intel Merced "; + break; + case EM_MIPS_X: + machineName = " Stanford MIPS-X "; + break; + case EM_COLDFIRE: + machineName = " Motorola Coldfire "; + break; + case EM_68HC12: + machineName = " Motorola M68HC12 "; + break; + case EM_MMA: + machineName = " Fujitsu MMA Multimedia Accelerator"; + break; + case EM_PCP: + machineName = " Siemens PCP "; + break; + case EM_NCPU: + machineName = " Sony nCPU embeeded RISC "; + break; + case EM_NDR1: + machineName = " Denso NDR1 microprocessor "; + break; + case EM_STARCORE: + machineName = " Motorola Start*Core processor "; + break; + case EM_ME16: + machineName = " Toyota ME16 processor "; + break; + case EM_ST100: + machineName = " STMicroelectronic ST100 processor "; + break; + case EM_TINYJ: + machineName = " Advanced Logic Corp. Tinyj emb.fam"; + break; + case EM_X86_64: + machineName = " AMD x86-64 architecture "; + break; + case EM_PDSP: + machineName = " Sony DSP Processor "; + break; + case EM_FX66: + machineName = " Siemens FX66 microcontroller "; + break; + case EM_ST9PLUS: + machineName = " STMicroelectronics ST9+ 8/16 mc "; + break; + case EM_ST7: + machineName = " STmicroelectronics ST7 8 bit mc "; + break; + case EM_68HC16: + machineName = " Motorola MC68HC16 microcontroller "; + break; + case EM_68HC11: + machineName = " Motorola MC68HC11 microcontroller "; + break; + case EM_68HC08: + machineName = " Motorola MC68HC08 microcontroller "; + break; + case EM_68HC05: + machineName = " Motorola MC68HC05 microcontroller "; + break; + case EM_SVX: + machineName = " Silicon Graphics SVx "; + break; + case EM_ST19: + machineName = " STMicroelectronics ST19 8 bit mc "; + break; + case EM_VAX: + machineName = " Digital VAX "; + break; + case EM_CRIS: + machineName = " Axis Communications 32-bit embedded processor "; + break; + case EM_JAVELIN: + machineName = " Infineon Technologies 32-bit embedded processor "; + break; + case EM_FIREPATH: + machineName = " Element 14 64-bit DSP Processor "; + break; + case EM_ZSP: + machineName = " LSI Logic 16-bit DSP Processor "; + break; + case EM_MMIX: + machineName = " Donald Knuth's educational 64-bit processor "; + break; + case EM_HUANY: + machineName = " Harvard University machine-independent object files "; + break; + case EM_PRISM: + machineName = " SiTera Prism "; + break; + case EM_AVR: + machineName = " Atmel AVR 8-bit microcontroller "; + break; + case EM_FR30: + machineName = " Fujitsu FR30 "; + break; + case EM_D10V: + machineName = " Mitsubishi D10V "; + break; + case EM_D30V: + machineName = " Mitsubishi D30V "; + break; + case EM_V850: + machineName = " NEC v850 "; + break; + case EM_M32R: + machineName = " Mitsubishi M32R "; + break; + case EM_MN10300: + machineName = " Matsushita MN10300 "; + break; + case EM_MN10200: + machineName = " Matsushita MN10200 "; + break; + case EM_PJ: + machineName = " picoJava "; + break; + case EM_OPENRISC: + machineName = " OpenRISC 32-bit embedded processor "; + break; + case EM_ARC_A5: + machineName = " ARC Cores Tangent-A5 "; + break; + case EM_XTENSA: + machineName = " Tensilica Xtensa Architecture "; + break; + case EM_AARCH64: + machineName = " ARM AARCH64 "; + break; + case EM_TILEPRO: + machineName = " Tilera TILEPro "; + break; + case EM_MICROBLAZE: + machineName = " Xilinx MicroBlaze "; + break; + case EM_TILEGX: + machineName = " Tilera TILE-Gx "; + break; + case EM_NUM: + machineName = ""; + break; + default: + machineName ="Unknow Machine"; + break; + } + return machineName; +} + + + + +QString ElfFile::getClass() +{ + if(this->e!=NULL) + { + int eclass = gelf_getclass(this->e); + if(eclass==ELFCLASS32)return "ELF32"; + if(eclass==ELFCLASS64)return "ELF64"; + } + return "none"; +} + + +bool ElfFile::iself() +{ + return (this->getType()!="Unknow"); +} + +QString ElfFile::getArchitecture() +{ + if(this->e!=NULL) + { + return elfresolveMachine(this->ehdr.e_machine); + } + return ""; +} + + +QString ElfFile::getType() +{ + QString kind(""); + if(this->e!=NULL) + { + switch(this->ek) + { + case ELF_K_AR: + kind = "Archive"; + break; + case ELF_K_ELF: + kind = "Elf"; + break; + case ELF_K_COFF: + kind = "COFF"; + break; + case ELF_K_NUM: + kind = "NUM"; + break; + case ELF_K_NONE: + kind = "Data"; + break; + default: + kind = "Unknow"; + break; + } + } + return kind; +} + +QString ElfFile::getEndianness() +{ + if(this->e!=NULL) + { + if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return "2's complement, little endian"; + if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return "2's complement, big endian"; + } + return "none"; +} + +QString ElfFile::getABI() +{ + if(this->e!=NULL) + { + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NONE)return "UNIX System V ABI"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SYSV)return "Alias"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_HPUX)return "HP-UX"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NETBSD)return "NetBSD"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_LINUX)return "Object uses GNU ELF extensions"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SOLARIS)return "Sun Solaris"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_AIX)return "IBM AIX"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_IRIX)return "SGI Irix"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_FREEBSD)return "FreeBSD"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_TRU64)return "Compaq TRU64 UNIX"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_MODESTO)return " Novell Modesto"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_OPENBSD)return "OpenBSD"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM_AEABI)return "ARM EABI"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM)return "ARM"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_STANDALONE)return "Standalone (embedded) application"; + } + return "none"; +} + + +qint64 ElfFile::getVersion() +{ + if(this->e!=NULL) + { + return this->ehdr.e_version; + } + return -1; +} + +qint64 ElfFile::getEntryPointAddress() +{ + if(this->e!=NULL) + { + return this->ehdr.e_entry; + } + return -1; +} + + +int ElfFile::getSectionCount() +{ + return (int)this->SectionCount; +} + +int ElfFile::getSymbolCount() +{ + return (int)this->SymbolCount; +} + + +int ElfFile::getSegmentCount() +{ + return (int)this->SegmentCount; +} + + +QString ElfFile::getSegmentType(int index) +{ + QString type(""); + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + switch(this->Segments.at(index)->p_type) + { + case PT_NULL: + type = "Program header table entry unused"; + break; + case PT_LOAD: + type = "Loadable program segment"; + break; + case PT_DYNAMIC : + type = "Dynamic linking information"; + break; + case PT_INTERP: + type ="Program interpreter"; + break; + case PT_NOTE: + type = "Auxiliary information"; + break; + case PT_SHLIB: + type = "Reserved"; + break; + case PT_PHDR: + type = "Entry for header table itself"; + break; + case PT_TLS: + type = "Thread-local storage segment"; + break; + case PT_NUM: + type = "Number of defined types"; + break; + case PT_LOOS: + type = "Start of OS-specific"; + break; + case PT_SUNWSTACK: + type = "Stack segment"; + break; + case PT_LOPROC: + type = "Start of processor-specific"; + break; + case PT_HIPROC: + type = "End of processor-specific"; + break; + default: + type = "Unknow Section Type"; + break; + } + } + } + + return type; +} + + +qint64 ElfFile::getSegmentOffset(int index) +{ + qint64 Offset = -1; + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + Offset = (qint64)this->Segments.at(index)->p_offset; + } + } + return Offset; +} + + +qint64 ElfFile::getSegmentVaddr(int index) +{ + int64_t Vaddr = 0; + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + Vaddr = (int64_t)this->Segments.at(index)->p_vaddr; + } + } + return Vaddr; +} + + +qint64 ElfFile::getSegmentPaddr(int index) +{ + int64_t Paddr=0; + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + Paddr = (int64_t)this->Segments.at(index)->p_paddr; + } + } + return Paddr; +} + +qint64 ElfFile::getSectionPaddr(int index) +{ + int64_t Paddr=0; + if(this->e!=NULL) + { + if(index < this->sections.count()) + { + Paddr = (int64_t)this->sections.at(index)->section_header->sh_addr; + } + } + return Paddr; +} + + +qint64 ElfFile::getSegmentFilesz(int index) +{ + int64_t FileSz=0; + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + FileSz = (int64_t)this->Segments.at(index)->p_filesz; + } + } + return FileSz; +} + +qint64 ElfFile::getSectionDatasz(int index) +{ + int64_t DataSz=0; + if(this->e!=NULL) + { + if(index < this->sections.count()) + { + if(this->sections.at(index)->section_header->sh_type==SHT_NOBITS) + { + DataSz=0; + } + else + { + DataSz = (int64_t)this->sections.at(index)->data->d_size; + } + } + } + return DataSz; +} + +bool ElfFile::getSectionData(int index, char **buffer) +{ + if(this->e!=NULL) + { + if(index < this->sections.count()) + { + *buffer = (char *)malloc(this->sections.at(index)->data->d_size); + memcpy(*buffer,this->sections.at(index)->data->d_buf,this->sections.at(index)->data->d_size); + return true; + } + } + return false; +} + + +qint64 ElfFile::getSegmentMemsz(int index) +{ + int64_t MemSz=0; + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + MemSz = (int64_t)this->Segments.at(index)->p_memsz; + } + } + return MemSz; +} + +qint64 ElfFile::getSectionMemsz(int index) +{ + int64_t MemSz=0; + if(this->e!=NULL) + { + if(index < this->sections.count()) + { + MemSz = (int64_t)this->sections.at(index)->section_header->sh_size; + } + } + return MemSz; +} + + +QString ElfFile::getSegmentFlags(int index) +{ + QString flags(""); + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + if((this->Segments.at(index)->p_flags&PF_X) == PF_X)flags+="x"; + if((this->Segments.at(index)->p_flags&PF_W) == PF_W)flags+="w"; + if((this->Segments.at(index)->p_flags&PF_R) == PF_R)flags+="r"; + if((this->Segments.at(index)->p_flags&PF_MASKOS) == PF_MASKOS)flags+=" OS-specific"; + if((this->Segments.at(index)->p_flags&PF_MASKPROC) == PF_MASKPROC)flags+=" Processor-specific"; + } + } + return flags; +} + + +QString ElfFile::getSectionName(int index) +{ + if((index=0)) + { + char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name); + return QString(nameChr); + } + return ""; +} + + +void ElfFile::updateSections() +{ + for(int i=0;isections.count();i++) + { + delete this->sections.at(i); + } + this->sections.clear(); + this->scn = elf_nextscn (this->e , NULL ); + this->SectionCount = 0; + while( this->scn != NULL ) + { + GElf_Shdr* shdr = (GElf_Shdr*)malloc(sizeof(GElf_Shdr)); + gelf_getshdr ( this->scn , shdr ); + Elf_Data* data = elf_getdata(this->scn, NULL); + this->sections.append(new Elf_Section(data,shdr)); + this->SectionCount+=1; + this->scn = elf_nextscn(e , scn); + } +} + + +void ElfFile::updateSegments() +{ + elf_getphdrnum (this->e , &this->SegmentCount); + for(int i=0;iSegments.count();i++) + { + free(this->Segments.at(i)); + } + this->Segments.clear(); + for(int i=0;i<(int)this->SegmentCount;i++) + { + GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr)); + gelf_getphdr (this->e , i , header ); + this->Segments.append(header); + } +} + +void ElfFile::updateSymbols() +{ + for(int i=0;isymbols.at(i); + } + this->symbols.clear(); + updateSections(); //Useless in most case but safer to do it + for(int i=0;i<(int)SectionCount;i++) + { + //First find Symbol table + if(this->getSectionName(i)==".symtab") + { + Elf_Section* sec = sections.at(i); + this->SymbolCount = sec->section_header->sh_size / sec->section_header->sh_entsize; + //Then list all symbols + for(int j=0;j<(int)this->SymbolCount;j++) + { + GElf_Sym* esym = (GElf_Sym*)malloc(sizeof(GElf_Sym)); + gelf_getsym(sec->data, j, esym); + QString name = elf_strptr(this->e,sec->section_header->sh_link,esym->st_name); + Elf_Symbol* sym = new Elf_Symbol(name,esym); + symbols.append(sym); + } + } + } + +} + + + +QString ElfFile::getSectionType(int index) +{ + QString type(""); + if(this->e!=NULL) + { + if(index < this->sections.count()) + { + switch(this->sections.at(index)->section_header->sh_type) + { + case SHT_NULL : type = "Section header table entry unused"; break; + case SHT_PROGBITS : type = "Program data"; break; + case SHT_SYMTAB : type = "Symbol table"; break; + case SHT_STRTAB : type = "String table"; break; + case SHT_RELA : type = "Relocation entries with addends"; break; + case SHT_HASH : type = "Symbol hash table"; break; + case SHT_DYNAMIC : type = "Dynamic linking information"; break; + case SHT_NOTE : type = "Notes"; break; + case SHT_NOBITS :type = "Program space with no data (bss)"; break; + case SHT_REL :type = "Relocation entries, no addends"; break; + case SHT_SHLIB : type = "Reserved"; break; + case SHT_DYNSYM : type = "Dynamic linker symbol table"; break; + case SHT_INIT_ARRAY : type = "Array of constructors"; break; + case SHT_FINI_ARRAY : type = "Array of destructors"; break; + case SHT_PREINIT_ARRAY : type = "Array of pre-constructors"; break; + case SHT_GROUP : type = "Section group"; break; + case SHT_SYMTAB_SHNDX : type = "Extended section indeces"; break; + case SHT_NUM : type = "Number of defined types. "; break; + case SHT_LOOS : type = "Start OS-specific. "; break; + case SHT_LOSUNW : type = "Sun-specific low bound. "; break; + case SHT_SUNW_COMDAT : type = " "; break; + case SHT_SUNW_syminfo : type = " "; break; + case SHT_GNU_verdef : type = "Version definition section. "; break; + case SHT_GNU_verneed : type = "Version needs section. "; break; + case SHT_GNU_versym : type = "Version symbol table. "; break; + case SHT_LOPROC : type = "Start of processor-specific"; break; + case SHT_HIPROC : type = "End of processor-specific"; break; + case SHT_HIUSER : type = "End of application-specific"; break; + } + } + } + return type; +} + +int ElfFile::getSectionIndex(QString name) +{ + if(this->e!=NULL) + { + for(int i=0;ie!=NULL) + { + if(index < this->sections.count()) + { + return this->sections.at(index)->section_header->sh_type== SHT_NOBITS; + } + } + return false; +} + +QString ElfFile::getSymbolName(int index) +{ + if(this->e!=NULL) + { + if(index < this->symbols.count()) + { + return symbols.at(index)->name; + } + } + return ""; +} + +QString ElfFile::getSymbolType(int index) +{ + if(this->e!=NULL) + { + if(index < this->symbols.count()) + { + int type = GELF_ST_TYPE(symbols.at(index)->sym->st_info); + switch(type) + { + case STT_NOTYPE: + return "No Type"; + break; + case STT_OBJECT: + return "Object"; + break; + case STT_FUNC: + return "Function"; + break; + case STT_SECTION: + return "Section"; + break; + case STT_FILE: + return "File"; + break; + case STT_COMMON: + return "Common data object"; + break; + case STT_TLS: + return "Thread-local data object"; + break; + case STT_NUM: + return "Number of defined types"; + break; + case STT_LOOS: + return "Start of OS-specific"; + break; + case STT_HIOS: + return "End of OS-specific"; + break; + case STT_LOPROC: + return "Start of processor-specific"; + break; + case STT_HIPROC: + return "End of processor-specific"; + break; + default: + return "none"; + break; + } + } + } + return "none"; +} + +quint64 ElfFile::getSymbolSize(int index) +{ + if(this->e!=NULL) + { + if((index < this->symbols.count()) && (index>=0)) + { + return symbols.at(index)->sym->st_size; + } + } + return 0; +} + +QString ElfFile::getSymbolSectionName(int index) +{ + if(this->e!=NULL) + { + if((index < this->symbols.count()) && (index>=0)) + { + return getSectionName(symbols.at(index)->sym->st_shndx-1); + } + } + return "none"; +} + +int ElfFile::getSymbolSectionIndex(int index) +{ + if(this->e!=NULL) + { + if((index < this->symbols.count()) && (index>=0)) + { + return symbols.at(index)->sym->st_shndx; + } + } + return 0; +} + +quint64 ElfFile::getSymbolAddress(int index) +{ + if(this->e!=NULL) + { + if((index < this->symbols.count()) && (index>=0)) + { + return symbols.at(index)->sym->st_value; + } + } + return 0; +} + +QString ElfFile::getSymbolLinkType(int index) +{ + if(this->e!=NULL) + { + if(index < this->symbols.count()) + { + int btype = GELF_ST_BIND(symbols.at(index)->sym->st_info); + switch(btype) + { + case STB_LOCAL: + return "Local"; + break; + case STB_GLOBAL: + return "Global"; + break; + case STB_WEAK: + return "Weak"; + break; + case STB_NUM: + return "Number of defined types"; + break; + case STB_LOOS: + return "Start of OS-specific"; + break; + case STB_HIOS: + return "End of OS-specific"; + break; + case STB_LOPROC: + return "Start of processor-specific"; + break; + case STB_HIPROC: + return "End of processor-specific"; + break; + default: + return "none"; + break; + } + } + } + return "none"; +} + +bool ElfFile::isElf(const QString &File) +{ + int file =0; +#ifdef _ELF_WINDOWS_ + file = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0); +#else + file = open(File.toStdString().c_str(),O_RDONLY ,0); +#endif + char Magic[4]; + if(file!=-1) + { + size_t res = read(file,Magic,4); + close(file); + if((res==4) && (Magic[0]==0x7f) && (Magic[1]==0x45) && (Magic[2]==0x4c) && (Magic[3]==0x46)) + { + return true; + } + } + return false; +} + +bool ElfFile::toSrec(const QString &File) +{ + return srecFile::toSrec(this->getFragments(),File); +} + +bool ElfFile::toBinary(const QString &File) +{ + return binaryFile::toBinary(getFragments(),File); +} diff --git a/src/common/genericBinaryFiles/elf/elffile.h b/src/common/genericBinaryFiles/elf/elffile.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/elffile.h @@ -0,0 +1,136 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef ELFFILE_H +#define ELFFILE_H + +class Elf_Section +{ +public: + Elf_Section(){} + Elf_Section(Elf_Data* data,GElf_Shdr* section_header) + { + this->data = data; + this->section_header = section_header; + } + ~Elf_Section() + { + free(section_header); + } + Elf_Data* data; + GElf_Shdr* section_header; +}; + +class Elf_Symbol +{ +public: + Elf_Symbol(){} + Elf_Symbol(const QString& name,GElf_Sym* sym):name(name),sym(sym){} + ~Elf_Symbol(){free(sym);} + QString name; + GElf_Sym* sym; +}; + +class ElfFile : public abstractBinFile +{ + Q_OBJECT +public: + ElfFile(); + ElfFile(const QString& File); + ~ElfFile(); + bool openFile(const QString& File); + bool isopened(); + int closeFile(); + QList getFragments(); + QList getFragments(QStringList fragmentList); + + QString getClass(); + QString getArchitecture(); + QString getType(); + QString getEndianness(); + QString getABI(); + qint64 getVersion(); + qint64 getEntryPointAddress(); + + int getSectionCount(); + int getSymbolCount(); + int getSegmentCount(); + + QString getSegmentType(int index); + qint64 getSegmentOffset(int index); + qint64 getSegmentVaddr(int index); + qint64 getSegmentPaddr(int index); + qint64 getSegmentFilesz(int index); + qint64 getSegmentMemsz(int index); + QString getSegmentFlags(int index); + + bool getSectionData(int index, char **buffer); + qint64 getSectionPaddr(int index); + qint64 getSectionMemsz(int index); + qint64 getSectionDatasz(int index); + QString getSectionName(int index); + QString getSectionType(int index); + int getSectionIndex(QString name); + bool sectionIsNobits(int index); + + QString getSymbolName(int index); + QString getSymbolType(int index); + quint64 getSymbolSize(int index); + QString getSymbolSectionName(int index); + int getSymbolSectionIndex(int index); + quint64 getSymbolAddress(int index); + QString getSymbolLinkType(int index); + bool iself(); + static bool isElf(const QString& File); + + bool toSrec(const QString& File); + bool toBinary(const QString& File); + +private: + codeFragment* getFragment(const QString& name); + void updateSections(); + void updateSegments(); + void updateSymbols(); + int elfFile; + bool opened; + bool type_elf; + Elf* e; + Elf_Kind ek; + GElf_Ehdr ehdr; + Elf_Scn * scn; + Elf_Data * data; + size_t SymbolCount,SectionCount,SegmentCount, shstrndx; + QList Segments; + QList sections; + QList symbols; + +}; + +#endif // ELFFILE_H diff --git a/src/common/genericBinaryFiles/elf/elffilewidget.cpp b/src/common/genericBinaryFiles/elf/elffilewidget.cpp new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/elffilewidget.cpp @@ -0,0 +1,346 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#include "elffilewidget.h" +#include "ui_elffilewidget.h" +#include +#include +#include "qhexedit.h" +#include "qtablewidgetintitem.h" +#include "../srec/srecfile.h" +#include "../BinFile/binaryfile.h" + +elfFileWidget::elfFileWidget(QWidget *parent) : + abstractBinFileWidget(parent), + ui(new Ui::elfFileWidget) +{ + ui->setupUi(this); + exportToSREC_action = new QAction(tr("Export to SREC"),this); + exportToBIN_action = new QAction(tr("Export to Binary"),this); + viewSymbolInHexViewer_action = new QAction(tr("View in Hexviewer"),this); + connect(this->ui->sectionsList,SIGNAL(cellActivated(int,int)),this,SLOT(sectionCellActivated(int,int))); + this->ui->sectionsList->addAction(exportToSREC_action); + this->ui->sectionsList->addAction(exportToBIN_action); + this->ui->symbolsList->addAction(viewSymbolInHexViewer_action); + this->ui->symbolsList->addAction(exportToSREC_action); + this->ui->symbolsList->addAction(exportToBIN_action); + connect(this->exportToBIN_action,SIGNAL(triggered()),this,SLOT(exportToBIN())); + connect(this->exportToSREC_action,SIGNAL(triggered()),this,SLOT(exportToSREC())); + connect(this->ui->symbolsFilter,SIGNAL(textChanged(QString)),this,SLOT(filterSymbols(QString))); + connect(this->ui->caseSensitive,SIGNAL(toggled(bool)),this,SLOT(filterSymbolsCaseUpdate(bool))); + connect(this->viewSymbolInHexViewer_action,SIGNAL(triggered()),this,SLOT(viewSymbolInHexViewer())); + this->p_hexviewer = new QHexEdit(); + this->p_hexviewer->setWindowTitle("SocExplorer Hexadecimal viewer"); + this->setWindowTitle("SocExplorer Elf viewer"); +} + + + +elfFileWidget::~elfFileWidget() +{ + delete ui; + delete p_hexviewer; +} + + + +void elfFileWidget::setFile(ElfFile *file) +{ + this->p_elf = file; + if(p_elf->isopened() && p_elf->iself()) + { + this->ui->classLabel->setText(p_elf->getClass()); + this->ui->VersionLabel->setText(QString::number(p_elf->getVersion())); + this->ui->machineLabel->setText(p_elf->getArchitecture()); + this->ui->endiannesLabel->setText(p_elf->getEndianness()); + this->ui->abiLabel->setText(p_elf->getABI()); + this->ui->entryPointLabel->setText(QString("0x%1").arg((uint)p_elf->getEntryPointAddress(),8,16)); + this->ui->typeLabel->setText(p_elf->getType()); + this->ui->sectionCountLabel->setText(QString::number(p_elf->getSectionCount())); + this->ui->symbolCountLabel->setText(QString::number(p_elf->getSymbolCount())); + } + reloadFile(); +} + +void elfFileWidget::reloadFile() +{ + updateSymbols(); + updateSections(); +} + + + +void elfFileWidget::updateSymbols() +{ + this->ui->symbolsList->clear(); + this->ui->symbolsList->setRowCount(p_elf->getSymbolCount()); + this->ui->symbolsList->setHorizontalHeaderLabels(QStringList()<<"Index"<<"Value"<<"Size"<<"Type"<<"Link"<<"Section"<<"Name"); + for(int i=0;igetSymbolCount();i++) + { + QTableWidgetItem *newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(i),DecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 0, newItem); + + newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("0x%1").arg(p_elf->getSymbolAddress(i),8,16).replace(" ","0"),HexaDecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 1, newItem); + + newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(p_elf->getSymbolSize(i)),DecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 2, newItem); + + newItem = new QTableWidgetItem(p_elf->getSymbolType(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 3, newItem); + + newItem = new QTableWidgetItem(p_elf->getSymbolLinkType(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 4, newItem); + + newItem = new QTableWidgetItem(p_elf->getSymbolSectionName(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 5, newItem); + + newItem = new QTableWidgetItem(p_elf->getSymbolName(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 6, newItem); + } + this->ui->symbolsList->resizeColumnsToContents(); +} + + + +void elfFileWidget::updateSections() +{ + this->ui->sectionsList->clear(); + this->ui->sectionsList->setRowCount(p_elf->getSectionCount()); + this->ui->sectionsList->setHorizontalHeaderLabels(QStringList()<<"Index"<<"Name"<<"Address"<<"Size"<<"File Size"<<"Type"); + for(int i=0;igetSectionCount();i++) + { + QTableWidgetItem *newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("%1").arg(i),DecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->sectionsList->setItem(i,0, newItem); + + newItem = new QTableWidgetItem(p_elf->getSectionName(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->sectionsList->setItem(i, 1, newItem); + + newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("0x%1").arg(p_elf->getSectionPaddr(i),8,16).replace(" ","0"),HexaDecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->sectionsList->setItem(i, 2, newItem); + + newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("%1").arg(p_elf->getSectionMemsz(i)),DecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->sectionsList->setItem(i, 3, newItem); + + newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("%1").arg(p_elf->getSectionDatasz(i)),DecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->sectionsList->setItem(i, 4, newItem); + + newItem = new QTableWidgetItem(p_elf->getSectionType(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->sectionsList->setItem(i, 5, newItem); + } + this->ui->sectionsList->resizeColumnsToContents(); +} + +void elfFileWidget::sectionCellActivated(int row, int column) +{ + Q_UNUSED(column) + char* buff=NULL; + int sectionIndex = p_elf->getSectionIndex(this->ui->sectionsList->item(row,1)->text()); + if(sectionIndex!=-1) + { + QString type = p_elf->getSectionType(sectionIndex); + if(!p_elf->sectionIsNobits(sectionIndex)) + { + this->p_elf->getSectionData(sectionIndex,&buff); + this->ui->sectionsHexView->setData(QByteArray(buff,this->p_elf->getSectionDatasz(sectionIndex))); + this->ui->sectionsHexView->setAddressOffset(this->p_elf->getSectionPaddr(sectionIndex)); + } + } +} + +void elfFileWidget::exportToSREC() +{ + QList fragments; + if(this->ui->tabWidget->currentWidget()==this->ui->symbolsTab) + { + fragments = getSelectedSymbolsFragments(); + } + if(this->ui->tabWidget->currentWidget()==this->ui->sectionsTab) + { + QStringList sectionList=getSelectedSectionsNames(); + if(sectionList.count()>0) + fragments = p_elf->getFragments(sectionList); + } + if(fragments.count()>0) + { + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), + NULL, + tr("SREC Files (*.srec)")); + if(!fileName.isEmpty()) + { + srecFile::toSrec(fragments,fileName); + } + } + +} + +void elfFileWidget::exportToBIN() +{ + QList fragments; + if(this->ui->tabWidget->currentWidget()==this->ui->symbolsTab) + { + fragments = getSelectedSymbolsFragments(); + } + if(this->ui->tabWidget->currentWidget()==this->ui->sectionsTab) + { + QStringList sectionList=getSelectedSectionsNames(); + if(sectionList.count()>0) + fragments = p_elf->getFragments(sectionList); + } + if(fragments.count()>0) + { + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), + NULL, + tr("Binary Files (*.bin)")); + if(!fileName.isEmpty()) + { + binaryFile::toBinary(fragments,fileName); + } + } + +} + +void elfFileWidget::viewSymbolInHexViewer() +{ + int row=this->ui->symbolsList->item(this->ui->symbolsList->currentRow(),0)->text().toInt(); + int section = p_elf->getSectionIndex(p_elf->getSymbolSectionName(row)); + qint64 address = p_elf->getSymbolAddress(row); + qint64 secAddress = p_elf->getSectionPaddr(section); + qint64 size = p_elf->getSymbolSize(row); + char* buff=NULL; + char* symBuff=NULL; + if(size && !p_elf->sectionIsNobits(section)) + { + if(section!=-1) + { + symBuff = (char*)malloc(size); + this->p_elf->getSectionData(section,&buff); + memcpy(symBuff,buff+(address-secAddress),size); + this->p_hexviewer->setData(QByteArray(symBuff,size)); + this->p_hexviewer->setAddressOffset(address); + this->p_hexviewer->show(); + } + } +} + +void elfFileWidget::filterSymbols(const QString &pattern) +{ + Qt::MatchFlags flag = Qt::MatchContains | Qt::MatchStartsWith | Qt::MatchEndsWith | Qt::MatchRegExp | Qt::MatchWildcard | Qt::MatchWrap |Qt::MatchRecursive; + if(this->ui->caseSensitive->isChecked()) + flag |= Qt::MatchCaseSensitive; + if(pattern.isEmpty()) + { + for(int i=0;iui->symbolsList->rowCount();i++) + this->ui->symbolsList->setRowHidden(i,false); + } + else + { + for(int i=0;iui->symbolsList->rowCount();i++) + this->ui->symbolsList->setRowHidden(i,true); + QList items = this->ui->symbolsList->findItems(pattern,flag); + for(int i=0;iui->symbolsList->setRowHidden(items.at(i)->row(),false); + } +} + +void elfFileWidget::filterSymbolsCaseUpdate(bool toggled) +{ + Q_UNUSED(toggled) + this->filterSymbols(this->ui->symbolsFilter->text()); +} + +QList elfFileWidget::getSelectedSymbolsFragments() +{ + QList fragments; + codeFragment * fragment; + if(p_elf->isopened()) + { + QList items = this->ui->symbolsList->selectedItems(); + for(int i=0;iui->symbolsList->item(items.at(i)->row(),0)->text().toInt(); + int section = p_elf->getSectionIndex(p_elf->getSymbolSectionName(row)); + qint64 address = p_elf->getSymbolAddress(row); + qint64 secAddress = p_elf->getSectionPaddr(section); + qint64 size = p_elf->getSymbolSize(row); + char* buff=NULL; + if(size && !p_elf->sectionIsNobits(section)) + { + if(section!=-1) + { + fragment= new codeFragment(); + fragment->data = (char*)malloc(size); + fragment->address = address; + fragment->size = size; + this->p_elf->getSectionData(section,&buff); + memcpy(fragment->data,buff+(address-secAddress),size); + fragments.append(fragment); + } + } + } + } + return fragments; + +} + + + +QStringList elfFileWidget::getSelectedSectionsNames() +{ + QStringList sectionList; + QList items = this->ui->sectionsList->selectedItems(); + for(int i=0;igetSectionName(items.at(i)->row()); + if(!sectionList.contains(section)) + { + sectionList.append(section); + } + } + return sectionList; +} + + + + + + + + + + + + + + diff --git a/src/common/genericBinaryFiles/elf/elffilewidget.h b/src/common/genericBinaryFiles/elf/elffilewidget.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/elffilewidget.h @@ -0,0 +1,66 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#ifndef ELFFILEWIDGET_H +#define ELFFILEWIDGET_H + +#include +#include "elffile.h" +#include +#include + +namespace Ui { +class elfFileWidget; +} + +class elfFileWidget : public abstractBinFileWidget +{ + Q_OBJECT + +public: + elfFileWidget(QWidget *parent = 0); + ~elfFileWidget(); + +public slots: + void setFile(ElfFile* file); + void reloadFile(); + void updateSymbols(); + void updateSections(); + +private slots: + void sectionCellActivated(int row, int column); + void exportToSREC(); + void exportToBIN(); + void viewSymbolInHexViewer(); + void filterSymbols(const QString& pattern); + void filterSymbolsCaseUpdate(bool toggled); +private: + QList getSelectedSymbolsFragments(); + Ui::elfFileWidget *ui; + QStringList getSelectedSectionsNames(); + ElfFile* p_elf; + QAction* exportToSREC_action; + QAction* exportToBIN_action; + QAction* viewSymbolInHexViewer_action; + QHexEdit* p_hexviewer; +}; + +#endif // ELFFILEWIDGET_H diff --git a/src/common/genericBinaryFiles/elf/elffilewidget.ui b/src/common/genericBinaryFiles/elf/elffilewidget.ui new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/elffilewidget.ui @@ -0,0 +1,337 @@ + + + elfFileWidget + + + + 0 + 0 + 786 + 387 + + + + + 0 + 0 + + + + Qt::NoFocus + + + Form + + + + + + 0 + + + + File Informations + + + + + + Elf header + + + + + + Class: + + + + + + + none + + + + + + + Endianness: + + + + + + + none + + + + + + + Version: + + + + + + + Type: + + + + + + + Machine: + + + + + + + Entry point address: + + + + + + + none + + + + + + + none + + + + + + + none + + + + + + + none + + + + + + + OS/ABI: + + + + + + + none + + + + + + + + + + Sections & Symbols + + + + + + Section count: + + + + + + + Symbols count: + + + + + + + none + + + + + + + none + + + + + + + + + + + Symbols + + + + + + + + + Filter: + + + + + + + Case Sensitive + + + + + + + Qt::ActionsContextMenu + + + true + + + false + + + false + + + + Index + + + + + Value + + + + + Size + + + + + Type + + + + + Link + + + + + Section + + + + + Name + + + + + + + + + Sections + + + + + + Qt::Horizontal + + + + + 100 + 0 + + + + + + Qt::ActionsContextMenu + + + true + + + false + + + false + + + + Index + + + + + Name + + + + + Address + + + + + Size + + + + + File Size + + + + + Type + + + + + + + + + + + + + + QHexEdit + QWidget +
qhexedit.h
+ 1 +
+
+ + +
diff --git a/src/common/genericBinaryFiles/elf/elfinfowdgt.cpp b/src/common/genericBinaryFiles/elf/elfinfowdgt.cpp new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/elfinfowdgt.cpp @@ -0,0 +1,164 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2013, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + +#include "elfinfowdgt.h" + +elfInfoWdgt::elfInfoWdgt(QWidget *parent) : + QWidget(parent) +{ + this->mainLayout = new QVBoxLayout; + this->ElfArchitecture= new QLabel; + this->ElfType = new QLabel; + this->ElfVersion = new QLabel; + this->splitter = new QSplitter; + this->hexViewer = new QHexEdit; + this->elfInfoWdgtLay = new QWidget; + this->elfInfoWdgtLayout = new QVBoxLayout; + this->segmentsListTableWdgt = new QTableWidget; + this->segmentsListTableWdgt->setColumnCount(7); + this->segmentsListTableWdgt->setHorizontalHeaderLabels(QStringList()<<"Type"<<"Offset"<<"Vaddr"<<"Paddr"<<"File Size"<<"Mem Size"<<"Flags"); + this->sectionsListTableWdgt = new QTableWidget; + this->sectionsListTableWdgt->setColumnCount(2); + this->sectionsListTableWdgt->setHorizontalHeaderLabels(QStringList()<<"Name"<<"Type"); + this->ElfArchitecture->setText(QString("Architecture: ")); + this->ElfType->setText(QString("Type: ")); + this->ElfVersion->setText(QString("Version: ")); + this->elfInfoWdgtLayout->addWidget(this->ElfArchitecture); + this->elfInfoWdgtLayout->addWidget(this->ElfType); + this->elfInfoWdgtLayout->addWidget(this->ElfVersion); + this->elfInfoWdgtLayout->addWidget(this->segmentsListTableWdgt); + this->elfInfoWdgtLayout->addWidget(this->sectionsListTableWdgt); + this->splitter->addWidget(this->hexViewer); + this->splitter->addWidget(this->elfInfoWdgtLay); + this->elfInfoWdgtLay->setLayout(this->elfInfoWdgtLayout); + this->mainLayout->addWidget(this->splitter); + this->setLayout(this->mainLayout); + connect(this->segmentsListTableWdgt,SIGNAL(cellActivated(int,int)),this,SLOT(cellActivated(int,int))); + connect(this->sectionsListTableWdgt,SIGNAL(cellActivated(int,int)),this,SLOT(cellActivated(int,int))); +} + + +void elfInfoWdgt::updateInfo(elfparser *parser) +{ + if(parser!=NULL) + { + this->ElfArchitecture->setText(QString("Architecture: ")+parser->getArchitecture()); + this->ElfType->setText(QString("Type: ")+parser->getType()); + this->ElfVersion->setText(QString("Version: 0x")+QString::number(parser->getVersion(),16)); + this->updateSectionsTable(parser); + this->updateSegmentsTable(parser); + } + +} + +void elfInfoWdgt::cellActivated(int row, int column) +{ + char* buff=NULL; + this->parser->getSectionData(row,&buff); + this->hexViewer->setData(QByteArray(buff,this->parser->getSectionDatasz(row))); +} + + +void elfInfoWdgt::updateSectionsTable(elfparser* parser) +{ + if(parser!=NULL) + { + this->parser = parser; + QTableWidgetItem *item; + for(int i=0 ;isectionsListTableWdgt->rowCount();i++) + { + for(int l=0;lsectionsListTableWdgt->columnCount();l++) + { + item = this->sectionsListTableWdgt->item(i,l); + delete item; + } + } + this->sectionsListTableWdgt->setRowCount(parser->getSectioncount()); + for(int i=0;igetSectioncount();i++) + { + item = new QTableWidgetItem(parser->getSectionName(i)); + item->setFlags(item->flags() &~ Qt::ItemIsEditable); + this->sectionsListTableWdgt->setItem(i,0,item); + item = new QTableWidgetItem(parser->getSectionType(i)); + item->setFlags(item->flags() &~ Qt::ItemIsEditable); + this->sectionsListTableWdgt->setItem(i,1,item); + } + this->sectionsListTableWdgt->resizeColumnsToContents(); + this->sectionsListTableWdgt->resizeRowsToContents(); + } +} + + +void elfInfoWdgt::updateSegmentsTable(elfparser* parser) +{ + if(parser!=NULL) + { + this->parser = parser; + QTableWidgetItem *item; + for(int i=0 ;isegmentsListTableWdgt->rowCount();i++) + { + for(int l=0;lsegmentsListTableWdgt->columnCount();l++) + { + item = this->segmentsListTableWdgt->item(i,l); + delete item; + } + } + this->segmentsListTableWdgt->setRowCount(parser->getSegmentcount()); + for(int i=0;igetSegmentcount();i++) + { + item = new QTableWidgetItem(parser->getSegmentType(i)); + item->setFlags(item->flags() &~ Qt::ItemIsEditable); + this->segmentsListTableWdgt->setItem(i,0,item); + item = new QTableWidgetItem("0x"+QString::number(parser->getSegmentOffset(i),16)); + item->setFlags(item->flags() &~ Qt::ItemIsEditable); + this->segmentsListTableWdgt->setItem(i,1,item); + item = new QTableWidgetItem("0x"+QString::number(parser->getSegmentVaddr(i),16)); + item->setFlags(item->flags() &~ Qt::ItemIsEditable); + this->segmentsListTableWdgt->setItem(i,2,item); + item = new QTableWidgetItem("0x"+QString::number(parser->getSegmentPaddr(i),16)); + item->setFlags(item->flags() &~ Qt::ItemIsEditable); + this->segmentsListTableWdgt->setItem(i,3,item); + item = new QTableWidgetItem("0x"+QString::number(parser->getSegmentFilesz(i),16)); + item->setFlags(item->flags() &~ Qt::ItemIsEditable); + this->segmentsListTableWdgt->setItem(i,4,item); + item = new QTableWidgetItem("0x"+QString::number(parser->getSegmentMemsz(i),16)); + item->setFlags(item->flags() &~ Qt::ItemIsEditable); + this->segmentsListTableWdgt->setItem(i,5,item); + item = new QTableWidgetItem(parser->getSegmentFlags(i)); + item->setFlags(item->flags() &~ Qt::ItemIsEditable); + this->segmentsListTableWdgt->setItem(i,6,item); + } + this->segmentsListTableWdgt->resizeColumnsToContents(); + this->segmentsListTableWdgt->resizeRowsToContents(); + } +} + + + + + + + + + + + diff --git a/src/common/genericBinaryFiles/elf/elfinfowdgt.h b/src/common/genericBinaryFiles/elf/elfinfowdgt.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/elfinfowdgt.h @@ -0,0 +1,64 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2013, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ +#ifndef ELFINFOWDGT_H +#define ELFINFOWDGT_H + +#include +#include "elfparser.h" +#include +#include +#include +#include +#include +#include +#include + +class elfInfoWdgt : public QWidget +{ + Q_OBJECT +public: + explicit elfInfoWdgt(QWidget *parent = 0); + +signals: + + +public slots: + void updateInfo(elfparser* parser); + void cellActivated ( int row, int column ); + +private: + void updateSectionsTable(elfparser* parser); + void updateSegmentsTable(elfparser* parser); + QVBoxLayout* mainLayout; + QLabel* ElfArchitecture; + QLabel* ElfType; + QLabel* ElfVersion; + QTableWidget* segmentsListTableWdgt,*sectionsListTableWdgt; + QHexEdit* hexViewer; + QSplitter* splitter; + QWidget* elfInfoWdgtLay; + QVBoxLayout* elfInfoWdgtLayout; + elfparser* parser; + +}; + +#endif // ELFINFOWDGT_H diff --git a/src/common/genericBinaryFiles/elf/elfparser.cpp b/src/common/genericBinaryFiles/elf/elfparser.cpp new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/elfparser.cpp @@ -0,0 +1,522 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2013, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ +#include "elfparser.h" +#include +#include +#include +#include + +extern QString elfresolveMachine(Elf64_Half e_machine); + + +elfparser::elfparser() +{ + this->opened = false; + this->type_elf = false; + this->elfFile = (int)NULL; + this->e = NULL; +} + + +int elfparser::setFilename(const QString &name) +{ + this->closeFile(); + if(elf_version(EV_CURRENT)==EV_NONE)return 0; +#ifdef _ELF_WINDOWS_ + this->elfFile = open(name.toStdString().c_str(),O_RDONLY|O_BINARY ,0); +#else + this->elfFile = open(name.toStdString().c_str(),O_RDONLY ,0); +#endif + if(this->elfFile==(int)NULL)return 0; + this->e = elf_begin(this->elfFile,ELF_C_READ,NULL); + if(this->e==NULL)return 0; + this->ek = elf_kind(this->e); + gelf_getehdr (this->e, &this->ehdr ); + elf_getshdrstrndx (this->e, &this->shstrndx); + this->updateSegments(); + this->updateSections(); + return 1; +} + + +int elfparser::closeFile() +{ + if(this->elfFile!=(int)NULL) + { + if(this->e!=NULL) + { + elf_end(this->e); + this->e = NULL; + } + close(this->elfFile); + this->elfFile = (int)NULL; + } + return 0; +} + +QString elfparser::getClass() +{ + if(this->e!=NULL) + { + int eclass = gelf_getclass(this->e); + if(eclass==ELFCLASS32)return "ELF32"; + if(eclass==ELFCLASS64)return "ELF64"; + } + return "none"; +} + + +bool elfparser::isopened() +{ + return this->opened; +} + + +bool elfparser::iself() +{ + return this->type_elf; +} + + +QString elfparser::getArchitecture() +{ + if(this->e!=NULL) + { + return elfresolveMachine(this->ehdr.e_machine); + } + return ""; +} + + +QString elfparser::getType() +{ + QString kind(""); + if(this->e!=NULL) + { + switch(this->ek) + { + case ELF_K_AR: + kind = "Archive"; + break; + case ELF_K_ELF: + kind = "Elf"; + break; + case ELF_K_COFF: + kind = "COFF"; + break; + case ELF_K_NUM: + kind = "NUM"; + break; + case ELF_K_NONE: + kind = "Data"; + break; + default: + kind = "Unknow"; + break; + } + } + return kind; +} + +QString elfparser::getEndianness() +{ + if(this->e!=NULL) + { + if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return "2's complement, little endian"; + if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return "2's complement, big endian"; + } + return "none"; +} + +QString elfparser::getABI() +{ + if(this->e!=NULL) + { + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NONE)return "UNIX System V ABI"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SYSV)return "Alias"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_HPUX)return "HP-UX"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NETBSD)return "NetBSD"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_LINUX)return "Object uses GNU ELF extensions"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SOLARIS)return "Sun Solaris"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_AIX)return "IBM AIX"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_IRIX)return "SGI Irix"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_FREEBSD)return "FreeBSD"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_TRU64)return "Compaq TRU64 UNIX"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_MODESTO)return " Novell Modesto"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_OPENBSD)return "OpenBSD"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM_AEABI)return "ARM EABI"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM)return "ARM"; + if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_STANDALONE)return "Standalone (embedded) application"; + } + return "none"; +} + + +qint64 elfparser::getVersion() +{ + if(this->e!=NULL) + { + return this->ehdr.e_version; + } + return -1; +} + +qint64 elfparser::getEntryPointAddress() +{ + if(this->e!=NULL) + { + return this->ehdr.e_entry; + } + return -1; +} + + +int elfparser::getSectioncount() +{ + return (int)this->SectionCount; +} + + +int elfparser::getSegmentcount() +{ + return (int)this->SegmentCount; +} + + +QString elfparser::getSegmentType(int index) +{ + QString type(""); + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + switch(this->Segments.at(index)->p_type) + { + case PT_NULL: + type = "Program header table entry unused"; + break; + case PT_LOAD: + type = "Loadable program segment"; + break; + case PT_DYNAMIC : + type = "Dynamic linking information"; + break; + case PT_INTERP: + type ="Program interpreter"; + break; + case PT_NOTE: + type = "Auxiliary information"; + break; + case PT_SHLIB: + type = "Reserved"; + break; + case PT_PHDR: + type = "Entry for header table itself"; + break; + case PT_TLS: + type = "Thread-local storage segment"; + break; + case PT_NUM: + type = "Number of defined types"; + break; + case PT_LOOS: + type = "Start of OS-specific"; + break; + case PT_SUNWSTACK: + type = "Stack segment"; + break; + case PT_LOPROC: + type = "Start of processor-specific"; + break; + case PT_HIPROC: + type = "End of processor-specific"; + break; + default: + type = "Unknow Section Type"; + break; + } + } + } + + return type; +} + + +qint64 elfparser::getSegmentOffset(int index) +{ + qint64 Offset=-1; + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + Offset = (qint64)this->Segments.at(index)->p_offset; + } + } + return Offset; +} + + +qint64 elfparser::getSegmentVaddr(int index) +{ + int64_t Vaddr = 0; + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + Vaddr = (int64_t)this->Segments.at(index)->p_vaddr; + } + } + return Vaddr; +} + + +qint64 elfparser::getSegmentPaddr(int index) +{ + int64_t Paddr=0; + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + Paddr = (int64_t)this->Segments.at(index)->p_paddr; + } + } + return Paddr; +} + +qint64 elfparser::getSectionPaddr(int index) +{ + int64_t Paddr=0; + if(this->e!=NULL) + { + if(index < this->sections.count()) + { + Paddr = (int64_t)this->sections.at(index)->section_header->sh_addr; + } + } + return Paddr; +} + + +qint64 elfparser::getSegmentFilesz(int index) +{ + int64_t FileSz=0; + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + FileSz = (int64_t)this->Segments.at(index)->p_filesz; + } + } + return FileSz; +} + +qint64 elfparser::getSectionDatasz(int index) +{ + int64_t DataSz=0; + if(this->e!=NULL) + { + if(index < this->sections.count()) + { + DataSz = (int64_t)this->sections.at(index)->data->d_size; + } + } + return DataSz; +} + +bool elfparser::getSectionData(int index, char **buffer) +{ + if(this->e!=NULL) + { + if(index < this->sections.count()) + { + *buffer = (char *)this->sections.at(index)->data->d_buf; + return true; + } + } + return false; +} + + +qint64 elfparser::getSegmentMemsz(int index) +{ + int64_t MemSz=0; + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + MemSz = (int64_t)this->Segments.at(index)->p_memsz; + } + } + return MemSz; +} + +qint64 elfparser::getSectionMemsz(int index) +{ + int64_t MemSz=0; + if(this->e!=NULL) + { + if(index < this->sections.count()) + { + MemSz = (int64_t)this->sections.at(index)->section_header->sh_size; + } + } + return MemSz; +} + + +QString elfparser::getSegmentFlags(int index) +{ + QString flags(""); + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + if((this->Segments.at(index)->p_flags&PF_X) == PF_X)flags+="x"; + if((this->Segments.at(index)->p_flags&PF_W) == PF_W)flags+="w"; + if((this->Segments.at(index)->p_flags&PF_R) == PF_R)flags+="r"; + if((this->Segments.at(index)->p_flags&PF_MASKOS) == PF_MASKOS)flags+=" OS-specific"; + if((this->Segments.at(index)->p_flags&PF_MASKPROC) == PF_MASKPROC)flags+=" Processor-specific"; + } + } + return flags; +} + + +QString elfparser::getSectionName(int index) +{ + char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name); + return QString(nameChr); +} + + +void elfparser::updateSections() +{ + for(int i=0;isections.count();i++) + { + delete this->sections.at(i); + } + this->sections.clear(); + this->scn = elf_nextscn (this->e , NULL ); + this->SectionCount = 0; + while( this->scn != NULL ) + { + GElf_Shdr* shdr = (GElf_Shdr*)malloc(sizeof(GElf_Shdr)); + gelf_getshdr ( this->scn , shdr ); + Elf_Data* data = elf_getdata(this->scn, NULL); + this->sections.append(new Elf_Section(data,shdr)); + this->SectionCount+=1; + this->scn = elf_nextscn(e , scn); + } +} + + +void elfparser::updateSegments() +{ + elf_getphdrnum (this->e , &this->SegmentCount); + for(int i=0;iSegments.count();i++) + { + free(this->Segments.at(i)); + } + this->Segments.clear(); + for(int i=0;i<(int)this->SegmentCount;i++) + { + GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr)); + gelf_getphdr (this->e , i , header ); + this->Segments.append(header); + } +} + + + + + +QString elfparser::getSectionType(int index) +{ + QString type(""); + if(this->e!=NULL) + { + if(index < this->Segments.count()) + { + switch(this->Segments.at(index)->p_type) + { + case SHT_NULL : type = "Section header table entry unused"; break; + case SHT_PROGBITS : type = "Program data"; break; + case SHT_SYMTAB : type = "Symbol table"; break; + case SHT_STRTAB : type = "String table"; break; + case SHT_RELA : type = "Relocation entries with addends"; break; + case SHT_HASH : type = "Symbol hash table"; break; + case SHT_DYNAMIC : type = "Dynamic linking information"; break; + case SHT_NOTE : type = "Notes"; break; + case SHT_NOBITS :type = "Program space with no data (bss)"; break; + case SHT_REL :type = "Relocation entries, no addends"; break; + case SHT_SHLIB : type = "Reserved"; break; + case SHT_DYNSYM : type = "Dynamic linker symbol table"; break; + case SHT_INIT_ARRAY : type = "Array of constructors"; break; + case SHT_FINI_ARRAY : type = "Array of destructors"; break; + case SHT_PREINIT_ARRAY : type = "Array of pre-constructors"; break; + case SHT_GROUP : type = "Section group"; break; + case SHT_SYMTAB_SHNDX : type = "Extended section indeces"; break; + case SHT_NUM : type = "Number of defined types. "; break; + case SHT_LOOS : type = "Start OS-specific. "; break; + case SHT_LOSUNW : type = "Sun-specific low bound. "; break; + case SHT_SUNW_COMDAT : type = " "; break; + case SHT_SUNW_syminfo : type = " "; break; + case SHT_GNU_verdef : type = "Version definition section. "; break; + case SHT_GNU_verneed : type = "Version needs section. "; break; + case SHT_GNU_versym : type = "Version symbol table. "; break; + case SHT_LOPROC : type = "Start of processor-specific"; break; + case SHT_HIPROC : type = "End of processor-specific"; break; + case SHT_HIUSER : type = "End of application-specific"; break; + } + } + } + return type; +} + +bool elfparser::isElf(const QString &File) +{ + int file =0; +#ifdef _ELF_WINDOWS_ + file = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0); +#else + file = open(File.toStdString().c_str(),O_RDONLY ,0); +#endif + char Magic[4]; + if(file!=-1) + { + size_t res = read(file,Magic,4); + close(file); + if((res == 4) && (Magic[0]==0x7f) && (Magic[1]==0x45) && (Magic[2]==0x4c) && (Magic[3]==0x46)) + { + return true; + } + } + return false; +} + + + + + + + + diff --git a/src/common/genericBinaryFiles/elf/elfparser.h b/src/common/genericBinaryFiles/elf/elfparser.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/elfparser.h @@ -0,0 +1,89 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2013, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ +#ifndef ELFPARSER_H +#define ELFPARSER_H +#include +#include +#include +#include +#include +#include +#include "elffile.h" + +class elfparser +{ +public: + elfparser(); + bool iself(); + bool isopened(); + int setFilename(const QString& name); + int closeFile(); + QString getClass(); + QString getArchitecture(); + QString getType(); + QString getEndianness(); + QString getABI(); + qint64 getVersion(); + qint64 getEntryPointAddress(); + int getSectioncount(); + int getSegmentcount(); + QString getSegmentType(int index); + qint64 getSegmentOffset(int index); + qint64 getSegmentVaddr(int index); + qint64 getSegmentPaddr(int index); + qint64 getSectionPaddr(int index); + qint64 getSegmentFilesz(int index); + qint64 getSectionDatasz(int index); + bool getSectionData(int index, char **buffer); + qint64 getSegmentMemsz(int index); + qint64 getSectionMemsz(int index); + QString getSegmentFlags(int index); + QString getSectionName(int index); + QString getSectionType(int index); + static bool isElf(const QString& File); + +private: + void updateSections(); + void updateSegments(); + int elfFile; + bool opened; + bool type_elf; + Elf* e; + Elf_Kind ek; + GElf_Ehdr ehdr; + Elf_Scn * scn; + Elf_Data * data; + size_t SectionCount,SegmentCount, shstrndx; + QList Segments; + QList sections; + +}; + +#endif // ELFPARSER_H + + + + + + + + diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/COPYING.LIB b/src/common/genericBinaryFiles/elf/libelfWin32/COPYING.LIB new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/COPYING.LIB @@ -0,0 +1,481 @@ + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/INSTALL b/src/common/genericBinaryFiles/elf/libelfWin32/INSTALL new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/INSTALL @@ -0,0 +1,176 @@ +Basic Installation +================== + + These are generic installation instructions. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, a file +`config.cache' that saves the results of its tests to speed up +reconfiguring, and a file `config.log' containing compiler output +(useful mainly for debugging `configure'). + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If at some point `config.cache' +contains results you don't want to keep, you may remove or edit it. + + The file `configure.in' is used to create `configure' by a program +called `autoconf'. You only need `configure.in' if you want to change +it or regenerate `configure' using a newer version of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. If you're + using `csh' on an old version of System V, you might need to type + `sh ./configure' instead to prevent `csh' from trying to execute + `configure' itself. + + Running `configure' takes awhile. While running, it prints some + messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the `configure' script does not know about. You can give `configure' +initial values for variables by setting them in the environment. Using +a Bourne-compatible shell, you can do that on the command line like +this: + CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure + +Or on systems that have the `env' program, you can do it like this: + env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you must use a version of `make' that +supports the `VPATH' variable, such as GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + If you have to use a `make' that does not supports the `VPATH' +variable, you have to compile the package for one architecture at a time +in the source code directory. After you have installed the package for +one architecture, use `make distclean' before reconfiguring for another +architecture. + +Installation Names +================== + + By default, `make install' will install the package's files in +`/usr/local/bin', `/usr/local/man', etc. You can specify an +installation prefix other than `/usr/local' by giving `configure' the +option `--prefix=PATH'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +give `configure' the option `--exec-prefix=PATH', the package will use +PATH as the prefix for installing programs and libraries. +Documentation and other data files will still use the regular prefix. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + + Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + + There may be some features `configure' can not figure out +automatically, but needs to determine by the type of host the package +will run on. Usually `configure' can figure that out, but if it prints +a message saying it can not guess the host type, give it the +`--host=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name with three fields: + CPU-COMPANY-SYSTEM + +See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the host type. + + If you are building compiler tools for cross-compiling, you can also +use the `--target=TYPE' option to select the type of system they will +produce code for and the `--build=TYPE' option to select the type of +system on which you are compiling the package. + +Sharing Defaults +================ + + If you want to set default values for `configure' scripts to share, +you can create a site shell script called `config.site' that gives +default values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Operation Controls +================== + + `configure' recognizes the following options to control how it +operates. + +`--cache-file=FILE' + Use and save the results of the tests in FILE instead of + `./config.cache'. Set FILE to `/dev/null' to disable caching, for + debugging `configure'. + +`--help' + Print a summary of the options to `configure', and exit. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`--version' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`configure' also accepts some other, not widely useful, options. + diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/MANIFEST b/src/common/genericBinaryFiles/elf/libelfWin32/MANIFEST new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/MANIFEST @@ -0,0 +1,96 @@ +25275 COPYING.LIB +35406 ChangeLog +7462 INSTALL +5908 Makefile.in +13232 README +7 VERSION +2955 acconfig.h +9381 aclocal.m4 +43611 config.guess +3987 config.h.in +31160 config.sub +110753 configure +11736 configure.in +2186 install-sh +4798 lib/32.fsize.c +1556 lib/32.getehdr.c +1557 lib/32.getphdr.c +1665 lib/32.getshdr.c +2181 lib/32.newehdr.c +3055 lib/32.newphdr.c +12322 lib/32.xlatetof.c +14221 lib/64.xlatetof.c +8012 lib/Makefile.in +4010 lib/Makefile.w32 +1119 lib/assert.c +10463 lib/begin.c +1685 lib/build.bat +3566 lib/byteswap.h +3937 lib/checksum.c +1901 lib/cntl.c +4851 lib/config.h.w32 +12554 lib/cook.c +1183 lib/data.c +24585 lib/elf_repl.h +2899 lib/end.c +2137 lib/errmsg.c +1037 lib/errno.c +6222 lib/errors.h +8107 lib/ext_types.h +997 lib/fill.c +2400 lib/flag.c +5103 lib/gelf.h +4151 lib/gelfehdr.c +3965 lib/gelfphdr.c +3758 lib/gelfshdr.c +9456 lib/gelftrans.c +1175 lib/getarhdr.c +1380 lib/getaroff.c +2421 lib/getarsym.c +1096 lib/getbase.c +3841 lib/getdata.c +1353 lib/getident.c +1449 lib/getscn.c +1212 lib/hash.c +2562 lib/input.c +1088 lib/kind.c +1214 lib/libelf.def +9050 lib/libelf.h +1505 lib/memset.c +1098 lib/ndxscn.c +1558 lib/newdata.c +3488 lib/newscn.c +1356 lib/next.c +1607 lib/nextscn.c +5898 lib/nlist.c +1452 lib/nlist.h +5071 lib/opt.delscn.c +13133 lib/private.h +1286 lib/rand.c +2543 lib/rawdata.c +1541 lib/rawfile.c +3393 lib/strptr.c +2285 lib/swap64.c +3812 lib/sys_elf.h.in +4066 lib/sys_elf.h.w32 +26008 lib/update.c +6884 lib/verdef.h +1586 lib/verdef_32_tof.c +1586 lib/verdef_32_tom.c +1614 lib/verdef_64_tof.c +1614 lib/verdef_64_tom.c +7135 lib/verneed.h +1435 lib/version.c +4425 lib/x.elfext.c +2721 lib/x.movscn.c +2870 lib/x.remscn.c +254 libelf.pc.in +619 mkinstalldirs +4593 po/Makefile.in +8748 po/de.gmo +52 po/de.msg +11332 po/de.po +3011 po/gmo2msg.c +6483 po/libelf.pot +10 po/stamp-po +10 stamp-h.in diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/README b/src/common/genericBinaryFiles/elf/libelfWin32/README new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/README @@ -0,0 +1,332 @@ +This is the public release of libelf-0.8.13, a free ELF object +file access library. If you have problems with applications +that use libelf and work with the commercial (SVR4, Solaris) +version but not with this one, please contact me. + +IMPORTANT NOTE: If you have libelf-0.5.2 installed, you probably +have a file .../include/elf.h that contains the single line +``#include ''. REMOVE THIS FILE BEFORE YOU RUN +configure. + +Installation is straightforward - the package is autoconf'ed. Just do +``cd libelf-0.8.13; ./configure; make; make install''. Header files +will be installed in .../include/libelf/. If your system does not +provide its own versions of libelf.h, nlist.h or gelf.h, ``make +install'' will add the missing headers. If you prefer not to have +these files installed in /usr/include, use ``--disable-compat'' and +add ``-I /usr/include/libelf'' to your CFLAGS when compiling +libelf-based programs. + +Note to distribution makers: You can install libelf in a separate root +hierarchy by using the command ``make instroot=/my/root install''. +You should also use the ``--enable-compat'' configure option in that +case, or run ``make instroot=/my/root install-compat'' manually, to +install all the required header files. + +If you are running Linux with libc 5.* as the default C library, +and you plan to use the 64-bit functions, you must either use +``-I.../include/libelf'', or remove /usr/include/libelf.h and use +``--enable-compat'' when running configure. Libc 6.* (aka glibc2) +doesn't have its own , or . + +You need an ANSI/ISO C compiler to build libelf. Gcc is optimal. + +On some systems (in particular, Solaris and all variants of Linux), +``make'' will try to build a shared library. If you run into problems +on your system, please pass ``--disable-shared'' to configure. +If you build a shared library and want it to be installed as +``libelf-0.8.13.so'' rather than ``libelf.so.0.8.13'', please use +``./configure --enable-gnu-names''. Other files, e.g. ``libelf.so'' and +``libelf.so.0'' are NOT affected. + +Another configure option, ``--enable-debug'', adds debugging code to +libelf; if you don't run into problems, you will probably not need it. + +When creating an ELF shared library, it is possible to add references +to other shared libraries in the DYNAMIC section of the resulting +file. The make variable DEPSHLIBS contains a list of libraries to add. +It is set to ``-lc'' on Linux systems, and empty otherwise. To +override this setting, use something like ``make DEPSHLIBS="-la -lb"''. +For Linux, `-lc' is included automagically. + +NLS is available and enabled by default. To turn it off, pass the +``--disable-nls'' option to configure. + +Libelf can use gettext or catgets for accessing message +catalogs. If gettext is available AND is part of libc (i.e. not +in a separate library), it will be used. Otherwise, configure +will look for catgets. If you have gettext in a separate +library and want to use it, you should pass the library's name +to configure, e.g. ``LIBS=-lintl ./configure''. Note that you +MUST link your libelf-based applications with -lintl then, +which is probably not what you want, or change the DEPSHLIBS variable +described above (in case you're building a shared library). + +If you have GNU gettext 0.10 installed on your system, and if GNU gettext +runs on top of the catgets interface (rather old Linux systems, using +libc5), configure will refuse to use it and use catgets instead. If you +absolutely want to use GNU gettext, go ahead and rebuild it (which is +IMHO a good idea in general in this case): + + cd .../gettext-0.10 + ac_cv_func_catgets=no ac_cv_func_gettext=no ./configure + make + make install + +After that, return to the libelf build directory, remove +config.cache, and start over. + +*** Large File Support (LFS) applications *** + +Some 32-bit systems support files that are larger than the address space +of the architecture. On these, the `off_t' data type may have 32 or +64 bits, depending on the API you choose. Since off_t is also part of +the libelf API, in particular the Elf_Data and Elf_Arhdr structures, +an application compiled with large file support will need a version of +libelf that has also been compiled with LFS; otherwise, it won't work +correctly. Similarly, a program compiled without LFS needs a library +compiled without LFS. + +Note that libelf is currently unable to process large files on 32-bit +architectures, whether you compile it for LFS or not, for the simple +reason that the files won't fit into the processes' address space. +Therefore, libelf is compiled without LFS by default. It can of course +read and write ELF files for 64-bit architectures, but they will be +limited in length on a 32-bit system. + +You may compile libelf with large file support by setting CPPFLAGS at +configuration time: + + CPPFLAGS=`getconf LFS_CFLAGS` ./configure + +But I really, really recommend you don't, because it breaks binary +compatibility with existing libelf based applications. + +*** 64-bit support *** + +Starting with libelf-0.7.0, libelf also supports 64-bit ELF files. +This is enabled by default unless your system (or your compiler) does +not support 64-bit integers, or lacks 64-bit declarations in . +If you have problems building with 64-bit support, please do + + ./configure --disable-elf64 + +for the moment, and contact me. Please note that I haven't tested 64-bit +support much. There are still some unresolved problems, e.g. IRIX +uses different Elf64_Rel and Elf64_Rela structures (they replaced the +r_info member), and the enumeration values for Elf_Type differ from +the commercial (SVR4) implementation of libelf - they broke binary +compatibility for no good reason, and I'm not willing to follow their +footsteps. The result is that libelf-0.7.* ist upward compatible with +libelf-0.6.4 (as it should be) but INCOMPATIBLE WITH SVR4 LIBELF. If you +have both versions installed, you'd better make sure that you link with +the library that matches the you're #include'ing. + +*** Symbol Versioning *** + +Libelf >= 0.8.0 supports the data structures and definitions used for +symbol versioning on Solaris and Linux, in particular, the Elfxx_Verdef, +Elfxx_Verdaux, Elfxx_Verneed, Elfxx_Vernaux and Elfxx_Versym structures +and the SHT_XXX_verdef, SHT_XXX_verneed and SHT_XXX_versym section types +(where `xx' is either `32' or `64', and `XXX' is either `SUNW' or `GNU'). +Libelf now translates versioning sections to/from their external +representation properly (earlier versions left them in `raw' format, +with the data type set to ELF_T_BYTE). This may cause problems on +systems which use the same (OS-specific) section types for different +purposes. The configure program tries to figure out if your OS uses +versioning; if that check fails, you can use + + ./configure --disable-versioning + +to turn off versioning translation support. + +*** W32 Support *** + +There is now some support for building on W32 systems (requires Microsoft +VC++). In order to build a W32 DLL, cd into the `lib' subdirectory, edit +build.bat if necessary (it needs the path to your compiler binaries) and +run it. If you're lucky, libelf.dll and the import/export libraries will +be built. If not, please drop me a line. + +I tested it on XP Pro (SP2), using VC++ 2005 Express Edition. +Apparently, Visual Studio .NET 2003 works fine as well. + +Various notes regarding the W32 port: + + - When you open() an ELF file, remember to use the O_BINARY flag. + - You may have to add /MD to the linker command line. + +*** Missing things *** + + * There is no documentation. You can use the Solaris + manpages instead (available at http://docs.sun.com/). + The ELF file format is described in several places; + among them Suns "Linker and Libraries Guide" and the + "System V Application Binary Interface" documents; + http://www.caldera.com/developer/devspecs/gabi41.pdf and + http://www.caldera.com/developer/gabi/ are probably good + starting points. Processor-specific documentation is spread + across a number of `Processor Supplement' documents, one + for each architecture; you'll have to use a search engine to + find them. + + * The COFF file format is not understood. This is so obsolete + that it will probably never be implemented. + + * nlist(3) is incomplete; the n_type and n_sclass + members of struct nl are set to zero even if type + (that is, debug) information is available. + + * Libelf does not translate Solaris' `Move' and `Syminfo' + sections. You can read them using elf_getdata(), but you'll + only get raw (untranslated) bytes. + +Changes since 0.8.12: + + * New function elf_getaroff(). + + * Build fixes. + +Changes since 0.8.11: + + * Due to some unfortunate confusion, the elf_getphnum(), + elf_getshnum() and elf_getshstrndx() are not compatible + between libelf implementations. Therefore, the developers + decided to replace them with new functions: elf_getphdrnum(), + elf_getshdrnum() and elf_getshdrstrndx(), which will always + return -1 on failure and 0 on success. Code using the old + interface should be upgraded to increase portability. + +Changes since 0.8.10: + + * Fixed a bug in elf_rawfile(). + * If you use ELF_F_LAYOUT together with ELF_F_LAYOUT_OVERLAP, + elf_update() will now tolerate overlapping sections. + +Changes since 0.8.9: + + * Ported to QNX Neutrino. + * Fixed Windows build errors. + * Parallel (make -j) installation should work now. + + * It's now possible to enable and disable select sanity checks + libelf performs. Currently, this affects the "NUL terminated + string table entry" check performed in elf_strptr(). By + default, the function will return an error if the string + requested is not properly terminated - because some + applications might dump core otherwise. If you configure + libelf with `--disable-sanity-checks', however, the check + (and, in the future, probably others as well) is disabled + by default. You can still turn it on and off at runtime by + setting the LIBELF_SANITY_CHECKS environment variable to + an integer value: + + # disable all sanity checks + export LIBELF_SANITY_CHECKS=0 + + # enable all sanity checks + export LIBELF_SANITY_CHECKS=-1 + + Each bit of the value corresponds to a particular check, + so you could use LIBELF_SANITY_CHECKS=1 to enable only + the elf_strptr() check. You may also use a value in hex + (0x...) or octal (0...) format. + +Changes since 0.8.8: + + * Improved translator for symbol versioning sections. + * The W32 library is now built in the `lib' subdirectory. + * Windows DLLs should work now. + +Changes since 0.8.6: + + * added elf_getphnum(). + * added elf_getshnum(). + * added elf_getshstrndx(). + * added elfx_update_shstrndx(). + * handle interrupted reads/writes more gracefully. + * added (partial) support for unusual e_[ps]hentsize values. + * fixed the bugs introduced in 0.8.7. + +Changes since 0.8.5: + + * added W32 support. + * added workaround for alignment errors in archive members. + * my email address has changed again ;) + +Changes since 0.8.4: + + * elf_strptr() should now work more safely with fragmented + or badly formatted string tables. + +Changes since 0.8.3: + + * Fixed a bug in elf_update() that was introduced in 0.8.3. + +Changes since 0.8.2: + + * Should compile on MacOSX now. + + * Can read and write files with more than 65280 sections + + * Tries to handle 64-bit ELF files that use 8-byte hash table + entries. In particular, libelf tries to guess the data type in + elf_getdata(), and doesn't override sh_entsize in elf_update() + any longer. If you want the library to pick the entry size, + you must set its value to 0 before you call elf_update(). + + * No longer dumps core in elf_update() when a versioning section + has no data. Instead, it returns an error message. Note that + you're supposed to provide a valid d_buf for any section, unless + it's empty or has SHT_NOBITS type. + + * Building a shared library is now the default (if supported). + +Changes since 0.8.0: + + * Corrected typo in lib/{32,64}.xlatetof.c that sometimes + caused a compilation failure. + + * Use open(name, O_RDONLY|O_BINARY) in lib/nlist.c. + +Changes since 0.7.0: + + * I implemented the gelf_* interface, as found on Solaris. + I don't know whether it's compatible -- the Solaris manpage + isn't very specific, so I had to guess return values etc. in + some cases. + + * Added elf{32,64}_checksum (supposed to be compatible with + Solaris). + + * Added symbol versioning support. + +Changes since 0.6.4: + + * Fixed configure for IRIX systems + * Added check for truncated archive members + * Added check for misaligned SHDR/PHDR tables + * Support for building libelf together with GNU libc + * Added elf_memory(3) + * Added 64-bit support + +Changes since 0.5.2: + + * some bug fixes + * mmap support + * new directory layout + * There is a new function, elf_delscn(), that deletes + a section from an ELF file. It also adjusts the + sh_link and sh_info members in the section header + table, if (and ONLY if) the ELF standard indicates + that these values are section indices. References + to the deleted section will be cleared, so be careful. + * my email address has changed ;) + +Where to get libelf: + + ftp://ftp.ibiblio.org/pub/Linux/libs/ + http://www.mr511.de/software/ + +Michael "Tired" Riepe + diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/VERSION b/src/common/genericBinaryFiles/elf/libelfWin32/VERSION new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/VERSION @@ -0,0 +1,1 @@ +0.8.13 diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/byteswap.h b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/byteswap.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/byteswap.h @@ -0,0 +1,95 @@ +/* +byteswap.h - functions and macros for byte swapping. +Copyright (C) 1995 - 2001 Michael Riepe + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ + +/* @(#) $Id: byteswap.h,v 1.7 2008/05/23 08:15:34 michael Exp $ */ + +#ifndef _BYTESWAP_H +#define _BYTESWAP_H + +#define lu(from,i,s) (((__libelf_u32_t)((unsigned char*)(from))[i])<<(s)) +#define li(from,i,s) (((__libelf_i32_t)(( signed char*)(from))[i])<<(s)) + +#define __load_u16L(from) ((__libelf_u32_t) \ + (lu(from,1,8) | lu(from,0,0))) +#define __load_u16M(from) ((__libelf_u32_t) \ + (lu(from,0,8) | lu(from,1,0))) +#define __load_i16L(from) ((__libelf_i32_t) \ + (li(from,1,8) | lu(from,0,0))) +#define __load_i16M(from) ((__libelf_i32_t) \ + (li(from,0,8) | lu(from,1,0))) + +#define __load_u32L(from) ((__libelf_u32_t) \ + (lu(from,3,24) | lu(from,2,16) | lu(from,1,8) | lu(from,0,0))) +#define __load_u32M(from) ((__libelf_u32_t) \ + (lu(from,0,24) | lu(from,1,16) | lu(from,2,8) | lu(from,3,0))) +#define __load_i32L(from) ((__libelf_i32_t) \ + (li(from,3,24) | lu(from,2,16) | lu(from,1,8) | lu(from,0,0))) +#define __load_i32M(from) ((__libelf_i32_t) \ + (li(from,0,24) | lu(from,1,16) | lu(from,2,8) | lu(from,3,0))) + +#define su(to,i,v,s) (((char*)(to))[i]=((__libelf_u32_t)(v)>>(s))) +#define si(to,i,v,s) (((char*)(to))[i]=((__libelf_i32_t)(v)>>(s))) + +#define __store_u16L(to,v) \ + (su(to,1,v,8), su(to,0,v,0)) +#define __store_u16M(to,v) \ + (su(to,0,v,8), su(to,1,v,0)) +#define __store_i16L(to,v) \ + (si(to,1,v,8), si(to,0,v,0)) +#define __store_i16M(to,v) \ + (si(to,0,v,8), si(to,1,v,0)) + +#define __store_u32L(to,v) \ + (su(to,3,v,24), su(to,2,v,16), su(to,1,v,8), su(to,0,v,0)) +#define __store_u32M(to,v) \ + (su(to,0,v,24), su(to,1,v,16), su(to,2,v,8), su(to,3,v,0)) +#define __store_i32L(to,v) \ + (si(to,3,v,24), si(to,2,v,16), si(to,1,v,8), si(to,0,v,0)) +#define __store_i32M(to,v) \ + (si(to,0,v,24), si(to,1,v,16), si(to,2,v,8), si(to,3,v,0)) + +#if __LIBELF64 + +/* + * conversion functions from swap64.c + */ +extern __libelf_u64_t _elf_load_u64L(const unsigned char *from); +extern __libelf_u64_t _elf_load_u64M(const unsigned char *from); +extern __libelf_i64_t _elf_load_i64L(const unsigned char *from); +extern __libelf_i64_t _elf_load_i64M(const unsigned char *from); +extern void _elf_store_u64L(unsigned char *to, __libelf_u64_t v); +extern void _elf_store_u64M(unsigned char *to, __libelf_u64_t v); +extern void _elf_store_i64L(unsigned char *to, __libelf_u64_t v); +extern void _elf_store_i64M(unsigned char *to, __libelf_u64_t v); + +/* + * aliases for existing conversion code + */ +#define __load_u64L _elf_load_u64L +#define __load_u64M _elf_load_u64M +#define __load_i64L _elf_load_i64L +#define __load_i64M _elf_load_i64M +#define __store_u64L _elf_store_u64L +#define __store_u64M _elf_store_u64M +#define __store_i64L _elf_store_i64L +#define __store_i64M _elf_store_i64M + +#endif /* __LIBELF64 */ + +#endif /* _BYTESWAP_H */ diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/elf_repl.h b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/elf_repl.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/elf_repl.h @@ -0,0 +1,1002 @@ +/* + * elf_repl.h - public header file for systems that lack it. + * Copyright (C) 1995 - 2006 Michael Riepe + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* @(#) $Id: elf_repl.h,v 1.22 2009/11/01 13:04:19 michael Exp $ */ + +/* + * NEVER INCLUDE THIS FILE DIRECTLY - USE INSTEAD! + */ + +#ifndef _ELF_REPL_H +#define _ELF_REPL_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Scalar data types + */ +typedef __libelf_u32_t Elf32_Addr; +typedef __libelf_u16_t Elf32_Half; +typedef __libelf_u32_t Elf32_Off; +typedef __libelf_i32_t Elf32_Sword; +typedef __libelf_u32_t Elf32_Word; + +#define ELF32_FSZ_ADDR 4 +#define ELF32_FSZ_HALF 2 +#define ELF32_FSZ_OFF 4 +#define ELF32_FSZ_SWORD 4 +#define ELF32_FSZ_WORD 4 + +#if __LIBELF64 + +typedef __libelf_u64_t Elf64_Addr; +typedef __libelf_u16_t Elf64_Half; +typedef __libelf_u64_t Elf64_Off; +typedef __libelf_i32_t Elf64_Sword; +typedef __libelf_u32_t Elf64_Word; +typedef __libelf_i64_t Elf64_Sxword; +typedef __libelf_u64_t Elf64_Xword; + +#define ELF64_FSZ_ADDR 8 +#define ELF64_FSZ_HALF 2 +#define ELF64_FSZ_OFF 8 +#define ELF64_FSZ_SWORD 4 +#define ELF64_FSZ_WORD 4 +#define ELF64_FSZ_SXWORD 8 +#define ELF64_FSZ_XWORD 8 + +/* + * Blame Sun for this... + */ +typedef __libelf_u64_t Elf64_Lword; +typedef __libelf_u64_t Elf32_Lword; + +#endif /* __LIBELF64 */ + +/* + * ELF header + */ +#define EI_NIDENT 16 + +typedef struct { + unsigned char e_ident[EI_NIDENT]; + Elf32_Half e_type; + Elf32_Half e_machine; + Elf32_Word e_version; + Elf32_Addr e_entry; + Elf32_Off e_phoff; + Elf32_Off e_shoff; + Elf32_Word e_flags; + Elf32_Half e_ehsize; + Elf32_Half e_phentsize; + Elf32_Half e_phnum; + Elf32_Half e_shentsize; + Elf32_Half e_shnum; + Elf32_Half e_shstrndx; +} Elf32_Ehdr; + +#if __LIBELF64 +typedef struct { + unsigned char e_ident[EI_NIDENT]; + Elf64_Half e_type; + Elf64_Half e_machine; + Elf64_Word e_version; + Elf64_Addr e_entry; + Elf64_Off e_phoff; + Elf64_Off e_shoff; + Elf64_Word e_flags; + Elf64_Half e_ehsize; + Elf64_Half e_phentsize; + Elf64_Half e_phnum; + Elf64_Half e_shentsize; + Elf64_Half e_shnum; + Elf64_Half e_shstrndx; +} Elf64_Ehdr; +#endif /* __LIBELF64 */ + +/* + * e_ident + */ +#define EI_MAG0 0 +#define EI_MAG1 1 +#define EI_MAG2 2 +#define EI_MAG3 3 +#define EI_CLASS 4 +#define EI_DATA 5 +#define EI_VERSION 6 +#define EI_OSABI 7 +#define EI_ABIVERSION 8 +#define EI_PAD 9 + +#define ELFMAG0 0x7f +#define ELFMAG1 'E' +#define ELFMAG2 'L' +#define ELFMAG3 'F' +#define ELFMAG "\177ELF" +#define SELFMAG 4 + +/* + * e_ident[EI_CLASS] + */ +#define ELFCLASSNONE 0 +#define ELFCLASS32 1 +#define ELFCLASS64 2 +#define ELFCLASSNUM 3 + +/* + * e_ident[EI_DATA] + */ +#define ELFDATANONE 0 +#define ELFDATA2LSB 1 +#define ELFDATA2MSB 2 +#define ELFDATANUM 3 + +/* + * e_ident[EI_OSABI] + */ +#define ELFOSABI_NONE 0 /* No extensions or unspecified */ +#define ELFOSABI_SYSV ELFOSABI_NONE +#define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */ +#define ELFOSABI_NETBSD 2 /* NetBSD */ +#define ELFOSABI_LINUX 3 /* Linux */ +#define ELFOSABI_SOLARIS 6 /* Sun Solaris */ +#define ELFOSABI_AIX 7 /* AIX */ +#define ELFOSABI_IRIX 8 /* IRIX */ +#define ELFOSABI_FREEBSD 9 /* FreeBSD */ +#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */ +#define ELFOSABI_MODESTO 11 /* Novell Modesto */ +#define ELFOSABI_OPENBSD 12 /* Open BSD */ +#define ELFOSABI_OPENVMS 13 /* Open VMS */ +#define ELFOSABI_NSK 14 /* Hewlett-Packard Non-Stop Kernel */ +#define ELFOSABI_AROS 15 /* Amiga Research OS */ +/* these are probably obsolete: */ +#define ELFOSABI_ARM_AEABI 64 /* ARM EABI */ +#define ELFOSABI_ARM 97 /* ARM */ +#define ELFOSABI_STANDALONE 255 /* standalone (embedded) application */ + + +/* + * e_type + */ +#define ET_NONE 0 +#define ET_REL 1 +#define ET_EXEC 2 +#define ET_DYN 3 +#define ET_CORE 4 +#define ET_NUM 5 +#define ET_LOOS 0xfe00 +#define ET_HIOS 0xfeff +#define ET_LOPROC 0xff00 +#define ET_HIPROC 0xffff + +/* + * e_machine + */ +#define EM_NONE 0 /* No machine */ +#define EM_M32 1 /* AT&T WE 32100 */ +#define EM_SPARC 2 /* SPARC */ +#define EM_386 3 /* Intel 80386 */ +#define EM_68K 4 /* Motorola 68000 */ +#define EM_88K 5 /* Motorola 88000 */ +#define EM_486 6 /* Intel i486 (DO NOT USE THIS ONE) */ +#define EM_860 7 /* Intel 80860 */ +#define EM_MIPS 8 /* MIPS I Architecture */ +#define EM_S370 9 /* IBM System/370 Processor */ +#define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */ +#define EM_SPARC64 11 /* SPARC 64-bit */ +#define EM_PARISC 15 /* Hewlett-Packard PA-RISC */ +#define EM_VPP500 17 /* Fujitsu VPP500 */ +#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ +#define EM_960 19 /* Intel 80960 */ +#define EM_PPC 20 /* PowerPC */ +#define EM_PPC64 21 /* 64-bit PowerPC */ +#define EM_S390 22 /* IBM System/390 Processor */ +#define EM_V800 36 /* NEC V800 */ +#define EM_FR20 37 /* Fujitsu FR20 */ +#define EM_RH32 38 /* TRW RH-32 */ +#define EM_RCE 39 /* Motorola RCE */ +#define EM_ARM 40 /* Advanced RISC Machines ARM */ +#define EM_FAKE_ALPHA 41 /* Digital Alpha */ +#define EM_SH 42 /* Hitachi SH */ +#define EM_SPARCV9 43 /* SPARC Version 9 */ +#define EM_TRICORE 44 /* Siemens TriCore embedded processor */ +#define EM_ARC 45 /* Argonaut RISC Core, Argonaut Technologies Inc. */ +#define EM_H8_300 46 /* Hitachi H8/300 */ +#define EM_H8_300H 47 /* Hitachi H8/300H */ +#define EM_H8S 48 /* Hitachi H8S */ +#define EM_H8_500 49 /* Hitachi H8/500 */ +#define EM_IA_64 50 /* Intel IA-64 processor architecture */ +#define EM_MIPS_X 51 /* Stanford MIPS-X */ +#define EM_COLDFIRE 52 /* Motorola ColdFire */ +#define EM_68HC12 53 /* Motorola M68HC12 */ +#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator */ +#define EM_PCP 55 /* Siemens PCP */ +#define EM_NCPU 56 /* Sony nCPU embedded RISC processor */ +#define EM_NDR1 57 /* Denso NDR1 microprocessor */ +#define EM_STARCORE 58 /* Motorola Star*Core processor */ +#define EM_ME16 59 /* Toyota ME16 processor */ +#define EM_ST100 60 /* STMicroelectronics ST100 processor */ +#define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded processor family */ +#define EM_X86_64 62 /* AMD x86-64 architecture */ +#define EM_AMD64 EM_X86_64 +#define EM_PDSP 63 /* Sony DSP Processor */ +#define EM_FX66 66 /* Siemens FX66 microcontroller */ +#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 bit microcontroller */ +#define EM_ST7 68 /* STMicroelectronics ST7 8-bit microcontroller */ +#define EM_68HC16 69 /* Motorola MC68HC16 Microcontroller */ +#define EM_68HC11 70 /* Motorola MC68HC11 Microcontroller */ +#define EM_68HC08 71 /* Motorola MC68HC08 Microcontroller */ +#define EM_68HC05 72 /* Motorola MC68HC05 Microcontroller */ +#define EM_SVX 73 /* Silicon Graphics SVx */ +#define EM_ST19 74 /* STMicroelectronics ST19 8-bit microcontroller */ +#define EM_VAX 75 /* Digital VAX */ +#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ +#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */ +#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ +#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ +#define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */ +#define EM_HUANY 81 /* Harvard University machine-independent object files */ +#define EM_PRISM 82 /* SiTera Prism */ +#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ +#define EM_FR30 84 /* Fujitsu FR30 */ +#define EM_D10V 85 /* Mitsubishi D10V */ +#define EM_D30V 86 /* Mitsubishi D30V */ +#define EM_V850 87 /* NEC v850 */ +#define EM_M32R 88 /* Mitsubishi M32R */ +#define EM_MN10300 89 /* Matsushita MN10300 */ +#define EM_MN10200 90 /* Matsushita MN10200 */ +#define EM_PJ 91 /* picoJava */ +#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ +#define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ +#define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ +#define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor */ +#define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose Processor */ +#define EM_NS32K 97 /* National Semiconductor 32000 series */ +#define EM_TPC 98 /* Tenor Network TPC processor */ +#define EM_SNP1K 99 /* Trebia SNP 1000 processor */ +#define EM_ST200 100 /* STMicroelectronics (www.st.com) ST200 microcontroller */ +#define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family */ +#define EM_MAX 102 /* MAX Processor */ +#define EM_CR 103 /* National Semiconductor CompactRISC microprocessor */ +#define EM_F2MC16 104 /* Fujitsu F2MC16 */ +#define EM_MSP430 105 /* Texas Instruments embedded microcontroller msp430 */ +#define EM_BLACKFIN 106 /* Analog Devices Blackfin (DSP) processor */ +#define EM_SE_C33 107 /* S1C33 Family of Seiko Epson processors */ +#define EM_SEP 108 /* Sharp embedded microprocessor */ +#define EM_ARCA 109 /* Arca RISC Microprocessor */ +#define EM_UNICORE 110 /* Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University */ +#define EM_AARCH64 183 /* ARM AARCH64 */ +#define EM_TILEPRO 188 /* Tilera TILEPro */ +#define EM_MICROBLAZE 189 /* Xilinx MicroBlaze */ +#define EM_TILEGX 191 /* Tilera TILE-Gx */ +#define EM_NUM 192 + + +/* + * e_ident[EI_VERSION], e_version + */ +#define EV_NONE 0 +#define EV_CURRENT 1 +#define EV_NUM 2 + +/* + * Section header + */ +typedef struct { + Elf32_Word sh_name; + Elf32_Word sh_type; + Elf32_Word sh_flags; + Elf32_Addr sh_addr; + Elf32_Off sh_offset; + Elf32_Word sh_size; + Elf32_Word sh_link; + Elf32_Word sh_info; + Elf32_Word sh_addralign; + Elf32_Word sh_entsize; +} Elf32_Shdr; + +#if __LIBELF64 +typedef struct { + Elf64_Word sh_name; + Elf64_Word sh_type; + Elf64_Xword sh_flags; + Elf64_Addr sh_addr; + Elf64_Off sh_offset; + Elf64_Xword sh_size; + Elf64_Word sh_link; + Elf64_Word sh_info; + Elf64_Xword sh_addralign; + Elf64_Xword sh_entsize; +} Elf64_Shdr; +#endif /* __LIBELF64 */ + +/* + * Special section indices + */ +#define SHN_UNDEF 0 +#define SHN_LORESERVE 0xff00 +#define SHN_LOPROC 0xff00 +#define SHN_HIPROC 0xff1f +#define SHN_LOOS 0xff20 +#define SHN_HIOS 0xff3f +#define SHN_ABS 0xfff1 +#define SHN_COMMON 0xfff2 +#define SHN_XINDEX 0xffff +#define SHN_HIRESERVE 0xffff + +/* + * sh_type + */ +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 +#define SHT_DYNAMIC 6 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_SHLIB 10 +#define SHT_DYNSYM 11 +#define SHT_INIT_ARRAY 14 +#define SHT_FINI_ARRAY 15 +#define SHT_PREINIT_ARRAY 16 +#define SHT_GROUP 17 +#define SHT_SYMTAB_SHNDX 18 +#define SHT_NUM 19 +#define SHT_LOOS 0x60000000 +#define SHT_HIOS 0x6fffffff +#define SHT_LOPROC 0x70000000 +#define SHT_HIPROC 0x7fffffff +#define SHT_LOUSER 0x80000000 +#define SHT_HIUSER 0xffffffff + +/* + * Solaris extensions + */ +#define SHT_LOSUNW 0x6ffffff4 +#define SHT_SUNW_dof 0x6ffffff4 +#define SHT_SUNW_cap 0x6ffffff5 +#define SHT_SUNW_SIGNATURE 0x6ffffff6 +#define SHT_SUNW_ANNOTATE 0x6ffffff7 +#define SHT_SUNW_DEBUGSTR 0x6ffffff8 +#define SHT_SUNW_DEBUG 0x6ffffff9 +#define SHT_SUNW_move 0x6ffffffa +#define SHT_SUNW_COMDAT 0x6ffffffb +#define SHT_SUNW_syminfo 0x6ffffffc +#define SHT_SUNW_verdef 0x6ffffffd +#define SHT_SUNW_verneed 0x6ffffffe +#define SHT_SUNW_versym 0x6fffffff +#define SHT_HISUNW 0x6fffffff + +#define SHT_SPARC_GOTDATA 0x70000000 +#define SHT_AMD64_UNWIND 0x70000001 + +/* + * GNU extensions + */ +#define SHT_GNU_verdef 0x6ffffffd +#define SHT_GNU_verneed 0x6ffffffe +#define SHT_GNU_versym 0x6fffffff + +/* + * sh_flags + */ +#define SHF_WRITE 0x1 +#define SHF_ALLOC 0x2 +#define SHF_EXECINSTR 0x4 +#define SHF_MERGE 0x10 +#define SHF_STRINGS 0x20 +#define SHF_INFO_LINK 0x40 +#define SHF_LINK_ORDER 0x80 +#define SHF_OS_NONCONFORMING 0x100 +#define SHF_GROUP 0x200 +#define SHF_TLS 0x400 +#define SHF_MASKOS 0x0ff00000 +#define SHF_MASKPROC 0xf0000000 + +/* + * Solaris extensions + */ +#define SHF_AMD64_LARGE 0x10000000 +#define SHF_ORDERED 0x40000000 +#define SHF_EXCLUDE 0x80000000 + +/* + * Section group flags + */ +#define GRP_COMDAT 0x1 +#define GRP_MASKOS 0x0ff00000 +#define GRP_MASKPROC 0xf0000000 + +/* + * Symbol table + */ +typedef struct { + Elf32_Word st_name; + Elf32_Addr st_value; + Elf32_Word st_size; + unsigned char st_info; + unsigned char st_other; + Elf32_Half st_shndx; +} Elf32_Sym; + +#if __LIBELF64 +typedef struct { + Elf64_Word st_name; + unsigned char st_info; + unsigned char st_other; + Elf64_Half st_shndx; + Elf64_Addr st_value; + Elf64_Xword st_size; +} Elf64_Sym; +#endif /* __LIBELF64 */ + +/* + * Special symbol indices + */ +#define STN_UNDEF 0 + +/* + * Macros for manipulating st_info + */ +#define ELF32_ST_BIND(i) ((i)>>4) +#define ELF32_ST_TYPE(i) ((i)&0xf) +#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) + +#if __LIBELF64 +#define ELF64_ST_BIND(i) ((i)>>4) +#define ELF64_ST_TYPE(i) ((i)&0xf) +#define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) +#endif /* __LIBELF64 */ + +/* + * Symbol binding + */ +#define STB_LOCAL 0 +#define STB_GLOBAL 1 +#define STB_WEAK 2 +#define STB_NUM 3 +#define STB_LOOS 10 +#define STB_HIOS 12 +#define STB_LOPROC 13 +#define STB_HIPROC 15 + +/* + * Symbol types + */ +#define STT_NOTYPE 0 +#define STT_OBJECT 1 +#define STT_FUNC 2 +#define STT_SECTION 3 +#define STT_FILE 4 +#define STT_COMMON 5 +#define STT_TLS 6 +#define STT_NUM 7 +#define STT_LOOS 10 +#define STT_HIOS 12 +#define STT_LOPROC 13 +#define STT_HIPROC 15 + +/* + * Macros for manipulating st_other + */ +#define ELF32_ST_VISIBILITY(o) ((o)&0x3) +#if __LIBELF64 +#define ELF64_ST_VISIBILITY(o) ((o)&0x3) +#endif /* __LIBELF64 */ + +/* + * Symbol visibility + */ +#define STV_DEFAULT 0 +#define STV_INTERNAL 1 +#define STV_HIDDEN 2 +#define STV_PROTECTED 3 + +/* + * Relocation + */ +typedef struct { + Elf32_Addr r_offset; + Elf32_Word r_info; +} Elf32_Rel; + +typedef struct { + Elf32_Addr r_offset; + Elf32_Word r_info; + Elf32_Sword r_addend; +} Elf32_Rela; + +#if __LIBELF64 +typedef struct { + Elf64_Addr r_offset; + Elf64_Xword r_info; +} Elf64_Rel; + +typedef struct { + Elf64_Addr r_offset; + Elf64_Xword r_info; + Elf64_Sxword r_addend; +} Elf64_Rela; +#endif /* __LIBELF64 */ + +/* + * Macros for manipulating r_info + */ +#define ELF32_R_SYM(i) ((i)>>8) +#define ELF32_R_TYPE(i) ((unsigned char)(i)) +#define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t)) + +#if __LIBELF64 +#define ELF64_R_SYM(i) ((Elf64_Xword)(i)>>32) +#define ELF64_R_TYPE(i) ((i)&0xffffffffL) +#define ELF64_R_INFO(s,t) (((Elf64_Xword)(s)<<32)+((t)&0xffffffffL)) +#endif /* __LIBELF64 */ + +/* + * Note entry header + */ +typedef struct { + Elf32_Word n_namesz; /* name size */ + Elf32_Word n_descsz; /* descriptor size */ + Elf32_Word n_type; /* descriptor type */ +} Elf32_Nhdr; + +#if __LIBELF64 +/* Solaris and GNU use this layout. Be compatible. */ +/* XXX: Latest ELF specs say it's 64-bit!!! */ +typedef struct { + Elf64_Word n_namesz; /* name size */ + Elf64_Word n_descsz; /* descriptor size */ + Elf64_Word n_type; /* descriptor type */ +} Elf64_Nhdr; +#endif /* __LIBELF64 */ + +/* + * Well-known descriptor types for ET_CORE files + */ +#define NT_PRSTATUS 1 +#define NT_PRFPREG 2 +#define NT_PRPSINFO 3 + +/* + * Program header + */ +typedef struct { + Elf32_Word p_type; + Elf32_Off p_offset; + Elf32_Addr p_vaddr; + Elf32_Addr p_paddr; + Elf32_Word p_filesz; + Elf32_Word p_memsz; + Elf32_Word p_flags; + Elf32_Word p_align; +} Elf32_Phdr; + +#if __LIBELF64 +typedef struct { + Elf64_Word p_type; + Elf64_Word p_flags; + Elf64_Off p_offset; + Elf64_Addr p_vaddr; + Elf64_Addr p_paddr; + Elf64_Xword p_filesz; + Elf64_Xword p_memsz; + Elf64_Xword p_align; +} Elf64_Phdr; +#endif /* __LIBELF64 */ + +/* + * Special numbers + */ +#define PN_XNUM 0xffff + +/* + * p_type + */ +#define PT_NULL 0 +#define PT_LOAD 1 +#define PT_DYNAMIC 2 +#define PT_INTERP 3 +#define PT_NOTE 4 +#define PT_SHLIB 5 +#define PT_PHDR 6 +#define PT_TLS 7 +#define PT_NUM 8 +#define PT_LOOS 0x60000000 +#define PT_HIOS 0x6fffffff +#define PT_LOPROC 0x70000000 +#define PT_HIPROC 0x7fffffff + +/* + * Solaris extensions + */ + +#define PT_SUNW_UNWIND 0x6464e550 +#define PT_LOSUNW 0x6ffffffa +#define PT_SUNWBSS 0x6ffffffa +#define PT_SUNWSTACK 0x6ffffffb +#define PT_SUNWDTRACE 0x6ffffffc +#define PT_SUNWCAP 0x6ffffffd +#define PT_HISUNW 0x6fffffff + +/* + * p_flags + */ +#define PF_X 0x1 +#define PF_W 0x2 +#define PF_R 0x4 +#define PF_MASKOS 0x0ff00000 +#define PF_MASKPROC 0xf0000000 + +/* + * Dynamic structure + */ +typedef struct { + Elf32_Sword d_tag; + union { + Elf32_Word d_val; + Elf32_Addr d_ptr; + } d_un; +} Elf32_Dyn; + +#if __LIBELF64 +typedef struct { + Elf64_Sxword d_tag; + union { + Elf64_Xword d_val; + Elf64_Addr d_ptr; + } d_un; +} Elf64_Dyn; +#endif /* __LIBELF64 */ + +/* + * Dynamic array tags + */ + /* d_un exec shared */ +#define DT_NULL 0 /* ign. mand. mand. */ +#define DT_NEEDED 1 /* d_val opt. opt. */ +#define DT_PLTRELSZ 2 /* d_val opt. opt. */ +#define DT_PLTGOT 3 /* d_ptr opt. opt. */ +#define DT_HASH 4 /* d_ptr mand. mand. */ +#define DT_STRTAB 5 /* d_ptr mand. mand. */ +#define DT_SYMTAB 6 /* d_ptr mand. mand. */ +#define DT_RELA 7 /* d_ptr mand. opt. */ +#define DT_RELASZ 8 /* d_val mand. opt. */ +#define DT_RELAENT 9 /* d_val mand. opt. */ +#define DT_STRSZ 10 /* d_val mand. mand. */ +#define DT_SYMENT 11 /* d_val mand. mand. */ +#define DT_INIT 12 /* d_ptr opt. opt. */ +#define DT_FINI 13 /* d_ptr opt. opt. */ +#define DT_SONAME 14 /* d_val ign. opt. */ +#define DT_RPATH 15 /* d_val opt. ign. */ +#define DT_SYMBOLIC 16 /* ign. ign. opt. */ +#define DT_REL 17 /* d_ptr mand. opt. */ +#define DT_RELSZ 18 /* d_val mand. opt. */ +#define DT_RELENT 19 /* d_val mand. opt. */ +#define DT_PLTREL 20 /* d_val opt. opt. */ +#define DT_DEBUG 21 /* d_ptr opt. ign. */ +#define DT_TEXTREL 22 /* ign. opt. opt. */ +#define DT_JMPREL 23 /* d_ptr opt. opt. */ +#define DT_BIND_NOW 24 /* ign. opt. opt. */ +#define DT_INIT_ARRAY 25 /* d_ptr opt. opt. */ +#define DT_FINI_ARRAY 26 /* d_ptr opt. opt. */ +#define DT_INIT_ARRAYSZ 27 /* d_val opt. opt. */ +#define DT_FINI_ARRAYSZ 28 /* d_val opt. opt. */ +#define DT_RUNPATH 29 /* d_val opt. opt. */ +#define DT_FLAGS 30 /* d_val opt. opt. */ +#define DT_ENCODING 32 /* odd/even encoding rule starts here */ +#define DT_PREINIT_ARRAY 32 /* d_ptr opt. ign. */ +#define DT_PREINIT_ARRAYSZ 33 /* d_val opt. ign. */ +#define DT_NUM 34 +#define DT_LOOS 0x6000000D +#define DT_HIOS 0x6ffff000 +#define DT_LOPROC 0x70000000 +#define DT_HIPROC 0x7fffffff + +/* + * DT_FLAGS values + */ +#define DF_ORIGIN 0x1 +#define DF_SYMBOLIC 0x2 +#define DF_TEXTREL 0x4 +#define DF_BIND_NOW 0x8 +#define DF_STATIC_TLS 0x10 + +/* + * Solaris extensions + */ +#define DT_VALRNGLO 0x6ffffd00 +#define DT_CHECKSUM 0x6ffffdf8 +#define DT_PLTPADSZ 0x6ffffdf9 +#define DT_MOVEENT 0x6ffffdfa +#define DT_MOVESZ 0x6ffffdfb +#define DT_FEATURE_1 0x6ffffdfc +#define DT_POSFLAG_1 0x6ffffdfd +#define DT_SYMINSZ 0x6ffffdfe +#define DT_SYMINENT 0x6ffffdff +#define DT_VALRNGHI 0x6ffffdff + +#define DT_ADDRRNGLO 0x6ffffe00 +#define DT_CONFIG 0x6ffffefa +#define DT_DEPAUDIT 0x6ffffefb +#define DT_AUDIT 0x6ffffefc +#define DT_PLTPAD 0x6ffffefd +#define DT_MOVETAB 0x6ffffefe +#define DT_SYMINFO 0x6ffffeff +#define DT_ADDRRNGHI 0x6ffffeff + +#define DT_RELACOUNT 0x6ffffff9 +#define DT_RELCOUNT 0x6ffffffa +#define DT_FLAGS_1 0x6ffffffb +#define DT_VERDEF 0x6ffffffc +#define DT_VERDEFNUM 0x6ffffffd +#define DT_VERNEED 0x6ffffffe +#define DT_VERNEEDNUM 0x6fffffff + +#define DT_AUXILIARY 0x7ffffffd +#define DT_USED 0x7ffffffe +#define DT_FILTER 0x7fffffff + +/* + * GNU extensions + */ +#define DT_VERSYM 0x6ffffff0 + +/* + * DT_FEATURE_1 values + */ +#define DTF_1_PARINIT 0x1 +#define DTF_1_CONFEXP 0x2 + +/* + * DT_POSFLAG_1 values + */ +#define DF_P1_LAZYLOAD 0x1 +#define DF_P1_GROUPPERM 0x2 + +/* + * DT_FLAGS_1 values + */ +#define DF_1_NOW 0x00000001 +#define DF_1_GLOBAL 0x00000002 +#define DF_1_GROUP 0x00000004 +#define DF_1_NODELETE 0x00000008 +#define DF_1_LOADFLTR 0x00000010 +#define DF_1_INITFIRST 0x00000020 +#define DF_1_NOOPEN 0x00000040 +#define DF_1_ORIGIN 0x00000080 +#define DF_1_DIRECT 0x00000100 +#define DF_1_TRANS 0x00000200 +#define DF_1_INTERPOSE 0x00000400 +#define DF_1_NODEFLIB 0x00000800 +#define DF_1_NODUMP 0x00001000 +#define DF_1_CONFALT 0x00002000 +#define DF_1_ENDFILTEE 0x00004000 +#define DF_1_DISPRELDNE 0x00008000 +#define DF_1_DISPRELPND 0x00010000 + +/* + * Syminfo structure + */ +typedef struct { + Elf32_Half si_boundto; + Elf32_Half si_flags; +} Elf32_Syminfo; + +#if __LIBELF64 +typedef struct { + Elf64_Half si_boundto; + Elf64_Half si_flags; +} Elf64_Syminfo; +#endif /* __LIBELF64 */ + +/* + * Syminfo version (stored in unused first entry) + */ +#define SYMINFO_NONE 0 +#define SYMINFO_CURRENT 1 +#define SYMINFO_NUM 2 + +/* + * si_boundto special values + */ +#define SYMINFO_BT_LOWRESERVE 0xff00 +#define SYMINFO_BT_PARENT 0xfffe /* bound to parent */ +#define SYMINFO_BT_SELF 0xffff /* bound to self */ + +/* + * si_flags + */ +#define SYMINFO_FLG_DIRECT 0x01 /* bound to an object */ +#define SYMINFO_FLG_PASSTHRU 0x02 /* pass-thru symbol */ +#define SYMINFO_FLG_COPY 0x04 /* result of a copy relocation */ +#define SYMINFO_FLG_LAZYLOAD 0x08 /* bound to lazy-loaded object */ + +/* + * Version definitions + */ +typedef struct { + Elf32_Half vd_version; + Elf32_Half vd_flags; + Elf32_Half vd_ndx; + Elf32_Half vd_cnt; + Elf32_Word vd_hash; + Elf32_Word vd_aux; + Elf32_Word vd_next; +} Elf32_Verdef; + +typedef struct { + Elf32_Word vda_name; + Elf32_Word vda_next; +} Elf32_Verdaux; + +typedef struct { + Elf32_Half vn_version; + Elf32_Half vn_cnt; + Elf32_Word vn_file; + Elf32_Word vn_aux; + Elf32_Word vn_next; +} Elf32_Verneed; + +typedef struct { + Elf32_Word vna_hash; + Elf32_Half vna_flags; + Elf32_Half vna_other; + Elf32_Word vna_name; + Elf32_Word vna_next; +} Elf32_Vernaux; + +typedef Elf32_Half Elf32_Versym; + +#if __LIBELF64 + +typedef struct { + Elf64_Half vd_version; + Elf64_Half vd_flags; + Elf64_Half vd_ndx; + Elf64_Half vd_cnt; + Elf64_Word vd_hash; + Elf64_Word vd_aux; + Elf64_Word vd_next; +} Elf64_Verdef; + +typedef struct { + Elf64_Word vda_name; + Elf64_Word vda_next; +} Elf64_Verdaux; + +typedef struct { + Elf64_Half vn_version; + Elf64_Half vn_cnt; + Elf64_Word vn_file; + Elf64_Word vn_aux; + Elf64_Word vn_next; +} Elf64_Verneed; + +typedef struct { + Elf64_Word vna_hash; + Elf64_Half vna_flags; + Elf64_Half vna_other; + Elf64_Word vna_name; + Elf64_Word vna_next; +} Elf64_Vernaux; + +typedef Elf64_Half Elf64_Versym; + +#endif /* __LIBELF64 */ + +/* + * vd_version + */ +#define VER_DEF_NONE 0 +#define VER_DEF_CURRENT 1 +#define VER_DEF_NUM 2 + +/* + * vn_version + */ +#define VER_NEED_NONE 0 +#define VER_NEED_CURRENT 1 +#define VER_NEED_NUM 2 + +/* + * vd_flags / vna_flags + */ +#define VER_FLG_BASE 0x1 /* vd_flags only */ +#define VER_FLG_WEAK 0x2 + +/* + * Elf*_Versym special values + */ +#define VER_NDX_LOCAL 0 +#define VER_NDX_GLOBAL 1 + +/* + * Solaris extensions + */ + +/* + * Move section + */ +#if __LIBELF64 + +typedef struct { + Elf32_Lword m_value; + Elf32_Word m_info; + Elf32_Word m_poffset; + Elf32_Half m_repeat; + Elf32_Half m_stride; +} Elf32_Move; + +typedef struct { + Elf64_Lword m_value; + Elf64_Xword m_info; + Elf64_Xword m_poffset; + Elf64_Half m_repeat; + Elf64_Half m_stride; +} Elf64_Move; + +#define ELF32_M_SYM(info) ((info)>>8) +#define ELF32_M_SIZE(info) ((unsigned char)(info)) +#define ELF32_M_INFO(sym, sz) (((sym)<<8)+(unsigned char)(sz)) + +#define ELF64_M_SYM(info) ((Elf64_Xword)(info)>>8) +#define ELF64_M_SIZE(info) ((unsigned char)(info)) +#define ELF64_M_INFO(sym, sz) (((Elf64_Xword)(sym)<<8)+(unsigned char)(sz)) + +#endif /* __LIBELF64 */ + +/* + * Capabilities + */ + +typedef struct { + Elf32_Word c_tag; + union { + Elf32_Word c_val; + Elf32_Addr c_ptr; + } c_un; +} Elf32_Cap; + +#if __LIBELF64 + +typedef struct { + Elf64_Xword c_tag; + union { + Elf64_Xword c_val; + Elf64_Addr c_ptr; + } c_un; +} Elf64_Cap; + +#endif /* __LIBELF64 */ + +#define CA_SUNW_NULL 0 /* c_un ignored */ +#define CA_SUNW_HW_1 1 /* c_un.c_val */ +#define CA_SUNW_SF_1 2 /* c_un.c_val */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _ELF_REPL_H */ diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/errors.h b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/errors.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/errors.h @@ -0,0 +1,100 @@ +/* + * errors.h - exhaustive list of all error codes and messages for libelf. + * Copyright (C) 1995 - 2003, 2006 Michael Riepe + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* @(#) $Id: errors.h,v 1.18 2008/05/23 08:15:34 michael Exp $ */ + +/* dummy for xgettext */ +#define _(str) str + +__err__(ERROR_OK, _("no error")) +__err__(ERROR_UNKNOWN, _("unknown error")) +__err__(ERROR_INTERNAL, _("Internal error: unknown reason")) +__err__(ERROR_UNIMPLEMENTED, _("Internal error: not implemented")) +__err__(ERROR_WRONLY, _("Request error: cntl(ELF_C_FDREAD) on write-only file")) +__err__(ERROR_INVALID_CMD, _("Request error: invalid ELF_C_* argument")) +__err__(ERROR_FDDISABLED, _("Request error: file descriptor disabled")) +__err__(ERROR_NOTARCHIVE, _("Request error: not an archive")) +__err__(ERROR_BADOFF, _("Request error: offset out of range")) +__err__(ERROR_UNKNOWN_VERSION, _("Request error: unknown ELF version")) +__err__(ERROR_CMDMISMATCH, _("Request error: ELF_C_* argument does not match")) +__err__(ERROR_MEMBERWRITE, _("Request error: archive member begin() for writing")) +__err__(ERROR_FDMISMATCH, _("Request error: archive/member file descriptor mismatch")) +__err__(ERROR_NOTELF, _("Request error: not an ELF file")) +__err__(ERROR_CLASSMISMATCH, _("Request error: class file/memory mismatch")) +__err__(ERROR_UNKNOWN_TYPE, _("Request error: invalid ELF_T_* argument")) +__err__(ERROR_UNKNOWN_ENCODING, _("Request error: unknown data encoding")) +__err__(ERROR_DST2SMALL, _("Request error: destination buffer too small")) +__err__(ERROR_NULLBUF, _("Request error: d_buf is NULL")) +__err__(ERROR_UNKNOWN_CLASS, _("Request error: unknown ELF class")) +__err__(ERROR_ELFSCNMISMATCH, _("Request error: section does not belong to file")) +__err__(ERROR_NOSUCHSCN, _("Request error: no section at index")) +__err__(ERROR_NULLSCN, _("Request error: can't manipulate null section")) +__err__(ERROR_SCNDATAMISMATCH, _("Request error: data does not belong to section")) +__err__(ERROR_NOSTRTAB, _("Request error: no string table")) +__err__(ERROR_BADSTROFF, _("Request error: string table offset out of range")) +__err__(ERROR_RDONLY, _("Request error: update(ELF_C_WRITE) on read-only file")) +__err__(ERROR_IO_SEEK, _("I/O error: seek")) +__err__(ERROR_IO_2BIG, _("I/O error: file too big for memory")) +__err__(ERROR_IO_READ, _("I/O error: raw read")) +__err__(ERROR_IO_GETSIZE, _("I/O error: get file size")) +__err__(ERROR_IO_WRITE, _("I/O error: output write")) +__err__(ERROR_IO_TRUNC, _("I/O error: can't truncate output file")) +__err__(ERROR_VERSION_UNSET, _("Sequence error: must set ELF version first")) +__err__(ERROR_NOEHDR, _("Sequence error: must create ELF header first")) +__err__(ERROR_OUTSIDE, _("Format error: reference outside file")) +__err__(ERROR_TRUNC_ARHDR, _("Format error: archive header truncated")) +__err__(ERROR_ARFMAG, _("Format error: archive fmag")) +__err__(ERROR_ARHDR, _("Format error: archive header")) +__err__(ERROR_TRUNC_MEMBER, _("Format error: archive member truncated")) +__err__(ERROR_SIZE_ARSYMTAB, _("Format error: archive symbol table size")) +__err__(ERROR_ARSTRTAB, _("Format error: archive string table")) +__err__(ERROR_ARSPECIAL, _("Format error: archive special name unknown")) +__err__(ERROR_TRUNC_EHDR, _("Format error: ELF header truncated")) +__err__(ERROR_TRUNC_PHDR, _("Format error: program header table truncated")) +__err__(ERROR_TRUNC_SHDR, _("Format error: section header table truncated")) +__err__(ERROR_TRUNC_SCN, _("Format error: data region truncated")) +__err__(ERROR_ALIGN_PHDR, _("Format error: program header table alignment")) +__err__(ERROR_ALIGN_SHDR, _("Format error: section header table alignment")) +__err__(ERROR_VERDEF_FORMAT, _("Format error: bad parameter in Verdef record")) +__err__(ERROR_VERDEF_VERSION, _("Format error: unknown Verdef version")) +__err__(ERROR_VERNEED_FORMAT, _("Format error: bad parameter in Verneed record")) +__err__(ERROR_VERNEED_VERSION, _("Format error: unknown Verneed version")) +__err__(ERROR_EHDR_SHNUM, _("Format error: bad e_shnum value")) +__err__(ERROR_EHDR_SHENTSIZE, _("Format error: bad e_shentsize value")) +__err__(ERROR_EHDR_PHENTSIZE, _("Format error: bad e_phentsize value")) +__err__(ERROR_UNTERM, _("Format error: unterminated string in string table")) +__err__(ERROR_SCN2SMALL, _("Layout error: section size too small for data")) +__err__(ERROR_SCN_OVERLAP, _("Layout error: overlapping sections")) +__err__(ERROR_MEM_ELF, _("Memory error: elf descriptor")) +__err__(ERROR_MEM_ARSYMTAB, _("Memory error: archive symbol table")) +__err__(ERROR_MEM_ARHDR, _("Memory error: archive member header")) +__err__(ERROR_MEM_EHDR, _("Memory error: ELF header")) +__err__(ERROR_MEM_PHDR, _("Memory error: program header table")) +__err__(ERROR_MEM_SHDR, _("Memory error: section header table")) +__err__(ERROR_MEM_SCN, _("Memory error: section descriptor")) +__err__(ERROR_MEM_SCNDATA, _("Memory error: section data")) +__err__(ERROR_MEM_OUTBUF, _("Memory error: output file space")) +__err__(ERROR_MEM_TEMPORARY, _("Memory error: temporary buffer")) +__err__(ERROR_BADVALUE, _("GElf error: value out of range")) +__err__(ERROR_BADINDEX, _("GElf error: index out of range")) +__err__(ERROR_BADTYPE, _("GElf error: type mismatch")) +__err__(ERROR_MEM_SYM, _("GElf error: not enough memory for GElf_Sym")) +__err__(ERROR_MEM_DYN, _("GElf error: not enough memory for GElf_Dyn")) +__err__(ERROR_MEM_RELA, _("GElf error: not enough memory for GElf_Rela")) +__err__(ERROR_MEM_REL, _("GElf error: not enough memory for GElf_Rel")) diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/ext_types.h b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/ext_types.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/ext_types.h @@ -0,0 +1,334 @@ +/* +ext_types.h - external representation of ELF data types. +Copyright (C) 1995 - 1998 Michael Riepe + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ + +/* @(#) $Id: ext_types.h,v 1.9 2008/05/23 08:15:34 michael Exp $ */ + +#ifndef _EXT_TYPES_H +#define _EXT_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Scalar data types + */ +typedef unsigned char __ext_Elf32_Addr [ELF32_FSZ_ADDR]; +typedef unsigned char __ext_Elf32_Half [ELF32_FSZ_HALF]; +typedef unsigned char __ext_Elf32_Off [ELF32_FSZ_OFF]; +typedef unsigned char __ext_Elf32_Sword [ELF32_FSZ_SWORD]; +typedef unsigned char __ext_Elf32_Word [ELF32_FSZ_WORD]; + +#if __LIBELF64 + +typedef unsigned char __ext_Elf32_Lword [8]; + +typedef unsigned char __ext_Elf64_Addr [ELF64_FSZ_ADDR]; +typedef unsigned char __ext_Elf64_Half [ELF64_FSZ_HALF]; +typedef unsigned char __ext_Elf64_Off [ELF64_FSZ_OFF]; +typedef unsigned char __ext_Elf64_Sword [ELF64_FSZ_SWORD]; +typedef unsigned char __ext_Elf64_Word [ELF64_FSZ_WORD]; +typedef unsigned char __ext_Elf64_Sxword[ELF64_FSZ_SXWORD]; +typedef unsigned char __ext_Elf64_Xword [ELF64_FSZ_XWORD]; + +typedef unsigned char __ext_Elf64_Lword [8]; + +#endif /* __LIBELF64 */ + +/* + * ELF header + */ +typedef struct { + unsigned char e_ident[EI_NIDENT]; + __ext_Elf32_Half e_type; + __ext_Elf32_Half e_machine; + __ext_Elf32_Word e_version; + __ext_Elf32_Addr e_entry; + __ext_Elf32_Off e_phoff; + __ext_Elf32_Off e_shoff; + __ext_Elf32_Word e_flags; + __ext_Elf32_Half e_ehsize; + __ext_Elf32_Half e_phentsize; + __ext_Elf32_Half e_phnum; + __ext_Elf32_Half e_shentsize; + __ext_Elf32_Half e_shnum; + __ext_Elf32_Half e_shstrndx; +} __ext_Elf32_Ehdr; + +#if __LIBELF64 +typedef struct { + unsigned char e_ident[EI_NIDENT]; + __ext_Elf64_Half e_type; + __ext_Elf64_Half e_machine; + __ext_Elf64_Word e_version; + __ext_Elf64_Addr e_entry; + __ext_Elf64_Off e_phoff; + __ext_Elf64_Off e_shoff; + __ext_Elf64_Word e_flags; + __ext_Elf64_Half e_ehsize; + __ext_Elf64_Half e_phentsize; + __ext_Elf64_Half e_phnum; + __ext_Elf64_Half e_shentsize; + __ext_Elf64_Half e_shnum; + __ext_Elf64_Half e_shstrndx; +} __ext_Elf64_Ehdr; +#endif /* __LIBELF64 */ + +/* + * Section header + */ +typedef struct { + __ext_Elf32_Word sh_name; + __ext_Elf32_Word sh_type; + __ext_Elf32_Word sh_flags; + __ext_Elf32_Addr sh_addr; + __ext_Elf32_Off sh_offset; + __ext_Elf32_Word sh_size; + __ext_Elf32_Word sh_link; + __ext_Elf32_Word sh_info; + __ext_Elf32_Word sh_addralign; + __ext_Elf32_Word sh_entsize; +} __ext_Elf32_Shdr; + +#if __LIBELF64 +typedef struct { + __ext_Elf64_Word sh_name; + __ext_Elf64_Word sh_type; + __ext_Elf64_Xword sh_flags; + __ext_Elf64_Addr sh_addr; + __ext_Elf64_Off sh_offset; + __ext_Elf64_Xword sh_size; + __ext_Elf64_Word sh_link; + __ext_Elf64_Word sh_info; + __ext_Elf64_Xword sh_addralign; + __ext_Elf64_Xword sh_entsize; +} __ext_Elf64_Shdr; +#endif /* __LIBELF64 */ + +/* + * Symbol table + */ +typedef struct { + __ext_Elf32_Word st_name; + __ext_Elf32_Addr st_value; + __ext_Elf32_Word st_size; + unsigned char st_info; + unsigned char st_other; + __ext_Elf32_Half st_shndx; +} __ext_Elf32_Sym; + +#if __LIBELF64 +typedef struct { + __ext_Elf64_Word st_name; + unsigned char st_info; + unsigned char st_other; + __ext_Elf64_Half st_shndx; + __ext_Elf64_Addr st_value; + __ext_Elf64_Xword st_size; +} __ext_Elf64_Sym; +#endif /* __LIBELF64 */ + +/* + * Relocation + */ +typedef struct { + __ext_Elf32_Addr r_offset; + __ext_Elf32_Word r_info; +} __ext_Elf32_Rel; + +typedef struct { + __ext_Elf32_Addr r_offset; + __ext_Elf32_Word r_info; + __ext_Elf32_Sword r_addend; +} __ext_Elf32_Rela; + +#if __LIBELF64 +typedef struct { + __ext_Elf64_Addr r_offset; +#if __LIBELF64_IRIX + __ext_Elf64_Word r_sym; + unsigned char r_ssym; + unsigned char r_type3; + unsigned char r_type2; + unsigned char r_type; +#else /* __LIBELF64_IRIX */ + __ext_Elf64_Xword r_info; +#endif /* __LIBELF64_IRIX */ +} __ext_Elf64_Rel; + +typedef struct { + __ext_Elf64_Addr r_offset; +#if __LIBELF64_IRIX + __ext_Elf64_Word r_sym; + unsigned char r_ssym; + unsigned char r_type3; + unsigned char r_type2; + unsigned char r_type; +#else /* __LIBELF64_IRIX */ + __ext_Elf64_Xword r_info; +#endif /* __LIBELF64_IRIX */ + __ext_Elf64_Sxword r_addend; +} __ext_Elf64_Rela; +#endif /* __LIBELF64 */ + +/* + * Program header + */ +typedef struct { + __ext_Elf32_Word p_type; + __ext_Elf32_Off p_offset; + __ext_Elf32_Addr p_vaddr; + __ext_Elf32_Addr p_paddr; + __ext_Elf32_Word p_filesz; + __ext_Elf32_Word p_memsz; + __ext_Elf32_Word p_flags; + __ext_Elf32_Word p_align; +} __ext_Elf32_Phdr; + +#if __LIBELF64 +typedef struct { + __ext_Elf64_Word p_type; + __ext_Elf64_Word p_flags; + __ext_Elf64_Off p_offset; + __ext_Elf64_Addr p_vaddr; + __ext_Elf64_Addr p_paddr; + __ext_Elf64_Xword p_filesz; + __ext_Elf64_Xword p_memsz; + __ext_Elf64_Xword p_align; +} __ext_Elf64_Phdr; +#endif /* __LIBELF64 */ + +/* + * Dynamic structure + */ +typedef struct { + __ext_Elf32_Sword d_tag; + union { + __ext_Elf32_Word d_val; + __ext_Elf32_Addr d_ptr; + } d_un; +} __ext_Elf32_Dyn; + +#if __LIBELF64 +typedef struct { + __ext_Elf64_Sxword d_tag; + union { + __ext_Elf64_Xword d_val; + __ext_Elf64_Addr d_ptr; + } d_un; +} __ext_Elf64_Dyn; +#endif /* __LIBELF64 */ + +/* + * Version definitions + */ +typedef struct { + __ext_Elf32_Half vd_version; + __ext_Elf32_Half vd_flags; + __ext_Elf32_Half vd_ndx; + __ext_Elf32_Half vd_cnt; + __ext_Elf32_Word vd_hash; + __ext_Elf32_Word vd_aux; + __ext_Elf32_Word vd_next; +} __ext_Elf32_Verdef; + +typedef struct { + __ext_Elf32_Word vda_name; + __ext_Elf32_Word vda_next; +} __ext_Elf32_Verdaux; + +typedef struct { + __ext_Elf32_Half vn_version; + __ext_Elf32_Half vn_cnt; + __ext_Elf32_Word vn_file; + __ext_Elf32_Word vn_aux; + __ext_Elf32_Word vn_next; +} __ext_Elf32_Verneed; + +typedef struct { + __ext_Elf32_Word vna_hash; + __ext_Elf32_Half vna_flags; + __ext_Elf32_Half vna_other; + __ext_Elf32_Word vna_name; + __ext_Elf32_Word vna_next; +} __ext_Elf32_Vernaux; + +#if __LIBELF64 + +typedef struct { + __ext_Elf64_Half vd_version; + __ext_Elf64_Half vd_flags; + __ext_Elf64_Half vd_ndx; + __ext_Elf64_Half vd_cnt; + __ext_Elf64_Word vd_hash; + __ext_Elf64_Word vd_aux; + __ext_Elf64_Word vd_next; +} __ext_Elf64_Verdef; + +typedef struct { + __ext_Elf64_Word vda_name; + __ext_Elf64_Word vda_next; +} __ext_Elf64_Verdaux; + +typedef struct { + __ext_Elf64_Half vn_version; + __ext_Elf64_Half vn_cnt; + __ext_Elf64_Word vn_file; + __ext_Elf64_Word vn_aux; + __ext_Elf64_Word vn_next; +} __ext_Elf64_Verneed; + +typedef struct { + __ext_Elf64_Word vna_hash; + __ext_Elf64_Half vna_flags; + __ext_Elf64_Half vna_other; + __ext_Elf64_Word vna_name; + __ext_Elf64_Word vna_next; +} __ext_Elf64_Vernaux; + +#endif /* __LIBELF64 */ + +/* + * Move section + */ +#if __LIBELF64 + +typedef struct { + __ext_Elf32_Lword m_value; + __ext_Elf32_Word m_info; + __ext_Elf32_Word m_poffset; + __ext_Elf32_Half m_repeat; + __ext_Elf32_Half m_stride; +} __ext_Elf32_Move; + +typedef struct { + __ext_Elf64_Lword m_value; + __ext_Elf64_Xword m_info; + __ext_Elf64_Xword m_poffset; + __ext_Elf64_Half m_repeat; + __ext_Elf64_Half m_stride; +} __ext_Elf64_Move; + +#endif /* __LIBELF64 */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _EXT_TYPES_H */ diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/gelf.h b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/gelf.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/gelf.h @@ -0,0 +1,155 @@ +/* + * gelf.h - public header file for libelf. + * Copyright (C) 2000 - 2006 Michael Riepe + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* @(#) $Id: gelf.h,v 1.16 2008/05/23 08:15:34 michael Exp $ */ + +#ifndef _GELF_H +#define _GELF_H + +#if __LIBELF_INTERNAL__ +#include +#else /* __LIBELF_INTERNAL__ */ +#include +#endif /* __LIBELF_INTERNAL__ */ + +#if __LIBELF_NEED_LINK_H +#include +#elif __LIBELF_NEED_SYS_LINK_H +#include +#endif /* __LIBELF_NEED_LINK_H */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifndef __P +# if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32) +# define __P(args) args +# else /* __STDC__ || defined(__cplusplus) */ +# define __P(args) () +# endif /* __STDC__ || defined(__cplusplus) */ +#endif /* __P */ + +#if !__LIBELF64 + +#error "GElf is not supported on this system." + +#else /* __LIBELF64 */ + +typedef Elf64_Addr GElf_Addr; +typedef Elf64_Half GElf_Half; +typedef Elf64_Off GElf_Off; +typedef Elf64_Sword GElf_Sword; +typedef Elf64_Word GElf_Word; +typedef Elf64_Sxword GElf_Sxword; +typedef Elf64_Xword GElf_Xword; + +typedef Elf64_Ehdr GElf_Ehdr; +typedef Elf64_Phdr GElf_Phdr; +typedef Elf64_Shdr GElf_Shdr; +typedef Elf64_Dyn GElf_Dyn; +typedef Elf64_Rel GElf_Rel; +typedef Elf64_Rela GElf_Rela; +typedef Elf64_Sym GElf_Sym; + +/* + * Symbol versioning + */ +#if __LIBELF_SYMBOL_VERSIONS +typedef Elf64_Verdef GElf_Verdef; +typedef Elf64_Verneed GElf_Verneed; +typedef Elf64_Verdaux GElf_Verdaux; +typedef Elf64_Vernaux GElf_Vernaux; +#endif /* __LIBELF_SYMBOL_VERSIONS */ + +/* + * These types aren't implemented (yet) + * +typedef Elf64_Move GElf_Move; +typedef Elf64_Syminfo GElf_Syminfo; + */ + +/* + * Generic macros + */ +#define GELF_ST_BIND ELF64_ST_BIND +#define GELF_ST_TYPE ELF64_ST_TYPE +#define GELF_ST_INFO ELF64_ST_INFO + +#define GELF_R_TYPE ELF64_R_TYPE +#define GELF_R_SYM ELF64_R_SYM +#define GELF_R_INFO ELF64_R_INFO + +/* + * Function declarations + */ +extern int gelf_getclass __P((Elf *__elf)); + +extern size_t gelf_fsize __P((Elf *__elf, Elf_Type __type, size_t __count, unsigned __ver)); + +extern Elf_Data *gelf_xlatetof __P((Elf *__elf, Elf_Data *__dst, const Elf_Data *__src, unsigned __encode)); +extern Elf_Data *gelf_xlatetom __P((Elf *__elf, Elf_Data *__dst, const Elf_Data *__src, unsigned __encode)); + +extern GElf_Ehdr *gelf_getehdr __P((Elf *__elf, GElf_Ehdr *__dst)); +extern int gelf_update_ehdr __P((Elf *__elf, GElf_Ehdr *__src)); +extern unsigned long gelf_newehdr __P((Elf *__elf, int __elfclass)); + +extern GElf_Phdr *gelf_getphdr __P((Elf *__elf, int ndx, GElf_Phdr *__dst)); +extern int gelf_update_phdr __P((Elf *__elf, int ndx, GElf_Phdr *__src)); +extern unsigned long gelf_newphdr __P((Elf *__elf, size_t __phnum)); + +extern GElf_Shdr *gelf_getshdr __P((Elf_Scn *__scn, GElf_Shdr *__dst)); +extern int gelf_update_shdr __P((Elf_Scn *__scn, GElf_Shdr *__src)); + +extern GElf_Dyn *gelf_getdyn __P((Elf_Data *__src, int __ndx, GElf_Dyn *__dst)); +extern int gelf_update_dyn __P((Elf_Data *__dst, int __ndx, GElf_Dyn *__src)); + +extern GElf_Rel *gelf_getrel __P((Elf_Data *__src, int __ndx, GElf_Rel *__dst)); +extern int gelf_update_rel __P((Elf_Data *__dst, int __ndx, GElf_Rel *__src)); + +extern GElf_Rela *gelf_getrela __P((Elf_Data *__src, int __ndx, GElf_Rela *__dst)); +extern int gelf_update_rela __P((Elf_Data *__dst, int __ndx, GElf_Rela *__src)); + +extern GElf_Sym *gelf_getsym __P((Elf_Data *__src, int __ndx, GElf_Sym *__dst)); +extern int gelf_update_sym __P((Elf_Data *__dst, int __ndx, GElf_Sym *__src)); + +extern long gelf_checksum __P((Elf *__elf)); + +/* + * These functions aren't implemented (yet) + * +extern GElf_Move *gelf_getmove __P((Elf_Data *__src, int __ndx, GElf_Move *__src)); +extern int gelf_update_move __P((Elf_Data *__dst, int __ndx, GElf_Move *__src)); + * +extern GElf_Syminfo* gelf_getsyminfo __P((Elf_Data *__src, int __ndx, GElf_Syminfo *__dst)); +extern int gelf_update_syminfo __P((Elf_Data *__dst, int __ndx, GElf_Syminfo *__src)); + */ + +/* + * Extensions (not available in other versions of libelf) + */ +extern size_t gelf_msize __P((Elf *__elf, Elf_Type __type, size_t __count, unsigned __ver)); + +#endif /* __LIBELF64 */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _GELF_H */ diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/libelf.h b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/libelf.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/libelf.h @@ -0,0 +1,305 @@ +/* + * libelf.h - public header file for libelf. + * Copyright (C) 1995 - 2008 Michael Riepe + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* @(#) $Id: libelf.h,v 1.29 2009/07/07 17:57:43 michael Exp $ */ + +#ifndef _LIBELF_H +#define _LIBELF_H + +#include /* for size_t */ +#include + +#if __LIBELF_INTERNAL__ +#include +#else /* __LIBELF_INTERNAL__ */ +#include +#endif /* __LIBELF_INTERNAL__ */ + +#if defined __GNUC__ && !defined __cplusplus +#define DEPRECATED __attribute__((deprecated)) +#else +#define DEPRECATED /* nothing */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifndef __P +# if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32) +# define __P(args) args +# else /* __STDC__ || defined(__cplusplus) */ +# define __P(args) () +# endif /* __STDC__ || defined(__cplusplus) */ +#endif /* __P */ + +/* + * Commands + */ +typedef enum { + ELF_C_NULL = 0, /* must be first, 0 */ + ELF_C_READ, + ELF_C_WRITE, + ELF_C_CLR, + ELF_C_SET, + ELF_C_FDDONE, + ELF_C_FDREAD, + ELF_C_RDWR, + ELF_C_NUM /* must be last */ +} Elf_Cmd; + +/* + * Flags + */ +#define ELF_F_DIRTY 0x1 +#define ELF_F_LAYOUT 0x4 +/* + * Allow sections to overlap when ELF_F_LAYOUT is in effect. + * Note that this flag ist NOT portable, and that it may render + * the output file unusable. Use with extreme caution! + */ +#define ELF_F_LAYOUT_OVERLAP 0x10000000 + +/* + * File types + */ +typedef enum { + ELF_K_NONE = 0, /* must be first, 0 */ + ELF_K_AR, + ELF_K_COFF, + ELF_K_ELF, + ELF_K_NUM /* must be last */ +} Elf_Kind; + +/* + * Data types + */ +typedef enum { + ELF_T_BYTE = 0, /* must be first, 0 */ + ELF_T_ADDR, + ELF_T_DYN, + ELF_T_EHDR, + ELF_T_HALF, + ELF_T_OFF, + ELF_T_PHDR, + ELF_T_RELA, + ELF_T_REL, + ELF_T_SHDR, + ELF_T_SWORD, + ELF_T_SYM, + ELF_T_WORD, + /* + * New stuff for 64-bit. + * + * Most implementations add ELF_T_SXWORD after ELF_T_SWORD + * which breaks binary compatibility with earlier versions. + * If this causes problems for you, contact me. + */ + ELF_T_SXWORD, + ELF_T_XWORD, + /* + * Symbol versioning. Sun broke binary compatibility (again!), + * but I won't. + */ + ELF_T_VDEF, + ELF_T_VNEED, + ELF_T_NUM /* must be last */ +} Elf_Type; + +/* + * Elf descriptor + */ +typedef struct Elf Elf; + +/* + * Section descriptor + */ +typedef struct Elf_Scn Elf_Scn; + +/* + * Archive member header + */ +typedef struct { + char* ar_name; + time_t ar_date; + long ar_uid; + long ar_gid; + unsigned long ar_mode; + off_t ar_size; + char* ar_rawname; +} Elf_Arhdr; + +/* + * Archive symbol table + */ +typedef struct { + char* as_name; + size_t as_off; + unsigned long as_hash; +} Elf_Arsym; + +/* + * Data descriptor + */ +typedef struct { + void* d_buf; + Elf_Type d_type; + size_t d_size; + off_t d_off; + size_t d_align; + unsigned d_version; +} Elf_Data; + +/* + * Function declarations + */ +extern Elf *elf_begin __P((int __fd, Elf_Cmd __cmd, Elf *__ref)); +extern Elf *elf_memory __P((char *__image, size_t __size)); +extern int elf_cntl __P((Elf *__elf, Elf_Cmd __cmd)); +extern int elf_end __P((Elf *__elf)); +extern const char *elf_errmsg __P((int __err)); +extern int elf_errno __P((void)); +extern void elf_fill __P((int __fill)); +extern unsigned elf_flagdata __P((Elf_Data *__data, Elf_Cmd __cmd, + unsigned __flags)); +extern unsigned elf_flagehdr __P((Elf *__elf, Elf_Cmd __cmd, + unsigned __flags)); +extern unsigned elf_flagelf __P((Elf *__elf, Elf_Cmd __cmd, + unsigned __flags)); +extern unsigned elf_flagphdr __P((Elf *__elf, Elf_Cmd __cmd, + unsigned __flags)); +extern unsigned elf_flagscn __P((Elf_Scn *__scn, Elf_Cmd __cmd, + unsigned __flags)); +extern unsigned elf_flagshdr __P((Elf_Scn *__scn, Elf_Cmd __cmd, + unsigned __flags)); +extern size_t elf32_fsize __P((Elf_Type __type, size_t __count, + unsigned __ver)); +extern Elf_Arhdr *elf_getarhdr __P((Elf *__elf)); +extern Elf_Arsym *elf_getarsym __P((Elf *__elf, size_t *__ptr)); +extern off_t elf_getbase __P((Elf *__elf)); +extern Elf_Data *elf_getdata __P((Elf_Scn *__scn, Elf_Data *__data)); +extern Elf32_Ehdr *elf32_getehdr __P((Elf *__elf)); +extern char *elf_getident __P((Elf *__elf, size_t *__ptr)); +extern Elf32_Phdr *elf32_getphdr __P((Elf *__elf)); +extern Elf_Scn *elf_getscn __P((Elf *__elf, size_t __index)); +extern Elf32_Shdr *elf32_getshdr __P((Elf_Scn *__scn)); +extern unsigned long elf_hash __P((const unsigned char *__name)); +extern Elf_Kind elf_kind __P((Elf *__elf)); +extern size_t elf_ndxscn __P((Elf_Scn *__scn)); +extern Elf_Data *elf_newdata __P((Elf_Scn *__scn)); +extern Elf32_Ehdr *elf32_newehdr __P((Elf *__elf)); +extern Elf32_Phdr *elf32_newphdr __P((Elf *__elf, size_t __count)); +extern Elf_Scn *elf_newscn __P((Elf *__elf)); +extern Elf_Cmd elf_next __P((Elf *__elf)); +extern Elf_Scn *elf_nextscn __P((Elf *__elf, Elf_Scn *__scn)); +extern size_t elf_rand __P((Elf *__elf, size_t __offset)); +extern Elf_Data *elf_rawdata __P((Elf_Scn *__scn, Elf_Data *__data)); +extern char *elf_rawfile __P((Elf *__elf, size_t *__ptr)); +extern char *elf_strptr __P((Elf *__elf, size_t __section, size_t __offset)); +extern off_t elf_update __P((Elf *__elf, Elf_Cmd __cmd)); +extern unsigned elf_version __P((unsigned __ver)); +extern Elf_Data *elf32_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src, + unsigned __encode)); +extern Elf_Data *elf32_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src, + unsigned __encode)); + +/* + * Additional functions found on Solaris + */ +extern long elf32_checksum __P((Elf *__elf)); + +#if __LIBELF64 +/* + * 64-bit ELF functions + * Not available on all platforms + */ +extern Elf64_Ehdr *elf64_getehdr __P((Elf *__elf)); +extern Elf64_Ehdr *elf64_newehdr __P((Elf *__elf)); +extern Elf64_Phdr *elf64_getphdr __P((Elf *__elf)); +extern Elf64_Phdr *elf64_newphdr __P((Elf *__elf, size_t __count)); +extern Elf64_Shdr *elf64_getshdr __P((Elf_Scn *__scn)); +extern size_t elf64_fsize __P((Elf_Type __type, size_t __count, + unsigned __ver)); +extern Elf_Data *elf64_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src, + unsigned __encode)); +extern Elf_Data *elf64_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src, + unsigned __encode)); + +/* + * Additional functions found on Solaris + */ +extern long elf64_checksum __P((Elf *__elf)); + +#endif /* __LIBELF64 */ + +/* + * ELF format extensions + * + * These functions return 0 on failure, 1 on success. Since other + * implementations of libelf may behave differently (there was quite + * some confusion about the correct values), they are now officially + * deprecated and should be replaced with the three new functions below. + */ +DEPRECATED extern int elf_getphnum __P((Elf *__elf, size_t *__resultp)); +DEPRECATED extern int elf_getshnum __P((Elf *__elf, size_t *__resultp)); +DEPRECATED extern int elf_getshstrndx __P((Elf *__elf, size_t *__resultp)); +/* + * Replacement functions (return -1 on failure, 0 on success). + */ +extern int elf_getphdrnum __P((Elf *__elf, size_t *__resultp)); +extern int elf_getshdrnum __P((Elf *__elf, size_t *__resultp)); +extern int elf_getshdrstrndx __P((Elf *__elf, size_t *__resultp)); + +/* + * Convenience functions + * + * elfx_update_shstrndx is elf_getshstrndx's counterpart. + * It should be used to set the e_shstrndx member. + * There is no update function for e_shnum or e_phnum + * because libelf handles them internally. + */ +extern int elfx_update_shstrndx __P((Elf *__elf, size_t __index)); + +/* + * Experimental extensions: + * + * elfx_movscn() moves section `__scn' directly after section `__after'. + * elfx_remscn() removes section `__scn'. Both functions update + * the section indices; elfx_remscn() also adjusts the ELF header's + * e_shnum member. The application is responsible for updating other + * data (in particular, e_shstrndx and the section headers' sh_link and + * sh_info members). + * + * elfx_movscn() returns the new index of the moved section. + * elfx_remscn() returns the original index of the removed section. + * A return value of zero indicates an error. + */ +extern size_t elfx_movscn __P((Elf *__elf, Elf_Scn *__scn, Elf_Scn *__after)); +extern size_t elfx_remscn __P((Elf *__elf, Elf_Scn *__scn)); + +/* + * elf_delscn() is obsolete. Please use elfx_remscn() instead. + */ +extern size_t elf_delscn __P((Elf *__elf, Elf_Scn *__scn)); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _LIBELF_H */ diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/nlist.h b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/nlist.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/nlist.h @@ -0,0 +1,48 @@ +/* + * nlist.h - public header file for nlist(3). + * Copyright (C) 1995 - 2006 Michael Riepe + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* @(#) $Id: nlist.h,v 1.10 2008/05/23 08:15:35 michael Exp $ */ + +#ifndef _NLIST_H +#define _NLIST_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +struct nlist { + char* n_name; + long n_value; + short n_scnum; + unsigned short n_type; + char n_sclass; + char n_numaux; +}; + +#if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32) +extern int nlist(const char *__filename, struct nlist *__nl); +#else /* __STDC__ || defined(__cplusplus) */ +extern int nlist(); +#endif /* __STDC__ || defined(__cplusplus) */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _NLIST_H */ diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/private.h b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/private.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/private.h @@ -0,0 +1,446 @@ +/* + * private.h - private definitions for libelf. + * Copyright (C) 1995 - 2007 Michael Riepe + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* @(#) $Id: private.h,v 1.40 2009/11/01 13:04:19 michael Exp $ */ + +#ifndef _PRIVATE_H +#define _PRIVATE_H + +#define __LIBELF_INTERNAL__ 1 + +#if HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +/* + * Workaround for GLIBC bug: + * include before + */ +#if HAVE_STDINT_H +#include +#endif +#include + +#if STDC_HEADERS +# include +# include +#else /* STDC_HEADERS */ +extern void *malloc(), *realloc(); +extern void free(), bcopy(), abort(); +extern int strcmp(), strncmp(), memcmp(); +extern void *memcpy(), *memmove(), *memset(); +#endif /* STDC_HEADERS */ + +#if defined(_WIN32) +#include +#else +#if HAVE_UNISTD_H +# include +#else /* HAVE_UNISTD_H */ +extern int read(), write(), close(); +extern off_t lseek(); +#if HAVE_FTRUNCATE +extern int ftruncate(); +#endif /* HAVE_FTRUNCATE */ +#endif /* HAVE_UNISTD_H */ +#endif /* defined(_WIN32) */ + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif /* SEEK_SET */ +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif /* SEEK_CUR */ +#ifndef SEEK_END +#define SEEK_END 2 +#endif /* SEEK_END */ + +#if !HAVE_MEMCMP +# define memcmp strncmp +#endif /* !HAVE_MEMCMP */ +#if !HAVE_MEMCPY +# define memcpy(d,s,n) bcopy(s,d,n) +#endif /* !HAVE_MEMCPY */ +#if !HAVE_MEMMOVE +# define memmove(d,s,n) bcopy(s,d,n) +#endif /* !HAVE_MEMMOVE */ + +#if !HAVE_MEMSET +# define memset _elf_memset +extern void *_elf_memset(); +#endif /* !HAVE_MEMSET */ + +#if HAVE_STRUCT_NLIST_DECLARATION +# define nlist __override_nlist_declaration +#endif /* HAVE_STRUCT_NLIST_DECLARATION */ + +#if __LIBELF_NEED_LINK_H +# include +#elif __LIBELF_NEED_SYS_LINK_H +# include +#endif /* __LIBELF_NEED_LINK_H */ + +#if HAVE_AR_H +#include +#else /* HAVE_AR_H */ + +#define ARMAG "!\n" +#define SARMAG 8 + +struct ar_hdr { + char ar_name[16]; + char ar_date[12]; + char ar_uid[6]; + char ar_gid[6]; + char ar_mode[8]; + char ar_size[10]; + char ar_fmag[2]; +}; + +#define ARFMAG "`\n" + +#endif /* HAVE_AR_H */ + +#include + +#if HAVE_STRUCT_NLIST_DECLARATION +# undef nlist +#endif /* HAVE_STRUCT_NLIST_DECLARATION */ + +#if __LIBELF64 +#include +#endif /* __LIBELF64 */ + +typedef struct Scn_Data Scn_Data; + +/* + * ELF descriptor + */ +struct Elf { + /* common */ + size_t e_size; /* file/member size */ + size_t e_dsize; /* size of memory image */ + Elf_Kind e_kind; /* kind of file */ + char* e_data; /* file/member data */ + char* e_rawdata; /* file/member raw data */ + size_t e_idlen; /* identifier size */ + int e_fd; /* file descriptor */ + unsigned e_count; /* activation count */ + /* archive members (still common) */ + Elf* e_parent; /* NULL if not an archive member */ + size_t e_next; /* 0 if not an archive member */ + size_t e_base; /* 0 if not an archive member */ + Elf* e_link; /* next archive member or NULL */ + Elf_Arhdr* e_arhdr; /* archive member header or NULL */ + /* archives */ + size_t e_off; /* current member offset (for elf_begin) */ + Elf* e_members; /* linked list of active archive members */ + char* e_symtab; /* archive symbol table */ + size_t e_symlen; /* length of archive symbol table */ + char* e_strtab; /* archive string table */ + size_t e_strlen; /* length of archive string table */ + /* ELF files */ + unsigned e_class; /* ELF class */ + unsigned e_encoding; /* ELF data encoding */ + unsigned e_version; /* ELF version */ + char* e_ehdr; /* ELF header */ + char* e_phdr; /* ELF program header table */ + size_t e_phnum; /* size of program header table */ + Elf_Scn* e_scn_1; /* first section */ + Elf_Scn* e_scn_n; /* last section */ + unsigned e_elf_flags; /* elf flags (ELF_F_*) */ + unsigned e_ehdr_flags; /* ehdr flags (ELF_F_*) */ + unsigned e_phdr_flags; /* phdr flags (ELF_F_*) */ + /* misc flags */ + unsigned e_readable : 1; /* file is readable */ + unsigned e_writable : 1; /* file is writable */ + unsigned e_disabled : 1; /* e_fd has been disabled */ + unsigned e_cooked : 1; /* e_data was modified */ + unsigned e_free_syms : 1; /* e_symtab is malloc'ed */ + unsigned e_unmap_data : 1; /* e_data is mmap'ed */ + unsigned e_memory : 1; /* created by elf_memory() */ + /* magic number for debugging */ + long e_magic; +}; + +#define ELF_MAGIC 0x012b649e + +#define INIT_ELF {\ + /* e_size */ 0,\ + /* e_dsize */ 0,\ + /* e_kind */ ELF_K_NONE,\ + /* e_data */ NULL,\ + /* e_rawdata */ NULL,\ + /* e_idlen */ 0,\ + /* e_fd */ -1,\ + /* e_count */ 1,\ + /* e_parent */ NULL,\ + /* e_next */ 0,\ + /* e_base */ 0,\ + /* e_link */ NULL,\ + /* e_arhdr */ NULL,\ + /* e_off */ 0,\ + /* e_members */ NULL,\ + /* e_symtab */ NULL,\ + /* e_symlen */ 0,\ + /* e_strtab */ NULL,\ + /* e_strlen */ 0,\ + /* e_class */ ELFCLASSNONE,\ + /* e_encoding */ ELFDATANONE,\ + /* e_version */ EV_NONE,\ + /* e_ehdr */ NULL,\ + /* e_phdr */ NULL,\ + /* e_phnum */ 0,\ + /* e_scn_1 */ NULL,\ + /* e_scn_n */ NULL,\ + /* e_elf_flags */ 0,\ + /* e_ehdr_flags */ 0,\ + /* e_phdr_flags */ 0,\ + /* e_readable */ 0,\ + /* e_writable */ 0,\ + /* e_disabled */ 0,\ + /* e_cooked */ 0,\ + /* e_free_syms */ 0,\ + /* e_unmap_data */ 0,\ + /* e_memory */ 0,\ + /* e_magic */ ELF_MAGIC\ +} + +/* + * Section descriptor + */ +struct Elf_Scn { + Elf_Scn* s_link; /* pointer to next Elf_Scn */ + Elf* s_elf; /* pointer to elf descriptor */ + size_t s_index; /* number of this section */ + unsigned s_scn_flags; /* section flags (ELF_F_*) */ + unsigned s_shdr_flags; /* shdr flags (ELF_F_*) */ + Scn_Data* s_data_1; /* first data buffer */ + Scn_Data* s_data_n; /* last data buffer */ + Scn_Data* s_rawdata; /* raw data buffer */ + /* data copied from shdr */ + unsigned s_type; /* section type */ + size_t s_offset; /* section offset */ + size_t s_size; /* section size */ + /* misc flags */ + unsigned s_freeme : 1; /* this Elf_Scn was malloc'ed */ + /* section header */ + union { +#if __LIBELF64 + Elf64_Shdr u_shdr64; +#endif /* __LIBELF64 */ + Elf32_Shdr u_shdr32; + } s_uhdr; + /* magic number for debugging */ + long s_magic; +}; +#define s_shdr32 s_uhdr.u_shdr32 +#define s_shdr64 s_uhdr.u_shdr64 + +#define SCN_MAGIC 0x012c747d + +#define INIT_SCN {\ + /* s_link */ NULL,\ + /* s_elf */ NULL,\ + /* s_index */ 0,\ + /* s_scn_flags */ 0,\ + /* s_shdr_flags */ 0,\ + /* s_data_1 */ NULL,\ + /* s_data_n */ NULL,\ + /* s_rawdata */ NULL,\ + /* s_type */ SHT_NULL,\ + /* s_offset */ 0,\ + /* s_size */ 0,\ + /* s_freeme */ 0,\ + /* s_uhdr */ {{0,}},\ + /* s_magic */ SCN_MAGIC\ +} + +/* + * Data descriptor + */ +struct Scn_Data { + Elf_Data sd_data; /* must be first! */ + Scn_Data* sd_link; /* pointer to next Scn_Data */ + Elf_Scn* sd_scn; /* pointer to section */ + char* sd_memdata; /* memory image of section */ + unsigned sd_data_flags; /* data flags (ELF_F_*) */ + /* misc flags */ + unsigned sd_freeme : 1; /* this Scn_Data was malloc'ed */ + unsigned sd_free_data : 1; /* sd_memdata is malloc'ed */ + /* magic number for debugging */ + long sd_magic; +}; + +#define DATA_MAGIC 0x01072639 + +#define INIT_DATA {\ + {\ + /* d_buf */ NULL,\ + /* d_type */ ELF_T_BYTE,\ + /* d_size */ 0,\ + /* d_off */ 0,\ + /* d_align */ 0,\ + /* d_version */ EV_NONE\ + },\ + /* sd_link */ NULL,\ + /* sd_scn */ NULL,\ + /* sd_memdata */ NULL,\ + /* sd_data_flags */ 0,\ + /* sd_freeme */ 0,\ + /* sd_free_data */ 0,\ + /* sd_magic */ DATA_MAGIC\ +} + +/* + * Private status variables + */ +extern unsigned _elf_version; +extern int _elf_errno; +extern int _elf_fill; +extern int _elf_sanity_checks; +#define SANITY_CHECK_STRPTR (1u << 0) + +/* + * Private functions + */ +extern void *_elf_read __P((Elf*, void*, size_t, size_t)); +extern void *_elf_mmap __P((Elf*)); +extern int _elf_cook __P((Elf*)); +extern char *_elf_getehdr __P((Elf*, unsigned)); +extern char *_elf_getphdr __P((Elf*, unsigned)); +extern Elf_Data *_elf_xlatetom __P((const Elf*, Elf_Data*, const Elf_Data*)); +extern Elf_Type _elf_scn_type __P((unsigned)); +extern size_t _elf32_xltsize __P((const Elf_Data *__src, unsigned __dv, unsigned __encode, int __tof)); +extern size_t _elf64_xltsize __P((const Elf_Data *__src, unsigned __dv, unsigned __encode, int __tof)); +extern int _elf_update_shnum(Elf *__elf, size_t __shnum); +extern Elf_Scn *_elf_first_scn(Elf *__elf); + +/* + * Special translators + */ +extern size_t _elf_verdef_32L11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verdef_32L11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verdef_32M11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verdef_32M11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verdef_64L11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verdef_64L11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verdef_64M11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verdef_64M11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verneed_32L11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verneed_32L11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verneed_32M11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verneed_32M11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verneed_64L11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verneed_64L11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verneed_64M11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); +extern size_t _elf_verneed_64M11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); + +/* + * Private data + */ +extern const Elf_Scn _elf_scn_init; +extern const Scn_Data _elf_data_init; +extern const size_t _elf_fmsize[2][EV_CURRENT - EV_NONE][ELF_T_NUM][2]; + +/* + * Access macros for _elf_fmsize[] + */ +#define _fmsize(c,v,t,w) \ + (_elf_fmsize[(c)-ELFCLASS32][(v)-EV_NONE-1][(t)-ELF_T_BYTE][(w)]) +#define _fsize(c,v,t) _fmsize((c),(v),(t),1) +#define _msize(c,v,t) _fmsize((c),(v),(t),0) + +/* + * Various checks + */ +#define valid_class(c) ((c) >= ELFCLASS32 && (c) <= ELFCLASS64) +#define valid_encoding(e) ((e) >= ELFDATA2LSB && (e) <= ELFDATA2MSB) +#define valid_version(v) ((v) > EV_NONE && (v) <= EV_CURRENT) +#define valid_type(t) ((unsigned)(t) < ELF_T_NUM) + +/* + * Error codes + */ +enum { +#define __err__(a,b) a, +#include /* include constants from errors.h */ +#undef __err__ +ERROR_NUM +}; + +#define seterr(err) (_elf_errno = (err)) + +/* + * Sizes of data types (external representation) + * These definitions should be in , but... + */ +#ifndef ELF32_FSZ_ADDR +# define ELF32_FSZ_ADDR 4 +# define ELF32_FSZ_HALF 2 +# define ELF32_FSZ_OFF 4 +# define ELF32_FSZ_SWORD 4 +# define ELF32_FSZ_WORD 4 +#endif /* ELF32_FSZ_ADDR */ +#ifndef ELF64_FSZ_ADDR +# define ELF64_FSZ_ADDR 8 +# define ELF64_FSZ_HALF 2 +# define ELF64_FSZ_OFF 8 +# define ELF64_FSZ_SWORD 4 +# define ELF64_FSZ_SXWORD 8 +# define ELF64_FSZ_WORD 4 +# define ELF64_FSZ_XWORD 8 +#endif /* ELF64_FSZ_ADDR */ + +/* + * More missing pieces, in no particular order + */ +#ifndef SHT_SYMTAB_SHNDX +#define SHT_SYMTAB_SHNDX 18 +#endif /* SHT_SYMTAB_SHNDX */ + +#ifndef SHN_XINDEX +#define SHN_XINDEX 0xffff +#endif /* SHN_XINDEX */ + +#ifndef PN_XNUM +#define PN_XNUM 0xffff +#endif /* PN_XNUM */ + +/* + * Debugging + */ +#if ENABLE_DEBUG +extern void __elf_assert __P((const char*, unsigned, const char*)); +# if (__STDC__ + 0) +# define elf_assert(x) do{if(!(x))__elf_assert(__FILE__,__LINE__,#x);}while(0) +# else /* __STDC__ */ +# define elf_assert(x) do{if(!(x))__elf_assert(__FILE__,__LINE__,"x");}while(0) +# endif /* __STDC__ */ +#else /* ENABLE_DEBUG */ +# define elf_assert(x) do{}while(0) +#endif /* ENABLE_DEBUG */ + +/* + * Return values for certain functions + */ +#define LIBELF_SUCCESS 1 +#define LIBELF_FAILURE 0 + +#endif /* _PRIVATE_H */ diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/sys_elf.h b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/sys_elf.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/sys_elf.h @@ -0,0 +1,131 @@ +/* lib/sys_elf.h. Generated automatically by configure. */ +/* +sys_elf.h.in - configure template for private "switch" file. +Copyright (C) 1998 - 2001 Michael Riepe + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ + +/* @(#) $Id: sys_elf.h.in,v 1.13 2008/05/23 08:57:07 michael Exp $ */ + +/* + * DO NOT USE THIS IN APPLICATIONS - #include INSTEAD! + */ + +/* Define to `' or `' if one of them is present */ +/* #undef __LIBELF_HEADER_ELF_H */ + +/* Define if Elf32_Dyn is declared in */ +/* #undef __LIBELF_NEED_LINK_H */ + +/* Define if Elf32_Dyn is declared in */ +/* #undef __LIBELF_NEED_SYS_LINK_H */ + +/* Define if you want 64-bit support (and your system supports it) */ +#define __LIBELF64 1 + +/* Define if you want 64-bit support, and are running IRIX */ +/* #undef __LIBELF64_IRIX */ + +/* Define if you want 64-bit support, and are running Linux */ +/* #undef __LIBELF64_LINUX */ + +/* Define if you want symbol versioning (and your system supports it) */ +#define __LIBELF_SYMBOL_VERSIONS 1 + +/* Define to a 64-bit signed integer type if one exists */ +#define __libelf_i64_t __int64 + +/* Define to a 64-bit unsigned integer type if one exists */ +#define __libelf_u64_t unsigned __int64 + +/* Define to a 32-bit signed integer type if one exists */ +#define __libelf_i32_t int + +/* Define to a 32-bit unsigned integer type if one exists */ +#define __libelf_u32_t unsigned int + +/* Define to a 16-bit signed integer type if one exists */ +#define __libelf_i16_t short + +/* Define to a 16-bit unsigned integer type if one exists */ +#define __libelf_u16_t unsigned short + +/* + * Ok, now get the correct instance of elf.h... + */ +#ifdef __LIBELF_HEADER_ELF_H +# include __LIBELF_HEADER_ELF_H +#else /* __LIBELF_HEADER_ELF_H */ +# if __LIBELF_INTERNAL__ +# include +# else /* __LIBELF_INTERNAL__ */ +# include +# endif /* __LIBELF_INTERNAL__ */ +#endif /* __LIBELF_HEADER_ELF_H */ + +/* + * On some systems, is severely broken. Try to fix it. + */ +#ifdef __LIBELF_HEADER_ELF_H + +# ifndef ELF32_FSZ_ADDR +# define ELF32_FSZ_ADDR 4 +# define ELF32_FSZ_HALF 2 +# define ELF32_FSZ_OFF 4 +# define ELF32_FSZ_SWORD 4 +# define ELF32_FSZ_WORD 4 +# endif /* ELF32_FSZ_ADDR */ + +# ifndef STN_UNDEF +# define STN_UNDEF 0 +# endif /* STN_UNDEF */ + +# if __LIBELF64 + +# ifndef ELF64_FSZ_ADDR +# define ELF64_FSZ_ADDR 8 +# define ELF64_FSZ_HALF 2 +# define ELF64_FSZ_OFF 8 +# define ELF64_FSZ_SWORD 4 +# define ELF64_FSZ_WORD 4 +# define ELF64_FSZ_SXWORD 8 +# define ELF64_FSZ_XWORD 8 +# endif /* ELF64_FSZ_ADDR */ + +# ifndef ELF64_ST_BIND +# define ELF64_ST_BIND(i) ((i)>>4) +# define ELF64_ST_TYPE(i) ((i)&0xf) +# define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) +# endif /* ELF64_ST_BIND */ + +# ifndef ELF64_R_SYM +# define ELF64_R_SYM(i) ((Elf64_Xword)(i)>>32) +# define ELF64_R_TYPE(i) ((i)&0xffffffffL) +# define ELF64_R_INFO(s,t) (((Elf64_Xword)(s)<<32)+((t)&0xffffffffL)) +# endif /* ELF64_R_SYM */ + +# if __LIBELF64_LINUX +typedef __libelf_u64_t Elf64_Addr; +typedef __libelf_u16_t Elf64_Half; +typedef __libelf_u64_t Elf64_Off; +typedef __libelf_i32_t Elf64_Sword; +typedef __libelf_u32_t Elf64_Word; +typedef __libelf_i64_t Elf64_Sxword; +typedef __libelf_u64_t Elf64_Xword; +# endif /* __LIBELF64_LINUX */ + +# endif /* __LIBELF64 */ +#endif /* __LIBELF_HEADER_ELF_H */ diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/verdef.h b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/verdef.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/verdef.h @@ -0,0 +1,241 @@ +/* + * verdef.h - copy versioning information. + * Copyright (C) 2001 - 2006 Michael Riepe + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef lint +static const char verdef_h_rcsid[] = "@(#) $Id: verdef.h,v 1.13 2008/05/23 08:15:35 michael Exp $"; +#endif /* lint */ + +#if VER_DEF_CURRENT != 1 +#error libelf currently does not support VER_DEF_CURRENT != 1 +#endif /* VER_DEF_CURRENT != 1 */ + +#if TOFILE + +static void +__store_verdaux(verdaux_ftype *dst, const verdaux_mtype *src, unsigned enc) { + if (enc == ELFDATA2LSB) { + __store_u32L(dst->vda_name, src->vda_name); + __store_u32L(dst->vda_next, src->vda_next); + } + else { + __store_u32M(dst->vda_name, src->vda_name); + __store_u32M(dst->vda_next, src->vda_next); + } +} + +static void +__store_verdef(verdef_ftype *dst, const verdef_mtype *src, unsigned enc) { + if (enc == ELFDATA2LSB) { + __store_u16L(dst->vd_version, src->vd_version); + __store_u16L(dst->vd_flags, src->vd_flags); + __store_u16L(dst->vd_ndx, src->vd_ndx); + __store_u16L(dst->vd_cnt, src->vd_cnt); + __store_u32L(dst->vd_hash, src->vd_hash); + __store_u32L(dst->vd_aux, src->vd_aux); + __store_u32L(dst->vd_next, src->vd_next); + } + else { + __store_u16M(dst->vd_version, src->vd_version); + __store_u16M(dst->vd_flags, src->vd_flags); + __store_u16M(dst->vd_ndx, src->vd_ndx); + __store_u16M(dst->vd_cnt, src->vd_cnt); + __store_u32M(dst->vd_hash, src->vd_hash); + __store_u32M(dst->vd_aux, src->vd_aux); + __store_u32M(dst->vd_next, src->vd_next); + } +} + +typedef verdaux_mtype verdaux_stype; +typedef verdaux_ftype verdaux_dtype; +typedef verdef_mtype verdef_stype; +typedef verdef_ftype verdef_dtype; +typedef align_mtype verdef_atype; + +#define copy_verdaux_srctotmp(d, s, e) (*(d) = *(s)) +#define copy_verdaux_tmptodst(d, s, e) __store_verdaux((d), (s), (e)) +#define copy_verdef_srctotmp(d, s, e) (*(d) = *(s)) +#define copy_verdef_tmptodst(d, s, e) __store_verdef((d), (s), (e)) + +#define translator_suffix _tof + +#else /* TOFILE */ + +static void +__load_verdaux(verdaux_mtype *dst, const verdaux_ftype *src, unsigned enc) { + if (enc == ELFDATA2LSB) { + dst->vda_name = __load_u32L(src->vda_name); + dst->vda_next = __load_u32L(src->vda_next); + } + else { + dst->vda_name = __load_u32M(src->vda_name); + dst->vda_next = __load_u32M(src->vda_next); + } +} + +static void +__load_verdef(verdef_mtype *dst, const verdef_ftype *src, unsigned enc) { + if (enc == ELFDATA2LSB) { + dst->vd_version = __load_u16L(src->vd_version); + dst->vd_flags = __load_u16L(src->vd_flags); + dst->vd_ndx = __load_u16L(src->vd_ndx); + dst->vd_cnt = __load_u16L(src->vd_cnt); + dst->vd_hash = __load_u32L(src->vd_hash); + dst->vd_aux = __load_u32L(src->vd_aux); + dst->vd_next = __load_u32L(src->vd_next); + } + else { + dst->vd_version = __load_u16M(src->vd_version); + dst->vd_flags = __load_u16M(src->vd_flags); + dst->vd_ndx = __load_u16M(src->vd_ndx); + dst->vd_cnt = __load_u16M(src->vd_cnt); + dst->vd_hash = __load_u32M(src->vd_hash); + dst->vd_aux = __load_u32M(src->vd_aux); + dst->vd_next = __load_u32M(src->vd_next); + } +} + +typedef verdaux_ftype verdaux_stype; +typedef verdaux_mtype verdaux_dtype; +typedef verdef_ftype verdef_stype; +typedef verdef_mtype verdef_dtype; +typedef align_ftype verdef_atype; + +#define copy_verdaux_srctotmp(d, s, e) __load_verdaux((d), (s), (e)) +#define copy_verdaux_tmptodst(d, s, e) (*(d) = *(s)) +#define copy_verdef_srctotmp(d, s, e) __load_verdef((d), (s), (e)) +#define copy_verdef_tmptodst(d, s, e) (*(d) = *(s)) + +#define translator_suffix _tom + +#endif /* TOFILE */ + +#define cat3(a,b,c) a##b##c +#define xlt3(p,e,s) cat3(p,e,s) +#define xltprefix(x) xlt3(x,_,class_suffix) +#define translator(x,e) xlt3(xltprefix(_elf_##x),e,translator_suffix) + +static size_t +xlt_verdef(unsigned char *dst, const unsigned char *src, size_t n, unsigned enc) { + size_t off; + + if (sizeof(verdef_stype) != sizeof(verdef_dtype) + || sizeof(verdaux_stype) != sizeof(verdaux_dtype)) { + /* never happens for ELF v1 and Verneed v1 */ + seterr(ERROR_UNIMPLEMENTED); + return (size_t)-1; + } + /* size translation shortcut */ + if (dst == NULL) { + return n; + } + if (src == NULL) { + seterr(ERROR_NULLBUF); + return (size_t)-1; + } + off = 0; + while (off + sizeof(verdef_stype) <= n) { + const verdef_stype *svd; + verdef_dtype *dvd; + verdef_mtype vd; + size_t acount; + size_t aoff; + + /* + * check for proper alignment + */ + if (off % sizeof(verdef_atype)) { + seterr(ERROR_VERDEF_FORMAT); + return (size_t)-1; + } + /* + * copy and check src + */ + svd = (verdef_stype*)(src + off); + dvd = (verdef_dtype*)(dst + off); + copy_verdef_srctotmp(&vd, svd, enc); + if (vd.vd_version < 1 + || vd.vd_version > VER_DEF_CURRENT) { + seterr(ERROR_VERDEF_VERSION); + return (size_t)-1; + } + if (vd.vd_cnt < 1 + || vd.vd_aux == 0) { + seterr(ERROR_VERDEF_FORMAT); + return (size_t)-1; + } + copy_verdef_tmptodst(dvd, &vd, enc); + /* + * copy aux array + */ + aoff = off + vd.vd_aux; + for (acount = 0; acount < vd.vd_cnt; acount++) { + const verdaux_stype *svda; + verdaux_dtype *dvda; + verdaux_mtype vda; + + /* + * are we still inside the buffer limits? + */ + if (aoff + sizeof(verdaux_stype) > n) { + break; + } + /* + * check for proper alignment + */ + if (aoff % sizeof(verdef_atype)) { + seterr(ERROR_VERDEF_FORMAT); + return (size_t)-1; + } + /* + * copy and check src + */ + svda = (verdaux_stype*)(src + aoff); + dvda = (verdaux_dtype*)(dst + aoff); + copy_verdaux_srctotmp(&vda, svda, enc); + copy_verdaux_tmptodst(dvda, &vda, enc); + /* + * advance to next verdaux + */ + if (vda.vda_next == 0) { + /* end of list */ + break; + } + aoff += vda.vda_next; + } + /* + * advance to next verdef + */ + if (vd.vd_next == 0) { + /* end of list */ + break; + } + off += vd.vd_next; + } + return n; +} + +size_t +translator(verdef,L11)(unsigned char *dst, const unsigned char *src, size_t n) { + return xlt_verdef(dst, src, n, ELFDATA2LSB); +} + +size_t +translator(verdef,M11)(unsigned char *dst, const unsigned char *src, size_t n) { + return xlt_verdef(dst, src, n, ELFDATA2MSB); +} diff --git a/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/verneed.h b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/verneed.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/elf/libelfWin32/include/libelf/verneed.h @@ -0,0 +1,245 @@ +/* + * verneed.h - copy versioning information. + * Copyright (C) 2001 - 2006 Michael Riepe + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef lint +static const char verneed_h_rcsid[] = "@(#) $Id: verneed.h,v 1.13 2008/05/23 08:15:35 michael Exp $"; +#endif /* lint */ + +#if VER_NEED_CURRENT != 1 +#error libelf currently does not support VER_NEED_CURRENT != 1 +#endif /* VER_NEED_CURRENT != 1 */ + +#if TOFILE + +static void +__store_vernaux(vernaux_ftype *dst, const vernaux_mtype *src, unsigned enc) { + if (enc == ELFDATA2LSB) { + __store_u32L(dst->vna_hash, src->vna_hash); + __store_u16L(dst->vna_flags, src->vna_flags); + __store_u16L(dst->vna_other, src->vna_other); + __store_u32L(dst->vna_name, src->vna_name); + __store_u32L(dst->vna_next, src->vna_next); + } + else { + __store_u32M(dst->vna_hash, src->vna_hash); + __store_u16M(dst->vna_flags, src->vna_flags); + __store_u16M(dst->vna_other, src->vna_other); + __store_u32M(dst->vna_name, src->vna_name); + __store_u32M(dst->vna_next, src->vna_next); + } +} + +static void +__store_verneed(verneed_ftype *dst, const verneed_mtype *src, unsigned enc) { + if (enc == ELFDATA2LSB) { + __store_u16L(dst->vn_version, src->vn_version); + __store_u16L(dst->vn_cnt, src->vn_cnt); + __store_u32L(dst->vn_file, src->vn_file); + __store_u32L(dst->vn_aux, src->vn_aux); + __store_u32L(dst->vn_next, src->vn_next); + } + else { + __store_u16M(dst->vn_version, src->vn_version); + __store_u16M(dst->vn_cnt, src->vn_cnt); + __store_u32M(dst->vn_file, src->vn_file); + __store_u32M(dst->vn_aux, src->vn_aux); + __store_u32M(dst->vn_next, src->vn_next); + } +} + +typedef vernaux_mtype vernaux_stype; +typedef vernaux_ftype vernaux_dtype; +typedef verneed_mtype verneed_stype; +typedef verneed_ftype verneed_dtype; +typedef align_mtype verneed_atype; + +#define copy_vernaux_srctotmp(d, s, e) (*(d) = *(s)) +#define copy_vernaux_tmptodst(d, s, e) __store_vernaux((d), (s), (e)) +#define copy_verneed_srctotmp(d, s, e) (*(d) = *(s)) +#define copy_verneed_tmptodst(d, s, e) __store_verneed((d), (s), (e)) + +#define translator_suffix _tof + +#else /* TOFILE */ + +static void +__load_vernaux(vernaux_mtype *dst, const vernaux_ftype *src, unsigned enc) { + if (enc == ELFDATA2LSB) { + dst->vna_hash = __load_u32L(src->vna_hash); + dst->vna_flags = __load_u16L(src->vna_flags); + dst->vna_other = __load_u16L(src->vna_other); + dst->vna_name = __load_u32L(src->vna_name); + dst->vna_next = __load_u32L(src->vna_next); + } + else { + dst->vna_hash = __load_u32M(src->vna_hash); + dst->vna_flags = __load_u16M(src->vna_flags); + dst->vna_other = __load_u16M(src->vna_other); + dst->vna_name = __load_u32M(src->vna_name); + dst->vna_next = __load_u32M(src->vna_next); + } +} + +static void +__load_verneed(verneed_mtype *dst, const verneed_ftype *src, unsigned enc) { + if (enc == ELFDATA2LSB) { + dst->vn_version = __load_u16L(src->vn_version); + dst->vn_cnt = __load_u16L(src->vn_cnt); + dst->vn_file = __load_u32L(src->vn_file); + dst->vn_aux = __load_u32L(src->vn_aux); + dst->vn_next = __load_u32L(src->vn_next); + } + else { + dst->vn_version = __load_u16M(src->vn_version); + dst->vn_cnt = __load_u16M(src->vn_cnt); + dst->vn_file = __load_u32M(src->vn_file); + dst->vn_aux = __load_u32M(src->vn_aux); + dst->vn_next = __load_u32M(src->vn_next); + } +} + +typedef vernaux_ftype vernaux_stype; +typedef vernaux_mtype vernaux_dtype; +typedef verneed_ftype verneed_stype; +typedef verneed_mtype verneed_dtype; +typedef align_ftype verneed_atype; + +#define copy_vernaux_srctotmp(d, s, e) __load_vernaux((d), (s), (e)) +#define copy_vernaux_tmptodst(d, s, e) (*(d) = *(s)) +#define copy_verneed_srctotmp(d, s, e) __load_verneed((d), (s), (e)) +#define copy_verneed_tmptodst(d, s, e) (*(d) = *(s)) + +#define translator_suffix _tom + +#endif /* TOFILE */ + +#define cat3(a,b,c) a##b##c +#define xlt3(p,e,s) cat3(p,e,s) +#define xltprefix(x) xlt3(x,_,class_suffix) +#define translator(x,e) xlt3(xltprefix(_elf_##x),e,translator_suffix) + +static size_t +xlt_verneed(unsigned char *dst, const unsigned char *src, size_t n, unsigned enc) { + size_t off; + + if (sizeof(verneed_stype) != sizeof(verneed_dtype) + || sizeof(vernaux_stype) != sizeof(vernaux_dtype)) { + /* never happens for ELF v1 and Verneed v1 */ + seterr(ERROR_UNIMPLEMENTED); + return (size_t)-1; + } + /* size translation shortcut */ + if (dst == NULL) { + return n; + } + if (src == NULL) { + seterr(ERROR_NULLBUF); + return (size_t)-1; + } + off = 0; + while (off + sizeof(verneed_stype) <= n) { + const verneed_stype *svn; + verneed_dtype *dvn; + verneed_mtype vn; + size_t acount; + size_t aoff; + + /* + * check for proper alignment + */ + if (off % sizeof(verneed_atype)) { + seterr(ERROR_VERNEED_FORMAT); + return (size_t)-1; + } + /* + * copy and check src + */ + svn = (verneed_stype*)(src + off); + dvn = (verneed_dtype*)(dst + off); + copy_verneed_srctotmp(&vn, svn, enc); + if (vn.vn_version < 1 + || vn.vn_version > VER_NEED_CURRENT) { + seterr(ERROR_VERNEED_VERSION); + return (size_t)-1; + } + if (vn.vn_cnt < 1 + || vn.vn_aux == 0) { + seterr(ERROR_VERNEED_FORMAT); + return (size_t)-1; + } + copy_verneed_tmptodst(dvn, &vn, enc); + /* + * copy aux array + */ + aoff = off + vn.vn_aux; + for (acount = 0; acount < vn.vn_cnt; acount++) { + const vernaux_stype *svna; + vernaux_dtype *dvna; + vernaux_mtype vna; + + /* + * are we still inside the buffer limits? + */ + if (aoff + sizeof(vernaux_stype) > n) { + break; + } + /* + * check for proper alignment + */ + if (aoff % sizeof(verneed_atype)) { + seterr(ERROR_VERNEED_FORMAT); + return (size_t)-1; + } + /* + * copy and check src + */ + svna = (vernaux_stype*)(src + aoff); + dvna = (vernaux_dtype*)(dst + aoff); + copy_vernaux_srctotmp(&vna, svna, enc); + copy_vernaux_tmptodst(dvna, &vna, enc); + /* + * advance to next vernaux + */ + if (vna.vna_next == 0) { + /* end of list */ + break; + } + aoff += vna.vna_next; + } + /* + * advance to next verneed + */ + if (vn.vn_next == 0) { + /* end of list */ + break; + } + off += vn.vn_next; + } + return n; +} + +size_t +translator(verneed,L11)(unsigned char *dst, const unsigned char *src, size_t n) { + return xlt_verneed(dst, src, n, ELFDATA2LSB); +} + +size_t +translator(verneed,M11)(unsigned char *dst, const unsigned char *src, size_t n) { + return xlt_verneed(dst, src, n, ELFDATA2MSB); +} diff --git a/src/common/genericBinaryFiles/srec/srecfile.cpp b/src/common/genericBinaryFiles/srec/srecfile.cpp new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/srec/srecfile.cpp @@ -0,0 +1,403 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#include "srecfile.h" +#include +#include "binaryfile.h" + +srecFile::srecFile() +{ +} + +srecFile::srecFile(const QString &File) +{ + openFile(File); +} + +srecFile::srecFile(const QStringList &Files) +{ + openFiles(Files); +} + +srecFile::~srecFile() +{ + +} + +bool srecFile::openFile(const QString &File) +{ + return openFiles(QStringList()<p_isSrec=true; + this->p_isSrec &= isSREC(Files.at(i)); + this->p_files.append(new QFile(Files.at(i))); + this->p_files.at(i)->open(QIODevice::ReadOnly); + parseFile(this->p_files.at(i)); + } + return true; +} + +bool srecFile::isopened() +{ + bool opened = true; + for(int i=0;ip_files.count();i++) + { + opened &= p_files.at(i)->isOpen(); + } + return opened; +} + +int srecFile::closeFile() +{ + for(int i=0;i srecFile::getFragments() +{ + return p_fragments; +} + +bool srecFile::toSrec(QList fragments, const QString &File) +{ + QString line; + QFile file(File); + file.open(QIODevice::WriteOnly); + if(file.isOpen()) + { + QTextStream stream( &file ); + //First build header + stream << buildRecord(0,0,File.toStdString().c_str(),File.count()); + for(int i=0;isize));j+=16) + { + stream << buildRecord(3,fragment->address+j,fragment->data+j,16); + } + int rem = fragment->size % 16; + if(rem) + { + stream << buildRecord(3,fragment->address+fragment->size-rem,fragment->data+fragment->size-rem,rem); + } + stream << buildRecord(7,fragment->address,NULL,0); + } + file.close(); + return true; + } + + return false; +} + +bool srecFile::toSrec(const QString &File) +{ + return toSrec(p_fragments,File); +} + +bool srecFile::toBinary(const QString &File) +{ + return binaryFile::toBinary(p_fragments,File); +} + +int srecFile::lineCount() +{ + return p_lineCount; +} + +int srecFile::getFragmentsCount() +{ + return p_fragments.count(); +} + +int srecFile::getFragmentAddress(int index) +{ + if((index < p_fragments.count()) && (index>=0)) + { + return p_fragments.at(index)->address; + } + return 0; +} + +int srecFile::getFragmentSize(int index) +{ + if((index < p_fragments.count()) && (index>=0)) + { + return p_fragments.at(index)->size; + } + return 0; +} + +codeFragment *srecFile::getFragment(int index) +{ + if((index < p_fragments.count()) && (index>=0)) + { + return p_fragments.at(index); + } + return NULL; +} + +QString srecFile::getFragmentHeader(int index) +{ + if((index < p_fragments.count()) && (index>=0)) + { + return p_fragments.at(index)->header; + } + return ""; +} + +bool srecFile::getFragmentData(int index, char **buffer) +{ + + if((index < p_fragments.count()) && (index>=0)) + { + *buffer = (char *)this->p_fragments.at(index)->data; + return true; + } + return false; +} + +bool srecFile::isSREC() +{ + return p_isSrec & isopened(); +} + +bool srecFile::isSREC(const QString &File) +{ + QFile file(File); + file.open(QIODevice::ReadOnly); + if(file.isOpen()) + { + file.seek(0); + QString line=file.readLine(); + file.close(); + return ((line.at(0)=='S')&&(line.at(1)=='0')); + } + return false; +} + +void srecFile::parseFile(QFile *file) +{ + if(file->isOpen()) + { + this->p_lineCount = 0; + file->seek(0); + codeFragment* fragment=NULL; + char* data; + quint64 size=0; + quint64 address=-1; + QString header; + while (!file->atEnd()) + { + QString line = file->readLine(); + p_lineCount++; + int rectype = parseLine(line,&address,&data,&size); + if(rectype==0) + { + header.clear(); + header.append(data); + fragment = new codeFragment(data,size,address); + fragment->header = header; + p_fragments.append(fragment); + } + else + { + if((rectype>=1) && (rectype<=3)) + { + bool merged = false; + //Could I merge it with an other fragment? + // TODO should make merging optionnal + for(int i=0;iaddress+frag->size)==address) && (merged==false) && (size!=0)) + { + char* mergedData=(char*)malloc(size+frag->size); + memcpy(mergedData,frag->data,frag->size); + memcpy(mergedData+frag->size,data,size); + free(frag->data); + free(data); + frag->data = mergedData; + frag->size = frag->size+size; + merged = true; + } + } + if(!merged) + { + fragment = new codeFragment(data,size,address); + fragment->header = header; + p_fragments.append(fragment); + } + } + else + { + + } + } + } + } +} + +int srecFile::parseLine(const QString &record, quint64 *address, char **data, quint64 *size) +{ +#define newData (*data) +#define newAddress (*address) +#define newSize (*size) + int recType = -1; + if((record.count()>4) && checkSum(record)) + { + if(record.at(0)=='S') + { + recType = record.at(1).toLatin1() & 0x0F; + //Header type + if(recType==0) + { + newAddress = record.mid(4,4).toInt(0,16); + newSize = record.mid(2,2).toInt(0,16) - 3; + if(newSize>0) + { + newData=(char*)malloc(newSize+1); + for(int i=0;i<(int)newSize;i++) + { + newData[i] = ((char)record.mid((2*i)+8,2).toInt(0,16)); + } + newData[newSize] = '\0'; // force string end for header + } + } + //2 address byte record type + if((recType==1) || (recType==5) || (recType==9)) + { + newAddress = record.mid(4,4).toInt(0,16); + newSize = record.mid(2,2).toInt(0,16) - 3; + if(newSize>0) + { + newData=(char*)malloc(newSize); + for(int i=0;i<(int)newSize;i++) + { + newData[i] = ((char)record.mid((2*i)+8,2).toInt(0,16)); + } + } + } + //3 address byte record type + if((recType==2) || (recType==6) || (recType==8)) + { + newAddress = record.mid(4,6).toInt(0,16); + newSize = record.mid(2,2).toInt(0,16) - 4; + if(newSize>0) + { + newData=(char*)malloc(newSize); + for(int i=0;i<(int)newSize;i++) + { + newData[i] = ((char)record.mid((2*i)+10,2).toInt(0,16)); + } + } + } + //4 address byte record type + if((recType==3) || (recType==7)) + { + newAddress = record.mid(4,8).toInt(0,16); + newSize = record.mid(2,2).toInt(0,16) - 5; + if(newSize>0) + { + newData=(char*)malloc(newSize); + for(int i=0;i<(int)newSize;i++) + { + newData[i] = ((char)record.mid((2*i)+12,2).toInt(0,16)); + } + } + } + } + } + return recType; +} + +char srecFile::lineCheckSum(const QString &line) +{ + char sum=0; + QString localLine = line; + bool ok; + if(localLine.at(0)=='S') // then should skip the first two digits + { + localLine.remove(0,2); + } + for(int i=0;i=0) && (recType<=9)) + { + record.append("S"); + record.append(QString::number(recType)); + //2 address byte record type + if((recType==0) || (recType==1) || (recType==5) || (recType==9)) + { + record.append(QString("%1").arg(3+size,2,16).replace(' ','0')); + record.append(QString("%1").arg(address,4,16).replace(' ','0')); + } + //3 address byte record type + if((recType==2) || (recType==6) || (recType==8)) + { + record.append(QString("%1").arg(4+size,2,16).replace(' ','0')); + record.append(QString("%1").arg(address,6,16).replace(' ','0')); + } + //4 address byte record type + if((recType==3) || (recType==7)) + { + record.append(QString("%1").arg(5+size,2,16).replace(' ','0')); + record.append(QString("%1").arg(address,8,16).replace(' ','0')); + } + for(int i=0; i +#include +#include +#include + +class srecFile : public abstractBinFile +{ + Q_OBJECT +public: + explicit srecFile(); + srecFile(const QString& File); + srecFile(const QStringList& Files); + ~srecFile(); + bool openFile(const QString& File); + bool openFiles(const QStringList& Files); + bool isopened(); + int closeFile(); + QList getFragments(); + static bool toSrec(QList fragments,const QString& File); + bool toSrec(const QString &File); + bool toBinary(const QString& File); + int lineCount(); + int getFragmentsCount(); + int getFragmentAddress(int index); + int getFragmentSize(int index); + codeFragment *getFragment(int index); + QString getFragmentHeader(int index); + bool getFragmentData(int index, char **buffer); + + bool isSREC(); + static bool isSREC(const QString& File); +signals: + +public slots: +private: + void parseFile(QFile* file); + static int parseLine(const QString& record, quint64 *address, char** data, quint64 *size); + static char lineCheckSum(const QString& line); + static bool checkSum(const QString& line); + static QString buildRecord(int recType,int address,const char* data,int size); + QStringList p_fileNames; + QListp_files; + QList p_fragments; + int p_lineCount; + bool p_isSrec; + +}; + +#endif // SRECFILE_H diff --git a/src/common/genericBinaryFiles/srec/srecfilewidget.cpp b/src/common/genericBinaryFiles/srec/srecfilewidget.cpp new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/srec/srecfilewidget.cpp @@ -0,0 +1,144 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#include "srecfilewidget.h" +#include "ui_srecfilewidget.h" +#include +#include +#include +#include "binaryfile.h" + +srecFileWidget::srecFileWidget(QWidget *parent) : + abstractBinFileWidget(parent), + ui(new Ui::srecFileWidget) +{ + ui->setupUi(this); + connect(this->ui->fragmentsList,SIGNAL(cellActivated(int,int)),this,SLOT(recordCellActivated(int,int))); + this->setWindowTitle("SocExplorer SREC viewer"); + exportToSREC_action = new QAction(tr("Export to SREC"),this); + exportToBIN_action = new QAction(tr("Export to Binary"),this); + this->ui->fragmentsList->addAction(exportToBIN_action); + this->ui->fragmentsList->addAction(exportToSREC_action); + connect(this->exportToBIN_action,SIGNAL(triggered()),this,SLOT(exportToBIN())); + connect(this->exportToSREC_action,SIGNAL(triggered()),this,SLOT(exportToSREC())); +} + +srecFileWidget::~srecFileWidget() +{ + delete ui; +} + +void srecFileWidget::setFile(abstractBinFile *file) +{ + this->p_srec = (srecFile*)file; + if(p_srec->isopened() && p_srec->isSREC()) + { + reloadFile(); + } +} + +void srecFileWidget::reloadFile() +{ + this->ui->fragmentsList->clear(); + this->ui->fragmentsList->setRowCount(p_srec->getFragmentsCount()); + this->ui->fragmentsList->setHorizontalHeaderLabels(QStringList()<<"Index"<<"Address"<<"Size"<<"Header"); + for(int i=0;igetFragmentsCount();i++) + { + QTableWidgetItem *newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(i),DecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->fragmentsList->setItem(i, 0, newItem); + + newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("0x%1").arg(p_srec->getFragmentAddress(i),8,16).replace(" ","0"),HexaDecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->fragmentsList->setItem(i, 1, newItem); + + newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(p_srec->getFragmentSize(i)),DecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->fragmentsList->setItem(i, 2, newItem); + + newItem = new QTableWidgetItem(p_srec->getFragmentHeader(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->fragmentsList->setItem(i, 3, newItem); + + } + this->ui->fragmentsList->resizeColumnsToContents(); +} + +void srecFileWidget::recordCellActivated(int row, int column) +{ + Q_UNUSED(column) + char* buff=NULL; + int index = this->ui->fragmentsList->item(row,0)->text().toInt(); + if(index!=-1) + { + this->p_srec->getFragmentData(index,&buff); + this->ui->fragmentHexView->setData(QByteArray(buff,this->p_srec->getFragmentSize(index))); + this->ui->fragmentHexView->setAddressOffset(this->p_srec->getFragmentAddress(index)); + } + +} + +void srecFileWidget::exportToSREC() +{ + QList SelectedFragmentsList=getSelectedFragments(); + if(SelectedFragmentsList.count()>0) + { + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), + NULL, + tr("SREC Files (*.srec)")); + if(!fileName.isEmpty()) + { + srecFile::toSrec(SelectedFragmentsList,fileName); + } + } +} + +void srecFileWidget::exportToBIN() +{ + QList SelectedFragmentsList=getSelectedFragments(); + if(SelectedFragmentsList.count()>0) + { + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), + NULL, + tr("Binary Files (*.bin)")); + if(!fileName.isEmpty()) + { + binaryFile::toBinary(SelectedFragmentsList,fileName); + } + } +} + +QList srecFileWidget::getSelectedFragments() +{ + QList SelectedFragmentsList; + QList items = this->ui->fragmentsList->selectedItems(); + for(int i=0;igetFragment(items.at(i)->row()); + if(!SelectedFragmentsList.contains(fragment)) + { + SelectedFragmentsList.append(fragment); + } + } + return SelectedFragmentsList; +} + + diff --git a/src/common/genericBinaryFiles/srec/srecfilewidget.h b/src/common/genericBinaryFiles/srec/srecfilewidget.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/srec/srecfilewidget.h @@ -0,0 +1,58 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#ifndef SRECFILEWIDGET_H +#define SRECFILEWIDGET_H + +#include +#include "srecfile.h" +#include + +namespace Ui { +class srecFileWidget; +} + +class srecFileWidget : public abstractBinFileWidget +{ + Q_OBJECT + +public: + explicit srecFileWidget(QWidget *parent = 0); + ~srecFileWidget(); + +public slots: + void setFile(abstractBinFile* file); + void reloadFile(); + +private slots: + void recordCellActivated(int row, int column); + void exportToSREC(); + void exportToBIN(); + +private: + QList getSelectedFragments(); + Ui::srecFileWidget *ui; + srecFile* p_srec; + QAction* exportToSREC_action; + QAction* exportToBIN_action; +}; + +#endif // SRECFILEWIDGET_H diff --git a/src/common/genericBinaryFiles/srec/srecfilewidget.ui b/src/common/genericBinaryFiles/srec/srecfilewidget.ui new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/srec/srecfilewidget.ui @@ -0,0 +1,87 @@ + + + srecFileWidget + + + + 0 + 0 + 740 + 516 + + + + Form + + + + + + Qt::Horizontal + + + + Hexadecimal Viewer + + + + + + + 256 + 0 + + + + + + + + + SREC records list + + + + + + Qt::ActionsContextMenu + + + + Index + + + + + Address + + + + + Size + + + + + Header + + + + + + + + + + + + + QHexEdit + QWidget +
qhexedit.h
+ 1 +
+
+ + +
diff --git a/src/common/pythongenerator.sh b/src/common/pythongenerator.sh --- a/src/common/pythongenerator.sh +++ b/src/common/pythongenerator.sh @@ -3,4 +3,4 @@ #export QTDIR=/usr/include #export QTDIR=/usr/include/qt5 -pythonqt_generator --include-paths=./elf:./srec:./BinFile:/usr/include/qt5:/usr/include/qt5/QtCore:/usr/include/qt5/QtWidgets --output-directory=pythonQtOut PySocExplorer.h pythonQtgeneratorCfg.txt +pythonqt_generator --include-paths=./genericBinaryFiles/elf:./genericBinaryFiles/srec:./genericBinaryFiles/BinFile:/usr/include/qt5:/usr/include/qt5/QtCore:/usr/include/qt5/QtWidgets --output-directory=pythonQtOut PySocExplorer.h pythonQtgeneratorCfg.txt diff --git a/src/src.pro b/src/src.pro --- a/src/src.pro +++ b/src/src.pro @@ -21,9 +21,10 @@ INCLUDEPATH+=$${PWD} \ $${PWD}/common \ $${PWD}/common/qhexedit \ $${PWD}/common/QCustomPlot \ - $${PWD}/common/elf \ - $${PWD}/common/srec \ - $${PWD}/common/BinFile \ + $${PWD}/common/genericBinaryFiles \ + $${PWD}/common/genericBinaryFiles/elf \ + $${PWD}/common/genericBinaryFiles/srec \ + $${PWD}/common/genericBinaryFiles/BinFile \ SocExplorerEngine/engine \ SocExplorerEngine/pluginloader \ SocExplorerEngine/pluginsInterface \ @@ -36,8 +37,8 @@ INCLUDEPATH+=$${PWD} \ SocExplorerEngine/PeripheralWidget/src win32:INCLUDEPATH+= \ - $${PWD}/common/elf/libelfWin32/include \ - $${PWD}/common/elf/libelfWin32/include/libelf \ + $${PWD}/common/genericBinaryFiles/elf/libelfWin32/include \ + $${PWD}/common/genericBinaryFiles/elf/libelfWin32/include/libelf \ RC_FILE = ../win32cfg/socexplorer.rc