-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrsp.go
201 lines (195 loc) · 5.9 KB
/
rsp.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
// The rsp package implements the RSP client protocol.
//
// # Introduction
//
// This document specifies the Remote Shutdown Protocol. The Remote Shutdown Protocol
// is a remote procedure call (RPC)-based protocol used to shut down or terminate shutdown
// on a remote computer.
//
// # Overview
//
// The Remote Shutdown Protocol is designed for shutting down a remote computer or for
// terminating the shutdown of a remote computer during the shutdown waiting period.
// Following are some of the examples of this protocol's applications:
//
// * Shut down a remote computer and display a message in the shutdown dialog box for
// 30 seconds.
//
// * Terminate a requested remote system shutdown during the shutdown waiting period.
//
// * Force applications to be closed, log off users, and shut down a remote computer.
//
// * Reboot a remote computer.
//
// In this document, the use of the terms client and server are in the protocol client
// and server context. This means that the client will initiate an RPC call and the
// server will respond.
//
// This is an RPC-based protocol. The protocol operation is stateless.
//
// This is a simple request-response protocol. For every method that the server receives,
// it executes the method and returns a completion. The client simply returns the completion
// status to the caller. This is a stateless protocol; each method call is independent
// of any previous method calls.
package rsp
import (
"context"
"fmt"
"strings"
"unicode/utf16"
dcerpc "github.com/oiweiwei/go-msrpc/dcerpc"
errors "github.com/oiweiwei/go-msrpc/dcerpc/errors"
uuid "github.com/oiweiwei/go-msrpc/midl/uuid"
ndr "github.com/oiweiwei/go-msrpc/ndr"
)
var (
_ = context.Background
_ = fmt.Errorf
_ = utf16.Encode
_ = strings.TrimPrefix
_ = ndr.ZeroString
_ = (*uuid.UUID)(nil)
_ = (*dcerpc.SyntaxID)(nil)
_ = (*errors.Error)(nil)
)
var (
// import guard
GoPackage = "rsp"
)
// UnicodeString structure represents REG_UNICODE_STRING RPC structure.
//
// This REG_UNICODE_STRING structure represents a counted string of Unicode (UTF-16)
// characters.
type UnicodeString struct {
// Length: The number of bytes actually used by the string. Because all UTF-16 characters
// occupy 2 bytes, this MUST be an even number in the range [0...65534]. The behavior
// for odd values is unspecified.
Length uint16 `idl:"name:Length" json:"length"`
// MaximumLength: The number of bytes allocated for the string. This MUST be an even
// number in the range [Length...65534].
MaximumLength uint16 `idl:"name:MaximumLength" json:"maximum_length"`
// Buffer: The Unicode UTF-16 characters comprising the string described by the structure.
// Note that counted strings might be terminated by a 0x0000 character, by convention;
// if such a terminator is present, it SHOULD NOT count toward the Length (but MUST,
// of course, be included in the MaximumLength).
Buffer []uint16 `idl:"name:Buffer;size_is:((MaximumLength/2));length_is:((Length/2))" json:"buffer"`
}
func (o *UnicodeString) xxx_PreparePayload(ctx context.Context) error {
if o.Buffer != nil && o.MaximumLength == 0 {
o.MaximumLength = uint16((len(o.Buffer) * 2))
}
if o.Buffer != nil && o.Length == 0 {
o.Length = uint16((len(o.Buffer) * 2))
}
if hook, ok := (interface{})(o).(interface{ AfterPreparePayload(context.Context) error }); ok {
if err := hook.AfterPreparePayload(ctx); err != nil {
return err
}
}
return nil
}
func (o *UnicodeString) MarshalNDR(ctx context.Context, w ndr.Writer) error {
if err := o.xxx_PreparePayload(ctx); err != nil {
return err
}
if err := w.WriteAlign(7); err != nil {
return err
}
if err := w.WriteData(o.Length); err != nil {
return err
}
if err := w.WriteData(o.MaximumLength); err != nil {
return err
}
if o.Buffer != nil || (o.MaximumLength/2) > 0 {
_ptr_Buffer := ndr.MarshalNDRFunc(func(ctx context.Context, w ndr.Writer) error {
dimSize1 := uint64((o.MaximumLength / 2))
if err := w.WriteSize(dimSize1); err != nil {
return err
}
sizeInfo := []uint64{
dimSize1,
}
dimLength1 := uint64((o.Length / 2))
if dimLength1 > sizeInfo[0] {
dimLength1 = sizeInfo[0]
} else {
sizeInfo[0] = dimLength1
}
if err := w.WriteSize(0); err != nil {
return err
}
if err := w.WriteSize(dimLength1); err != nil {
return err
}
for i1 := range o.Buffer {
i1 := i1
if uint64(i1) >= sizeInfo[0] {
break
}
if err := w.WriteData(o.Buffer[i1]); err != nil {
return err
}
}
for i1 := len(o.Buffer); uint64(i1) < sizeInfo[0]; i1++ {
if err := w.WriteData(uint16(0)); err != nil {
return err
}
}
return nil
})
if err := w.WritePointer(&o.Buffer, _ptr_Buffer); err != nil {
return err
}
} else {
if err := w.WritePointer(nil); err != nil {
return err
}
}
return nil
}
func (o *UnicodeString) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
if err := w.ReadAlign(7); err != nil {
return err
}
if err := w.ReadData(&o.Length); err != nil {
return err
}
if err := w.ReadData(&o.MaximumLength); err != nil {
return err
}
_ptr_Buffer := ndr.UnmarshalNDRFunc(func(ctx context.Context, w ndr.Reader) error {
sizeInfo := []uint64{
0,
}
for sz1 := range sizeInfo {
if err := w.ReadSize(&sizeInfo[sz1]); err != nil {
return err
}
}
for sz1 := range sizeInfo {
if err := w.ReadSize(&sizeInfo[sz1]); err != nil {
return err
}
if err := w.ReadSize(&sizeInfo[sz1]); err != nil {
return err
}
}
if sizeInfo[0] > uint64(w.Len()) /* sanity-check */ {
return fmt.Errorf("buffer overflow for size %d of array o.Buffer", sizeInfo[0])
}
o.Buffer = make([]uint16, sizeInfo[0])
for i1 := range o.Buffer {
i1 := i1
if err := w.ReadData(&o.Buffer[i1]); err != nil {
return err
}
}
return nil
})
_s_Buffer := func(ptr interface{}) { o.Buffer = *ptr.(*[]uint16) }
if err := w.ReadPointer(&o.Buffer, _s_Buffer, _ptr_Buffer); err != nil {
return err
}
return nil
}