Developing iTunes as an Application in C #

I need to develop an application in C # that can automatically detect an iPhone when it is connected to the system and read a specific file for the iPhone file system. I basically want this file to download automatically from the device to the PC. I used the USBpcap tool, which assumes iTunes connects to the phone using some XML format. Any help or understanding is greatly appreciated. Is there any third party API documentation that can help me get started? There are some applications that can replicate iTunes functionality, such as Copytrans

Is there any protocol or API provided by Apple?

I dig the Internet and found this link Multilevel Communication for iPhone . I also use LibUsbDotNet libraries to communicate with a USB device ( Example ). Is it possible to guess which endpoints should be used.

It seems to me that I should implement usbmuxd in a Windows application. This is a layered protocol. There should be some libraries that implement usbmuxd (I donโ€™t think I have to implement the protocol myself)

I donโ€™t have a big idea about sharing iTunes, as well as about USB connectivity. I am adding as much information as I can (of course, with what I came up with in my R&D). Any help is appreciated.

public static DateTime LastDataEventDate = DateTime.Now; public static UsbDevice MyUsbDevice; #region SET YOUR USB Vendor and Product ID! public static UsbDeviceFinder MyUsbFinder = new UsbDeviceFinder(1452, 4768); #endregion private void LibUSB() { ErrorCode ec = ErrorCode.None; try { // Find and open the usb device. MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder); // If the device is open and ready if (MyUsbDevice == null) throw new Exception("Device Not Found."); // If this is a "whole" usb device (libusb-win32, linux libusb) // it will have an IUsbDevice interface. If not (WinUSB) the // variable will be null indicating this is an interface of a // device. IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // This is a "whole" USB device. Before it can be used, // the desired configuration and interface must be selected. // Select config #1 wholeUsbDevice.SetConfiguration(1); // Claim interface #0. wholeUsbDevice.ClaimInterface(0); } // open read endpoint 1. UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep03); // open write endpoint 1. UsbEndpointWriter writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep02); int bytesWritten; ec = writer.Write(usbmux_header.GetBytes(), 2000, out bytesWritten); if (ec != ErrorCode.None) throw new Exception(UsbDevice.LastErrorString); byte[] readBuffer = new byte[1024]; while (ec == ErrorCode.None) { int bytesRead; // If the device hasn't sent data in the last 100 milliseconds, // a timeout error (ec = IoTimedOut) will occur. ec = reader.Read(readBuffer, 10000, out bytesRead); if (ec == ErrorCode.Win32Error) throw new Exception("port not open"); if (bytesRead == 0) throw new Exception("No more bytes!"); // Write that output to the console. Console.Write(Encoding.Default.GetString(readBuffer, 0, bytesRead)); } } catch (Exception ex) { Console.WriteLine(); Console.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message); } finally { if (MyUsbDevice != null) { if (MyUsbDevice.IsOpen) { // If this is a "whole" usb device (libusb-win32, linux libusb-1.0) // it exposes an IUsbDevice interface. If not (WinUSB) the // 'wholeUsbDevice' variable will be null indicating this is // an interface of a device; it does not require or support // configuration and interface selection. IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // Release interface #0. wholeUsbDevice.ReleaseInterface(0); } MyUsbDevice.Close(); } MyUsbDevice = null; // Free usb resources UsbDevice.Exit(); } } } class usbmux_header { public static UInt32 length = 10; // length of message, including header public static UInt32 reserved = 0; // always zero public static UInt32 type = 3; // message type public static UInt32 tag = 2; // responses to this query will echo back this tag public static byte[] GetBytes() { byte[] lgth = BitConverter.GetBytes(length); byte[] res = BitConverter.GetBytes(reserved); byte[] tpe = BitConverter.GetBytes(type); byte[] tg = BitConverter.GetBytes(tag); byte[] retArray = new byte[16]; lgth.CopyTo(retArray, 0); res.CopyTo(retArray, 4); tpe.CopyTo(retArray, 8); tg.CopyTo(retArray, 12); return retArray; } }; 

I am trying to send a packet byte greeting to an iPhone, but I cannot read the response from the phone.

+6
source share
2 answers

To play with ipod, you can use SharePodLib

0
source

As I understand it, only one client can use a USB connection with iOS at a time. In both macOS and Windows, this client is usbmux. This library multiplexes TCP connections to higher-level clients, including iTunes, Photos, and (on macOS) the open source peertalk library.

So, on Windows, you donโ€™t want to implement your own usbmux, but rather the client that is on top of it is similar to peertalk. I did not see anything open source that does this, but many developers did this using their own proprietary software.

If anyone else has pointers to using usbmux on Windows, I'd love to hear about it.

-Dave

0
source

Source: https://habr.com/ru/post/956867/


All Articles