C header to Go binding generator, powered by modernc.org/cc/v4.
bindgen parses C headers using a real C compiler frontend and generates idiomatic Go bindings — structs, enums, typedefs, macro constants, and DLL function wrappers — all from a single go test invocation.
- Full C parsing — uses modernc.org/cc/v4 (no CGO required), supports MSVC-specific types and EWDK include paths
- Struct generation — C structs → Go structs with correct field alignment, including bitfield getter/setter methods
- Enum generation — C enums → Go
constblocks with proper type aliases - Typedef resolution — C typedefs → Go type aliases, including function pointer types
- Macro constant extraction —
#defineconstants → Goconst, with arithmetic expression evaluation - DLL binding — generates
syscall.LoadDLL-based wrappers with configurable function name filtering - Single-file or multi-file output — per-project configuration
byteslicepackage — genericbyte/int8↔stringconversion utilities from shared library (github.com/ddkwork/golibrary/byteslice)
- Go 1.26.2+
- Windows (MSVC toolchain)
- EWDK or Visual Studio with
cl.exeon PATH
Bindings are generated via go test:
go test -v -run TestGenerate -count=1 -timeout 300s .This processes all project configurations defined in generate_test.go and writes Go source files to each project's output directory.
| Project | Package | DLL Binding | Description |
|---|---|---|---|
| HyperDbg SDK | sdk |
— | HyperDbg debugger SDK structures and constants |
| Zydis | zydis |
zydis.dll |
Fast x86/x86-64 disassembler |
| Keystone | keystone |
keystone.dll |
Multi-architecture assembler engine |
| Intel XED | xed |
xed.dll |
x86 encoder/decoder |
| GLFW | glfw |
glfw3.dll |
Window and input library |
| WinDivert | windivert |
WinDivert64.dll |
Network packet interception |
| Everything SDK | everything |
Everything64.dll |
File search engine SDK |
| ARImpRec | ipmrec |
ARImpRec.dll |
Import reconstruction library |
bindgen/
├── generate_test.go # Binding generation logic and project configs
├── parse_test.go # C parsing test helpers
├── msenv.go # EWDK/MSVC environment detection
├── cc/v4/ # Vendored modernc.org/cc/v4
└── project/ # Generated bindings output
├── hyperdbg/sdk/
├── zydis/
├── keystone/
├── xed/
├── glfw/
├── WinDivert/
├── Everything-SDK/
└── ARImpRec/
Add a BindgenConfig entry in generate_test.go's TestGenerate:
t.Run("mylib", func(t *testing.T) {
Generate(t, []BindgenConfig{{
HeadersDir: "project/mylib/clone/include",
OutputDir: "project/mylib",
PackageName: "mylib",
HeaderOrder: []string{"mylib.h"},
BindDll: true,
DllName: "mylib.dll",
DllFuncFilter: func(name string) bool {
return strings.HasPrefix(name, "mylib_")
},
}})
})Generic byte/int8 ↔ string conversion utilities for C interop, from shared library github.com/ddkwork/golibrary/byteslice:
import "github.com/ddkwork/golibrary/byteslice"
// []byte/[]int8 → string (truncates at NUL)
s := byteslice.ToString[byte]([]byte("hello\x00world")) // "hello"
s := byteslice.ToString[int8]([]int8{104, 101, 108, 108, 111, 0}) // "hello"
// *byte/*int8 → string (reads until NUL)
s := byteslice.PtrToString[byte](p)
s := byteslice.PtrToString[int8](p)
// string → []byte/[]int8 (appends NUL terminator)
slice := byteslice.FromString[byte]("hello")
slice := byteslice.FromString[int8]("hello")
// string → *byte/*int8 (appends NUL terminator)
ptr := byteslice.PtrFromString[byte]("hello")
ptr := byteslice.PtrFromString[int8]("hello")
// []byte ↔ struct (zero-copy)
data := byteslice.FromStruct(&myStruct)
ptr := byteslice.ToStruct[MyStruct](buf)
// []T → []byte (zero-copy)
raw := byteslice.FromSlice(mySlice)GitHub Actions workflow (.github/workflows/go.yml) runs on Windows:
- Mount EWDK ISO for MSVC headers
- Run
go test -run TestGenerateto generate all bindings - Verify generated code compiles with
go vet - Run per-project tests (DLL tests require corresponding
.dllfiles)
This project uses modernc.org/cc/v4 which is licensed under the BSD-3-Clause.