Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 69 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,104 +1,78 @@
# Windows

Windows API bindings for [Rux](https://rux-lang.dev).All functions follow the official [Microsoft Win32 documentation](https://learn.microsoft.com/en-us/windows/win32/api/).

## Install

```toml
[Dependencies]
Windows = "0.2.1"
```

## Modules

| File | What |
|------|------|
| `Kernel32.rux` | kernel32.dll — processes, memory, threads, DLLs, sync, console, heap |
| `Pe.rux` | PE/COFF structs (DOS header, NT headers, IAT, EAT, sections) |
| `Process.rux` | Process enumeration, DLL injection, memory read/write |
| `Hook.rux` | IAT and inline (trampoline) function hooking |
| `ProxyDll.rux` | Proxy DLL pattern — forwarding to the real DLL |
| `Advapi32.rux` | advapi32.dll — registry, services, security, LSA |
| `DbgHelp.rux` | dbghelp.dll — minidumps, stack walking, symbols |
| `Gdi32.rux` | gdi32.dll — bitmap, font, DC, region |
| `NtDll.rux` | ntdll.dll — NT API (process, system, memory info) |
| `Psapi.rux` | psapi.dll — process/device driver enumeration |
| `User32.rux` | user32.dll — windows, messages, controls, input |
| `WinHvPlatform.rux` | WinHvPlatform.dll — Hyper-V whpx |
| `Ws2_32.rux` | ws2_32.dll — sockets (Winsock 2) |

### Memory Management

Functions for heap-based memory allocation.

| Function | Description |
| ------------------ | ----------------------------------------------------------- |
| `GetProcessHeap()` | Returns a handle to the default heap of the calling process |
| `HeapAlloc()` | Allocates a block of memory from a specified heap |
| `HeapReAlloc()` | Reallocates a block of memory from a heap |
| `HeapFree()` | Frees a memory block allocated from a heap |

### Memory Operations

Low-level memory utility routines (RTL).

| Function | Description |
| ----------------- | ---------------------------------------------- |
| `RtlFillMemory()` | Fills a block of memory with a specified value |
| `RtlZeroMemory()` | Fills a block of memory with zeros |
| `RtlCopyMemory()` | Copies a block of memory to another location |

### Console I/O

Functions for allocating and writing to a console.

| Function | Description |
| ----------------- | --------------------------------------------------------------- |
| `AllocConsole()` | Allocates a new console for the calling process |
| `GetStdHandle()` | Retrieves a handle to a standard device (stdin, stdout, stderr) |
| `WriteConsoleA()` | Writes a string of ANSI characters to the console |
| `WriteConsoleW()` | Writes a string of UTF-16 characters to the console |
| `Beep()` | Generates a tone on the system speaker |

### String Conversion

| Function | Description |
| ----------------------- | --------------------------------------------------------- |
| `MultiByteToWideChar()` | Converts a multi-byte ANSI string to a UTF-16 wide string |

### Process & Thread Control

| Function | Description |
| --------------- | -------------------------------------------------- |
| `Sleep()` | Suspends the execution of the current thread |
| `ExitProcess()` | Terminates the calling process and all its threads |

### Error Handling

| Function | Description |
| ---------------- | --------------------------------------------------- |
| `GetLastError()` | Retrieves the last-error code of the calling thread |


## Example
# Windows — Rux API Bindings (v0.4.0)

Complete, zero-conflict Windows API bindings for the [Rux programming language](https://rux-lang.dev).
This is the **the-lust/Windows** fork, kept in sync with and fully compatible with [rux-lang/Windows](https://github.com/rux-lang/Windows).

## Source files

| File | DLL(s) | Coverage |
|---|---|---|
| Kernel32.rux | kernel32.dll | Process, thread, memory, file I/O, console, sync, heap, DLL mgmt, interlocked ops, timing |
| NtDll.rux | ntdll.dll | NT native API, all STATUS_* codes, RtlXxx helpers, UnicodeString, ObjectAttributes |
| User32.rux | user32.dll | Window creation, message loop, input, menus, clipboard, DPI, raw input, touch, tray |
| Gdi32.rux | gdi32.dll + msimg32.dll | DC, bitmap, pen, brush, font, path, region, AlphaBlend, GradientFill, TransparentBlt |
| Advapi32.rux | advapi32.dll | Registry, token/privilege, security, services, event log, DPAPI |
| BCrypt.rux | bcrypt.dll | CNG: hash, HMAC, AES, RSA, ECDH, PBKDF2, random bytes |
| Crypt32.rux | crypt32.dll | Base64/hex encode-decode, DPAPI, cert store, chain validation, PKCS12 |
| DbgHelp.rux | dbghelp.dll | Symbol engine, stack walking, type info, minidump |
| Psapi.rux | psapi.dll | Process/module enumeration, memory counters, working set |
| Ws2_32.rux | ws2_32.dll | BSD sockets, WSA overlapped I/O, getaddrinfo, byte-order helpers |
| WinHvPlatform.rux | winhvplatform.dll | WHvP: partitions, VPs, GPA ranges, interrupts, CPUID override |
| Shell32.rux | shell32.dll | ShellExecute, SHFileOperation, known folders, CSIDL, tray, drag-drop |
| Ole32.rux | ole32.dll + oleaut32.dll | COM init, CoCreateInstance, IUnknown/IDispatch, VARIANT, BSTR, SAFEARRAY, storage |
| Seh.rux | kernel32.dll + ntdll.dll | SEH, VEH, unhandled exception filter, CONTEXT (x64 + ARM64), RtlUnwindEx |
| Pe.rux | *(pure Rux)* | PE32/PE32+ parsing, export/import tables, section lookup, base relocation |
| Hook.rux | *(pure Rux)* | x64 + ARM64 inline hooks, IAT hooks, global registry, RIP-relative fixup |
| Process.rux | kernel32.dll | Spawn helpers, DLL injection (LoadLibrary + reflective), PID-by-name, memory scanner |
| ProxyDll.rux | kernel32.dll | Proxy DLL: forward stubs (x64 + ARM64), per-export registration |
| Compat.rux | *(pure Rux)* | C/C++/Rust/Zig FFI type aliases, calling-convention docs, Win32 macros |

## Architecture support

| Target | Status |
|---|---|
| Windows x64 (AMD64) | Full support |
| Windows ARM64 (AArch64) | Full support — ARM64 stubs in Hook.rux + ProxyDll.rux, ARM64 CONTEXT in Seh.rux |
| Linux / macOS / WASM | Safe — all Win32 blocks are @[Target("Windows")]; other targets compile to nothing |

## Zero-conflict guarantee

- STATUS_* NTSTATUS codes — only in NtDll.rux
- Interlocked* primitives — only in Kernel32.rux
- GetLastError / SetLastError — only in Kernel32.rux
- DLL_PROCESS_ATTACH/DETACH/THREAD_* — only in Kernel32.rux
- HrSucceeded / HrFailed — only in WinHvPlatform.rux and Ole32.rux
- No file re-declares a symbol from any other file in the package

## Cross-language FFI

See Compat.rux for Rux-to-C/Rust/Zig type mapping and calling convention notes.

## Quick start

```rux
import Windows::*;
import Windows;

func Main() -> int {
let heap = GetProcessHeap();
let mem = HeapAlloc(heap, 0u32, 1024u);
RtlZeroMemory(mem, 1024u);

let stdout = GetStdHandle(StdHandle::Output as uint32);
@[Entry]
func Main() -> int32 {
let con = GetStdHandle(STD_OUTPUT_HANDLE);
var written: uint32 = 0u32;
WriteConsoleA(stdout, "Hello, Windows!\n\0", 16u32, &written, null);

HeapFree(heap, 0u32, mem);
WriteConsoleA(con, c"Hello, Windows!\n", 16u32, &written, null);
return 0;
}
```

## License
## Changelog

### v0.4.0
- Fixed all duplicate-symbol errors (STATUS_*, Interlocked*, GetLastError, DLL_PROCESS_ATTACH, …)
- Fixed struct pad/size errors (ProcessBasicInfo, WsaData, SockAddrIn, ExceptionRecord, ImageNtHeaders64, LogFontA, …)
- Fixed wrong return types (connect, RegQueryValueExA, SymGetLineFromAddr64, SelectObject, WHvCreatePartition, …)
- Fixed incorrect constant values (IMAGE_DIRECTORY_ENTRY_BASERELOC, EXCEPTION_FLT_DENORMAL_OPERAND, SYMOPT_EXACT_SYMBOLS, …)
- Fixed missing APIs (GetStdHandle, PostQuitMessage, CreateFontIndirectA, EnumProcessModulesEx, CryptBinaryToStringA, …)
- Added ARM64 hook stubs and CONTEXT struct
- Added Shell32.rux, Ole32.rux, Compat.rux (new files)
- All 19 source files carry @[Target("Windows")]

[MIT](LICENSE)
### v0.3.0
- Initial dev-branch release
12 changes: 10 additions & 2 deletions Rux.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
[Package]
Name = "Windows"
Version = "0.3.0"
Version = "0.4.0"
Type = "Source"
Description = "Windows API bindings — Kernel32, User32, Gdi32, NtDll, Advapi32, BCrypt, Crypt32, DbgHelp, Psapi, Ws2_32, WinHvPlatform, SEH, PE/hooks/process/proxy-DLL utilities"
Description = "Windows API bindings for Rux — Kernel32, User32, Gdi32, NtDll, Advapi32, BCrypt, Crypt32, DbgHelp, Psapi, Ws2_32, WinHvPlatform, Shell32, Ole32/OleAut32, SEH/VEH, PE/hooks/process/proxy-DLL utilities, cross-language FFI compatibility. Supports x64 and ARM64. Zero-conflict with rux-lang/Windows upstream."
Authors = ["Rux Contributors <info@rux-lang.dev>", "the-lust"]

[Dependencies]

[Targets]
Windows = true
Linux = false
macOS = false
WASM = false
Loading