-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_windows.go
60 lines (50 loc) · 1.21 KB
/
func_windows.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
//go:build windows
// +build windows
package main
import (
"fmt"
"io"
"os"
"time"
"github.com/UserExistsError/conpty"
)
/*
v2023-10-07.1520
v2023-10-13.1445; refactored sendX commands
*/
var cptyInstance *conpty.ConPty
// conpty func for windows pty support
func initializeConPTY(fullCmd string) error {
var err error
cptyInstance, err = conpty.Start(fullCmd)
if err != nil {
return err
}
return nil
}
// sendX func
func windowsSendCmd(cmd string, stdin io.Writer) {
_, err := cptyInstance.Write([]byte(cmd + "\n"))
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to send '%s' command: %v", cmd, err)
}
}
// initialize OS specific logic
func initializeAndExecute(cmdStr string, timeT int, crackT int, debug bool) {
err := initializeConPTY(cmdStr)
if err != nil {
fmt.Fprintln(os.Stderr, "Error initializing ConPTY:", err)
return
}
sendB = func(stdin io.Writer) { windowsSendCmd("b", stdin) }
sendQ = func(stdin io.Writer) {
windowsSendCmd("q", stdin)
cptyInstance.Close()
time.Sleep(1 * time.Second)
os.Exit(0)
}
// listen for user commands
go ReadUserInput(cptyInstance)
// initialize common logic
initializeAndExecuteCommon(cmdStr, timeT, crackT, debug, cptyInstance, cptyInstance, checkOS)
}