How lich0821/wechatferry works
The WeChatFerry project is essentially a native Windows library (a DLL) that provides a “play-with-WeChat” functionality. It not only implements core capabilities such as fetching QR codes, sending various message types (text, image, file, etc.), managing contacts and chatrooms, and even handling advanced operations like decrypting images and monitoring friend applications – but it also exposes these capabilities to multiple client platforms (Python, Java, Go, NodeJS, Rust, etc.) via various clients built on top.
Main Components
• Core Modules (inside the WeChatFerry folder):
– com: Contains logging utilities and common helper functions used across the project.
– rpc: Handles remote procedure calls. This includes protocol buffers using nanopb, the proto definitions, associated encoding/decoding routines, and a set of generator tools for building the protocol interfaces.
– sdk: Implements DLL injection and startup functionality. This is central to exposing the core functionalities of WeChatFerry.
– smc: Contains the modules related to Silk-MP3 conversion – a specialized functionality.
– spy: Implements the “spy” functions that realize the core business logic (account management, message handling, database querying, etc.).
• Client Wrappers (in the clients folder):
– Multiple client folders (python, java, go, node, rust, http, etc.) indicate that the core functionality is wrapped in various programming languages and paradigms.
– These clients interact with the core system via the exposed SDK functionality (e.g., through the dll “sdk.dll” or HTTP interfaces).
• External Dependencies & Build Support:
– Build configurations: Visual Studio solution (WeChatFerry.sln), CMake/vcpkg integration (vcpkg.json, .editorconfig), and GitHub workflows for continuous integration.
– Protocol buffer generation tools and nanopb libraries reside under the rpc subtree.
Relationships and Interactions
• The Core DLL (produced mainly from the sdk, spy, and supporting modules) exposes functions for initializing the SDK, processing messages, and performing operations.
• The rpc module isolates protocol definitions and provides a means to serialize and deserialize message data – this is key for the interoperability with external clients.
• Clients in various languages (Python, Go, Java, etc.) use either direct DLL bindings or REST/HTTP interfaces (for example, clients/go_wcf_http, clients/node) to interact with the core DLL functionality.
• Communication flows:
• Clients call into the exposed API of the DLL (via language-specific bindings).
• The DLL (via the spy, rpc, and sdk modules) performs operations internally (logging, message parsing, etc.) and may use nanopb-backed protocol functionality.
• External tools (the rpc/tool scripts, Makefiles, and protoc binaries) are used during the build/generation phase to keep the protocol definitions in sync.
Important Patterns and Design Principles
• Modular architecture: The separation of concerns is evident (common utilities separate from RPC, SDK, and core “spy” functionalities).
• Language interoperability: The design supports multiple programming language clients through well-defined protocol interfaces and DLL exports.
• RPC & Protobuf usage: The nanopb integration (with proto definitions, code generators, etc.) reveals an emphasis on lightweight communication protocols.
• Injection and Hooking: The sdk module is in charge of injecting and hooking into the WeChat process – an aspect that is central to the project’s capability to “play” with WeChat.
Relevant Technologies, Frameworks, and Tools
• Visual Studio 2019 is used as the primary IDE/build system.
• Protobuf and nanopb for RPC/serialization.
• vcpkg for dependency management.
• Python (for SDK testing, client prototypes, and generating some parts of the protocol buffers).
• GitHub Actions workflows as seen in .github/workflows.
• Multiple language runtimes (as indicated by client directories).
Specific Elements
• Each main component (com, rpc, sdk, smc, spy) should be presented as a labelled block inside an overall “Core DLL” container.
• External tools and configuration elements such as version control (GitHub workflows), vcpkg, and protoc tool should be represented to show how they support build and deployment.
• Initialization flow (client → DLL: e.g., sdk.WxInitSDK())
• Action calls (client commands → spy, via DLL interface or RPC).
• Data flow from RPC module to clients (message serialization/deserialization).
Final Rendering
• Don’t hesitate to further break down the internal parts of the core system if needed (e.g., show that “rpc” internally uses nanopb and code generation tools).
Happy diagramming!