LoginSignup
0
0

More than 5 years have passed since last update.

elfsharp > ELFReader.cs > CheckELFType() > 先頭4文字のチェック

Last updated at Posted at 2015-08-19

...
public static Class CheckELFType(string fileName)
        {
            var size = new FileInfo(fileName).Length;
            if(size < Consts.MinimalELFSize)
            {
                return Class.NotELF;
            }
            using(var reader = new BinaryReader(File.OpenRead(fileName)))
            {
                var magic = reader.ReadBytes(4);
                for(var i = 0; i < 4; i++)
                {
                    if(magic[i] != Magic[i])
                    {
                        return Class.NotELF;
                    }
                }
                var value = reader.ReadByte();
                return value == 1 ? Class.Bit32 : Class.Bit64;
            }
        }
...

ファイルの先頭から4文字のチェック (Magicかどうか) をしている。

Magicは同じスクリプト内で

private static readonly byte[] Magic = new byte[] {
            0x7F,
            0x45,
            0x4C,
            0x46
        }; // 0x7F 'E' 'L' 'F'
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0