Exemplo n.º 1
0
	public LockdownConnection(iPhoneWrapper IPW) : base(IPW, 0x0A00, 0xF27E)
	{
		MemoryStream MS = new MemoryStream();
		XmlWriter XTW = XmlWriter.Create(MS, XWS);
		XTW.WriteStartDocument();
		XTW.WriteDocType("plist", sApplePubID, sAppleSysID, null);
		XTW.WriteStartElement("plist");
		XTW.WriteAttributeString("version", "1.0");
		XTW.WriteStartElement("dict");
		XTW.WriteElementString("key", "Request");
		XTW.WriteElementString("string", "QueryType");
		XTW.WriteEndElement(); // dict
		XTW.WriteEndElement(); // plist
		XTW.WriteEndDocument();
		XTW.Flush();

		byte[] bXMLData = MS.GetBuffer();
		XTW.Close(); // Closes MS, too.

		PListSend(bXMLData);
		bXMLData = PListReceive();

		if (!CheckXMLForSuccess(bXMLData))
			throw new Exception("Lockdown hello wasn't successful.");

		#region Get public key
		// Public key is encrypted in base 64.
		string sPublicKey = GetValueFromDevice(null, "DevicePublicKey");

		// Decode sPublicKey from base 64, the result of which looks like
		// "
		// -----BEGIN RSA PUBLIC KEY-----
		// MIGJAoGBAIBNlqucaJt9Q9uX/uYgd5TRYbK4Y3tjMrrkIWThpVL/ry3rTovr9J3b
		// eGaHLUHLU/0ykXB+k7N+li7dOWhOdeAid/k5c5q4UlrOl1+eScsKeR1xUqQD2WMqGL0
		// gsOSstN+38SDOqVxcpP/geTMZsecInrgxv0asbStXdyXdy2DvJaHl2/AgMBAAE=
		// -----END RSA PUBLIC KEY-----
		// "
		byte[] bDecoded = Convert.FromBase64String(sPublicKey);

		// Read the RSA public key into a BouncyCastle structure, to be used in
		// making an X.509 device certificate.
		MS = new MemoryStream(bDecoded);
		TextReader TR = new StreamReader(MS);
		Org.BouncyCastle.OpenSsl.PemReader PR = new Org.BouncyCastle.OpenSsl.PemReader(TR);
		DevicePublicKey = (Org.BouncyCastle.Crypto.Parameters.RsaKeyParameters)PR.ReadObject();
		TR.Close();
		MS.Close();
		#endregion
	}
Exemplo n.º 2
0
	// A USBMUX connection is created for each port that will be used for communication.
	// For instance, one will be created on port 0xF27E for the lockdown protocol.
	// Communications are all prefaced by a TCP-like packet header that is managed on a
	// per-connection basis by this class.
	public USBMUXConnection(iPhoneWrapper IPW, ushort SPort, ushort DPort)
	{
		if (IPW == null || !IPW.Usable) throw new Exception("No device ready in USBMUXConnection constructor.");
		if (SPort == 0 || DPort == 0) throw new Exception("Need non-zero ports to create USBMUXConnection");

		iPhone = IPW;
		BufferedPacketsWaiting = new Queue<byte[]>();
		SourcePort = SPort;
		DestPort = DPort;
		SentCount = 0;
		ReceivedCount = 0;

		// Initialize packet header for SYN step of handshake.
		byPacketHeader = new byte[28];
		MemoryStream MS = new MemoryStream(byPacketHeader);
		BinaryWriter BW = new BinaryWriter(MS);
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((int)6)); // Type
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((int)28)); // Length
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((short)SourcePort)); // Source port
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((short)DestPort)); // Destination port
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((int)SentCount)); // Self Count
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((int)ReceivedCount)); // OCnt
		BW.Write((byte)0x50); // Offset
		BW.Write((byte)2); // TCP Flag = SYN
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((short)0x0200)); // Window size
		BW.Seek(2, SeekOrigin.Current); // Always zero
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((short)28)); // Length16
		BW.Close();
		MS.Close();

		// Initiate handshake: send SYN.
		if (SendHeader() < 0)
			throw new Exception("Failed to send SYN");

		// Continue handshake: receive SYNACK.
		byte[] byResponse = iPhone.ReceiveFromiPhone();
		if (byResponse == null || byResponse.Length != 28 || byResponse[0x15] != 0x12)
			throw new Exception("Expected SYNACK, got something else.");

		byPacketHeader[0x15] = 0x10;
		SentCount = 1;
		ReceivedCount = 1;
	}
Exemplo n.º 3
0
	public NotificationProxyConnection(iPhoneWrapper IPW, ushort SPort, ushort DPort)
		: base(IPW, SPort, DPort)
	{

	}
Exemplo n.º 4
0
	public PListConnection(iPhoneWrapper IPW, ushort SPort, ushort DPort)
		: base(IPW, SPort, DPort)
	{
		if (XWS == null)
		{
			XWS = new XmlWriterSettings();
			XWS.NewLineChars = "\n";
			XWS.Encoding = UTF8SansBOM;
			XWS.Indent = true;
			XWS.IndentChars = "\t";
		}
	}
Exemplo n.º 5
0
	public AFCConnection(iPhoneWrapper IPW, ushort SPort, ushort DPort)
		: base(IPW, SPort, DPort)
	{
		nPacketCounter = 0;
	}
Exemplo n.º 6
0
	private void MountDevice(bool bAFC2)
	{
		if (cbDeviceList.SelectedItem != null && ((UsbRegistry)((ComboBoxItem)cbDeviceList.SelectedItem).Item).IsAlive)
		{
			cbDeviceList.Enabled = false;
			Application.DoEvents(); // Without this, combobox doesn't appear disabled until the iPhone comm. finishes.

			Global.Log("Attempting to mount" + (bAFC2 ? " (as root)" : "") + "...\n");

			try
			{
				sbpMountStatus.Text = "Negotiating with device...";
				((UsbRegistry)((ComboBoxItem)cbDeviceList.SelectedItem).Item).Open(out iPhoneUSBDevice);
				iPhone = new iPhoneWrapper(iPhoneUSBDevice, bAFC2);
			}
			catch (Exception ex)
			{
				Global.Log("Aborting because exception encountered:\n" + ex + "\n\n");
				UnmountDevice();
				PopulateDeviceList();
				return;
			}

			buMount.Text = "Unmount";
			tsmiReapplyLibUSBFilters.Enabled = false;

			#region  Find the first available drive letter. Skip A:\ and B:\.
			List<char> Letters = new List<char>();
			for (int i = 2; i < 26; i++)
				Letters.Add(Convert.ToChar((byte)('A' + i)));

			DriveInfo[] Drives = DriveInfo.GetDrives();
			foreach (DriveInfo DI in Drives)
				try { Letters.Remove(DI.Name[0]); }
				catch { }

			cMountDriveLetter = Letters[0];
			#endregion

			System.ComponentModel.BackgroundWorker DokanBW = new System.ComponentModel.BackgroundWorker();
			DokanBW.DoWork += new System.ComponentModel.DoWorkEventHandler(DokanBW_DoWork);
			DokanBW.WorkerSupportsCancellation = true;
			DokanBW.RunWorkerAsync(iPhone);

			sbpDeviceCount.Text = "";
			sbpMountStatus.Text = ((UsbRegistry)((ComboBoxItem)cbDeviceList.SelectedItem).Item).DeviceProperties["FriendlyName"] + " mounted on drive " + cMountDriveLetter + ":\\";
		}
	}
Exemplo n.º 7
0
	private void UnmountDevice(bool bUnexpected)
	{
		if (cMountDriveLetter != char.MinValue) DokanNet.DokanUnmount(cMountDriveLetter);
		if (iPhone != null) iPhone.Shutdown(bUnexpected);
		iPhoneUSBDevice = null;
		iPhone = null;
		cMountDriveLetter = char.MinValue;
		buMount.Text = "Mount";
		tsmiReapplyLibUSBFilters.Enabled = true;
		sbpMountStatus.Text = "No device mounted";
		cbDeviceList.Enabled = true;
	}