1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
const std = @import("std");
fn capstone(b: *std.Build, options: struct {
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
}) struct {
dep: *std.Build.Dependency,
artifact: *std.Build.Step.Compile,
mod: *std.Build.Module,
} {
const capstone_dep = b.dependency("capstone", .{
.target = options.target,
.optimize = options.optimize,
});
const compiled_capstone = capstone_dep.artifact("capstone");
// I don't really know what I'm doing here, but it works
const capstone_c = b.addTranslateC(.{
.root_source_file = b.path("deps/tmp/capstone-6.0.0-Alpha4/include/capstone/capstone.h"),
// .root_source_file = capstone_dep.path("capstone.h"),
.target = options.target,
.optimize = options.optimize,
.link_libc = true,
});
const capstone_c_mod = capstone_c.createModule();
return .{
.dep = capstone_dep,
.artifact = compiled_capstone,
.mod = capstone_c_mod,
};
}
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const elfo_module = b.createModule(.{
.root_source_file = b.path("src/elfo-pretty.zig"),
.target = target,
.optimize = optimize,
});
const gloves_module = b.createModule(.{
.root_source_file = b.path("src/gloves.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
const cs = capstone(b, .{
.target = target,
.optimize = optimize,
});
elfo_module.addImport("capstone", cs.mod);
elfo_module.addLibraryPath(cs.artifact.getEmittedBin().dirname());
elfo_module.linkLibrary(cs.artifact);
elfo_module.addIncludePath(cs.artifact.getEmittedIncludeTree());
const elfo = b.addExecutable(.{
.name = "elfo-pretty",
.root_module = elfo_module,
});
const gloves = b.addExecutable(.{
.name = "gloves",
.root_module = gloves_module,
});
elfo.linkLibrary(cs.artifact);
b.installArtifact(elfo);
b.installArtifact(gloves);
const run_elfo_cmd = b.addRunArtifact(elfo);
const run_elfo_step = b.step("elfo", "See the pretty elfo!");
run_elfo_step.dependOn(&run_elfo_cmd.step);
const run_gloves_cmd = b.addRunArtifact(gloves);
const run_gloves_step = b.step("gloves", "See the pretty gloves!");
run_gloves_step.dependOn(&run_gloves_cmd.step);
// TODO: add flag to run on pwndbg
}
|