Esempio n. 1
0
        public unsafe bool ConnectViaHouseArrest(string bundleIdentifier)
        {
            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);
            }

            if (string.IsNullOrEmpty(bundleIdentifier))
            {
                Console.WriteLine("Bundle identifier cannot be null when using house arrest service.");
                return(false);
            }

            // Connect via house arrest, only Documents directory is accessible on device
            if (MobileDevice.AMDeviceStartHouseArrestService(iPhoneHandle,
                                                             MobileDevice.__CFStringMakeConstantString(MobileDevice.StringToCString(bundleIdentifier)), null,
                                                             ref hService, 0) != 0)
            {
                Console.WriteLine("Unable to find bundle with id: {0}", bundleIdentifier);
                return(false);
            }

            // Need to stop session and disconnect for house arrest to work, comment out for AFC
            if (MobileDevice.AMDeviceStopSession(iPhoneHandle) != 0)
            {
                return(false);
            }
            if (MobileDevice.AMDeviceDisconnect(iPhoneHandle) != 0)
            {
                return(false);
            }

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

            _connected = true;
            return(true);
        }
Esempio n. 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);
 }
        /// <summary>
        /// 链接到设备,用于设备链接失效或者手动推出后重链接操作,此函数只要设备还在USB树上,是无需用户插拔的
        /// </summary>
        /// <returns></returns>
        public kAMDError Connect()
        {
            kAMDError kAMDSuccess = kAMDError.kAMDSuccess;

            try
            {
                if (!this.isConnected)
                {
                    kAMDSuccess = (kAMDError)MobileDevice.AMDeviceConnect(this.DevicePtr);
                    if (kAMDSuccess == kAMDError.kAMDSuccess)
                    {
                        this.isConnected = true;
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
            }
            return(kAMDSuccess);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
 }
Esempio n. 6
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);
        }