예제 #1
0
        public static Dictionary <string, MSBT> Extract(byte[] bytes)
        {
            var pos        = 12;
            var dataOffset = BitConverter.ToUInt32(bytes, pos);

            pos += 14;
            var nodeCount = BitConverter.ToUInt16(bytes, pos);

            pos += 6;

            var nodes = new uint[nodeCount][];

            for (var i = 0; i < nodeCount; i++)
            {
                nodes[i]    = new uint[2];
                nodes[i][0] = BitConverter.ToUInt32(bytes, pos + 8);
                nodes[i][1] = BitConverter.ToUInt32(bytes, pos + 12);

                pos += 16;
            }

            pos += 8;

            var fileNames = new string[nodeCount];

            for (var i = 0; i < nodeCount; i++)
            {
                var tempName = "";
                while (bytes[pos] != 0)
                {
                    tempName += ((char)bytes[pos]).ToString();
                    pos      += 1;
                }

                while (bytes[pos] == 0)
                {
                    pos += 1;
                }

                fileNames[i] = tempName;
            }

            var dicOut = new Dictionary <string, MSBT>();

            for (var i = 0; i < nodeCount; i++)
            {
                var dataArray = new byte[(int)(nodes[i][1] - nodes[i][0])];
                Array.Copy(bytes, (int)(nodes[i][0] + dataOffset), dataArray, 0, (int)(nodes[i][1] - nodes[i][0]));
                // Console.WriteLine(fileNames[i]);
                dicOut.Add(fileNames[i], MSBT.Open(dataArray));
            }

            return(dicOut);
        }
예제 #2
0
        public static MSBT Open(byte[] bytes)
        {
            var id = Encoding.UTF8.GetString(bytes, 0, 8);

            if (id != "MsgStdBn")
            {
                throw new InvalidDataException("File is not MSBT format");
            }

            var labels = new LBL(bytes);

            var lblPad = 16 - labels.Length % 16;

            if (lblPad == 16)
            {
                lblPad = 0;
            }

            var atrOffset = (int)(labels.Length + 32 + 16 + lblPad);

            var atrLength = BitConverter.ToUInt32(bytes, atrOffset + 4);
            var artPad    = 16 - atrLength % 16;

            if (artPad == 16)
            {
                artPad = 0;
            }

            var txtOffset = (int)(atrOffset + atrLength + 16 + artPad);

            var text = new TXT(bytes, txtOffset);

            var msbt = new MSBT()
            {
                LBLData = labels, TXTData = text
            };
            var sort = new Dictionary <string, string>();

            for (var i = 0; i < labels.Labels.Length; i++)
            {
                sort.Add(labels.Labels[i].Name, text.Texts[i].Value);
            }

            msbt.Sorted = sort.OrderBy(k => k.Key).ToArray();

            return(msbt);
        }