public static bool SignIpa(string path) { if (!File.Exists(Path.Combine(Program.DeveloperPath, "key.pem"))) { File.Copy(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools/developer/readme"), Path.Combine(Program.DeveloperPath, "readme"), true); Extensions.ShowMessage(MessageType.Error, "Cannot codesign application", "No certificate found in " + Program.DeveloperPath + ".\nRead README for information about how to place them."); return(false); } Program.WinInstance.StateLabel.Text = "Signing IPA"; if (File.Exists(Path.Combine(Project.Path, "build/" + Project.Name + ".ipa"))) { File.Delete(Path.Combine(Project.Path, "build/" + Project.Name + ".ipa")); } var process = Extensions.GetProcess(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools/helper/sign-ipa"), string.Format("-m {4} -c {3} -k {2} -o {1} {0}", "'" + path + "'", "'" + Path.Combine(Project.Path, "build/" + Project.Name + ".ipa'"), "'" + Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools/developer/key.pem'"), "'" + Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools/developer/certificate.pem'"), "'" + Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools/developer/provision-profile.mobileprovision'") )); int i = Program.WinInstance.Output.Run(process, (int)ActionCategory.Sideload); Program.WinInstance.ProgressBar.Fraction += Program.WinInstance.ProgressBar.PulseStep; return(i == 0); }
public static void RunProject() { var win = DeviceSelectorWindow.Create(); if (win.Run() == (int)ResponseType.Ok) { JObject jobj = PList.ParsePList(new PList(win.AttributesPlist)); /* Can't get this code working. * Will use temporarily the command ideviceimagemounter * var iDevice = LibiMobileDevice.Instance.iDevice; * var Lockdown = LibiMobileDevice.Instance.Lockdown; * var ImageMounter = LibiMobileDevice.Instance.MobileImageMounter; * var Plist = LibiMobileDevice.Instance.Plist; * * iDeviceHandle deviceHandle; * iDevice.idevice_new(out deviceHandle, jobj["UniqueDeviceID"].ToString()).ThrowOnError(); * * LockdownClientHandle lockdownHandle; * Lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "iCode").ThrowOnError(); * * LockdownServiceDescriptorHandle lockdownServiceHandle; * Lockdown.lockdownd_start_service(lockdownHandle, "com.apple.mobile.mobile_image_mounter", out lockdownServiceHandle).ThrowOnError(); * * MobileImageMounterClientHandle mounterHandle; * ImageMounter.mobile_image_mounter_new(deviceHandle, lockdownServiceHandle, out mounterHandle).ThrowOnError(); * * string s = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools/dmgs/" + jobj["BuildVersion"].ToString() + "/DeveloperDiskImage.dmg.signature"); * * var b = File.Open(s, FileMode.Open, FileAccess.Read); * var str = b.ReadFully(); * var b_length = new System.IO.FileInfo(s).Length; * var file = File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools/dmgs/" + jobj["BuildVersion"].ToString() + "/DeveloperDiskImage.dmg")); * GCHandle pinnedArray = GCHandle.Alloc(file, GCHandleType.Pinned); * IntPtr pointer = pinnedArray.AddrOfPinnedObject(); * * ImageMounter.mobile_image_mounter_upload_image(mounterHandle, "Developer", (ushort) file.Length, str, (ushort) str.Length, (buffer, length, userData) => { return (int) length; }, pointer).ThrowOnError(); * * PlistHandle plist; * ImageMounter.mobile_image_mounter_mount_image(mounterHandle, "/private/var/mobile/Media/PublicStaging/staging.dimage", str, (ushort) str.Length, "Developer", out plist).ThrowOnError(); * * uint a = 20; * string xml; * Plist.plist_to_xml(plist, out xml, ref a); * * JObject result = PList.ParsePList(new PList(xml)); * Console.WriteLine(result.ToString()); * * * b.Close(); * deviceHandle.Dispose(); * lockdownHandle.Dispose(); * lockdownServiceHandle.Dispose(); * mounterHandle.Dispose(); * pinnedArray.Free(); * plist.Dispose();*/ if (BuildProject()) { Task.Factory.StartNew(() => { try { var file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools/dmgs/" + jobj["BuildVersion"].ToString() + "/DeveloperDiskImage.dmg"); var fileSig = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools/dmgs/" + jobj["BuildVersion"].ToString() + "/DeveloperDiskImage.dmg.signature"); Program.WinInstance.Output.Run(Extensions.GetProcess("ideviceinstaller", "-U '" + Path.Combine(Project.Path, "build/" + Project.Name + ".ipa") + "'"), (int)ActionCategory.Sideload); Thread.Sleep(500); Program.WinInstance.Output.Run(Extensions.GetProcess("ideviceinstaller", "-i '" + Path.Combine(Project.Path, "build/" + Project.Name + ".ipa") + "'"), (int)ActionCategory.Sideload); Thread.Sleep(500); Program.WinInstance.Output.Run(Extensions.GetProcess("ideviceimagemounter", "'" + file + "' '" + fileSig + "'"), (int)ActionCategory.Launch); Thread.Sleep(500); Program.WinInstance.Output.Run(Extensions.GetProcess("idevicedebug", "run " + Project.BundleId), (int)ActionCategory.Launch); } catch (Exception e) { ExceptionWindow.Create(e, null).ShowAll(); } }); } } }
public static bool BuildProject() { if (!Directory.Exists(Program.SDKPath) || !Directory.EnumerateFileSystemEntries(Program.SDKPath).Any()) { Extensions.ShowMessage(MessageType.Error, "Cannot build application", "SDK path is empty, add SDK to " + Program.SDKPath); return(false); } var cachedir = Path.Combine(Project.Path, ".icode"); if (Directory.Exists(cachedir)) { Directory.Delete(cachedir, true); } Directory.CreateDirectory(cachedir); string s = ""; Program.WinInstance.ProgressBar.PulseStep = 1.0d / (double)(((double)Project.Classes.Count(c => c.Filename.EndsWith(".m", StringComparison.CurrentCulture))) + 2d); if (Project.Classes.Any((arg) => arg.Filename.EndsWith(".swift", StringComparison.CurrentCultureIgnoreCase))) { Extensions.ShowMessage(MessageType.Error, "Cannot build.", "Swift is not supported for the moment."); } foreach (var @class in from c in Project.Classes where !c.Filename.EndsWith(".h", StringComparison.CurrentCultureIgnoreCase) select c) { Program.WinInstance.StateLabel.Text = "Building " + @class; Directory.CreateDirectory(Path.Combine(cachedir, "build")); var flags = string.Join(" ", Flags) + " -c " + string.Join(" ", @class.CompilerFlags) + " "; var proc = Extensions.GetProcess("clang", flags + "'" + Path.Combine(Project.Path, @class.Filename) + "' -o '" + Path.Combine(cachedir, "build", @class.Filename + ".output") + "'"); if (Program.WinInstance.Output.Run(proc, (int)ActionCategory.Make) != 0) { return(false); } s += "'" + Path.Combine(cachedir, "build", @class.Filename + ".output") + "' "; Program.WinInstance.ProgressBar.Fraction += Program.WinInstance.ProgressBar.PulseStep; } Program.WinInstance.StateLabel.Text = "Linking"; Directory.CreateDirectory(Path.Combine(Project.Path, ".icode/Payload/" + Project.Name + ".app/")); var process = Extensions.GetProcess("clang", @"-target '" + Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools/target/arm64-apple-darwin14") + "' -framework " + string.Join(" -framework ", Project.Frameworks) + " -isysroot '" + Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools/sdk") + "' -arch arm64 -o '" + Path.Combine(Project.Path, ".icode/Payload/" + Project.Name + ".app/" + Project.Name) + "' " + s); if (Program.WinInstance.Output.Run(process, (int)ActionCategory.Link) != 0) { return(false); } Program.WinInstance.ProgressBar.Fraction += Program.WinInstance.ProgressBar.PulseStep; Program.WinInstance.StateLabel.Text = "Packing IPA"; foreach (var f in Directory.GetFiles(Path.Combine(Project.Path, "Resources"))) { File.Copy(f, Path.Combine(Project.Path, ".icode/Payload/" + Project.Name + ".app/")); } Directory.Delete(Path.Combine(cachedir, "build"), true); if (!Directory.Exists(Path.Combine(Project.Path, "build"))) { Directory.CreateDirectory(Path.Combine(Project.Path, "build")); } if (File.Exists(Path.Combine(Project.Path, "build/" + Project.Name + "-unsigned.ipa"))) { File.Delete(Path.Combine(Project.Path, "build/" + Project.Name + "-unsigned.ipa")); } ZipFile.CreateFromDirectory(cachedir, Path.Combine(Project.Path, "build/" + Project.Name + "-unsigned.ipa")); return(SignIpa(Path.Combine(Project.Path, "build/" + Project.Name + "-unsigned.ipa"))); }