Conversation
Convert protocol templates (HTTP, POST, Redis, SMTP) to raw string literals so backslashes are preserved. Change payload_to_printf to convert actual newlines to literal "\r\n" in the "Escapes" mode. In NcCommandBuilder, convert literal "\r\n" sequences back to real newlines for the payload preview so the GUI shows human-readable output. These tweaks make escaping consistent between storage, formatting, and display.
Replace minimal platform notes with a full Build (Portable / Single-file) guide. Adds per-OS PyInstaller commands and expected outputs for Windows, macOS, and Linux, macOS .icns conversion notes, and system-wide/user install instructions. Also adds the netcat-logo.ico asset used by the examples.
Add icon assets (netcat-logo.ico, netcat-logo.png, netcat-logo.svg) under icons/ and update main.py to load them at startup. The code checks APP_DIR/icons, uses iconbitmap() with the .ico on Windows and PhotoImage + iconphoto() with the .png (keeping a reference in self._icon_img) so the application window shows the app icon across platforms.
Move icon assets into an icons/ subdirectory and update build instructions to match. Update Windows and macOS pyinstaller commands to use icons/netcat-logo.(ico|png), adjust macOS icon conversion steps to read/write from icons/, produce icons/netcat-logo.icns, and clarify the macOS output as dist/nc-command-builder.app.
Update packaging docs to include --add-data for icons (Windows uses "icons;icons", macOS uses "icons:icons"). In code, add RESOURCE_DIR that uses sys._MEIPASS when frozen and switch icon_dir to RESOURCE_DIR/icons so the packaged executable can locate bundled icon resources.
Reformat the macOS pyinstaller invocation and update options: switch from --onefile to --onedir to produce a bundle directory, add --osx-bundle-identifier to set the app bundle ID, and normalize the icon/add-data arguments. The change makes the macOS build produce a proper .app bundle and improves readability of the command.
Update payload_to_printf to provide safer, more comprehensive escaping for the "Escapes (\\r\\n, \\x41)" mode and clarify its docstring. The new implementation iterates the input and normalizes CRLF/newlines, escapes backslashes, double quotes, shell metacharacters ($, `), doubles percent signs to avoid printf format interpolation, and encodes control characters (and DEL) as \xNN. Docstring updated to state output is safe for use inside shell double quotes. Other modes (Plain text, Hex) remain unchanged.
Strengthen escaping in payload_to_printf. Plain text mode now additionally escapes "$" and backtick to avoid shell expansion and keep payload/preview identical. Escapes mode switches to a \"\xNN\"-style encoding for spaces, quotes, %, \, $, backticks, control characters and DEL, while preserving alphanumerics and safe punctuation. Simplifies multiple per-char branches into a single encode set and updates comments to explain the encoding rationale.
Add robust handling for URL-encoding and single-quote escaping in payloads. Introduce _URL_SAFE, _url_encode_uri, and _escape_for_single_quotes helpers and import re. Rework payload_to_printf to accept send_method, normalize line endings, URL-encode the URI in HTTP request lines for Escapes mode, and escape single quotes/backslashes in headers/body while preserving readability. Update build_command to pass send_method and choose single vs double quotes depending on mode and send method so printf/echo -e invocations are correctly quoted.
Update .gitignore to add a custom ignore section and exclude test.json from version control to prevent committing local test data.
Detect HTTP request lines and auto-append the required blank line between headers and body. Introduces an is_http flag, consolidates result assembly, and appends '\r\n\r\n' when a detected HTTP payload is missing the terminating CRLF sequence to ensure correct HTTP formatting when using printf-style output.
Update PyInstaller commands in build.md to use platform-specific artifact names to avoid collisions: --name values changed to `nc-command-builder-win`, `nc-command-builder-mac`, and `nc-command-builder-linux` for the Windows, macOS, and Linux examples respectively. This clarifies the generated build outputs in the documentation.
There was a problem hiding this comment.
Pull request overview
This PR updates payload escaping/encoding behavior for generated netcat commands, improves template display handling, adds packaged app icon support, and expands build instructions.
Changes:
- Adds URL-style encoding helpers and shell quoting changes for payload generation.
- Converts protocol templates to raw strings and displays template CRLFs as readable newlines.
- Adds icon resource loading plus updated platform build documentation and ignore rules.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
main.py |
Updates payload encoding, command quoting, template insertion, and window icon loading. |
icons/netcat-logo.svg |
Adds SVG source asset for the app icon. |
build.md |
Replaces minimal notes with platform-specific PyInstaller build/install instructions. |
.gitignore |
Adds a local test.json ignore rule. |
Comments suppressed due to low confidence (1)
build.md:73
- These install commands no longer match the platform-specific outputs documented above: the macOS build creates an
.appbundle, and the Linux build uses thenc-command-builder-linuxname. Split the macOS and Linux install steps or update the paths so users can copy an artifact that actually exists and is executable fromPATH.
### macOS / Linux
```bash
sudo cp dist/nc-command-builder /usr/local/bin/
</details>
---
💡 <a href="/swarfte/nc-command-builder/new/main?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
Comment on lines
+67
to
+71
| Single-quoted strings can't contain literal '. We encode it as | ||
| {pct}27 (the URL-encoded form). Backslashes are doubled so that | ||
| printf/echo-e interpret \\ as a literal backslash. | ||
| """ | ||
| return line.replace('\\', '\\\\').replace("'", f'{pct}27') |
Comment on lines
+114
to
+119
| # Auto-append if the user didn't include one. | ||
| if is_http: | ||
| if not result.endswith('\\r\\n'): | ||
| result += '\\r\\n' | ||
| if not result.endswith('\\r\\n\\r\\n'): | ||
| result += '\\r\\n' |
| uv run pyinstaller --icon=icons/netcat-logo.ico --add-data "icons;icons" --onefile --windowed --name "nc-command-builder-win" main.py | ||
| ``` | ||
|
|
||
| Output: `dist/nc-command-builder.exe` |
| main.py | ||
| ``` | ||
|
|
||
| Output: `dist/nc-command-builder.app` |
|
|
||
| ```bash | ||
| uv run pyinstaller --onefile --windowed --name "nc-command-builder" main.py | ||
| uv run pyinstaller --onefile --windowed --name "nc-command-builder-linux" main.py |
| uv run pyinstaller --onefile --windowed --name "nc-command-builder-linux" main.py | ||
| ``` | ||
|
|
||
| Output: `dist/nc-command-builder` |
Comment on lines
+59
to
+60
| f'{pct}{ord(ch):02X}' if ch not in _URL_SAFE else ch | ||
| for ch in uri |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request makes several improvements to the build documentation, payload encoding, and user interface of the application. The most significant changes include detailed build instructions for multiple platforms, enhanced payload encoding for shell safety and HTTP requests, and improved handling of application icons across operating systems.
Build process and documentation:
build.mdwith comprehensive, platform-specific build instructions for Windows, macOS, and Linux, including icon handling and installation steps.Payload encoding and command generation:
payload_to_printfand related helpers inmain.pyto provide safer and more accurate encoding for shell commands, especially for HTTP requests and shell quoting. Added logic to URL-encode HTTP URIs, escape for shell single quotes, and auto-append required HTTP line endings.'for escapes mode,"otherwise) and pass thesend_methodtopayload_to_printffor correct percent encoding.User interface improvements:
.icoon Windows and.pngon other platforms, ensuring the icon displays correctly in the UI.\r\nsequences for better readability.Other codebase updates:
import reto support new regular expression usage for HTTP request detection.