コード例 #1
0
        /// <summary>
        /// Gets a string from the string table
        /// </summary>
        /// <param name="elf">The ELF</param>
        /// <param name="offset">The offset in the string table</param>
        /// <returns>The string</returns>
        private static unsafe string getString(ELF32 *elf, uint offset)
        {
            SectionHeader *section = getSection(elf, elf->ShnStrNdx);
            uint           strtab  = (uint)elf + section->Offset;

            return(Util.CharPtrToString((char *)(strtab + offset)));
        }
コード例 #2
0
        /// <summary>
        /// Checks if the ELF file is valid
        /// </summary>
        /// <param name="elf">The pointer to the ELF</param>
        /// <returns>If it's valid</returns>
        private static unsafe bool isValidELF(ELF32 *elf)
        {
            if (elf->Ident[(int)Ident.EI_MAG0] != 0x7F || elf->Ident[(int)Ident.EI_MAG1] != 'E' || elf->Ident[(int)Ident.EI_MAG2] != 'L' || elf->Ident[(int)Ident.EI_MAG3] != 'F')
            {
                return(false);
            }

            if (elf->Type != (int)ExecutableType.ET_EXEC)
            {
                return(false);
            }

            if (elf->Version != 1)
            {
                return(false);
            }

            if (elf->Machine != (int)MachineType.EM_X86)
            {
                return(false);
            }

            return(true);
        }
コード例 #3
0
 /// <summary>
 /// Gets a section header
 /// </summary>
 /// <param name="elf">The ELF</param>
 /// <param name="index">The index of the section</param>
 /// <returns>The pointer to the section header</returns>
 private static unsafe SectionHeader *getSection(ELF32 *elf, uint index)
 {
     return((SectionHeader *)((int)elf + elf->ShOff + (index * elf->ShEntSize)));
 }