// copyright (c) 2017-2021 hors // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // #include "xelf.h" XELF::XELF(QIODevice *pDevice, bool bIsImage, qint64 nModuleAddress): XBinary(pDevice,bIsImage,nModuleAddress) { } XELF::~XELF() { } bool XELF::isValid() { bool bResult=false; if(getIdent_Magic()== XELF_DEF::ELFMAG) { quint8 nClass=getIdent_class(); if((nClass== XELF_DEF::ELFCLASS32)||(nClass== XELF_DEF::ELFCLASS64)) { bResult=true; } } return bResult; } bool XELF::isValid(QIODevice *pDevice, bool bIsImage, qint64 nModuleAddress) { XELF xelf(pDevice,bIsImage,nModuleAddress); return xelf.isValid(); } XBinary::MODE XELF::getMode(QIODevice *pDevice, bool bIsImage, qint64 nModuleAddress) { XELF xelf(pDevice,bIsImage,nModuleAddress); return xelf.getMode(); } bool XELF::isBigEndian() { return getIdent_data()== XELF_DEF::ELFDATA2MSB; } qint64 XELF::getEhdrOffset() { return 0; } qint64 XELF::getEhdr32Size() { return sizeof(XELF_DEF::Elf32_Ehdr); } qint64 XELF::getEhdr64Size() { return sizeof(XELF_DEF::Elf64_Ehdr); } quint32 XELF::getIdent_Magic() { return read_uint32((quint64) XELF_DEF::EI_MAG0); } void XELF::setIdent_Magic(quint32 nValue) { write_uint32((quint64) XELF_DEF::EI_MAG0,nValue); } quint8 XELF::getIdent_mag(int nMag) { quint8 nValue=0; if(nMag<4) { nValue=read_uint8(nMag); } return nValue; } void XELF::setIdent_mag(quint8 nValue, int nMag) { if(nMag<4) { write_uint8(nMag,nValue); } } quint32 XELF::getIdent_mag_LE() { return read_uint32(0,false); } void XELF::setIdent_mag_LE(quint32 nValue) { write_uint32(0,nValue,false); } quint8 XELF::getIdent_class() { return read_uint8( XELF_DEF::EI_CLASS); } void XELF::setIdent_class(quint8 nValue) { write_uint8( XELF_DEF::EI_CLASS,nValue); } quint8 XELF::getIdent_data() { return read_uint8( XELF_DEF::EI_DATA); } void XELF::setIdent_data(quint8 nValue) { write_uint8( XELF_DEF::EI_DATA,nValue); } quint8 XELF::getIdent_version() { return read_uint8( XELF_DEF::EI_VERSION); } void XELF::setIdent_version(quint8 nValue) { write_uint8( XELF_DEF::EI_VERSION,nValue); } quint8 XELF::getIdent_osabi() { return read_uint8( XELF_DEF::EI_OSABI); } void XELF::setIdent_osabi(quint8 nValue) { write_uint8( XELF_DEF::EI_OSABI,nValue); } quint8 XELF::getIdent_abiversion() { return read_uint8( XELF_DEF::EI_ABIVERSION); } void XELF::setIdent_abiversion(quint8 nValue) { write_uint8( XELF_DEF::EI_ABIVERSION,nValue); } quint8 XELF::getIdent_pad(int nPad) { quint8 nValue=0; if(nPad<7) { nValue=read_uint8( XELF_DEF::EI_ABIVERSION+1+nPad); } return nValue; } void XELF::setIdent_pad(quint8 nValue, int nPad) { if(nPad<7) { write_uint8( XELF_DEF::EI_ABIVERSION+1+nPad,nValue); } } quint16 XELF::getHdr32_type() { return read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_type),isBigEndian()); } void XELF::setHdr32_type(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_type),nValue,isBigEndian()); } quint16 XELF::getHdr32_machine() { return read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_machine),isBigEndian()); } void XELF::setHdr32_machine(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_machine),nValue,isBigEndian()); } quint32 XELF::getHdr32_version() { return read_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_version),isBigEndian()); } void XELF::setHdr32_version(quint32 nValue) { write_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_version),nValue,isBigEndian()); } quint32 XELF::getHdr32_entry() { return read_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_entry),isBigEndian()); } void XELF::setHdr32_entry(quint32 nValue) { write_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_entry),nValue,isBigEndian()); } quint32 XELF::getHdr32_phoff() { return read_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_phoff),isBigEndian()); } void XELF::setHdr32_phoff(quint32 nValue) { write_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_phoff),nValue,isBigEndian()); } quint32 XELF::getHdr32_shoff() { return read_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_shoff),isBigEndian()); } void XELF::setHdr32_shoff(quint32 nValue) { write_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_shoff),nValue,isBigEndian()); } quint32 XELF::getHdr32_flags() { return read_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_flags),isBigEndian()); } void XELF::setHdr32_flags(quint32 nValue) { write_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_flags),nValue,isBigEndian()); } quint16 XELF::getHdr32_ehsize() { return read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_ehsize),isBigEndian()); } void XELF::setHdr32_ehsize(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_ehsize),nValue,isBigEndian()); } quint16 XELF::getHdr32_phentsize() { return read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_phentsize),isBigEndian()); } void XELF::setHdr32_phentsize(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_phentsize),nValue,isBigEndian()); } quint16 XELF::getHdr32_phnum() { return read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_phnum),isBigEndian()); } void XELF::setHdr32_phnum(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_phnum),nValue,isBigEndian()); } quint16 XELF::getHdr32_shentsize() { return read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_shentsize),isBigEndian()); } void XELF::setHdr32_shentsize(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_shentsize),nValue,isBigEndian()); } quint16 XELF::getHdr32_shnum() { return read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_shnum),isBigEndian()); } void XELF::setHdr32_shnum(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_shnum),nValue,isBigEndian()); } quint16 XELF::getHdr32_shstrndx() { return read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_shstrndx),isBigEndian()); } void XELF::setHdr32_shstrndx(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_shstrndx),nValue,isBigEndian()); } quint16 XELF::getHdr64_type() { return read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_type),isBigEndian()); } void XELF::setHdr64_type(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_type),nValue,isBigEndian()); } quint16 XELF::getHdr64_machine() { return read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_machine),isBigEndian()); } void XELF::setHdr64_machine(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_machine),nValue,isBigEndian()); } quint32 XELF::getHdr64_version() { return read_uint32(offsetof(XELF_DEF::Elf64_Ehdr,e_version),isBigEndian()); } void XELF::setHdr64_version(quint32 nValue) { write_uint32(offsetof(XELF_DEF::Elf64_Ehdr,e_version),nValue,isBigEndian()); } quint64 XELF::getHdr64_entry() { return read_uint64(offsetof(XELF_DEF::Elf64_Ehdr,e_entry),isBigEndian()); } void XELF::setHdr64_entry(quint64 nValue) { write_uint64(offsetof(XELF_DEF::Elf64_Ehdr,e_entry),nValue,isBigEndian()); } quint64 XELF::getHdr64_phoff() { return read_uint64(offsetof(XELF_DEF::Elf64_Ehdr,e_phoff),isBigEndian()); } void XELF::setHdr64_phoff(quint64 nValue) { write_uint64(offsetof(XELF_DEF::Elf64_Ehdr,e_phoff),nValue,isBigEndian()); } quint64 XELF::getHdr64_shoff() { return read_uint64(offsetof(XELF_DEF::Elf64_Ehdr,e_shoff),isBigEndian()); } void XELF::setHdr64_shoff(quint64 nValue) { write_uint64(offsetof(XELF_DEF::Elf64_Ehdr,e_shoff),nValue,isBigEndian()); } quint32 XELF::getHdr64_flags() { return read_uint32(offsetof(XELF_DEF::Elf64_Ehdr,e_flags),isBigEndian()); } void XELF::setHdr64_flags(quint32 nValue) { write_uint32(offsetof(XELF_DEF::Elf64_Ehdr,e_flags),nValue,isBigEndian()); } quint16 XELF::getHdr64_ehsize() { return read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_ehsize),isBigEndian()); } void XELF::setHdr64_ehsize(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_ehsize),nValue,isBigEndian()); } quint16 XELF::getHdr64_phentsize() { return read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_phentsize),isBigEndian()); } void XELF::setHdr64_phentsize(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_phentsize),nValue,isBigEndian()); } quint16 XELF::getHdr64_phnum() { return read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_phnum),isBigEndian()); } void XELF::setHdr64_phnum(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_phnum),nValue,isBigEndian()); } quint16 XELF::getHdr64_shentsize() { return read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_shentsize),isBigEndian()); } void XELF::setHdr64_shentsize(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_shentsize),nValue,isBigEndian()); } quint16 XELF::getHdr64_shnum() { return read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_shnum),isBigEndian()); } void XELF::setHdr64_shnum(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_shnum),nValue,isBigEndian()); } quint16 XELF::getHdr64_shstrndx() { return read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_shstrndx),isBigEndian()); } void XELF::setHdr64_shstrndx(quint16 nValue) { write_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_shstrndx),nValue,isBigEndian()); } XELF_DEF::Elf_Ehdr XELF::getHdr() { XELF_DEF::Elf_Ehdr result={}; bool bIsbigEndian=isBigEndian(); if(!is64()) { result.e_type=read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_type),bIsbigEndian); result.e_machine=read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_machine),bIsbigEndian); result.e_version=read_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_version),bIsbigEndian); result.e_entry=read_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_entry),bIsbigEndian); result.e_phoff=read_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_phoff),bIsbigEndian); result.e_shoff=read_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_shoff),bIsbigEndian); result.e_flags=read_uint32(offsetof(XELF_DEF::Elf32_Ehdr,e_flags),bIsbigEndian); result.e_ehsize=read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_ehsize),bIsbigEndian); result.e_phentsize=read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_phentsize),bIsbigEndian); result.e_phnum=read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_phnum),bIsbigEndian); result.e_shentsize=read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_shentsize),bIsbigEndian); result.e_shnum=read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_shnum),bIsbigEndian); result.e_shstrndx=read_uint16(offsetof(XELF_DEF::Elf32_Ehdr,e_shstrndx),bIsbigEndian); } else { result.e_type=read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_type),bIsbigEndian); result.e_machine=read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_machine),bIsbigEndian); result.e_version=read_uint32(offsetof(XELF_DEF::Elf64_Ehdr,e_version),bIsbigEndian); result.e_entry=read_uint64(offsetof(XELF_DEF::Elf64_Ehdr,e_entry),bIsbigEndian); result.e_phoff=read_uint64(offsetof(XELF_DEF::Elf64_Ehdr,e_phoff),bIsbigEndian); result.e_shoff=read_uint64(offsetof(XELF_DEF::Elf64_Ehdr,e_shoff),bIsbigEndian); result.e_flags=read_uint32(offsetof(XELF_DEF::Elf64_Ehdr,e_flags),bIsbigEndian); result.e_ehsize=read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_ehsize),bIsbigEndian); result.e_phentsize=read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_phentsize),bIsbigEndian); result.e_phnum=read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_phnum),bIsbigEndian); result.e_shentsize=read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_shentsize),bIsbigEndian); result.e_shnum=read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_shnum),bIsbigEndian); result.e_shstrndx=read_uint16(offsetof(XELF_DEF::Elf64_Ehdr,e_shstrndx),bIsbigEndian); } return result; } QMap XELF::getTypes() { QMap mapResult; mapResult.insert(0,"ET_NONE"); mapResult.insert(1,"ET_REL"); mapResult.insert(2,"ET_EXEC"); mapResult.insert(3,"ET_DYN"); mapResult.insert(4,"ET_CORE"); mapResult.insert(5,"ET_NUM"); mapResult.insert(0xff00,"ET_LOPROC"); mapResult.insert(0xffff,"ET_HIPROC"); return mapResult; } QMap XELF::getTypesS() { QMap mapResult; mapResult.insert(0,"NONE"); mapResult.insert(1,"REL"); mapResult.insert(2,"EXEC"); mapResult.insert(3,"DYN"); mapResult.insert(4,"CORE"); mapResult.insert(5,"NUM"); mapResult.insert(0xff00,"LOPROC"); mapResult.insert(0xffff,"HIPROC"); return mapResult; } QMap XELF::getMachines() { QMap mapResult; mapResult.insert(0,"EM_NONE"); // TODO http://users.sosdg.org/~qiyong/mxr/source/sys/sys/exec_XELF_DEF::Elf.h mapResult.insert(1,"EM_M32"); mapResult.insert(2,"EM_SPARC"); mapResult.insert(3,"EM_386"); mapResult.insert(4,"EM_68K"); mapResult.insert(5,"EM_88K"); mapResult.insert(6,"EM_486"); /* Perhaps disused */ mapResult.insert(7,"EM_860"); mapResult.insert(8,"EM_MIPS"); mapResult.insert(9,"EM_S370"); mapResult.insert(10,"EM_MIPS_RS3_LE"); mapResult.insert(11,"EM_RS6000"); mapResult.insert(15,"EM_PARISC"); mapResult.insert(16,"EM_nCUBE"); mapResult.insert(17,"EM_VPP500"); mapResult.insert(18,"EM_SPARC32PLUS"); mapResult.insert(19,"EM_960"); mapResult.insert(20,"EM_PPC"); mapResult.insert(21,"EM_PPC64"); mapResult.insert(22,"EM_S390"); mapResult.insert(23,"EM_SPU"); mapResult.insert(36,"EM_V800"); mapResult.insert(37,"EM_FR20"); mapResult.insert(38,"EM_RH32"); mapResult.insert(39,"EM_RCE"); mapResult.insert(40,"EM_ARM"); mapResult.insert(41,"EM_ALPHA"); mapResult.insert(42,"EM_SH"); mapResult.insert(43,"EM_SPARCV9"); mapResult.insert(44,"EM_TRICORE"); mapResult.insert(45,"EM_ARC"); mapResult.insert(46,"EM_H8_300"); mapResult.insert(47,"EM_H8_300H"); mapResult.insert(48,"EM_H8S"); mapResult.insert(49,"EM_H8_500"); mapResult.insert(50,"EM_IA_64"); mapResult.insert(51,"EM_MIPS_X"); mapResult.insert(52,"EM_COLDFIRE"); mapResult.insert(53,"EM_68HC12"); mapResult.insert(54,"EM_MMA"); mapResult.insert(55,"EM_PCP"); mapResult.insert(56,"EM_NCPU"); mapResult.insert(57,"EM_NDR1"); mapResult.insert(58,"EM_STARCORE"); mapResult.insert(59,"EM_ME16"); mapResult.insert(60,"EM_ST100"); mapResult.insert(61,"EM_TINYJ"); mapResult.insert(62,"EM_AMD64"); // EM_X86_64 mapResult.insert(63,"EM_PDSP"); mapResult.insert(66,"EM_FX66"); mapResult.insert(67,"EM_ST9PLUS"); mapResult.insert(68,"EM_ST7"); mapResult.insert(69,"EM_68HC16"); mapResult.insert(70,"EM_68HC11"); mapResult.insert(71,"EM_68HC08"); mapResult.insert(72,"EM_68HC05"); mapResult.insert(73,"EM_SVX"); mapResult.insert(74,"EM_ST19"); mapResult.insert(75,"EM_VAX"); mapResult.insert(76,"EM_CRIS"); mapResult.insert(77,"EM_JAVELIN"); mapResult.insert(78,"EM_FIREPATH"); mapResult.insert(79,"EM_ZSP"); mapResult.insert(80,"EM_MMIX"); mapResult.insert(81,"EM_HUANY"); mapResult.insert(82,"EM_PRISM"); mapResult.insert(83,"EM_AVR"); mapResult.insert(84,"EM_FR30"); mapResult.insert(85,"EM_D10V"); mapResult.insert(86,"EM_D30V"); mapResult.insert(87,"EM_V850"); mapResult.insert(88,"EM_M32R"); mapResult.insert(89,"EM_MN10300"); mapResult.insert(90,"EM_MN10200"); mapResult.insert(91,"EM_PJ"); mapResult.insert(92,"EM_OPENRISC"); mapResult.insert(93,"EM_ARC_A5"); mapResult.insert(94,"EM_XTENSA"); mapResult.insert(95,"EM_NUM"); // TODO mapResult.insert(106,"EM_BLACKFIN"); mapResult.insert(113,"EM_ALTERA_NIOS2"); mapResult.insert(140,"EM_TI_C6000"); mapResult.insert(183,"EM_AARCH64"); mapResult.insert(243,"EM_RISC_V"); mapResult.insert(0x5441,"EM_FRV"); mapResult.insert(0x18ad,"EM_AVR32"); mapResult.insert(0x9026,"EM_ALPHA"); mapResult.insert(0x9080,"EM_CYGNUS_V850"); mapResult.insert(0x9041,"EM_CYGNUS_M32R"); mapResult.insert(0xA390,"EM_S390_OLD"); mapResult.insert(0xbeef,"EM_CYGNUS_MN10300"); return mapResult; } QMap XELF::getMachinesS() { QMap mapResult; // TODO ftp://ftp.eso.org/pub/solaris/rec_patches/8/8_Recommended/109147-39/SUNWhea/reloc/usr/include/sys/elf.h // TODO http://users.sosdg.org/~qiyong/mxr/source/sys/sys/elf.h mapResult.insert(0,"NONE"); mapResult.insert(1,"M32"); mapResult.insert(2,"SPARC"); mapResult.insert(3,"386"); mapResult.insert(4,"68K"); mapResult.insert(5,"88K"); mapResult.insert(6,"486"); /* Perhaps disused */ mapResult.insert(7,"860"); mapResult.insert(8,"MIPS"); mapResult.insert(9,"S370"); mapResult.insert(10,"MIPS_RS3_LE"); mapResult.insert(11,"RS6000"); mapResult.insert(15,"PARISC"); mapResult.insert(16,"nCUBE"); mapResult.insert(17,"VPP500"); mapResult.insert(18,"SPARC32PLUS"); mapResult.insert(19,"960"); mapResult.insert(20,"PPC"); mapResult.insert(21,"PPC64"); mapResult.insert(22,"S390"); mapResult.insert(23,"SPU"); mapResult.insert(36,"V800"); mapResult.insert(37,"FR20"); mapResult.insert(38,"RH32"); mapResult.insert(39,"RCE"); mapResult.insert(40,"ARM"); mapResult.insert(41,"ALPHA"); mapResult.insert(42,"SH"); mapResult.insert(43,"SPARCV9"); mapResult.insert(44,"TRICORE"); mapResult.insert(45,"ARC"); mapResult.insert(46,"H8_300"); mapResult.insert(47,"H8_300H"); mapResult.insert(48,"H8S"); mapResult.insert(49,"H8_500"); mapResult.insert(50,"IA_64"); mapResult.insert(51,"MIPS_X"); mapResult.insert(52,"COLDFIRE"); mapResult.insert(53,"68HC12"); mapResult.insert(54,"MMA"); mapResult.insert(55,"PCP"); mapResult.insert(56,"NCPU"); mapResult.insert(57,"NDR1"); mapResult.insert(58,"STARCORE"); mapResult.insert(59,"ME16"); mapResult.insert(60,"ST100"); mapResult.insert(61,"TINYJ"); mapResult.insert(62,"AMD64"); // X86_64 mapResult.insert(63,"PDSP"); mapResult.insert(66,"FX66"); mapResult.insert(67,"ST9PLUS"); mapResult.insert(68,"ST7"); mapResult.insert(69,"68HC16"); mapResult.insert(70,"68HC11"); mapResult.insert(71,"68HC08"); mapResult.insert(72,"68HC05"); mapResult.insert(73,"SVX"); mapResult.insert(74,"ST19"); mapResult.insert(75,"VAX"); mapResult.insert(76,"CRIS"); mapResult.insert(77,"JAVELIN"); mapResult.insert(78,"FIREPATH"); mapResult.insert(79,"ZSP"); mapResult.insert(80,"MMIX"); mapResult.insert(81,"HUANY"); mapResult.insert(82,"PRISM"); mapResult.insert(83,"AVR"); mapResult.insert(84,"FR30"); mapResult.insert(85,"D10V"); mapResult.insert(86,"D30V"); mapResult.insert(87,"V850"); mapResult.insert(88,"M32R"); mapResult.insert(89,"MN10300"); mapResult.insert(89,"MN10300"); mapResult.insert(90,"MN10200"); mapResult.insert(91,"PJ"); // TODO mapResult.insert(92,"OPENRISC"); mapResult.insert(93,"ARC_A5"); mapResult.insert(94,"XTENSA"); mapResult.insert(95,"NUM"); mapResult.insert(106,"BLACKFIN"); mapResult.insert(113,"ALTERA_NIOS2"); mapResult.insert(140,"TI_C6000"); mapResult.insert(183,"AARCH64"); mapResult.insert(243,"RISC_V"); mapResult.insert(0x5441,"FRV"); mapResult.insert(0x18ad,"AVR32"); mapResult.insert(0x9026,"ALPHA"); mapResult.insert(0x9080,"CYGNUS_V850"); mapResult.insert(0x9041,"CYGNUS_M32R"); mapResult.insert(0xA390,"S390_OLD"); mapResult.insert(0xbeef,"CYGNUS_MN10300"); return mapResult; } QMap XELF::getHeaderVersionList() { QMap mapResult; mapResult.insert(1,"EV_CURRENT"); return mapResult; } QMap XELF::getIndentMag() { QMap mapResult; mapResult.insert(0x464C457F,"ELFMAG"); return mapResult; } QMap XELF::getIndentMagS() { QMap mapResult; mapResult.insert(0x464C457F,"ELFMAG"); return mapResult; } QMap XELF::getIndentClasses() { QMap mapResult; mapResult.insert(0,"ELFCLASSNONE"); mapResult.insert(1,"ELFCLASS32"); mapResult.insert(2,"ELFCLASS64"); return mapResult; } QMap XELF::getIndentClassesS() { QMap mapResult; mapResult.insert(0,"NONE"); mapResult.insert(1,"32"); mapResult.insert(2,"64"); return mapResult; } QMap XELF::getIndentDatas() { QMap mapResult; mapResult.insert(0,"ELFDATANONE"); mapResult.insert(1,"ELFDATA2LSB"); mapResult.insert(2,"ELFDATA2MSB"); return mapResult; } QMap XELF::getIndentDatasS() { QMap mapResult; mapResult.insert(0,"NONE"); mapResult.insert(1,"2LSB"); mapResult.insert(2,"2MSB"); return mapResult; } QMap XELF::getIndentVersions() { QMap mapResult; mapResult.insert(1,"EV_CURRENT"); return mapResult; } QMap XELF::getIndentVersionsS() { QMap mapResult; mapResult.insert(1,"CURRENT"); return mapResult; } QMap XELF::getIndentOsabis() { QMap mapResult; mapResult.insert(0,"ELFOSABI_SYSV"); mapResult.insert(1,"ELFOSABI_HPUX"); mapResult.insert(2,"ELFOSABI_NETBSD"); mapResult.insert(3,"ELFOSABI_LINUX"); mapResult.insert(4,"ELFOSABI_HURD"); mapResult.insert(5,"ELFOSABI_86OPEN"); mapResult.insert(6,"ELFOSABI_SOLARIS"); mapResult.insert(7,"ELFOSABI_AIX"); mapResult.insert(8,"ELFOSABI_IRIX"); mapResult.insert(9,"ELFOSABI_FREEBSD"); mapResult.insert(10,"ELFOSABI_TRU64"); mapResult.insert(11,"ELFOSABI_MODESTO"); mapResult.insert(12,"ELFOSABI_OPENBSD"); mapResult.insert(13,"ELFOSABI_OPENVMS"); mapResult.insert(14,"ELFOSABI_NSK"); mapResult.insert(15,"ELFOSABI_AROS"); mapResult.insert(16,"ELFOSABI_FENIXOS"); mapResult.insert(17,"ELFOSABI_CLOUDABI"); mapResult.insert(64,"ELFOSABI_ARM_AEABI"); mapResult.insert(97,"ELFOSABI_ARM"); mapResult.insert(255,"ELFOSABI_STANDALONE"); return mapResult; } QMap XELF::getIndentOsabisS() { QMap mapResult; mapResult.insert(0,"SYSV"); mapResult.insert(1,"HPUX"); mapResult.insert(2,"NETBSD"); mapResult.insert(3,"LINUX"); mapResult.insert(4,"HURD"); mapResult.insert(5,"86OPEN"); mapResult.insert(6,"SOLARIS"); mapResult.insert(7,"AIX"); mapResult.insert(8,"IRIX"); mapResult.insert(9,"FREEBSD"); mapResult.insert(10,"TRU64"); mapResult.insert(11,"MODESTO"); mapResult.insert(12,"OPENBSD"); mapResult.insert(13,"OPENVMS"); mapResult.insert(14,"NSK"); mapResult.insert(15,"AROS"); mapResult.insert(16,"FENIXOS"); mapResult.insert(17,"CLOUDABI"); mapResult.insert(64,"ARM_AEABI"); mapResult.insert(97,"ARM"); mapResult.insert(255,"STANDALONE"); return mapResult; } QMap XELF::getSectionTypes() { QMap mapResult; mapResult.insert(0,"SHT_NULL"); mapResult.insert(1,"SHT_PROGBITS"); mapResult.insert(2,"SHT_SYMTAB"); mapResult.insert(3,"SHT_STRTAB"); mapResult.insert(4,"SHT_RELA"); mapResult.insert(5,"SHT_HASH"); mapResult.insert(6,"SHT_DYNAMIC"); mapResult.insert(7,"SHT_NOTE"); mapResult.insert(8,"SHT_NOBITS"); mapResult.insert(9,"SHT_REL"); mapResult.insert(10,"SHT_SHLIB"); mapResult.insert(11,"SHT_DYNSYM"); mapResult.insert(14,"SHT_INIT_ARRAY"); mapResult.insert(15,"SHT_FINI_ARRAY"); mapResult.insert(16,"SHT_PREINIT_ARRAY"); mapResult.insert(17,"SHT_GROUP"); mapResult.insert(18,"SHT_SYMTAB_SHNDX"); mapResult.insert(19,"SHT_NUM"); mapResult.insert(0x60000000,"SHT_LOOS"); mapResult.insert(0x6ffffff6,"SHT_GNU_HASH"); mapResult.insert(0x6ffffffa,"SHT_SUNW_move"); mapResult.insert(0x6ffffffc,"SHT_SUNW_syminfo"); mapResult.insert(0x6ffffffd,"SHT_GNU_verdef"); mapResult.insert(0x6ffffffe,"SHT_GNU_verneed"); mapResult.insert(0x6fffffff,"SHT_GNU_versym"); mapResult.insert(0x70000000,"SHT_LOPROC"); mapResult.insert(0x70000001,"SHT_AMD64_UNWIND"); mapResult.insert(0x70000002,"SHT_ARM_PREEMPTMAP"); mapResult.insert(0x70000003,"SHT_ARM_ATTRIBUTES"); mapResult.insert(0x70000004,"SHT_ARM_DEBUGOVERLAY"); mapResult.insert(0x70000005,"SHT_ARM_OVERLAYSECTION"); mapResult.insert(0x70000006,"SHT_MIPS_REGINFO"); mapResult.insert(0x70000007,"SHT_MIPS_PACKAGE"); mapResult.insert(0x70000008,"SHT_MIPS_PACKSYM"); mapResult.insert(0x70000009,"SHT_MIPS_RELD"); mapResult.insert(0x7000000b,"SHT_MIPS_IFACE"); mapResult.insert(0x7000000c,"SHT_MIPS_CONTENT"); mapResult.insert(0x7000000d,"SHT_MIPS_OPTIONS"); mapResult.insert(0x70000010,"SHT_MIPS_SHDR"); mapResult.insert(0x70000011,"SHT_MIPS_FDESC"); mapResult.insert(0x70000012,"SHT_MIPS_EXTSYM"); mapResult.insert(0x70000013,"SHT_MIPS_DENSE"); mapResult.insert(0x70000014,"SHT_MIPS_PDESC"); mapResult.insert(0x70000015,"SHT_MIPS_LOCSYM"); mapResult.insert(0x70000016,"SHT_MIPS_AUXSYM"); mapResult.insert(0x70000017,"SHT_MIPS_OPTSYM"); mapResult.insert(0x70000018,"SHT_MIPS_LOCSTR"); mapResult.insert(0x70000019,"SHT_MIPS_LINE"); mapResult.insert(0x7000001a,"SHT_MIPS_RFDESC"); mapResult.insert(0x7000001b,"SHT_MIPS_DELTASYM"); mapResult.insert(0x7000001c,"SHT_MIPS_DELTAINST"); mapResult.insert(0x7000001d,"SHT_MIPS_DELTACLASS"); mapResult.insert(0x7000001e,"SHT_MIPS_DWARF"); mapResult.insert(0x7000001f,"SHT_MIPS_DELTADECL"); mapResult.insert(0x70000020,"SHT_MIPS_SYMBOL_LIB"); mapResult.insert(0x70000021,"SHT_MIPS_EVENTS"); mapResult.insert(0x70000022,"SHT_MIPS_TRANSLATE"); mapResult.insert(0x70000023,"SHT_MIPS_PIXIE"); mapResult.insert(0x70000024,"SHT_MIPS_XLATE"); mapResult.insert(0x70000025,"SHT_MIPS_XLATE_DEBUG"); mapResult.insert(0x70000026,"SHT_MIPS_WHIRL"); mapResult.insert(0x70000027,"SHT_MIPS_EH_REGION"); mapResult.insert(0x70000028,"SHT_MIPS_XLATE_OLD"); mapResult.insert(0x70000029,"SHT_MIPS_PDR_EXCEPTION"); mapResult.insert(0x7000002a,"SHT_MIPS_ABIFLAGS"); mapResult.insert(0x7fffffff,"SHT_HIPROC"); mapResult.insert(0x80000000,"SHT_LOUSER"); mapResult.insert(0xffffffff,"SHT_HIUSER"); return mapResult; } QMap XELF::getSectionTypesS() { QMap mapResult; mapResult.insert(0,"NULL"); mapResult.insert(1,"PROGBITS"); mapResult.insert(2,"SYMTAB"); mapResult.insert(3,"STRTAB"); mapResult.insert(4,"RELA"); mapResult.insert(5,"HASH"); mapResult.insert(6,"DYNAMIC"); mapResult.insert(7,"NOTE"); mapResult.insert(8,"NOBITS"); mapResult.insert(9,"REL"); mapResult.insert(10,"SHLIB"); mapResult.insert(11,"DYNSYM"); mapResult.insert(14,"INIT_ARRAY"); mapResult.insert(15,"FINI_ARRAY"); mapResult.insert(16,"PREINIT_ARRAY"); mapResult.insert(17,"GROUP"); mapResult.insert(18,"SYMTAB_SHNDX"); mapResult.insert(19,"NUM"); mapResult.insert(0x60000000,"LOOS"); mapResult.insert(0x6ffffff6,"GNU_HASH"); mapResult.insert(0x6ffffffa,"SUNW_move"); mapResult.insert(0x6ffffffc,"SUNW_syminfo"); mapResult.insert(0x6ffffffd,"GNU_verdef"); mapResult.insert(0x6ffffffe,"GNU_verneed"); mapResult.insert(0x6fffffff,"GNU_versym"); mapResult.insert(0x70000000,"LOPROC"); mapResult.insert(0x70000001,"AMD64_UNWIND"); mapResult.insert(0x70000002,"ARM_PREEMPTMAP"); mapResult.insert(0x70000003,"ARM_ATTRIBUTES"); mapResult.insert(0x70000004,"ARM_DEBUGOVERLAY"); mapResult.insert(0x70000005,"ARM_OVERLAYSECTION"); mapResult.insert(0x70000006,"MIPS_REGINFO"); mapResult.insert(0x70000007,"MIPS_PACKAGE"); mapResult.insert(0x70000008,"MIPS_PACKSYM"); mapResult.insert(0x70000009,"MIPS_RELD"); mapResult.insert(0x7000000b,"MIPS_IFACE"); mapResult.insert(0x7000000c,"MIPS_CONTENT"); mapResult.insert(0x7000000d,"MIPS_OPTIONS"); mapResult.insert(0x70000010,"MIPS_SHDR"); mapResult.insert(0x70000011,"MIPS_FDESC"); mapResult.insert(0x70000012,"MIPS_EXTSYM"); mapResult.insert(0x70000013,"MIPS_DENSE"); mapResult.insert(0x70000014,"MIPS_PDESC"); mapResult.insert(0x70000015,"MIPS_LOCSYM"); mapResult.insert(0x70000016,"MIPS_AUXSYM"); mapResult.insert(0x70000017,"MIPS_OPTSYM"); mapResult.insert(0x70000018,"MIPS_LOCSTR"); mapResult.insert(0x70000019,"MIPS_LINE"); mapResult.insert(0x7000001a,"MIPS_RFDESC"); mapResult.insert(0x7000001b,"MIPS_DELTASYM"); mapResult.insert(0x7000001c,"MIPS_DELTAINST"); mapResult.insert(0x7000001d,"MIPS_DELTACLASS"); mapResult.insert(0x7000001e,"MIPS_DWARF"); mapResult.insert(0x7000001f,"MIPS_DELTADECL"); mapResult.insert(0x70000020,"MIPS_SYMBOL_LIB"); mapResult.insert(0x70000021,"MIPS_EVENTS"); mapResult.insert(0x70000022,"MIPS_TRANSLATE"); mapResult.insert(0x70000023,"MIPS_PIXIE"); mapResult.insert(0x70000024,"MIPS_XLATE"); mapResult.insert(0x70000025,"MIPS_XLATE_DEBUG"); mapResult.insert(0x70000026,"MIPS_WHIRL"); mapResult.insert(0x70000027,"MIPS_EH_REGION"); mapResult.insert(0x70000028,"MIPS_XLATE_OLD"); mapResult.insert(0x70000029,"MIPS_PDR_EXCEPTION"); mapResult.insert(0x7000002a,"MIPS_ABIFLAGS"); mapResult.insert(0x7fffffff,"HIPROC"); mapResult.insert(0x80000000,"LOUSER"); mapResult.insert(0xffffffff,"HIUSER"); return mapResult; } QMap XELF::getSectionFlags() { QMap mapResult; mapResult.insert(0x00000001,"SHF_WRITE"); mapResult.insert(0x00000002,"SHF_ALLOC"); mapResult.insert(0x00000004,"SHF_EXECINSTR"); mapResult.insert(0x00000010,"SHF_MERGE"); mapResult.insert(0x00000020,"SHF_STRINGS"); mapResult.insert(0x00000040,"SHF_INFO_LINK"); mapResult.insert(0x00000080,"SHF_LINK_ORDER"); mapResult.insert(0x00000100,"SHF_OS_NONCONFORMING"); mapResult.insert(0x00000200,"SHF_GROUP"); mapResult.insert(0x00000400,"SHF_TLS"); mapResult.insert(0x0ff00000,"SHF_MASKOS"); mapResult.insert(0xf0000000,"SHF_MASKPROC"); mapResult.insert(0x40000000,"SHF_ORDERED"); mapResult.insert(0x80000000,"SHF_EXCLUDE"); return mapResult; } QMap XELF::getSectionFlagsS() { QMap mapResult; mapResult.insert(0x00000001,"WRITE"); mapResult.insert(0x00000002,"ALLOC"); mapResult.insert(0x00000004,"EXECINSTR"); mapResult.insert(0x00000010,"MERGE"); mapResult.insert(0x00000020,"STRINGS"); mapResult.insert(0x00000040,"INFO_LINK"); mapResult.insert(0x00000080,"LINK_ORDER"); mapResult.insert(0x00000100,"OS_NONCONFORMING"); mapResult.insert(0x00000200,"GROUP"); mapResult.insert(0x00000400,"TLS"); mapResult.insert(0x0ff00000,"MASKOS"); mapResult.insert(0xf0000000,"MASKPROC"); mapResult.insert(0x40000000,"ORDERED"); mapResult.insert(0x80000000,"EXCLUDE"); return mapResult; } QMap XELF::getProgramTypes() { QMap mapResult; mapResult.insert(0,"PT_NULL"); mapResult.insert(1,"PT_LOAD"); mapResult.insert(2,"PT_DYNAMIC"); mapResult.insert(3,"PT_INTERP"); mapResult.insert(4,"PT_NOTE"); mapResult.insert(5,"PT_SHLIB"); mapResult.insert(6,"PT_PHDR"); mapResult.insert(7,"PT_TLS"); mapResult.insert(8,"PT_NUM"); mapResult.insert(0x60000000,"PT_LOOS"); mapResult.insert(0x6464e550,"PT_SUNW_UNWIND"); mapResult.insert(0x6474e550,"PT_GNU_EH_FRAME"); // PT_SUNW_EH_FRAME mapResult.insert(0x6474e551,"PT_GNU_STACK"); mapResult.insert(0x6474e552,"PT_GNU_RELRO"); mapResult.insert(0x6ffffffa,"PT_LOSUNW"); mapResult.insert(0x6ffffffa,"PT_SUNWBSS"); mapResult.insert(0x6ffffffb,"PT_SUNWSTACK"); mapResult.insert(0x6ffffffc,"PT_SUNWDTRACE"); mapResult.insert(0x6ffffffd,"PT_SUNWCAP"); mapResult.insert(0x6fffffff,"PT_HIOS"); // PT_HISUNW mapResult.insert(0x70000000,"PT_LOPROC"); mapResult.insert(0x7fffffff,"PT_HIPROC"); // mapResult.insert(0x70000000,"PT_MIPXELF_DEF::REGINFO"); return mapResult; } QMap XELF::getProgramTypesS() { QMap mapResult; mapResult.insert(0,"NULL"); mapResult.insert(1,"LOAD"); mapResult.insert(2,"DYNAMIC"); mapResult.insert(3,"INTERP"); mapResult.insert(4,"NOTE"); mapResult.insert(5,"SHLIB"); mapResult.insert(6,"PHDR"); mapResult.insert(7,"TLS"); mapResult.insert(8,"NUM"); mapResult.insert(0x60000000,"LOOS"); mapResult.insert(0x6464e550,"SUNW_UNWIND"); mapResult.insert(0x6474e550,"GNU_EH_FRAME"); // SUNW_EH_FRAME mapResult.insert(0x6474e551,"GNU_STACK"); mapResult.insert(0x6474e552,"GNU_RELRO"); mapResult.insert(0x6ffffffa,"LOSUNW"); mapResult.insert(0x6ffffffa,"SUNWBSS"); mapResult.insert(0x6ffffffb,"SUNWSTACK"); mapResult.insert(0x6ffffffc,"SUNWDTRACE"); mapResult.insert(0x6ffffffd,"SUNWCAP"); mapResult.insert(0x6fffffff,"HIOS"); // HISUNW mapResult.insert(0x70000000,"LOPROC"); mapResult.insert(0x7fffffff,"HIPROC"); // mapResult.insert(0x70000000,"MIPXELF_DEF::REGINFO"); return mapResult; } QMap XELF::getProgramFlags() { QMap mapResult; mapResult.insert(0x00000001,"PF_X"); mapResult.insert(0x00000002,"PF_W"); mapResult.insert(0x00000004,"PF_R"); mapResult.insert(0x0ff00000,"PF_MASKOS"); mapResult.insert(0xf0000000,"PF_MASKPROC"); return mapResult; } QMap XELF::getProgramFlagsS() { QMap mapResult; mapResult.insert(0x00000001,"X"); mapResult.insert(0x00000002,"W"); mapResult.insert(0x00000004,"R"); mapResult.insert(0x0ff00000,"MASKOS"); mapResult.insert(0xf0000000,"MASKPROC"); return mapResult; } quint16 XELF::getSectionStringTable() { return getSectionStringTable(is64()); } quint16 XELF::getSectionStringTable(bool bIs64) { quint32 nResult=0; if(bIs64) { nResult=getHdr64_shstrndx(); } else { nResult=getHdr32_shstrndx(); } return nResult; } XBinary::OFFSETSIZE XELF::getSectionOffsetSize(quint32 nSection) { OFFSETSIZE result={}; if(is64()) { XELF_DEF::Elf64_Shdr section_header=getElf64_Shdr(nSection); result.nOffset=section_header.sh_offset; result.nSize=section_header.sh_size; } else { XELF_DEF::Elf32_Shdr section_header=getElf32_Shdr(nSection); result.nOffset=section_header.sh_offset; result.nSize=section_header.sh_size; } return result; } QMap XELF::getStringsFromSection(quint32 nSection) { QMap mapResult; if(nSection!= XELF_DEF::SHN_UNDEF) { QByteArray baSection=getSection(nSection); mapResult=getStringsFromSectionData(&baSection); } return mapResult; } QMap XELF::getStringsFromSectionData(QByteArray *pbaData) { QMap mapResult; int nSize=pbaData->size(); char *pOffset=pbaData->data(); quint32 nCurrentOffset=0; while(nSize>0) { QString sString(pOffset+nCurrentOffset); if(sString.length()) { mapResult.insert(nCurrentOffset,sString); } nCurrentOffset+=(quint32)sString.length()+1; nSize-=sString.length()+1; } return mapResult; } QString XELF::getStringFromSection(quint32 nIndex, quint32 nSection) { QString sResult; XBinary::OFFSETSIZE offsetSize=getSectionOffsetSize(nSection); sResult=getStringFromIndex(offsetSize.nOffset,offsetSize.nSize,nIndex); return sResult; } QMap XELF::getStringsFromMainSection() { quint32 nSection=getSectionStringTable(); return getStringsFromSection(nSection); } QString XELF::getStringFromMainSection(quint32 nIndex) { quint32 nSection=getSectionStringTable(); return getStringFromSection(nIndex,nSection); // TODO optimize } QByteArray XELF::getSection(quint32 nIndex) { qint64 nOffset=0; qint64 nSize=0; if(is64()) { XELF_DEF::Elf64_Shdr section_header=getElf64_Shdr(nIndex); nSize=section_header.sh_size; nOffset=(isImage())?(section_header.sh_addr):(section_header.sh_offset); } else { XELF_DEF::Elf32_Shdr section_header=getElf32_Shdr(nIndex); nSize=section_header.sh_size; nOffset=(isImage())?(section_header.sh_addr):(section_header.sh_offset); } return read_array(nOffset,nSize); } bool XELF::isSectionValid(quint32 nIndex) { quint32 nNumberOfSections=getHdr32_shnum(); return (nIndex XELF::getElf32_ShdrList() { QList listResult; quint32 nNumberOfSections=getHdr32_shnum(); nNumberOfSections=qMin((quint32)1000,nNumberOfSections); quint32 nOffset=getHdr32_shoff(); bool bIsBigEndian=isBigEndian(); for(quint32 i=0; i XELF::getElf64_ShdrList() { QList listResult; quint32 nNumberOfSections=getHdr64_shnum(); nNumberOfSections=qMin((quint32)1000,nNumberOfSections); quint64 nOffset=getHdr64_shoff(); bool bIsBigEndian=isBigEndian(); for(quint32 i=0; i XELF::getElf_ShdrList() { QList listResult; bool bIs64=is64(); if(bIs64) { QList listSectionHeaders=getElf64_ShdrList(); int nNumberOfSections=listSectionHeaders.count(); for(int i=0;i listSectionHeaders=getElf32_ShdrList(); int nNumberOfSections=listSectionHeaders.count(); for(int i=0;i *pListSectionHeaders) { quint32 nResult=0; if(nIndex<(quint32)pListSectionHeaders->count()) { nResult=pListSectionHeaders->at(nIndex).sh_name; } return nResult; } quint32 XELF::getElf_Shdr_type(quint32 nIndex, QList *pListSectionHeaders) { quint32 nResult=0; if(nIndex<(quint32)pListSectionHeaders->count()) { nResult=pListSectionHeaders->at(nIndex).sh_type; } return nResult; } quint64 XELF::getElf_Shdr_flags(quint32 nIndex, QList *pListSectionHeaders) { quint64 nResult=0; if(nIndex<(quint32)pListSectionHeaders->count()) { nResult=pListSectionHeaders->at(nIndex).sh_flags; } return nResult; } quint64 XELF::getElf_Shdr_addr(quint32 nIndex, QList *pListSectionHeaders) { quint64 nResult=0; if(nIndex<(quint32)pListSectionHeaders->count()) { nResult=pListSectionHeaders->at(nIndex).sh_addr; } return nResult; } quint64 XELF::getElf_Shdr_offset(quint32 nIndex, QList *pListSectionHeaders) { quint64 nResult=0; if(nIndex<(quint32)pListSectionHeaders->count()) { nResult=pListSectionHeaders->at(nIndex).sh_offset; } return nResult; } quint64 XELF::getElf_Shdr_size(quint32 nIndex, QList *pListSectionHeaders) { quint64 nResult=0; if(nIndex<(quint32)pListSectionHeaders->count()) { nResult=pListSectionHeaders->at(nIndex).sh_size; } return nResult; } quint32 XELF::getElf_Shdr_link(quint32 nIndex, QList *pListSectionHeaders) { quint32 nResult=0; if(nIndex<(quint32)pListSectionHeaders->count()) { nResult=pListSectionHeaders->at(nIndex).sh_link; } return nResult; } quint32 XELF::getElf_Shdr_info(quint32 nIndex, QList *pListSectionHeaders) { quint32 nResult=0; if(nIndex<(quint32)pListSectionHeaders->count()) { nResult=pListSectionHeaders->at(nIndex).sh_info; } return nResult; } quint64 XELF::getElf_Shdr_addralign(quint32 nIndex, QList *pListSectionHeaders) { quint64 nResult=0; if(nIndex<(quint32)pListSectionHeaders->count()) { nResult=pListSectionHeaders->at(nIndex).sh_addralign; } return nResult; } quint64 XELF::getElf_Shdr_entsize(quint32 nIndex, QList *pListSectionHeaders) { quint32 nResult=0; if(nIndex<(quint32)pListSectionHeaders->count()) { nResult=pListSectionHeaders->at(nIndex).sh_entsize; } return nResult; } qint64 XELF::getShdrOffset(quint32 nIndex) { quint64 nResult=-1; bool bIs64=is64(); quint32 nNumberOfSections=0; if(bIs64) { nNumberOfSections=getHdr64_shnum(); if(nIndex XELF::getElf32_PhdrList() { QList result; quint32 nNumberOfProgramms=getHdr32_phnum(); nNumberOfProgramms=qMin((quint32)1000,nNumberOfProgramms); quint32 nOffset=getHdr32_phoff(); bool bIsBigEndian=isBigEndian(); for(quint32 i=0; i XELF::getElf64_PhdrList() { QList result; quint32 nNumberOfProgramms=getHdr64_phnum(); nNumberOfProgramms=qMin((quint32)1000,nNumberOfProgramms); quint64 nOffset=getHdr64_phoff(); bool bIsBigEndian=isBigEndian(); for(quint32 i=0; i XELF::getElf_PhdrList() { QList listResult; bool bIs64=is64(); if(bIs64) { QList listProgramHeaders=getElf64_PhdrList(); int nNumberOfPrograms=listProgramHeaders.count(); for(int i=0;i listProgramHeaders=getElf32_PhdrList(); int nNumberOfPrograms=listProgramHeaders.count(); for(int i=0;i *pListProgramHeaders) { quint32 nResult=0; if(nIndex<(quint32)pListProgramHeaders->count()) { nResult=pListProgramHeaders->at(nIndex).p_type; } return nResult; } quint64 XELF::getElf_Phdr_offset(quint32 nIndex, QList *pListProgramHeaders) { quint64 nResult=0; if(nIndex<(quint32)pListProgramHeaders->count()) { nResult=pListProgramHeaders->at(nIndex).p_offset; } return nResult; } quint64 XELF::getElf_Phdr_vaddr(quint32 nIndex, QList *pListProgramHeaders) { quint64 nResult=0; if(nIndex<(quint32)pListProgramHeaders->count()) { nResult=pListProgramHeaders->at(nIndex).p_vaddr; } return nResult; } quint64 XELF::getElf_Phdr_paddr(quint32 nIndex, QList *pListProgramHeaders) { quint64 nResult=0; if(nIndex<(quint32)pListProgramHeaders->count()) { nResult=pListProgramHeaders->at(nIndex).p_paddr; } return nResult; } quint64 XELF::getElf_Phdr_filesz(quint32 nIndex, QList *pListProgramHeaders) { quint64 nResult=0; if(nIndex<(quint32)pListProgramHeaders->count()) { nResult=pListProgramHeaders->at(nIndex).p_filesz; } return nResult; } quint64 XELF::getElf_Phdr_memsz(quint32 nIndex, QList *pListProgramHeaders) { quint64 nResult=0; if(nIndex<(quint32)pListProgramHeaders->count()) { nResult=pListProgramHeaders->at(nIndex).p_memsz; } return nResult; } quint32 XELF::getElf_Phdr_flags(quint32 nIndex, QList *pListProgramHeaders) { quint32 nResult=0; if(nIndex<(quint32)pListProgramHeaders->count()) { nResult=pListProgramHeaders->at(nIndex).p_flags; } return nResult; } quint64 XELF::getElf_Phdr_align(quint32 nIndex, QList *pListProgramHeaders) { quint64 nResult=0; if(nIndex<(quint32)pListProgramHeaders->count()) { nResult=pListProgramHeaders->at(nIndex).p_align; } return nResult; } qint64 XELF::getPhdrOffset(quint32 nIndex) { quint64 nResult=-1; bool bIs64=is64(); quint32 nNumberOfPrograms=0; if(bIs64) { nNumberOfPrograms=getHdr64_phnum(); if(nIndex listProgramHeaders=getElf_PhdrList(); return getProgramInterpreterName(&listProgramHeaders); } XBinary::OS_ANSISTRING XELF::getProgramInterpreterName(QList *pListProgramHeaders) { OS_ANSISTRING result={}; QList listInterps=_getPrograms(pListProgramHeaders,XELF_DEF::PT_INTERP); if(listInterps.count()) { result=getOsAnsiString(listInterps.at(0).p_offset,listInterps.at(0).p_filesz); } return result; } QList XELF::getCommentStrings() { // TODO Optimize return getCommentStrings(getSectionIndexByName(".comment")); } QList XELF::getCommentStrings(int nSection) { return getStringsFromSection(nSection).values(); } QList XELF::getNotes() { QList listProgramHeaders=getElf_PhdrList(); return getNotes(&listProgramHeaders); } //QString XELF::getCompatibleKernelVersion() //{ // QString sResult; // QByteArray baData=getSectionByName(".note.ABI-tag"); // bool bIsBigEndian=isBigEndian(); // NOTE note=getNote(baData,bIsBigEndian); // if((note.nType==1)&&(note.name=="GNU")) // { // quint32 kv[4]; // kv[0]=_read_uint32(note.desc.data()+0,bIsBigEndian); // kv[1]=_read_uint32(note.desc.data()+4,bIsBigEndian); // kv[2]=_read_uint32(note.desc.data()+8,bIsBigEndian); // kv[3]=_read_uint32(note.desc.data()+12,bIsBigEndian); // if(kv[0]==0) // { // sResult=QString("%1.%2.%3").arg(QString::number(kv[1]),QString::number(kv[2]),QString::number(kv[3])); // } // } // return sResult; //} QList XELF::getNotes(QList *pListProgramHeaders) { QList listResult; QList listNotes=_getPrograms(pListProgramHeaders,XELF_DEF::PT_NOTE); bool bIsBigEndian=isBigEndian(); int nNumberOfNotes=listNotes.count(); for(int i=0;i XELF::_getNotes(qint64 nOffset, qint64 nSize, bool bIsBigEndian) { QList listResult; int nNumberOfRecords=0; while(nSize>0) { NOTE note=_readNote(nOffset,nSize,bIsBigEndian); if(note.nSize) { listResult.append(note); nOffset+=note.nSize; nSize-=note.nSize; } else { break; } nNumberOfRecords++; if(nNumberOfRecords>1000) { break; } } return listResult; } XELF::NOTE XELF::_readNote(qint64 nOffset, qint64 nSize, bool bIsBigEndian) { NOTE result={}; if(nSize>=6) { quint16 nNameLength= read_uint32(nOffset+0,bIsBigEndian); quint16 nDescLength= read_uint32(nOffset+4,bIsBigEndian); quint16 nType= read_uint32(nOffset+8,bIsBigEndian); qint32 nNoteSize=12+S_ALIGN_UP(nNameLength,4)+S_ALIGN_UP(nDescLength,4); if(nSize>=nNoteSize) { result.nOffset=nOffset; result.nSize=nNoteSize; result.nType=nType; if(nNameLength>=1) { result.sName=read_ansiString(nOffset+12,nNameLength-1); } result.nDataOffset=nOffset+12+S_ALIGN_UP(nNameLength,4); result.nDataSize=qMax((nOffset+nSize)-result.nDataOffset,(qint64)0); } } return result; } bool XELF::isNotePresent(QList *pListNotes, QString sName) { bool bResult=false; for(int i=0;icount();i++) { if(pListNotes->at(i).sName==sName) { bResult=true; false; } } return bResult; } XELF::NOTE XELF::getNote(QList *pListNotes, QString sName) { NOTE result={}; for(int i=0;icount();i++) { if(pListNotes->at(i).sName==sName) { result=pListNotes->at(i); false; } } return result; } QList XELF::getTagStructs() { _MEMORY_MAP memoryMap=getMemoryMap(); QList listProgramHeaders=getElf_PhdrList(); return getTagStructs(&listProgramHeaders,&memoryMap); } QList XELF::getTagStructs(QList *pListProgramHeaders, XBinary::_MEMORY_MAP *pMemoryMap) { QList listResult; bool bIs64=is64(); bool bIsBigEndian=isBigEndian(); QList listTags=_getPrograms(pListProgramHeaders,XELF_DEF::PT_DYNAMIC); int nNumberOfTags=listTags.count(); for(int i=0;i XELF::_getTagStructs(qint64 nOffset, qint64 nSize, bool bIs64, bool bIsBigEndian) { QList listResult; while(nSize>0) { TAG_STRUCT tagStruct={}; tagStruct.nOffset=nOffset; if(bIs64) { tagStruct.nTag=read_int64(nOffset,bIsBigEndian); tagStruct.nValue=read_int64(nOffset+8,bIsBigEndian); nOffset+=16; nSize-=16; } else { tagStruct.nTag=read_int32(nOffset,bIsBigEndian); tagStruct.nValue=read_int32(nOffset+4,bIsBigEndian); nOffset+=8; nSize-=8; } if(tagStruct.nTag) { listResult.append(tagStruct); } else { break; } } return listResult; } QList XELF::_getTagStructs(QList *pListTagStructs, qint64 nTag) { QList listResult; int nNumberOfTags=pListTagStructs->count(); for(int i=0;iat(i).nTag==nTag) { listResult.append(pListTagStructs->at(i)); } } return listResult; } qint64 XELF::getDynamicArraySize() { quint64 nResult=0; bool bIs64=is64(); if(bIs64) { nResult=16; // TODO defs } else { nResult=8; // TODO defs } return nResult; } qint64 XELF::getDynamicArrayTag(qint64 nOffset) { qint64 nResult=0; bool bIs64=is64(); bool bIsBigEndian=isBigEndian(); if(bIs64) { nResult=read_int64(nOffset,bIsBigEndian); } else { nResult=read_int32(nOffset,bIsBigEndian); } return nResult; } qint64 XELF::getDynamicArrayValue(qint64 nOffset) { qint64 nResult=0; bool bIs64=is64(); bool bIsBigEndian=isBigEndian(); if(bIs64) { nResult=read_int64(nOffset+8,bIsBigEndian); } else { nResult=read_int32(nOffset+4,bIsBigEndian); } return nResult; } void XELF::setDynamicArrayTag(qint64 nOffset, qint64 nValue) { bool bIs64=is64(); bool bIsBigEndian=isBigEndian(); if(bIs64) { write_int64(nOffset,nValue,bIsBigEndian); } else { write_int32(nOffset,(qint32)nValue,bIsBigEndian); } } void XELF::setDynamicArrayValue(qint64 nOffset, qint64 nValue) { bool bIs64=is64(); bool bIsBigEndian=isBigEndian(); if(bIs64) { write_int64(nOffset+8,nValue,bIsBigEndian); } else { write_int32(nOffset+4,(qint32)nValue,bIsBigEndian); } } XBinary::OFFSETSIZE XELF::getStringTable() { _MEMORY_MAP memoryMap=getMemoryMap(); QList listStructs=getTagStructs(); return getStringTable(&memoryMap,&listStructs); } XBinary::OFFSETSIZE XELF::getStringTable(XBinary::_MEMORY_MAP *pMemoryMap, QList *pListTagStructs) { OFFSETSIZE result={}; QList listStrTab=_getTagStructs(pListTagStructs,XELF_DEF::DT_STRTAB); QList listStrSize=_getTagStructs(pListTagStructs,XELF_DEF::DT_STRSZ); if(listStrTab.count()&&listStrSize.count()) { qint64 nOffset=addressToOffset(pMemoryMap,listStrTab.at(0).nValue); qint64 nSize=listStrSize.at(0).nValue; if(isOffsetAndSizeValid(pMemoryMap,nOffset,nSize)) { result.nOffset=nOffset; result.nSize=nSize; } } return result; } QList XELF::getLibraries() { _MEMORY_MAP memoryMap=getMemoryMap(); QList listTagStructs=getTagStructs(); return getLibraries(&memoryMap,&listTagStructs); } QList XELF::getLibraries(_MEMORY_MAP *pMemoryMap,QList *pList) { QList listResult; QList listNeeded=_getTagStructs(pList,XELF_DEF::DT_NEEDED); OFFSETSIZE offsetSize=getStringTable(pMemoryMap,pList); if(offsetSize.nSize) { qint64 nOffset=offsetSize.nOffset; QByteArray baSection=read_array(nOffset,offsetSize.nSize); qint64 nSectionTableSize=baSection.size(); int nNumberOfNeededs=listNeeded.count(); for(int i=0;i listTagStructs=getTagStructs(); return getRunPath(&memoryMap,&listTagStructs); } XBinary::OS_ANSISTRING XELF::getRunPath(XBinary::_MEMORY_MAP *pMemoryMap, QList *pListTagStructs) { OS_ANSISTRING result={}; QList listRunPath=_getTagStructs(pListTagStructs,XELF_DEF::DT_RUNPATH); QList listStrTab=_getTagStructs(pListTagStructs,XELF_DEF::DT_STRTAB); QList listStrSize=_getTagStructs(pListTagStructs,XELF_DEF::DT_STRSZ); if(listStrTab.count()&&listStrSize.count()&&listRunPath.count()) { qint64 nOffset=addressToOffset(pMemoryMap,listStrTab.at(0).nValue); qint64 nSize=listStrSize.at(0).nValue; qint64 nRunPath=listRunPath.at(0).nValue; if(nRunPath XELF::getDynamicTags() { QMap mapResult; mapResult.insert(0,"DT_NULL"); mapResult.insert(1,"DT_NEEDED"); mapResult.insert(2,"DT_PLTRELSZ"); mapResult.insert(3,"DT_PLTGOT"); mapResult.insert(4,"DT_HASH"); mapResult.insert(5,"DT_STRTAB"); mapResult.insert(6,"DT_SYMTAB"); mapResult.insert(7,"DT_RELA"); mapResult.insert(8,"DT_RELASZ"); mapResult.insert(9,"DT_RELAENT"); mapResult.insert(10,"DT_STRSZ"); mapResult.insert(11,"DT_SYMENT"); mapResult.insert(12,"DT_INIT"); mapResult.insert(13,"DT_FINI"); mapResult.insert(14,"DT_SONAME"); mapResult.insert(15,"DT_RPATH"); mapResult.insert(16,"DT_SYMBOLIC"); mapResult.insert(17,"DT_REL"); mapResult.insert(18,"DT_RELSZ"); mapResult.insert(19,"DT_RELENT"); mapResult.insert(20,"DT_PLTREL"); mapResult.insert(21,"DT_DEBUG"); mapResult.insert(22,"DT_TEXTREL"); mapResult.insert(23,"DT_JMPREL"); mapResult.insert(24,"DT_BIND_NOW"); mapResult.insert(25,"DT_INIT_ARRAY"); mapResult.insert(26,"DT_FINI_ARRAY"); mapResult.insert(27,"DT_INIT_ARRAYSZ"); mapResult.insert(28,"DT_FINI_ARRAYSZ"); mapResult.insert(29,"DT_RUNPATH"); mapResult.insert(30,"DT_FLAGS"); mapResult.insert(32,"DT_PREINIT_ARRAY"); // DT_ENCODING mapResult.insert(33,"DT_PREINIT_ARRAYSZ"); mapResult.insert(0x6000000d,"DT_LOOS"); mapResult.insert(0x6000000e,"DT_SUNW_RTLDINF"); mapResult.insert(0x6ffff000,"DT_HIOS"); mapResult.insert(0x6ffffd00,"DT_VALRNGLO"); mapResult.insert(0x6ffffdf8,"DT_CHECKSUM"); mapResult.insert(0x6ffffdf9,"DT_PLTPADSZ"); mapResult.insert(0x6ffffdfa,"DT_MOVEENT"); mapResult.insert(0x6ffffdfb,"DT_MOVESZ"); mapResult.insert(0x6ffffdfc,"DT_FEATURE_1"); mapResult.insert(0x6ffffdfd,"DT_POSFLAG_1"); mapResult.insert(0x6ffffdfe,"DT_SYMINSZ"); mapResult.insert(0x6ffffdff,"DT_SYMINENT"); mapResult.insert(0x6ffffdff,"DT_VALRNGHI"); mapResult.insert(0x6ffffe00,"DT_ADDRRNGLO"); mapResult.insert(0x6ffffef5,"DT_GNU_HASH"); mapResult.insert(0x6ffffefa,"DT_CONFIG"); mapResult.insert(0x6ffffefb,"DT_DEPAUDIT"); mapResult.insert(0x6ffffefc,"DT_AUDIT"); mapResult.insert(0x6ffffefd,"DT_PLTPAD"); mapResult.insert(0x6ffffefe,"DT_MOVETAB"); mapResult.insert(0x6ffffeff,"DT_SYMINFO"); mapResult.insert(0x6ffffeff,"DT_ADDRRNGHI"); mapResult.insert(0x6ffffff0,"DT_VERSYM"); mapResult.insert(0x6ffffff9,"DT_RELACOUNT"); mapResult.insert(0x6ffffffa,"DT_RELCOUNT"); mapResult.insert(0x6ffffffb,"DT_FLAGS_1"); mapResult.insert(0x6ffffffc,"DT_VERDEF"); mapResult.insert(0x6ffffffd,"DT_VERDEFNUM"); mapResult.insert(0x6ffffffe,"DT_VERNEED"); mapResult.insert(0x6fffffff,"DT_VERNEEDNUM"); mapResult.insert(0x70000000,"DT_LOPROC"); mapResult.insert(0x70000001,"DT_SPARC_REGISTER"); mapResult.insert(0x7ffffffd,"DT_AUXILIARY"); mapResult.insert(0x7ffffffe,"DT_USED"); mapResult.insert(0x7fffffff,"DT_HIPROC"); // DT_FILTER return mapResult; } QMap XELF::getDynamicTagsS() { QMap mapResult; mapResult.insert(0,"NULL"); mapResult.insert(1,"NEEDED"); mapResult.insert(2,"PLTRELSZ"); mapResult.insert(3,"PLTGOT"); mapResult.insert(4,"HASH"); mapResult.insert(5,"STRTAB"); mapResult.insert(6,"SYMTAB"); mapResult.insert(7,"RELA"); mapResult.insert(8,"RELASZ"); mapResult.insert(9,"RELAENT"); mapResult.insert(10,"STRSZ"); mapResult.insert(11,"SYMENT"); mapResult.insert(12,"INIT"); mapResult.insert(13,"FINI"); mapResult.insert(14,"SONAME"); mapResult.insert(15,"RPATH"); mapResult.insert(16,"SYMBOLIC"); mapResult.insert(17,"REL"); mapResult.insert(18,"RELSZ"); mapResult.insert(19,"RELENT"); mapResult.insert(20,"PLTREL"); mapResult.insert(21,"DEBUG"); mapResult.insert(22,"TEXTREL"); mapResult.insert(23,"JMPREL"); mapResult.insert(24,"BIND_NOW"); mapResult.insert(25,"INIT_ARRAY"); mapResult.insert(26,"FINI_ARRAY"); mapResult.insert(27,"INIT_ARRAYSZ"); mapResult.insert(28,"FINI_ARRAYSZ"); mapResult.insert(29,"RUNPATH"); mapResult.insert(30,"FLAGS"); mapResult.insert(32,"PREINIT_ARRAY"); // ENCODING mapResult.insert(33,"PREINIT_ARRAYSZ"); mapResult.insert(0x6000000d,"LOOS"); mapResult.insert(0x6000000e,"SUNW_RTLDINF"); mapResult.insert(0x6ffff000,"HIOS"); mapResult.insert(0x6ffffd00,"VALRNGLO"); mapResult.insert(0x6ffffdf8,"CHECKSUM"); mapResult.insert(0x6ffffdf9,"PLTPADSZ"); mapResult.insert(0x6ffffdfa,"MOVEENT"); mapResult.insert(0x6ffffdfb,"MOVESZ"); mapResult.insert(0x6ffffdfc,"FEATURE_1"); mapResult.insert(0x6ffffdfd,"POSFLAG_1"); mapResult.insert(0x6ffffdfe,"SYMINSZ"); mapResult.insert(0x6ffffdff,"SYMINENT"); mapResult.insert(0x6ffffdff,"VALRNGHI"); mapResult.insert(0x6ffffe00,"ADDRRNGLO"); mapResult.insert(0x6ffffef5,"GNU_HASH"); mapResult.insert(0x6ffffefa,"CONFIG"); mapResult.insert(0x6ffffefb,"DEPAUDIT"); mapResult.insert(0x6ffffefc,"AUDIT"); mapResult.insert(0x6ffffefd,"PLTPAD"); mapResult.insert(0x6ffffefe,"MOVETAB"); mapResult.insert(0x6ffffeff,"SYMINFO"); mapResult.insert(0x6ffffeff,"ADDRRNGHI"); mapResult.insert(0x6ffffff0,"VERSYM"); mapResult.insert(0x6ffffff9,"RELACOUNT"); mapResult.insert(0x6ffffffa,"RELCOUNT"); mapResult.insert(0x6ffffffb,"FLAGS_1"); mapResult.insert(0x6ffffffc,"VERDEF"); mapResult.insert(0x6ffffffd,"VERDEFNUM"); mapResult.insert(0x6ffffffe,"VERNEED"); mapResult.insert(0x6fffffff,"VERNEEDNUM"); mapResult.insert(0x70000000,"LOPROC"); mapResult.insert(0x70000001,"SPARC_REGISTER"); mapResult.insert(0x7ffffffd,"AUXILIARY"); mapResult.insert(0x7ffffffe,"USED"); mapResult.insert(0x7fffffff,"HIPROC"); // FILTER return mapResult; } XBinary::_MEMORY_MAP XELF::getMemoryMap() { // TODO Check alignment! XBinary::_MEMORY_MAP result={}; qint32 nIndex=0; result.mode=getMode(); if(result.mode==MODE_64) { result.fileType=FT_ELF64; } else { result.fileType=FT_ELF32; } result.sArch=getArch(); result.bIsBigEndian=isBigEndian(); result.sType=getTypeAsString(); result.nRawSize=getSize(); QList listProgramHeaders=getElf_PhdrList(); QList listSegments=_getPrograms(&listProgramHeaders,XELF_DEF::PT_LOAD); // bool bIs64=is64(); int nNumberOfSegments=listSegments.count(); bool bImageAddressInit=false; qint64 nMaxOffset=0; qint64 nMaxAddress=0; for(int i=0; i(quint64)nVirtualAddress) { XBinary::_MEMORY_RECORD record={}; record.type=MMT_LOADSEGMENT; record.sName=sName; // TODO Section number! record.nAddress=nVirtualAddress; record.nSize=listSegments.at(i).p_vaddr-nVirtualAddress; record.nOffset=-1; record.nIndex=nIndex++; record.bIsVirtual=true; result.listRecords.append(record); } if(nFileSize) { XBinary::_MEMORY_RECORD record={}; record.type=MMT_LOADSEGMENT; record.sName=sName; // TODO Section number! record.nAddress=listSegments.at(i).p_vaddr; record.nSize=nFileSize; record.nOffset=nFileOffset; record.nIndex=nIndex++; result.listRecords.append(record); } if(nVirtualSize>(nFileSize+((qint64)listSegments.at(i).p_vaddr-nVirtualAddress))) { XBinary::_MEMORY_RECORD record={}; record.type=MMT_LOADSEGMENT; record.sName=sName; // TODO Section number! record.nAddress=listSegments.at(i).p_vaddr+nFileSize; record.nSize=nVirtualSize-nFileSize-(listSegments.at(i).p_vaddr-nVirtualAddress); record.nOffset=-1; record.nIndex=nIndex++; record.bIsVirtual=true; result.listRecords.append(record); } if(!bImageAddressInit) { result.nModuleAddress=nVirtualAddress; bImageAddressInit=true; } nMaxOffset=qMax(nMaxOffset,nFileOffset+nFileSize); result.nModuleAddress=qMin(nVirtualAddress,result.nModuleAddress); nMaxAddress=qMax(nVirtualAddress+nVirtualSize,nMaxAddress); } result.nImageSize=nMaxAddress-result.nModuleAddress; qint64 nNoLoadableSize=result.nRawSize-nMaxOffset; if(nNoLoadableSize>0) { XBinary::_MEMORY_RECORD record={}; record.type=MMT_NOLOADABLE; // TODO Section number! // TODO virtual sections! record.nAddress=-1; record.nSize=nNoLoadableSize; record.nOffset=nMaxOffset; record.nIndex=nIndex++; result.listRecords.append(record); } return result; } qint64 XELF::getEntryPointOffset(_MEMORY_MAP *pMemoryMap) { qint64 nAddress=-1; bool bIs64=is64(); if(bIs64) { nAddress=getHdr64_entry(); } else { nAddress=getHdr32_entry(); } return addressToOffset(pMemoryMap,nAddress); } QList XELF::getSectionRecords(QList *pListSectionHeaders, bool bIsImage, QByteArray *pbaSectionTable) { QList listRecords; int nNumberOfSections=pListSectionHeaders->count(); quint32 nSectionTableSize=pbaSectionTable->size(); for(int i=0;iat(i).sh_size; record.nFlags=pListSectionHeaders->at(i).sh_flags; if(bIsImage) { record.nOffset=pListSectionHeaders->at(i).sh_addr; } else { record.nOffset=pListSectionHeaders->at(i).sh_offset; } if(pListSectionHeaders->at(i).sh_namedata()+pListSectionHeaders->at(i).sh_name; } listRecords.append(record); } return listRecords; } bool XELF::isSectionNamePresent(QString sSectionName) { bool bIs64=is64(); quint16 nStringTableSection=getSectionStringTable(bIs64); QByteArray baStringTable=getSection(nStringTableSection); QList listSectionHeaders=getElf_ShdrList(); QList listSectionRecords=getSectionRecords(&listSectionHeaders,bIs64,&baStringTable); return isSectionNamePresent(sSectionName,&listSectionRecords); } bool XELF::isSectionNamePresent(QString sSectionName, QList *pListSectionRecords) { bool bResult=false; int nNumberOfSections=pListSectionRecords->count(); for(int i=0; iat(i).sName==sSectionName) { bResult=true; break; } } return bResult; } qint32 XELF::getSectionNumber(QString sSectionName) { bool bIs64=is64(); quint16 nStringTableSection=getSectionStringTable(bIs64); QByteArray baStringTable=getSection(nStringTableSection); QList listSectionHeaders=getElf_ShdrList(); QList listSectionRecords=getSectionRecords(&listSectionHeaders,bIs64,&baStringTable); return getSectionNumber(sSectionName,&listSectionRecords); } qint32 XELF::getSectionNumber(QString sSectionName, QList *pListSectionRecords) { qint32 nResult=-1; int nNumberOfSections=pListSectionRecords->count(); for(int i=0; iat(i).sName==sSectionName) { nResult=i; break; } } return nResult; } XELF::SECTION_RECORD XELF::getSectionRecord(QString sSectionName, QList *pListSectionRecords) { SECTION_RECORD result={}; int nNumberOfSections=pListSectionRecords->count(); for(int i=0; iat(i).sName==sSectionName) { result=pListSectionRecords->at(i); break; } } return result; } XBinary::MODE XELF::getMode() { MODE result=MODE_32; quint8 ident=getIdent_class(); if(ident== XELF_DEF::ELFCLASS32) { result=MODE_32; } else if(ident== XELF_DEF::ELFCLASS64) { result=MODE_64; } return result; } QString XELF::getArch() { return getMachinesS().value(getHdr32_machine(),QString("UNKNOWN")); } int XELF::getType() { int nResult=TYPE_UNKNOWN; quint16 nType=0; if(is64()) { nType=getHdr64_type(); } else { nType=getHdr32_type(); } if(nType==XELF_DEF::ET_REL) { nResult=TYPE_REL; } else if(nType==XELF_DEF::ET_EXEC) { nResult=TYPE_EXEC; } else if(nType==XELF_DEF::ET_DYN) { nResult=TYPE_DYN; } else if(nType==XELF_DEF::ET_CORE) { nResult=TYPE_CORE; } else if(nType==XELF_DEF::ET_NUM) { nResult=TYPE_NUM; } return nResult; } XBinary::FT XELF::getFileType() { FT result=FT_ELF32; MODE mode=getMode(); if(mode==MODE_32) { result=FT_ELF32; } else if(mode==MODE_64) { result=FT_ELF64; } return result; } QString XELF::typeIdToString(int nType) { QString sResult="Unknown"; // mb TODO translate switch(nType) { case TYPE_UNKNOWN: sResult=QString("Unknown"); break; // mb TODO translate case TYPE_REL: sResult=QString("REL"); break; case TYPE_EXEC: sResult=QString("EXEC"); break; case TYPE_DYN: sResult=QString("DYN"); break; case TYPE_CORE: sResult=QString("CORE"); break; case TYPE_NUM: sResult=QString("NUM"); break; } return sResult; } qint64 XELF::getBaseAddress() { return getMemoryMap().nModuleAddress; // TODO Check !!! } QList XELF::_getPrograms(QList *pListProgramHeaders, quint32 nType) { QList listResult; int nNumberOfPrograms=pListProgramHeaders->count(); for(int i=0;iat(i).p_type==nType) { listResult.append(pListProgramHeaders->at(i)); } } return listResult; } QList XELF::getDatasetsFromSections(QList *pListSectionHeaders) { QList listResult; quint32 nMainStringSection=getSectionStringTable(); XBinary::OFFSETSIZE osStringTable=getSectionOffsetSize(nMainStringSection); int nNumberOfSections=pListSectionHeaders->count(); for(int i=0;iat(i).sh_name); if((pListSectionHeaders->at(i).sh_type==1)&&(sSectionName==".interp")) // Interpreter TODO const { DATASET dataset={}; dataset.nAddress=pListSectionHeaders->at(i).sh_addr; dataset.nOffset=pListSectionHeaders->at(i).sh_offset; dataset.nSize=pListSectionHeaders->at(i).sh_size; dataset.nType=DS_INTERPRETER; dataset.sName=QString("%1[%2]").arg("Interpreter",sSectionName); // TODO mb translate listResult.append(dataset); } else if(pListSectionHeaders->at(i).sh_type==2) // Symbol table TODO const { DATASET dataset={}; dataset.nAddress=pListSectionHeaders->at(i).sh_addr; dataset.nOffset=pListSectionHeaders->at(i).sh_offset; dataset.nSize=pListSectionHeaders->at(i).sh_size; dataset.nType=DS_SYMBOLTABLE; dataset.sName=QString("%1[%2]").arg("Symbol table",sSectionName); // TODO mb translate int nSectionIndex=getSectionIndexByName(".strtab"); if(nSectionIndex!=-1) { XBinary::OFFSETSIZE osStringTable=getSectionOffsetSize(nSectionIndex); dataset.nStringTableOffset=osStringTable.nOffset; dataset.nStringTableSize=osStringTable.nSize; } listResult.append(dataset); } else if(pListSectionHeaders->at(i).sh_type==0xb) // Symbol table dynamic TODO const { DATASET dataset={}; dataset.nAddress=pListSectionHeaders->at(i).sh_addr; dataset.nOffset=pListSectionHeaders->at(i).sh_offset; dataset.nSize=pListSectionHeaders->at(i).sh_size; dataset.nType=DS_SYMBOLTABLE; dataset.sName=QString("%1[%2]").arg("Symbol table",sSectionName); // TODO mb translate int nSectionIndex=getSectionIndexByName(".dynstr"); if(nSectionIndex!=-1) { XBinary::OFFSETSIZE osStringTable=getSectionOffsetSize(nSectionIndex); dataset.nStringTableOffset=osStringTable.nOffset; dataset.nStringTableSize=osStringTable.nSize; } listResult.append(dataset); } else if(pListSectionHeaders->at(i).sh_type==3) // String table TODO const { DATASET dataset={}; dataset.nAddress=pListSectionHeaders->at(i).sh_addr; dataset.nOffset=pListSectionHeaders->at(i).sh_offset; dataset.nSize=pListSectionHeaders->at(i).sh_size; dataset.nType=DS_STRINGTABLE; dataset.sName=QString("%1[%2]").arg("String table",sSectionName); // TODO mb translate listResult.append(dataset); } else if(pListSectionHeaders->at(i).sh_type==4) // RELA TODO const { DATASET dataset={}; dataset.nAddress=pListSectionHeaders->at(i).sh_addr; dataset.nOffset=pListSectionHeaders->at(i).sh_offset; dataset.nSize=pListSectionHeaders->at(i).sh_size; dataset.nType=DS_RELA; dataset.sName=QString("%1[%2]").arg("RELA",sSectionName); // TODO mb translate listResult.append(dataset); } else if(pListSectionHeaders->at(i).sh_type==6) // Dynamic TODO const { DATASET dataset={}; dataset.nAddress=pListSectionHeaders->at(i).sh_addr; dataset.nOffset=pListSectionHeaders->at(i).sh_offset; dataset.nSize=pListSectionHeaders->at(i).sh_size; dataset.nType=DS_DYNAMICTAGS; dataset.sName=QString("%1[%2]").arg("Dynamic tags",sSectionName); // TODO mb translate listResult.append(dataset); } else if(pListSectionHeaders->at(i).sh_type==7) // Notes TODO const { DATASET dataset={}; dataset.nAddress=pListSectionHeaders->at(i).sh_addr; dataset.nOffset=pListSectionHeaders->at(i).sh_offset; dataset.nSize=pListSectionHeaders->at(i).sh_size; dataset.nType=DS_NOTES; dataset.sName=QString("%1[%2]").arg("Notes",sSectionName); // TODO mb translate listResult.append(dataset); } else if(pListSectionHeaders->at(i).sh_type==9) // REL TODO const { DATASET dataset={}; dataset.nAddress=pListSectionHeaders->at(i).sh_addr; dataset.nOffset=pListSectionHeaders->at(i).sh_offset; dataset.nSize=pListSectionHeaders->at(i).sh_size; dataset.nType=DS_REL; dataset.sName=QString("%1[%2]").arg("REL",sSectionName); // TODO mb translate listResult.append(dataset); } } return listResult; } QList XELF::getDatasetsFromPrograms(QList *pListProgramHeaders) { QList listResult; int nNumberOfPrograms=pListProgramHeaders->count(); for(int i=0;iat(i).p_type==3)) // Interpreter TODO const { DATASET dataset={}; dataset.nAddress=pListProgramHeaders->at(i).p_vaddr; dataset.nOffset=pListProgramHeaders->at(i).p_offset; dataset.nSize=pListProgramHeaders->at(i).p_filesz; dataset.nType=DS_INTERPRETER; dataset.sName=QString("%1").arg("Interpreter"); // TODO mb translate listResult.append(dataset); } else if((pListProgramHeaders->at(i).p_type==4)) // Notes TODO const { DATASET dataset={}; dataset.nAddress=pListProgramHeaders->at(i).p_vaddr; dataset.nOffset=pListProgramHeaders->at(i).p_offset; dataset.nSize=pListProgramHeaders->at(i).p_filesz; dataset.nType=DS_NOTES; dataset.sName=QString("%1").arg("Notes"); // TODO mb translate listResult.append(dataset); } else if((pListProgramHeaders->at(i).p_type==2)) // Tags TODO const { DATASET dataset={}; dataset.nAddress=pListProgramHeaders->at(i).p_vaddr; dataset.nOffset=pListProgramHeaders->at(i).p_offset; dataset.nSize=pListProgramHeaders->at(i).p_filesz; dataset.nType=DS_DYNAMICTAGS; dataset.sName=QString("%1").arg("Dynamic tags"); // TODO mb translate listResult.append(dataset); } } return listResult; } QList XELF::getDatasetsFromTagStructs(XBinary::_MEMORY_MAP *pMemoryMap, QList *pListTagStructs) { QList listResult; QList listStrTab=_getTagStructs(pListTagStructs,XELF_DEF::DT_STRTAB); QList listStrSize=_getTagStructs(pListTagStructs,XELF_DEF::DT_STRSZ); QList listStrNeeded=_getTagStructs(pListTagStructs,XELF_DEF::DT_NEEDED); QList listRunPath=_getTagStructs(pListTagStructs,0x1d); // TODO const QList listSymbols=_getTagStructs(pListTagStructs,XELF_DEF::DT_SYMTAB); QList listRelaTab=_getTagStructs(pListTagStructs,XELF_DEF::DT_RELA); QList listRelaSize=_getTagStructs(pListTagStructs,XELF_DEF::DT_RELASZ); QList listRelTab=_getTagStructs(pListTagStructs,17); // TODO const QList listRelSize=_getTagStructs(pListTagStructs,18); // TODO const qint64 nStringTableOffset=0; qint64 nStringTableSize=0; if(listStrTab.count()&&listStrSize.count()) { DATASET dataset={}; dataset.nAddress=listStrTab.at(0).nValue; dataset.nOffset=addressToOffset(pMemoryMap,dataset.nAddress); dataset.nSize=listStrSize.at(0).nValue; dataset.nType=DS_STRINGTABLE; dataset.sName="String table"; // TODO mb translate if(isOffsetAndSizeValid(pMemoryMap,dataset.nOffset,dataset.nSize)) { listResult.append(dataset); } nStringTableOffset=dataset.nOffset; nStringTableSize=dataset.nSize; } if(listRelaTab.count()&&listRelaSize.count()) { DATASET dataset={}; dataset.nAddress=listRelaTab.at(0).nValue; dataset.nOffset=addressToOffset(pMemoryMap,dataset.nAddress); dataset.nSize=listRelaSize.at(0).nValue; dataset.nType=DS_RELA; dataset.sName="RELA"; // TODO mb translate dataset.nStringTableOffset=nStringTableOffset; dataset.nStringTableSize=nStringTableSize; listResult.append(dataset); } if(listRelTab.count()&&listRelSize.count()) { DATASET dataset={}; dataset.nAddress=listRelTab.at(0).nValue; dataset.nOffset=addressToOffset(pMemoryMap,dataset.nAddress); dataset.nSize=listRelSize.at(0).nValue; dataset.nType=DS_REL; dataset.sName="REL"; // TODO mb translate dataset.nStringTableOffset=nStringTableOffset; dataset.nStringTableSize=nStringTableSize; listResult.append(dataset); } if(listStrNeeded.count()) { DATASET dataset={}; dataset.nAddress=0; dataset.nOffset=0; dataset.nSize=0; dataset.nType=DS_LIBRARIES; dataset.sName="Libraries"; // TODO mb translate dataset.nStringTableOffset=nStringTableOffset; dataset.nStringTableSize=nStringTableSize; listResult.append(dataset); } if(listRunPath.count()) { qint64 nAddress=listStrTab.at(0).nValue; qint64 nOffset=addressToOffset(pMemoryMap,nAddress); qint64 nRunPath=listRunPath.at(0).nValue; qint64 nSize=listStrSize.at(0).nValue; if(nRunPath XELF::getElf32_SymList(qint64 nOffset, qint64 nSize) { QList listResult; bool bIsBigEndian=isBigEndian(); while(nSize>0) { XELF_DEF::Elf32_Sym record=_readElf32_Sym(nOffset,bIsBigEndian); listResult.append(record); nOffset+=sizeof(XELF_DEF::Elf32_Sym); nSize-=sizeof(XELF_DEF::Elf32_Sym); } return listResult; } QList XELF::getElf64_SymList(qint64 nOffset, qint64 nSize) { QList listResult; bool bIsBigEndian=isBigEndian(); while(nSize>0) { XELF_DEF::Elf64_Sym record=_readElf64_Sym(nOffset,bIsBigEndian); listResult.append(record); nOffset+=sizeof(XELF_DEF::Elf64_Sym); nSize-=sizeof(XELF_DEF::Elf64_Sym); } return listResult; } XELF_DEF::Elf32_Sym XELF::_readElf32_Sym(qint64 nOffset, bool bIsBigEndian) { XELF_DEF::Elf32_Sym result={}; result.st_name=read_uint32(nOffset+offsetof(XELF_DEF::Elf32_Sym,st_name),bIsBigEndian); result.st_value=read_uint32(nOffset+offsetof(XELF_DEF::Elf32_Sym,st_value),bIsBigEndian); result.st_size=read_uint32(nOffset+offsetof(XELF_DEF::Elf32_Sym,st_size),bIsBigEndian); result.st_info=read_uint8(nOffset+offsetof(XELF_DEF::Elf32_Sym,st_info)); result.st_other=read_uint8(nOffset+offsetof(XELF_DEF::Elf32_Sym,st_other)); result.st_shndx=read_uint16(nOffset+offsetof(XELF_DEF::Elf32_Sym,st_shndx),bIsBigEndian); return result; } XELF_DEF::Elf64_Sym XELF::_readElf64_Sym(qint64 nOffset, bool bIsBigEndian) { XELF_DEF::Elf64_Sym result={}; result.st_name=read_uint32(nOffset+offsetof(XELF_DEF::Elf64_Sym,st_name),bIsBigEndian); result.st_info=read_uint8(nOffset+offsetof(XELF_DEF::Elf64_Sym,st_info)); result.st_other=read_uint8(nOffset+offsetof(XELF_DEF::Elf64_Sym,st_other)); result.st_shndx=read_uint16(nOffset+offsetof(XELF_DEF::Elf64_Sym,st_shndx),bIsBigEndian); result.st_value=read_uint64(nOffset+offsetof(XELF_DEF::Elf64_Sym,st_value),bIsBigEndian); result.st_size=read_uint64(nOffset+offsetof(XELF_DEF::Elf64_Sym,st_size),bIsBigEndian); return result; } void XELF::setElf32_Sym_st_name(qint64 nOffset, quint32 nValue, bool bIsBigEndian) { write_uint32(nOffset+offsetof(XELF_DEF::Elf32_Sym,st_name),nValue,bIsBigEndian); } void XELF::setElf32_Sym_st_value(qint64 nOffset, quint32 nValue, bool bIsBigEndian) { write_uint32(nOffset+offsetof(XELF_DEF::Elf32_Sym,st_value),nValue,bIsBigEndian); } void XELF::setElf32_Sym_st_size(qint64 nOffset, quint32 nValue, bool bIsBigEndian) { write_uint32(nOffset+offsetof(XELF_DEF::Elf32_Sym,st_size),nValue,bIsBigEndian); } void XELF::setElf32_Sym_st_info(qint64 nOffset, quint8 nValue) { write_uint8(nOffset+offsetof(XELF_DEF::Elf32_Sym,st_info),nValue); } void XELF::setElf32_Sym_st_other(qint64 nOffset, quint8 nValue) { write_uint8(nOffset+offsetof(XELF_DEF::Elf32_Sym,st_other),nValue); } void XELF::setElf32_Sym_st_shndx(qint64 nOffset, quint16 nValue, bool bIsBigEndian) { write_uint16(nOffset+offsetof(XELF_DEF::Elf32_Sym,st_shndx),nValue,bIsBigEndian); } void XELF::setElf64_Sym_st_name(qint64 nOffset, quint32 nValue, bool bIsBigEndian) { write_uint32(nOffset+offsetof(XELF_DEF::Elf64_Sym,st_name),nValue,bIsBigEndian); } void XELF::setElf64_Sym_st_info(qint64 nOffset, quint8 nValue) { write_uint8(nOffset+offsetof(XELF_DEF::Elf64_Sym,st_info),nValue); } void XELF::setElf64_Sym_st_other(qint64 nOffset, quint8 nValue) { write_uint8(nOffset+offsetof(XELF_DEF::Elf64_Sym,st_other),nValue); } void XELF::setElf64_Sym_st_shndx(qint64 nOffset, quint16 nValue, bool bIsBigEndian) { write_uint16(nOffset+offsetof(XELF_DEF::Elf64_Sym,st_shndx),nValue,bIsBigEndian); } void XELF::setElf64_Sym_st_value(qint64 nOffset, quint64 nValue, bool bIsBigEndian) { write_uint64(nOffset+offsetof(XELF_DEF::Elf64_Sym,st_value),nValue,bIsBigEndian); } void XELF::setElf64_Sym_st_size(qint64 nOffset, quint64 nValue, bool bIsBigEndian) { write_uint64(nOffset+offsetof(XELF_DEF::Elf64_Sym,st_size),nValue,bIsBigEndian); } qint64 XELF::getSymSize() { quint64 nResult=0; bool bIs64=is64(); if(bIs64) { nResult=sizeof(XELF_DEF::Elf64_Sym); } else { nResult=sizeof(XELF_DEF::Elf32_Sym); } return nResult; } qint64 XELF::getSymTableSize(qint64 nOffset) { qint64 nResult=0; bool bIsBigEndian=isBigEndian(); bool bIs64=is64(); if(bIs64) { nResult+=sizeof(XELF_DEF::Elf64_Sym); nOffset+=sizeof(XELF_DEF::Elf64_Sym); while(true) { XELF_DEF::Elf64_Sym record=_readElf64_Sym(nOffset,bIsBigEndian); if((!record.st_info)||(record.st_other)) { break; } nResult+=sizeof(XELF_DEF::Elf64_Sym); nOffset+=sizeof(XELF_DEF::Elf64_Sym); } } else { nResult+=sizeof(XELF_DEF::Elf32_Sym); nOffset+=sizeof(XELF_DEF::Elf32_Sym); while(true) { XELF_DEF::Elf32_Sym record=_readElf32_Sym(nOffset,bIsBigEndian); if((!record.st_info)||(record.st_other)) { break; } nResult+=sizeof(XELF_DEF::Elf32_Sym); nOffset+=sizeof(XELF_DEF::Elf32_Sym); } } return nResult; } XELF_DEF::Elf32_Rel XELF::_readElf32_Rel(qint64 nOffset, bool bIsBigEndian) { XELF_DEF::Elf32_Rel result={}; result.r_offset=read_uint32(nOffset+offsetof(XELF_DEF::Elf32_Rel,r_offset),bIsBigEndian); result.r_info=read_uint32(nOffset+offsetof(XELF_DEF::Elf32_Rel,r_info),bIsBigEndian); return result; } XELF_DEF::Elf64_Rel XELF::_readElf64_Rel(qint64 nOffset, bool bIsBigEndian) { XELF_DEF::Elf64_Rel result={}; result.r_offset=read_uint64(nOffset+offsetof(XELF_DEF::Elf64_Rel,r_offset),bIsBigEndian); result.r_info=read_uint64(nOffset+offsetof(XELF_DEF::Elf64_Rel,r_info),bIsBigEndian); return result; } XELF_DEF::Elf32_Rela XELF::_readElf32_Rela(qint64 nOffset, bool bIsBigEndian) { XELF_DEF::Elf32_Rela result={}; result.r_offset=read_uint32(nOffset+offsetof(XELF_DEF::Elf32_Rela,r_offset),bIsBigEndian); result.r_info=read_uint32(nOffset+offsetof(XELF_DEF::Elf32_Rela,r_info),bIsBigEndian); result.r_addend=read_int32(nOffset+offsetof(XELF_DEF::Elf32_Rela,r_addend),bIsBigEndian); return result; } XELF_DEF::Elf64_Rela XELF::_readElf64_Rela(qint64 nOffset, bool bIsBigEndian) { XELF_DEF::Elf64_Rela result={}; result.r_offset=read_uint64(nOffset+offsetof(XELF_DEF::Elf64_Rela,r_offset),bIsBigEndian); result.r_info=read_uint64(nOffset+offsetof(XELF_DEF::Elf64_Rela,r_info),bIsBigEndian); result.r_addend=read_int64(nOffset+offsetof(XELF_DEF::Elf64_Rela,r_addend),bIsBigEndian); return result; } QList XELF::getElf32_RelList(qint64 nOffset, qint64 nSize) { QList listResult; bool bIsBigEndian=isBigEndian(); while(nSize>0) { XELF_DEF::Elf32_Rel record=_readElf32_Rel(nOffset,bIsBigEndian); listResult.append(record); nOffset+=sizeof(XELF_DEF::Elf32_Rel); nSize-=sizeof(XELF_DEF::Elf32_Rel); } return listResult; } QList XELF::getElf64_RelList(qint64 nOffset, qint64 nSize) { QList listResult; bool bIsBigEndian=isBigEndian(); while(nSize>0) { XELF_DEF::Elf64_Rel record=_readElf64_Rel(nOffset,bIsBigEndian); listResult.append(record); nOffset+=sizeof(XELF_DEF::Elf64_Rel); nSize-=sizeof(XELF_DEF::Elf64_Rel); } return listResult; } QList XELF::getElf32_RelaList(qint64 nOffset, qint64 nSize) { QList listResult; bool bIsBigEndian=isBigEndian(); while(nSize>0) { XELF_DEF::Elf32_Rela record=_readElf32_Rela(nOffset,bIsBigEndian); listResult.append(record); nOffset+=sizeof(XELF_DEF::Elf32_Rela); nSize-=sizeof(XELF_DEF::Elf32_Rela); } return listResult; } QList XELF::getElf64_RelaList(qint64 nOffset, qint64 nSize) { QList listResult; bool bIsBigEndian=isBigEndian(); while(nSize>0) { XELF_DEF::Elf64_Rela record=_readElf64_Rela(nOffset,bIsBigEndian); listResult.append(record); nOffset+=sizeof(XELF_DEF::Elf64_Rela); nSize-=sizeof(XELF_DEF::Elf64_Rela); } return listResult; } void XELF::setElf32_Rel_r_offset(qint64 nOffset, quint32 nValue, bool bIsBigEndian) { write_uint32(nOffset+offsetof(XELF_DEF::Elf32_Rel,r_offset),nValue,bIsBigEndian); } void XELF::setElf32_Rel_r_info(qint64 nOffset, quint32 nValue, bool bIsBigEndian) { write_uint32(nOffset+offsetof(XELF_DEF::Elf32_Rel,r_info),nValue,bIsBigEndian); } void XELF::setElf64_Rel_r_offset(qint64 nOffset, quint64 nValue, bool bIsBigEndian) { write_uint64(nOffset+offsetof(XELF_DEF::Elf64_Rel,r_offset),nValue,bIsBigEndian); } void XELF::setElf64_Rel_r_info(qint64 nOffset, quint64 nValue, bool bIsBigEndian) { write_uint64(nOffset+offsetof(XELF_DEF::Elf64_Rel,r_info),nValue,bIsBigEndian); } void XELF::setElf32_Rela_r_offset(qint64 nOffset, quint32 nValue, bool bIsBigEndian) { write_uint32(nOffset+offsetof(XELF_DEF::Elf32_Rela,r_offset),nValue,bIsBigEndian); } void XELF::setElf32_Rela_r_info(qint64 nOffset, quint32 nValue, bool bIsBigEndian) { write_uint32(nOffset+offsetof(XELF_DEF::Elf32_Rela,r_info),nValue,bIsBigEndian); } void XELF::setElf32_Rela_r_addend(qint64 nOffset, quint32 nValue, bool bIsBigEndian) { write_uint32(nOffset+offsetof(XELF_DEF::Elf32_Rela,r_addend),nValue,bIsBigEndian); } void XELF::setElf64_Rela_r_offset(qint64 nOffset, quint64 nValue, bool bIsBigEndian) { write_uint64(nOffset+offsetof(XELF_DEF::Elf64_Rela,r_offset),nValue,bIsBigEndian); } void XELF::setElf64_Rela_r_info(qint64 nOffset, quint64 nValue, bool bIsBigEndian) { write_uint64(nOffset+offsetof(XELF_DEF::Elf64_Rela,r_info),nValue,bIsBigEndian); } void XELF::setElf64_Rela_r_addend(qint64 nOffset, quint64 nValue, bool bIsBigEndian) { write_uint64(nOffset+offsetof(XELF_DEF::Elf64_Rela,r_addend),nValue,bIsBigEndian); } quint16 XELF::getNumberOfSections() { quint16 nResult=0; if(is64()) { nResult=getHdr64_shnum(); } else { nResult=getHdr32_shnum(); } return nResult; } quint16 XELF::getNumberOfPrograms() { quint16 nResult=0; if(is64()) { nResult=getHdr64_phnum(); } else { nResult=getHdr32_phnum(); } return nResult; } bool XELF::isSectionsTablePresent() { return (bool)getNumberOfSections(); } bool XELF::isProgramsTablePresent() { return (bool)getNumberOfPrograms(); } QMap XELF::getRelTypes_x86() { QMap mapResult; mapResult.insert(0,"R_386_NONE"); mapResult.insert(1,"R_386_32"); mapResult.insert(2,"R_386_PC32"); mapResult.insert(3,"R_386_GOT32"); mapResult.insert(4,"R_386_PLT32"); mapResult.insert(5,"R_386_COPY"); mapResult.insert(6,"R_386_GLOB_DAT"); mapResult.insert(7,"R_386_JMP_SLOT"); mapResult.insert(8,"R_386_RELATIVE"); mapResult.insert(9,"R_386_GOTOFF"); mapResult.insert(10,"R_386_GOTPC"); mapResult.insert(11,"R_386_32PLT"); mapResult.insert(20,"R_386_16"); mapResult.insert(21,"R_386_PC16"); mapResult.insert(22,"R_386_8"); mapResult.insert(23,"R_386_PC8"); mapResult.insert(38,"R_386_SIZE32"); return mapResult; } QMap XELF::getRelTypesS_x86() { QMap mapResult; mapResult.insert(0,"386_NONE"); mapResult.insert(1,"386_32"); mapResult.insert(2,"386_PC32"); mapResult.insert(3,"386_GOT32"); mapResult.insert(4,"386_PLT32"); mapResult.insert(5,"386_COPY"); mapResult.insert(6,"386_GLOB_DAT"); mapResult.insert(7,"386_JMP_SLOT"); mapResult.insert(8,"386_RELATIVE"); mapResult.insert(9,"386_GOTOFF"); mapResult.insert(10,"386_GOTPC"); mapResult.insert(11,"386_32PLT"); mapResult.insert(20,"386_16"); mapResult.insert(21,"386_PC16"); mapResult.insert(22,"386_8"); mapResult.insert(23,"386_PC8"); mapResult.insert(38,"386_SIZE32"); return mapResult; } QMap XELF::getRelTypes_x64() { QMap mapResult; mapResult.insert(0,"R_X86_64_NONE"); mapResult.insert(1,"R_X86_64_32"); mapResult.insert(2,"R_386_PC32"); mapResult.insert(3,"R_386_GOT32"); mapResult.insert(4,"R_X86_64_PLT32"); mapResult.insert(5,"R_X86_64_COPY"); mapResult.insert(6,"R_X86_64_GLOB_DAT"); mapResult.insert(7,"R_X86_64_JMP_SLOT"); mapResult.insert(8,"R_X86_64_RELATIVE"); mapResult.insert(9,"R_X86_64_GOTPCREL"); mapResult.insert(10,"R_X86_64_32"); mapResult.insert(11,"R_X86_64_32S"); mapResult.insert(12,"R_X86_64_16"); mapResult.insert(13,"R_X86_64_PC16"); mapResult.insert(14,"R_X86_64_8"); mapResult.insert(15,"R_X86_64_PC8"); mapResult.insert(24,"R_X86_64_PC64"); return mapResult; } QMap XELF::getRelTypesS_x64() { QMap mapResult; mapResult.insert(0,"X86_64_NONE"); mapResult.insert(1,"X86_64_32"); mapResult.insert(2,"386_PC32"); mapResult.insert(3,"386_GOT32"); mapResult.insert(4,"X86_64_PLT32"); mapResult.insert(5,"X86_64_COPY"); mapResult.insert(6,"X86_64_GLOB_DAT"); mapResult.insert(7,"X86_64_JMP_SLOT"); mapResult.insert(8,"X86_64_RELATIVE"); mapResult.insert(9,"X86_64_GOTPCREL"); mapResult.insert(10,"X86_64_32"); mapResult.insert(11,"X86_64_32S"); mapResult.insert(12,"X86_64_16"); mapResult.insert(13,"X86_64_PC16"); mapResult.insert(14,"X86_64_8"); mapResult.insert(15,"X86_64_PC8"); mapResult.insert(24,"X86_64_PC64"); return mapResult; } QMap XELF::getRelTypes_SPARC() { QMap mapResult; mapResult.insert(0,"R_SPARC_NONE"); mapResult.insert(1,"R_SPARC_8"); mapResult.insert(2,"R_SPARC_16"); mapResult.insert(3,"R_SPARC_32"); mapResult.insert(4,"R_SPARC_DISP8"); mapResult.insert(5,"R_SPARC_DISP16"); mapResult.insert(6,"R_SPARC_DISP32"); mapResult.insert(7,"R_SPARC_WDISP30"); mapResult.insert(8,"R_SPARC_WDISP22"); mapResult.insert(9,"R_SPARC_HI22"); mapResult.insert(10,"R_SPARC_22"); mapResult.insert(11,"R_SPARC_13"); mapResult.insert(12,"R_SPARC_LO10"); mapResult.insert(13,"R_SPARC_GOT10"); mapResult.insert(14,"R_SPARC_GOT13"); mapResult.insert(15,"R_SPARC_GOT22"); mapResult.insert(16,"R_SPARC_PC10"); mapResult.insert(17,"R_SPARC_PC22"); mapResult.insert(18,"R_SPARC_WPLT30"); mapResult.insert(19,"R_SPARC_COPY"); mapResult.insert(20,"R_SPARC_GLOB_DAT"); mapResult.insert(21,"R_SPARC_JMP_SLOT"); mapResult.insert(22,"R_SPARC_RELATIVE"); mapResult.insert(23,"R_SPARC_UA32"); mapResult.insert(24,"R_SPARC_PLT32"); mapResult.insert(25,"R_SPARC_HIPLT22"); mapResult.insert(26,"R_SPARC_LOPLT10"); mapResult.insert(27,"R_SPARC_PCPLT32"); mapResult.insert(28,"R_SPARC_PCPLT22"); mapResult.insert(29,"R_SPARC_PCPLT10"); mapResult.insert(30,"R_SPARC_10"); mapResult.insert(31,"R_SPARC_11"); mapResult.insert(32,"R_SPARC_64"); mapResult.insert(33,"R_SPARC_OLO10"); mapResult.insert(34,"R_SPARC_HH22"); mapResult.insert(35,"R_SPARC_HM10"); mapResult.insert(36,"R_SPARC_LM22"); mapResult.insert(37,"R_SPARC_PC_HH22"); mapResult.insert(38,"R_SPARC_PC_HM10"); mapResult.insert(39,"R_SPARC_PC_LM22"); mapResult.insert(40,"R_SPARC_WDISP16"); mapResult.insert(41,"R_SPARC_WDISP19"); mapResult.insert(43,"R_SPARC_7"); mapResult.insert(44,"R_SPARC_5"); mapResult.insert(45,"R_SPARC_6"); mapResult.insert(46,"R_SPARC_DISP64"); mapResult.insert(47,"R_SPARC_PLT64"); mapResult.insert(48,"R_SPARC_HIX22"); mapResult.insert(49,"R_SPARC_LOX10"); mapResult.insert(50,"R_SPARC_H44"); mapResult.insert(51,"R_SPARC_M44"); mapResult.insert(52,"R_SPARC_L44"); mapResult.insert(53,"R_SPARC_REGISTER"); mapResult.insert(54,"R_SPARC_UA64"); mapResult.insert(55,"R_SPARC_UA16"); mapResult.insert(80,"R_SPARC_GOTDATA_HIX22"); mapResult.insert(81,"R_SPARC_GOTDATA_LOX10"); mapResult.insert(82,"R_SPARC_GOTDATA_OP_HIX22"); mapResult.insert(83,"R_SPARC_GOTDATA_OP_LOX10"); mapResult.insert(84,"R_SPARC_GOTDATA_OP"); mapResult.insert(85,"R_SPARC_SIZE32"); // mb TODO https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/6n33n7fct/index.html mapResult.insert(87,"R_SPARC_SIZE64"); return mapResult; } QMap XELF::getRelTypesS_SPARC() { QMap mapResult; mapResult.insert(0,"SPARC_NONE"); mapResult.insert(1,"SPARC_8"); mapResult.insert(2,"SPARC_16"); mapResult.insert(3,"SPARC_32"); mapResult.insert(4,"SPARC_DISP8"); mapResult.insert(5,"SPARC_DISP16"); mapResult.insert(6,"SPARC_DISP32"); mapResult.insert(7,"SPARC_WDISP30"); mapResult.insert(8,"SPARC_WDISP22"); mapResult.insert(9,"SPARC_HI22"); mapResult.insert(10,"SPARC_22"); mapResult.insert(11,"SPARC_13"); mapResult.insert(12,"SPARC_LO10"); mapResult.insert(13,"SPARC_GOT10"); mapResult.insert(14,"SPARC_GOT13"); mapResult.insert(15,"SPARC_GOT22"); mapResult.insert(16,"SPARC_PC10"); mapResult.insert(17,"SPARC_PC22"); mapResult.insert(18,"SPARC_WPLT30"); mapResult.insert(19,"SPARC_COPY"); mapResult.insert(20,"SPARC_GLOB_DAT"); mapResult.insert(21,"SPARC_JMP_SLOT"); mapResult.insert(22,"SPARC_RELATIVE"); mapResult.insert(23,"SPARC_UA32"); mapResult.insert(24,"SPARC_PLT32"); mapResult.insert(25,"SPARC_HIPLT22"); mapResult.insert(26,"SPARC_LOPLT10"); mapResult.insert(27,"SPARC_PCPLT32"); mapResult.insert(28,"SPARC_PCPLT22"); mapResult.insert(29,"SPARC_PCPLT10"); mapResult.insert(30,"SPARC_10"); mapResult.insert(31,"SPARC_11"); mapResult.insert(32,"SPARC_64"); mapResult.insert(33,"SPARC_OLO10"); mapResult.insert(34,"SPARC_HH22"); mapResult.insert(35,"SPARC_HM10"); mapResult.insert(36,"SPARC_LM22"); mapResult.insert(37,"SPARC_PC_HH22"); mapResult.insert(38,"SPARC_PC_HM10"); mapResult.insert(39,"SPARC_PC_LM22"); mapResult.insert(40,"SPARC_WDISP16"); mapResult.insert(41,"SPARC_WDISP19"); mapResult.insert(43,"SPARC_7"); mapResult.insert(44,"SPARC_5"); mapResult.insert(45,"SPARC_6"); mapResult.insert(46,"SPARC_DISP64"); mapResult.insert(47,"SPARC_PLT64"); mapResult.insert(48,"SPARC_HIX22"); mapResult.insert(49,"SPARC_LOX10"); mapResult.insert(50,"SPARC_H44"); mapResult.insert(51,"SPARC_M44"); mapResult.insert(52,"SPARC_L44"); mapResult.insert(53,"SPARC_REGISTER"); mapResult.insert(54,"SPARC_UA64"); mapResult.insert(55,"SPARC_UA16"); mapResult.insert(80,"SPARC_GOTDATA_HIX22"); mapResult.insert(81,"SPARC_GOTDATA_LOX10"); mapResult.insert(82,"SPARC_GOTDATA_OP_HIX22"); mapResult.insert(83,"SPARC_GOTDATA_OP_LOX10"); mapResult.insert(84,"SPARC_GOTDATA_OP"); mapResult.insert(85,"SPARC_SIZE32"); // mb TODO https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/6n33n7fct/index.html mapResult.insert(87,"SPARC_SIZE64"); return mapResult; } QMap XELF::getStBinds() { QMap mapResult; mapResult.insert(0,"STB_LOCAL"); mapResult.insert(1,"STB_GLOBAL"); mapResult.insert(2,"STB_WEAK"); mapResult.insert(10,"STB_LOOS"); mapResult.insert(12,"STB_HIOS"); mapResult.insert(13,"STB_LOPROC"); mapResult.insert(15,"STB_HIPROC"); return mapResult; } QMap XELF::getStBindsS() { QMap mapResult; mapResult.insert(0,"LOCAL"); mapResult.insert(1,"GLOBAL"); mapResult.insert(2,"WEAK"); mapResult.insert(10,"LOOS"); mapResult.insert(12,"HIOS"); mapResult.insert(13,"LOPROC"); mapResult.insert(15,"HIPROC"); return mapResult; } QMap XELF::getStTypes() { QMap mapResult; mapResult.insert(0,"STT_NOTYPE"); mapResult.insert(1,"STT_OBJECT"); mapResult.insert(2,"STT_FUNC"); mapResult.insert(3,"STT_SECTION"); mapResult.insert(4,"STT_FILE"); mapResult.insert(5,"STT_COMMON"); mapResult.insert(10,"STT_LOOS"); mapResult.insert(12,"STT_HIOS"); mapResult.insert(13,"STT_LOPROC"); // STT_SPARC_REGISTER mapResult.insert(15,"STT_HIPROC"); return mapResult; } QMap XELF::getStTypesS() { QMap mapResult; mapResult.insert(0,"NOTYPE"); mapResult.insert(1,"OBJECT"); mapResult.insert(2,"FUNC"); mapResult.insert(3,"SECTION"); mapResult.insert(4,"FILE"); mapResult.insert(5,"COMMON"); mapResult.insert(10,"LOOS"); mapResult.insert(12,"HIOS"); mapResult.insert(13,"LOPROC"); // SPARC_REGISTER mapResult.insert(15,"HIPROC"); return mapResult; }