Ejemplo n.º 1
0
        internal MachInfo Parse(IIntegerReader s)
        {
            var            magic = s.ReadUInt32();
            MachHeaderType type;

            if (magic == MH_MAGIC)
            {
                type = MachHeaderType.Mach32;
            }
            else if (magic == MH_MAGIC_64)
            {
                type = MachHeaderType.Mach64;
            }
            else
            {
                return(null);
            }

            var cpu      = s.ReadInt32();
            var subtype  = s.ReadInt32(); //machine specifier
            var filetype = s.ReadUInt32();

            s.ReadUInt32();             //# of load cmds
            s.ReadUInt32();             //size of load cms
            var flags = s.ReadUInt32(); //flags

            return(new MachInfo(type, cpu, subtype, (MachFileType)filetype));
        }
Ejemplo n.º 2
0
        MachInfo ParseSingleArch(IIntegerReader s)
        {
            //CPU specifier
            var cpu = s.ReadInt32();
            //CPU subtype
            var subtype = s.ReadInt32();

            //offset, size, and alignment of obj. file
            s.ReadUInt32(); s.ReadUInt32(); s.ReadUInt32();
            return(new MachInfo(MachHeaderType.MachMulti, cpu, subtype, null));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns null if this is not a Fat binary, or if the endianess is wrong.
        /// May return an empty list if the file is invalid, such that the supported architecture count is 0
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        internal IEnumerable <MachInfo> Parse(IIntegerReader s)
        {
            //Magic byte
            if (s.ReadUInt32() != FAT_MAGIC)
            {
                return(null);
            }
            //architecture count
            var count = s.ReadUInt32();
            var list  = new List <MachInfo>((int)count);

            for (var i = 0; i < count; i++)
            {
                list.Add(ParseSingleArch(s));
            }
            return(list);
        }