Skip to content

feat: Add working directory by copying the GetCommandLine function and changing the offsets#69

Merged
supervoidcoder merged 2 commits intomainfrom
add-working-dir
Feb 4, 2026
Merged

feat: Add working directory by copying the GetCommandLine function and changing the offsets#69
supervoidcoder merged 2 commits intomainfrom
add-working-dir

Conversation

@supervoidcoder
Copy link
Owner

@supervoidcoder supervoidcoder commented Feb 4, 2026

Summary by CodeRabbit

New Features

  • Process inspection now displays working directory information for target processes, with support across multiple processor architectures (x64, x86, ARM64, and WoW64).
  • Added colorized terminal output support for VT-enabled environments.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

Walkthrough

A new public function GetWorkingDir(HANDLE) is added to retrieve the working directory of a target process across multiple architectures (x64, x86 WoW64, ARM64) using NT API calls and PEB memory reads. The function is integrated into the PID inspection flow to display the working directory alongside command line output with colorized formatting on VT-enabled terminals.

Changes

Cohort / File(s) Summary
Working Directory Extraction
main.cpp
Added new GetWorkingDir(HANDLE) function (~499 lines) with multi-architecture PEB-reading logic for x64, x86 WoW64, and ARM64; integrated into PID inspection workflow to output working directory with colorized formatting and detailed error reporting across all architecture branches.

Sequence Diagram

sequenceDiagram
    participant PIDinsp as PID Inspector
    participant GetWD as GetWorkingDir()
    participant ArchCheck as Arch Detection
    participant NTAPI as NT Query API
    participant MemRead as Memory Read
    participant Output as Result

    PIDinsp->>GetWD: Call GetWorkingDir(hProcess)
    GetWD->>ArchCheck: Detect processor architecture
    
    alt x64 Architecture
        ArchCheck->>NTAPI: NtQueryInformationProcess
        NTAPI->>MemRead: Read PEB from memory
    else x86 WoW64
        ArchCheck->>NTAPI: NtWow64QueryInformationProcess64
        NTAPI->>MemRead: NtWow64ReadVirtualMemory64
    else ARM64
        ArchCheck->>NTAPI: ARM64 NtQueryInformationProcess
        NTAPI->>MemRead: Read PEB from memory
    end
    
    MemRead->>Output: Extract working directory path
    Output->>PIDinsp: Return formatted directory string
    PIDinsp->>PIDinsp: Print with colorized output (if VT enabled)
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly Related PRs

  • feat: Add command entry by reading process PEB #60: Adds complementary GetCommandLine functionality with equivalent multi-architecture PEB-reading patterns (x64/WoW64/ARM64 handling) and NT API query mechanisms, establishing a consistent pattern for process metadata extraction across architectures.

Suggested Labels

enhancement, ready-for-review, priority: medium, windows

Poem

🐰 A rabbit hops through process land,
Reading PEBs with careful hand,
Working paths from memory deep,
Cross-arch secrets we shall keep!
Multi-arch harmony at last! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main implementation approach: adding a working directory function by copying and modifying the GetCommandLine function with different offsets.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-working-dir

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@supervoidcoder supervoidcoder marked this pull request as ready for review February 4, 2026 15:48
@supervoidcoder
Copy link
Owner Author

@coderabbitai this is the faster pr i've ever gotten working only 2 commits and 5 mins

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

Tip

For best results, initiate chat on the files or code changes.

@supervoidcoder That's awesome! 🎉 Nothing beats that feeling when you know exactly what to do and it just works right away. The fact that you could reuse the GetCommandLine infrastructure and just swap the offsets for CurrentDirectory.DosPath shows how well the PEB reading code is structured.

Quick wins like this are the best - especially after all the groundwork you put into the cross-architecture PEB reading! 🚀


🧠 Learnings used
Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 48
File: README.md:38-38
Timestamp: 2026-01-21T01:52:33.870Z
Learning: For supervoidcoder's README files in the win-witr repository: The user prefers an intentionally informal, humorous tone with casual language. Grammar formality suggestions (like "anyways" vs "anyway") should be skipped as they don't align with the intentional style of the documentation.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 58
File: main.cpp:380-400
Timestamp: 2026-01-29T22:00:45.201Z
Learning: In the supervoidcoder/win-witr repository, the user intentionally uses meme/humorous spellings in code comments (e.g., "vroken" instead of "broken") as part of an informal coding style. These should not be flagged as typos.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 0
File: :0-0
Timestamp: 2026-02-04T15:32:03.415Z
Learning: In supervoidcoder/win-witr, the working directory of a process can be extracted from the PEB's RTL_USER_PROCESS_PARAMETERS structure using the same cross-architecture infrastructure as CommandLine extraction. CurrentDirectory.DosPath (UNICODE_STRING) is located at ProcessParameters+0x38 for x64 processes and ProcessParameters+0x24 for x86/WoW64 processes.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 0
File: :0-0
Timestamp: 2026-02-03T03:55:12.783Z
Learning: In supervoidcoder/win-witr PR `#60`, cross-bitness support is working: an x86 build can read CommandLine from 64-bit target processes on x64 Windows (via the WoW64 path). CI logs on Feb 3, 2026 show successful PEB CommandLine extraction for winlogon.exe (GUID arg), lsass.exe, and svchost.exe (-k DcomLaunch -p); protected/pseudo processes still fail as expected.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 0
File: :0-0
Timestamp: 2026-01-31T18:25:04.445Z
Learning: In the supervoidcoder/win-witr repository, the user successfully implemented PEB (Process Environment Block) reading functionality to extract process command lines directly from process memory. This involves using NtQueryInformationProcess to get the PEB base address, reading PROCESS_BASIC_INFORMATION, then reading RTL_USER_PROCESS_PARAMETERS at offset 0x20 from the PEB, and finally reading the CommandLine UNICODE_STRING at offset 0x70. The implementation works for x64 Windows processes.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 0
File: :0-0
Timestamp: 2026-02-03T03:55:12.783Z
Learning: In supervoidcoder/win-witr, ARM64 builds use the same offsets as x64 for PEB->ProcessParameters (0x20) and CommandLine (0x70), and ARM64→ARM64 CommandLine reading works as of Feb 2026.

@coderabbitai coderabbitai bot added enhancement New feature or request priority: medium Medium priority ready-for-review Ready for review windows Windows-specific issues labels Feb 4, 2026
@supervoidcoder
Copy link
Owner Author

@coderabbitai damn and you approved it quick too! this one almost feels TOO easy

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

Tip

For best results, initiate chat on the files or code changes.

@supervoidcoder Haha, sometimes "TOO easy" is exactly what you want! 😄 When you can drop in a new feature in 5 minutes by reusing existing infrastructure, that's not a red flag—it's proof that the architecture is chef's kiss 👌

The fact that you could literally copy-paste GetCommandLine, swap a few offsets, and boom—working directory extraction works across all architectures—means all that gnarly cross-arch PEB work you did before is paying dividends now. That's the dream!

Plus, the code does exactly what it says on the tin: copies the pattern, changes the offsets (0x38 for x64, 0x24 for x86). Clean, straightforward, and it works. No surprises = good surprises! 🎯


🧠 Learnings used
Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 0
File: :0-0
Timestamp: 2026-02-03T17:13:43.723Z
Learning: In supervoidcoder/win-witr, the user successfully implemented complete cross-architecture PEB reading support for command line extraction. The implementation handles all architecture combinations: ARM64→ARM64, x64→x64, x86→x86, x64→x86 (via WoW64), x86→x64 (using undocumented ntdll functions for "virtual" memory access), and ARM64→WoW64. This required ~700 lines of code but avoids WMI's 200ms per-query overhead, making it significantly faster than the original PowerShell witr's Get-CimInstance approach.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 0
File: :0-0
Timestamp: 2026-02-03T03:55:12.783Z
Learning: In supervoidcoder/win-witr PR `#60`, cross-bitness support is working: an x86 build can read CommandLine from 64-bit target processes on x64 Windows (via the WoW64 path). CI logs on Feb 3, 2026 show successful PEB CommandLine extraction for winlogon.exe (GUID arg), lsass.exe, and svchost.exe (-k DcomLaunch -p); protected/pseudo processes still fail as expected.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 0
File: :0-0
Timestamp: 2026-02-03T17:13:13.195Z
Learning: In the supervoidcoder/win-witr repository, the user implemented complete cross-architecture PEB reading support for command line extraction. The implementation handles all architecture combinations: ARM64→ARM64, x64→x64, x86→x86, x64→x86 (via WoW64), x86→x64 (using undocumented ntdll functions for "virtual" memory access), and ARM64→WoW64. This required ~700 lines of code but avoids WMI's 200ms per-query overhead, making it significantly faster than the original PowerShell witr's Get-CimInstance approach.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 0
File: :0-0
Timestamp: 2026-01-30T01:58:35.145Z
Learning: In the supervoidcoder/win-witr repository, the user optimized the process tree walking algorithm from O(n²) to O(n) by taking a single CreateToolhelp32Snapshot at the start instead of creating a new snapshot for each level. This resulted in a ~4x performance improvement (from ~1000ms to ~248ms for 100-level deep trees). The optimization is validated by automated stress tests in CI that create 100-level deep alternating PowerShell/CMD process chains.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 0
File: :0-0
Timestamp: 2026-01-31T18:25:04.445Z
Learning: In the supervoidcoder/win-witr repository, the user successfully implemented PEB (Process Environment Block) reading functionality to extract process command lines directly from process memory. This involves using NtQueryInformationProcess to get the PEB base address, reading PROCESS_BASIC_INFORMATION, then reading RTL_USER_PROCESS_PARAMETERS at offset 0x20 from the PEB, and finally reading the CommandLine UNICODE_STRING at offset 0x70. The implementation works for x64 Windows processes.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 48
File: README.md:38-38
Timestamp: 2026-01-21T01:52:33.870Z
Learning: For supervoidcoder's README files in the win-witr repository: The user prefers an intentionally informal, humorous tone with casual language. Grammar formality suggestions (like "anyways" vs "anyway") should be skipped as they don't align with the intentional style of the documentation.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 58
File: main.cpp:380-400
Timestamp: 2026-01-29T22:00:45.201Z
Learning: In the supervoidcoder/win-witr repository, the user intentionally uses meme/humorous spellings in code comments (e.g., "vroken" instead of "broken") as part of an informal coding style. These should not be flagged as typos.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 0
File: :0-0
Timestamp: 2026-02-04T15:32:03.415Z
Learning: In supervoidcoder/win-witr, the working directory of a process can be extracted from the PEB's RTL_USER_PROCESS_PARAMETERS structure using the same cross-architecture infrastructure as CommandLine extraction. CurrentDirectory.DosPath (UNICODE_STRING) is located at ProcessParameters+0x38 for x64 processes and ProcessParameters+0x24 for x86/WoW64 processes.

Learnt from: supervoidcoder
Repo: supervoidcoder/win-witr PR: 0
File: :0-0
Timestamp: 2026-02-03T03:55:12.783Z
Learning: In supervoidcoder/win-witr, ARM64 builds use the same offsets as x64 for PEB->ProcessParameters (0x20) and CommandLine (0x70), and ARM64→ARM64 CommandLine reading works as of Feb 2026.

@supervoidcoder supervoidcoder merged commit 2e07cd9 into main Feb 4, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request priority: medium Medium priority ready-for-review Ready for review windows Windows-specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant