/// <summary>
        /// 开启Socket服务
        /// </summary>
        /// <param name="serviceName">服务名</param>
        /// <param name="serviceSocket">Socket链接</param>
        /// <returns></returns>
        private bool StartSocketService(string serviceName, ref int serviceSocket)
        {
            var kAMDSuccess = kAMDError.kAMDSuccess;

            if (serviceSocket > 0)//已经开启服务
            {
                return(true);
            }
            if (!this.isConnected)
            {
                if (Connect() != (int)kAMDError.kAMDSuccess)
                {
                    Console.WriteLine("StartService()执行Connect()失败");
                    return(false);
                }
            }
            bool openSession = false;

            if (!this.isSessionOpen)
            {
                kAMDSuccess = StartSession();
                if (kAMDSuccess == kAMDError.kAMDSuccess)
                {
                    openSession = true;
                }
                else
                {
                    return(false);
                }
            }
            var result = false;
            var zero   = IntPtr.Zero;

            if ((MobileDevice.AMDeviceSecureStartService(this.DevicePtr, CoreFoundation.StringToCFString(serviceName), IntPtr.Zero, ref zero) == (int)kAMDError.kAMDSuccess))
            {
                serviceSocket = MobileDevice.AMDServiceConnectionGetSocket(zero);
                result        = true;
            }
            else if (MobileDevice.AMDeviceStartService(this.DevicePtr, CoreFoundation.StringToCFString(serviceName), ref serviceSocket, IntPtr.Zero) == (int)kAMDError.kAMDSuccess)
            {
                result = true;
            }
            if (openSession)
            {
                StopSession();
            }
            return(result);
        }
Пример #2
0
 /// <summary>
 /// 链接到设备并开启相应服务,无需单独调用,在NotifyCallback已经调用
 /// </summary>
 /// <returns></returns>
 private unsafe bool ConnectToPhone()
 {
     if (MobileDevice.AMDeviceConnect(this.iPhoneHandle) == 1)
     {
         throw new Exception("Phone in recovery mode, support not yet implemented");
     }
     if (MobileDevice.AMDeviceIsPaired(this.iPhoneHandle) == 0)
     {
         return(false);
     }
     if (MobileDevice.AMDeviceValidatePairing(this.iPhoneHandle) != 0)
     {
         return(false);
     }
     if (MobileDevice.AMDeviceStartSession(this.iPhoneHandle) == 1)
     {
         return(false);
     }
     //检测是否存在afc2服务
     if (MobileDevice.AMDeviceStartService(this.iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.afc2"), ref this.hService, null) != 0)
     {
         //打开afc服务
         if (MobileDevice.AMDeviceStartService(this.iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.afc"), ref this.hService, null) != 0)
         {
             return(false);
         }
     }
     else
     {
         this.wasAFC2 = true;
     }
     if (MobileDevice.AFCConnectionOpen(this.hService, 0, ref this.hAFC) != 0)
     {
         return(false);
     }
     this.connected = true;
     //开启安装IPA服务
     if (MobileDevice.AMDeviceStartService(this.iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.mobile.installation_proxy"), ref this.installFD, null) != 0)
     {
         return(false);
     }
     return(true);
 }
Пример #3
0
        public unsafe bool ConnectViaAFC()
        {
            if (_connected)
            {
                MobileDevice.AFCConnectionClose(hAFC);
                _connected = false;
            }

            var connectResult = MobileDevice.AMDeviceConnect(iPhoneHandle);

            if (connectResult == 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);
            }

            // Connect via AFC, only Media directory is accessible on device
            if (0 != MobileDevice.AMDeviceStartService(iPhoneHandle, MobileDevice.__CFStringMakeConstantString(MobileDevice.StringToCString("com.apple.afc2")), ref hService, null))
            {
                if (0 != MobileDevice.AMDeviceStartService(iPhoneHandle, MobileDevice.__CFStringMakeConstantString(MobileDevice.StringToCString("com.apple.afc")), ref hService, null))
                {
                    return(false);
                }
            }

            _connected = true;
            return(true);
        }
Пример #4
0
 private unsafe bool ConnectToPhone()
 {
     if (MobileDevice.AMDeviceConnect(this.iPhoneHandle) == 1)
     {
         throw new Exception("Phone in recovery mode, support not yet implemented");
     }
     if (MobileDevice.AMDeviceIsPaired(this.iPhoneHandle) == 0)
     {
         return(false);
     }
     if (MobileDevice.AMDeviceValidatePairing(this.iPhoneHandle) != 0)
     {
         return(false);
     }
     if (MobileDevice.AMDeviceStartSession(this.iPhoneHandle) == 1)
     {
         return(false);
     }
     if (0 != MobileDevice.AMDeviceStartService(this.iPhoneHandle, MobileDevice.__CFStringMakeConstantString(MobileDevice.StringToCString("com.apple.afc2")), ref this.hService, null))
     {
         if (0 != MobileDevice.AMDeviceStartService(this.iPhoneHandle, MobileDevice.__CFStringMakeConstantString(MobileDevice.StringToCString("com.apple.afc")), ref this.hService, null))
         {
             return(false);
         }
     }
     else
     {
         this.wasAFC2 = true;
     }
     if (MobileDevice.AFCConnectionOpen(this.hService, 0, ref this.hAFC) != 0)
     {
         return(false);
     }
     this.connected = true;
     return(true);
 }
Пример #5
0
        private unsafe iPhone CreateiPhone(void *handle)
        {
            var connectResult = MobileDevice.AMDeviceConnect(handle);

            if (connectResult == 1)
            {
                throw new Exception("Phone in recovery mode, support not yet implemented.");
            }
            if (MobileDevice.AMDeviceIsPaired(handle) == 0)
            {
                return(null);
            }
            if (MobileDevice.AMDeviceValidatePairing(handle) != 0)
            {
                return(null);
            }
            if (MobileDevice.AMDeviceStartSession(handle) == 1)
            {
                return(null);
            }

            void *hService = null;
            void *hAFC     = null;

            if (0 != MobileDevice.AMDeviceStartService(handle, MobileDevice.__CFStringMakeConstantString(MobileDevice.StringToCString("com.apple.afc")), ref hService, null))
            {
                return(null);
            }

            if (MobileDevice.AFCConnectionOpen(hService, 0, ref hAFC) != 0)
            {
                return(null);
            }

            var iPhone = new iPhone(MobileDevice.AMDeviceCopyValue(handle, 0, "ActivationState"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "BasebandBootloaderVersion"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "BasebandVersion"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "BuildVersion"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "FirmwareVersion"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "UniqueDeviceID"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "IntegratedCircuitCardIdentity"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "iTunesHasConnected"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "ModelNumber"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "DeviceName"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "PhoneNumber"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "ProductType"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "SerialNumber"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "SIMStatus"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "DeviceClass"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "ProductVersion"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "WiFiAddress"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "InternationalMobileSubscriberIdentity"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "InternationalMobileEquipmentIdentity"),
                                    MobileDevice.AMDeviceCopyValue(handle, 0, "UniqueChipID"));

            iPhone.iPhoneHandle = handle;

            if (MobileDevice.AMDeviceStopSession(handle) != 0)
            {
                return(null);
            }
            if (MobileDevice.AMDeviceDisconnect(handle) != 0)
            {
                return(null);
            }

            if (MobileDevice.AFCConnectionOpen(hService, 0, ref hAFC) != 0)
            {
                return(null);
            }

            if (MobileDevice.AFCConnectionClose(hAFC) != 0)
            {
                return(null);
            }

            return(iPhone);
        }