Esempio n. 1
0
        private Prl[] ExpandPrm(Prm prm, Clx clx)
        {
            if (prm.fComplex)
            {
                int index = prm.igrpprl;
                return clx.RgPrc[index].GrpPrl;
            }
            else if (prm.prm != 0x0000)
            {
                ushort sprm;
                if (!SinglePropertyModifiers.prm0Map.TryGetValue(prm.isprm, out sprm))
                    throw new WordFileReaderException("Invalid Prm: isprm");
                byte value = prm.val;

                Prl prl = new Prl();
                prl.sprm = new Sprm(sprm);
                prl.operand = new byte[] { value };
                return new Prl[] { prl };
            }
            else
                return new Prl[0];
        }
        private static Prl ReadPrl(Stream s, int length, out int read)
        {
            if (length < 2) throw new WordFileReaderException("Invalid Prl: length");

            read = 0;
            Prl prl = new Prl();
            prl.sprm = ReadSprm(s, ref read);

            int operandLength = GetLengthFromSprm(prl.sprm);
            if (operandLength < 0)
            {
                if (prl.sprm.sprm == SinglePropertyModifiers.sprmPChgTabs)
                {
                    if (read + ReadUtils.ByteSize > length) throw new WordFileReaderException("Invalid Prl: operand length (1)");
                    operandLength = ReadUtils.ReadByte(s, ref read);
                    if (operandLength == 255)
                    {
                        if (read + ReadUtils.ByteSize > length) throw new WordFileReaderException("Invalid Prl: operand length (2)");
                        operandLength = ReadUtils.ReadByte(s, ref read);

                        MemoryStream ms = new MemoryStream();
                        byte cTabs = ReadUtils.ReadByte(s);
                        ms.WriteByte(cTabs);
                        int delPortionSize = 1 + cTabs * 4;
                        if (read + delPortionSize > length) throw new WordFileReaderException("Invalid Prl: operand length (3)");
                        byte[] data = ReadUtils.ReadExact(s, cTabs * 4);
                        ms.Write(data, 0, data.Length);
                        if (read + 1 + delPortionSize > length) throw new WordFileReaderException("Invalid Prl: operand length (4)");
                        cTabs = ReadUtils.ReadByte(s);
                        ms.WriteByte(cTabs);

                        int addPortionSize = 1 + cTabs * 3;
                        if (read + delPortionSize + addPortionSize > length) throw new WordFileReaderException("Invalid Prl: operand length (5)");
                        data = ReadUtils.ReadExact(s, cTabs * 3);
                        ms.Write(data, 0, data.Length);
                        ms.Close();

                        data = ms.ToArray();
                        operandLength = data.Length;

                        prl.operand = data;
                        read += operandLength;
                        return prl;
                    }
                }
                else if (prl.sprm.sprm == SinglePropertyModifiers.sprmTDefTable)
                {
                    if (read + ReadUtils.WordSize > length) throw new WordFileReaderException("Invalid Prl: operand length (6)");
                    operandLength = BitConverter.ToUInt16(ReadUtils.ReadExact(s, ReadUtils.WordSize, ref read), 0) + 1;
                }
                else
                {
                    if (read + ReadUtils.ByteSize > length) throw new WordFileReaderException("Invalid Prl: operand length (0)");
                    operandLength = ReadUtils.ReadByte(s, ref read);
                }
            }
            if (read + operandLength > length) throw new WordFileReaderException("Invalid Prl: operand length");
            prl.operand = ReadUtils.ReadExact(s, operandLength, ref read);
            return prl;
        }