Esempio n. 1
0
        internal MachO(Stream stream, bool is64, Endianess endianess, bool ownsStream)
        {
            this.is64 = is64;

            using var reader = new SimpleEndianessAwareReader(stream, endianess, ownsStream);

            Machine = (Machine)reader.ReadInt32();
            reader.ReadBytes(4); // we don't support the cpu subtype now
            FileType = (FileType)reader.ReadUInt32();
            var noOfCommands = reader.ReadInt32();

            reader.ReadInt32();  // size of commands
            reader.ReadBytes(4); // we don't support flags now
            if (is64)
            {
                reader.ReadBytes(4); // reserved
            }
            commands = new Command[noOfCommands];
            ReadCommands(noOfCommands, stream, reader);
        }
Esempio n. 2
0
        internal Dylib(SimpleEndianessAwareReader reader, Stream stream, uint commandSize) : base(reader, stream)
        {
            var offset               = reader.ReadUInt32();
            var timestamp            = reader.ReadInt32();
            var currentVersion       = reader.ReadUInt32();
            var compatibilityVersion = reader.ReadUInt32();

            Timestamp            = DateTimeOffset.FromUnixTimeSeconds(timestamp).UtcDateTime;
            CurrentVersion       = GetVersion(currentVersion);
            CompatibilityVersion = GetVersion(compatibilityVersion);
            Name = GetString(reader.ReadBytes((int)(commandSize - offset)));
        }
Esempio n. 3
0
        public static IEnumerable <MachO> Enumerate(Stream stream, bool shouldOwnStream)
        {
            // Fat header is always big endian.
            var reader = new SimpleEndianessAwareReader(stream, Endianess.BigEndian, !shouldOwnStream);

            // We assume that fat magic has been already read.
            var machOCount      = reader.ReadInt32();
            var alreadyRead     = 0;
            var fatEntriesBegin = stream.Position;

            while (alreadyRead < machOCount)
            {
                // We're only interested in offset and size.
                stream.Seek(fatEntriesBegin + 20 * alreadyRead + 8, SeekOrigin.Begin);
                var offset    = reader.ReadInt32();
                var size      = reader.ReadInt32();
                var substream = new SubStream(stream, offset, size);
                yield return(MachOReader.Load(substream, false));

                alreadyRead++;
            }
        }