summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-03-09 17:09:09 -0300
committerGabriel Schneider <[email protected]>2026-06-08 23:05:18 -0300
commit4c12cb8aa39035c6ece5efad0971c6de4c2898fe (patch)
tree8a24e4dfa8941f9f407cf1e893a9374ca507e4a9
parent80ba1db819a80e784a488d6d660a890e14b19282 (diff)
downloadcodenomicon-4c12cb8aa39035c6ece5efad0971c6de4c2898fe.tar.gz
codenomicon-4c12cb8aa39035c6ece5efad0971c6de4c2898fe.zip
some changes to build.zig
-rw-r--r--.\0
-rw-r--r--.gitignore1
-rw-r--r--build.zig36
-rw-r--r--build.zig.zon4
-rw-r--r--src/shock.zig44
-rwxr-xr-xtests/c/a.outbin15904 -> 0 bytes
-rw-r--r--tests/c/hello-world.c10
7 files changed, 62 insertions, 33 deletions
diff --git a/.\ b/.\
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/.\
diff --git a/.gitignore b/.gitignore
index 43a5254..2b27afe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ notes.*
dirty-pin
zig-pkg
zig-out
+*a.out
diff --git a/build.zig b/build.zig
index 08789c7..6f7ad07 100644
--- a/build.zig
+++ b/build.zig
@@ -6,6 +6,8 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
+ const vaxis_dep = b.dependency("vaxis", .{});
+
const gloves_module = b.createModule(.{
.root_source_file = b.path("src/gloves.zig"),
.target = target,
@@ -33,6 +35,8 @@ pub fn build(b: *std.Build) !void {
}),
});
+ shock.root_module.addImport("vaxis", vaxis_dep.module("vaxis"));
+
const capstone_lib = capstone(b, .{
.optimize = optimize,
.target = target,
@@ -73,34 +77,34 @@ pub fn build(b: *std.Build) !void {
});
// Looooopy
- const gcc_test = b.addSystemCommand(&.{"gcc"});
- gcc_test.addFileArg(b.path("tests/c/hello-world.c"));
- gcc_test.addArg("-o");
- const gcc_hello_file = gcc_test.addOutputFileArg("hello-world");
+ const c_file = b.createModule(.{
+ .optimize = .ReleaseFast,
+ .target = target,
+ .link_libc = true,
+ });
+ const c_test_exe = b.addExecutable(.{
+ .root_module = c_file,
+ .name = "sample_exe",
+ });
+ c_file.addCSourceFile(.{ .file = b.path("tests/c/hello-world.c") });
- const runner = b.addRunArtifact(shock);
- runner.addFileArg(gcc_hello_file);
- runner.addFileArg(gcc_hello_file);
+ const runner = b.addRunArtifact(elfo);
+ runner.addArtifactArg(c_test_exe);
const loop_step = b.step("loop", "Interative Programming Loop! you should run it with watch: i.e. zig build loop --watch");
loop_step.dependOn(&runner.step);
// ---
- const test_step = b.step("test", "Run unit tests");
- const run_elfo_step = b.step("elfo", "See the pretty elfo!");
- const run_shock_step = b.step("shock", "SHOCK something!");
- const run_gloves_step = b.step("gloves", "See the pretty gloves!");
-
const zls_check = b.step("check", "Check if the program compiles");
zls_check.dependOn(&elfo.step);
zls_check.dependOn(&shock.step);
zls_check.dependOn(&unit_tests.step);
const run_steps = [_]struct { *std.Build.Step, *std.Build.Step.Compile }{
- .{ test_step, unit_tests },
- .{ run_elfo_step, elfo },
- .{ run_gloves_step, gloves },
- .{ run_shock_step, shock },
+ .{ b.step("test", "Run unit tests"), unit_tests },
+ .{ b.step("elfo", "See the pretty elfo!"), elfo },
+ .{ b.step("gloves", "See the pretty gloves!"), gloves },
+ .{ b.step("shock", "SHOCK something!"), shock },
};
const gdbscript = b.addWriteFile("gdbscript",
diff --git a/build.zig.zon b/build.zig.zon
index 4906467..d47ea8a 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -10,6 +10,10 @@
.url = "git+https://github.com/frida/frida-gum.git#7804914181117f05d20d3b143f7c13935658777f",
.hash = "N-V-__8AAFeo1AEV9-c5BwB6KQi5gLoDP-sj6d2duyERG2u-",
},
+ .vaxis = .{
+ .url = "git+https://github.com/unexge/libvaxis.git#42a9d80d7129d4ecda160acb23a868acfd87fb38",
+ .hash = "vaxis-0.5.1-BWNV_KU-CQA3Cp59zzqkaJ376rYQK4PIwLlzNZkpwLef",
+ },
},
.paths = .{""},
.fingerprint = 0xdc1ade2e38c84164,
diff --git a/src/shock.zig b/src/shock.zig
index 262b176..90e6edf 100644
--- a/src/shock.zig
+++ b/src/shock.zig
@@ -1,4 +1,5 @@
const std = @import("std");
+const elfo = @import("elfo.zig");
pub fn main(init: std.process.Init.Minimal) !void {
var args = init.args.iterate();
@@ -10,21 +11,21 @@ pub fn main(init: std.process.Init.Minimal) !void {
var debug_alloc: std.heap.DebugAllocator(.{}) = .init;
const alloc = debug_alloc.allocator();
- // var threaded: std.Io.Threaded = .init(alloc, .{
- // .argv0 = .init(init.args),
- // .environ = init.environ,
- // });
- // defer threaded.deinit();
- // const io = threaded.io();
-
- var evented: std.Io.Evented = undefined;
- try evented.init(alloc, .{
+ var threaded: std.Io.Threaded = .init(alloc, .{
.argv0 = .init(init.args),
.environ = init.environ,
- .backing_allocator_needs_mutex = false,
});
- defer evented.deinit();
- const io = evented.io();
+ defer threaded.deinit();
+ const io = threaded.io();
+
+ // var evented: std.Io.Evented = undefined;
+ // try evented.init(alloc, .{
+ // .argv0 = .init(init.args),
+ // .environ = init.environ,
+ // .backing_allocator_needs_mutex = false,
+ // });
+ // defer evented.deinit();
+ // const io = evented.io();
// const f = try std.Io.Dir.cwd().openFile(io, subject, .{ .mode = .read_only });
// std.debug.print("file: {any}\n", .{f});
@@ -36,10 +37,23 @@ pub fn main(init: std.process.Init.Minimal) !void {
const buf = try alloc.alloc(u8, 0x400);
defer alloc.free(buf);
- _ = try child.stdout.?.readPositionalAll(io, buf, 0);
+ _ = try child.stdout.?.readStreaming(io, &.{buf});
std.debug.print("spawned child: {any}\n", .{child});
- const term = try child.wait(io);
- std.debug.print("waited term: {any}\n", .{term});
+ // io.async(function: anytype, args: (unknown type))
+ var child_fut = io.async(std.process.Child.wait, .{ &child, io });
+ const child_out = try child_fut.await(io);
+ // const child_out = try child.wait(io);
+ std.debug.print("stdout: {s}\n", .{buf});
+
+ {
+ var buffer: [64]u8 = undefined;
+ const stderr = try io.lockStderr(&buffer, .escape_codes);
+ defer io.unlockStderr();
+ const term = stderr.terminal();
+ try elfo.printHexdump(u8, term.writer, term, buf, 0);
+ }
+
+ std.debug.print("waited term: {any}\n", .{child_out});
}
diff --git a/tests/c/a.out b/tests/c/a.out
deleted file mode 100755
index ef80bc7..0000000
--- a/tests/c/a.out
+++ /dev/null
Binary files differ
diff --git a/tests/c/hello-world.c b/tests/c/hello-world.c
index e0a0dd1..28c18a9 100644
--- a/tests/c/hello-world.c
+++ b/tests/c/hello-world.c
@@ -1,9 +1,15 @@
#include <stdio.h>
+#include <stdlib.h>
void a() {}
void bcd() {}
-int main() {
- printf("Heeeello, world! %d\n", 42);
+int main(int argc, char **argv) {
+ int *p = malloc(0x10);
+ free(p);
+
+ printf("- freed: (%x/%x)\n", p, *p);
+ printf("- fns: (%x/printf)\n", &printf);
+
return 0;
}