Skip to content

Fixed command-line parsing for arguments in GUI application, Added ability to specify execution working directory #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions GM/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions GMLib/Collector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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,
Expand All @@ -92,6 +95,7 @@ public Collector(
{
Path = path;
Args = args;
WorkingDirectory = workingDirectory;
Delay = delay;
Interval = dumpInterval;
Count = dumpCount;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion GarbageMan/GarbageMan.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Description>.NET heap analyzer</Description>
<Copyright />
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>0.2.2</Version>
<Version>0.2.3</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
48 changes: 29 additions & 19 deletions GarbageMan/RunExecutable.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,52 @@
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">
<Grid Background="#f8f8ff">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" MinHeight="38.62" />
<RowDefinition Height="Auto" MinHeight="39.96" />
<RowDefinition Height="38" />
<RowDefinition Height="37"/>
<RowDefinition Height="Auto" MinHeight="41" />
<RowDefinition Height="Auto" MinHeight="80.255" />
<RowDefinition Height="36" />
<RowDefinition Height="1"/>
<RowDefinition Height="Auto" MinHeight="46.96" />
<RowDefinition Height="Auto" MinHeight="74.76" />
</Grid.RowDefinitions>
<TextBlock Text="Run executable" Grid.Row="0" FontSize="14" FontWeight="SemiBold" Margin="5,10,0,10" />
<Grid Grid.Row="1" Margin="10">
<Grid Grid.Row="1" Margin="10,10,10,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="Executable" Grid.Column="0" Margin="0,0,5,0" />
<TextBox x:Name="RunExecutablePathTextBox" Grid.Column="1" Margin="0,0,5,0" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
<Button x:Name="RunExecutablePathPickerButton" Content="Pick file" Grid.Column="2" Click="RunExecutablePathPickerButton_Click" />
<Button x:Name="RunExecutablePathPickerButton" Content="Pick file" Grid.Column="2" Click="RunExecutablePathPickerButton_Click" />
</Grid>
<Grid Grid.Row="2" Margin="10">
<Grid Grid.Row="2" Margin="10,10,10,10" Grid.RowSpan="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Arguments" Grid.Column="0" Margin="0,0,5,0" />
<TextBox x:Name="RunExectableArgsTextBox" Grid.Column="1" Margin="0,0,5,0" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
</Grid>
<Grid Grid.Row="3" Margin="10">
<Grid Grid.Row="3" Margin="10,10,10,10" Grid.RowSpan="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Working Directory (Optional)" Grid.Column="0" Margin="0,0,5,0" />
<TextBox x:Name="RunExectableWorkingDirTextBox" Grid.Column="1" Margin="0,0,5,0" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
</Grid>
<Grid Grid.Row="4" Margin="10,10,10,11">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
Expand All @@ -56,7 +66,7 @@
<TextBox x:Name="RunExecutableSnapshotIntervalTextBox" Grid.Column="6" Width="50" Margin="0,0,2,0" />
<TextBlock Text="ms" Grid.Column="7" />
</Grid>
<Grid Grid.Row="4" Margin="10">
<Grid Grid.Row="5" Margin="10,9,10,10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.7*" />
Expand All @@ -78,7 +88,7 @@
</StackPanel>
</Grid>
</Grid>
<Grid Grid.Row="5" Margin="10">
<Grid Grid.Row="6" Margin="10,10,10,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
Expand All @@ -88,7 +98,7 @@
<TextBox x:Name="RunExecutableDatabaseNameTextBox" Grid.Column="1" Text="database.db" Margin="0,0,5,0" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
<Button x:Name="RunExecutableDatabasePickerButton" Content="Pick file" Grid.Column="2" Click="RunExecutableDatabasePickerButton_Click" />
</Grid>
<Grid Grid.Row="6" Margin="10">
<Grid Grid.Row="8" Margin="10,7,10,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
Expand All @@ -98,7 +108,7 @@
<Button x:Name="RunExecutableStartButton" Content="Start" Grid.Column="1" Margin="5" Click="RunExecutableStartButton_Click" />
<Button x:Name="RunExecutableCancelButton" Content="Cancel" Grid.Column="2" Margin="5" Click="RunExecutableCancelButton_Click" />
</Grid>
<StackPanel Grid.Row="7">
<StackPanel Grid.Row="9" Margin="0,0,0,38">
<TextBlock x:Name="RunExecutableStatusText" Text="Creating database, please wait..." Margin="10,0,0,5" Visibility="Hidden" />
<ProgressBar x:Name="RunExecutableProgressBar" IsIndeterminate="True" Height="5" Margin="20,0,20,10" Visibility="Hidden" />
</StackPanel>
Expand Down
5 changes: 4 additions & 1 deletion GarbageMan/RunExecutable.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private void RunExecutableStartButton_Click(object sender, RoutedEventArgs e)
// Get all the settings
string path = RunExecutablePathTextBox.Text;
string args = RunExectableArgsTextBox.Text;
string workingDirectory = RunExectableWorkingDirTextBox.Text;
int delay = int.Parse((RunExecutableDelayTextBox.Text == "") ? "" : RunExecutableDelayTextBox.Text);
int count = int.Parse((RunExecutableSnapshotCountTextBox.Text == "") ? "1" : RunExecutableSnapshotCountTextBox.Text);
int interval = int.Parse((RunExecutableSnapshotIntervalTextBox.Text == "") ? "0" : RunExecutableSnapshotIntervalTextBox.Text);
Expand Down Expand Up @@ -121,7 +122,9 @@ 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 (workingDirectory != "")
cmdLine += $"--workingdirectory=\"{workingDirectory}\" ";
if (count > 1)
cmdLine += $"--count {count} --interval {interval} --nextitems {nextFlags}";

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Crash course:

If you need to use `psnotify` for dumping, you need to extract it to `C:\psnotify` (yes, that's fixed for now). Just run `psnotify.exe` and stop it with `Ctrl+C` when done. It will create minidumps in `C:\dumps`. You can later then analyze those dumps with GarbageMan.

**Note**: If you'd like to specify a working directory for the program to execute from, make sure psnotify isn't running as it will conflict with GarbageMan.


## How to compile the GUI tool

Expand Down