diff --git a/README.md b/README.md index 9cc3224..c1d839f 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,46 @@ # wxapkg -> **Disclaimer**: This tool is only for the purpose of learning and studying the design ideas and principles contained within the software. Users shall assume all legal and related liabilities resulting from the use of this tool! The author shall not be held liable for any legal consequences! -> > **免责声明**:此工具仅限于学习和研究软件内含的设计思想和原理,用户承担因使用此工具而导致的所有法律和相关责任!作者不承担任何法律责任! -**Usage:** +**🎨 用法** ![demo](demo.gif) -- scan mini program +- 微信小程序扫描 + 解密 + 解包 + > 不指定参数的话,会在默认安装目录扫描小程序 wxid,然后获取小程序信息(需要网络) + + 键盘上下键选中想要处理的小程序,然后按回车 ```bash - # wxapkg.exe scan --help wxapkg.exe scan ``` -- unpack mini program - - ```bash - # wxapkg.exe unpack --help +- 单独解密 + 解包指定的微信小程序 + > 指定小程序路径,自动获取 wxid 然后解密解包 + ```bash wxapkg.exe unpack -o out-dir -r "%USERPROFILE%\Documents\WeChat Files\Applet\wx00000000000000" ``` -**Install:** +**⚒️ 安装** -Download the latest [release](https://github.com/wux1an/wxapkg/releases/latest) or build with `go install` by yourself +下载最新的发布版本 [release](https://github.com/wux1an/wxapkg/releases/latest),或者用下面的命令自己编译 ``` go install github.com/wux1an/wxapkg@latest ``` -**Todo:** +**📝 其他功能** -- [x] scan more information (need networking) -- [x] json beautify -- [x] javascript beautify -- [x] html beautify -- [ ] auto export uri in files +- [x] 获取小程序信息(需要网络连接) +- [x] 代码美化,默认开启,可以使用 `--disable-beautify` 参数禁用 + - [x] 美化 `JSON` 文件 + - [x] 美化 `JavaScript` 文件(会有点慢) + - [x] 美化 `Html` 文件,包括其中的 ``) +var jsOptions = jsbeautifier.DefaultOptions() + +func PrettyJson(data []byte) []byte { + return pretty.Pretty(data) +} + +func PrettyHtml(data []byte) []byte { + data = gohtml.FormatBytes(bytes.TrimSpace(data)) // use `TrimSpace` to remove leading whitespace + data = regScriptInHtml.ReplaceAllFunc(data, func(script []byte) []byte { + var space = countLeadingSpaces(script) + + var jsCode = regScriptInHtml.FindSubmatch(script)[1] + var jsStr = strings.Repeat(" ", space+2) + string(bytes.TrimSpace(jsCode)) + + beautify, err := jsbeautifier.Beautify(&jsStr, jsOptions) + if err == nil { + return bytes.Replace(script, jsCode, []byte("\n"+beautify+"\n"+strings.Repeat(" ", space)), 1) + } + return script + }) + return data +} + +func PrettyJavaScript(data []byte) []byte { + var code = string(bytes.TrimSpace(data)) // use `TrimSpace` to remove leading whitespace + beautify, err := jsbeautifier.Beautify(&code, jsOptions) + if err != nil { + return data + } + + return []byte(beautify) +} + +func countLeadingSpaces(data []byte) int { + var result = 0 + for _, c := range data { + if c == ' ' { + result++ + } else { + return result + } + } + + return result +}