示例#1
0
        static object ReadFile(BinaryReader reader, string filename)
        {
            var magic = reader.ReadUInt32();

            reader.BaseStream.Position = 0;
            switch (magic)
            {
            case MH_MAGIC:
            case MH_MAGIC_64:
                var mf = new MachOFile(filename);
                mf.Read(reader);
                return(mf);

            case FAT_MAGIC:             // little-endian fat binary
            case FAT_CIGAM:             // big-endian fat binary
            {
                var f = new FatFile(filename);
                f.Read(reader);
                return(f);
            }

            default:
                if (StaticLibrary.IsStaticLibrary(reader))
                {
                    var sl = new StaticLibrary();
                    sl.Read(filename, reader, reader.BaseStream.Length);
                    return(sl);
                }
                throw new Exception(string.Format("File format not recognized: {0} (magic: 0x{1})", filename, magic.ToString("X")));
            }
        }
示例#2
0
        internal void Read(string filename, BinaryReader reader, long size)
        {
            IsStaticLibrary(reader, throw_if_error: true);

            var pos = reader.BaseStream.Position;

            reader.BaseStream.Position += 8;             // header

            byte [] bytes;
            while (reader.BaseStream.Position < pos + size)
            {
                var fileIdentifier            = ReadString(reader, 16);
                var fileModificationTimestamp = ReadDecimal(reader, 12);
                var ownerId  = ReadDecimal(reader, 6);
                var groupId  = ReadDecimal(reader, 6);
                var fileMode = ReadOctal(reader, 8);
                var fileSize = ReadDecimal(reader, 10);
                bytes = reader.ReadBytes(2);                  // ending characters
                if (bytes [0] != 0x60 && bytes [1] != 0x0A)
                {
                    throw ErrorHelper.CreateError(1605, Errors.MT1605, fileIdentifier, filename, bytes[0].ToString("x"), bytes[1].ToString("x"));
                }

                if (fileIdentifier.StartsWith("#1/", StringComparison.Ordinal))
                {
                    var nameLength = int.Parse(fileIdentifier.Substring(3).TrimEnd(' '));
                    fileIdentifier = ReadString(reader, nameLength);
                    fileSize      -= nameLength;
                }

                var nextPosition = reader.BaseStream.Position + fileSize;
                if (MachOFile.IsMachOLibrary(null, reader))
                {
                    var file = new MachOFile(fileIdentifier);
                    file.Read(reader);
                    object_files.Add(file);
                }
                // byte position is always even after each file.
                if (nextPosition % 1 == 1)
                {
                    nextPosition++;
                }
                reader.BaseStream.Position = nextPosition;
            }
        }
示例#3
0
        internal void ReadEntry(BinaryReader reader)
        {
            reader.BaseStream.Position = offset;

            if (MachOFile.IsMachOLibrary(this, reader))
            {
                entry = new MachOFile(this);
                entry.Read(reader);
            }
            else if (StaticLibrary.IsStaticLibrary(reader))
            {
                static_library = new StaticLibrary();
                static_library.Read(parent?.Filename, reader, size);
            }
            else
            {
                throw ErrorHelper.CreateError(1603, Errors.MX1603, offset, parent.Filename);
            }
        }
示例#4
0
        internal void ReadEntry(BinaryReader reader)
        {
            reader.BaseStream.Position = offset;

            if (MachOFile.IsMachOLibrary(this, reader))
            {
                entry = new MachOFile(this);
                entry.Read(reader);
            }
            else if (StaticLibrary.IsStaticLibrary(reader))
            {
                static_library = new StaticLibrary();
                static_library.Read(reader);
            }
            else
            {
                throw ErrorHelper.CreateError(1603, "Unknown format for fat entry at position {0} in {1}.", offset, parent.Filename);
            }
        }
示例#5
0
        internal void ReadEntry(BinaryReader reader)
        {
            reader.BaseStream.Position = offset;

            if (MachOFile.IsMachOLibrary (this, reader)) {
                entry = new MachOFile (this);
                entry.Read (reader);
            } else if (StaticLibrary.IsStaticLibrary (reader)) {
                static_library = new StaticLibrary ();
                static_library.Read (reader);
            } else {
                throw ErrorHelper.CreateError (1603, "Unknown format for fat entry at position {0} in {1}.", offset, parent.Filename);
            }
        }
示例#6
0
 static object ReadFile(BinaryReader reader, string filename)
 {
     var magic = reader.ReadUInt32 ();
     reader.BaseStream.Position = 0;
     switch (magic) {
     case MH_MAGIC:
     case MH_MAGIC_64:
         var mf = new MachOFile (filename);
         mf.Read (reader);
         return mf;
     case FAT_MAGIC: // little-endian fat binary
     case FAT_CIGAM: // big-endian fat binary
         {
             var f = new FatFile (filename);
             f.Read (reader);
             return f;
         }
     default:
         if (StaticLibrary.IsStaticLibrary (reader)) {
             var sl = new StaticLibrary ();
             sl.Read (reader);
             return sl;
         }
         throw new Exception (string.Format ("File format not recognized: {0} (magic: 0x{1})", filename, magic.ToString ("X")));
     }
 }