-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


[ ] Xenoblade Chronicles

, 09 2017 . 17:11 +
image

! , TTEMMA, . Russian Studio Video 7 - .

, Resident Evil Nintendo GameCube Resident Evil Remake Resident Evil Zero, - , , , Xenoblade Chronicles Nintendo Wii , . , ?, , . , ?


Xenoblade Chronicles , - , , Nintendo Wii. JRPG, , , , . , Nintendo Wii, , Super Mario ., , Monolith Soft , Xenoblade Chronicles , ( Resident Evil Remake Resident Evil Zero).

image

, , . , , . .


Wii , .

Nintendo GameCube, Nintendo Wii IBM PowerPC. Big-Endian , ( , Big-Endian , Little-Endian - ).

, Nintendo SDK , . , . Nintendo BRFNA (Binary Revolution Font), .


Xenoblade Chronicles( XC) , BRFNA.

Wii :

  1. BRFNT( )
  2. BRFNA( )

, :

  • BRFNA , (ansi, kanji, european ..)
  • BRFNA , BRFNT .

BRFNA , , . , , 3DS SDK Nintendo. , XC, , . , UTF8.

image

, - . , - , , , . , , c IA4(4 , 4 ) I4(4 , ) , XC .

? ! , . , , , , , , . , , .

.

PKB\PKH


- . , - PKB.

PKB , , . , , , 2048 .

PKB
image

PKH , . PKH U8 static.arc.

STATIC.ARC
image

PKH PKB, , . - , , .. .

, .

PKH 2 : Header Entry, .

public class pkhModuleEntry
    {
        public uint ID;
        public uint unk;
        public ushort sizeFile;
        public uint offsetFile;

        public pkhModuleEntry()
        {
            ID = unk = offsetFile = sizeFile = 0;
        }

    }

public class pkhModule
    {
        uint Magic;
        uint version;
        uint tableOffset;
        uint pkhSize;
        uint countFiles;
        pkhModuleEntry[] entry;
        string[] extensions;
        ...
    }

Entry tableOffset. , entry , :

for (int i = 0; i < countFiles; i++)
            {
                entry[i] = new pkhModuleEntry();
                entry[i].ID = mainPkhSfa.ReadUInt32();
                entry[i].unk = mainPkhSfa.ReadUInt32();
            }

            for (int i = 0; i < countFiles; i++)
                entry[i].sizeFile = mainPkhSfa.ReadUInt16();

            for (int i = 0; i < countFiles; i++)
                entry[i].offsetFile = mainPkhSfa.ReadUInt32();

, 3 :


, uint32, 4- , , -, 2-. , , PKB 2048 . , . , 0xC, PKB 0xC * 0x800 = 0x6000.

PKH
image

\ , .


, . 3 :

  1. BDAT - , (, , ).
  2. SB .
  3. REV , -.

, .
, , . , , .

BDAT , SB , REV , .. .

BDAT


image

, BDAT. , , . , . - , . , , , -, . , , . , . , .

, BDAT , . , . !

, Dolphin ( PCSX, ). , BDAT , , Dolphin , \ . RAM , . Dolphin Dolphin DebugFast 4 , \ RAM, , .

, , BDAT. . BDAT 2 , R5, R0 , , 1(true).

1, R5, 0, R0.

XOR, :

  1. = ^ R(5 0)
  2. R(5 0) = ( + R(5 0)) & 0xFF

C#:

public static void BDAT_DecryptPart(int offset, int size, ushort key, MemoryStream data)
        {
            data.Position = offset;
            int endOffset = offset + size;
            if (endOffset > data.Length)
                endOffset = (int)data.Length;

            bool reg = true;
            byte _r0 = (byte)(0xFF - (key & 0xFF));
            byte _r5 = (byte)(0xFF - (key >> 8 & 0xFF));
            byte inByte = 0;

            while (offset < endOffset)
            {
                inByte = data.GetBuffer()[offset];
                if (reg)
                {
                    data.GetBuffer()[offset] = (byte)(inByte ^ _r5);
                    _r5 = (byte)((_r5 + inByte) & 0xFF);
                    reg = false;
                }
                else
                {
                    data.GetBuffer()[offset] = (byte)(inByte ^ _r0);
                    _r0 = (byte)((_r0 + inByte) & 0xFF);
                    reg = true;
                }
                offset += 1;
            }
        }

, , , ! , , .

, BDAT. , - , - .

0x2C 0x66.

image

, . , , Header 0x20 , .

, , , .

class header
    {
        public uint magic;
        public byte mode;
        public byte unk;
        public ushort offsetToNameBlock;
        public ushort sizeTableStruct;
        public ushort unkTableOffset;
        public ushort unk2;
        public ushort offsetToMainData;
        public ushort countEntryMain;
        public ushort unk3; public ushort unk4;
        public ushort cryptKey;
        public uint offsetToStringBlock;
        public uint sizeStringBlock;
        ...
   }

  • Magic BDAT(ansi)
  • Mode 1: , 3:
  • unk , ,
  • offsetToNameBlock
  • sizeTableStruct
  • unkTableOffset ,
  • unk2 , 0x3D
  • offsetToMainData ,
  • countEntryMain offsetToMainData ( MainData : sizeTableStruct * countEntryMain)
  • unk3 , 0x01
  • unk4 , 0x02
  • cryptKey 2-
  • offsetToStringBlock
  • sizeStringBlock ( 0, )

Header offsetToNameBlock , MainData :

class typeStruct
    {
        public byte unk;
        public byte type;
        public ushort idx;
        ...
    }

  • unk
  • type
  • idx MainData( : offsetToMainData + (IndexStructure * sizeTableStruct) + idx

offsetToNameBlock, :

class nameBlock
    {
        public string bdatName;
        public nameBlockEntry[] nameEntry;

        public nameBlock(StreamFunctionAdd sfa, int countName)
        {
            bdatName = sfa.ReadAnsiStringStopByte();
            sfa.SeekValue(2);

            nameEntry = new nameBlockEntry[countName];

            for (int i = 0; i < countName; i++)
            {
                nameEntry[i] = new nameBlockEntry(sfa);
            }
        }
    }

    class nameBlockEntry
    {
        public ushort offsetToStructType;
        public ushort unk;
        public string name;
        public typeStruct type;

        public nameBlockEntry(StreamFunctionAdd sfa)
        {
            offsetToStructType = sfa.ReadUInt16();
            unk = sfa.ReadUInt16();
            name = sfa.ReadAnsiStringStopByte();

            type = new typeStruct(sfa, offsetToStructType);

            sfa.SeekValue(2);
        }
    }

countName, Header, NameBlock 0x20 4. : Header 0x20, NameBlock Header, , Header MainData, 4 . - , , 4.

, , , :

, MainData. , countEntryMain, sizeTableStruct. typeStruct, 1 . typeStruct , nameBlockEntry.

, BDAT \ , .

BDAT
image


, Wii , , .

, . , , Resident Evil Remake Resident Evil Zero.

!

P.S. , , . - , , .
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/330612/

:  

: [1] []
 

:
: 

: ( )

:

  URL