Skip to content

Using URL-encoding in escape type - #3

Merged
swarfte merged 13 commits into
mainfrom
dev
May 28, 2026
Merged

Using URL-encoding in escape type#3
swarfte merged 13 commits into
mainfrom
dev

Conversation

@swarfte

@swarfte swarfte commented May 27, 2026

Copy link
Copy Markdown
Owner

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:

  • Updated build.md with comprehensive, platform-specific build instructions for Windows, macOS, and Linux, including icon handling and installation steps.

Payload encoding and command generation:

  • Refactored payload_to_printf and related helpers in main.py to 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.
  • Modified command generation to use appropriate quoting (' for escapes mode, " otherwise) and pass the send_method to payload_to_printf for correct percent encoding.

User interface improvements:

  • Added logic to set the application window icon using .ico on Windows and .png on other platforms, ensuring the icon displays correctly in the UI.
  • Improved template insertion: when selecting a template, the display now shows human-readable newlines instead of literal \r\n sequences for better readability.

Other codebase updates:

  • Updated template definitions to use raw strings for HTTP and protocol payloads, ensuring escape sequences are handled as intended.
  • Added import re to support new regular expression usage for HTTP request detection.

swarfte added 12 commits May 27, 2026 17:13
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.
Copilot AI review requested due to automatic review settings May 27, 2026 16:57

Copilot AI left a comment

Copy link
Copy Markdown

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 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 .app bundle, and the Linux build uses the nc-command-builder-linux name. Split the macOS and Linux install steps or update the paths so users can copy an artifact that actually exists and is executable from PATH.
### 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 thread main.py
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 thread main.py
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'
Comment thread build.md
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`
Comment thread build.md
main.py
```

Output: `dist/nc-command-builder.app`
Comment thread build.md

```bash
uv run pyinstaller --onefile --windowed --name "nc-command-builder" main.py
uv run pyinstaller --onefile --windowed --name "nc-command-builder-linux" main.py
Comment thread build.md
uv run pyinstaller --onefile --windowed --name "nc-command-builder-linux" main.py
```

Output: `dist/nc-command-builder`
Comment thread main.py
Comment on lines +59 to +60
f'{pct}{ord(ch):02X}' if ch not in _URL_SAFE else ch
for ch in uri
@swarfte
swarfte merged commit 1b31622 into main May 28, 2026
1 check failed
Copilot stopped work on behalf of swarfte due to an error May 28, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants