コード例 #1
0
 public static bool CanLoadBinary(Uri uri)
 {
     try
     {
         return(ELFReader.CheckELFType(Path.GetFullPath(uri.LocalPath)) != Class.NotELF);
     }
     catch (IOException) { return(false); }
     catch (UnauthorizedAccessException) { return(false); }
 }
コード例 #2
0
        static void Main(string[] args)
        {
            PrintInfo();
            var path = Console.ReadLine();

            path = path?.Replace("\"", "");
            if (File.Exists(path))
            {
                var type = ELFReader.CheckELFType(path);

                switch (type)
                {
                case Class.Bit32:
                    Console.WriteLine("32Bit Elf detected!");
                    var myElf = new MyELF <Int32>(path);
                    myElf.ReadAndFixHeader();
                    myElf.PrintHeaderInfo();
                    myElf.ReadSegmentHeaders();
                    myElf.PrintSegmentHeaderInfo();
                    myElf.RebuildSegmentByLoad();
                    break;

                case Class.Bit64:
                    Console.WriteLine("64Bit Elf is not support currently!");
                    return;

                case Class.NotELF:
                    Console.WriteLine("Given File is not a valid Elf! Make sure the magic is correct!");
                    return;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
        }
コード例 #3
0
        public static bool TryLoad(Stream stream, string filePath, out AnELF?anElf)
        {
            anElf = null;
            Class elfClass = ELFReader.CheckELFType(stream);

            if (elfClass == Class.NotELF)
            {
                Log.Warning($"AnELF.TryLoad: {filePath} is not an ELF binary");
                return(false);
            }

            IELF elf = ELFReader.Load(stream, shouldOwnStream: false);

            if (elf.Type != FileType.SharedObject)
            {
                Log.Warning($"AnELF.TryLoad: {filePath} is not a shared library");
                return(false);
            }

            if (elf.Endianess != Endianess.LittleEndian)
            {
                Log.Warning($"AnELF.TryLoad: {filePath} is not a little-endian binary");
                return(false);
            }

            bool is64;

            switch (elf.Machine)
            {
            case Machine.ARM:
            case Machine.Intel386:
                is64 = false;

                break;

            case Machine.AArch64:
            case Machine.AMD64:
                is64 = true;

                break;

            default:
                Log.Warning($"{filePath} is for an unsupported machine type {elf.Machine}");
                return(false);
            }

            ISymbolTable?symtab = GetSymbolTable(elf, DynsymSectionName);

            if (symtab == null)
            {
                Log.Warning($"{filePath} does not contain dynamic symbol section '{DynsymSectionName}'");
                return(false);
            }
            ISymbolTable dynsym = symtab;

            ISection?sec = GetSection(elf, RodataSectionName);

            if (sec == null)
            {
                Log.Warning("${filePath} does not contain read-only data section ('{RodataSectionName}')");
                return(false);
            }
            ISection rodata = sec;

            ISymbolTable?sym = GetSymbolTable(elf, SymtabSectionName);

            if (is64)
            {
                anElf = new ELF64(stream, filePath, elf, dynsym, rodata, sym);
            }
            else
            {
                anElf = new ELF32(stream, filePath, elf, dynsym, rodata, sym);
            }

            Log.Debug($"AnELF.TryLoad: {filePath} is a {anElf.Bitness}-bit ELF binary ({elf.Machine})");
            return(true);
        }
コード例 #4
0
        public static bool IsElfFile(string fileName)
        {
            var fileType = ELFReader.CheckELFType(fileName);

            return(fileType != Class.NotELF);
        }