Skip to content

feat: add support for utf-8 transcoding and unicode console mode for exec commands#62

Open
Vladyslav Nikonov (vnikonov-devolutions) wants to merge 2 commits into
masterfrom
feat/exec-unicode
Open

feat: add support for utf-8 transcoding and unicode console mode for exec commands#62
Vladyslav Nikonov (vnikonov-devolutions) wants to merge 2 commits into
masterfrom
feat/exec-unicode

Conversation

@vnikonov-devolutions
Copy link
Copy Markdown
Contributor

@vnikonov-devolutions Vladyslav Nikonov (vnikonov-devolutions) commented May 12, 2026

This PR updates now proto to v1.6, adding the following:

  • now-proto now requires agent to implement server-side OEM code page transcoding to UTF-8.
  • By default redirected IO for cmd, PowerShell5 and PowerShell7 now automatically transcoded to UTF-8. Current RDM implementation already expects UTF-8, so when new agent version will be installed, "garbaged input" issue DGW-370 will be automatically fixed.
  • Note that for process execution mode, raw (no-transcoding) is still default, but transcoding could be enabled by NOW_EXEC_FLAG_PROCESS_ENCODING_UTF8 flag instead, as process execution is more advanced use case usually needed for bit-bit output, so no explicit transcoding is provided.
  • Added NOW_CAP_EXEC_UNICODE_CONSOLE capability to signify that new flags are supported and the redirected streams are indeed correct utf-8.
  • [testing] Updated CLI test app for encoding testing purposes

Comment thread dotnet/Devolutions.NowProto/src/Messages/NowMsgExecBatch.cs
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR bumps NOW-PROTO to v1.6 and introduces encoding-control support for exec commands, including OEM→UTF-8 transcoding controls and a Unicode console mode signal via a new capability flag.

Changes:

  • Add new exec flags for RAW_ENCODING, UNICODE_CONSOLE, and PROCESS_ENCODING_UTF8 across Rust + .NET message models/builders.
  • Add NOW_CAP_EXEC_UNICODE_CONSOLE capability + bump protocol version to 1.6 (Rust/.NET + docs/tests).
  • Expand the .NET CLI test app to exercise the new flags and help validate encoding behavior.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
rust/now-proto-testsuite/tests/proto/channel.rs Updates roundtrip expectations for protocol minor version bump (1.5 → 1.6).
rust/now-proto-pdu/src/exec/win_ps.rs Adds WinPS exec flags + builder/query helpers for raw encoding and unicode console mode.
rust/now-proto-pdu/src/exec/pwsh.rs Adds Pwsh exec flags + builder/query helpers (reusing WinPS flag set).
rust/now-proto-pdu/src/exec/process.rs Adds process flag + helpers for enabling OEM→UTF-8 transcoding.
rust/now-proto-pdu/src/exec/batch.rs Adds batch flags + helpers for raw encoding and unicode console mode.
rust/now-proto-pdu/src/channel/capset.rs Adds capability flag + bumps NowProtoVersion::CURRENT to 1.6.
dotnet/Devolutions.NowProto/src/NowProtoVersion.cs Bumps .NET protocol version constant to 1.6.
dotnet/Devolutions.NowProto/src/Messages/NowMsgExecWinPs.cs Adds WinPS message flags + builder toggles + exposed properties.
dotnet/Devolutions.NowProto/src/Messages/NowMsgExecPwsh.cs Adds Pwsh message flags + builder toggles + exposed properties.
dotnet/Devolutions.NowProto/src/Messages/NowMsgExecProcess.cs Adds EncodingUtf8 flag support to serialization/deserialization + builder.
dotnet/Devolutions.NowProto/src/Messages/NowMsgExecBatch.cs Adds batch raw/unicode-console flags support to serialization/deserialization + builder.
dotnet/Devolutions.NowProto/src/Capabilities/NowCapabilityExec.cs Adds UnicodeConsole capability and includes it in All.
dotnet/Devolutions.NowClient/src/ExecWinPsParams.cs Exposes new WinPS params to set raw/unicode-console and maps them to message flags.
dotnet/Devolutions.NowClient/src/ExecPwshParams.cs Exposes new Pwsh params to set raw/unicode-console and maps them to message flags.
dotnet/Devolutions.NowClient/src/ExecProcessParams.cs Exposes new process param EncodingUtf8 and maps it to the message flag.
dotnet/Devolutions.NowClient/src/ExecBatchParams.cs Exposes new batch params to set raw/unicode-console and maps them to message flags.
dotnet/Devolutions.NowClient.Cli/Program.cs Adds interactive commands and output capture to test cmd/winps/pwsh encoding flags.
docs/NOW-spec.md Updates spec to 1.6 and documents the new flags/capability + encoding behavior notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

///
/// NOW-PROTO: NOW_CAP_EXEC_IO_REDIRECTION
const IO_REDIRECTION = 0x1000;
/// Set if host supports encoding control flags for exec commands\n /// (RAW_ENCODING, UNICODE_CONSOLE, and ENCODING_UTF8 flags).
Comment on lines 7 to 8


Comment thread docs/NOW-spec.md
Comment on lines +1140 to +1142
**Encoding behavior (Pwsh):** PowerShell 7 (pwsh) defaults to UTF-8 output natively, so no OEM transcoding is performed by default.
`NOW_EXEC_FLAG_PS_RAW_ENCODING` has no additional effect since pwsh already outputs UTF-8.
Set `NOW_EXEC_FLAG_PS_UNICODE_CONSOLE` to inject the encoding setup snippet for explicit UTF-8 console configuration.
Comment thread docs/NOW-spec.md

**Encoding behavior:** By default, batch (cmd.exe) output is transcoded from OEM encoding to UTF-8, since cmd.exe uses the system OEM code page.
Set `NOW_EXEC_FLAG_BATCH_RAW_ENCODING` to disable transcoding and pass raw bytes through unchanged.
Set `NOW_EXEC_FLAG_BATCH_UNICODE_CONSOLE` to inject `@chcp 65001 > nul` and pass UTF-8 streams directly without transcoding.
@vnikonov-devolutions
Copy link
Copy Markdown
Contributor Author

Copilot please open PR for issues found after review; also please fix dotnet tests (tests fail after default capabilities were changed)

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

Vladyslav Nikonov (@vnikonov-devolutions) I've opened a new pull request, #63, to work on those changes. Once the pull request is ready, I'll request review from you.

…s/comments (#63)

This follow-up addresses post-review issues from the UTF-8 transcoding /
Unicode console support work. It fixes failing .NET capset snapshot
tests after the protocol default/version change and resolves
documentation/comment formatting gaps flagged in review.

- **.NET tests: update capset wire snapshots for protocol v1.6**
- Updated expected encoded bytes in channel capset tests to match
`NowProtoVersion.Current = 1.6`.

- **Spec: clarify combined RAW + UNICODE behavior**
  - Clarified behavior for batch and WinPS when both flags are set:
    - Agent **MUST** enable Unicode console mode for process startup.
    - Agent **MUST NOT** perform stdout/stderr transcoding.
- Returned output is raw process output bytes; clients **MUST NOT**
assume a specific output encoding.
  - Fixed inline-code formatting for `NOW_EXEC_FLAG_PS_RAW_ENCODING`.

- **Rust docs: fix malformed doc comment rendering**
- Removed literal `\n` sequence and corrected indentation in
`NowExecCapsetFlags::UNICODE_CONSOLE` docs so rustdoc renders correctly.

- **C# formatting: remove accidental blank lines**
  - Cleaned extra blank lines in `NowProtoVersion.cs` near `Current`.

```csharp
// MsgChannel capset expected version bytes updated from 1.5 to 1.6
// before: ... 0x01, 0x00, 0x05, 0x00, ...
// after:  ... 0x01, 0x00, 0x06, 0x00, ...
```

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: vnikonov-devolutions <246051166+vnikonov-devolutions@users.noreply.github.com>
Copy link
Copy Markdown
Member

@CBenoit Benoît Cortier (CBenoit) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants