Esempio n. 1
0
 private void Align(BinaryParser parser)
 {
     if (_pack > 1)
     {
         parser.Align(_pack);
     }
 }
Esempio n. 2
0
        public Sections(Reader reader)
        {
            this.memStream = reader.memStream;
            this.binaryParser = reader.binaryParser;
            this.sectionCount = (int)(reader.GetFileHeader().GetNumberOfSections());
            long optHeaderAddress = reader.GetDOSHeader().GetFileAddress() + fileHeaderLength;
            long dataDirectoryAddress = optHeaderAddress + optHeaderLength;
            sectionAddress = (dataDirectoryAddress + dataDirectorySize) + sectionPadding + 0x4;

            for (int i = 0; i < sectionCount; i++)
            {
                long count = sectionLength * i;
                long offset = sectionAddress + count;
                memStream.Position = offset;
                string name = Encoding.Default.GetString(binaryParser.ReadBytes(8));
                UInt32 virtualSize = (UInt32)(memStream.Position = binaryParser.ReadUInt32());
                memStream.Position = offset + 0xc;
                UInt32 virtualAddress = (UInt32)(memStream.Position = binaryParser.ReadUInt32());
                memStream.Position = offset + 0x10;
                UInt32 rawDataSize = (UInt32)(memStream.Position = binaryParser.ReadUInt32());
                memStream.Position = offset + 0x14;
                UInt32 rawDataAddress = (UInt32)(memStream.Position = binaryParser.ReadUInt32());
                memStream.Position = offset + 0x18;
                UInt32 relocAddress = (UInt32)(memStream.Position = binaryParser.ReadUInt32());
                memStream.Position = offset + 0x1c;
                UInt32 lineAddress = (UInt32)(memStream.Position = binaryParser.ReadUInt32());
                memStream.Position = offset + 0x20;
                UInt16 relocCount = (UInt16)(memStream.Position = binaryParser.ReadUInt16());
                memStream.Position = offset + 0x22;
                UInt16 lineCount = (UInt16)(memStream.Position = binaryParser.ReadUInt16());

                this.allSections.Add(new Section(name, virtualAddress, virtualSize, rawDataSize, rawDataAddress, relocAddress, lineAddress, relocCount, lineCount));
            }
        }
Esempio n. 3
0
 public DataDirectories(Reader reader)
 {
     this.memStream = reader.memStream;
     this.binaryParser = reader.binaryParser;
     long optHeaderAddress = reader.GetDOSHeader().GetFileAddress() + fileHeaderLength;
     dataDirectoryAddress = optHeaderAddress + optHeaderLength;
 }
Esempio n. 4
0
File: Reader.cs Progetto: 0xe9/Snile
 private Reader(DataStream memorySteam)
 {
     if (memStream == null)
         throw new Exception("Stream is null");
     this.memStream = memorySteam;
     this.binaryParser = new BinaryParser(memStream);
 }
Esempio n. 5
0
        private Object Read(BinaryParser parser, FieldInfo field, Type type)
        {
            PscxArgumentException.ThrowIf((type == field.DeclaringType), "Parsing field {0} would loop forever.", field);

            if (IsRecord(type))
            {
                return new RecordParser(type).Parse(parser);
            }

            if (type == typeof(String))
            {
                return ReadString(parser, field);
            }

            if (type == typeof(DateTime))
            {
                return ReadDateTime(parser, field);
            }

            if (type == typeof(Version))
            {
                return ReadVersion(parser, field);
            }

            return ReadIntegral(parser, type);
        }
Esempio n. 6
0
 public CLRHeader(Reader reader)
 {
     this.memStream = reader.memStream;
     this.binaryParser = reader.binaryParser;
     uint netDirectoryAddress = reader.GetDataDirectories().GetNETMetadataDirectory().GetAddress();
     this.clrHeaderAddress = (long)reader.RVAtoOffset(netDirectoryAddress);
 }
Esempio n. 7
0
		private void ParseSkinSet(BinaryParser parser, AnimSkin skin)
		{
			var name = parser.ConsumeUInt32();
			var numVerts = parser.ConsumeUInt32();
			var numBones = parser.ConsumeByte();
			parser.Expect(1);
			var boneIds = parser.ConsumeByteArray(numBones);
			var vertIds = parser.ConsumeUInt16Array((int)numVerts);
			var preMultipliedPositions = parser.ConsumeVector3Array((int)numVerts * numBones);
			var weights = parser.ConsumeFloatArray((int)numVerts * numBones);

			for (int index = 0; index < vertIds.Length; index++)
			{
				var id = vertIds[index];
				skin.Weights.EnsureAt(id);
				var vertexWeights = new VertexWeights { };
				if (numBones > 0)
				{
					vertexWeights.Bone0 = new VertexWeight { BoneIndex = boneIds[0], Weight = weights[0 + index * numBones] };
				}
				if (numBones > 1)
				{
					vertexWeights.Bone1 = new VertexWeight { BoneIndex = boneIds[1], Weight = weights[1 + index * numBones] };
				}
				if (numBones > 2)
				{
					vertexWeights.Bone2 = new VertexWeight { BoneIndex = boneIds[2], Weight = weights[2 + index * numBones] };
				}
				if (numBones > 3)
				{
					vertexWeights.Bone3 = new VertexWeight { BoneIndex = boneIds[3], Weight = weights[3 + index * numBones] };
				}
				skin.Weights[id] = vertexWeights;
			}
		}
        public void Read(BinaryParser input)
        {
            // binaryHeaderEnum has already been read
            _objectId = input.ReadInt32();
            _name = input.ReadString();
            _numMembers = input.ReadInt32();
            _memberNames = new string[_numMembers];
            _binaryTypeEnumA = new BinaryTypeEnum[_numMembers];
            _typeInformationA = new object[_numMembers];
            _memberAssemIds = new int[_numMembers];
            for (int i = 0; i < _numMembers; i++)
            {
                _memberNames[i] = input.ReadString();
            }
            for (int i = 0; i < _numMembers; i++)
            {
                _binaryTypeEnumA[i] = (BinaryTypeEnum)input.ReadByte();
            }
            for (int i = 0; i < _numMembers; i++)
            {
                if (_binaryTypeEnumA[i] != BinaryTypeEnum.ObjectUrt && _binaryTypeEnumA[i] != BinaryTypeEnum.ObjectUser)
                {
                    _typeInformationA[i] = BinaryTypeConverter.ReadTypeInfo(_binaryTypeEnumA[i], input, out _memberAssemIds[i]);
                }
                else
                {
                    BinaryTypeConverter.ReadTypeInfo(_binaryTypeEnumA[i], input, out _memberAssemIds[i]);
                }
            }

            if (_binaryHeaderEnum == BinaryHeaderEnum.ObjectWithMapTypedAssemId)
            {
                _assemId = input.ReadInt32();
            }
        }
Esempio n. 9
0
 public MetadataHeader(Reader reader)
 {
     this.memStream = reader.memStream;
     this.binaryParser = reader.binaryParser;
     uint metaDataRVA = reader.GetCLRHeader().GetMetaDataRVA();
     this.metaDataHeaderAddress = (long)reader.RVAtoOffset(metaDataRVA);
     this.versionLength = (int)(binaryParser.ParseUInt32(metaDataHeaderAddress + 0xC));
 }
Esempio n. 10
0
 public BlobHeap(Reader reader, string name, uint offset, uint size)
     : base(name, offset, size)
 {
     this.binaryParser = reader.GetBinaryParser();
     this.name = name;
     this.offset = offset;
     this.size = size;
 }
Esempio n. 11
0
File: Reader.cs Progetto: 0xe9/Snile
        public Reader(byte[] data)
        {
            if(data == null)
                throw new Exception("Parameter is null");

            this.memStream = new DataStream(data);
            this.binaryParser = new BinaryParser(memStream);
        }
Esempio n. 12
0
File: Reader.cs Progetto: 0xe9/Snile
        public Reader(string filePath)
        {
            if (filePath.Length < 0)
                throw new Exception("File path is empty");

            data = File.ReadAllBytes(filePath);
            this.memStream = new DataStream(data);
            this.binaryParser = new BinaryParser(memStream);
        }
Esempio n. 13
0
        public OcadFile ReadFile()
        {
            using (var stream = new FileStream(_filePath, FileMode.Open))
            {
                var reader = new OcadStreamReader(stream);
                var parser = new BinaryParser<OcadFile>();

                return parser.Read(reader);
            }
        }
Esempio n. 14
0
 public void Read(BinaryParser input, BinaryHeaderEnum binaryHeaderEnum)
 {
     //binaryHeaderEnum = input.ReadByte(); already read
     switch (binaryHeaderEnum)
     {
         case BinaryHeaderEnum.ObjectNull:
             _nullCount = 1;
             break;
         case BinaryHeaderEnum.ObjectNullMultiple256:
             _nullCount = input.ReadByte();
             break;
         case BinaryHeaderEnum.ObjectNullMultiple:
             _nullCount = input.ReadInt32();
             break;
     }
 }
Esempio n. 15
0
        public void Read(BinaryParser input)
        {
            _objectId = input.ReadInt32();
            _name = input.ReadString();
            _numMembers = input.ReadInt32();

            _memberNames = new string[_numMembers];
            for (int i = 0; i < _numMembers; i++)
            {
                _memberNames[i] = input.ReadString();
            }

            if (_binaryHeaderEnum == BinaryHeaderEnum.ObjectWithMapAssemId)
            {
                _assemId = input.ReadInt32();
            }
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            OcadCourseSettingProject project = new OcadCourseSettingProject();
            using (var stream = new FileStream(@"D:\temp\testmap.ocd", FileMode.Open))
            {
                var reader = new OcadStreamReader(stream);
                var parser = new BinaryParser<OcadFile>();

                var file = parser.Read(reader);
                project.Load(file);
            }

            foreach (var symbol in project.Symbols)
            {
                Console.WriteLine(symbol.Description);
            }
        }
Esempio n. 17
0
		/// <summary>
		/// Parse binary block.
		/// </summary>
		public Managed Parse(BinaryParser parser)
		{
			var material = this.context.Resolve<Material>();
			material.NameHash = parser.ConsumeUInt32();

			var isShort = parser.ConsumeBool();

			material.Flags = parser.ConsumeUInt32();

			if (!isShort)
			{
				material.ZDepthOfs = parser.ConsumeInt16();
				material.ZDepthOfsHW = parser.ConsumeInt16();
				material.ColEmissive = parser.ConsumeColor();
				material.ColAmbient = parser.ConsumeColor();
				material.ColDiffuse = parser.ConsumeColor();
				Color specular = parser.ConsumeColor();
				material.ColSpecular = specular;
				material.SpecularPower = specular.A;
				parser.Expect((uint)4);
			}
			material.Texture0.HashReference = parser.ConsumeUInt32();
			if (!isShort)
			{
				material.Texture1.HashReference = parser.ConsumeUInt32();
				material.Texture2.HashReference = parser.ConsumeUInt32();
				material.Texture3.HashReference = parser.ConsumeUInt32();

				var animated = parser.ConsumeBool();
				if (animated)
				{
					material.MatAnim = new MatAnim();
					parser.Expect(0);
					material.MatAnim.CelNum = parser.ConsumeByte();
					material.MatAnim.CelNumU = parser.ConsumeByte();
					material.MatAnim.CelW = parser.ConsumeByte();
					material.MatAnim.CelH = parser.ConsumeByte();
					material.MatAnim.CelPeriod = parser.ConsumeByte();
				}
				material.AlphaTestValue = parser.ConsumeByte();
				material.ShaderTechnique.HashReference = parser.ConsumeUInt32();
			}
			return material;
		}
Esempio n. 18
0
		/// <summary>
		/// Parse binary block.
		/// </summary>
		public Managed Parse(BinaryParser parser)
		{
			var texture = this.context.Resolve<Texture>();
			texture.NameHash = parser.ConsumeUInt32();
			texture.Flags = parser.ConsumeUInt32();
			texture.FormatSW = (ImageFormat)parser.ConsumeByte();
			texture.FormatHW = (ImageFormat)parser.ConsumeByte();

			float x = parser.ConsumeFloat();
			float y = parser.ConsumeFloat();
			texture.UVScale = new Vector2(x, y);

			texture.Image = this.ParseImage(parser);

			var e = parser.ConsumeBool();
			//parser.Expect(false);

			return texture;
		}
Esempio n. 19
0
		/// <summary>
		/// Parse binary block.
		/// </summary>
		public Managed Parse(BinaryParser parser)
		{
			var skin = this.context.Resolve<AnimSkin>();
			skin.NameHash = parser.ConsumeUInt32();
			skin.Flags = parser.ConsumeUInt32();
			skin.SkeletonModel.HashReference = parser.ConsumeUInt32();
			skin.Skeleton.HashReference = parser.ConsumeUInt32();
			var numGroups = parser.ConsumeUInt32();
			while (numGroups > 0)
			{
				--numGroups;
				var type = parser.ConsumeUInt32();
				if (type == Hash.Get("CIwAnimSkinSet"))
				{
					this.ParseSkinSet(parser, skin);
					continue;
				}
				throw new FormatException();
			}
			return skin;
		}
Esempio n. 20
0
        public Object Parse(BinaryParser parser)
        {
            var record = Activator.CreateInstance(_type);

            foreach (var field in Fields)
            {
                var type = field.FieldType;

                if (type.IsEnum)
                {
                    type = Enum.GetUnderlyingType(type);
                }

                var value = Read(parser, field, type);

                field.SetValue(record, value);

                ValidateSignature(field, value);
                Align(parser);
            }

            return record;
        }
Esempio n. 21
0
        public PortableExecutableInfo(string path)
        {
            this.imagePath = path;

            using(Stream stream = OpenImage())
            {
                using (BinaryParser br = new BinaryParser(stream))
                {
                    dosHeader = DosHeader.Parse(br);

                    br.SkipTo(dosHeader.CoffHeaderOffset);

                    coffHeader = br.ReadRecord<CoffHeader>();
                    peHeader = PEHeader.Parse(br);

                    sections = new List<PESection>();
                    for (int i = 0; i < coffHeader.NumberOfSections; i++)
                    {
                        sections.Add(br.ReadRecord<PESection>());
                    }
                }
            }
        }
Esempio n. 22
0
		/// <summary>
		/// Parse binary block.
		/// </summary>
		public Managed Parse(BinaryParser parser)
		{
			var skel = this.context.Resolve<AnimSkel>();
			skel.NameHash = parser.ConsumeUInt32();

			var numBones = parser.ConsumeUInt32();
			while (numBones > 0)
			{
				parser.Expect(Hash.Get("CIwAnimBone"));
				var nameHash = parser.ConsumeUInt32();
				var parent = parser.ConsumeUInt32();
				var parentIndex = skel.EnsureBone(parent);
				var boneIndex = skel.EnsureBone(nameHash);
				var bone = skel.Bones[boneIndex];
				bone.Parent = parentIndex;
				bone.BindingRot = parser.ConsumeQuaternion();
				bone.BindingPos = parser.ConsumeVector3();
				bone.SkelId = parser.ConsumeUInt16();
				bone.Flags = parser.ConsumeUInt16();

				--numBones;
			}
			return skel;
		}
Esempio n. 23
0
        private static Object ReadVersion(BinaryParser parser, FieldInfo field)
        {
            var attr = BinaryParser.GetAttribute<VersionFieldAttribute>(field);

            if (attr != null)
            {
                var args = new Object[attr.ComponentCount];

                for (int i = 0; i < args.Length; i++)
                {
                    args[i] = ReadIntegral(parser, attr.ComponentType);
                }

                return Activator.CreateInstance(typeof(Version), args);
            }

            PscxArgumentException.Throw(field.Name, "Don't know how to parse field " + field.ToString());
            return null;
        }
Esempio n. 24
0
        private static String ReadString(BinaryParser parser, FieldInfo field)
        {
            var attr = BinaryParser.GetAttribute<BinaryFieldAttribute>(field);

            if (attr != null)
            {
                if (attr.FieldType == BinaryFieldType.StringAsciiZ)
                {
                    if (attr.FixedLength > 0)
                    {
                        return parser.ReadStringAsciiZ();
                    }

                    return parser.ReadStringAsciiZ();
                }
            }

            PscxArgumentException.Throw(field.Name, "Don't know how to parse field " + field.ToString());
            return null;
        }
Esempio n. 25
0
        private static Object ReadIntegral(BinaryParser parser, TypeCode typeCode)
        {
            switch (typeCode)
            {
                case TypeCode.Byte: return parser.ReadByte();
                case TypeCode.UInt16: return parser.ReadUInt16();
                case TypeCode.UInt32: return parser.ReadUInt32();
                case TypeCode.UInt64: return parser.ReadUInt64();

                case TypeCode.SByte: return parser.ReadSByte();
                case TypeCode.Int16: return parser.ReadInt16();
                case TypeCode.Int32: return parser.ReadInt32();
                case TypeCode.Int64: return parser.ReadInt64();
            }

            return null;
        }
Esempio n. 26
0
        private static Object ReadIntegral(BinaryParser parser, Type type)
        {
            var result = ReadIntegral(parser, Type.GetTypeCode(type));

            if (result == null)
            {
                BinaryParserException.ThrowUnknownType(type);
            }

            return result;
        }
Esempio n. 27
0
 public static Uint8 FromParser(BinaryParser parser, int?hint = null)
 {
     return(parser.ReadOne());
 }
Esempio n. 28
0
 public void Read(BinaryParser input)
 {
     _assemId       = input.ReadInt32();
     _assemblyIndex = input.ReadInt32();
 }
Esempio n. 29
0
 public static Hash256 FromParser(BinaryParser parser, int?hint = null)
 {
     return(new Hash256(parser.Read(32)));
 }
Esempio n. 30
0
 public void Read(BinaryParser input)
 {
     _primitiveTypeEnum = (InternalPrimitiveTypeE)input.ReadByte(); //PDJ
     _value             = input.ReadValue(_primitiveTypeEnum);
 }
 public static Uint16 FromParser(BinaryParser parser, int?hint = null)
 {
     return(Bits.ToUInt16(parser.Read(2), 0));
 }
Esempio n. 32
0
 public static Hash160 FromParser(BinaryParser parser, int?hint = null)
 {
     return(new Hash160(parser.Read(20)));
 }
Esempio n. 33
0
 public void Read(BinaryParser input)
 {
     _objectId = input.ReadInt32();
     _value    = input.ReadString();
 }
Esempio n. 34
0
 public void Read(BinaryParser input)
 {
     //binaryHeaderEnum = input.ReadByte(); already read
     _idRef = input.ReadInt32();
 }
Esempio n. 35
0
        private static DateTime ReadDateTime(BinaryParser parser, FieldInfo field)
        {
            var attr = BinaryParser.GetAttribute<BinaryFieldAttribute>(field);

            if (attr != null)
            {
                if (attr.FieldType == BinaryFieldType.UnixTime)
                {
                    return UnixTime.ToDateTime(parser.ReadUInt32());
                }
            }

            PscxArgumentException.Throw("Don't know how to parse DateTime field " + field.ToString());
            return DateTime.MinValue;
        }
Esempio n. 36
0
 public void Read(BinaryParser input)
 {
     _objectId = input.ReadInt32();
     _mapId = input.ReadInt32();
 }
Esempio n. 37
0
 public void Read(BinaryParser input)
 {
     Read(input, BinaryHeaderEnum.ObjectNull);
 }
Esempio n. 38
0
 public void Read(BinaryParser input)
 {
     _assemId        = input.ReadInt32();
     _assemblyString = input.ReadString();
 }
Esempio n. 39
0
 public NTHeader(Reader reader)
 {
     this.memStream = reader.memStream;
     this.binaryParser = reader.binaryParser;
 }
Esempio n. 40
0
        public static Cplc Parse(byte[] cplc)
        {
            if (cplc == null)
            {
                throw new NullReferenceException();
            }
            if (cplc.Length != CplcLength)
            {
                throw new InvalidOperationException("CPLC length mismatch");
            }

            BinaryParser parser = new BinaryParser(cplc, ByteEndianess.BigEndian, BitEndianess.Msb);
            Cplc         output = new Cplc();

            /*
             * 5 ROM identifiers (10 bytes), each consisting of 4 digits coded on 2 bytes:
             */

            // -  IC Fabricator (2B)
            output.ICFabricator = parser.ReadUInt16();

            // -  IC Type (2B)
            output.ICType = parser.ReadUInt16();

            // -  Operating System Provider Identifier (2B)
            output.OSProviderId = parser.ReadUInt16();

            // -  Operating System Release Date (2B)
            output.OSReleaseDate = parser.ReadUInt16();

            // -  Operating System Release Level (2B)
            output.OSReleaseLevel = parser.ReadUInt16();

            /*
             * EEPROM Identifiers contain chip, card, pre-perso & personalizer info., in the given order :
             */

            // -  Chip Identifiers:
            // -  IC Fabrication Date (2B)
            output.ICFabricationDate = parser.ReadUInt16();

            // -  IC Serial Number (4B)
            output.ICSerialNo = parser.ReadUInt32();

            // -  IC Batch Identifier (2B)
            output.ICBatchId = parser.ReadUInt16();

            // -  Card identifiers :
            // -  IC Module Fabricator  (2B)
            output.ICModuleFabricator = parser.ReadUInt16();

            // -  IC Module Packaging Date      (2B)
            output.ICModulePackagingDate = parser.ReadUInt16();

            // -  ICC Manufacturer      (2B)
            output.ICCManufacturer = parser.ReadUInt16();

            // -  IC Embedding date     (2B)
            output.ICEmbeddingDate = parser.ReadUInt16();

            // -  Pre-personalization identifiers :
            // -  Pre-personalizer Identifier (2B)
            output.PrePersoId = parser.ReadUInt16();

            // -  Pre-personalization Date (2B)
            output.PrePersoDate = parser.ReadUInt16();

            // -  Pre-personalization Equipment (4B)
            output.PrePersoEquipment = parser.ReadUInt16();

            // -  Personalization identifiers :
            // -  Personalizer Identifier (2B)
            output.PersoId = parser.ReadUInt16();

            // -  Personalization Date (2B)
            output.PersoDate = parser.ReadUInt16();

            // -  Personalization Equipment (4B)
            output.PersoEquipment = parser.ReadUInt16();

            return(output);
        }