示例#1
0
        int DumpSFBX(string fn)
        {
            int sfbxaddr = 0, sfbxsize;

            for (int i = 0; i < SFBX_START.Length; i++)
            {
                byte[] sfbx_magic = ReadFile(fn, SFBX_START[i], SFBX_MAGIC.Length);
                if (CheckMagic(sfbx_magic, SFBX_MAGIC_START, SFBX_MAGIC))
                {
                    sfbxaddr = SFBX_START[i];
                    break;
                }
                if (i == SFBX_START.Length - 1)
                {
                    Console.WriteLine("SFBX data wasn't found. Scanning for it!");
                    sfbxaddr = ScanForSFBX(fn);
                    break;
                }
            }
            sfbxsize = GetSizeSFBX(fn, sfbxaddr);
            sfbxaddr = sfbxaddr + SFBX_ENTS_START; // Don't want the header

            if (sfbxsize == 0)
            {
                Console.WriteLine("Size of SFBX wasn't found in Adresstable");
                return(0);
            }

            int sfbx_ents_size   = sfbxsize - SFBX_BLOB_SIZE - SFBX_ENTS_START;
            int sfbx_ents_maxcnt = sfbx_ents_size / SFBX_EN_SIZE;
            int j = 0;

            //Read adresses in array
            for (; j < sfbx_ents_maxcnt; j++)
            {
                int    total_pos = sfbxaddr + j * SFBX_EN_SIZE;
                byte[] entry     = ReadFile(fn, total_pos, SFBX_EN_SIZE);

                int lba = ReadUInt32_LE(entry, SFBX_EN_LBA_START);
                int sz  = ReadUInt32_LE(entry, SFBX_EN_SZ_START);

                int fileaddr = lba * LOG_BLOCK_SZ;

                // msft-xvd magic doesnt start at 0x0!
                byte[] xvd = ReadFile(fn, fileaddr + XVD_MAGIC_START, XVD_MAGIC.Length);
                byte[] magic;
                if (Oper.ByteArrayCompare(xvd, XVD_MAGIC))
                {
                    magic = Oper.StringToByteArray_v3("XVD");
                }
                else
                {
                    magic = ReadFile(fn, fileaddr, MAGIC_SIZE);
                }

                SFBX s = new SFBX(total_pos, lba, sz, magic);
                sfbx_arr.Add(s);
            }
            return(j - 1);
        }