Skip to content

Commit

Permalink
feat: 新增还原wxml功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Ackites committed Aug 4, 2024
1 parent 136d059 commit 9fcb258
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 117 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ builds:
- CGO_ENABLED=0
goos:
- windows
- darwin

archives:
- format: binary
Expand Down
11 changes: 2 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cmd

import (
"flag"
"fmt"
"log"
"sync"

Expand All @@ -11,13 +9,7 @@ import (
"github.com/Ackites/KillWxapkg/internal/restore"
)

func Execute(appID, input, outputDir, fileExt string, restoreDir bool, pretty bool) {
if appID == "" || input == "" {
fmt.Println("使用方法: program -id=<AppID> -in=<输入文件1,输入文件2> 或 -in=<输入目录> -out=<输出目录> [-ext=<文件后缀>] [-restore]")
flag.PrintDefaults()
return
}

func Execute(appID, input, outputDir, fileExt string, restoreDir bool, pretty bool, noClean bool) {
// 存储配置
configManager := NewSharedConfigManager()
configManager.Set("appID", appID)
Expand All @@ -26,6 +18,7 @@ func Execute(appID, input, outputDir, fileExt string, restoreDir bool, pretty bo
configManager.Set("fileExt", fileExt)
configManager.Set("restoreDir", restoreDir)
configManager.Set("pretty", pretty)
configManager.Set("noClean", noClean)

inputFiles := ParseInput(input, fileExt)

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.22

require (
github.com/ditashi/jsbeautifier-go v0.0.0-20141206144643-2520a8026a9c
github.com/dop251/goja v0.0.0-20240707163329-b1681fb2a2f5
github.com/gorilla/css v1.0.1
github.com/dop251/goja v0.0.0-20240731150404-c665f0b58f6e
github.com/tdewolff/parse/v2 v2.7.15
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4
golang.org/x/crypto v0.25.0
golang.org/x/net v0.27.0
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ github.com/ditashi/jsbeautifier-go v0.0.0-20141206144643-2520a8026a9c h1:+Zo5Ca9
github.com/ditashi/jsbeautifier-go v0.0.0-20141206144643-2520a8026a9c/go.mod h1:HJGU9ULdREjOcVGZVPB5s6zYmHi1RxzT71l2wQyLmnE=
github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dop251/goja v0.0.0-20240707163329-b1681fb2a2f5 h1:ZRqTaoW9WZ2DqeOQGhK9q73eCb47SEs30GV2IRHT9bo=
github.com/dop251/goja v0.0.0-20240707163329-b1681fb2a2f5/go.mod h1:o31y53rb/qiIAONF7w3FHJZRqqP3fzHUr1HqanthByw=
github.com/dop251/goja v0.0.0-20240731150404-c665f0b58f6e h1:jhfevGje1Gw4uDNv30Kj+tl/SpHb4La9InZOnwMrNUs=
github.com/dop251/goja v0.0.0-20240731150404-c665f0b58f6e/go.mod h1:o31y53rb/qiIAONF7w3FHJZRqqP3fzHUr1HqanthByw=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg=
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
github.com/tdewolff/parse/v2 v2.7.15 h1:hysDXtdGZIRF5UZXwpfn3ZWRbm+ru4l53/ajBRGpCTw=
github.com/tdewolff/parse/v2 v2.7.15/go.mod h1:3FbJWZp3XT9OWVN3Hmfp0p/a08v4h8J9W1aghka0soA=
github.com/tdewolff/test v1.0.11-0.20231101010635-f1265d231d52 h1:gAQliwn+zJrkjAHVcBEYW/RFvd2St4yYimisvozAYlA=
github.com/tdewolff/test v1.0.11-0.20231101010635-f1265d231d52/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 h1:0sw0nJM544SpsihWx1bkXdYLQDlzRflMgFJQ4Yih9ts=
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4/go.mod h1:+ccdNT0xMY1dtc5XBxumbYfOUhmduiGudqaDgD2rVRE=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
Expand Down
4 changes: 4 additions & 0 deletions internal/config/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func (f *FileDeletionManager) DeleteFiles() {
log.Println("文件删除操作已取消")
return
default:
// 判断文件是否存在
if _, err := os.Stat(file); os.IsNotExist(err) {
continue
}
err := os.Remove(file)
if err != nil {
log.Printf("删除文件 %s 失败: %v\n", file, err)
Expand Down
36 changes: 34 additions & 2 deletions internal/restore/decompiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func isParserV1(wxapkg *config.WxapkgInfo) bool {
}
}

func isParserV3(wxapkg *config.WxapkgInfo) bool {
func isParserV2(wxapkg *config.WxapkgInfo) bool {
switch wxapkg.WxapkgType {
case enum.App_V3, enum.App_V4, enum.APP_SUBPACKAGE_V2, enum.APP_PLUGIN_V1:
return true
Expand Down Expand Up @@ -89,6 +89,7 @@ func (d *WxapkgDecompiler) Decompile(outputDir string) {

wxapkgManager := config.GetWxapkgManager()
for _, wxapkg := range wxapkgManager.Packages {
log.Println(wxapkg.WxapkgType)
switch wxapkg.WxapkgType {
case enum.App_V1, enum.App_V4:
wxapkg.Option = &config.WxapkgOption{
Expand Down Expand Up @@ -152,8 +153,39 @@ func setApp(wxapkg *config.WxapkgInfo) {
}

wxapkg.Parsers = append(wxapkg.Parsers, &unpack.JavaScriptParser{OutputDir: OutputDir})
wxapkg.Parsers = append(wxapkg.Parsers, &unpack.XssParser{OutputDir: OutputDir})
if isParserV1(wxapkg) {
wxapkg.Parsers = append(wxapkg.Parsers, &unpack.XmlParser{OutputDir: OutputDir, Version: "v1"})
} else if isParserV2(wxapkg) {
wxapkg.Parsers = append(wxapkg.Parsers, &unpack.XmlParser{OutputDir: OutputDir, Version: "v2"})
}

// 清除无用文件
cleanApp(wxapkg.SourcePath)
}

func cleanApp() {
func cleanApp(path string) {
// 创建文件删除管理器
manager := config.NewFileDeletionManager()

// 删除相关的JS文件, unlinks
unlinks := []string{
//".appservice.js",
"appservice.js",
"app-config.json",
"app-service.js",
"app-wxss.js",
"appservice.app.js",
"common.app.js",
"page-frame.js",
"page-frame.html",
"pageframe.js",
"webview.app.js",
"subContext.js",
"plugin.js",
}

for _, unlink := range unlinks {
manager.AddFile(filepath.Join(path, unlink))
}
}
14 changes: 11 additions & 3 deletions internal/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,20 @@ func ProjectStructure(outputDir string, restoreDir bool) {
return
}

configManager := config.NewSharedConfigManager()

// 创建文件删除管理器
manager := config.NewFileDeletionManager()

defer func() {
if noClean, ok := configManager.Get("noClean"); ok {
if !noClean.(bool) {
// 执行删除文件操作
manager.DeleteFiles()
}
}
}()

// 包管理器
wxakpgManager := config.GetWxapkgManager()

Expand All @@ -60,7 +71,4 @@ func ProjectStructure(outputDir string, restoreDir bool) {
// 创建命令执行器, 执行解析器
executor := NewCommandExecutor(wxakpgManager)
executor.ExecuteAll()

// 执行删除文件操作
manager.DeleteFiles()
}
94 changes: 0 additions & 94 deletions internal/unpack/fileMagicNumbers.go

This file was deleted.

Loading

0 comments on commit 9fcb258

Please sign in to comment.