dartmetal 0.1.0
dartmetal: ^0.1.0 copied to clipboard
DartMetal — Low-level system programming for Dart. Touch the metal. Allocate memory. Talk to syscalls. No guardrails.
DartMetal #
DartMetal — Touch the Metal from Dart.
DartMetal is a low-level system programming library for Dart. It gives you manual memory management, raw pointers, direct syscalls, and low-level I/O — essentially bringing Dart into the world of systems programming.
⚠️ Warning: This library is unsafe by design. You can crash the Dart VM, corrupt memory, or perform invalid syscalls. Use at your own risk.
Features #
UnsafePointer<T>— C-style pointers with typed read/write and pointer arithmetic.- Manual memory allocation:
malloc,free,memcpy,memset. - Low-level syscalls (POSIX + Windows).
- Raw file and device I/O.
- Struct & union bindings for native interop.
- CPU info and raw register access (mocked or real).
Installation #
Add to your pubspec.yaml:
dependencies:
dartmetal: ^0.1.0
Note: DartMetal requires a native library (
dartmetal.dll,libdartmetal.so, orlibdartmetal.dylib) compiled for your platform.
Build the native library:
dart run native/build.dart
Usage Examples #
Memory Allocation #
import 'package:dartmetal/dartmetal.dart';
void main() {
final ptr = UnsafePointer<Uint32>.allocate(4);
ptr.write(0, 0xdeadbeef);
print('Memory first 4 bytes: 0x${ptr.read<int>(0).toRadixString(16)}');
ptr.free();
}
Unsafe Pointer Arithmetic #
final ptr = UnsafePointer<Uint32>.allocate(2);
ptr.write(0, 0xcafebabe);
ptr.write(1, 0xfeedface);
final second = ptr.offset(1);
print('Second value: 0x${second.read<int>(0).toRadixString(16)}');
ptr.free();
Syscalls Example #
import 'package:dartmetal/dartmetal.dart';
void main() {
final pid = sysGetPid();
print('Current PID: $pid');
}
Tests #
Run the included test suite:
dart run test/dartmetal_test.dart
Sample output:
✅ All tests completed successfully!
Contributing #
DartMetal is experimental and evolving. Contributions are welcome, especially:
- Additional syscalls
- Cross-platform support
- Unsafe memory helpers
- Threading & atomic operations
License #
MIT License © 2025 [MuerteSeguraZ]
---