How nmap/npcap works
Project type and purpose
• Npcap is a system-level packet capture and injection library for Windows.
• It consists of a kernel-mode driver (npf.sys), user-mode helper services, a WinPcap-compatible API (wpcap.dll/Packet.dll), installer modules, SDK headers/libs, example apps, build scripts, and documentation.
File structure
Top-level directories:
– Common: shared header definitions for both driver and user-mode components.
– wpcap: WinPcap API compatibility layer (wpcap.dll).
– packetWin7: kernel-mode driver source (npf) and helper projects for Windows 7+ (NDIS, WFP).
– installer: scripts and projects for driver/service installation (NPFInstall, registry, callouts).
– Examples-pcap & Examples: sample applications showing how to call the API.
– docs: API reference, developer guide, internals docs (XML/HTML/PDF).
– test: test harness, scripts, props.
– build scripts (.bat, .cmake) at root to build SDK, examples, libs, docs.
README for additional insights
• The README confirms Npcap replaces WinPcap, improves speed, reliability, security, and includes OEM licensing.
• It points to a developer guide and internals documentation that describe driver internals, installer behavior, and API usage.
a. Main components to include
– Kernel-mode driver (“npf.sys”): interfaces with NDIS/WFP to capture/inject packets.
– User-mode API libraries (wpcap.dll / Packet.dll): expose pcap_* functions, wrap DeviceIoControl calls.
– Helper service (NpcapHelper.exe): user-mode service for loopback capture via Windows Filtering Platform (WFP).
– Installer service (NPFInstall.exe / callout modules): installs and registers the driver, helper service, loopback interfaces.
– Example applications: UDPdump, basic_dump, stats, etc., linking against wpcap.dll.
– Build & packaging scripts: build_sdk.bat, build_lib, create_examples, installer scripts.
– Documentation assets (docs folder): XML/HTML/PDF guides, developer reference.
b. Relationships and data flow
1. Installation flow: installer scripts ➔ NPFInstall.exe ➔ installs npf.sys driver as Windows service ➔ registers device names, callouts.
2. Runtime capture flow: user app calls pcap_open_live (wpcap.dll) ➔ DeviceIoControl to npf.sys ➔ driver hooks NDIS/WFP, captures packets ➔ buffers returned to wpcap.dll ➔ user app processes data.
3. Injection flow: user app calls pcap_sendpacket ➔ wpcap.dll ➔ DeviceIoControl to driver ➔ driver injects packet via NDIS.
4. Loopback capture: NpcapHelper.exe registers WFP callouts ➔ intercepts loopback traffic ➔ forwards packets to driver capture paths.
5. Build flow: build scripts invoke MSBuild/CMake to compile driver, libraries, examples; produce SDK package.
c. Architectural patterns / design principles
– Layered architecture:
• Kernel layer: driver interacts with Windows networking stack.
• API layer: WinPcap-compatible DLLs.
• Application layer: sample and third-party apps.
• Installer layer: separate installer for service registration and security.
– Separation of concerns: capture/inject in kernel, API abstraction in DLL, loopback in helper service.
– Compatibility shim: wpcap.dll implements old WinPcap API over new driver.
– Modular build: scripts orchestrate discreet build steps for docs, examples, libs, installer.
d. Key technologies / frameworks
– Windows NDIS (Driver), WFP (loopback).
– Visual C++ solutions/projects (.vcxproj) for driver, helper, installer, examples.
– CMake, batch scripts for cross-component builds.
– XML/HTML for documentation generation.