예제 #1
0
        public Trophy_File Load(byte[] bytes)
        {
            Trophy_File rtn = new Trophy_File();

            try
            {
                this.trophyItemList = new List <TrophyItem>();
                this.Bytes          = bytes;
                using (MemoryStream memoryStream = new MemoryStream(bytes))
                {
                    TrophyHeader hdr = LoadHeader(memoryStream);
                    trphy = hdr;
                    if (!Utils.ByteArraysEqual(hdr.magic, new byte[] { 220, 162, 77, 0 }))
                    {
                        throw new Exception("This file is not supported!");
                    }
                    ReadContent(memoryStream);
                    if (Version > 1)
                    {
                        SHA1 = CalculateSHA1Hash();
                    }
                }
            }
            catch (Exception ex)
            {
            }
            rtn.Bytes          = Bytes;
            rtn.SHA1           = SHA1;
            rtn.trphy          = trphy;
            rtn.trophyItemList = trophyItemList;
            return(rtn);
        }
예제 #2
0
        private TrophyHeader LoadHeader(Stream fs)
        {
            TrophyHeader hdr = default(TrophyHeader);

            hdr.magic        = new byte[4];
            hdr.version      = new byte[4];
            hdr.file_size    = new byte[8];
            hdr.files_count  = new byte[4];
            hdr.element_size = new byte[4];
            hdr.dev_flag     = new byte[4];
            hdr.sha1         = new byte[20];
            hdr.padding      = new byte[36];
            fs.Read(hdr.magic, 0, hdr.magic.Length);
            fs.Read(hdr.version, 0, hdr.version.Length);
            fs.Read(hdr.file_size, 0, hdr.file_size.Length);
            fs.Read(hdr.files_count, 0, hdr.files_count.Length);
            fs.Read(hdr.element_size, 0, hdr.element_size.Length);
            fs.Read(hdr.dev_flag, 0, hdr.dev_flag.Length);
            long num = Utils.byteArrayToLittleEndianInteger(hdr.version);

            if (num <= 3L && num >= 1L)
            {
                switch ((int)(num - 1L))
                {
                case 0:
                    fs.Read(hdr.padding, 0, hdr.padding.Length);
                    break;

                case 1:
                    fs.Read(hdr.sha1, 0, hdr.sha1.Length);
                    hdr.padding = new byte[16];
                    fs.Read(hdr.padding, 0, hdr.padding.Length);
                    break;

                case 2:
                    fs.Read(hdr.sha1, 0, hdr.sha1.Length);
                    hdr.padding = new byte[48];
                    fs.Read(hdr.padding, 0, hdr.padding.Length);
                    break;
                }
            }
            return(hdr);
        }
예제 #3
0
 /// <summary>
 /// Method Will Create a Trohy File From a File Path
 /// </summary>
 /// <param name="FilePath">File Location on disk</param>
 public Trophy_File(string FilePath)
 {
     this.SHA1           = "";
     this.trophyItemList = new List <TrophyItem>();
     using (FileStream fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         fileStream.Read(Bytes, 0, checked ((int)fileStream.Length));
         fileStream.Seek(0L, SeekOrigin.Begin);
         TrophyHeader hdr = LoadHeader(fileStream);
         trphy = hdr;
         if (Utils.ByteArraysEqual(hdr.magic, new byte[] { 220, 162, 77, 0 }))
         {
             throw new Exception("This file is not supported!");
         }
         ReadContent(fileStream);
         if (Version > 1)
         {
             SHA1 = CalculateSHA1Hash();
         }
     }
     //MessageBox.Show(this._error, "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
 }