Skip to content
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

Fix bug with incorrect parse exe path with contains space #11

Merged
merged 1 commit into from
Apr 21, 2024
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
2 changes: 2 additions & 0 deletions Tests/ProcPiperInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ public void InvalidInputParseTest(string input)

[TestCase(@"EXEC:C:\Foo.exe bar", ExpectedResult = @"C:\Foo.exe")]
[TestCase(@"EXEC:C:\Foo.exe", ExpectedResult = @"C:\Foo.exe")]
[TestCase(@"EXEC:""C:\foo\space dir\bar.exe"" arg1 arg2", ExpectedResult = @"C:\foo\space dir\bar.exe")]
public string FileNamePatternMatchTest(string input)
{
var element = AddressElement.TryParse(input);
return Firejox.App.WinSocat.ProcPiperInfo.TryParse(element).FileName;
}

[TestCase(@"EXEC:C:\Foo.exe bar1 bar2", ExpectedResult = "bar1 bar2")]
[TestCase(@"EXEC:""C:\foo\space dir\bar.exe"" arg1 arg2", ExpectedResult = @"arg1 arg2")]
public string ArgumentPatternMatchTest(string input)
{
var element = AddressElement.TryParse(input);
Expand Down
2 changes: 1 addition & 1 deletion winsocat/AddressElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static AddressElement TryParse(string input)
return null!;

string tag = tagSplits[0];
string address = tagSplits[1].Substring(0, addressSepOffset);
string address = tagSplits[1].Substring(0, addressSepOffset).Trim();
var options = GetOptions(tagSplits[1].Substring(addressSepOffset));

return new AddressElement(tag, address, options);
Expand Down
22 changes: 6 additions & 16 deletions winsocat/Process.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.IO.Pipelines;
using System.CommandLine.Parsing;

namespace Firejox.App.WinSocat;

Expand All @@ -20,25 +21,14 @@ public ProcPiperInfo(string filename, string arguments)
public static ProcPiperInfo TryParse(AddressElement element)
{
if (!element.Tag.Equals("EXEC", StringComparison.OrdinalIgnoreCase)) return null!;

string execPattern = element.Address.Trim('\'', '\"');
int sepIndex = execPattern.IndexOf(' ');
string filename;
string arguments;

if (sepIndex != -1)
{
filename = execPattern.Substring(0, sepIndex);
arguments = execPattern.Substring(sepIndex + 1);
}
else
{
filename = execPattern;
arguments = "";
}
var execPattern = element.Address;
var cmdLine = CommandLineStringSplitter.Instance.Split(execPattern);
string filename = cmdLine.First();
string arguments = String.Join(' ', cmdLine.Skip(1));

return new ProcPiperInfo(filename, arguments);
}

}

public class ProcPiper : IPiper
Expand Down
Loading