forked from ropnop/go-clr
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathassembly.go
129 lines (119 loc) · 3.69 KB
/
assembly.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
// +build windows
package clr
import (
"fmt"
"syscall"
"unsafe"
"golang.org/x/sys/windows"
)
// from mscorlib.tlh
type Assembly struct {
vtbl *AssemblyVtbl
}
// AssemblyVtbl is a COM virtual table of functions for the Assembly Class
// https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly?view=netframework-4.8
type AssemblyVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
GetTypeInfoCount uintptr
GetTypeInfo uintptr
GetIDsOfNames uintptr
Invoke uintptr
get_ToString uintptr
Equals uintptr
GetHashCode uintptr
GetType uintptr
get_CodeBase uintptr
get_EscapedCodeBase uintptr
GetName uintptr
GetName_2 uintptr
get_FullName uintptr
get_EntryPoint uintptr
GetType_2 uintptr
GetType_3 uintptr
GetExportedTypes uintptr
GetTypes uintptr
GetManifestResourceStream uintptr
GetManifestResourceStream_2 uintptr
GetFile uintptr
GetFiles uintptr
GetFiles_2 uintptr
GetManifestResourceNames uintptr
GetManifestResourceInfo uintptr
get_Location uintptr
get_Evidence uintptr
GetCustomAttributes uintptr
GetCustomAttributes_2 uintptr
IsDefined uintptr
GetObjectData uintptr
add_ModuleResolve uintptr
remove_ModuleResolve uintptr
GetType_4 uintptr
GetSatelliteAssembly uintptr
GetSatelliteAssembly_2 uintptr
LoadModule uintptr
LoadModule_2 uintptr
CreateInstance uintptr
CreateInstance_2 uintptr
CreateInstance_3 uintptr
GetLoadedModules uintptr
GetLoadedModules_2 uintptr
GetModules uintptr
GetModules_2 uintptr
GetModule uintptr
GetReferencedAssemblies uintptr
get_GlobalAssemblyCache uintptr
}
func (obj *Assembly) QueryInterface(riid *windows.GUID, ppvObject *uintptr) uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.QueryInterface,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(riid)),
uintptr(unsafe.Pointer(ppvObject)))
return ret
}
func (obj *Assembly) AddRef() uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.AddRef,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
func (obj *Assembly) Release() uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.Release,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
// GetEntryPoint returns the assembly's MethodInfo
// virtual HRESULT __stdcall get_EntryPoint (
// /*[out,retval]*/ struct _MethodInfo * * pRetVal ) = 0;
// https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.entrypoint?view=netframework-4.8#System_Reflection_Assembly_EntryPoint
// https://docs.microsoft.com/en-us/dotnet/api/system.reflection.methodinfo?view=netframework-4.8
func (obj *Assembly) GetEntryPoint() (pRetVal *MethodInfo, err error) {
debugPrint("Entering into assembly.GetEntryPoint()...")
hr, _, err := syscall.Syscall(
obj.vtbl.get_EntryPoint,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&pRetVal)),
0,
)
if err != syscall.Errno(0) {
err = fmt.Errorf("the Assembly::GetEntryPoint method returned an error:\r\n%s", err)
return
}
if hr != S_OK {
err = fmt.Errorf("the Assembly::GetEntryPoint method returned a non-zero HRESULT: 0x%x", hr)
return
}
err = nil
return
}