How javeleyqaq/wechatopendevtools-python works
Project type and purpose
• This is a Python-based command-line tool (“WeChatOpenDevTools-Python”) whose purpose is to hook into the WeChat desktop application or its built-in browser and automatically enable F12 devtools (for WeChat mini-programs or the in-App browser). Its core functionality is process-injection and automation of WeChat’s developer tools UI.
File structure
• Top level:
• main.py: the CLI entry point, parses flags (-x, -c) and kicks off the hook flow.
• requirements.txt: Python dependencies.
• configs/: multiple JSON files keyed by WeChat mini-program version, used to locate memory addresses for patching.
• WechatOpenDevTools/: a Python package (wrapping process-attach & patch logic).
• utils/: helper modules (banner printing, colorized logs, common routines, WeChat-specific utilities).
• scripts/hook.js: the JavaScript shim that actually injects into the target process (via Node or an embedded JS engine).
• docs/: user documentation.
• workflows/: CI/CD definitions (GitHub Actions for dev and release).
README
• Describes supported WeChat versions, usage commands (python main.py -x to open mini-program F12, -c to open built-in browser F12), troubleshooting, and the fact that the code is a Python 3 rewrite of an existing Node.js tool.
Components
a. Main components
1. User/CLI Interface (main.py)
2. Configuration Manager (configs/*.json)
3. Hook Engine
– Python layer (WechatOpenDevTools package)
– JavaScript shim (scripts/hook.js)
4. Utilities (utils/*.py)
5. External WeChat Process (Windows or Mac desktop app)
6. CI/CD Pipeline (workflows/*.yml)
7. Documentation subsystem (docs/)—optional side component
b. Relationships and data flow
• User invokes main.py -> CLI parser
• CLI parser consults Configuration Manager to select JSON based on target WeChat version
• CLI calls into the Hook Engine (Python API in WechatOpenDevTools)
• Hook Engine loads and executes scripts/hook.js (via embedded JS runtime or Node child process)
• Hook Engine uses OS-level process APIs to attach to the WeChat process (using addresses from the config JSON)
• JS shim patches memory or injects code to enable F12 dev-tools
• Optionally, CI/CD workflows build and publish releases automatically
c. Architectural patterns and design principles
– Modular separation: CLI layer vs. business logic (WechatOpenDevTools) vs. low-level hook scripts
– Configuration-driven: JSON files isolate version-specific addresses from code
– Utility library: DRY principles in utils/ for logging, common routines, and process discovery
– CI/CD as code: workflows/ directory holds GitHub Actions definitions
d. Key technologies, frameworks, or libraries
– Python 3.9+
– JSON for configs
– Embedded JavaScript (Node.js or other JS engine) for hook.js
– GitHub Actions for dev.yml and release.yml
– pip requirements (psutil, pexpect, etc., as listed in requirements.txt)
• Entry points (CLI): rectangle in green
• Hook Engine (Python modules): rectangle in blue
• JS shim (scripts/hook.js): rectangle in purple
1. User → CLI
2. CLI → Config Manager (read JSON)
3. CLI → Hook Engine API
4. Hook Engine → JS shim (execute)
5. JS shim → WeChat Process (attach/inject)
6. WeChat Process → Hook Engine (callback or status)
7. Hook Engine → CLI (result)