public void InputStringLengthLessThanPatternLength() { String inputString = "ase"; Int32 patternLength = 4; PatternFinder.CountPatterns(inputString, patternLength); }
public void PatternLengthEqualsZero() { String inputString = "ase"; Int32 patternLength = 0; PatternFinder.CountPatterns(inputString, patternLength); }
public void EmptyInputString() { String inputString = String.Empty; Int32 patternLength = 2; PatternFinder.CountPatterns(inputString, patternLength); }
public void NoInputString() { String inputString = null; Int32 patternLength = 3; PatternFinder.CountPatterns(inputString, patternLength); }
static EnmityManager() { var pf = new PatternFinder(Core.Memory); EnmityBasePtr = pf.Find("Search 4C 8D 3D ? ? ? ? 66 90 8B 03 48 8D 0D ? ? ? ? 41 89 46 FC 45 33 C0 8B 43 04 Add 3 TraceRelative"); EnmityCountPtr = pf.Find("Search 89 05 ? ? ? ? 48 8B FA 40 38 32 76 78 Add 2 TraceRelative"); }
public void PatternLengthLessThanZero() { String inputString = "ase"; Int32 patternLength = -1; PatternFinder.CountPatterns(inputString, patternLength); }
protected override async Task <bool> RunAsync() { AtkAddonControl window = RaptureAtkUnitManager.GetWindowByName(_windowName); if (window == null) { PatternFinder patternFinder = new PatternFinder(Core.Memory); IntPtr agentVtable = patternFinder.Find(_agentOffset); int agentId = AgentModule.FindAgentIdByVtable(agentVtable); AgentModule.GetAgentInterfaceById(agentId).Toggle(); await Coroutine.Wait(5000, () => RaptureAtkUnitManager.GetWindowByName(_windowName) != null); window = RaptureAtkUnitManager.GetWindowByName(_windowName); } if (window != null) { // Choose Dungeon window.SendAction(2, 3, 15, 4, (ulong)Dungeon - 1); await Coroutine.Sleep(250); // Register for Duty window.SendAction(1, 3, 14); } return(false); }
private int getAgent() { var patternFinder = new PatternFinder(Core.Memory); IntPtr agentVtable = patternFinder.Find("48 8D 05 ? ? ? ? 48 89 51 ? 48 89 01 48 8B F9 48 8D 05 ? ? ? ? 4C 89 79 ? Add 3 TraceRelative"); return(AgentModule.FindAgentIdByVtable(agentVtable)); }
private void buttonImport_Click(object sender, EventArgs e) { try { if (textBoxFilePath.Text == "") throw new FileNotFoundException("No file chosen. Enter file name into the text box."); var graphMaker = new GraphMaker(); var graph = graphMaker.CreateGraphFromXml(textBoxFilePath.Text); richTextBoxXml.Text = graphMaker.ModelChildrenNode.ToString(); var patternFinder = new PatternFinder(); string patterns = patternFinder.FindAllPatterns(graph); richTextBoxPatterns.Text = patterns; PatternString = patterns; } catch (FileNotFoundException ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show("Cannot find patterns in the submitted file.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void PatternFinderCheckNeighboursDictionaryTest() { //arrange //act var neighbours = PatternFinder.FindPossibleNeighbursForAllPatterns(strategy, patterndataResults); StringBuilder b; foreach (var item in neighbours) { b = new StringBuilder(); b.Append("Pattern " + item.Key + " "); foreach (var item2 in item.Value.directionNeighbourPatternDictionary) { b.Append("Direction " + item2.Key.ToString() + " "); foreach (var item3 in item2.Value) { b.Append(item3 + ","); } } Debug.Log(b.ToString()); } if (patternSize == 1) { Assert.That(neighbours.Count == 5); } else if (patternSize == 2) { Assert.That(neighbours.Count == 15); } else { Assert.False(true); } }
public static Task <IntPtr?> FindPattern(Pattern pattern, Process proc) => Task <IntPtr?> .Factory.StartNew(() => { using (var patternFinder = new PatternFinder(proc)) { var ptr = patternFinder.Find(pattern.PatternString); return(ptr); } });
public RemoteProcess(Process process) { Native = process ?? throw new ArgumentNullException(nameof(process)); Native.EnableRaisingEvents = true; Native.Exited += NativeOnExited; Handle = NativeMethods.OpenProcess(ProcessAccessFlags.AllAccess, false, process.Id); Pattern = new PatternFinder(this); }
public static void OpenRepair() { var patternFinder = new PatternFinder(Core.Memory); var off = patternFinder.Find("4C 8D 0D ? ? ? ? 45 33 C0 33 D2 48 8B C8 E8 ? ? ? ? Add 3 TraceRelative"); var func = patternFinder.Find("48 89 5C 24 ? 57 48 83 EC ? 88 51 ? 49 8B F9"); Core.Memory.CallInjected64 <IntPtr>(func, AgentModule.GetAgentInterfaceById(AgentId).Pointer, 0, 0, off); }
public void PatternAtTheEnd() { String inputString = "ab3ab"; Int32 patternLength = 2; Dictionary <String, Int32> patterns = PatternFinder.CountPatterns(inputString, patternLength); Assert.AreEqual(3, patterns.Count); Assert.AreEqual(2, patterns["ab"]); }
public void OneSymbolInputString() { String inputString = "aaaa"; Int32 patternLength = 2; Dictionary <String, Int32> patterns = PatternFinder.CountPatterns(inputString, patternLength); Assert.AreEqual(1, patterns.Count); Assert.AreEqual(3, patterns["aa"]); }
static EnmityManager() { var pf = new PatternFinder(Core.Memory); TargetEnmityBasePtr = pf.Find("Search 4C 8D 3D ? ? ? ? 66 90 8B 03 48 8D 0D ? ? ? ? 41 89 46 FC 45 33 C0 8B 43 04 Add 3 TraceRelative"); EnmityCountPtr = pf.Find("Search 89 05 ? ? ? ? 48 8B FA 40 38 32 76 78 Add 2 TraceRelative"); MyEnmityCountPtr = pf.Find("Search 44 39 3D ? ? ? ? 41 8B EF Add 3 TraceRelative"); MyEnmityListPtr = pf.Find("Search 48 8D 0D ? ? ? ? E8 ? ? ? ? 84 C0 74 18 8B 57 74 Add 3 TraceRelative"); }
/// <summary> /// Finds the list of string that matches any of the patterns with the indices of each occurrence in sequence. /// </summary> /// <param name="patterns">List of patterns that needs to be searched in Sequence.</param> /// <param name="startIndex">Minimum index in Sequence at which match has to start.</param> /// <param name="ignoreCase"> /// if true ignore character casing while match. /// <remarks> /// Note that symbols in Sequence are always Upper case. /// </remarks> /// </param> /// <returns></returns> public IDictionary <string, IList <int> > FindMatches(IList <string> patterns, int startIndex = 0, bool ignoreCase = true) { if (PatternFinder == null) { PatternFinder = new BoyerMoore(); } return(PatternFinder.FindMatch( this, PatternConverter.GetInstanace(this.Alphabet).Convert(patterns).Values.SelectMany(pattern => pattern).ToList())); }
private static IntPtr ParseField(FieldInfo field, PatternFinder pf) { var offset = (OffsetAttribute)Attribute.GetCustomAttributes(field, typeof(OffsetAttribute)) .FirstOrDefault(); var valcn = (OffsetValueCN)Attribute.GetCustomAttributes(field, typeof(OffsetValueCN)) .FirstOrDefault(); var valna = (OffsetValueNA)Attribute.GetCustomAttributes(field, typeof(OffsetValueNA)) .FirstOrDefault(); var result = IntPtr.Zero; var lang = (Language)typeof(DataManager).GetFields(BindingFlags.Static | BindingFlags.NonPublic) .First(i => i.FieldType == typeof(Language)).GetValue(null); if (lang == Language.Chn) { if (valcn != null) { return((IntPtr)valcn.Value); } if (offset == null) { return(IntPtr.Zero); } var b1 = true; var results = pf.FindMany(offset.PatternCN, ref b1); if (results != null) { result = results[0]; } } else { if (valna != null) { return((IntPtr)valna.Value); } if (offset == null) { return(IntPtr.Zero); } var b1 = true; var results = pf.FindMany(offset.Pattern, ref b1); if (results != null) { result = results[0]; } } Log($"[{field.Name:,27}] {result.ToInt64():X}"); return(result); }
private static IntPtr ParseField(FieldInfo field, PatternFinder pf) { OffsetAttribute offset = (OffsetAttribute)Attribute.GetCustomAttributes(field, typeof(OffsetAttribute)) .FirstOrDefault(); OffsetValueCN valcn = (OffsetValueCN)Attribute.GetCustomAttributes(field, typeof(OffsetValueCN)) .FirstOrDefault(); OffsetValueNA valna = (OffsetValueNA)Attribute.GetCustomAttributes(field, typeof(OffsetValueNA)) .FirstOrDefault(); IntPtr result = IntPtr.Zero; if (Constants.Lang == Language.Chn) { if (valcn != null) { return((IntPtr)valcn.Value); } if (offset == null) { return(IntPtr.Zero); } bool b1 = true; IntPtr[] results = pf.FindMany(offset.PatternCN, ref b1); if (results != null) { result = results[0]; } } else { if (valna != null) { return((IntPtr)valna.Value); } if (offset == null) { return(IntPtr.Zero); } bool b1 = true; IntPtr[] results = pf.FindMany(offset.Pattern, ref b1); if (results != null) { result = results[0]; } } Logger.Info("[OffsetManager][{0:,27}] {1}", field.Name, result.ToString("X")); return(result); }
public void PatternLengthOneSymbol() { String inputString = "abcabcabc"; Int32 patternLength = 1; Dictionary <String, Int32> patterns = PatternFinder.CountPatterns(inputString, patternLength); Assert.AreEqual(3, patterns.Count); Assert.AreEqual(3, patterns["a"]); Assert.AreEqual(3, patterns["b"]); Assert.AreEqual(3, patterns["c"]); }
public void Init() { tileMapPrefab = Resources.Load("TestTilemap Variant") as GameObject; //"TestTilemap" tilemap = tileMapPrefab.GetComponent <Tilemap>(); inputReader = new InputReader(tilemap); valueManager = new ValuesManager <TileBase>(inputReader.ReadInputToGrid()); patterndataResults = PatternFinder.GetPatternDataFromGrid(valueManager, patternSize, false); if (patternSize > 1) { strategy = new NeighbourStartegySize2andMore(); } }
public void PatternsIntersection() { String inputString = "#xc513a7*c2!xa7*+3a7ckrc51g=hra7*"; Int32 patternLength = 3; Dictionary <String, Int32> allPatterns = PatternFinder.CountPatterns(inputString, patternLength); Dictionary <String, Int32> patterns = allPatterns.Where(x => x.Value > 1).ToDictionary(x => x.Key, y => y.Value); Assert.AreEqual(3, patterns.Count); Assert.AreEqual(2, patterns["3a7"]); Assert.AreEqual(2, patterns["c51"]); Assert.AreEqual(3, patterns["a7*"]); }
public void QuantityCheck() { String inputString = "ab3ab*7"; Int32 patternLength = 2; Dictionary <String, Int32> patterns = PatternFinder.CountPatterns(inputString, patternLength); Assert.AreEqual(5, patterns.Count); Assert.AreEqual(2, patterns["ab"]); Assert.AreEqual(1, patterns["b3"]); Assert.AreEqual(1, patterns["3a"]); Assert.AreEqual(1, patterns["b*"]); Assert.AreEqual(1, patterns["*7"]); }
private static void InitializeValue(ref IntPtr value, string name, string pattern, int offset = 0) { PatternFinder patternFinder = new PatternFinder(Core.Memory); try { value = patternFinder.Find(pattern) + offset; LogHelper.Instance.Log($"[Offset] Found {name} at {value.ToInt64():X}."); } catch (Exception e) { LogHelper.Instance.Log($"[Offset] {name} not found. "); } }
public async Task testMine() { var patternFinder = new PatternFinder(Core.Memory); IntPtr AnimationLocked = patternFinder.Find("48 8D 0D ?? ?? ?? ?? BA ?? ?? ?? ?? E8 ?? ?? ?? ?? 80 8B ?? ?? ?? ?? ?? 45 33 C9 44 8B C7 89 BB ?? ?? ?? ?? Add 3 TraceRelative"); var GatherLock = Core.Memory.Read <uint>(AnimationLocked + 0x2A); Log("in Test Gather"); if (GatheringManager.WindowOpen) { GatheringItem items = GatheringManager.GatheringWindowItems.FirstOrDefault(i => i.IsFilled && i.CanGather); if (Core.Me.CurrentGP >= 500) { await Coroutine.Wait(5000, () => ActionManager.CanCast(241, Core.Me)); ActionManager.DoAction(241, Core.Me); await Coroutine.Sleep(2500); } /* * if (Core.Me.CurrentGP >= 250) * { * await Coroutine.Wait(5000, () => ActionManager.CanCast(4587, Core.Me)); * ActionManager.DoAction(4587, Core.Me); * await Coroutine.Sleep(2500); * } */ Log($"Gathering: {items}"); while (GatheringManager.SwingsRemaining > 0 && GatheringManager.WindowOpen) { if (Core.Me.CurrentGP >= 100) { await Coroutine.Wait(5000, () => ActionManager.CanCast(272, Core.Me)); ActionManager.DoAction(272, Core.Me); await Coroutine.Sleep(2500); } await Coroutine.Wait(20000, () => Core.Memory.Read <uint>(AnimationLocked + 0x2A) == 0); items?.GatherItem(); await Coroutine.Wait(20000, () => Core.Memory.Read <uint>(AnimationLocked + 0x2A) != 0); await Coroutine.Wait(20000, () => Core.Memory.Read <uint>(AnimationLocked + 0x2A) == 0); } } }
public void PatternFinderCheckNeighboursPattern0Down() { //arrange //act var neighbours = PatternFinder.FindPossibleNeighbursForAllPatterns(strategy, patterndataResults); StringBuilder b; Debug.Log("Pattern 0:"); for (int i = 0; i < patternSize; i++) { b = new StringBuilder(); for (int j = 0; j < patternSize; j++) { b.Append(patterndataResults.PatternIndexDictionary[0].Pattern.GetGridValue(j, i) + " "); } Debug.Log(b.ToString()); } Debug.Log("Neighbours:"); foreach (var index in neighbours[0].GetNeighboursInDirection(Direction.Down)) { Debug.Log("Pattern " + index + " "); for (int i = 0; i < patternSize; i++) { b = new StringBuilder(); for (int j = 0; j < patternSize; j++) { b.Append(patterndataResults.PatternIndexDictionary[index].Pattern.GetGridValue(j, i) + " "); } Debug.Log(b.ToString()); } } if (patternSize == 1) { Assert.That(patterndataResults.PatternIndexDictionary[0].Pattern.GetGridValue(0, 0) == patterndataResults.PatternIndexDictionary[neighbours[0].GetNeighboursInDirection(Direction.Down).ElementAt(0)].Pattern.GetGridValue(0, 0)); } else { Assert.That( patterndataResults.PatternIndexDictionary[0].Pattern.GetGridValue(0, 0) == patterndataResults.PatternIndexDictionary[neighbours[0].GetNeighboursInDirection(Direction.Down).ElementAt(0)].Pattern.GetGridValue(0, patternSize - 1) && patterndataResults.PatternIndexDictionary[0].Pattern.GetGridValue(patternSize - 1, 0) == patterndataResults.PatternIndexDictionary[neighbours[0].GetNeighboursInDirection(Direction.Down).ElementAt(0)].Pattern.GetGridValue(patternSize - 1, patternSize - 1) ); }; }
internal static void Init() { var types = typeof(Offsets).GetFields(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); using (var pf = new PatternFinder(Core.Memory)) { Parallel.ForEach(types, type => { if (type.FieldType.IsClass) { var instance = Activator.CreateInstance(type.FieldType); foreach (var field in type.FieldType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { var res = ParseField(field, pf); if (field.FieldType == typeof(IntPtr)) { field.SetValue(instance, res); } else { field.SetValue(instance, (int)res); } } //set the value type.SetValue(null, instance); } else { var res = ParseField(type, pf); if (type.FieldType == typeof(IntPtr)) { type.SetValue(null, res); } else { type.SetValue(null, (int)res); } } } ); } }
public void PatternFinderCheckNeighbours3Test() { //arrange //act var neighbours = PatternFinder.CheckNeighboursInEachDirection(0, 1, patterndataResults); foreach (var item in neighbours.directionNeighbourPatternDictionary) { Debug.Log("Direction " + item.Key.ToString()); foreach (var item2 in item.Value) { Debug.Log("Pattern: " + item2); } } Assert.That(neighbours.directionNeighbourPatternDictionary.Count == 3); }
public async Task DebugPatternFinderTest() { // Arrange var solutionPath = Path.GetFullPath(@"..\Solution.sln"); var configurationItemPath = Path.GetFullPath(@"..\ConfigurationItem.xml"); var patternFinder = new PatternFinder(); await patternFinder.Initialize(new List <string> { configurationItemPath }, new List <string>() { solutionPath }, true); // Act var results = patternFinder.FindPatterns(); // Assert Assert.IsNotNull(results); }
private static IntPtr ParseField(FieldInfo field, PatternFinder pf) { var offset = (OffsetAttribute)Attribute.GetCustomAttributes(field, typeof(OffsetAttribute)) .FirstOrDefault(); var valcn = (OffsetValueCN)Attribute.GetCustomAttributes(field, typeof(OffsetValueCN)) .FirstOrDefault(); var valna = (OffsetValueNA)Attribute.GetCustomAttributes(field, typeof(OffsetValueNA)) .FirstOrDefault(); IntPtr results; if (Constants.Lang == Language.Chn) { if (valcn != null) { return((IntPtr)valcn.Value); } if (offset == null) { return(IntPtr.Zero); } lock (Core.Memory) { results = pf.Find(offset.PatternCN); } } else { if (valna != null) { return((IntPtr)valna.Value); } if (offset == null) { return(IntPtr.Zero); } lock (Core.Memory) { results = pf.Find(offset.Pattern); } } Logger.Info("[OffsetManager][{0:,27}] {1}", field.Name, results.ToString("X")); return(results); }
public void PatternFinderHashCalculationTest() { Hashtable table = new Hashtable(); int[][] arr1 = new int[2][]; arr1[0] = new int[] { 1, 2 }; arr1[1] = new int[] { 1, 2 }; int[][] arr2 = new int[2][]; arr2[0] = new int[] { 1, 2 }; arr2[1] = new int[] { 1, 2 }; int[][] arr3 = new int[2][]; arr3[0] = new int[] { 2, 2 }; arr3[1] = new int[] { 1, 2 }; Assert.That(PatternFinder.AreArraysTheSame(arr1, arr2)); }
private void button4_Click(object sender, EventArgs e) { #if DEBUG OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "CSV|*.csv"; if (dialog.ShowDialog() == DialogResult.OK) { Dictionary<string, DatFile2> files = new Dictionary<string, DatFile2>(); try { Dictionary<string, List<int>> ids = new Dictionary<string, List<int>>(); List<string> fullPattern = new List<string>(); using (CSV csv = new CSV(dialog.FileName)) { csv.GetRow(); while (true) { string[] row = csv.GetRow(); if (row == null) break; string path = row[5]; string fileName = Path.GetFileName(path); if (!fileName.StartsWith("client_") || (!fileName.EndsWith(".dat") && !fileName.EndsWith(".datx"))) continue; DatFile2 file; if (!files.TryGetValue(path, out file)) { try { file = new DatFile2(path); files.Add(path, file); file.CheckJumpTables(); } catch (Exception ex) { MessageBox.Show(string.Format("Error processing {0}, Exception: {1}", path, ex.ToString())); return; } ids[fileName] = new List<int>(); } string result = row[7]; long offset; long length; bool hitDisk; if (ParseResult(result, out offset, out length, out hitDisk)) { if (!hitDisk) { int id; if (file.TryMapToId(offset, out id)) { string check = fileName + ":" + id.ToString(); ids[fileName].Add(id); fullPattern.Add(check); } } } } } PatternFinder<string> patterns = new PatternFinder<string>(fullPattern, EqualityComparer<string>.Default); PatternFinder<string>.PatternTree tree = patterns.FindPatterns(); } finally { foreach (DatFile2 file in files.Values) { file.Dispose(); } } } Viewer view = new Viewer(); view.Show(this); #endif }
public static void IntalizeOffsets() { if (SecondaryOffsetManager.Initalized) { return; } Rebase = Core.Memory.Process.MainModule.BaseAddress; //The namespace specified should only be containers for offsets var types = Assembly.GetExecutingAssembly() .GetTypes() .Where(t => t.Namespace == "ExBuddy.Offsets" && t.IsClass) .OrderBy(t => t.Name) .ToArray(); Parallel.ForEach( types, type => { var pf = new PatternFinder(Core.Memory); foreach (var info in type.GetFields()) { #if RB_X64 var offset = (Offset64)Attribute.GetCustomAttributes(info, typeof(Offset64)).FirstOrDefault(); #else var offset = (Offset) Attribute.GetCustomAttributes(info, typeof (Offset)).FirstOrDefault(r => r.GetType() != typeof (OffsetCN)); #if RB_CN var tmp = (Offset)Attribute.GetCustomAttribute(info, typeof(OffsetCN)); if (tmp != null) { offset = tmp; } #endif #endif if (offset == null) { continue; } try { var markedDontRebase = false; var pattern = offset.Pattern; if (!pattern.Trim().EndsWith("DontRebase")) { pattern = pattern + " DontRebase"; } var results = pf.FindMany(pattern, ref markedDontRebase); if (results == null) { //Failed to find a pattern match. logr.Write("No match for {0} some functionality may not work correctly", info.Name); continue; } if (results.Length > 1) { lock (Core.Memory) { if (offset.MultipleResults) { if (results.Distinct().Count() == 1) { //Multiple matches were expected but there was only one result, double check that our pattern is still finding what we wanted logr.Write( "Multiple matches for {0} were expected, but only one result was found, some functionality may not work correctly", info.Name); } } else { //Multiple matches to the provided pattern were found and we were not expecting this logr.Write( "Multiple matches for {0} which was not expected, some functionality may not work correctly", info.Name); } } } #if RB_X64 var addrz = (long)results[0]; if (offset.Modifier != 0) { addrz = (long)(addrz + offset.Modifier); } logr.Write("[SecondaryOffsetManager] Found 0x{0:X} for {1}", addrz, info.Name); if (info.FieldType == typeof(IntPtr)) { info.SetValue(null, (IntPtr)addrz); } else { info.SetValue(null, (int)addrz); } #else var addrz = (uint) results[0]; if (offset.Modifier != 0) { addrz = (uint) (addrz + offset.Modifier); } logr.Write("[SecondaryOffsetManager] Found 0x{0:X} for {1}", addrz, info.Name); if (info.FieldType == typeof (IntPtr)) { info.SetValue(null, (IntPtr) addrz); } else { info.SetValue(null, (int) addrz); } #endif } catch (Exception e) { //Something went wrong logr.WriteException(e); } } }); SecondaryOffsetManager.Initalized = true; }