Adversarial C2 Protocol Implemented in Zig
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Upgrade deps to 0.15.1

+131 -61
+125 -55
build.zig
··· 1 1 const std = @import("std"); 2 2 3 - // Although this function looks imperative, note that its job is to 4 - // declaratively construct a build graph that will be executed by an external 5 - // runner. 3 + // Although this function looks imperative, it does not perform the build 4 + // directly and instead it mutates the build graph (`b`) that will be then 5 + // executed by an external runner. The functions in `std.Build` implement a DSL 6 + // for defining build steps and express dependencies between them, allowing the 7 + // build runner to parallelize the build automatically (and the cache system to 8 + // know when a step doesn't need to be re-run). 6 9 pub fn build(b: *std.Build) void { 7 - // Standard target options allows the person running `zig build` to choose 10 + // Standard target options allow the person running `zig build` to choose 8 11 // what target to build for. Here we do not override the defaults, which 9 12 // means any target is allowed, and the default is native. Other options 10 13 // for restricting supported target set are available. 11 14 const target = b.standardTargetOptions(.{}); 12 - 13 15 // Standard optimization options allow the person running `zig build` to select 14 16 // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not 15 17 // set a preferred release mode, allowing the user to decide how to optimize. 16 18 const optimize = b.standardOptimizeOption(.{}); 19 + // It's also possible to define more custom flags to toggle optional features 20 + // of this build script using `b.option()`. All defined flags (including 21 + // target and optimize options) will be listed when running `zig build --help` 22 + // in this directory. 17 23 18 - const lib_mod = b.createModule(.{ 24 + // This creates a module, which represents a collection of source files alongside 25 + // some compilation options, such as optimization mode and linked system libraries. 26 + // Zig modules are the preferred way of making Zig code available to consumers. 27 + // addModule defines a module that we intend to make available for importing 28 + // to our consumers. We must give it a name because a Zig package can expose 29 + // multiple modules and consumers will need to be able to specify which 30 + // module they want to access. 31 + const mod = b.addModule("zaprus", .{ 32 + // The root source file is the "entry point" of this module. Users of 33 + // this module will only be able to access public declarations contained 34 + // in this file, which means that if you have declarations that you 35 + // intend to expose to consumers that were defined in other files part 36 + // of this module, you will have to make sure to re-export them from 37 + // the root file. 19 38 .root_source_file = b.path("src/root.zig"), 20 - .target = target, 21 - .optimize = optimize, 22 - }); 23 - 24 - // We will also create a module for our other entry point, 'main.zig'. 25 - const exe_mod = b.createModule(.{ 26 - // `root_source_file` is the Zig "entry point" of the module. If a module 27 - // only contains e.g. external object files, you can make this `null`. 28 - // In this case the main source file is merely a path, however, in more 29 - // complicated build scripts, this could be a generated file. 30 - .root_source_file = b.path("src/main.zig"), 39 + // Later on we'll use this module as the root module of a test executable 40 + // which requires us to specify a target. 31 41 .target = target, 32 - .optimize = optimize, 33 42 }); 34 43 35 - lib_mod.addImport("network", b.dependency("network", .{}).module("network")); 36 - lib_mod.addImport("gatorcat", b.dependency("gatorcat", .{}).module("gatorcat")); 44 + mod.addImport("network", b.dependency("network", .{}).module("network")); 45 + mod.addImport("gatorcat", b.dependency("gatorcat", .{}).module("gatorcat")); 37 46 38 - exe_mod.addImport("zaprus", lib_mod); 39 - exe_mod.addImport("clap", b.dependency("clap", .{}).module("clap")); 40 - 41 - const lib = b.addLibrary(.{ 42 - .linkage = .static, 43 - .name = "zaprus", 44 - .root_module = lib_mod, 45 - }); 46 - 47 - b.installArtifact(lib); 48 - 49 - // This creates another `std.Build.Step.Compile`, but this one builds an executable 50 - // rather than a static library. 47 + // Here we define an executable. An executable needs to have a root module 48 + // which needs to expose a `main` function. While we could add a main function 49 + // to the module defined above, it's sometimes preferable to split business 50 + // business logic and the CLI into two separate modules. 51 + // 52 + // If your goal is to create a Zig library for others to use, consider if 53 + // it might benefit from also exposing a CLI tool. A parser library for a 54 + // data serialization format could also bundle a CLI syntax checker, for example. 55 + // 56 + // If instead your goal is to create an executable, consider if users might 57 + // be interested in also being able to embed the core functionality of your 58 + // program in their own executable in order to avoid the overhead involved in 59 + // subprocessing your CLI tool. 60 + // 61 + // If neither case applies to you, feel free to delete the declaration you 62 + // don't need and to put everything under a single module. 51 63 const exe = b.addExecutable(.{ 52 64 .name = "zaprus", 53 - .root_module = exe_mod, 65 + .root_module = b.createModule(.{ 66 + // b.createModule defines a new module just like b.addModule but, 67 + // unlike b.addModule, it does not expose the module to consumers of 68 + // this package, which is why in this case we don't have to give it a name. 69 + .root_source_file = b.path("src/main.zig"), 70 + // Target and optimization levels must be explicitly wired in when 71 + // defining an executable or library (in the root module), and you 72 + // can also hardcode a specific target for an executable or library 73 + // definition if desireable (e.g. firmware for embedded devices). 74 + .target = target, 75 + .optimize = optimize, 76 + // List of modules available for import in source files part of the 77 + // root module. 78 + .imports = &.{ 79 + // Here "zaprus" is the name you will use in your source code to 80 + // import this module (e.g. `@import("zaprus")`). The name is 81 + // repeated because you are allowed to rename your imports, which 82 + // can be extremely useful in case of collisions (which can happen 83 + // importing modules from different packages). 84 + .{ .name = "zaprus", .module = mod }, 85 + .{ .name = "clap", .module = b.dependency("clap", .{}).module("clap") }, 86 + }, 87 + }), 54 88 }); 55 89 56 90 // This declares intent for the executable to be installed into the 57 - // standard location when the user invokes the "install" step (the default 58 - // step when running `zig build`). 91 + // install prefix when running `zig build` (i.e. when executing the default 92 + // step). By default the install prefix is `zig-out/` but can be overridden 93 + // by passing `--prefix` or `-p`. 59 94 b.installArtifact(exe); 95 + b.installArtifact(b.addLibrary(.{ 96 + .linkage = .static, 97 + .name = "zaprus", 98 + .root_module = mod, 99 + })); 60 100 61 - // This *creates* a Run step in the build graph, to be executed when another 62 - // step is evaluated that depends on it. The next line below will establish 63 - // such a dependency. 101 + // This creates a top level step. Top level steps have a name and can be 102 + // invoked by name when running `zig build` (e.g. `zig build run`). 103 + // This will evaluate the `run` step rather than the default step. 104 + // For a top level step to actually do something, it must depend on other 105 + // steps (e.g. a Run step, as we will see in a moment). 106 + const run_step = b.step("run", "Run the app"); 107 + 108 + // This creates a RunArtifact step in the build graph. A RunArtifact step 109 + // invokes an executable compiled by Zig. Steps will only be executed by the 110 + // runner if invoked directly by the user (in the case of top level steps) 111 + // or if another step depends on it, so it's up to you to define when and 112 + // how this Run step will be executed. In our case we want to run it when 113 + // the user runs `zig build run`, so we create a dependency link. 64 114 const run_cmd = b.addRunArtifact(exe); 115 + run_step.dependOn(&run_cmd.step); 65 116 66 - // By making the run step depend on the install step, it will be run from the 117 + // By making the run step depend on the default step, it will be run from the 67 118 // installation directory rather than directly from within the cache directory. 68 - // This is not necessary, however, if the application depends on other installed 69 - // files, this ensures they will be present and in the expected location. 70 119 run_cmd.step.dependOn(b.getInstallStep()); 71 120 72 121 // This allows the user to pass arguments to the application in the build ··· 75 124 run_cmd.addArgs(args); 76 125 } 77 126 78 - // This creates a build step. It will be visible in the `zig build --help` menu, 79 - // and can be selected like this: `zig build run` 80 - // This will evaluate the `run` step rather than the default, which is "install". 81 - const run_step = b.step("run", "Run the app"); 82 - run_step.dependOn(&run_cmd.step); 127 + // Creates an executable that will run `test` blocks from the provided module. 128 + // Here `mod` needs to define a target, which is why earlier we made sure to 129 + // set the releative field. 130 + const mod_tests = b.addTest(.{ 131 + .root_module = mod, 132 + }); 133 + 134 + // A run step that will run the test executable. 135 + const run_mod_tests = b.addRunArtifact(mod_tests); 83 136 84 - const exe_unit_tests = b.addTest(.{ 85 - .root_module = exe_mod, 137 + // Creates an executable that will run `test` blocks from the executable's 138 + // root module. Note that test executables only test one module at a time, 139 + // hence why we have to create two separate ones. 140 + const exe_tests = b.addTest(.{ 141 + .root_module = exe.root_module, 86 142 }); 87 143 88 - const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); 144 + // A run step that will run the second test executable. 145 + const run_exe_tests = b.addRunArtifact(exe_tests); 146 + 147 + // A top level step for running all tests. dependOn can be called multiple 148 + // times and since the two run steps do not depend on one another, this will 149 + // make the two of them run in parallel. 150 + const test_step = b.step("test", "Run tests"); 151 + test_step.dependOn(&run_mod_tests.step); 152 + test_step.dependOn(&run_exe_tests.step); 89 153 90 - // Similar to creating the run step earlier, this exposes a `test` step to 91 - // the `zig build --help` menu, providing a way for the user to request 92 - // running the unit tests. 93 - const test_step = b.step("test", "Run unit tests"); 94 - test_step.dependOn(&run_exe_unit_tests.step); 154 + // Just like flags, top level steps are also listed in the `--help` menu. 155 + // 156 + // The Zig build system is entirely implemented in userland, which means 157 + // that it cannot hook into private compiler APIs. All compilation work 158 + // orchestrated by the build system will result in other Zig compiler 159 + // subcommands being invoked with the right flags defined. You can observe 160 + // these invocations when one fails (or you pass a flag to increase 161 + // verbosity) to validate assumptions and diagnose problems. 162 + // 163 + // Lastly, the Zig build system is relatively simple and self-contained, 164 + // and reading its source code will allow you to master it. 95 165 }
+6 -6
build.zig.zon
··· 37 37 // internet connectivity. 38 38 .dependencies = .{ 39 39 .network = .{ 40 - .url = "https://github.com/ikskuh/zig-network/archive/c76240d2240711a3dcbf1c0fb461d5d1f18be79a.zip", 41 - .hash = "network-0.1.0-AAAAAOwlAQAQ6zKPUrsibdpGisxld9ftUKGdMvcCSpaj", 40 + .url = "git+https://github.com/ikskuh/zig-network#7947237eec317d9458897f82089f343a05450c2b", 41 + .hash = "network-0.1.0-Pm-Agl8xAQBmkwohveGOfTk4zQnuqDs0Ptfbms4KP5Ce", 42 42 }, 43 43 .clap = .{ 44 - .url = "git+https://github.com/Hejsil/zig-clap?ref=0.10.0#e47028deaefc2fb396d3d9e9f7bd776ae0b2a43a", 45 - .hash = "clap-0.10.0-oBajB434AQBDh-Ei3YtoKIRxZacVPF1iSwp3IX_ZB8f0", 44 + .url = "git+https://github.com/Hejsil/zig-clap#9cfa61596cd44ef7be35f8d2e108d2025e09868e", 45 + .hash = "clap-0.10.0-oBajB_TnAQB0l5UdW9WYhhJDEswbedvwFOzzZwGknYeR", 46 46 }, 47 47 .gatorcat = .{ 48 - .url = "git+https://github.com/kj4tmp/gatorcat.git#0a97b666677501db4939e3e8245f88a19e015893", 49 - .hash = "gatorcat-0.3.4-WcrpTcleBwCta_9TjomuIGb3bdg2Pke_FXI_WkMTEivH", 48 + .url = "git+https://github.com/jeffective/gatorcat#db73d0f7780331d82e785e85773d1afaf154c2e6", 49 + .hash = "gatorcat-0.3.11-WcrpTQn0BwArrCFVHy9FPBIPDJQqPrFdJlhiyH7Ng5x4", 50 50 }, 51 51 }, 52 52 .paths = .{