-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
123 lines (106 loc) · 2.48 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"errors"
"io/fs"
"os"
"path/filepath"
"github.com/ac0d3r/wxapkg"
"github.com/fatih/color"
"github.com/urfave/cli/v2"
)
var (
err_ = color.New(color.FgRed)
warn_ = color.New(color.FgYellow)
info_ = color.New(color.FgCyan)
)
func New() *cli.App {
app := cli.NewApp()
app.Name = "wxapkg"
app.Usage = "wxapkg analysis tool for macos"
app.Version = "v0.0.1"
app.Commands = []*cli.Command{
{
Name: "unpack",
Usage: "unpack .wxapkg file",
Flags: []cli.Flag{
&cli.StringFlag{Name: "in", Required: true, Usage: ".wxapkg file path"},
&cli.StringFlag{Name: "out", Required: false, Value: "./unpack_out", Usage: "unpacked output path"},
&cli.BoolFlag{Name: "format", Value: false, Usage: "format content (e.g. js html json)"},
&cli.BoolFlag{Name: "v", Value: false, Usage: "more info"},
},
Action: unpack,
},
{
Name: "list",
Usage: "list macOS Wechat .wxapkg file",
Flags: []cli.Flag{},
Action: list,
},
}
return app
}
func unpack(c *cli.Context) error {
in := c.String("in")
out := c.String("out")
v := c.Bool("v")
format := c.Bool("format")
info_.Printf("[+] unpacking %s -> %s \n", in, out)
var infof func(format string, a ...interface{}) = nil
if v {
infof = func(format string, a ...interface{}) {
info_.Printf(format, a...)
}
}
err := wxapkg.Unpack(in, out, format, infof)
if err != nil {
if errors.Is(err, wxapkg.ErrInvalidWXAPkg) {
err_.Printf("[-] '%s' %s\n", in, err.Error())
}
err_.Printf("[-] unpack '%s' error: %s \n", in, err.Error())
}
info_.Println("[+] unpacking completed")
return nil
}
func list(c *cli.Context) error {
warn_.Println("[*] only support WeChat version 3.8.*")
root := wxapkg.GetWXAppletPath()
info_.Printf("list %s\n", root)
stat, err := os.Stat(root)
if err != nil {
err_.Println("[-] not support WeChat version")
return err
}
if !stat.IsDir() {
err_.Println("[-] not support WeChat version")
return nil
}
var tab int
return filepath.Walk(root, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
if path == root {
return nil
}
tab++
info_.Printf("%s%s\n", getTabTree(tab), path)
} else {
info_.Printf("%s%s\n", getTabTree(tab), path)
}
return nil
})
}
func getTabTree(tab int) string {
s := ""
for i := 0; i < tab; i++ {
s += "\t"
}
return s
}
func main() {
if err := New().Run(os.Args); err != nil {
err_.Println()
err_.Printf("[-] %s\n", err.Error())
}
}