Skip to content

Commit

Permalink
feat: 新增hook功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Ackites committed Aug 5, 2024
1 parent 5b2a03a commit 7a2eb65
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 11 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
- [x] JavaScript代码还原
- [x] Wxml代码还原
- [x] Wxss代码还原
- [ ] Hook小程序,动态调试,开启小程序F12
- [x] Hook小程序,动态调试,开启小程序F12
- [ ] 支持小游戏
- [ ] 敏感数据导出

Expand Down Expand Up @@ -73,7 +73,7 @@
## 用法

> -id=<输入AppID> -in=<输入文件1,输入文件2> 或 -in=<输入目录> -out=<输出目录>
> [-ext=<文件后缀>] [-restore] [-pretty] [-noClean] [-help]
> [-ext=<文件后缀>] [-restore] [-pretty] [-noClean] [-help] [-hook]
### 参数说明
- `-id string`
Expand All @@ -97,6 +97,9 @@
- 例:-ext=.wxapkg
- `-noClean`
- 是否清理反编译的中间文件,默认清理
- `-hook`
- 是否Hook小程序,动态调试,开启F12,默认不Hook
- 注意:目前仅支持Windows
- `-help`
- 显示帮助信息

Expand Down
6 changes: 6 additions & 0 deletions internal/hook/embed_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build !windows

package hook

// 在非 Windows 平台下不嵌入任何内容
var embeddedExe []byte
10 changes: 10 additions & 0 deletions internal/hook/embed_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build windows

package hook

import (
_ "embed"
)

//go:embed win.exe
var embeddedExe []byte
64 changes: 64 additions & 0 deletions internal/hook/hook.go
Original file line number Diff line number Diff line change
@@ -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)
}
Binary file added internal/hook/win.exe
Binary file not shown.
24 changes: 17 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/Ackites/KillWxapkg/cmd"
hook2 "github.com/Ackites/KillWxapkg/internal/hook"
)

var (
Expand All @@ -15,6 +16,7 @@ var (
restoreDir bool
pretty bool
noClean bool
hook bool
)

func init() {
Expand All @@ -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=<AppID> -in=<输入文件1,输入文件2> 或 -in=<输入目录> -out=<输出目录> [-ext=<文件后缀>] [-restore] [-pretty] [-noClean]")
flag.PrintDefaults()
return
}

banner := `
_ __ _ _ _ __ __ _
| | / /(_) | | \ \ / / | |
Expand All @@ -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=<AppID> -in=<输入文件1,输入文件2> 或 -in=<输入目录> -out=<输出目录> [-ext=<文件后缀>] [-restore] [-pretty] [-noClean] [-hook]")
flag.PrintDefaults()
fmt.Println()
return
}

// 执行命令
cmd.Execute(appID, input, outputDir, fileExt, restoreDir, pretty, noClean)
}

0 comments on commit 7a2eb65

Please sign in to comment.