/
winptylib.go
89 lines (77 loc) · 3.04 KB
/
winptylib.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
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may not
// use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing
// permissions and limitations under the License.
//
// +build windows
//winpty package is wrapper package for calling procedures of winpty.dll
package winpty
import (
"syscall"
)
const (
WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN = 1
NIL_POINTER_VALUE = 0
DEFAULT_WINPTY_FLAGS = 0
WINPTY_FLAG_IMPERSONATE_THREAD = 0x10
CREATE_FILE_CREATE_MODE = syscall.OPEN_EXISTING
CREATE_FILE_MODE = 0
CREATE_FILE_ATTRS = 0
CREATE_FILE_TEMPLATE = 0
CONIN_FILE_ACCESS = syscall.GENERIC_WRITE
CONOUT_FILE_ACCESS = syscall.GENERIC_READ
STDIN_FILE_NAME = "stdin"
STDOUT_FILE_NAME = "stdout"
WINPTY_ERROR_SPAWN_CREATE_PROCESS_FAILED uint32 = 2
)
var (
winpty_error_code,
winpty_error_msg,
winpty_error_free,
winpty_config_new,
winpty_config_free,
winpty_config_set_initial_size,
winpty_open,
winpty_conin_name,
winpty_conout_name,
winpty_spawn_config_new,
winpty_spawn_config_free,
winpty_spawn,
winpty_set_size,
winpty_free *syscall.LazyProc
)
var winptyModule *syscall.LazyDLL
//loadDll gets lazydll for winpty.dll which gets loaded once it's procedures are called
func loadDll(winptyDllFilePath string) {
winptyModule = syscall.NewLazyDLL(winptyDllFilePath)
}
//defineProcedures gets lazyproc for winpty.dll procedures
func defineProcedures() {
// Error handling.
winpty_error_code = winptyModule.NewProc("winpty_error_code")
winpty_error_msg = winptyModule.NewProc("winpty_error_msg")
winpty_error_free = winptyModule.NewProc("winpty_error_free")
// Configuration of a new agent.
winpty_config_new = winptyModule.NewProc("winpty_config_new")
winpty_config_free = winptyModule.NewProc("winpty_config_free")
winpty_config_set_initial_size = winptyModule.NewProc("winpty_config_set_initial_size")
// Start the agent.
winpty_open = winptyModule.NewProc("winpty_open")
// I/O Pipes
winpty_conin_name = winptyModule.NewProc("winpty_conin_name")
winpty_conout_name = winptyModule.NewProc("winpty_conout_name")
// Agent RPC Calls
winpty_spawn_config_new = winptyModule.NewProc("winpty_spawn_config_new")
winpty_spawn_config_free = winptyModule.NewProc("winpty_spawn_config_free")
winpty_spawn = winptyModule.NewProc("winpty_spawn")
winpty_set_size = winptyModule.NewProc("winpty_set_size")
winpty_free = winptyModule.NewProc("winpty_free")
}