mitm/UTF8_FIX_README.md

76 lines
2.4 KiB
Markdown

# UTF-8 Encoding Fix for Chinese Windows Systems
## Problem
On Chinese Windows systems, the default console encoding is often GBK/GB2312, which causes garbled text when the MITM proxy outputs UTF-8 characters. This results in unreadable console output, especially for Unicode characters and symbols.
## Solution
This fix implements a comprehensive UTF-8 encoding solution for Windows systems:
### 1. Batch File Fixes
All batch files now include the command:
```batch
chcp 65001 >nul 2>&1
```
This sets the console code page to UTF-8 (65001) before running any commands.
**Fixed files:**
- `run.bat`
- `demo.bat`
- `build.bat`
- `test.bat`
### 2. Go Program Fixes
The main Go program now automatically sets the console to UTF-8 mode on Windows:
```go
// Set console to UTF-8 on Windows to prevent garbled text
if runtime.GOOS == "windows" {
setConsoleUTF8()
}
```
**Implementation details:**
- Added `setConsoleUTF8()` function that executes `chcp 65001`
- Automatic detection of Windows OS using `runtime.GOOS`
- Enhanced console output with UTF-8 symbols (✓, 🚀, 🛑, etc.)
### 3. Testing
A test script `utf8_test.bat` is provided to verify the fix works correctly:
```batch
utf8_test.bat
```
This script:
- Sets console to UTF-8
- Displays various Unicode characters (Chinese, Japanese, Korean)
- Runs the MITM proxy in test mode to verify UTF-8 output
## Usage
Simply run any of the batch files as usual. The UTF-8 encoding will be automatically configured:
```batch
run.bat # Start the proxy with UTF-8 support
demo.bat # Run the demo with UTF-8 support
utf8_test.bat # Test UTF-8 encoding specifically
```
## Verification
After applying the fix, you should see:
- ✓ Clear display of Unicode characters
- 🚀 Proper rendering of emoji symbols
- 正确显示中文字符 (Correct display of Chinese characters)
- 日本語の文字が正しく表示される (Japanese characters display correctly)
## Technical Notes
- Code page 65001 is the Windows UTF-8 code page
- The fix is automatically applied only on Windows systems
- No changes are needed for Linux/macOS systems
- The original functionality remains unchanged
## Compatibility
- Windows 10/11: Full support
- Windows 8/8.1: Full support
- Windows 7: Partial support (depends on system configuration)
- Chinese, Japanese, Korean Windows: Full support
- English Windows: Full support (no changes to existing behavior)