public override bool TryGetMember(GetMemberBinder binder, out object result) { result = null; if (_object is JArray && binder.Name == "Length") { result = (_object as JArray).Count; return true; } JObject jObject = _object as JObject; object obj = jObject.SelectToken(binder.Name); if (obj is JValue) result = ((JValue)obj).ToString(); else result = new JsonObject(jObject.SelectToken(binder.Name)); return true; }
public static string[] AuthEasyCapture(int errorcode) { CREDUI_INFO credui = new CREDUI_INFO(); credui.pszCaptionText = "Log in to EasyCaptu.re"; credui.pszMessageText = "If you don't got a account, create one at EasyCaptu.re"; credui.cbSize = Marshal.SizeOf(credui); uint authPackage = 0; IntPtr outCredBuffer = new IntPtr(); uint outCredSize; bool save = false; int result = CredUIPromptForWindowsCredentials(ref credui, errorcode, ref authPackage, IntPtr.Zero, 0, out outCredBuffer, out outCredSize, ref save, 1); var usernameBuf = new StringBuilder(100); var passwordBuf = new StringBuilder(100); var domainBuf = new StringBuilder(100); int maxUserName = 100; int maxDomain = 100; int maxPassword = 100; if (result == 0) { if (CredUnPackAuthenticationBuffer(0, outCredBuffer, outCredSize, usernameBuf, ref maxUserName, domainBuf, ref maxDomain, passwordBuf, ref maxPassword)) { //clear the memory allocated by CredUIPromptForWindowsCredentials CoTaskMemFree(outCredBuffer); using (WebClient wc = new WebClient()) { errorcode = 0; ProgressDialog diag = new ProgressDialog(IntPtr.Zero); diag.Line1 = "Authenticating with EasyCaptu.re..."; diag.Line2 = "EasyCapture is contacting the EasyCapture server..."; diag.Line3 = " "; diag.Title = "EasyCapture"; diag.Maximum = 1; diag.CancelMessage = "Trying to stop...."; diag.ShowDialog(); diag.Value = 1337; //will create desired marquee effect string resp = ""; try { resp = wc.DownloadString(new Uri(string.Format("http://api.easycaptu.re/login/{0}/{1}", usernameBuf.ToString(), passwordBuf.ToString()))); ; } catch (Exception z) { Out.WriteError(z.ToString()); resp = "Bad API request, EC Network error"; } diag.CloseDialog(); if (!diag.HasUserCancelled) { Out.WriteLine("EasyCapture auth server returned: " + resp); JObject o = (JObject)JsonConvert.DeserializeObject(resp); dynamic json = new JsonObject(o); if (Convert.ToBoolean(json.error)) { if (json.message == "Username/Password not found") return AuthEasyCapture(1326); else return AuthEasyCapture(59); } else { TaskDialog.Show("Your EasyCaptu.re account has been successfully saved", "Authorization succeeded", "Yay!"); return new string[] { Crypto.EncryptStringAES(json.userkey, Core.Secret), json.username }; } } else return new string[] { "", "" }; } } else errorcode = 1359; //an internal error occured } return new string[] { "", "" }; }
void updateCheck() { try { JObject o = (JObject)JsonConvert.DeserializeObject(new WebClient().DownloadString("http://update.easycaptu.re/version")); dynamic json = new JsonObject(o); this.Invoke(new UpdateHandler(drawUpdate), Core.isNewer(Application.ProductVersion, json.version), json.version); } catch { try { this.Invoke(new WaitCallback(updateFail)); } catch { } } }
static void Main(string[] args) { if (args.Length > 0) foreach (string arg in args) { switch (arg) { case "/s": Silent = true; break; case "/i": Ignore = true; break; } } //Out.WriteBlank("^0C^1o^2l^3o^4r^5T^6e^7s^8t^9d^10A^11b^12c"); //AllocConsole(); //WINAPI.ShowWindow(WINAPI.GetConsoleWindow(), WINAPI.ShowWindowCommands.Hide); //WINAPI.ShowWindow(ConPtr, WINAPI.ShowWindowCommands.Hide); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Out.WritePlain(Core.Version); foreach (Process p in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Application.ExecutablePath))) { if (p.MainModule.FileName == Application.ExecutablePath && !Ignore && p.Id != Process.GetCurrentProcess().Id) { TaskDialog.Show("You cannot run multiple EasyCaptures, Please exit the currently running EasyCapture first.", "EasyCapture is already running"); Environment.Exit(1); } } if (Silent) Out.WriteLine("Running in silent mode. Not showing splash screen."); ServicePointManager.Expect100Continue = false; Core.Status = "Initializing user directory..."; Out.WriteLine("Initializing user directory..."); UserDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\EasyCapture"; if (!Directory.Exists(UserDir)) Directory.CreateDirectory(UserDir); if (!File.Exists(UserDir + "\\EasyCapture.ini")) if (File.Exists(Path.GetDirectoryName(Application.ExecutablePath) + "\\example.ini")) File.Copy(Path.GetDirectoryName(Application.ExecutablePath) + "\\example.ini", UserDir + "\\EasyCapture.ini"); else { MessageBox.Show("EasyCapture could not find one if it's required files.\r\nPlease reinstall the program.", "EasyCapture installation corrupt", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(10); } Core.Status = "Cleaning up user directory..."; Out.WriteLine("Cleaning up user directory..."); CleanUp(); Core.Status = "Reading settings..."; Out.WriteLine("Reading settings..."); Core.Settings = new IniFile(UserDir + "\\EasyCapture.ini"); if(!Silent) Silent = !Convert.ToBoolean(Convert.ToInt32(Settings.IniReadValue("MISC", "ShowSplash"))); if (!Silent) { new Thread(splash).Start(); while (statusChanged == null) { Thread.Sleep(250); } } if (Settings.IniReadValue("MISC", "Console") == "1") { startConsole(); Console.Clear(); Out.Write(Out.Buffer, true, new object[] { }); Console.Title = "EasyCapture.Console"; } if (Settings.IniReadValue("Update", "Disable") != "1") { Core.Status = "Checking for updates..."; Out.WriteLine("Checking for updates..."); try { using (WebClient wc = new WebClient()) { JObject o = (JObject)JsonConvert.DeserializeObject(wc.DownloadString("http://update.easycaptu.re/version")); dynamic json = new JsonObject(o); if (isNewer(Application.ProductVersion, json.version)) { Out.WriteLine("Downloading installer..."); Status = "Downloading installer..."; string installer = UserDir + "\\EZCapInstaller-" + Path.GetRandomFileName().Replace(".", "") + ".exe"; new WebClient().DownloadFile("http://update.easycaptu.re/download/" + json.version + "/EasyCaptureInstaller.exe", installer); System.Diagnostics.Process.Start(installer, "/f"); System.Diagnostics.Process.GetCurrentProcess().Kill(); } } } catch (Exception z) { Out.WriteError("Checking for updates failed: " + z); Status = "Checking for updates failed :("; Thread.Sleep(2000); } } Out.WriteLine("Setting up hotkey hook"); new Thread(HotKeys.Init).Start(); Core.Status = "Setting up audio driver..."; Out.WriteLine("Setting up audio driver..."); SoundCapture.Init(); new Thread(icon).Start(); if (Settings.IniReadValue("CHANGELOG", "ReadV" + Application.ProductVersion) != "1") { Settings.IniWriteValue("CHANGELOG", "ReadV" + Application.ProductVersion, "1"); TaskDialog changelog = new TaskDialog(); changelog.InstructionText = "EasyCapture has just been updated!"; changelog.Text = "EasyCapture has just been updated, Please read through this changelog if you want to see what changes there are in this version"; changelog.DetailsCollapsedLabel = "Show changelog"; changelog.Caption = changelog.InstructionText; changelog.DetailsExpandedLabel = "Hide changelog"; changelog.HyperlinksEnabled = true; changelog.HyperlinkClick += delegate(object sender, TaskDialogHyperlinkClickedEventArgs e) { openLink(e.LinkText); }; string chfile = Path.GetDirectoryName(Application.ExecutablePath) + "\\" + Application.ProductVersion + ".txt"; try { changelog.DetailsExpandedText = File.ReadAllText(chfile); } catch { changelog.DetailsExpandedText = string.Format("Unable to read changelog file '{0}'", chfile); } //changelog.DetailsExpanded = true; changelog.Icon = TaskDialogStandardIcon.Shield; changelog.Show(); } //ThreadPool.QueueUserWorkItem(new WaitCallback(DemoThread)); //Reminder("EC ALPHA RELEASE "+Application.ProductVersion, "Not for distribution, Testing build only.\r\nStill has - known - bugs.", 3000); //if (Settings.IniReadValue("MISC", "ShowLoginReminder") != "0") //Reminder("Create an account and get more!", "If you create a account you can see all your texts and images and modify them as well from any computer. Click this message to sign up!", 5000); if (Settings.IniReadValue("MISC", "NotFirstTime") != "1") { Settings.IniWriteValue("MISC", "NotFirstTime", "1"); TaskDialog d = WelcomeDialog(); TaskDialogCommandLink link1 = new TaskDialogCommandLink("link1", "Let EasyCapture start with windows"); link1.ShowElevationIcon = true; TaskDialogCommandLink link2 = new TaskDialogCommandLink("link2", "Don't let EasyCapture start with windows", "If you change your mind, you can still change it in the settings"); link1.Click += delegate(object sender, EventArgs arg) { RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); key.SetValue("EasyCapture", "\"" + Application.ExecutablePath + "\" /s"); d.Close(); /*d = WelcomeDialog(); d = Step2(d); d.Show();*/ }; link2.Click += delegate(object sender, EventArgs arg) { d.Close(); /*d = WelcomeDialog(); d = Step2(d); d.Show();*/ }; d.Controls.Add(link1); d.Controls.Add(link2); d.Show(); CustomBalloon("Oh, Hai there!", "You can click this icon to customize EasyCapture to your likings!", 5000, ECIcon.BigIcon); ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object o) { Thread.Sleep(6000); Keys textkeys = (Keys)Convert.ToInt32(Core.Settings.IniReadValue("HotKeys", "text")); Keys screenkeys = (Keys)Convert.ToInt32(Core.Settings.IniReadValue("HotKeys", "screen")); Keys soundkeys = (Keys)Convert.ToInt32(Core.Settings.IniReadValue("HotKeys", "sound")); CustomBalloon("Wondering how to take a capture?", "Press " + SettingsV3.getModifier(screenkeys).ToString() + "+" + SettingsV3.removeModifiers(screenkeys).ToString() + " to take a Screen Capture\r\n" + "Press " + SettingsV3.getModifier(textkeys).ToString() + "+" + SettingsV3.removeModifiers(textkeys).ToString() + " to take a Text Capture\r\n" + "Press " + SettingsV3.getModifier(soundkeys).ToString() + "+" + SettingsV3.removeModifiers(soundkeys).ToString() + " to take a Sound Capture\r\n" , 10000, ECIcon.BigIcon); }), null); } int garbagecollects = 0; int pointer = 0; Out.WriteDebug("Hotkey loop started"); while (Online) { try { Thread.Sleep(100); // RAM garbage collecting pointer++; if (pointer == 100) { GC.Collect(); garbagecollects++; pointer = 0; } if (soundCapture) { if (SoundCaptureUp != null) SoundCaptureUp(); //if (!SoundCapture.Recording) Reminder("Recording sound...", "EasyCapture is now recording all sound output from the sound device '" + SoundCapture.RecordDevice + "'. Press the SoundCapture button again to cancel. There is a 30 seconds limit.", 5000); ThreadPool.QueueUserWorkItem(GoSS); soundCapture = false; SoundCapture.Record(); int i = 0; while (SoundCapture.Recording && soundCapture == false && i != 300) { Thread.Sleep(100); i++; } soundCapture = false; var file = SoundCapture.Stop(); StopSS(); //upload ThreadPool.QueueUserWorkItem(new WaitCallback(doDiag)); WebClient wc = new WebClient(); NameValueCollection nvc = new NameValueCollection(); nvc.Add("type", "sound"); nvc.Add("content", Convert.ToBase64String(File.ReadAllBytes(file))); File.Delete(file); bool w8 = true; bool canceled = false; string resp = ""; wc.UploadProgressChanged += delegate(object sender, UploadProgressChangedEventArgs e) { diag.Line3 = e.BytesSent + "/" + e.TotalBytesToSend; diag.Value = Convert.ToUInt32(e.ProgressPercentage); if (diag.HasUserCancelled) { wc.CancelAsync(); canceled = true; } }; wc.UploadValuesCompleted += delegate(object sender, UploadValuesCompletedEventArgs e) { if (e.Error != null && !canceled) Refused(); else { if (!canceled) { Out.WriteLine("Sound uploaded"); resp = Encoding.Default.GetString(e.Result); } diag.CloseDialog(); w8 = false; } }; string key = Core.Settings.IniReadValue("MISC", "userkey"); string ukey = ""; if (key != string.Empty) ukey = "?userkey=" + Crypto.DecryptStringAES(key, Core.Secret); wc.UploadValuesAsync(new Uri("http://upload.easycaptu.re/" + Application.ProductVersion+ukey), nvc); /*try { resp = Encoding.Default.GetString(wc.UploadValues(new Uri("http://upload.easycaptu.re/" + Application.ProductVersion), nvc)); } catch { }*/ while (w8) { Thread.Sleep(100); } if (!canceled) { Out.WriteLine("Server responded:\r\n" + resp); List<EasyCaptureResponse> keys = (List<EasyCaptureResponse>)JsonConvert.DeserializeObject(resp, typeof(List<EasyCaptureResponse>)); if (keys != null || resp != string.Empty) { var inn = String.Format("http://in.easycaptu.re/{0}/{1}", keys[0].hash, keys[0].authcode); int action = Convert.ToInt32(Core.Settings.IniReadValue("ACTIONS", "sound")); Out.WriteDebug("action=" + action); if (action == 0) { Out.WriteLine("Opening '" + inn + "'"); openLink(inn); } else if (action == 1) { string raw = "http://easycaptu.re/" + keys[0].hash + ".mp3"; Out.WriteLine("Opening '" + raw + "'"); openLink(raw); } else if (action == 2) { string copy = "http://easycaptu.re/" + keys[0].hash; Clipboard.SetText(copy); Out.WriteLine("Copied '" + copy + "' to clipboard"); Reminder("Link copied", "Link was copied to your clipboard", 2000); } } else Refused(); } if (SoundCaptureTrigger != null) SoundCaptureTrigger(); soundCapture = false; } if (textCapture) { if (TextCaptureUp != null) TextCaptureUp(); string ccopy = HotKeys.Copy(); if (ccopy == string.Empty) { TaskDialog err = new TaskDialog(); err.Icon = TaskDialogStandardIcon.Error; err.Text = "Are you sure you selected something?"; err.InstructionText = "Unable to get selected text"; err.Show(); } else { if (Settings.IniReadValue("TextCapture", "pastebin") != "1") { WebClient wc = new WebClient(); NameValueCollection nvc = new NameValueCollection(); nvc.Add("type", "text"); nvc.Add("content", Convert.ToBase64String(Encoding.Default.GetBytes(ccopy))); //Out.WriteDebug("[DEBUG] [SUPERDEBUG] [EXPIREMENTAL] " + nvc["content"]); string resp = ""; string key = Core.Settings.IniReadValue("MISC", "userkey"); string ukey = ""; if (key != string.Empty) ukey = "?userkey=" + Crypto.DecryptStringAES(key, Core.Secret); resp = Encoding.Default.GetString(wc.UploadValues("http://upload.easycaptu.re/" + Application.ProductVersion + ukey, "POST", nvc)); Out.WriteLine("Server responded:\r\n" + resp); List<EasyCaptureResponse> keys = (List<EasyCaptureResponse>)JsonConvert.DeserializeObject(resp, typeof(List<EasyCaptureResponse>)); if (keys != null || resp != string.Empty) { var inn = String.Format("http://in.easycaptu.re/{0}/{1}", keys[0].hash, keys[0].authcode); int action = Convert.ToInt32(Core.Settings.IniReadValue("ACTIONS", "text")); Out.WriteDebug("action=" + action); if (action == 0) { Out.WriteLine("Opening '" + inn + "'"); openLink(inn); } else if (action == 1) { string raw = "http://easycaptu.re/" + keys[0].hash + ".txt"; Out.WriteLine("Opening '" + raw + "'"); openLink(raw); } else if (action == 2) { string copy = "http://easycaptu.re/" + keys[0].hash; Clipboard.SetText(copy); Out.WriteLine("Copied '" + copy + "' to clipboard"); Reminder("Link copied", "Link was copied to your clipboard", 2000); } else Refused(); } } else { using (WebClient wc = new WebClient()) { string user = Crypto.DecryptStringAES(Settings.IniReadValue("TextCapture", "user_key"), Core.Secret); NameValueCollection nvc = new NameValueCollection(); nvc.Add("api_dev_key", ApiKeys.Pastebin); nvc.Add("api_option", "paste"); nvc.Add("api_paste_code", ccopy); nvc.Add("api_paste_private", Settings.IniReadValue("TextCapture", "exposure")); nvc.Add("api_paste_name", "Uploaded with easycaptu.re - Share media instantly!"); if (user != string.Empty) nvc.Add("api_user_key", user); string resp = Encoding.Default.GetString(wc.UploadValues("http://pastebin.com/api/api_post.php", nvc)); Out.WriteDebug("Server responded:\r\n" + resp); //if(!resp.StartsWith("http:// Out.WriteLine("Checking for captcha's...."); wc.Headers.Add("User-Agent", "EC RequestCaptcha " + Application.ProductVersion); string spam = wc.DownloadString(resp); CookieContainer cc = new CookieContainer(); cc.SetCookies(new Uri("http://pastebin.com"), wc.ResponseHeaders["Set-Cookie"]); string url = ""; string code = ""; foreach (string a in spam.Split(new string[] { "\n" }, StringSplitOptions.None)) { if (a.Contains("<img id=\"siimage\"")) { string re1 = ".*?"; // Non-greedy match on filler string re2 = "\".*?\""; // Uninteresting: string string re3 = ".*?"; // Non-greedy match on filler string re4 = "\".*?\""; // Uninteresting: string string re5 = ".*?"; // Non-greedy match on filler string re6 = "(\"/etc.*?\")"; // Double Quote String 1 Regex r = new Regex(re1 + re2 + re3 + re4 + re5 + re6, RegexOptions.IgnoreCase | RegexOptions.Singleline); Match m = r.Match(a); if (m.Success) { url = m.Groups[1].ToString(); } } if (a.Contains("captcha_item_key")) { string re1 = ".*?"; // Non-greedy match on filler string re2 = "(?:[a-z][a-z0-9_]*)"; // Uninteresting: var string re3 = ".*?"; // Non-greedy match on filler string re4 = "(?:[a-z][a-z0-9_]*)"; // Uninteresting: var string re5 = ".*?"; // Non-greedy match on filler string re6 = "(?:[a-z][a-z0-9_]*)"; // Uninteresting: var string re7 = ".*?"; // Non-greedy match on filler string re8 = "(?:[a-z][a-z0-9_]*)"; // Uninteresting: var string re9 = ".*?"; // Non-greedy match on filler string re10 = "((?:[a-z][a-z0-9_]*))"; // Variable Name 1 Regex r = new Regex(re1 + re2 + re3 + re4 + re5 + re6 + re7 + re8 + re9 + re10, RegexOptions.IgnoreCase | RegexOptions.Singleline); Match m = r.Match(a); if (m.Success) { code = m.Groups[1].ToString(); } } } Out.WriteDebug("---- headerdump ----"); foreach (string d in wc.Headers) { Out.WriteDebug(d); } Out.WriteDebug("Image = " + url + " Captcha key = " + code); if (url != string.Empty) { RequestCaptcha(url, code, resp, cc); } switch (Convert.ToInt32(Core.Settings.IniReadValue("ACTIONS", "text"))) { case 0: Out.WriteLine("Opening " + resp); openLink(resp); break; case 1: string dd = "http://pastebin.com/raw.php?i=" + resp.Replace("http://pastebin.com/", ""); Out.WriteLine("Opening " + dd); openLink(resp); break; case 2: Out.WriteLine("Copying " + resp); Clipboard.SetText(resp); Out.WriteLine("Copied '" + resp + "' to clipboard"); Reminder("Link copied", "Link was copied to your clipboard", 2000); break; } } } } if (TextCaptureTrigger != null) TextCaptureTrigger(); textCapture = false; } if (screenCapture) { if (ScreenCaptureUp != null) ScreenCaptureUp(); Form1 screencap = new Form1(false); screencap.ShowDialog(); if (!screencap.abort) { string resp = Encoding.Default.GetString(screencap.DATAZ); Out.WriteLine("Server responded:\r\n" + resp); if (!screencap.imgur) { List<EasyCaptureImageResponse> keys = (List<EasyCaptureImageResponse>)JsonConvert.DeserializeObject(resp, typeof(List<EasyCaptureImageResponse>)); if (keys != null || resp != string.Empty) { int action = Convert.ToInt32(Core.Settings.IniReadValue("ACTIONS", "screen")); Out.WriteDebug("action=" + action); var inn = String.Format("http://in.easycaptu.re/{0}/{1}", keys[0].hash, keys[0].authcode); if (action == 0) { Out.WriteLine("Opening " + inn); openLink(inn); } else if (action == 1) { Out.WriteLine("Opening absolute pic"); openLink(string.Format("http://easycaptu.re/{0}.png", keys[0].hash)); } else if (action == 2) { Out.WriteLine("Copying link"); //Invoke(new cliphandler(Clipboard.SetText), (object)(string.Format("http://easycapture.re/{0}", keys[0].hash))); Clipboard.SetText(string.Format("http://easycaptu.re/{0}", keys[0].hash)); Reminder("Link copied", "Link was copied to your clipboard", 2000); } } else Refused(); } else { try { XmlDocument doc = new XmlDocument(); doc.LoadXml(resp); int action = Convert.ToInt32(Core.Settings.IniReadValue("ACTIONS", "screen")); string url = doc.GetElementsByTagName("imgur_page")[0].InnerText; string direct = doc.GetElementsByTagName("original")[0].InnerText; switch (action) { case 0: Out.WriteLine("Opening " + url); openLink(url); break; case 1: Out.WriteLine("Opening absolute pic"); openLink(direct); break; case 2: Out.WriteLine("Copying link"); Clipboard.SetText(url); Reminder("Link copied", "Link was copied to your clipboard", 2000); break; default: TaskDialog.Show("Invalid action (see %AppData%\\EasyCapture.ini)"); break; } } catch(Exception z) { Out.WriteError("Error while parsing response: " + z.ToString()); Refused(); } } } if (ScreenCaptureTrigger != null) ScreenCaptureTrigger(); screenCapture = false; } } catch (Exception z) { //if (!DebugMode) FatalError(z); //else throw (z); } } Out.WriteLine("Main thread stopped, all other threads are offline as well."); Out.WriteDebug("BYE!"); //Thread.Sleep(2000); //Application.Run(new Form1()); }