Example #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject jsonRecord = JObject.Load(reader);

            if (jsonRecord.ContainsKey("tx")) // 1P4 for MS-Windows
            {
                this.convertWinToMac(jsonRecord);
            }

            string     recordType = (string)jsonRecord.GetValue("typeName");
            BaseRecord record     = null;

            if (!string.IsNullOrEmpty(recordType) && classTypesByItemType.ContainsKey(recordType))
            {
                record = Activator.CreateInstance(classTypesByItemType[recordType]) as BaseRecord;
            }
            else
            {
                record = new UnknownRecord();
            }

            serializer.Populate(jsonRecord.CreateReader(), record);

            return(record);
        }
Example #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject jsonRecord = JObject.Load(reader);
            string  recordType = (string)jsonRecord.GetValue("category");

            ItemRecord record = null;

            if (!string.IsNullOrEmpty(recordType) && classTypesByItemType.ContainsKey(recordType))
            {
                record = Activator.CreateInstance(classTypesByItemType[recordType]) as ItemRecord;
            }
            else
            {
                record = new UnknownRecord();
            }

            KeyPair itemKeyPair = jsonRecord.GetValue("k").ToObject <KeyPair>(serializer);

            if (itemKeyPair == null)
            {
                return(null);
            }

            foreach (JsonConverter converter in serializer.Converters)
            {
                if (converter is DetailsOPDataConverter)
                {
                    (converter as DetailsOPDataConverter).KeyPair = itemKeyPair;
                }
            }

            serializer.Populate(jsonRecord.CreateReader(), record);

            return(record);
        }
Example #3
0
 protected void WaitForInstructions()
 {
     while (this.Connection != null)
     {
         foreach (var record in UnknownRecord.FromStream(this.Stream, this.Crypter))
         {
             if (record is ClientHelloRecord)
             {
                 var helloFromClient = record as ClientHelloRecord;
             }
         }
     }
 }
Example #4
0
        public RecordTreeNode(Record record)
        {
            if (record is ObjRecord)
            {
                ObjRecord or      = (ObjRecord)record;
                IList     subrecs = or.SubRecords;
                foreach (SubRecord sr in subrecs)
                {
                    this.Nodes.Add(new SubRecordTreeNode(sr));
                }
                this.ImageKey         = "Folder";
                this.SelectedImageKey = "Folder";
            }
            else if (record is SSTRecord)
            {
                IEnumerator strings = ((SSTRecord)record).GetStrings();

                this.ImageKey         = "Folder";
                this.SelectedImageKey = "Folder";

                while (strings.MoveNext())
                {
                    this.Nodes.Add(new UnicodeStringTreeNode((UnicodeString)strings.Current));
                }
            }
            else if (record is DrawingGroupRecord)
            {
                this.ImageKey         = "Folder";
                this.SelectedImageKey = "Folder";

                DrawingGroupRecord dgr = (DrawingGroupRecord)record;

                for (int i = 0; i < dgr.EscherRecords.Count; i++)
                {
                    this.Nodes.Add(new EscherRecordTreeNode((NPOI.DDF.EscherRecord)dgr.EscherRecords[i]));
                }
            }
            else
            {
                this.ImageKey = "Binary";
            }
            if (record is UnknownRecord)
            {
                this.Text = UnknownRecord.GetBiffName(record.Sid) + "*";
            }
            else
            {
                this.Text = record.GetType().Name;
            }
            this.Record = record;
        }
Example #5
0
        private IList TestData()
        {
            IList           records         = new ArrayList();
            FormulaRecord   formulaRecord   = new FormulaRecord();
            UnknownRecord   unknownRecord   = new UnknownRecord();
            BlankRecord     blankRecord     = new BlankRecord();
            WindowOneRecord windowOneRecord = new WindowOneRecord();

            formulaRecord.Row    = 1;
            formulaRecord.Column = 1;
            blankRecord.Row      = 2;
            blankRecord.Column   = 2;
            records.Add(formulaRecord);
            records.Add(blankRecord);
            records.Add(windowOneRecord);
            return(records);
        }
Example #6
0
        public static Record CreateSubRecord(RecordInputStream in1)
        {
            Record r = null;

            /* This must surely be an earlier hack?? Delete when confident
            short adjustedSize = size;
            if ( size < 0 )
            {
                adjustedSize = 0;
            }
            else if ( offset + size > data.Length )
            {
                adjustedSize = (short) ( data.Length - offset );
                if ( adjustedSize > 4 )
                {
                    adjustedSize -= 4;
                }
            }
    */
            switch (in1.Sid)
            {
                case CommonObjectDataSubRecord.sid:
                    r = new CommonObjectDataSubRecord(in1);
                    break;
                case EmbeddedObjectRefSubRecord.sid:
                    r = new EmbeddedObjectRefSubRecord(in1);
                    break;
                case GroupMarkerSubRecord.sid:
                    r = new GroupMarkerSubRecord(in1);
                    break;
                case EndSubRecord.sid:
                    r = new EndSubRecord(in1);
                    break;
                case NoteStructureSubRecord.sid:
                    r = new NoteStructureSubRecord(in1);
                    break;
                default:
                    r = new UnknownRecord(in1);
                    break;
            }
            return r;
        }
Example #7
0
        /// <summary>
        /// Sends a &quot;hello&quot; to the server.
        /// </summary>
        public void SayHello()
        {
            lock (this._SYNC)
            {
                try
                {
                    var helloServer = new ClientHelloRecord(this.Crypter);
                    helloServer.SendTo(this.Connection);

                    foreach (var record in UnknownRecord.FromStream(this.Stream, this.Crypter))
                    {
                        if (record != null)
                        {
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.RaiseError(ex, true);
                }
            }
        }
        public DnsResourceRecord GetRecord(ResourceRecordInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            var oldIndex = _reader.Index;
            DnsResourceRecord result;

            switch (info.RecordType)
            {
            case ResourceRecordType.A:
                result = new ARecord(info, _reader.ReadIPAddress());
                break;

            case ResourceRecordType.NS:
                result = new NsRecord(info, _reader.ReadDnsName());
                break;

            case ResourceRecordType.CNAME:
                result = new CNameRecord(info, _reader.ReadDnsName());
                break;

            case ResourceRecordType.SOA:
                result = ResolveSoaRecord(info);
                break;

            case ResourceRecordType.MB:
                result = new MbRecord(info, _reader.ReadDnsName());
                break;

            case ResourceRecordType.MG:
                result = new MgRecord(info, _reader.ReadDnsName());
                break;

            case ResourceRecordType.MR:
                result = new MrRecord(info, _reader.ReadDnsName());
                break;

            case ResourceRecordType.NULL:
                result = new NullRecord(info, _reader.ReadBytes(info.RawDataLength).ToArray());
                break;

            case ResourceRecordType.WKS:
                result = ResolveWksRecord(info);
                break;

            case ResourceRecordType.PTR:
                result = new PtrRecord(info, _reader.ReadDnsName());
                break;

            case ResourceRecordType.HINFO:
                result = new HInfoRecord(info, _reader.ReadStringWithLengthPrefix(), _reader.ReadStringWithLengthPrefix());
                break;

            case ResourceRecordType.MINFO:
                result = new MInfoRecord(info, _reader.ReadDnsName(), _reader.ReadDnsName());
                break;

            case ResourceRecordType.MX:
                result = ResolveMXRecord(info);
                break;

            case ResourceRecordType.TXT:
                result = ResolveTXTRecord(info);
                break;

            case ResourceRecordType.RP:
                result = new RpRecord(info, _reader.ReadDnsName(), _reader.ReadDnsName());
                break;

            case ResourceRecordType.AFSDB:
                result = new AfsDbRecord(info, (AfsType)_reader.ReadUInt16NetworkOrder(), _reader.ReadDnsName());
                break;

            case ResourceRecordType.AAAA:
                result = new AaaaRecord(info, _reader.ReadIPv6Address());
                break;

            case ResourceRecordType.SRV:
                result = ResolveSrvRecord(info);
                break;

            case ResourceRecordType.OPT:
                result = ResolveOptRecord(info);
                break;

            case ResourceRecordType.URI:
                result = ResolveUriRecord(info);
                break;

            case ResourceRecordType.CAA:
                result = ResolveCaaRecord(info);
                break;

            case ResourceRecordType.SSHFP:
                result = ResolveSshfpRecord(info);
                break;

            default:
                result = new UnknownRecord(info, _reader.ReadBytes(info.RawDataLength).ToArray());
                break;
            }

            // sanity check
            _reader.SanitizeResult(oldIndex + info.RawDataLength, info.RawDataLength);

            return(result);
        }
Example #9
0
        internal static Gdr ConvertToGdr(UnknownRecord unknownRecord)
        {
            Gdr gdr = new Gdr();

            using (BinaryReader reader = new BinaryReader(new MemoryStream(unknownRecord.Content), unknownRecord.Endian, true)) {
                ushort   fieldCount = reader.ReadUInt16();
                object[] data       = new object[fieldCount];
                for (int i = 0; i < fieldCount; i++)
                {
                    byte dataTypeCode = reader.ReadByte();
                    switch (dataTypeCode)
                    {
                    case 0:
                        break;

                    case 1:
                        data[i] = reader.ReadByte();
                        break;

                    case 2:
                        data[i] = reader.ReadUInt16();
                        break;

                    case 3:
                        data[i] = reader.ReadUInt32();
                        break;

                    case 4:
                        data[i] = reader.ReadSByte();
                        break;

                    case 5:
                        data[i] = reader.ReadInt16();
                        break;

                    case 6:
                        data[i] = reader.ReadInt32();
                        break;

                    case 7:
                        data[i] = reader.ReadSingle();
                        break;

                    case 8:
                        data[i] = reader.ReadDouble();
                        break;

                    case 10:
                        data[i] = reader.ReadString();
                        break;

                    case 11: {
                        byte   length = reader.ReadByte();
                        byte[] bytes  = new byte[length];
                        for (int byteIndex = 0; byteIndex < length; byteIndex++)
                        {
                            bytes[byteIndex] = reader.ReadByte();
                        }
                        data[i] = bytes;
                        break;
                    }

                    case 12: {
                        ushort length = reader.ReadUInt16();
                        length = (ushort)((length / 8) + (((length % 8) > 0)?1:0));
                        byte[] bytes = new byte[length];
                        for (int byteIndex = 0; byteIndex < length; byteIndex++)
                        {
                            bytes[byteIndex] = reader.ReadByte();
                        }
                        data[i] = bytes;
                        break;
                    }

                    case 13: {
                        byte nibble = reader.ReadByte();
                        nibble = (byte)(nibble & 0x0F);
                        break;
                    }

                    default:
                        throw new InvalidOperationException(string.Format(Resources.InvalidGdrDataTypeCode, dataTypeCode));
                    }
                }
                gdr.GenericData = data;
            }
            return(gdr);
        }
Example #10
0
        internal static Plr ConvertToPlr(UnknownRecord unknownRecord)
        {
            Plr plr = new Plr();

            using (BinaryReader reader = new BinaryReader(new MemoryStream(unknownRecord.Content), unknownRecord.Endian, true)) {
                // Group count and list of group indexes are required
                ushort groupCount = reader.ReadUInt16();
                plr.GroupIndexes = reader.ReadUInt16Array(groupCount, true);

                // Latter arrays are optional, and may be truncated
                if (!reader.AtEndOfStream)
                {
                    ushort[] groupModes = reader.ReadUInt16Array(groupCount, false);
                    // Expand a truncated array, filling with missing value
                    if ((groupModes != null) && (groupModes.Length < groupCount))
                    {
                        int i = groupModes.Length;
                        Array.Resize <ushort>(ref groupModes, groupCount);
                        for (; i < groupModes.Length; i++)
                        {
                            groupModes[i] = ushort.MinValue;
                        }
                    }
                    plr.GroupModes = groupModes;
                }
                if (!reader.AtEndOfStream)
                {
                    byte[] groupRadixes = reader.ReadByteArray(groupCount, false);
                    // Expand a truncated array, filling with missing value
                    if ((groupRadixes != null) && (groupRadixes.Length < groupCount))
                    {
                        int i = groupRadixes.Length;
                        Array.Resize <byte>(ref groupRadixes, groupCount);
                        for (; i < groupRadixes.Length; i++)
                        {
                            groupRadixes[i] = byte.MinValue;
                        }
                    }
                    plr.GroupRadixes = groupRadixes;
                }
                if (!reader.AtEndOfStream)
                {
                    string[] programStatesRight = reader.ReadStringArray(groupCount, false);
                    // Expand a truncated array, filling with missing value
                    if ((programStatesRight != null) && (programStatesRight.Length < groupCount))
                    {
                        int i = programStatesRight.Length;
                        Array.Resize <string>(ref programStatesRight, groupCount);
                        for (; i < programStatesRight.Length; i++)
                        {
                            programStatesRight[i] = "";
                        }
                    }
                    plr.ProgramStatesRight = programStatesRight;
                }
                if (!reader.AtEndOfStream)
                {
                    string[] returnStatesRight = reader.ReadStringArray(groupCount, false);
                    // Expand a truncated array, filling with missing value
                    if ((returnStatesRight != null) && (returnStatesRight.Length < groupCount))
                    {
                        int i = returnStatesRight.Length;
                        Array.Resize <string>(ref returnStatesRight, groupCount);
                        for (; i < returnStatesRight.Length; i++)
                        {
                            returnStatesRight[i] = "";
                        }
                    }
                    plr.ReturnStatesRight = returnStatesRight;
                }
                if (!reader.AtEndOfStream)
                {
                    string[] programStatesLeft = reader.ReadStringArray(groupCount, false);
                    // Expand a truncated array, filling with missing value
                    if ((programStatesLeft != null) && (programStatesLeft.Length < groupCount))
                    {
                        int i = programStatesLeft.Length;
                        Array.Resize <string>(ref programStatesLeft, groupCount);
                        for (; i < programStatesLeft.Length; i++)
                        {
                            programStatesLeft[i] = "";
                        }
                    }
                    plr.ProgramStatesLeft = programStatesLeft;
                }
                if (!reader.AtEndOfStream)
                {
                    string[] returnStatesLeft = reader.ReadStringArray(groupCount, false);
                    // Expand a truncated array, filling with missing value
                    if ((returnStatesLeft != null) && (returnStatesLeft.Length < groupCount))
                    {
                        int i = returnStatesLeft.Length;
                        Array.Resize <string>(ref returnStatesLeft, groupCount);
                        for (; i < returnStatesLeft.Length; i++)
                        {
                            returnStatesLeft[i] = "";
                        }
                    }
                    plr.ReturnStatesLeft = returnStatesLeft;
                }
            }
            return(plr);
        }