Skip to content

Commit f65b284

Browse files
committed
init
0 parents  commit f65b284

File tree

7 files changed

+299
-0
lines changed

7 files changed

+299
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.zig text eol=lf
2+
*.zon text eol=lf

.github/workflows/ci.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Continuous Integration
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
pull_request:
8+
branches: [main]
9+
10+
workflow_dispatch:
11+
12+
jobs:
13+
exes:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Check out repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Zig
21+
uses: mlugg/setup-zig@v1
22+
23+
- name: Run `exes`
24+
run: zig build exes
25+
26+
fmt:
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Check out repository
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Zig
34+
uses: mlugg/setup-zig@v1
35+
36+
- name: Run `fmt`
37+
run: zig build fmt

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kcov-output/
2+
.zig-cache/
3+
zig-out/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Jora Troosh
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# AFLplusplus
2+
3+
[![CI][ci-shd]][ci-url]
4+
[![LC][lc-shd]][lc-url]
5+
6+
## Zig build of [AFLplusplus executable suite](https://github.com/AFLplusplus/AFLplusplus).
7+
8+
### :rocket: Usage
9+
10+
```sh
11+
git clone https://github.com/allyourcodebase/AFLplusplus.git
12+
cd AFLplusplus/
13+
zig build exes -Doptimize=ReleaseFast
14+
./zig-out/bin/afl-fuzz
15+
./zig-out/bin/afl-showmap
16+
./zig-out/bin/afl-tmin
17+
./zig-out/bin/afl-analyze
18+
./zig-out/bin/afl-gotcpu
19+
./zig-out/bin/afl-as
20+
```
21+
22+
<!-- MARKDOWN LINKS -->
23+
24+
[ci-shd]: https://img.shields.io/github/actions/workflow/status/allyourcodebase/AFLplusplus/ci.yaml?branch=main&style=for-the-badge&logo=github&label=CI&labelColor=black
25+
[ci-url]: https://github.com/allyourcodebase/AFLplusplus/blob/main/.github/workflows/ci.yaml
26+
[lc-shd]: https://img.shields.io/github/license/allyourcodebase/AFLplusplus.svg?style=for-the-badge&labelColor=black
27+
[lc-url]: https://github.com/allyourcodebase/AFLplusplus/blob/main/LICENSE

build.zig

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const optimize = b.standardOptimizeOption(.{});
6+
const version = std.SemanticVersion{ .major = 4, .minor = 21, .patch = 0 };
7+
8+
// Dependencies
9+
const AFLplusplus_dep = b.dependency("AFLplusplus", .{});
10+
const AFLplusplus_src_path = AFLplusplus_dep.path("src/");
11+
const AFLplusplus_inc_path = AFLplusplus_dep.path("include/");
12+
13+
// Executable suite
14+
const exes_step = b.step("exes", "Install executables");
15+
16+
var flags = std.BoundedArray([]const u8, 15){};
17+
flags.appendSliceAssumeCapacity(&FLAGS);
18+
if (target.result.cpu.arch.isX86()) {
19+
flags.appendSliceAssumeCapacity(&.{ "-mavx2", "-D_HAVE_AVX2" });
20+
}
21+
if (target.query.isNative()) {
22+
flags.appendAssumeCapacity("-march=native");
23+
}
24+
25+
const fuzz_exe = b.addExecutable(.{
26+
.name = "afl-fuzz",
27+
.pic = true,
28+
.target = target,
29+
.version = version,
30+
.optimize = optimize,
31+
});
32+
fuzz_exe.addCSourceFiles(.{
33+
.root = AFLplusplus_src_path,
34+
.files = &(FUZZ_SOURCES ++ SHARED_SOURCES),
35+
.flags = flags.constSlice(),
36+
});
37+
fuzz_exe.addIncludePath(AFLplusplus_inc_path);
38+
fuzz_exe.linkSystemLibrary("z");
39+
fuzz_exe.linkLibC();
40+
41+
const fuzz_exe_install = b.addInstallArtifact(fuzz_exe, .{});
42+
exes_step.dependOn(&fuzz_exe_install.step);
43+
44+
const showmap_exe = b.addExecutable(.{
45+
.name = "afl-showmap",
46+
.pic = true,
47+
.target = target,
48+
.version = version,
49+
.optimize = optimize,
50+
});
51+
showmap_exe.addCSourceFiles(.{
52+
.root = AFLplusplus_src_path,
53+
.files = &(.{ "afl-showmap.c", "afl-fuzz-mutators.c", "afl-fuzz-python.c" } ++ SHARED_SOURCES),
54+
.flags = flags.constSlice(),
55+
});
56+
showmap_exe.addIncludePath(AFLplusplus_inc_path);
57+
showmap_exe.linkSystemLibrary("z");
58+
showmap_exe.linkLibC();
59+
60+
const showmap_exe_install = b.addInstallArtifact(showmap_exe, .{});
61+
exes_step.dependOn(&showmap_exe_install.step);
62+
63+
const tmin_exe = b.addExecutable(.{
64+
.name = "afl-tmin",
65+
.pic = true,
66+
.target = target,
67+
.version = version,
68+
.optimize = optimize,
69+
});
70+
tmin_exe.addCSourceFiles(.{
71+
.root = AFLplusplus_src_path,
72+
.files = &(.{"afl-tmin.c"} ++ SHARED_SOURCES),
73+
.flags = flags.constSlice(),
74+
});
75+
tmin_exe.addIncludePath(AFLplusplus_inc_path);
76+
tmin_exe.linkSystemLibrary("z");
77+
tmin_exe.linkLibC();
78+
79+
const tmin_exe_install = b.addInstallArtifact(tmin_exe, .{});
80+
exes_step.dependOn(&tmin_exe_install.step);
81+
82+
const analyze_exe = b.addExecutable(.{
83+
.name = "afl-analyze",
84+
.pic = true,
85+
.target = target,
86+
.version = version,
87+
.optimize = optimize,
88+
});
89+
analyze_exe.addCSourceFiles(.{
90+
.root = AFLplusplus_src_path,
91+
.files = &(.{"afl-analyze.c"} ++ SHARED_SOURCES),
92+
.flags = flags.constSlice(),
93+
});
94+
analyze_exe.addIncludePath(AFLplusplus_inc_path);
95+
analyze_exe.linkSystemLibrary("z");
96+
analyze_exe.linkLibC();
97+
98+
const analyze_exe_install = b.addInstallArtifact(analyze_exe, .{});
99+
exes_step.dependOn(&analyze_exe_install.step);
100+
101+
const gotcpu_exe = b.addExecutable(.{
102+
.name = "afl-gotcpu",
103+
.pic = true,
104+
.target = target,
105+
.version = version,
106+
.optimize = optimize,
107+
});
108+
gotcpu_exe.addCSourceFiles(.{
109+
.root = AFLplusplus_src_path,
110+
.files = &.{ "afl-gotcpu.c", "afl-common.c" },
111+
.flags = flags.constSlice(),
112+
});
113+
gotcpu_exe.addIncludePath(AFLplusplus_inc_path);
114+
gotcpu_exe.linkSystemLibrary("z");
115+
gotcpu_exe.linkLibC();
116+
117+
const gotcpu_exe_install = b.addInstallArtifact(gotcpu_exe, .{});
118+
exes_step.dependOn(&gotcpu_exe_install.step);
119+
120+
const as_exe = b.addExecutable(.{
121+
.name = "afl-as",
122+
.pic = true,
123+
.target = target,
124+
.version = version,
125+
.optimize = optimize,
126+
});
127+
as_exe.addCSourceFiles(.{
128+
.root = AFLplusplus_src_path,
129+
.files = &.{"afl-as.c"},
130+
.flags = flags.constSlice(),
131+
});
132+
as_exe.addIncludePath(AFLplusplus_inc_path);
133+
as_exe.linkSystemLibrary("z");
134+
as_exe.linkLibC();
135+
136+
const as_exe_install = b.addInstallArtifact(as_exe, .{});
137+
exes_step.dependOn(&as_exe_install.step);
138+
139+
b.default_step.dependOn(exes_step);
140+
141+
// Formatting checks
142+
const fmt_step = b.step("fmt", "Run formatting checks");
143+
144+
const fmt = b.addFmt(.{
145+
.paths = &.{
146+
"build.zig",
147+
},
148+
.check = true,
149+
});
150+
fmt_step.dependOn(&fmt.step);
151+
b.default_step.dependOn(fmt_step);
152+
}
153+
154+
const FUZZ_SOURCES = .{
155+
"afl-fuzz-bitmap.c",
156+
"afl-fuzz-cmplog.c",
157+
"afl-fuzz-extras.c",
158+
"afl-fuzz-init.c",
159+
"afl-fuzz-mutators.c",
160+
"afl-fuzz-one.c",
161+
"afl-fuzz-python.c",
162+
"afl-fuzz-queue.c",
163+
"afl-fuzz-redqueen.c",
164+
"afl-fuzz-run.c",
165+
"afl-fuzz-skipdet.c",
166+
"afl-fuzz-state.c",
167+
"afl-fuzz-stats.c",
168+
"afl-fuzz-statsd.c",
169+
"afl-fuzz.c",
170+
};
171+
172+
const SHARED_SOURCES = .{
173+
"afl-performance.c",
174+
"afl-common.c",
175+
"afl-forkserver.c",
176+
"afl-sharedmem.c",
177+
};
178+
179+
const FLAGS = .{
180+
"-O2",
181+
"-g",
182+
"-Wno-pointer-sign",
183+
"-Wno-variadic-macros",
184+
"-Wall",
185+
"-Wextra",
186+
"-Wno-pointer-arith",
187+
"-D_AFL_SPECIAL_PERFORMANCE",
188+
"-DHAVE_ZLIB",
189+
"-DAFL_PATH=\"\"",
190+
"-DBIN_PATH=\"\"",
191+
"-DDOC_PATH=\"\"",
192+
};

build.zig.zon

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.{
2+
.name = "AFLplusplus",
3+
.version = "4.21.0",
4+
.minimum_zig_version = "0.13.0",
5+
.dependencies = .{
6+
.AFLplusplus = .{
7+
.url = "https://github.com/AFLplusplus/AFLplusplus/archive/19ca7b3.tar.gz",
8+
.hash = "12202609f778b890810bfa3a2574c8319dc211e170419bc2bc4f51241f549ba5033a",
9+
},
10+
},
11+
.paths = .{
12+
"build.zig",
13+
"build.zig.zon",
14+
"LICENSE",
15+
"README.md",
16+
},
17+
}

0 commit comments

Comments
 (0)