Beispiel #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);
        }
        /// <summary>
        /// 开启Session。Session需要在调用服务前先行打开,然后完成服务操作后自行关闭(函数会自动关闭),否则可能会遇到无法打开服务的错误
        /// </summary>
        /// <returns></returns>
        public kAMDError StartSession(bool isRretry = false)
        {
            var kAMDSuccess = kAMDError.kAMDSuccess;

            try
            {
                if (!this.isSessionOpen)
                {
                    kAMDSuccess = (kAMDError)MobileDevice.AMDeviceStartSession(this.DevicePtr);
                    if (kAMDSuccess != kAMDError.kAMDInvalidHostIDError)
                    {
                        if (kAMDSuccess != (int)kAMDError.kAMDSuccess)
                        {
                            //修复:Session关闭后一段时间无法再次打开的问题
                            if (!isRretry)
                            {
                                this.Disconnect();
                                this.Connect();
                                return(StartSession(true));
                            }
                            return(kAMDSuccess);
                        }
                        this.isSessionOpen = true;
                        return(kAMDSuccess);
                    }
                    if ((MobileDevice.AMDeviceUnpair(this.DevicePtr) == (int)kAMDError.kAMDSuccess) &&
                        (MobileDevice.AMDevicePair(this.DevicePtr) == (int)kAMDError.kAMDSuccess))
                    {
                        kAMDSuccess = (kAMDError)MobileDevice.AMDeviceStartSession(this.DevicePtr);
                        if (kAMDSuccess != kAMDError.kAMDSuccess)
                        {
                            return(kAMDSuccess);
                        }
                        this.isSessionOpen = true;
                        return(kAMDSuccess);
                    }
                }
                return(kAMDSuccess);
            }
            catch
            {
                kAMDSuccess = kAMDError.kAMDUndefinedError;
            }
            return(kAMDSuccess);
        }
Beispiel #3
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);
 }
Beispiel #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);
        }
Beispiel #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);
 }
        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);
        }