Example #1
0
 public unsafe void ReConnect(string bundleIdentifier)
 {
     MobileDevice.AFCConnectionClose(hAFC);
     MobileDevice.AMDeviceStopSession(iPhoneHandle);
     MobileDevice.AMDeviceDisconnect(iPhoneHandle);
     ConnectViaHouseArrest(bundleIdentifier);
 }
Example #2
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);
        }
Example #3
0
 public unsafe void ReConnect()
 {
     MobileDevice.AFCConnectionClose(this.hAFC);
     MobileDevice.AMDeviceStopSession(this.iPhoneHandle);
     MobileDevice.AMDeviceDisconnect(this.iPhoneHandle);
     this.ConnectToPhone();
 }
        /// <summary>
        /// 断开设备链接,但不会断开USB树链接,因而可以通过调用Connect来重新链接到设备
        /// </summary>
        /// <returns></returns>
        public kAMDError Disconnect()
        {
            var kAMDSuccess = kAMDError.kAMDSuccess;

            this.isConnected = false;
            try
            {
                kAMDSuccess = (kAMDError)MobileDevice.AMDeviceDisconnect(DevicePtr);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
            }
            return(kAMDSuccess);
        }
        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);
        }