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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const gloves_module = b.createModule(.{
.root_source_file = b.path("src/gloves.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
const capstone_dep = b.dependency("capstone", .{});
const translate_c = b.addTranslateC(.{
.root_source_file = capstone_dep.path("include/capstone/capstone.h"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
// translate
const c_mod = translate_c.createModule();
const capstone_lib = b.addLibrary(.{
.name = "capstone",
.linkage = .static,
.root_module = c_mod,
});
capstone_lib.root_module.addIncludePath(capstone_dep.path("include"));
capstone_lib.root_module.addIncludePath(capstone_dep.path("include/capstone"));
capstone_lib.root_module.addIncludePath(capstone_dep.path("include/capstone/X86"));
capstone_lib.installHeadersDirectory(capstone_dep.path("include/capstone"), "capstone", .{});
capstone_lib.installHeader(capstone_dep.path("include/platform.h"), "capstone/platform.h");
if (optimize == .Debug) capstone_lib.root_module.addCMacro("CAPSTONE_DEBUG", "");
capstone_lib.root_module.addCMacro("CAPSTONE_HAS_X86", "");
capstone_lib.root_module.addCMacro("CAPSTONE_BUILD_CSTOOL", "OFF");
capstone_lib.root_module.addCMacro("CAPSTONE_USE_SYS_DYN_MEM", "OFF");
capstone_lib.root_module.addCSourceFiles(.{ .root = capstone_dep.path(""), .files = common_sources });
// capstone_lib.root_module.addCSourceFiles(.{
// .root = capstone_dep.path("arch/AArch64"),
// .files = &.{
// "AArch64BaseInfo.c",
// "AArch64Disassembler.c",
// "AArch64DisassemblerExtension.c",
// "AArch64InstPrinter.c",
// "AArch64Mapping.c",
// "AArch64Module.c",
// },
// });
capstone_lib.root_module.addCSourceFiles(.{
.root = capstone_dep.path("arch/X86"),
.files = &.{
"X86Disassembler.c",
"X86DisassemblerDecoder.c",
"X86IntelInstPrinter.c",
"X86ATTInstPrinter.c",
"X86InstPrinterCommon.c",
"X86Mapping.c",
"X86Module.c",
},
});
b.installArtifact(capstone_lib);
const elfo = b.addExecutable(.{
.name = "elfo-pretty",
.root_module = b.createModule(.{
.root_source_file = b.path("src/elfo-pretty.zig"),
.target = target,
.optimize = optimize,
}),
});
elfo.root_module.linkLibrary(capstone_lib);
elfo.root_module.addImport("capstone", capstone_lib.root_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 gdb
}
const common_sources: []const []const u8 = &.{
"cs.c",
"Mapping.c",
"MCInst.c",
"MCInstrDesc.c",
"MCInstPrinter.c",
"MCRegisterInfo.c",
"SStream.c",
"utils.c",
};
// .AArch64
// .ARC
// .ARM
// .Alpha
// .BPF
// .EVM
// .HPPA
// .LoongArch
// .M680X
// .M68K
// .MOS65XX
// .Mips
// .PowerPC
// .RISCV
// .SH
// .Sparc
// .SystemZ
// .TMS320C64x
// .TriCore
// .WASM
// .X86
// .XCore
// .Xtensa
|