Commit 5852043
committed
feat: add Windows platform support with ETW, inline hooking, and Npcap
This commit ports eCapture to Windows (amd64/arm64), replacing eBPF
uprobes/kprobes with platform-native alternatives: ETW (Event Tracing
for Windows) for kernel-level telemetry and pure-Go x64 inline
function hooking for DLL export interception.
## Core Infrastructure
### ETW Integration (pkg/util/etw/)
- etw_windows.go: Full ETW session lifecycle via advapi32.dll
(StartTraceW, EnableTraceEx2, OpenTraceW, ProcessTrace,
ControlTraceW), event record structs, thread-safe shutdown with
WaitGroup + mutex.
- schannel_windows.go: Schannel provider event parser covering
handshake complete/failure, extended handshake log, SSL log events,
and alert events. Decodes counted UTF-16 strings from ETW property
buffers.
- etw_stub.go: No-op stub for non-Windows builds.
### Inline Function Hooking (pkg/util/hook/)
- hook_windows.go: HookManager with reference-counted module loading
(loadModuleRef/freeModuleRef) to prevent dangling function pointers
after FreeLibrary. Double-checked locking for concurrent AddHook.
- trampoline_windows.go: Pure-Go x64 inline hook implementation with
minimal instruction-length decoder, 12-byte absolute jump patching
(mov rax, addr; jmp rax), FlushInstructionCache via kernel32.dll,
and invokeTrampoline through syscall.Syscall6.
- hook_stub.go: Stub for non-Windows builds with matching API surface.
### Npcap/WinPcap Capture (pkg/util/pcap/)
- npcap_windows.go: Packet capture via gopacket/pcap, implementing
domain.Event interface with Start/Stop/readLoop and interface
discovery helper (FindInterface).
### Platform Adaptation Layer
- pkg/util/kernel/: Windows kernel version detection via
RtlGetVersion (kernel_version_windows.go), Version type
(version_windows.go), stubs for non-Windows/non-Linux builds.
- pkg/util/ebpf/: Windows stubs for BPF config (bpf_windows.go),
cgroup (cgroup_windows.go), and elibpcap (elibpcap_windows.go).
- pkg/util/roratelog/: Platform-specific chown handling split into
rorate_chown.go (Unix) and rorate_chown_windows.go.
## Probe Implementations
### Fully Implemented (5 probes)
- **TLS/OpenSSL** (internal/probe/openssl/*_windows.go): ETW
Schannel provider for TLS handshake/key/certificate events +
OpenSSL DLL hooking (SSL_read/SSL_write) for plaintext capture.
Supports --schannel flag for Schannel-only mode.
- **Bash/Shell** (internal/probe/bash/*_windows.go): ETW PowerShell
ScriptBlock/Command events + cmd.exe process creation auditing.
Supports --shell-type flag (powershell/cmd/auto).
- **GoTLS** (internal/probe/gotls/*_windows.go): PE binary symbol
resolution for crypto/tls.Read/Write + inline hooking of Go
binaries compiled for Windows.
- **MySQL** (internal/probe/mysql/*_windows.go): DLL hooking of
mysql_real_query in libmysql.dll / mysqlclient-*.dll with query
string extraction and structured event output.
- **PostgreSQL** (internal/probe/postgres/*_windows.go): DLL hooking
of PQexec in libpq.dll with query string extraction and structured
event output.
### Stub Probes (3 probes — not applicable on Windows)
- GnuTLS, NSPR, Zsh: register_windows.go returns "not supported"
error via factory registration.
## CLI Layer
- cli/cmd/tls_windows.go: Windows TLS subcommand with --schannel.
- cli/cmd/bash_windows.go: Windows Shell subcommand with --shell-type.
- cli/cmd/gotls_windows.go: Windows GoTLS subcommand.
- cli/cmd/mysqld_windows.go: Windows MySQL subcommand.
- cli/cmd/postgres_windows.go: Windows PostgreSQL subcommand.
- cli/cmd/env_detection_windows.go: Windows version check
(Build 17763+), administrator privilege verification, architecture
validation (amd64/arm64).
- cli/cmd/upgrade_windows.go: Upgrade stub (no-op on Windows).
- cli/http/config_factory_windows.go: HTTP config factory stub.
## Build System
- Makefile: Added `windows` and `windows-arm64` targets.
- variables.mk / functions.mk: Windows cross-compile variables and
build functions.
- builder/Makefile.release: Added release_windows, snapshot_windows,
snapshot_windows_arm64 targets producing .zip artifacts.
- .github/workflows/release.yml: Integrated Windows build step into
CI/CD pipeline (runs after Linux/Android, before publish).
## Build Tag Strategy
- Added `!windows` build tag to 23 existing Linux-only source files
(probe implementations, config parsers using debug/elf, eBPF
utilities, CLI commands, and upgrade logic).
- Updated `!ecap_android` to `!ecap_android && !windows` on 14 files
that already had Android exclusions.
- All new Windows files use `//go:build windows` constraint.
## E2E Test Suite (test/e2e/windows/)
- common_windows.ps1: Shared helpers (Test-Admin, Get-EcaptureBinary,
Start-Ecapture, Stop-Ecapture, Test-OutputContains).
- windows_tls_test.ps1: TLS capture tests (text mode + keylog mode).
- windows_bash_test.ps1: Shell capture tests (PowerShell + cmd).
- windows_pcap_test.ps1: Network packet capture tests.
- windows_mysql_test.ps1: MySQL query capture tests.
- windows_postgres_test.ps1: PostgreSQL query capture tests.
## Documentation
- docs/compilation.md: Added "Compiling for Windows" section.
- docs/compilation-zh_Hans.md: Added "Windows 编译" section.
- doc/eCapture-Windows-Technical-Report.md: Updated roadmap to
reflect all 6 phases completed, corrected probe matrix, file
inventory, and architecture tables.
## Summary
- 68 files modified (build tags, platform guards, build system)
- 54 files added (probes, utilities, CLI, tests, docs)
- Build verified: `go build -tags windows ./...` ✓
- Vet verified: `go vet -tags windows -unsafeptr=false ./...` ✓
Signed-off-by: digger yu <digger-yu@outlook.com>1 parent 97c1c1a commit 5852043
118 files changed
Lines changed: 5947 additions & 115 deletions
File tree
- .github/workflows
- builder
- cli
- cmd
- http
- docs
- internal
- errors
- probe
- base
- bash
- gnutls
- gotls
- mysql
- nspr
- openssl
- postgres
- zsh
- pkg
- upgrade
- util
- ebpf
- etw
- hook
- kernel
- pcap
- roratelog
- test/e2e
- windows
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
102 | 120 | | |
| 121 | + | |
103 | 122 | | |
104 | 123 | | |
105 | 124 | | |
106 | 125 | | |
107 | | - | |
| 126 | + | |
108 | 127 | | |
109 | 128 | | |
110 | 129 | | |
111 | 130 | | |
112 | 131 | | |
113 | 132 | | |
114 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
115 | 140 | | |
116 | 141 | | |
117 | 142 | | |
| |||
122 | 147 | | |
123 | 148 | | |
124 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
125 | 213 | | |
126 | 214 | | |
127 | 215 | | |
128 | | - | |
| 216 | + | |
129 | 217 | | |
130 | 218 | | |
131 | 219 | | |
132 | 220 | | |
133 | 221 | | |
134 | | - | |
135 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
136 | 226 | | |
137 | 227 | | |
138 | | - | |
| 228 | + | |
139 | 229 | | |
140 | 230 | | |
141 | 231 | | |
| |||
146 | 236 | | |
147 | 237 | | |
148 | 238 | | |
149 | | - | |
| 239 | + | |
| 240 | + | |
150 | 241 | | |
| 242 | + | |
151 | 243 | | |
152 | | - | |
153 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
154 | 247 | | |
155 | 248 | | |
156 | 249 | | |
157 | 250 | | |
158 | 251 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
163 | 256 | | |
164 | 257 | | |
165 | | - | |
166 | | - | |
167 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
168 | 266 | | |
169 | 267 | | |
170 | 268 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
110 | 113 | | |
111 | 114 | | |
112 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
96 | 102 | | |
97 | 103 | | |
98 | 104 | | |
| |||
111 | 117 | | |
112 | 118 | | |
113 | 119 | | |
| 120 | + | |
114 | 121 | | |
115 | 122 | | |
116 | 123 | | |
| |||
202 | 209 | | |
203 | 210 | | |
204 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
205 | 267 | | |
206 | 268 | | |
207 | 269 | | |
| |||
0 commit comments