public long GetFileSize(string file) { string text2 = ReplayHelper.ByteArrayToHexString(ReplayCrypt.HTTPFSEncrypt("name=" + file)).ToLower(); byte[] bytes = HTTPClient.Get(string.Format("http://{0}/httpfs-fstat?__Q_={1}", this.theDevice.ip, text2), httpfsHeaders); if (bytes == null) { throw new ApplicationException(string.Format("Send failed! No response from {0} ReplayTV. Is it connected to the network?", this.theDevice.friendlyName)); } if (bytes.GetLength(0) == 0) { throw new ApplicationException("Send failed! Show size -1MB error caught. Unable to determine a valid clock offset. Check your computer's clock."); } string text4 = Encoding.Default.GetString(bytes); char[] separator = new char[] { '\n' }; string[] textArray = text4.Split(separator); if (text4.StartsWith("80820005")) { throw new ApplicationException(string.Format("Send failed! Show not found on {0} ReplayTV. Refresh your listings.", this.theDevice.friendlyName)); } long num = -1; string[] textArray2 = textArray; int length = textArray2.Length; for (int i = 0; i < length; i++) { string text5 = textArray2[i]; if (text5.StartsWith("size=")) { num = Convert.ToInt64(text5.Substring(5).Trim()); } } if (num == -1) { throw new ApplicationException("Send failed! Show size -1MB error caught. Check your computer's clock."); } return(num); }
public ReplayDevice RDDNSLookup(string isn, bool final, string rddnsip) { string requestUri; string text2 = ReplayHelper.ByteArrayToHexString(ReplayCrypt.RDDNSEncrypt("isn=" + isn)).ToLower(); if (rddnsip.Length > 0) { requestUri = string.Format("http://{0}/rd/servlet/gu?q={1}", rddnsip, text2); } else { requestUri = string.Format("http://{0}/rd/servlet/gu?q={1}", rddnsServer, text2); } byte[] responseContent = HTTPClient.Get(requestUri); ReplayDevice device = this.ParseRDDNSResponse(responseContent); if ((!final && this.erRespType.Equals("SERVER")) && this.erRespId.Equals("-1")) { device = this.RDDNSLookup(isn, true, rddnsip); } return(device); }
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); }
public int IVSSend5000(string recipientISN, string showID, string rddnsip) { try { this.recipientDevice = this.RDDNSLookup(recipientISN, false, rddnsip); } catch { throw new ApplicationException("Unable to contact RDDNS server. IVS may be down."); } if (this.erRespType.Equals("SERVER") && this.erRespId.Equals("-1")) { throw new ApplicationException("RDDNS lookup failed. Check your computer's clock."); } if (this.erRespType.Equals("WORKER") && this.erRespId.Equals("5000")) { throw new ApplicationException(string.Format("{0} not found on IVS server.", recipientISN)); } if (this.recipientDevice == null) { throw new ApplicationException(string.Format("{0} not found on IVS server.", recipientISN)); } IVSInvite5000 structure = new IVSInvite5000(); structure.unknown1 = IPAddress.HostToNetworkOrder(1); structure.unknown2 = IPAddress.HostToNetworkOrder(0); structure.unknown3 = IPAddress.HostToNetworkOrder(0); structure.unknown4 = IPAddress.HostToNetworkOrder(1); structure.isn_field_length = IPAddress.HostToNetworkOrder(0x12); structure.recipient_isn = recipientISN; structure.magic1 = IPAddress.HostToNetworkOrder(0); structure.magic2 = IPAddress.HostToNetworkOrder(5); structure.sender_abe.name = this.theDevice.ivsNickname; byte[] bytes = BitConverter.GetBytes(long.Parse(this.theDevice.isn.Replace("-", ""))); structure.sender_abe.serial_number = new byte[6]; if (BitConverter.IsLittleEndian) { structure.sender_abe.serial_number[0] = bytes[5]; structure.sender_abe.serial_number[1] = bytes[4]; structure.sender_abe.serial_number[2] = bytes[3]; structure.sender_abe.serial_number[3] = bytes[2]; structure.sender_abe.serial_number[4] = bytes[1]; structure.sender_abe.serial_number[5] = bytes[0]; } else { structure.sender_abe.serial_number[0] = bytes[2]; structure.sender_abe.serial_number[1] = bytes[3]; structure.sender_abe.serial_number[2] = bytes[4]; structure.sender_abe.serial_number[3] = bytes[5]; structure.sender_abe.serial_number[4] = bytes[6]; structure.sender_abe.serial_number[5] = bytes[7]; } structure.sender_abe.unknown = 0; structure.sender_abe.flags = IPAddress.HostToNetworkOrder(0); structure.replay_show = new byte[0x1ac]; ReplayGuide guide = new ReplayGuide(this.theDevice); Array.Copy(guide.GetReplayShow(Convert.ToInt32(showID)), 0, structure.replay_show, 0, structure.replay_show.Length); long host = this.GetFileSize("/Video/" + showID + ".mpg"); structure.mpeg_size = IPAddress.HostToNetworkOrder(host); host = this.GetFileSize("/Video/" + showID + ".ndx"); structure.index_size = IPAddress.HostToNetworkOrder(host); host = this.GetFileSize("/Video/" + showID + ".evt"); structure.evt_size = IPAddress.HostToNetworkOrder(host); structure.reserved1 = new byte[0x2c]; structure.reserved2 = new byte[8]; structure.reserved3 = new byte[8]; IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(structure)); Marshal.StructureToPtr(structure, ptr, true); if (ptr == IntPtr.Zero) { return(1); } byte[] destination = new byte[Marshal.SizeOf(structure)]; Marshal.Copy(ptr, destination, 0, destination.Length); string text = ReplayHelper.ByteArrayToHexString(destination).ToUpper(); string asString = HTTPClient.GetAsString(string.Concat(new object[] { "http://", this.recipientDevice.ip, ":", this.recipientDevice.port, "/ivs-IVSSendNotification?isn=", recipientISN, "&size=", text.Length, "&data=", text })); if (asString == "0x9478001e") { throw new ApplicationException(string.Format("Remote ReplayTV is blocking sends from {0}. Unable to send show!", this.theDevice.ivsNickname)); } if (asString != "0x00000000") { throw new ApplicationException("Unable to contact remote ReplayTV"); } return(0); }