cryptocode

joined 1 year ago
MODERATOR OF
 

Work-in-progress Python 3.10 Interpreter written in Zig

 

A time library written in zig, licenced under MIT

 

Musa is a Wayland compositor with external window managers and first-class multiseat support. Musa is slowly approaching daily usability, but there's still a long way to a polished compositor.

Inspired by River

 

From the README:

zcrun

a simple linux container runtime built with zig

Features

  • namespaces:
    • isolate network, pid, mount, and uts namespace
  • cgroups:
    • support cgroups v2
    • limit memory, cpu, or pids (# of procs).
  • internet access inside containers using SNAT

Usage

[!NOTE] make sure that ip forwarding is enabled to be able to access the internet inside containers. run sysctl net.ipv4.ip_forward to check if it is enabled. if not, run sudo sysctl -w net.ipv4.ip_forward=1 to enable it.

[!Important] zcrun must be run as root

$ mkdir rootfs
# export container rootfs dir using docker
$ docker export $(docker create busybox) | tar -C rootfs -xvf -
# run the container using zcrun
# zcrun run <name>  <rootfs> <cmd>
$ zcrun run busybox rootfs   sh

Dependencies:

  • The iptables command.
  • Zig. This branch was tested using version 0.12.0-dev.3191+9cf28d1e9.
 

From the README:

A gap buffer is like a std.ArrayList, except that rather than having one contiguous block of items, there are two, with a moveable “gap” between them. Although moving the gap requires a copy, insertions and deletions at either side of the gap become O(1) operations.

This repository implements managed, unmanaged and optionally aligned versions of GapBuffer(T). The API is directly inspired by std.ArrayList. The main differences are “Before” and “After” versions of operations that operate or affect the gap—“Before” operations will add or remove elements before the gap. There are also convenience functions for translating a “logical” index into an offset, an element, or a pointer from the buffer, allowing the user to be largely agnostic about the location of the gap.

 

Additional cross-platform SIMD support for Zig.

Based loosely on Google Highway

 

From the README:

zig-router

Straightforward HTTP-like request routing.


Project is tested against zig 0.12.0-dev.2341+92211135f

Sample

const router = @import("zig-router");

const MyJsonBody = struct {
    float: f32,
    text: []const u8,
    number_with_default: u32 = 42,
};

fn putJson(body: MyJsonBody) !Response {
    log.info("float: {}", .{body.float});
    log.info("text: {s}", .{body.text});
    log.info("number_with_default: {}", .{body.number_with_default});
    return .{ .body = "ok" };
}

const MyPathParams = struct {
    id: []const u8,
    bundle: u32,
};

fn getDynamic(params: MyPathParams) !Response {
    log.info("id: {s}", .{params.id});
    log.info("bundle: {}", .{params.bundle});
    return .{};
}

const MyQuery = struct {
    id: []const u8 = "plz give me a good paying stable job",
    bundle: u32 = 42,
};

fn getQuery(query: MyQuery) !Response {
    log.info("id: {s}", .{query.id});
    log.info("bundle: {}", .{query.bundle});
    return .{};
}

fn getError() !void {
    return error.EPIC_FAIL;
}

fn onRequest(arena: *std.heap.ArenaAllocator, request: Request) !void {
    router.Router(.{
        router.Decoder(.json, router.JsonBodyDecoder(.{}, 4096).decode),
    }, .{
        router.Route(.PUT, "/json", putJson, .{}),
        router.Route(.GET, "/dynamic/:id/paths/:bundle", getDynamic, .{}),
        router.Route(.GET, "/query", getQuery, .{}),
        router.Route(.GET, "/error", getError, .{}),
    }).match(arena.allocator(), .{
        .method = request.method,
        .path = request.path,
        .query = request.query,
        .body = .{ .reader = request.body.reader() }
    }, .{ arena.allocator() }) catch |err| switch (err) {
        error.not_found => return .{ .status = .not_found },
        error.bad_request => return .{ .status = .bad_request },
        else => return err,
    };
}

Depend

build.zig.zon

.zig_router = .{
  .url = "https://github.com/Cloudef/zig-router/archive/{COMMIT}.tar.gz",
  .hash = "{HASH}",
},

build.zig

const zig_router = b.dependency("zig_router", .{}).module("zig-router");
exe.root_module.addImport("zig-router", zig_router);
 

Budoux for Zig (and C)

Original library from Google: https://github.com/google/budoux

 

zat is a syntax highlighting cat like utility.

It uses tree-sitter and supports for vscode themes.

 

From the README:

Z-labs blog post - Running BOFs with 'bof-launcher' library

Introduction

Cobalt Strike 4.1 released on 25 June 2020, introduced a novel (for that time) capability of running so called Beacon Object Files - small post-ex capabilities that execute in Beacon, parse arguments, call a few Win32 APIs, report output, and exit. Since that time BOFs became very popular and the demand to launch/execute them in other environments than Cobalt Strike's Beacon has emerged.

Purpose

We at Z-Labs saw a big potential in BOFs and decided to extend its capabilities, versatility and usefulness even further. That's how this project came to live.

bof-launcher is an open-source library for loading, relocating and launching BOFs on Windows and UNIX/Linux systems. It's an alternative to Trustedsec's COFFLoader and ELFLoader with some very interesting features:

  • Fully compatibile with Cobalt Strike's Beacon. Can compile and run every BOF available at Cobalt Strike Community Kit and every other open-source BOF that adheres to generic BOF template.
  • Distributed as a fully standalone library with zero dependency (it does not even use libc).
  • Fully integrable with programs written in C/C++ and/or Zig progamming languages.
  • Adds capability to write BOFs in Zig programming language - which is a low-level langauge with a goal of being a "better C". All the features of the language and rich standard library can be used in BOFs (hash maps and other data structures, cross-platform OS layer, http, networking, threading, crypto and more).
  • Asynchronous BOF execution - capability to launch more time-consuming BOFs in a separate thread.
  • BOF process injection - capability to launch more risky BOFs (i.e. privilege escalation exploits) by injecting it to a new process.
  • Seamless support for either Windows COFF and UNIX/Linux ELF formats.
  • ARM and AARCH64 support on Linux.
  • Used in our cli4bofs tool that allows for running BOF files directly from a filesystem.
  • Very flexible and efficient API allowing for so called BOF chaining.
 

From the README:

A simple pretty printer for arbitrary data structures in Zig⚡️

Designed to inspect deeply-nested and recursive tree structures.

 

From the README:

zbind generates TypeScript bindings for calling Zig code compiled to native code or Wasm, in Node.js or Bun or browsers.

Example Zig code lib/main.zig:

const std = @import("std");
const zbind = @import("zbind");

pub fn hello(name: []const u8) void {
    std.debug.print("Hello, {s}!\n", .{ name });
}

pub fn main() void {}

comptime {
    zbind.init(@This());
}
view more: ‹ prev next ›