Exemple #1
0
        public byte[] GetBytes()
        {
            foreach (FatArch fatArch in Architectures.Keys)
            {
                if (fatArch.AlignLog2 == 0)
                {
                    fatArch.Align = DefaultAlignment;
                }
            }

            byte[] buffer = new byte[Length];
            Header.WriteBytes(buffer);
            int nextObjectOffset = FatHeader.Length + Architectures.Count * FatArch.Length;

            for (int index = 0; index < Architectures.Count; index++)
            {
                FatArch        fatArch = Architectures[index].Key;
                MachObjectFile file    = Architectures[index].Value;
                int            align   = fatArch.Align;
                int            padding = (align - (nextObjectOffset % align)) % align;
                nextObjectOffset += padding;
                fatArch.Offset    = (uint)nextObjectOffset;
                fatArch.Size      = (uint)file.Length;
                fatArch.WriteBytes(buffer, FatHeader.Length + index * FatArch.Length);
                file.WriteBytes(buffer, nextObjectOffset);
                nextObjectOffset += (int)fatArch.Size;
            }
            return(buffer);
        }
Exemple #2
0
 public static List <MachObjectFile> ReadMachObjects(byte[] buffer)
 {
     if (UniversalBinaryFile.IsUniversalBinaryFile(buffer))
     {
         UniversalBinaryFile file = new UniversalBinaryFile(buffer);
         return(file.MachObjects);
     }
     else if (MachObjectFile.IsMachObjectFile(buffer, 0))
     {
         List <MachObjectFile> result = new List <MachObjectFile>();
         result.Add(new MachObjectFile(buffer, 0, buffer.Length));
         return(result);
     }
     else
     {
         return(null);
     }
 }
Exemple #3
0
        public UniversalBinaryFile(byte[] buffer)
        {
            Header = new FatHeader(buffer);

            List <FatArch> architectures = new List <FatArch>();

            for (int index = 0; index < Header.NumberOfArchitectures; index++)
            {
                FatArch architecture = new FatArch(buffer, FatHeader.Length + index * FatArch.Length);
                architectures.Add(architecture);
            }

            foreach (FatArch architecture in architectures)
            {
                MachObjectFile machObject = new MachObjectFile(buffer, (int)architecture.Offset, (int)architecture.Size);
                Architectures.Add(architecture, machObject);
            }
        }