Skip to content

Commit

Permalink
Replace gocat with WinSocat
Browse files Browse the repository at this point in the history
  • Loading branch information
arixmkii committed Jan 15, 2025
1 parent 9e8c2be commit 76539ed
Show file tree
Hide file tree
Showing 8 changed files with 1,336 additions and 648 deletions.
71 changes: 0 additions & 71 deletions .github/workflows/prepare-gocat-release.yml

This file was deleted.

42 changes: 0 additions & 42 deletions .github/workflows/prepare-msys2-tools.yml

This file was deleted.

96 changes: 96 additions & 0 deletions .github/workflows/prepare-winsocat-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Prepare QCW WinSocat (from revision)

on:
workflow_dispatch:
workflow_call:
outputs:
winsocat_version:
description: WinSocat version"
value: ${{ jobs.build.outputs.winsocat_version }}

env:
WINSOCAT_GITURL: https://github.com/firejox/WinSocat.git
WINSOCAT_SHA: ad84bd28b6721c6415b73a37bb4a23aa53936062 # v0.1.3
WINSOCAT_VERSION: 0.1.3

jobs:
build:
runs-on: windows-latest
outputs:
winsocat_version: ${{ steps.make_versions.outputs.winsocat }}

steps:
- name: "🏗️ Install msys2"
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: true
install: >-
git
dos2unix
- name: "🏗️ Install dotnet"
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-quality: 'ga'

- name: "📝 Configure checkout"
run: git config --global core.autocrlf input

- name: "📝 Checkout"
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: "📝 Fetch sources"
shell: msys2 {0}
run: |
mkdir winsocat-release
cd winsocat-release
git init
git remote add origin $WINSOCAT_GITURL
git fetch --depth 1 origin $WINSOCAT_SHA
git checkout FETCH_HEAD
find . -type f -print0 | xargs -0 dos2unix
patch --binary -l -p 1 < ../patches/WinSocat/0001-Pending-0.1.3.patch
patch --binary -l -p 1 < ../patches/WinSocat/0002-Upgrade-to-dontent8.patch
patch --binary -l -p 1 < ../patches/WinSocat/0003-Improve-solution-setup.patch
- name: "🧪 Test WinSocat"
working-directory: winsocat-release
shell: pwsh
run: |
dotnet restore
dotnet build --no-restore
dotnet test --no-build
- name: "🛠️ Build WinSocat"
working-directory: winsocat-release
shell: pwsh
run: |
dotnet restore
dotnet build -c Release --no-restore
dotnet publish winsocat -c Release -r win-x64 -p:PublishDir=../build/x64 -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:EnableCompressionInSingleFile=true -p:PublishReadyToRun=true -p:PublishTrimmed=true --self-contained true
- name: "📦 Pack WinSocat"
shell: msys2 {0}
run: |
mkdir -p qcw
cp "winsocat-release/build/x64/"*".exe" qcw/
cd qcw
find . -type f \( ! -iname "*.checksums" \) -exec sha256sum -b {} \; > sha.checksums
find . -type f \( ! -iname "*.checksums" \) -exec sha512sum -b {} \; >> sha.checksums
cat sha.checksums
- id: make_versions
name: "📌 Export versions"
shell: msys2 {0}
run: |
echo "winsocat=$WINSOCAT_VERSION" >> "$GITHUB_OUTPUT"
- name: "🚀 Upload artifact"
uses: actions/upload-artifact@v4
with:
name: qcw-winsocat
path: qcw
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ default.

Ordered alphabetically

* `docker-cli` - [Github](https://github.com/docker/cli) `docker` command line interface;
* `docker-compose` - [Github](https://github.com/docker/compose) orchestration tool for containers;
* `gocat` - [Github](https://github.com/sumup-oss/gocat) multipurpose networking relay;
* `gvisor-tap-vsock` - [Github](https://github.com/containers/gvisor-tap-vsock) the tool to provide networking for
* `docker-cli` - [GitHub](https://github.com/docker/cli) `docker` command line interface;
* `docker-compose` - [GitHub](https://github.com/docker/compose) orchestration tool for containers;
* `gvisor-tap-vsock` - [GitHub](https://github.com/containers/gvisor-tap-vsock) the tool to provide networking for
accessing containers from Windows;
* `OpenSSH` - [home page](https://www.openssh.com/) SSH connectivity tool fork from [Powershell Github](https://github.com/PowerShell/openssh-portable);
* `Podman` - [home page](https://podman.io/) and [Github](https://github.com/containers/podman) free and open source
* `OpenSSH` - [home page](https://www.openssh.com/) SSH connectivity tool fork from [Powershell GitHub](https://github.com/PowerShell/openssh-portable);
* `Podman` - [home page](https://podman.io/) and [GitHub](https://github.com/containers/podman) free and open source
container runtime;
* `Podman Desktop` - [home page](https://podman-desktop.io/) and [Github](https://github.com/containers/podman-desktop)
* `Podman Desktop` - [home page](https://podman-desktop.io/) and [GitHub](https://github.com/containers/podman-desktop)
GUI companion to Podman;
* `QEMU` - [home page](https://www.qemu.org/) and [Github (mirror)](https://github.com/qemu/qemu) free and open source
* `QEMU` - [home page](https://www.qemu.org/) and [GitHub (mirror)](https://github.com/qemu/qemu) free and open source
feature rich machine emulator;
* `WinSocat` - [GitHub](https://github.com/firejox/WinSocat) socat-like windows-specific program;
* `Zlib` - [home page](https://www.zlib.net/) compression library.

### Versions and patches
Expand All @@ -53,10 +53,6 @@ Version `v27.4.0`. Rebuilt for Windows amd64 platform.

Version `v2.31.0`. Rebuilt for Windows amd64 platform.

#### `gocat`

Built from HEAD of the development branch. Added patch with updated dependencies.

#### `gvisor-tap-vsock`

Version bundled with Podman is used
Expand Down Expand Up @@ -86,6 +82,13 @@ Version `9.2.0` with 3 patch sets from QEMU mailing list:
* WHPX: Add support for device backed memory regions https://lists.gnu.org/archive/html/qemu-devel/2022-07/msg04837.html;
* Windows installer: keep dependency cache https://lists.gnu.org/archive/html/qemu-devel/2023-01/msg03125.html.

#### `WinSocat`

Version `0.1.3` with 3 patch sets:
* Pending commits after the release https://github.com/firejox/WinSocat/compare/v0.1.3...b7e32fa8f782ae38475cfc7cf1eed25de1fad339
* Dependency updates from https://github.com/firejox/WinSocat/pull/16
* Some additinal cleanups for VisualStudio solution setup

#### `Zlib`

Version `1.3` with 2 patches from main after release and from Powershell fork:
Expand Down
123 changes: 123 additions & 0 deletions patches/WinSocat/0001-Pending-0.1.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
From 0580ae45c013b66d88d51aa1de5715d51f796d43 Mon Sep 17 00:00:00 2001
From: Firejox <[email protected]>
Date: Sun, 28 May 2023 20:59:16 +0800
Subject: [PATCH 1/2] Update README.md

---
README.md | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/README.md b/README.md
index 5df26da..f7ecfb4 100644
--- a/README.md
+++ b/README.md
@@ -10,13 +10,21 @@
WinSocat is a socat-like program specific on Windows platform. It can bridge Windows named pipe and other general I/O, e.g., STDIO, TCP, the STDIO of Process.

## Installation
+There are several ways to install WinSocat.

+### .NET CLI
[Install .NET 6 or newer](https://get.dot.net) and install via `dotnet tool`

```
dotnet tool install -g winsocat
```

+### Windows Package Manager
+Install via `winget`
+```
+winget install -e --id Firejox.WinSocat
+```
+
## Command Form

The WinSocat is accept two address pattern

From b7e32fa8f782ae38475cfc7cf1eed25de1fad339 Mon Sep 17 00:00:00 2001
From: Firejox <[email protected]>
Date: Sun, 21 Apr 2024 21:27:31 +0800
Subject: [PATCH 2/2] Fix the bug when exe path contains space will result
error (#11)

---
Tests/ProcPiperInfoTest.cs | 2 ++
winsocat/AddressElement.cs | 2 +-
winsocat/Process.cs | 22 ++++++----------------
3 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/Tests/ProcPiperInfoTest.cs b/Tests/ProcPiperInfoTest.cs
index 16bafe0..2b1e122 100644
--- a/Tests/ProcPiperInfoTest.cs
+++ b/Tests/ProcPiperInfoTest.cs
@@ -34,6 +34,7 @@ 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);
@@ -41,6 +42,7 @@ public string FileNamePatternMatchTest(string input)
}

[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);
diff --git a/winsocat/AddressElement.cs b/winsocat/AddressElement.cs
index a768ba5..094ccff 100644
--- a/winsocat/AddressElement.cs
+++ b/winsocat/AddressElement.cs
@@ -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);
diff --git a/winsocat/Process.cs b/winsocat/Process.cs
index fe0ef28..84f3a4b 100644
--- a/winsocat/Process.cs
+++ b/winsocat/Process.cs
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.IO.Pipelines;
+using System.CommandLine.Parsing;

namespace Firejox.App.WinSocat;

@@ -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
Loading

0 comments on commit 76539ed

Please sign in to comment.