internal static List <MachoBinary> Load(Stream stream) { var binaries = new List <MachoBinary>(); var eReader = new EndianReader(stream, Endian.Big); var binaryCount = eReader.ReadUInt32(); var startPosition = stream.Position; for (var idx = 0; idx < binaryCount; idx++) { stream.Seek(startPosition + Constants.FAT_HEADER_SIZE * idx + 8, SeekOrigin.Begin); var offset = eReader.ReadInt32(); var size = eReader.ReadInt32(); var result = new byte[size]; stream.Seek(offset, SeekOrigin.Begin); stream.Read(result, 0, size); binaries.Add(MachoBinary.Load(result)); } return(binaries); }
internal static MachoBinary Load(Stream stream, BinaryReader bReader, MachoFormat binaryFormat) { var result = new MachoBinary { Format = binaryFormat }; // Reset to the beginning right after the binaryFormat 4 bytes stream.Seek(4, SeekOrigin.Begin); result.CpuType = (CpuTypes)bReader.ReadInt32(); bReader.ReadBytes(4); // TODO: CPU Subtype Mapping result.FileType = (FileTypes)bReader.ReadUInt32(); var commandCount = bReader.ReadInt32(); result.CommandSize = bReader.ReadInt32(); bReader.ReadBytes(4); // TODO: Flags // Reserved for 64bit Binaries if (result.CpuType.IsCpu64bit()) { bReader.ReadBytes(4); // TODO: Store? } result.Commands = ParseCommands(bReader, stream, commandCount, result.CpuType); return(result); }