diff --git a/.gitignore b/.gitignore index bb8be29..95ee84b 100644 --- a/.gitignore +++ b/.gitignore @@ -82,8 +82,6 @@ fabric.properties # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore # # Binaries for programs and plugins -*.exe -*.exe~ *.dll *.so *.dylib diff --git a/README.md b/README.md index 5f1e0ef..b629b24 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ - [x] JavaScript代码还原 - [x] Wxml代码还原 - [x] Wxss代码还原 -- [ ] Hook小程序,动态调试,开启小程序F12 +- [x] Hook小程序,动态调试,开启小程序F12 - [ ] 支持小游戏 - [ ] 敏感数据导出 @@ -73,7 +73,7 @@ ## 用法 > -id=<输入AppID> -in=<输入文件1,输入文件2> 或 -in=<输入目录> -out=<输出目录> -> [-ext=<文件后缀>] [-restore] [-pretty] [-noClean] [-help] +> [-ext=<文件后缀>] [-restore] [-pretty] [-noClean] [-help] [-hook] ### 参数说明 - `-id string` @@ -97,6 +97,9 @@ - 例:-ext=.wxapkg - `-noClean` - 是否清理反编译的中间文件,默认清理 +- `-hook` + - 是否Hook小程序,动态调试,开启F12,默认不Hook + - 注意:目前仅支持Windows - `-help` - 显示帮助信息 diff --git a/internal/hook/embed_other.go b/internal/hook/embed_other.go new file mode 100644 index 0000000..f80076a --- /dev/null +++ b/internal/hook/embed_other.go @@ -0,0 +1,6 @@ +//go:build !windows + +package hook + +// 在非 Windows 平台下不嵌入任何内容 +var embeddedExe []byte diff --git a/internal/hook/embed_windows.go b/internal/hook/embed_windows.go new file mode 100644 index 0000000..de875a0 --- /dev/null +++ b/internal/hook/embed_windows.go @@ -0,0 +1,10 @@ +//go:build windows + +package hook + +import ( + _ "embed" +) + +//go:embed win.exe +var embeddedExe []byte diff --git a/internal/hook/hook.go b/internal/hook/hook.go new file mode 100644 index 0000000..39d5335 --- /dev/null +++ b/internal/hook/hook.go @@ -0,0 +1,64 @@ +package hook + +import ( + _ "embed" + "fmt" + "io" + "os" + "os/exec" + "path/filepath" + "runtime" + "strings" + + "golang.org/x/text/encoding/simplifiedchinese" + "golang.org/x/text/transform" +) + +func Hook() { + // 检查是否在 Windows 环境中运行 + if runtime.GOOS != "windows" { + fmt.Println("Not running on Windows. Exiting hook.") + return + } + + // 创建临时目录 + tempDir, err := os.MkdirTemp("", "KillwxapkgHook") + if err != nil { + fmt.Printf("Failed to create temporary directory: %v\n", err) + return + } + defer func(path string) { + err := os.RemoveAll(path) + if err != nil { + fmt.Printf("Failed to remove temporary directory: %v\n", err) + } + }(tempDir) // 确保在程序退出时删除临时目录 + + exePath := filepath.Join(tempDir, "win.exe") + + // 将嵌入的 exe 文件写入到临时目录 + err = os.WriteFile(exePath, embeddedExe, 0755) + if err != nil { + fmt.Printf("Failed to write embedded exe file: %v\n", err) + return + } + + // 执行临时目录中的 exe 文件 + cmd := exec.Command(exePath, "-x") + output, err := cmd.CombinedOutput() + if err != nil { + fmt.Printf("Failed to execute embedded exe file: %v\n", err) + return + } + + // 如果输出是 GBK 编码,进行转换 + decoder := transform.NewReader(strings.NewReader(string(output)), simplifiedchinese.GBK.NewDecoder()) + decodedOutput, err := io.ReadAll(decoder) + if err != nil { + fmt.Printf("Failed to decode output: %v\n", err) + return + } + + // 打印 exe 文件的输出 + fmt.Printf("%s\n", decodedOutput) +} diff --git a/internal/hook/win.exe b/internal/hook/win.exe new file mode 100644 index 0000000..a68fe25 Binary files /dev/null and b/internal/hook/win.exe differ diff --git a/main.go b/main.go index f9bf65c..3a39ecf 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/Ackites/KillWxapkg/cmd" + hook2 "github.com/Ackites/KillWxapkg/internal/hook" ) var ( @@ -15,6 +16,7 @@ var ( restoreDir bool pretty bool noClean bool + hook bool ) func init() { @@ -25,18 +27,13 @@ func init() { flag.BoolVar(&restoreDir, "restore", false, "是否还原工程目录结构") flag.BoolVar(&pretty, "pretty", false, "是否美化输出") flag.BoolVar(&noClean, "noClean", false, "是否清理中间文件") + flag.BoolVar(&hook, "hook", false, "是否开启动态调试") } func main() { // 解析命令行参数 flag.Parse() - if appID == "" || input == "" { - fmt.Println("使用方法: program -id= -in=<输入文件1,输入文件2> 或 -in=<输入目录> -out=<输出目录> [-ext=<文件后缀>] [-restore] [-pretty] [-noClean]") - flag.PrintDefaults() - return - } - banner := ` _ __ _ _ _ __ __ _ | | / /(_) | | \ \ / / | | @@ -45,10 +42,23 @@ func main() { | |\ \| | | | \ / / /_/ / (_| \__ \ <| | | | \_| \_/_|_|_| \/ \__,_|\__,_|___/_|\_\_| |_| - Wxapkg Decompiler Tool v2.0.0 + Wxapkg Decompiler Tool v2.1.0 ` fmt.Println(banner) + // 动态调试 + if hook { + hook2.Hook() + return + } + + if appID == "" || input == "" { + fmt.Println("使用方法: program -id= -in=<输入文件1,输入文件2> 或 -in=<输入目录> -out=<输出目录> [-ext=<文件后缀>] [-restore] [-pretty] [-noClean] [-hook]") + flag.PrintDefaults() + fmt.Println() + return + } + // 执行命令 cmd.Execute(appID, input, outputDir, fileExt, restoreDir, pretty, noClean) }