Ejemplo n.º 1
0
        public int GetGuide()
        {
            int      count;
            DateTime time       = new DateTime(0x7b2, 1, 1, 0, 0, 0, 0);
            string   requestUri = string.Format("http://{0}/http_replay_guide-get_snapshot?guide_file_name=0&serial_no=RTV4080K0000000000", this.theDevice.ip, (long)(((ulong)(DateTime.UtcNow.Ticks - time.Ticks)) / 0x989680));

            try
            {
                byte[] haystack = HTTPClient.Get(requestUri);
                int    offset   = ReplayHelper.FindInByteArray(haystack, this.encoding.GetBytes("#####ATTACHED_FILE_START#####")) + 0x1d;
                count = ReplayHelper.FindInByteArray(haystack, this.encoding.GetBytes("#####ATTACHED_FILE_END#####")) - offset;
                try
                {
                    if (count > 0)
                    {
                        FileStream stream = File.Create(this.guideFile);
                        stream.Write(haystack, offset, count);
                        stream.Close();
                    }
                }
                catch (Exception)
                {
                    ReplayLogger.DebugLog(string.Concat(new object[] { "Unable to create guide file: ", this.guideFile, " of ", count, " bytes." }));
                }
            }
            catch (Exception)
            {
                ReplayLogger.DebugLog(string.Format("Unable to contact ReplayTV {0} at {1}", this.theDevice.friendlyName, this.theDevice.ip));
                throw new ApplicationException(string.Format("Unable to contact ReplayTV {0} at {1}", this.theDevice.friendlyName, this.theDevice.ip));
            }
            return(count);
        }
Ejemplo n.º 2
0
        public ReplayGuide(ReplayDevice rd)
        {
            this.theDevice    = rd;
            this.guideFile    = ReplayHelper.MakePathAndFile(this.theDevice.serialNumber + ".guide");
            this.guideXMLFile = ReplayHelper.MakePathAndFile(this.theDevice.serialNumber + ".xml");
            OperatingSystem oSVersion = Environment.OSVersion;

            if (((oSVersion.Platform == PlatformID.Win32NT) || (oSVersion.Platform == PlatformID.Win32S)) || (oSVersion.Platform == PlatformID.Win32Windows))
            {
                ReplayLogger.DebugLog("Using Default Encoding for Windows - " + oSVersion.Platform);
                this.encoding = Encoding.Default;
            }
            else
            {
                ReplayLogger.DebugLog("Request iso-8859-1 Encoding for " + oSVersion.Platform);
                this.encoding = Encoding.GetEncoding("iso-8859-1");
            }
        }
Ejemplo n.º 3
0
        private static byte[] RTVDecrypt(byte[] cryptoText, byte[] extraData)
        {
            MD5 md = new MD5CryptoServiceProvider();

            byte[] destinationArray = new byte[0x10];
            byte[] buffer2          = new byte[4];
            uint   key = 0;

            byte[] buffer3 = new byte[4];
            byte[] buffer4 = new byte[4];
            byte[] buffer5 = new byte[(cryptoText.Length - 0x18) + extraData.Length];
            byte[] buffer6 = new byte[4];
            Array.Copy(cryptoText, 8, destinationArray, 0, 0x10);
            if (BitConverter.IsLittleEndian)
            {
                buffer2[0] = cryptoText[7];
                buffer2[1] = cryptoText[1];
                buffer2[2] = cryptoText[4];
                buffer2[3] = cryptoText[2];
            }
            else
            {
                buffer2[0] = cryptoText[2];
                buffer2[1] = cryptoText[4];
                buffer2[2] = cryptoText[1];
                buffer2[3] = cryptoText[7];
            }
            key        = BitConverter.ToUInt32(buffer2, 0) ^ 0xcb0baf47;
            buffer4[0] = cryptoText[6];
            buffer4[1] = cryptoText[5];
            buffer4[2] = cryptoText[3];
            buffer4[3] = cryptoText[0];
            Array.Copy(cryptoText, 0x18, buffer5, 0, cryptoText.Length - 0x18);
            Array.Copy(extraData, 0, buffer5, cryptoText.Length - 0x18, extraData.Length);
            byte[] byteArray = md.ComputeHash(buffer5);
            if (!ReplayHelper.ByteArrayToHexString(byteArray).Equals(ReplayHelper.ByteArrayToHexString(destinationArray)))
            {
                object[] args = new object[] { ReplayHelper.ByteArrayToHexString(byteArray), ReplayHelper.ByteArrayToHexString(destinationArray) };
                ReplayLogger.DebugLog("Bad checksum (Computed: {0}) (Expected: {1})", args);
                return(null);
            }
            ReplayCryptBlock(ref cryptoText, key, cryptoText.Length - 0x18, 0x18);
            Array.Copy(cryptoText, 0x18, buffer3, 0, 4);
            uint num2 = !BitConverter.IsLittleEndian ? 0x42ffdfa9 : 0xa9dfff42;

            if (BitConverter.ToUInt32(buffer3, 0) != num2)
            {
                object[] objArray2 = new object[] { ReplayHelper.ByteArrayToHexString(buffer3), BitConverter.ToInt32(buffer3, 0), 0x42ffdfa9 };
                ReplayLogger.DebugLog("Bad sanity number in decrypted data ({1} != {2}) {0}", objArray2);
                return(null);
            }
            Array.Copy(cryptoText, 0x1c, buffer6, 0, 4);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(buffer6);
            }
            int num3 = (int)(((ulong)(DateTime.UtcNow.Ticks - UTCBase.Ticks)) / 0x989680);

            timeOffset = ((int)BitConverter.ToUInt32(buffer6, 0)) - num3;
            byte[] buffer8 = new byte[cryptoText.Length - 0x20];
            Array.Copy(cryptoText, 0x20, buffer8, 0, cryptoText.Length - 0x20);
            return(buffer8);
        }
Ejemplo n.º 4
0
        private int Save5000GuideAsXML(bool shareReceived, bool showHDTV)
        {
            XmlTextWriter writer = new XmlTextWriter(this.guideXMLFile, Encoding.UTF8);

            writer.Formatting = Formatting.Indented;
            writer.WriteStartElement("result");
            int[]      numArray = new int[] { 0, 0 };
            FileStream stream   = File.OpenRead(this.guideFile);

            byte[] array = new byte[(int)stream.Length];
            stream.Read(array, 0, (int)stream.Length);
            stream.Close();
            bool       flag         = true;
            SortedList categoryList = new SortedList();

            categoryList = this.Build5000Categories(array);
            writer.WriteStartElement("category-list");
            for (int i = 0; i < categoryList.Count; i++)
            {
                writer.WriteStartElement("category");
                writer.WriteAttributeString("categoryID", null, categoryList.GetKey(i).ToString());
                writer.WriteAttributeString("categoryName", null, categoryList.GetByIndex(i).ToString());
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            SortedList list2 = new SortedList();

            list2 = this.Build5000Channels(array, categoryList);
            writer.WriteStartElement("channel-list");
            try
            {
                int    num2             = 0;
                int    length           = array.Length;
                int    num4             = length - (840 + (0x2c8 * ReplayHelper.ReplayByteToInt(array, 0x10, 4)));
                byte[] destinationArray = new byte[num4];
                byte[] buffer3          = new byte[0x200];
                Array.Copy(array, 840 + (0x2c8 * ReplayHelper.ReplayByteToInt(array, 0x10, 4)), destinationArray, 0, num4);
                byte[] buffer4 = null;
                byte[] buffer5 = null;
                byte[] buffer6 = null;
                for (int j = 0; (num4 - (0x200 * j)) >= 0x200; j++)
                {
                    string text5;
                    Array.Copy(destinationArray, 0x200 * j, buffer3, 0, 0x200);
                    DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0, 0);
                    long     num6 = ReplayHelper.ReplayByteToLong(buffer3, 120, 4);
                    int      num7 = 0;
                    if ((num6 & 0x40) > 0)
                    {
                        num7 += 4;
                    }
                    if ((num6 & 0x20) > 0)
                    {
                        num7 += 8;
                    }
                    int num8 = ReplayHelper.ReplayByteToInt(buffer3, 0, 4);
                    int num9 = ReplayHelper.ReplayByteToInt(buffer3, 4, 4);
                    buffer4 = new byte[ReplayHelper.ReplayByteToInt(buffer3, 140, 1) - 1];
                    buffer5 = new byte[ReplayHelper.ReplayByteToInt(buffer3, 0x8d, 1) - 1];
                    buffer6 = new byte[ReplayHelper.ReplayByteToInt(buffer3, 0x8e, 1) - 1];
                    int    qualityCode = ReplayHelper.ReplayByteToInt(buffer3, 12, 4);
                    string quality     = this.GetQuality(qualityCode);
                    int    num11       = ReplayHelper.ReplayByteToInt(buffer3, 0x188, 4);
                    int    num12       = num11 / 60;
                    if ((num11 % 60) >= 30)
                    {
                        num12++;
                    }
                    string text2 = num12.ToString();
                    int    num13 = ReplayHelper.ReplayByteToInt(buffer3, 0x7c, 4);
                    int    num14 = ReplayHelper.ReplayByteToInt(buffer3, 380, 4);
                    int    num15 = ReplayHelper.ReplayByteToInt(buffer3, 0x184, 4);
                    string text3 = time.AddSeconds((double)num13).ToString("yyyy-MM-dd HH:mm:ss.000", DateTimeFormatInfo.InvariantInfo);
                    Array.Copy(buffer3, 0x94 + num7, buffer4, 0, buffer4.Length);
                    Array.Copy(buffer3, ((0x94 + num7) + buffer4.Length) + 1, buffer5, 0, buffer5.Length);
                    Array.Copy(buffer3, ((((0x94 + num7) + buffer4.Length) + 1) + buffer5.Length) + 1, buffer6, 0, buffer6.Length);
                    ReplayChannelGuide guide        = (ReplayChannelGuide)list2[num8];
                    string             channelTitle = guide.channelTitle;
                    switch (guide.channelType)
                    {
                    case 1:
                        text5 = "Recurring";
                        break;

                    case 2:
                        text5 = "Theme";
                        break;

                    case 3:
                        text5 = "Single";
                        break;

                    case 4:
                        text5 = "Zone";
                        break;

                    default:
                        text5 = "";
                        break;
                    }
                    int    channelCategory = guide.channelCategory;
                    string channelCatName  = guide.channelCatName;
                    string text7           = ReplayHelper.ReplaceUTF8InString(this.encoding.GetString(buffer4));
                    string text8           = ReplayHelper.ReplaceUTF8InString(this.encoding.GetString(buffer6));
                    string text9           = ReplayHelper.ReplaceUTF8InString(this.encoding.GetString(buffer5));
                    if (shareReceived || ((num14 == 0) && (num15 < 15)))
                    {
                        if (num8 != num2)
                        {
                            if (flag)
                            {
                                flag = false;
                            }
                            else
                            {
                                writer.WriteEndElement();
                            }
                            writer.WriteStartElement("channel");
                            writer.WriteAttributeString("title", null, channelTitle);
                            writer.WriteAttributeString("channelID", null, num8.ToString());
                            writer.WriteAttributeString("channelType", null, text5);
                            writer.WriteAttributeString("categoryID", null, channelCategory.ToString());
                            writer.WriteAttributeString("categoryName", null, channelCatName);
                            guide.channelDone = true;
                        }
                        writer.WriteStartElement("show");
                        if (shareReceived && (num14 != 0))
                        {
                            writer.WriteAttributeString("title", null, text7);
                        }
                        else if (text5.Equals("Single") || text5.Equals("Recurring"))
                        {
                            writer.WriteAttributeString("title", null, channelTitle);
                        }
                        else
                        {
                            writer.WriteAttributeString("title", null, text7);
                        }
                        writer.WriteAttributeString("description", null, text8);
                        if (!showHDTV && text9.StartsWith("(HDTV) "))
                        {
                            text9 = text9.Remove(0, 7);
                        }
                        if (text9.Equals(""))
                        {
                            if (text8.Equals(""))
                            {
                                writer.WriteAttributeString("episodeTitle", null, text7);
                            }
                            else
                            {
                                if (text8.Length > 0x23)
                                {
                                    text8 = text8.Substring(0, 0x20);
                                    if (text8.LastIndexOf(" ") >= 0)
                                    {
                                        text8 = text8.Substring(0, text8.LastIndexOf(" ")) + "...";
                                    }
                                }
                                writer.WriteAttributeString("episodeTitle", null, text8);
                            }
                        }
                        else
                        {
                            writer.WriteAttributeString("episodeTitle", null, text9);
                        }
                        writer.WriteAttributeString("startTimeGMT", null, text3);
                        writer.WriteAttributeString("durationInMinutes", null, text2);
                        writer.WriteAttributeString("quality", null, quality);
                        writer.WriteAttributeString("showID", null, num9.ToString());
                        writer.WriteEndElement();
                    }
                    num2 = num8;
                }
                if (!flag)
                {
                    writer.WriteEndElement();
                }
                IList keyList = list2.GetKeyList();
                for (int k = 0; k < list2.Count; k++)
                {
                    string             text11;
                    ReplayChannelGuide guide2 = (ReplayChannelGuide)list2[keyList[k]];
                    string             text10 = guide2.channelTitle;
                    switch (guide2.channelType)
                    {
                    case 1:
                        text11 = "Recurring";
                        break;

                    case 2:
                        text11 = "Theme";
                        break;

                    case 3:
                        text11 = "Single";
                        break;

                    case 4:
                        text11 = "Zone";
                        break;

                    default:
                        text11 = "";
                        break;
                    }
                    int    num18  = guide2.channelCategory;
                    string text12 = guide2.channelCatName;
                    if (!guide2.channelDone)
                    {
                        writer.WriteStartElement("channel");
                        writer.WriteAttributeString("title", null, text10);
                        writer.WriteAttributeString("channelID", null, keyList[k].ToString());
                        writer.WriteAttributeString("channelType", null, text11);
                        writer.WriteAttributeString("categoryID", null, num18.ToString());
                        writer.WriteAttributeString("categoryName", null, text12);
                        writer.WriteEndElement();
                    }
                }
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            catch (Exception exception)
            {
                ReplayLogger.Log("Save5000GuideAsXML Exception" + exception.ToString());
                if (!flag)
                {
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.Flush();
                writer.Close();
                return(-1);
            }
            writer.Flush();
            writer.Close();
            return(1);
        }
Ejemplo n.º 5
0
        private void LogSend(string showID)
        {
            this.recipientDevice.ivsNickname = "n/a";
            try
            {
                string xml = null;
                xml = HTTPClient.GetAsString("http://" + this.recipientDevice.ip + ":" + this.recipientDevice.port + "/ivs-IVSGetUnitInfo");
                XmlDocument document = new XmlDocument();
                document.LoadXml(xml);
                foreach (XmlNode node in document.SelectNodes("/UnitInfo"))
                {
                    XmlElement element = node as XmlElement;
                    if (element != null)
                    {
                        this.recipientDevice.ivsNickname = element.GetAttribute("nickname");
                    }
                }
            }
            catch
            {
                ReplayLogger.Log("Send logging: Unable to query remote replay for ivsNickname");
            }
            string      text2     = "n/a";
            string      text3     = "n/a";
            string      text4     = "n/a";
            XmlDocument document2 = new XmlDocument();
            string      path      = ReplayHelper.MakePathAndFile(this.theDevice.serialNumber + ".xml");

            if (System.IO.File.Exists(path))
            {
                document2.Load(path);
                XmlElement element2 = document2.SelectSingleNode(string.Format("/result/channel-list/channel/show[@showID=\"{0}\"]", showID)) as XmlElement;
                if (element2 != null)
                {
                    text2 = element2.GetAttribute("title");
                    text3 = element2.GetAttribute("episodeTitle");
                    text4 = element2.GetAttribute("startTimeGMT");
                }
                else
                {
                    ReplayLogger.Log("showID not found in guide xml file: " + showID);
                }
            }
            else
            {
                ReplayLogger.Log("guide xml file not found.");
            }
            string      filename  = ReplayHelper.MakePathAndFile("sendlog.xml");
            XmlDocument document3 = new XmlDocument();

            try
            {
                document3.Load(filename);
            }
            catch (FileNotFoundException)
            {
                XmlTextWriter writer = new XmlTextWriter(filename, Encoding.UTF8);
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteStartElement("sendlog");
                writer.Close();
                document3.Load(filename);
            }
            try
            {
                XmlElement   newChild = document3.CreateElement("send");
                XmlAttribute newAttr  = document3.CreateAttribute("show");
                newAttr.Value = text2;
                XmlAttribute attribute2 = document3.CreateAttribute("episode");
                attribute2.Value = text3;
                XmlAttribute attribute3 = document3.CreateAttribute("showdate");
                attribute3.Value = text4;
                XmlAttribute attribute4 = document3.CreateAttribute("isn");
                attribute4.Value = this.recipientDevice.isn;
                XmlAttribute attribute5 = document3.CreateAttribute("ivsname");
                attribute5.Value = this.recipientDevice.ivsNickname;
                XmlAttribute attribute6 = document3.CreateAttribute("senddate");
                attribute6.Value = DateTime.Now.ToString();
                XmlAttribute attribute7 = document3.CreateAttribute("unit");
                attribute7.Value = this.theDevice.friendlyName;
                newChild.SetAttributeNode(newAttr);
                newChild.SetAttributeNode(attribute2);
                newChild.SetAttributeNode(attribute3);
                newChild.SetAttributeNode(attribute4);
                newChild.SetAttributeNode(attribute5);
                newChild.SetAttributeNode(attribute6);
                newChild.SetAttributeNode(attribute7);
                document3.DocumentElement.InsertBefore(newChild, document3.DocumentElement.FirstChild);
                document3.Save(filename);
            }
            catch (Exception exception)
            {
                ReplayLogger.Log("Send Log write exception: " + exception.ToString());
            }
        }