-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcontext.go
53 lines (42 loc) · 1.24 KB
/
context.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
package dcom
import (
"fmt"
"github.com/oiweiwei/go-msrpc/ndr"
)
// InterfacePointer function encodes the context object into an InterfacePointer.
func (o *Context) InterfacePointer() (*InterfacePointer, error) {
blob, err := ndr.Marshal(o, ndr.Opaque)
if err != nil {
return nil, fmt.Errorf("marshal context: %w", err)
}
ref := &ObjectReference{
Signature: ([]byte)(ObjectReferenceCustomSignature),
Flags: ObjectReferenceTypeCustom,
IID: ContextIID,
ObjectReference: &ObjectReference_ObjectReference{
Value: &ObjectReference_Custom{
Custom: &ObjectReferenceCustom{
ClassID: ContextMarshalerClassID,
Size: uint32(len(blob)),
ObjectData: blob,
},
},
},
}
b, err := ndr.Marshal(ref, ndr.Opaque)
if err != nil {
return nil, fmt.Errorf("marshal object_reference: %w", err)
}
return &InterfacePointer{Data: b}, nil
}
// Parse function decodes the context object from an InterfacePointer.
func (o *Context) Parse(in *InterfacePointer) error {
ref := in.GetCustomObjectReference()
if ref == nil {
return fmt.Errorf("invalid interface_pointer")
}
if err := ndr.Unmarshal(ref.ObjectData, o, ndr.Opaque); err != nil {
return fmt.Errorf("unmarshal context: %w", err)
}
return nil
}