-
Notifications
You must be signed in to change notification settings - Fork 56
/
utils.go
57 lines (48 loc) · 1012 Bytes
/
utils.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
// +build windows
package clr
import (
"bytes"
"fmt"
"log"
"strings"
"unicode/utf16"
"unsafe"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
)
const S_OK = 0x0
func checkOK(hr uintptr, caller string) error {
if hr != S_OK {
return fmt.Errorf("%s returned 0x%08x", caller, hr)
} else {
return nil
}
}
func must(err error) {
if err != nil {
log.Fatal(err)
}
}
func utf16Le(s string) []byte {
enc := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM).NewEncoder()
var buf bytes.Buffer
t := transform.NewWriter(&buf, enc)
t.Write([]byte(s))
return buf.Bytes()
}
func expectsParams(input string) bool {
return !strings.Contains(input, "Void Main()")
}
func readUnicodeStr(ptr unsafe.Pointer) string {
var byteVal uint16
out := make([]uint16, 0)
for i := 0; ; i++ {
byteVal = *(*uint16)(unsafe.Pointer(ptr))
if byteVal == 0x0000 {
break
}
out = append(out, byteVal)
ptr = unsafe.Pointer(uintptr(ptr) + 2)
}
return string(utf16.Decode(out))
}