Esempio n. 1
0
        /// <summary>
        /// iPhone端口本地映射
        /// </summary>
        public void CreateUSBMuxConnect(int port = 2222)
        {
            //连接打开成功,建立双向通道负责数据转发
            Socket     s        = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //创建Socket对象
            IPAddress  serverIP = IPAddress.Parse("127.0.0.1");
            IPEndPoint server   = new IPEndPoint(serverIP, port);                                              //实例化服务器的IP和端口

            s.Bind(server);
            s.Listen(0);
            int socket = 0;

            while (true)
            {
                Socket cSocket;
                cSocket = s.Accept(); //用cSocket来代表该客户端连接
                int ret = MobileDevice.USBMuxConnectByPort(MobileDevice.AMDeviceGetConnectionID(this.Device),
                                                           MobileDevice.htons(22), ref socket);
                if (ret != 0)
                {
                    //连接错误,跳出
                    return;
                }
                IntPtr conn = IntPtr.Zero;
                conn = this.OpenConnection(socket); //socket链接通过AFC函数来打开,然后剩下工作交给映射的recv和send函数,函数模型和winsock相同
                if (conn != IntPtr.Zero)
                {
                    try
                    {
                        if (cSocket.Connected) //测试是否连接成功
                        {
                            Thread tread1 = new Thread(() =>
                            {
                                Conn_Forwarding_Thread(cSocket.Handle.ToInt32(), socket);
                                //USBMuxClientToPhone(cSocket, socket);
                            });
                            tread1.Start();
                            Thread tread2 = new Thread(() =>
                            {
                                Conn_Forwarding_Thread(socket, cSocket.Handle.ToInt32());
                                //USBMuxPhoneToClient(cSocket, socket);
                            });
                            tread2.Start();
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 开启AFC服务
        /// </summary>
        /// <param name="inSocket">socket句柄</param>
        /// <param name="blnInclude"></param>
        /// <returns></returns>
        public IntPtr OpenConnection(int inSocket)
        {
            IntPtr zero = IntPtr.Zero;

            try
            {
                if (MobileDevice.AFCConnectionOpen(new IntPtr(inSocket), 0, ref zero) != (int)kAMDError.kAMDSuccess)
                {
                    return(zero);
                }
            }
            catch
            {
            }
            return(zero);
        }
Esempio n. 3
0
        /// <summary>
        ///     获取设备所有信息
        /// </summary>
        /// <returns>Dictionary集合,第一个参数为键,第二个参数为键值</returns>
        public Dictionary <string, string> GetDeviceInfo()
        {
            var    dictionary = new Dictionary <string, string>();
            IntPtr dict       = IntPtr.Zero;

            if ((MobileDevice.AFCDeviceInfoOpen(hAFC, ref dict) == 0) && (dict != null))
            {
                IntPtr voidPtr2 = IntPtr.Zero;
                IntPtr voidPtr3 = IntPtr.Zero;
                while (((MobileDevice.AFCKeyValueRead(dict, ref voidPtr2, ref voidPtr3) == 0) && (voidPtr2 != null)) &&
                       (voidPtr3 != null))
                {
                    string key  = Marshal.PtrToStringAnsi(voidPtr2);
                    string str2 = Marshal.PtrToStringAnsi(voidPtr3);
                    dictionary.Add(key, str2);
                }
                MobileDevice.AFCKeyValueClose(dict);
            }
            return(dictionary);
        }
Esempio n. 4
0
 /// <summary>
 ///     链接到设备并开启相应服务,无需单独调用,在NotifyCallback已经调用
 /// </summary>
 /// <returns></returns>
 private bool ConnectToPhone()
 {
     if (MobileDevice.AMDeviceConnect(iPhoneHandle) == 1)
     {
         throw new Exception("Phone in recovery mode, support not yet implemented");
     }
     //if (MobileDevice.AMDeviceIsPaired(iPhoneHandle) == 0)
     //{
     //    return false;
     //}
     //if (MobileDevice.AMDeviceValidatePairing(iPhoneHandle) != 0)
     //{
     //    return false;
     //}
     if (MobileDevice.AMDeviceStartSession(iPhoneHandle) == 1)
     {
         return(false);
     }
     connected = true;
     return(true);
 }
Esempio n. 5
0
        /// <summary>
        ///     配置链接,注册通知回调
        /// </summary>
        private void doConstruction()
        {
            IntPtr voidPtr = IntPtr.Zero;

            dnc  = NotifyCallback;
            drn1 = DfuConnectCallback;
            drn2 = RecoveryConnectCallback;
            drn3 = DfuDisconnectCallback;
            drn4 = RecoveryDisconnectCallback;
            int num = MobileDevice.AMDeviceNotificationSubscribe(dnc, 0, 0, 0, ref voidPtr);

            if (num != 0)
            {
                throw new Exception("AMDeviceNotificationSubscribe failed with error " + num);
            }
            num = MobileDevice.AMRestoreRegisterForDeviceNotifications(drn1, drn2, drn3, drn4, 0, IntPtr.Zero);
            if (num != 0)
            {
                throw new Exception("AMRestoreRegisterForDeviceNotifications failed with error " + num);
            }
            current_directory = "/";
        }
 public int setAutoBoot(bool value)
 {
     return(MobileDevice.AMRecoveryModeDeviceSetAutoBoot(RecoveryHandle,
                                                         Conversions.ToByte(Interaction.IIf(value, 1, 0))));
 }
 public void reboot()
 {
     MobileDevice.AMRecoveryModeDeviceReboot(RecoveryHandle);
 }
Esempio n. 8
0
 public string GetiPhoneStr(string str)
 {
     return(MobileDevice.AMDeviceCopyValue(iPhoneHandle, str));
 }
Esempio n. 9
0
 /// <summary>
 ///     获取UDID
 /// </summary>
 /// <returns></returns>
 public string GetCopyDeviceIdentifier()
 {
     return(Marshal.PtrToStringAnsi(MobileDevice.AMDeviceCopyDeviceIdentifier(iPhoneHandle)));
 }