Ejemplo n.º 1
0
        private int create_new_device(string udid, ref DeviceModel device)
        {
            iDeviceHandle iDeviceHandle;

            iDevice.idevice_new(out iDeviceHandle, udid).ThrowOnError();
            LockdownClientHandle lockdownClientHandle;

            var ret_handshake = lockdown.lockdownd_client_new_with_handshake(iDeviceHandle,
                                                                             out lockdownClientHandle, "Quamotion");

            if (ret_handshake != 0)
            {
                return(-1);
            }

            var ret_get_devname = lockdown.lockdownd_get_device_name(lockdownClientHandle,
                                                                     out var deviceName);

            if (ret_get_devname != 0)
            {
                return(-1);
            }

            ret_handshake = lockdown.lockdownd_client_new_with_handshake(iDeviceHandle,
                                                                         out lockdownClientHandle, "waua");
            if (ret_handshake != 0)
            {
                return(-1);
            }

            var ret_get_value = lockdown.lockdownd_get_value(lockdownClientHandle, null,
                                                             "ProductVersion", out var node);

            if (ret_get_devname != 0)
            {
                return(-1);
            }

            LibiMobileDevice.Instance.Plist.plist_get_string_val(node, out var version);

            ret_get_value = lockdown.lockdownd_get_value(lockdownClientHandle, null,
                                                         "BuildVersion", out node);
            if (ret_get_devname != 0)
            {
                return(-1);
            }

            LibiMobileDevice.Instance.Plist.plist_get_string_val(node, out var bldVersion);

            iDeviceHandle.Dispose();
            lockdownClientHandle.Dispose();

            device.UDID         = udid;
            device.Name         = deviceName;
            device.Version      = version;
            device.BuildVersion = bldVersion;
            device.ShortVersion = string.Join(".", version.Split('.').Take(2));
            device.FullVersion  = string.Join(".", version.Split('.').Take(2)) + "(" + bldVersion + ")";
            device.isDevMode    = DeviceUtils.is_device_on_dev_mode(udid);

            return(0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// this is quick dirty method -- calling ideviceimagemounter.exe to
        /// mount the DeveloperDiskImage.dmg to device.
        /// A more sophisticated / robust way is needed to improve this.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void start_prov_btn_Click(object sender, EventArgs e)
        {
            // disable the button during the process to prevent re-entry
            this.start_prov_btn.Enabled = false;

            if (device.isDevMode)
            {
                System.Windows.Forms.MessageBox.Show("Device is already properly provisioned!");
                return;
            }
            this.detailed_devinfo.Text += "Device provisioning start...\n";



            // "C:\Users\cabir\Downloads\14.0(18A373).zip.zip"


            // 1.download the DDI package.
            this.detailed_devinfo.Text += "1. Download provisioning package for your device....\n";
            string prov_pkg_url = DeviceUtils.get_ddi_image_url(device);

            // make sure the temp directory exists.  If not, create it
            string tmpPath = Path.GetTempPath();

            if (!Directory.Exists(tmpPath))
            {
                this.detailed_devinfo.Text += $"Temp directory path {tmpPath} doesn't exist. Attempting to create it.";
                try
                {
                    Directory.CreateDirectory(tmpPath);
                } catch (Exception ex)
                {
                    this.detailed_devinfo.Text += $"Error creating directory {tmpPath}.\n{ex}\nPlease create it yourself and rerun.";
                    return;
                }
            }

            string local_package_file = Path.Combine(tmpPath, device.FullVersion + ".zip");

            if (File.Exists(local_package_file))
            {
                this.detailed_devinfo.Text += $"Using existing downloaded file at {local_package_file}";
            }
            else
            {
                try
                {
                    WebClient webClient = new WebClient();
                    webClient.Headers.Add("cookie", "");
                    webClient.DownloadFile(new Uri(prov_pkg_url), local_package_file);
                }
                catch (Exception ex)
                {
                    this.detailed_devinfo.Text += "we can't find" + device.FullVersion + ".zip from our repository," +
                                                  " please go to apple.com download the image and manually provision your device. \n";
                    return;
                }
                this.detailed_devinfo.Text += "Done. \n";
            }



            // 2. unzip the package..
            // FIXME: better to use async downloader.
            this.detailed_devinfo.Text += "2. Unzipping the package... \n";
            string local_folder = @"c:\temp\";

            // clear up the directory if it has anything there
            if (System.IO.Directory.Exists(local_folder + device.FullVersion))
            {
                System.IO.Directory.Delete(local_folder + device.FullVersion, true);
            }

            // clear up the directory if it has anything there
            if (System.IO.Directory.Exists(local_folder + device.ShortVersion))
            {
                System.IO.Directory.Delete(local_folder + device.ShortVersion, true);
            }

            System.IO.Compression.ZipFile.ExtractToDirectory(local_package_file, local_folder);

            string dev_image_path = local_folder + device.FullVersion + @"\DeveloperDiskImage.dmg";

            if (!Directory.Exists(local_folder + device.FullVersion))
            {
                dev_image_path = local_folder + device.ShortVersion + @"\DeveloperDiskImage.dmg";
            }

            bool all_files_present = (System.IO.File.Exists(dev_image_path) &&
                                      System.IO.File.Exists(dev_image_path + ".signature"));

            if (!all_files_present)
            {
                this.detailed_devinfo.Text += "Error: Package doesn't contain correct payload!\n";
                return;
            }
            this.detailed_devinfo.Text += "Done.\n";

            // 3. call the provisioning tool to do the job.
            this.detailed_devinfo.Text += "3. Provisioning...\n";
            string mounter = System.AppDomain.CurrentDomain.BaseDirectory +
                             @"win-x86\ideviceimagemounter.exe";

            if (!System.IO.File.Exists(mounter))
            {
                this.detailed_devinfo.Text += "Error: image mounter is not found!\n";
                return;
            }

            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName  = mounter;
            p.StartInfo.Arguments = dev_image_path;

            // Do not show the console window.
            p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            p.Start();
            p.WaitForExit();

            if (DeviceUtils.is_device_on_dev_mode(device.UDID))
            {
                this.detailed_devinfo.Text += "Done.\n";
                this.detailed_devinfo.Text += "Congratulations, your device is provisioned successfully, " +
                                              "please reconnect the USB cable to your PC.\n";
            }
            else
            {
                this.detailed_devinfo.Text += "Failed.\n";
                this.detailed_devinfo.Text += "Please ensure the device screen is NOT locked!\n";
                this.start_prov_btn.Enabled = true;
            }

            // enable the button back.
            this.start_prov_btn.Enabled = true;
        }