Esempio n. 1
0
        public bool SetProperty(string domain, string key, string value)
        {
            bool    rv = false;
            iDevice id = Devices[0];
            IntPtr  currDevice;
            string  currUdid = id.Udid;

            LibiMobileDevice.iDeviceError returnCode = LibiMobileDevice.NewDevice(out currDevice, currUdid);
            IntPtr ldService;
            IntPtr lockdownClient;

            Lockdown.LockdownError lockdownReturnCode = Lockdown.Start(currDevice, out lockdownClient, out ldService);
            if (lockdownReturnCode == Lockdown.LockdownError.LOCKDOWN_E_SUCCESS)
            {
                IntPtr plistString             = LibiMobileDevice.plist_new_string(value);
                Lockdown.LockdownError lderror = Lockdown.lockdownd_set_value(lockdownClient, domain, key, plistString);
                if (lderror == Lockdown.LockdownError.LOCKDOWN_E_SUCCESS)
                {
                    rv = true;
                }
            }
            Lockdown.FreeClient(lockdownClient);
            Lockdown.FreeService(ldService);
            LibiMobileDevice.idevice_free(currDevice);
            return(rv);
        }
Esempio n. 2
0
        public static List <iDevice> GetDevices()
        {
            IntPtr devicesPtr;
            int    count;

            LibiMobileDevice.IDeviceError returnCode = LibiMobileDevice.idevice_get_device_list(out devicesPtr, out count);

            List <iDevice> deviceList = new List <iDevice>();

            if (returnCode != LibiMobileDevice.IDeviceError.IDEVICE_E_SUCCESS || devicesPtr == IntPtr.Zero ||
                count == 0 || Marshal.ReadInt32(devicesPtr) == 0)
            {
                return(deviceList);
            }

            string currUdid;
            int    i = 0;

            while ((currUdid = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(devicesPtr, i))) != null)
            {
                deviceList.Add(new iDevice(currUdid));
                i = i + 4;
            }

            LibiMobileDevice.idevice_device_list_free(devicesPtr);

            return(deviceList);
        }
Esempio n. 3
0
        public void UninstallApplication(string applicationBundleIdentifier)
        {
            string  appId = applicationBundleIdentifier;
            iDevice id    = Devices[0];
            IntPtr  currDevice;
            string  currUdid = id.Udid;

            LibiMobileDevice.iDeviceError returnCode = LibiMobileDevice.NewDevice(out currDevice, currUdid);
            IntPtr ldService;
            IntPtr lockdownClient;

            Lockdown.LockdownError lockdownReturnCode = Lockdown.Start(currDevice, out lockdownClient, out ldService);
            IntPtr InstProxyClient;
            IntPtr InstProxyServer;

            InstallationProxy.InstproxyError ipe = InstallationProxy.instproxy_client_start_service(currDevice, out InstProxyClient, out InstProxyServer);
            ipe = InstallationProxy.instproxy_uninstall(InstProxyClient, appId, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
            InstallationProxy.instproxy_client_free(InstProxyClient);
            Lockdown.FreeClient(lockdownClient);
            Lockdown.FreeService(ldService);
            LibiMobileDevice.idevice_free(currDevice);
            if (ipe != InstallationProxy.InstproxyError.INSTPROXY_E_SUCCESS)
            {
                throw new iPhoneException("Installation Proxy encountered an error ({0})", ipe);
            }
        }
Esempio n. 4
0
        public unsafe XDocument RequestProperties(string domain)
        {
            iDevice id = Devices[0];
            IntPtr  currDevice;
            string  currUdid = id.Udid;

            LibiMobileDevice.iDeviceError returnCode = LibiMobileDevice.NewDevice(out currDevice, currUdid);
            IntPtr ldService;
            IntPtr lockdownClient;

            Lockdown.LockdownError lockdownReturnCode = Lockdown.Start(currDevice, out lockdownClient, out ldService);
            if (lockdownReturnCode == Lockdown.LockdownError.LOCKDOWN_E_SUCCESS)
            {
                IntPtr resultPlist;
                Lockdown.LockdownError lderror = Lockdown.lockdownd_get_value(lockdownClient, domain, null, out resultPlist);
                XDocument xd = LibiMobileDevice.PlistToXml(resultPlist);
                Lockdown.FreeClient(lockdownClient);
                Lockdown.FreeService(ldService);
                LibiMobileDevice.idevice_free(currDevice);
                return(xd);
            }
            else
            {
                Lockdown.FreeClient(lockdownClient);
                Lockdown.FreeService(ldService);
                LibiMobileDevice.idevice_free(currDevice);
                throw new iPhoneException("Lockdown Encountered an Error {0}", lockdownReturnCode);
            }
        }
Esempio n. 5
0
        static void updateDeviceList()
        {
            List <iDevice> deviceList;

            LibiMobileDevice.iDeviceError getDeviceReturnCode = LibiMobileDevice.GetDeviceList(out deviceList);

            // Setting found devices "Connected" property to "true", and the others' to "false"
            foreach (iDevice currDevice in Devices)
            {
                currDevice.Connected = false;
                foreach (iDevice currDevice2 in deviceList)
                {
                    if (currDevice.Udid == currDevice2.Udid)
                    {
                        currDevice.Connected = true;
                    }
                }
            }

            // Adding new devices to the list
            List <iDevice> noDuplicatesList = deviceList.Where(x => Devices.Where(y => y.Udid == x.Udid).Count() == 0).ToList();

            if (noDuplicatesList != null)
            {
                Devices.AddRange(noDuplicatesList);
            }
        }
Esempio n. 6
0
        public List <iOSApplication> GetApplicationList()
        {
            iDevice id = Devices[0];
            IntPtr  currDevice;
            string  currUdid = id.Udid;

            LibiMobileDevice.iDeviceError returnCode = LibiMobileDevice.NewDevice(out currDevice, currUdid);
            IntPtr ldService;
            IntPtr lockdownClient;

            Lockdown.LockdownError lockdownReturnCode = Lockdown.Start(currDevice, out lockdownClient, out ldService);
            IntPtr InstProxyClient;

            InstallationProxy.InstproxyError ipe = InstallationProxy.Connect(currDevice, ldService, out InstProxyClient);
            List <iOSApplication>            appList;

            InstallationProxy.GetApplications(InstProxyClient, out appList);
            Lockdown.FreeClient(lockdownClient);
            Lockdown.FreeService(ldService);
            if (ipe == InstallationProxy.InstproxyError.INSTPROXY_E_SUCCESS)
            {
                InstallationProxy.instproxy_client_free(InstProxyClient);
                LibiMobileDevice.idevice_free(currDevice);
                return(appList);
            }
            else
            {
                throw new iPhoneException("Installation Proxy encountered an error ({0})", ipe);
            }
        }
        public static InstproxyError GetApplications(IntPtr installProxyClient, out List <iOSApplication> appList)
        {
            IntPtr clientOptions = instproxy_client_options_new();

            instproxy_client_options_add(clientOptions, "ApplicationType", "Any", IntPtr.Zero);



            IntPtr         resultPlist;
            InstproxyError returnCode = instproxy_browse(installProxyClient, clientOptions, out resultPlist);

            instproxy_client_options_free(clientOptions);

            XDocument resultXml = LibiMobileDevice.PlistToXml(resultPlist);

            appList = new List <iOSApplication>();
            if (returnCode != InstproxyError.INSTPROXY_E_SUCCESS)
            {
                return(returnCode);
            }

            else if (resultPlist == IntPtr.Zero || resultXml == default(XDocument))
            {
                return(InstproxyError.INSTPROXY_E_UNKNOWN_ERROR);
            }



            List <XElement> appElementList = resultXml.Descendants("dict").Where(x => x.Parent.Parent.Name == "plist").ToList();

            appList = new List <iOSApplication>();
            foreach (XElement currElement in appElementList)
            {
                string version = getAttribute(currElement, "CFBundleShortVersionString");
                if (version == null || version == "")
                {
                    version = getAttribute(currElement, "CFBundleVersion");
                }

                string name           = getAttribute(currElement, "CFBundleName");
                string executableName = getAttribute(currElement, "CFBundleExecutable");
                if (name == null || name == "")
                {
                    name = executableName;
                }

                string         type = getAttribute(currElement, "ApplicationType");
                string         applicationIdentifier = getAttribute(currElement, "ApplicationIdentifier");
                string         identifier            = getAttribute(currElement, "CFBundleIdentifier");
                string         staticsize            = getAttribute(currElement, "StaticDiskUsage");
                string         dynsize = getAttribute(currElement, "DynamicDiskUsage");
                iOSApplication newApp  = new iOSApplication(type, name, version, identifier, executableName, applicationIdentifier, staticsize, dynsize);
                appList.Add(newApp);
            }

            return(returnCode);
        }
Esempio n. 8
0
        public void Connect()
        {
            IntPtr deviceHandle;

            LibiMobileDevice.IDeviceError returnCode = LibiMobileDevice.NewDevice(out deviceHandle, Udid);
            if (returnCode != LibiMobileDevice.IDeviceError.IDEVICE_E_SUCCESS || deviceHandle == IntPtr.Zero)
            {
                return;
            }

            handle = deviceHandle;
        }
Esempio n. 9
0
 public void Deactivate()
 {
     if (this.IsConnected)
     {
         iDevice id = Devices[0];
         IntPtr  currDevice;
         string  currUdid = id.Udid;
         LibiMobileDevice.iDeviceError returnCode = LibiMobileDevice.NewDevice(out currDevice, currUdid);
         IntPtr ldService;
         IntPtr lockdownClient;
         Lockdown.LockdownError lockdownReturnCode = Lockdown.Start(currDevice, out lockdownClient, out ldService);
         Lockdown.lockdownd_deactivate(lockdownClient);
         Lockdown.FreeService(ldService);
         Lockdown.FreeClient(lockdownClient);
         LibiMobileDevice.idevice_free(currDevice);
     }
     else
     {
         throw new iPhoneException("Device not connected.");
     }
 }
Esempio n. 10
0
        public void Reboot()
        {
            iDevice id = Devices[0];
            IntPtr  currDevice;
            string  currUdid = id.Udid;

            LibiMobileDevice.iDeviceError returnCode = LibiMobileDevice.NewDevice(out currDevice, currUdid);
            IntPtr ldService;
            IntPtr lockdownClient;

            Lockdown.LockdownError lockdownReturnCode = Lockdown.Start(currDevice, out lockdownClient, out ldService);
            IntPtr diagService;
            IntPtr diagClient;

            iDiagnostics.diagnostics_relay_error_t dre = iDiagnostics.diagnostics_relay_client_start_service(currDevice, out diagClient, out diagService);
            iDiagnostics.diagnostics_relay_restart(diagClient, iDiagnostics.DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_PASS);
            iDiagnostics.diagnostics_relay_client_free(diagClient);
            Lockdown.FreeClient(lockdownClient);
            Lockdown.FreeService(ldService);
            LibiMobileDevice.idevice_free(currDevice);
        }
Esempio n. 11
0
        public void Sleep()
        {
            iDevice id = Devices[0];
            IntPtr  currDevice;
            string  currUdid = id.Udid;

            LibiMobileDevice.iDeviceError returnCode = LibiMobileDevice.NewDevice(out currDevice, currUdid);
            IntPtr ldService;
            IntPtr lockdownClient;

            Lockdown.LockdownError lockdownReturnCode = Lockdown.Start(currDevice, out lockdownClient, out ldService);
            IntPtr diagService;
            IntPtr diagClient;

            iDiagnostics.diagnostics_relay_error_t dre = iDiagnostics.diagnostics_relay_client_start_service(currDevice, out diagClient, out diagService);
            iDiagnostics.diagnostics_relay_sleep(diagClient);
            iDiagnostics.diagnostics_relay_client_free(diagClient);
            Lockdown.FreeClient(lockdownClient);
            Lockdown.FreeService(ldService);
            LibiMobileDevice.idevice_free(currDevice);
        }
Esempio n. 12
0
 public void Disconnect()
 {
     LibiMobileDevice.FreeDevice(handle);
     handle = IntPtr.Zero;
 }
Esempio n. 13
0
        static int Main(string[] args)
        {
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(typeof(NativeLibraries).Assembly.Location);

            Console.WriteLine($"Running tests for imobiledevice-net");
            Console.WriteLine($"- Version {fvi.FileVersion}");
            Console.WriteLine($"- .NET 4.5");

            if (Environment.Is64BitProcess)
            {
                Console.WriteLine("- 64-bit process");
            }
            else
            {
                Console.WriteLine("- 32-bit process");
            }

            // Make sure a call to NativeLibraries.Load() works
            Console.WriteLine("Loading native libraries");
            NativeLibraries.Load();

            LibiMobileDevice api = new LibiMobileDevice();

            // Test a method exposed in libplist
            Console.WriteLine("libplist - Creating a property list");
            using (var plist = api.Plist.plist_new_dict())
            {
            }

            // Test a method exposed in libusbmuxd
            Console.WriteLine("libusbmuxd - Set debug level");
            api.Usbmuxd.libusbmuxd_set_debug_level(1);

            // Test a method exposed in libimobiledevice
            Console.WriteLine("libimobiledevice - Creating installation proxy options");
            using (var options = api.InstallationProxy.instproxy_client_options_new())
            {
            }

            // List all devices
            Console.WriteLine("libimobiledevice - Listing devices");
            ListDevices();

            // Test a method exposed in libideviceactivation
            Console.WriteLine("libideviceactivation - Creating a new activation request");
            iDeviceActivationRequestHandle request;

            api.iDeviceActivation.idevice_activation_request_new(iDeviceActivationClientType.ClientItunes, out request);
            request.Dispose();

            // Make sure usbmuxd, iproxy.exe exist
            Console.WriteLine("utilities - making sure iproxy can be found");
            if (!File.Exists(Utilities.GetProxyPath()))
            {
                Console.Error.WriteLine($"Could not locate iproxy at {Utilities.GetProxyPath()}");
                return(-1);
            }

            Console.WriteLine("utilities - making sure usbmuxd can be found");
            if (!File.Exists(Utilities.GetUsbMuxdPath()))
            {
                Console.Error.WriteLine($"Could not locate usbmuxd at {Utilities.GetUsbMuxdPath()}");
                return(-1);
            }

            return(0);
        }