-
Notifications
You must be signed in to change notification settings - Fork 56
/
icorruntimehost.go
97 lines (87 loc) · 2.48 KB
/
icorruntimehost.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
// +build windows
package clr
import (
"syscall"
"unsafe"
)
type ICORRuntimeHost struct {
vtbl *ICORRuntimeHostVtbl
}
type ICORRuntimeHostVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
CreateLogicalThreadState uintptr
DeleteLogicalThreadState uintptr
SwitchInLogicalThreadState uintptr
SwitchOutLogicalThreadState uintptr
LocksHeldByLogicalThreadState uintptr
MapFile uintptr
GetConfiguration uintptr
Start uintptr
Stop uintptr
CreateDomain uintptr
GetDefaultDomain uintptr
EnumDomains uintptr
NextDomain uintptr
CloseEnum uintptr
CreateDomainEx uintptr
CreateDomainSetup uintptr
CreateEvidence uintptr
UnloadDomain uintptr
CurrentDomain uintptr
}
// GetICORRuntimeHost is a wrapper function that takes in an ICLRRuntimeInfo and returns an ICORRuntimeHost object
// and loads it into the current process. This is the "deprecated" API, but the only way currently to load an assembly
// from memory (afaict)
func GetICORRuntimeHost(runtimeInfo *ICLRRuntimeInfo) (*ICORRuntimeHost, error) {
var pRuntimeHost uintptr
hr := runtimeInfo.GetInterface(&CLSID_CorRuntimeHost, &IID_ICorRuntimeHost, &pRuntimeHost)
err := checkOK(hr, "runtimeInfo.GetInterface")
if err != nil {
return nil, err
}
runtimeHost := NewICORRuntimeHostFromPtr(pRuntimeHost)
hr = runtimeHost.Start()
err = checkOK(hr, "runtimeHost.Start")
return runtimeHost, err
}
func NewICORRuntimeHostFromPtr(ppv uintptr) *ICORRuntimeHost {
return (*ICORRuntimeHost)(unsafe.Pointer(ppv))
}
func (obj *ICORRuntimeHost) AddRef() uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.AddRef,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
func (obj *ICORRuntimeHost) Release() uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.Release,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
func (obj *ICORRuntimeHost) Start() uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.Start,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
func (obj *ICORRuntimeHost) GetDefaultDomain(pAppDomain *uintptr) uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetDefaultDomain,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(pAppDomain)),
0)
return ret
}