Exemple #1
0
        public static MbdbRecord[] ParseMbdbData(byte[] mbdbData)
        {
            if (mbdbData.Length < MbdbSignature.Length)
            {
                throw new MbdbDataInvalidException("MBDB data is too short to be valid.");
            }

            int dataPosition = 0;

            while (dataPosition < MbdbSignature.Length)
            {
                if (mbdbData[dataPosition] != MbdbSignature[dataPosition])
                {
                    throw new MbdbDataInvalidException("MBDB data does not have valid data signature.");
                }
                dataPosition++;
            }

            List <MbdbRecord> records = new List <MbdbRecord>();

            while (dataPosition < mbdbData.Length)
            {
                try
                {
                    MbdbRecord nextRecord = ParseMbdbRecord(mbdbData, ref dataPosition);
                    records.Add(nextRecord);
                }
                catch (Exception ex)
                {
                    throw new MbdbDataInvalidException("Failed to parse MBDB data", ex);
                }
            }

            return(records.ToArray());;
        }
Exemple #2
0
        private static MbdbRecord ParseMbdbRecord(byte[] mbdbData, ref int dataPosition)
        {
            MbdbRecord record = new MbdbRecord();

            record.Domain               = ParseString(mbdbData, ref dataPosition);
            record.Path                 = ParseString(mbdbData, ref dataPosition);
            record.LinkTarget           = ParseString(mbdbData, ref dataPosition);
            record.DataHash             = ParseString(mbdbData, ref dataPosition);
            record.UnknownField1        = ParseString(mbdbData, ref dataPosition);
            record.Mode                 = ByteConverter.ParseUInt16(mbdbData, ref dataPosition);
            record.UnknownField2        = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.UnknownField3        = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.UserId               = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.GroupId              = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.LastModificationTime = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.LastAccessedTime     = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.CreationTime         = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.FileLength           = ByteConverter.ParseUInt64(mbdbData, ref dataPosition);
            record.Flag                 = ByteConverter.ParseByte(mbdbData, ref dataPosition);

            byte propertyCount = ByteConverter.ParseByte(mbdbData, ref dataPosition);

            List <MbdbRecordProperty> recordProperties = new List <MbdbRecordProperty>();

            for (byte i = 0; i < propertyCount; i++)
            {
                MbdbRecordProperty nextRecordProperty = ParseRecordProperty(mbdbData, ref dataPosition);
                recordProperties.Add(nextRecordProperty);
            }
            record.Properties = recordProperties;

            return(record);
        }
Exemple #3
0
        private static MbdbRecord ParseMbdbRecord(byte[] mbdbData, ref int dataPosition)
        {
            MbdbRecord record = new MbdbRecord();

            record.Domain = ParseString(mbdbData, ref dataPosition);
            record.Path = ParseString(mbdbData, ref dataPosition);
            record.LinkTarget = ParseString(mbdbData, ref dataPosition);
            record.DataHash = ParseString(mbdbData, ref dataPosition);
            record.UnknownField1 = ParseString(mbdbData, ref dataPosition);
            record.Mode = ByteConverter.ParseUInt16(mbdbData, ref dataPosition);
            record.UnknownField2 = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.UnknownField3 = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.UserId = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.GroupId = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.LastModificationTime = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.LastAccessedTime = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.CreationTime = ByteConverter.ParseUInt32(mbdbData, ref dataPosition);
            record.FileLength = ByteConverter.ParseUInt64(mbdbData, ref dataPosition);
            record.Flag = ByteConverter.ParseByte(mbdbData, ref dataPosition);

            byte propertyCount = ByteConverter.ParseByte(mbdbData, ref dataPosition);

            List<MbdbRecordProperty> recordProperties = new List<MbdbRecordProperty>();
            for (byte i = 0; i < propertyCount; i++)
            {
                MbdbRecordProperty nextRecordProperty = ParseRecordProperty(mbdbData, ref dataPosition);
                recordProperties.Add(nextRecordProperty);
            }
            record.Properties = recordProperties;

            return record;
        }