From d753e06a9100cd82756734159040ffa0c51f67e6 Mon Sep 17 00:00:00 2001 From: alphillips-lab Date: Thu, 22 Dec 2022 09:11:32 -0500 Subject: [PATCH 1/2] Fixed command-line parsing for arguments in GUI application --- GarbageMan/GarbageMan.csproj | 2 +- GarbageMan/RunExecutable.xaml.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GarbageMan/GarbageMan.csproj b/GarbageMan/GarbageMan.csproj index 2c490e0..fb9fd86 100644 --- a/GarbageMan/GarbageMan.csproj +++ b/GarbageMan/GarbageMan.csproj @@ -10,7 +10,7 @@ .NET heap analyzer MIT - 0.2.2 + 0.2.3 diff --git a/GarbageMan/RunExecutable.xaml.cs b/GarbageMan/RunExecutable.xaml.cs index d9cd5e3..7b676be 100644 --- a/GarbageMan/RunExecutable.xaml.cs +++ b/GarbageMan/RunExecutable.xaml.cs @@ -121,7 +121,7 @@ private void RunExecutableStartButton_Click(object sender, RoutedEventArgs e) { string cmdLine = $"--path \"{path}\" --delay {delay} --dbpath {RealPath} --items {initialFlags} "; if (args != "") - cmdLine += $"--arguments \"{args}\" "; + cmdLine += $"--arguments=\"{args}\" "; if (count > 1) cmdLine += $"--count {count} --interval {interval} --nextitems {nextFlags}"; From 8e388f0256a563ff0a0700570f75e909334a5beb Mon Sep 17 00:00:00 2001 From: alphillips-lab Date: Thu, 22 Dec 2022 11:54:52 -0500 Subject: [PATCH 2/2] Added a working directory argument to GM utility and GUI --- GM/Program.cs | 4 +++ GMLib/Collector.cs | 6 ++++ GarbageMan/RunExecutable.xaml | 48 +++++++++++++++++++------------- GarbageMan/RunExecutable.xaml.cs | 3 ++ README.md | 2 ++ 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/GM/Program.cs b/GM/Program.cs index 345b388..59521b2 100644 --- a/GM/Program.cs +++ b/GM/Program.cs @@ -36,6 +36,9 @@ class Options [Option(SetName = "path", HelpText = "Program arguments.")] public string Arguments { get; set; } + [Option(SetName = "path", HelpText = "Set the working directory (Default: %SYSTEMROOT%\\system32)")] + public string WorkingDirectory { get; set; } + [Option(SetName = "path", HelpText = "Wait before attaching (ms).")] public int Delay { get; set; } @@ -207,6 +210,7 @@ static void RunOptions(Options opts) path: opts.Path, dataBasePath: opts.DBPath, args: opts.Arguments, + workingDirectory: opts.WorkingDirectory, delay: opts.Delay, dumpInterval: opts.Interval, dumpCount: opts.Count, diff --git a/GMLib/Collector.cs b/GMLib/Collector.cs index 68cbf0d..55051d8 100644 --- a/GMLib/Collector.cs +++ b/GMLib/Collector.cs @@ -29,6 +29,7 @@ public class Collector public int Count { get; set; } public string Path { get; set; } public string Args { get; set; } + public string WorkingDirectory { get; set; } public int Delay { get; set; } public string CrashDump { get; set; } public int Pid { get; set; } @@ -80,9 +81,11 @@ public Collector( DataBasePath = dataBasePath; } + // Added the option to set the working directory for the process public Collector( string path, string args, + string workingDirectory, int delay = 500, uint flags = Constants.COLLECT_EVERYTHING, uint initialFlags = Constants.COLLECT_EVERYTHING, @@ -92,6 +95,7 @@ public Collector( { Path = path; Args = args; + WorkingDirectory = workingDirectory; Delay = delay; Interval = dumpInterval; Count = dumpCount; @@ -158,6 +162,8 @@ public int Run() proc.StartInfo.FileName = Path; if (Args != null) proc.StartInfo.Arguments = Args; + if (WorkingDirectory != null) + proc.StartInfo.WorkingDirectory = WorkingDirectory; proc.StartInfo.CreateNoWindow = true; proc.Start(); Pid = proc.Id; diff --git a/GarbageMan/RunExecutable.xaml b/GarbageMan/RunExecutable.xaml index 468ce40..1bc509a 100644 --- a/GarbageMan/RunExecutable.xaml +++ b/GarbageMan/RunExecutable.xaml @@ -5,20 +5,22 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:GarbageMan" mc:Ignorable="d" Closing="RunExecutable_Closing" - Title="RunExecutable" Height="400" Width="400" Icon="assets/Recycle.ico"> + Title="RunExecutable" Height="440" Width="400" Icon="assets/Recycle.ico"> - - - - - - - - + + + + + + + + + + - + @@ -26,9 +28,9 @@ -