Skip to content

Commit be40ac5

Browse files
authored
Merge pull request #2 from alphillips-lab/master
Fixed command-line parsing for arguments in GUI application, Added ability to specify execution working directory
2 parents b77b07f + 8e388f0 commit be40ac5

File tree

6 files changed

+46
-21
lines changed

6 files changed

+46
-21
lines changed

GM/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class Options
3636
[Option(SetName = "path", HelpText = "Program arguments.")]
3737
public string Arguments { get; set; }
3838

39+
[Option(SetName = "path", HelpText = "Set the working directory (Default: %SYSTEMROOT%\\system32)")]
40+
public string WorkingDirectory { get; set; }
41+
3942
[Option(SetName = "path", HelpText = "Wait before attaching (ms).")]
4043
public int Delay { get; set; }
4144

@@ -207,6 +210,7 @@ static void RunOptions(Options opts)
207210
path: opts.Path,
208211
dataBasePath: opts.DBPath,
209212
args: opts.Arguments,
213+
workingDirectory: opts.WorkingDirectory,
210214
delay: opts.Delay,
211215
dumpInterval: opts.Interval,
212216
dumpCount: opts.Count,

GMLib/Collector.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class Collector
2929
public int Count { get; set; }
3030
public string Path { get; set; }
3131
public string Args { get; set; }
32+
public string WorkingDirectory { get; set; }
3233
public int Delay { get; set; }
3334
public string CrashDump { get; set; }
3435
public int Pid { get; set; }
@@ -80,9 +81,11 @@ public Collector(
8081
DataBasePath = dataBasePath;
8182
}
8283

84+
// Added the option to set the working directory for the process
8385
public Collector(
8486
string path,
8587
string args,
88+
string workingDirectory,
8689
int delay = 500,
8790
uint flags = Constants.COLLECT_EVERYTHING,
8891
uint initialFlags = Constants.COLLECT_EVERYTHING,
@@ -92,6 +95,7 @@ public Collector(
9295
{
9396
Path = path;
9497
Args = args;
98+
WorkingDirectory = workingDirectory;
9599
Delay = delay;
96100
Interval = dumpInterval;
97101
Count = dumpCount;
@@ -158,6 +162,8 @@ public int Run()
158162
proc.StartInfo.FileName = Path;
159163
if (Args != null)
160164
proc.StartInfo.Arguments = Args;
165+
if (WorkingDirectory != null)
166+
proc.StartInfo.WorkingDirectory = WorkingDirectory;
161167
proc.StartInfo.CreateNoWindow = true;
162168
proc.Start();
163169
Pid = proc.Id;

GarbageMan/GarbageMan.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Description>.NET heap analyzer</Description>
1111
<Copyright />
1212
<PackageLicenseExpression>MIT</PackageLicenseExpression>
13-
<Version>0.2.2</Version>
13+
<Version>0.2.3</Version>
1414
</PropertyGroup>
1515

1616
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

GarbageMan/RunExecutable.xaml

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,52 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:GarbageMan"
77
mc:Ignorable="d" Closing="RunExecutable_Closing"
8-
Title="RunExecutable" Height="400" Width="400" Icon="assets/Recycle.ico">
8+
Title="RunExecutable" Height="440" Width="400" Icon="assets/Recycle.ico">
99
<Grid Background="#f8f8ff">
1010
<Grid.RowDefinitions>
11-
<RowDefinition Height="Auto" />
12-
<RowDefinition Height="Auto" />
13-
<RowDefinition Height="Auto" />
14-
<RowDefinition Height="Auto" />
15-
<RowDefinition Height="Auto" />
16-
<RowDefinition Height="Auto" />
17-
<RowDefinition Height="Auto" />
18-
<RowDefinition Height="Auto" />
11+
<RowDefinition Height="Auto" MinHeight="38.62" />
12+
<RowDefinition Height="Auto" MinHeight="39.96" />
13+
<RowDefinition Height="38" />
14+
<RowDefinition Height="37"/>
15+
<RowDefinition Height="Auto" MinHeight="41" />
16+
<RowDefinition Height="Auto" MinHeight="80.255" />
17+
<RowDefinition Height="36" />
18+
<RowDefinition Height="1"/>
19+
<RowDefinition Height="Auto" MinHeight="46.96" />
20+
<RowDefinition Height="Auto" MinHeight="74.76" />
1921
</Grid.RowDefinitions>
2022
<TextBlock Text="Run executable" Grid.Row="0" FontSize="14" FontWeight="SemiBold" Margin="5,10,0,10" />
21-
<Grid Grid.Row="1" Margin="10">
23+
<Grid Grid.Row="1" Margin="10,10,10,10">
2224
<Grid.ColumnDefinitions>
2325
<ColumnDefinition Width="Auto" />
2426
<ColumnDefinition Width="*" />
2527
<ColumnDefinition Width="Auto" />
2628
</Grid.ColumnDefinitions>
2729
<TextBlock Text="Executable" Grid.Column="0" Margin="0,0,5,0" />
2830
<TextBox x:Name="RunExecutablePathTextBox" Grid.Column="1" Margin="0,0,5,0" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
29-
<Button x:Name="RunExecutablePathPickerButton" Content="Pick file" Grid.Column="2" Click="RunExecutablePathPickerButton_Click" />
31+
<Button x:Name="RunExecutablePathPickerButton" Content="Pick file" Grid.Column="2" Click="RunExecutablePathPickerButton_Click" />
3032
</Grid>
31-
<Grid Grid.Row="2" Margin="10">
33+
<Grid Grid.Row="2" Margin="10,10,10,10" Grid.RowSpan="1">
3234
<Grid.ColumnDefinitions>
3335
<ColumnDefinition Width="Auto" />
3436
<ColumnDefinition Width="*" />
3537
</Grid.ColumnDefinitions>
3638
<TextBlock Text="Arguments" Grid.Column="0" Margin="0,0,5,0" />
3739
<TextBox x:Name="RunExectableArgsTextBox" Grid.Column="1" Margin="0,0,5,0" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
3840
</Grid>
39-
<Grid Grid.Row="3" Margin="10">
41+
<Grid Grid.Row="3" Margin="10,10,10,10" Grid.RowSpan="1">
4042
<Grid.ColumnDefinitions>
4143
<ColumnDefinition Width="Auto" />
42-
<ColumnDefinition Width="Auto" />
43-
<ColumnDefinition Width="Auto" />
44+
<ColumnDefinition Width="*" />
45+
</Grid.ColumnDefinitions>
46+
<TextBlock Text="Working Directory (Optional)" Grid.Column="0" Margin="0,0,5,0" />
47+
<TextBox x:Name="RunExectableWorkingDirTextBox" Grid.Column="1" Margin="0,0,5,0" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
48+
</Grid>
49+
<Grid Grid.Row="4" Margin="10,10,10,11">
50+
<Grid.ColumnDefinitions>
51+
<ColumnDefinition Width="Auto" />
52+
<ColumnDefinition Width="Auto" />
53+
<ColumnDefinition Width="Auto" />
4454
<ColumnDefinition Width="Auto" />
4555
<ColumnDefinition Width="Auto" />
4656
<ColumnDefinition Width="Auto" />
@@ -56,7 +66,7 @@
5666
<TextBox x:Name="RunExecutableSnapshotIntervalTextBox" Grid.Column="6" Width="50" Margin="0,0,2,0" />
5767
<TextBlock Text="ms" Grid.Column="7" />
5868
</Grid>
59-
<Grid Grid.Row="4" Margin="10">
69+
<Grid Grid.Row="5" Margin="10,9,10,10">
6070
<Grid>
6171
<Grid.ColumnDefinitions>
6272
<ColumnDefinition Width="1.7*" />
@@ -78,7 +88,7 @@
7888
</StackPanel>
7989
</Grid>
8090
</Grid>
81-
<Grid Grid.Row="5" Margin="10">
91+
<Grid Grid.Row="6" Margin="10,10,10,5">
8292
<Grid.ColumnDefinitions>
8393
<ColumnDefinition Width="Auto" />
8494
<ColumnDefinition Width="*" />
@@ -88,7 +98,7 @@
8898
<TextBox x:Name="RunExecutableDatabaseNameTextBox" Grid.Column="1" Text="database.db" Margin="0,0,5,0" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
8999
<Button x:Name="RunExecutableDatabasePickerButton" Content="Pick file" Grid.Column="2" Click="RunExecutableDatabasePickerButton_Click" />
90100
</Grid>
91-
<Grid Grid.Row="6" Margin="10">
101+
<Grid Grid.Row="8" Margin="10,7,10,10">
92102
<Grid.ColumnDefinitions>
93103
<ColumnDefinition Width="*" />
94104
<ColumnDefinition Width="*" />
@@ -98,7 +108,7 @@
98108
<Button x:Name="RunExecutableStartButton" Content="Start" Grid.Column="1" Margin="5" Click="RunExecutableStartButton_Click" />
99109
<Button x:Name="RunExecutableCancelButton" Content="Cancel" Grid.Column="2" Margin="5" Click="RunExecutableCancelButton_Click" />
100110
</Grid>
101-
<StackPanel Grid.Row="7">
111+
<StackPanel Grid.Row="9" Margin="0,0,0,38">
102112
<TextBlock x:Name="RunExecutableStatusText" Text="Creating database, please wait..." Margin="10,0,0,5" Visibility="Hidden" />
103113
<ProgressBar x:Name="RunExecutableProgressBar" IsIndeterminate="True" Height="5" Margin="20,0,20,10" Visibility="Hidden" />
104114
</StackPanel>

GarbageMan/RunExecutable.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ private void RunExecutableStartButton_Click(object sender, RoutedEventArgs e)
9494
// Get all the settings
9595
string path = RunExecutablePathTextBox.Text;
9696
string args = RunExectableArgsTextBox.Text;
97+
string workingDirectory = RunExectableWorkingDirTextBox.Text;
9798
int delay = int.Parse((RunExecutableDelayTextBox.Text == "") ? "" : RunExecutableDelayTextBox.Text);
9899
int count = int.Parse((RunExecutableSnapshotCountTextBox.Text == "") ? "1" : RunExecutableSnapshotCountTextBox.Text);
99100
int interval = int.Parse((RunExecutableSnapshotIntervalTextBox.Text == "") ? "0" : RunExecutableSnapshotIntervalTextBox.Text);
@@ -121,7 +122,9 @@ private void RunExecutableStartButton_Click(object sender, RoutedEventArgs e)
121122
{
122123
string cmdLine = $"--path \"{path}\" --delay {delay} --dbpath {RealPath} --items {initialFlags} ";
123124
if (args != "")
124-
cmdLine += $"--arguments \"{args}\" ";
125+
cmdLine += $"--arguments=\"{args}\" ";
126+
if (workingDirectory != "")
127+
cmdLine += $"--workingdirectory=\"{workingDirectory}\" ";
125128
if (count > 1)
126129
cmdLine += $"--count {count} --interval {interval} --nextitems {nextFlags}";
127130

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Crash course:
3333

3434
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.
3535

36+
**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.
37+
3638

3739
## How to compile the GUI tool
3840

0 commit comments

Comments
 (0)