forked from joejulian/gio
a206e5e847
In order to avoid DLL preloading attacks, we should always load our system dependencies using the helper that only searches the system library path. Thanks to Mohsen Mirzakhani and Utkarsh Satya Prakash for bringing this to our attention. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
36 lines
687 B
Go
36 lines
687 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package app
|
|
|
|
import (
|
|
"log"
|
|
"unsafe"
|
|
|
|
syscall "golang.org/x/sys/windows"
|
|
)
|
|
|
|
type logger struct{}
|
|
|
|
var (
|
|
kernel32 = syscall.NewLazySystemDLL("kernel32")
|
|
outputDebugStringW = kernel32.NewProc("OutputDebugStringW")
|
|
debugView *logger
|
|
)
|
|
|
|
func init() {
|
|
// Windows DebugView already includes timestamps.
|
|
if syscall.Stderr == 0 {
|
|
log.SetFlags(log.Flags() &^ log.LstdFlags)
|
|
log.SetOutput(debugView)
|
|
}
|
|
}
|
|
|
|
func (l *logger) Write(buf []byte) (int, error) {
|
|
p, err := syscall.UTF16PtrFromString(string(buf))
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
outputDebugStringW.Call(uintptr(unsafe.Pointer(p)))
|
|
return len(buf), nil
|
|
}
|