public async void ClipboardFieldCopyCommandAction(Object parameter) { App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Information, "Clipboard field copy command invoked."); ResetIdleTime(); ClipboardField field = parameter as ClipboardField; if (field != null) { try { if (AppConfig.Instance.EnableClipboardObfuscator) { App.StopClipboardObfuscator(true, new TimeSpan(0, 0, 30)); await ClipboardObfuscator.Instance.PerformObfuscation(SimpleRandomGenerator.QuickGetRandomInt(1, 10)); } await Xamarin.Essentials.Clipboard.SetTextAsync(field.Value); App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "Successfully copied field to clipboard."); } catch (Exception ex) { App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.VerboseLow | devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Exception, "Failed to set clipboard text.\r\n'{0}'.", ex.ToString()); } } }
public void Start() { if (!_running) { Device.StartTimer(TimeSpan.FromMilliseconds(SimpleRandomGenerator.QuickGetRandomInt(2000, 30000)), TimerCallback); _stop = false; _running = true; } }
private async Task PerformObfuscation() { await Task.Yield(); //generate a fake username or password here List <string> _fakes = new List <string>(); if (FakeUsernames) { _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Generating fake username."); string user = SimpleRandomGenerator.QuickGetRandomString( SimpleRandomGenerator.CharSelection.Lowercase | SimpleRandomGenerator.CharSelection.Uppercase | SimpleRandomGenerator.CharSelection.Digits, SimpleRandomGenerator.QuickGetRandomInt(4, 12), false); string userName = String.Empty; if (_domains == null) { _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Loading list of domains for first time."); _domains = new List <string>(); using (StringReader stringReader = new StringReader(Properties.Resources.domains)) { string curLine = stringReader.ReadLine(); while (!String.IsNullOrEmpty(curLine)) { if (!_domains.Contains(curLine)) { _domains.Add(curLine); } curLine = stringReader.ReadLine(); } } } string domain = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(_domains.ToArray()); userName = String.Format("{0}@{1}", user, domain); _fakes.Add(userName); } if (FakePasswords) { _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Generating fake password."); _fakes.Add(SimpleRandomGenerator.QuickGetRandomString(SimpleRandomGenerator.CharSelection.All, 16, false)); } _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Randomly picking fake data."); string fakeEntry = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(_fakes.ToArray()); _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Fake data picked, invoking obfuscate action."); await _action.Invoke(new ClipboardObfuscatorGeneratedFakeEventArgs(fakeEntry)); }
private void Generate() { if (Memorable) { try { string format = String.Empty; if (RandomFormat) { List <string> formatParts = new List <string>(); formatParts.Add("{adjective:rc}"); formatParts.Add("{noun:rc}"); formatParts.Add("{verb:rc}"); formatParts.Add("{special1:1}"); formatParts.Add("{int:1-100}"); while (formatParts.Count > 0) { if (formatParts.Count > 0) { int randomIndex = SimpleRandomGenerator.QuickGetRandomInt(0, formatParts.Count); format += formatParts[randomIndex]; formatParts.RemoveAt(randomIndex); } else { format += formatParts[0]; formatParts.RemoveAt(0); } } } else { format = MemorableFormat; } Password = Dictionaries.Instance.GeneratePhrase(format); } catch (Exception) { Password = "******"; } } else { SimpleRandomGenerator.CharSelection charSelection = SimpleRandomGenerator.CharSelection.None; if (UseDigits) { charSelection |= SimpleRandomGenerator.CharSelection.Digits; } if (UseLowercase) { charSelection |= SimpleRandomGenerator.CharSelection.Lowercase; } if (UseUppercase) { charSelection |= SimpleRandomGenerator.CharSelection.Uppercase; } if (UseSpecial && UseBrackets) { charSelection |= SimpleRandomGenerator.CharSelection.Brackets; } if (UseSpecial && UseMinus) { charSelection |= SimpleRandomGenerator.CharSelection.Minus; } if (UseSpecial && UseOther) { charSelection |= SimpleRandomGenerator.CharSelection.Other; } if (UseSpecial && UseSpace) { charSelection |= SimpleRandomGenerator.CharSelection.Space; } if (UseSpecial && UseUnderline) { charSelection |= SimpleRandomGenerator.CharSelection.Underline; } Password = SimpleRandomGenerator.QuickGetRandomString(charSelection, Length, AtLeastOneOfEach); } }
public string GeneratePhrase(string format) { string phrase = format; //we do this in a loop so we can replace individual tokens as we go Regex tokenRegex = new Regex("\\{(.*?)\\}"); Dictionary <string, string> invalidTokens = new Dictionary <string, string>(); MatchCollection tokens = tokenRegex.Matches(phrase); while (tokens.Count > 0) { Match firstMatch = tokens[0]; string token = firstMatch.Value.Trim(new char[] { '{', '}' }); string[] tokenParts = token.Split(':'); if (tokenParts.Length == 2) { string randomWord = String.Empty; switch (tokenParts[0]) { case "verb": { randomWord = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(Verbs.ToArray()); break; } case "adjective": { randomWord = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(Adjectives.ToArray()); break; } case "noun": { randomWord = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(Nouns.ToArray()); break; } case "int": { randomWord = "{int}"; break; } case "special1": { randomWord = "{special1}"; break; } default: { randomWord = "{invalid}"; break; } } bool replace = true; switch (randomWord) { case "{int}": { string range = tokenParts[1]; string[] rangeParts = range.Split('-'); int min = int.Parse(rangeParts[0]); int max = int.Parse(rangeParts[1]); if (max > min) { int randomInt = SimpleRandomGenerator.QuickGetRandomInt(min, max); randomWord = randomInt.ToString(); } else { randomWord = String.Empty; } break; } case "{special1}": { int count = int.Parse(tokenParts[1]); randomWord = SimpleRandomGenerator.QuickGetRandomString( SimpleRandomGenerator.CharSelection.Minus | SimpleRandomGenerator.CharSelection.Underline, count, false); break; } case "{invalid}": { string tempReplacement = String.Format("[invalidtoken:{0}]", invalidTokens.Count); invalidTokens.Add(tempReplacement, firstMatch.Value); phrase = phrase.Remove(firstMatch.Index, firstMatch.Length); phrase = phrase.Insert(firstMatch.Index, tempReplacement); replace = false; break; } default: { string casing = tokenParts[1]; if (casing == "rc") { casing = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(new string[] { "lc", "uc", "ic" }); } switch (casing) { case "lc": { randomWord = randomWord.ToLower(); break; } case "uc": { randomWord = randomWord.ToUpper(); break; } case "ic": { randomWord = randomWord[0].ToString().ToUpper() + randomWord.Substring(1); break; } } break; } } if (replace) { phrase = phrase.Remove(firstMatch.Index, firstMatch.Length); phrase = phrase.Insert(firstMatch.Index, randomWord); } } else { //invalid token, remove it so that we don't get stuck in the loop string tempReplacement = String.Format("[invalidtoken:{0}]", invalidTokens.Count); invalidTokens.Add(tempReplacement, firstMatch.Value); phrase = phrase.Remove(firstMatch.Index, firstMatch.Length); phrase = phrase.Insert(firstMatch.Index, tempReplacement); } tokens = tokenRegex.Matches(phrase); } foreach (string token in invalidTokens.Keys) { if (phrase.Contains(token)) { phrase = phrase.Replace(token, invalidTokens[token]); } } return(phrase); }