예제 #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 += file.Length;
            }
            return(buffer);
        }
예제 #2
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);
            }
        }
예제 #3
0
 public static byte[] PackMachObjects(List <MachObjectFile> files)
 {
     if (files.Count == 1)
     {
         return(files[0].GetBytes());
     }
     else
     {
         UniversalBinaryFile universalBinaryFile = new UniversalBinaryFile();
         universalBinaryFile.Header.NumberOfArchitectures = (uint)files.Count;
         foreach (MachObjectFile machObject in files)
         {
             FatArch fatArch = new FatArch();
             fatArch.CpuType    = machObject.Header.CpuType;
             fatArch.CpuSubType = machObject.Header.CpuSubType;
             universalBinaryFile.Architectures.Add(fatArch, machObject);
         }
         return(universalBinaryFile.GetBytes());
     }
 }