~/talk

Safety Not Guaranteed: Calling Windows APIs using Unsafe & Syscall

Talkat GopherCon 2020 · 2020-11-09..11-13· [go, security]
slides:none on file

Shows how to call Windows APIs from Go without cgo by using syscall and unsafe, golang.org/x/sys/windows and the make_windows_syscall generator, with concrete examples like CreateJobObject / GetExtendedTcpTable and CredEnumerate. Explains mapping C types to Go, utf16 string conversions, the rule about keeping unsafe-to-uintptr conversions inside the syscall argument list, handling three levels of indirection for pointer arrays, a buffer-resize loop for variable-sized results, and builds working netstat and credential-enumeration tools (repo linked).

AI-written summary · about

  1. 0:00Intro
  2. 2:06Windows Containers 2016
  3. 4:16No Syscalls on Windows
  4. 7:22Pointer Arithmetic
  5. 8:14Pointer Rules
  6. 9:04Bad Pointers
  7. 11:07Finding DLL and Call Signatures
  8. 14:12Loading a DLL Procedure
  9. 14:41Calling Windows APIs Mapping C Types
  10. 16:27Primitive C-Type mappings
  11. 17:19Mapping Parameters
  12. 17:37Go string to string
  13. 19:46Struct Types
  14. 22:37Inspecting Return Value
  15. 23:15CreateJobObject
  16. 23:45Locking memory down during syscall
  17. 25:18mkwinsyscall - source
  18. 28:19Memory Management
  19. 32:24Example: Designing For Unmanged Memory - Free
  20. 33:46Example: Designing For Unmanged Memory- Iterating
  21. 35:21Improvement - Copy & Free
  22. 35:54Example: Copy & Free Design - Cred Enumerate
  23. 36:48Example: Copy & Free Design - Credential/Attribute
  24. 37:28Managed Memory: Generic Example
  25. 39:29Example: GetExtendedTcp Table - Syscall Loop
  26. 42:43Example: GetExtendedTcp Table - Table to Rows
  27. 43:52Full Code Available
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.