示例#1
0
        public static List <MBFileRecord> ReadMBDB(string BackupPath)
        {
            try
            {
                List <MBFileRecord> files;
                byte[]                    signature = new byte[6];           // buffer signature
                byte[]                    buf       = new byte[26];          // buffer for .mbdx record
                StringBuilder             sb        = new StringBuilder(40); // stringbuilder for the Key
                byte[]                    data      = new byte[40];          // buffer for the fixed part of .mbdb record
                SHA1CryptoServiceProvider hasher    = new SHA1CryptoServiceProvider();

                System.DateTime unixEpoch = new System.DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);


                // open the database
                FileStream mbdb = new FileStream(Path.Combine(BackupPath, "Manifest.mbdb"), FileMode.Open, FileAccess.Read);

                // skip signature
                mbdb.Read(signature, 0, 6);
                if (BitConverter.ToString(signature, 0) != "6D-62-64-62-05-00")     // "mbdb\5\0"
                {
                    throw new Exception("bad .mbdb file");
                }

                files = new List <MBFileRecord>();

                // loop through the records
                for (int i = 0; mbdb.Position < mbdb.Length; ++i)
                {
                    MBFileRecord rec = new MBFileRecord();

                    rec.Domain     = getS(mbdb);
                    rec.Path       = getS(mbdb);
                    rec.LinkTarget = getS(mbdb);
                    rec.DataHash   = getD(mbdb);
                    rec.alwaysNull = getD(mbdb);

                    mbdb.Read(data, 0, 40);

                    rec.data = toHex(data, 2, 4, 4, 4, 4, 4, 4, 4, 8, 1, 1);

                    rec.Mode       = BigEndianBitConverter.ToUInt16(data, 0);
                    rec.alwaysZero = BigEndianBitConverter.ToInt32(data, 2);
                    rec.inode      = BigEndianBitConverter.ToUInt32(data, 6);
                    rec.UserId     = BigEndianBitConverter.ToUInt32(data, 10);  // or maybe GroupId (don't care...)
                    rec.GroupId    = BigEndianBitConverter.ToUInt32(data, 14);  // or maybe UserId

                    rec.aTime = unixEpoch.AddSeconds(BigEndianBitConverter.ToUInt32(data, 18));
                    rec.bTime = unixEpoch.AddSeconds(BigEndianBitConverter.ToUInt32(data, 22));
                    rec.cTime = unixEpoch.AddSeconds(BigEndianBitConverter.ToUInt32(data, 26));

                    rec.FileLength = BigEndianBitConverter.ToInt64(data, 30);

                    rec.flag          = data[38];
                    rec.PropertyCount = data[39];

                    rec.Properties = new MBFileRecord.Property[rec.PropertyCount];
                    for (int j = 0; j < rec.PropertyCount; ++j)
                    {
                        rec.Properties[j].Name  = getS(mbdb);
                        rec.Properties[j].Value = getD(mbdb);
                    }

                    StringBuilder fileName = new StringBuilder();
                    byte[]        fb       = hasher.ComputeHash(ASCIIEncoding.UTF8.GetBytes(rec.Domain + "-" + rec.Path));
                    for (int k = 0; k < fb.Length; k++)
                    {
                        fileName.Append(fb[k].ToString("x2"));
                    }

                    rec.key = fileName.ToString();

                    files.Add(rec);
                }

                return(files);
            }
            catch (Exception e)
            {
                Console.WriteLine("exception: {0}", e.Message);
            }

            return(null);
        }