gpt4 book ai didi

xcode - 在 C# 中开发类似 iTunes 的应用程序

转载 作者:行者123 更新时间:2023-12-04 16:10:31 26 4
gpt4 key购买 nike

我需要用 c# 开发一个应用程序,它可以在 iPhone 连接到系统时自动检测它并读取 iPhone 文件系统的特定文件。我基本上希望这个文件自动从设备下载到 PC。我使用了 USBpcap 工具,该工具建议 iTunes 使用某种 XML 格式连接到手机。非常感谢任何帮助或见解。是否有任何第三方 API 文档可以帮助我入门?有一些应用程序可以复制 iTunes 功能,例如 Copytrans

Apple 是否提供任何协议(protocol)或 API?

我一直在挖掘互联网并找到此链接Layered communication for iPhone .
此外,我正在使用 LibUsbDotNet 库与 USB 设备(Example)进行通信。任何人都可以建议应该使用哪些端点。

在我看来,我必须在 Windows 应用程序中实现 usbmuxd。它是一个多层协议(protocol)。一定有一些库实现了usbmuxd(我不认为我必须自己实现协议(protocol))

我对 iTunes 通信和 USB 通信不太了解。我正在尽可能多地添加信息(当然还有我在研发中提出的东西)。非常感谢任何帮助。

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;
}
};

我一直在尝试向 iPhone 发送 hello 数据包字节,但我无法从手机读取任何响应。

最佳答案

要玩 ipod,您可以使用 SharePodLib

关于xcode - 在 C# 中开发类似 iTunes 的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19634249/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com