From 8438ed9bf68a17b1ce3fc15b7c00a9aa2f2b12d8 Mon Sep 17 00:00:00 2001 From: beerpsi Date: Fri, 12 Apr 2024 04:40:48 +0700 Subject: [PATCH] Organize patterns and shit --- CHUNITHM-Patch-Finder.csproj | 8 ++++---- .../amdaemon.yaml | 2 +- patterns.yaml => Patterns/chusanApp.yaml | 0 Program.cs | 20 +++++++++++++++---- README.md | 10 ++++++---- 5 files changed, 27 insertions(+), 13 deletions(-) rename patterns_amdaemon.yaml => Patterns/amdaemon.yaml (95%) rename patterns.yaml => Patterns/chusanApp.yaml (100%) diff --git a/CHUNITHM-Patch-Finder.csproj b/CHUNITHM-Patch-Finder.csproj index 03096e7..7dde766 100644 --- a/CHUNITHM-Patch-Finder.csproj +++ b/CHUNITHM-Patch-Finder.csproj @@ -15,10 +15,10 @@ - - PreserveNewest - %(Filename)%(Extension) - + + PreserveNewest + Patterns/%(RecursiveDir)/%(Filename)%(Extension) + diff --git a/patterns_amdaemon.yaml b/Patterns/amdaemon.yaml similarity index 95% rename from patterns_amdaemon.yaml rename to Patterns/amdaemon.yaml index 083c061..26bd626 100644 --- a/patterns_amdaemon.yaml +++ b/Patterns/amdaemon.yaml @@ -16,4 +16,4 @@ patches: - offset: 0x03 off: [0x28] - on: [0x08] \ No newline at end of file + on: [0x08] diff --git a/patterns.yaml b/Patterns/chusanApp.yaml similarity index 100% rename from patterns.yaml rename to Patterns/chusanApp.yaml diff --git a/Program.cs b/Program.cs index 93c31e1..6a8d582 100644 --- a/Program.cs +++ b/Program.cs @@ -11,17 +11,29 @@ using YamlDotNet.Serialization.NamingConventions; if (args.Length < 1) { - Console.WriteLine($"Usage: {Environment.ProcessPath} "); + Console.WriteLine($"Usage: {Environment.ProcessPath} [PATH TO PATTERNS]"); Environment.Exit(22); // EINVAL } var deserializer = new DeserializerBuilder() .WithNamingConvention(LowerCaseNamingConvention.Instance) .Build(); +var exeFile = args[0]; +var exeFileName = Path.GetFileName(exeFile); +var patternsFile = args.Length >= 2 + ? args[1] + : Path.Join("Patterns", Path.GetFileNameWithoutExtension(exeFile) + ".yaml"); + +if (!Path.Exists(patternsFile)) +{ + Console.WriteLine($"[ERROR] Could not find patterns file {patternsFile}. Nothing to search for."); + Environment.Exit(1); +} + var patches = deserializer.Deserialize( - File.ReadAllText("patterns.yaml")); -var binary = File.ReadAllBytes(args[0]); + File.ReadAllText(patternsFile)); +var binary = File.ReadAllBytes(exeFile); var scanner = new Scanner(binary); var exportedPatches = new List(); @@ -70,7 +82,7 @@ foreach (var patch in patches) } // max track count patch -if (Path.GetFileName(args[0]) == "chusanApp.exe") +if (exeFileName == "chusanApp.exe") { var offset = scanner .FindPatterns([ diff --git a/README.md b/README.md index 07969b2..07fb486 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,13 @@ Does not do any patch validation for now. ## Usage ```sh -./CHUNITHM-Patch-Finder +./CHUNITHM-Patch-Finder [PATH TO PATTERNS] ``` -The program expects a file called `patterns.yaml` (see files in -repo for example) and outputs BemaniPatcher-compatible patches -to `patches.json`. +If a patterns file is not specified, the program defaults to +finding a file named `[file].yaml` under its `Patterns` +directory. + +The output is in a format compatible with [BemaniPatcher](https://github.com/mon/BemaniPatcher). [How to find signatures](https://reloaded-project.github.io/Reloaded-II/CheatSheet/SignatureScanning/) \ No newline at end of file