-
Notifications
You must be signed in to change notification settings - Fork 63
/
xray.go
112 lines (97 loc) · 3.22 KB
/
xray.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
package main
import (
"bufio"
"bytes"
"fmt"
"golang.org/x/text/encoding/simplifiedchinese"
"os"
"os/exec"
"runtime"
"strings"
"time"
)
var xraytime = "2022-02-09"
type Charset string
const (
UTF8 = Charset("UTF-8")
GB18030 = Charset("GB18030")
)
func ConvertByte2String(byte []byte, charset Charset) string {
var str string
switch charset {
case GB18030:
var decodeBytes, _ = simplifiedchinese.GB18030.NewDecoder().Bytes(byte)
str = string(decodeBytes)
case UTF8:
fallthrough
default:
str = string(byte)
}
return str
}
func Cmd(args []byte) <-chan struct{} {
//case "windows":
args = bytes.Trim(args, " ")
argss := strings.Split("/C "+string(args), " ")
cmd := exec.Command("c:\\windows\\system32\\cmd.exe", argss...)
closed := make(chan struct{})
defer close(closed)
stdoutPipe, err := cmd.StdoutPipe()
if err != nil {
panic(err)
}
defer stdoutPipe.Close()
go func() {
scanner := bufio.NewScanner(stdoutPipe)
for scanner.Scan() { // 命令在执行的过程中, 实时地获取其输出
cmdRe := ConvertByte2String(scanner.Bytes(), UTF8) //编码
fmt.Printf("%s\n", string(cmdRe))
}
}()
if err := cmd.Run(); err != nil {
panic(err)
}
return closed
}
func init() {
log := `
██╗ ██╗██████╗ █████╗ ██╗ ██╗ ██████╗██╗ ██╗███████╗ ██████╗██╗ ██╗
╚██╗██╔╝██╔══██╗██╔══██╗╚██╗ ██╔╝ ██╔════╝██║ ██║██╔════╝██╔════╝██║ ██╔╝
╚███╔╝ ██████╔╝███████║ ╚████╔╝ ██║ ███████║█████╗ ██║ █████╔╝
██╔██╗ ██╔══██╗██╔══██║ ╚██╔╝ ██║ ██╔══██║██╔══╝ ██║ ██╔═██╗
██╔╝ ██╗██║ ██║██║ ██║ ██║███████╗╚██████╗██║ ██║███████╗╚██████╗██║ ██╗
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═════╝╚═╝ ╚═╝
--by:GOGOGO(Need UAC)
------------------------------------------------------------------------------------
`
fmt.Print(log)
}
func SetTime(settime string) {
time.Sleep(time.Duration(1) * time.Second)
Cmd([]byte("date "+settime))
}
func main() {
args := os.Args
var xrayargs string
var xray string
for x := 1; x < len(args); x++ {
if len(args) == 1 {
xrayargs = ""
break
}
xrayargs = xrayargs + " " + args[x]
}
settime := time.Now().Format("2006-01-02")
//fmt.Println(settime)
Cmd([]byte("date " + xraytime))
switch runtime.GOOS {
case "windows":
xray = "xray.exe"
//case "darwin":
// xray = "./xray"
//case "linux":
// xray = "./xray"
}
go SetTime(settime)
<-Cmd([]byte(xray + xrayargs))
}