Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
big refactoring with back comp broke
Browse files Browse the repository at this point in the history
  • Loading branch information
ergoz committed Aug 11, 2019
1 parent 157b6d9 commit 95b3fe1
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 163 deletions.
17 changes: 9 additions & 8 deletions advapi32.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
procRegDeleteTree = modadvapi32.NewProc("RegDeleteTreeW")
procRegDeleteValue = modadvapi32.NewProc("RegDeleteValueW")
procRegEnumKeyEx = modadvapi32.NewProc("RegEnumKeyExW")
procRegGetValue = modadvapi32.NewProc("RegGetValueW")
procRegGetValueW = modadvapi32.NewProc("RegGetValueW")
procRegOpenKeyEx = modadvapi32.NewProc("RegOpenKeyExW")
procRegSetValueEx = modadvapi32.NewProc("RegSetValueExW")
procSetSecurityDescriptorDacl = modadvapi32.NewProc("SetSecurityDescriptorDacl")
Expand Down Expand Up @@ -117,7 +117,7 @@ func InitializeSecurityDescriptor(rev uint16) (pSecurityDescriptor *SECURITY_DES

func RegCreateKey(hKey HKEY, subKey string) HKEY {
var result HKEY
ret, _, _ := procRegCreateKeyEx.Call(
_, _, _ = procRegCreateKeyEx.Call(
uintptr(hKey),
uintptr(pointerStringWithoutError(subKey)),
uintptr(0),
Expand All @@ -127,10 +127,11 @@ func RegCreateKey(hKey HKEY, subKey string) HKEY {
uintptr(0),
uintptr(unsafe.Pointer(&result)),
uintptr(0))
_ = ret

return result
}

// TODO Validate this method!!! may be deprecated parts used
func RegOpenKeyEx(hKey HKEY, subKey string, samDesired uint32) HKEY {
var result HKEY
ret, _, _ := procRegOpenKeyEx.Call(
Expand Down Expand Up @@ -163,7 +164,7 @@ func RegGetRaw(hKey HKEY, subKey string, value string) []byte {
if len(value) > 0 {
valptr = pointerStringWithoutError(value)
}
procRegGetValue.Call(
procRegGetValueW.Call(
uintptr(hKey),
uintptr(pointerStringWithoutError(subKey)),
uintptr(valptr),
Expand All @@ -177,7 +178,7 @@ func RegGetRaw(hKey HKEY, subKey string, value string) []byte {
}

buf := make([]byte, bufLen)
ret, _, _ := procRegGetValue.Call(
ret, _, _ := procRegGetValueW.Call(
uintptr(hKey),
uintptr(pointerStringWithoutError(subKey)),
uintptr(valptr),
Expand Down Expand Up @@ -255,7 +256,7 @@ func RegSetUint32(hKey HKEY, subKey string, value uint32) (errno int) {

func RegGetString(hKey HKEY, subKey string, value string) string {
var bufLen uint32
procRegGetValue.Call(
procRegGetValueW.Call(
uintptr(hKey),
uintptr(pointerStringWithoutError(subKey)),
uintptr(pointerStringWithoutError(value)),
Expand All @@ -269,7 +270,7 @@ func RegGetString(hKey HKEY, subKey string, value string) string {
}

buf := make([]uint16, bufLen)
ret, _, _ := procRegGetValue.Call(
ret, _, _ := procRegGetValueW.Call(
uintptr(hKey),
uintptr(pointerStringWithoutError(subKey)),
uintptr(pointerStringWithoutError(value)),
Expand All @@ -287,7 +288,7 @@ func RegGetString(hKey HKEY, subKey string, value string) string {

func RegGetUint32(hKey HKEY, subKey string, value string) (data uint32, errno int) {
var dataLen uint32 = uint32(unsafe.Sizeof(data))
ret, _, _ := procRegGetValue.Call(
ret, _, _ := procRegGetValueW.Call(
uintptr(hKey),
uintptr(pointerStringWithoutError(subKey)),
uintptr(pointerStringWithoutError(value)),
Expand Down
60 changes: 29 additions & 31 deletions gdi32.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
procCreateBrushIndirect = modgdi32.NewProc("CreateBrushIndirect")
procCreateCompatibleBitmap = modgdi32.NewProc("CreateCompatibleBitmap")
procCreateCompatibleDC = modgdi32.NewProc("CreateCompatibleDC")
procCreateDC = modgdi32.NewProc("CreateDCW")
procCreateDCW = modgdi32.NewProc("CreateDCW")
procCreateDIBSection = modgdi32.NewProc("CreateDIBSection")
procCreateEnhMetaFile = modgdi32.NewProc("CreateEnhMetaFileW")
procCreateFontIndirect = modgdi32.NewProc("CreateFontIndirectW")
Expand Down Expand Up @@ -148,10 +148,10 @@ func CloseEnhMetaFile(hdc HDC) HENHMETAFILE {
return HENHMETAFILE(ret)
}

func CopyEnhMetaFile(hemfSrc HENHMETAFILE, lpszFile *uint16) HENHMETAFILE {
func CopyEnhMetaFile(hEnh HENHMETAFILE, lpFileName string) HENHMETAFILE {
ret, _, _ := procCopyEnhMetaFile.Call(
uintptr(hemfSrc),
uintptr(unsafe.Pointer(lpszFile)))
uintptr(hEnh),
uintptr(pointerStringWithoutError(lpFileName)))

return HENHMETAFILE(ret)
}
Expand All @@ -174,12 +174,12 @@ func CreateCompatibleDC(hdc HDC) HDC {
return HDC(ret)
}

func CreateDC(lpszDriver, lpszDevice, lpszOutput *uint16, lpInitData *DEVMODE) HDC {
ret, _, _ := procCreateDC.Call(
uintptr(unsafe.Pointer(lpszDriver)),
uintptr(unsafe.Pointer(lpszDevice)),
uintptr(unsafe.Pointer(lpszOutput)),
uintptr(unsafe.Pointer(lpInitData)))
func CreateDC(pwszDriver, pwszDevice, pszPort string, pdm *DEVMODE) HDC {
ret, _, _ := procCreateDCW.Call(
uintptr(pointerStringWithoutError(pwszDriver)),
uintptr(pointerStringWithoutError(pwszDevice)),
uintptr(pointerStringWithoutError(pszPort)),
uintptr(unsafe.Pointer(pdm)))

return HDC(ret)
}
Expand All @@ -196,30 +196,28 @@ func CreateDIBSection(hdc HDC, pbmi *BITMAPINFO, iUsage uint, ppvBits *unsafe.Po
return HBITMAP(ret)
}

func CreateEnhMetaFile(hdcRef HDC, lpFilename *uint16, lpRect *RECT, lpDescription *uint16) HDC {
func CreateEnhMetaFile(hdc HDC, lpFilename string, lprc *RECT, lpDesc string) HDC {
ret, _, _ := procCreateEnhMetaFile.Call(
uintptr(hdcRef),
uintptr(unsafe.Pointer(lpFilename)),
uintptr(unsafe.Pointer(lpRect)),
uintptr(unsafe.Pointer(lpDescription)))
uintptr(hdc),
uintptr(pointerStringWithoutError(lpFilename)),
uintptr(unsafe.Pointer(lprc)),
uintptr(pointerStringWithoutError(lpDesc)))

return HDC(ret)
}

func CreateIC(lpszDriver, lpszDevice, lpszOutput *uint16, lpdvmInit *DEVMODE) HDC {
func CreateIC(pszDriver, pszDevice string, pdm *DEVMODE) HDC {
ret, _, _ := procCreateIC.Call(
uintptr(unsafe.Pointer(lpszDriver)),
uintptr(unsafe.Pointer(lpszDevice)),
uintptr(unsafe.Pointer(lpszOutput)),
uintptr(unsafe.Pointer(lpdvmInit)))
uintptr(pointerStringWithoutError(pszDriver)),
uintptr(pointerStringWithoutError(pszDevice)),
uintptr(nil),
uintptr(unsafe.Pointer(pdm)))

return HDC(ret)
}

func DeleteDC(hdc HDC) bool {
ret, _, _ := procDeleteDC.Call(
uintptr(hdc))

ret, _, _ := procDeleteDC.Call(uintptr(hdc))
return ret != 0
}

Expand Down Expand Up @@ -266,9 +264,9 @@ func ExtCreatePen(dwPenStyle, dwWidth uint, lplb *LOGBRUSH, dwStyleCount uint, l
return HPEN(ret)
}

func GetEnhMetaFile(lpszMetaFile *uint16) HENHMETAFILE {
func GetEnhMetaFile(lpName string) HENHMETAFILE {
ret, _, _ := procGetEnhMetaFile.Call(
uintptr(unsafe.Pointer(lpszMetaFile)))
uintptr(pointerStringWithoutError(lpName)))

return HENHMETAFILE(ret)
}
Expand Down Expand Up @@ -298,25 +296,25 @@ func GetStockObject(fnObject int) HGDIOBJ {
return HGDIOBJ(ret)
}

func GetTextExtentExPoint(hdc HDC, lpszStr *uint16, cchString, nMaxExtent int, lpnFit, alpDx *int, lpSize *SIZE) bool {
func GetTextExtentExPoint(hdc HDC, lpszString string, cchString, nMaxExtent int, lpnFit, lpnDx *int, lpSize *SIZE) bool {
ret, _, _ := procGetTextExtentExPoint.Call(
uintptr(hdc),
uintptr(unsafe.Pointer(lpszStr)),
uintptr(pointerStringWithoutError(lpszString)),
uintptr(cchString),
uintptr(nMaxExtent),
uintptr(unsafe.Pointer(lpnFit)),
uintptr(unsafe.Pointer(alpDx)),
uintptr(unsafe.Pointer(lpnDx)),
uintptr(unsafe.Pointer(lpSize)))

return ret != 0
}

func GetTextExtentPoint32(hdc HDC, lpString *uint16, c int, lpSize *SIZE) bool {
func GetTextExtentPoint32(hdc HDC, lpString string, c int, psizl *SIZE) bool {
ret, _, _ := procGetTextExtentPoint32.Call(
uintptr(hdc),
uintptr(unsafe.Pointer(lpString)),
uintptr(pointerStringWithoutError(lpString)),
uintptr(c),
uintptr(unsafe.Pointer(lpSize)))
uintptr(unsafe.Pointer(psizl)))

return ret != 0
}
Expand Down
4 changes: 4 additions & 0 deletions gdiplus.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func GetGpStatus(s int32) string {
return "Unknown Status Value"
}

// TODO REFACTOR THIS LIBRARY
// TODO See https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-func-functions

var (
token uintptr

Expand Down Expand Up @@ -114,6 +117,7 @@ func GdipCreateBitmapFromFile(filename string) (*uintptr, error) {
return bitmap, nil
}

// todo fix this method!
func GdipCreateBitmapFromResource(instance HINSTANCE, resId *uint16) (*uintptr, error) {
var bitmap *uintptr
ret, _, _ := procGdipCreateBitmapFromResource.Call(
Expand Down
35 changes: 20 additions & 15 deletions kernel32.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,33 +218,38 @@ func VirtualProtect(lpAddress uintptr, dwSize int, flNewProtect int, lpflOldProt
}

// https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
func CreateProcessA(lpApplicationName *string,
func CreateProcessA(lpApplicationName string,
lpCommandLine string,
lpProcessAttributes *syscall.SecurityAttributes,
lpThreadAttributes *syscall.SecurityAttributes,
bInheritHandles bool,
dwCreationFlags uint32,
lpEnvironment *string,
lpCurrentDirectory *uint16,
lpEnvironment string,
lpCurrentDirectory string,
lpStartupInfo *syscall.StartupInfo,
lpProcessInformation *syscall.ProcessInformation) {
lpProcessInformation *syscall.ProcessInformation) (bool, error) {

inherit := 0
if bInheritHandles {
inherit = 1
}

procCreateProcessA.Call(
uintptr(pointerStringWithoutError(*lpApplicationName)),
ret, _, err := procCreateProcessA.Call(
uintptr(pointerStringWithoutError(lpApplicationName)),
uintptr(pointerStringWithoutError(lpCommandLine)),
uintptr(unsafe.Pointer(lpProcessAttributes)),
uintptr(unsafe.Pointer(lpThreadAttributes)),
uintptr(inherit),
uintptr(dwCreationFlags),
uintptr(unsafe.Pointer(lpEnvironment)),
uintptr(unsafe.Pointer(lpCurrentDirectory)),
uintptr(pointerStringWithoutError(lpEnvironment)),
uintptr(pointerStringWithoutError(lpCurrentDirectory)),
uintptr(unsafe.Pointer(lpStartupInfo)),
uintptr(unsafe.Pointer(lpProcessInformation)))

if ret == 0 && err.(syscall.Errno) != ERROR_SUCCESS {
return false, err
}
return ret != 0, nil
}

// https://msdn.microsoft.com/en-us/library/windows/desktop/aa366890(v=vs.85).aspx
Expand Down Expand Up @@ -367,16 +372,16 @@ func GetUserDefaultLCID() uint32 {
return uint32(ret)
}

func Lstrlen(lpString *uint16) int {
ret, _, _ := procLstrlen.Call(uintptr(unsafe.Pointer(lpString)))
func Lstrlen(lpString string) int {
ret, _, _ := procLstrlen.Call(uintptr(pointerStringWithoutError(lpString)))

return int(ret)
}

func Lstrcpy(buf []uint16, lpString *uint16) {
func Lstrcpy(buf []uint16, lpString string) {
procLstrcpy.Call(
uintptr(unsafe.Pointer(&buf[0])),
uintptr(unsafe.Pointer(lpString)))
uintptr(pointerStringWithoutError(lpString)))
}

func GlobalAlloc(uFlags uint, dwBytes uint32) HGLOBAL {
Expand Down Expand Up @@ -422,11 +427,11 @@ func MoveMemory(destination, source unsafe.Pointer, length uint32) {
uintptr(length))
}

func FindResource(hModule HMODULE, lpName, lpType *uint16) (HRSRC, error) {
func FindResource(hModule HMODULE, lpName, lpType string) (HRSRC, error) {
ret, _, _ := procFindResource.Call(
uintptr(hModule),
uintptr(unsafe.Pointer(lpName)),
uintptr(unsafe.Pointer(lpType)))
uintptr(pointerStringWithoutError(lpName)),
uintptr(pointerStringWithoutError(lpType)))

if ret == 0 {
return 0, syscall.GetLastError()
Expand Down
Loading

0 comments on commit 95b3fe1

Please sign in to comment.