-
Notifications
You must be signed in to change notification settings - Fork 16
/
uname.zig
61 lines (54 loc) · 1.98 KB
/
uname.zig
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
///name: uname
///description: "Print system information. With no flag, same as -s"
///author: Z-Labs
///tags: ['linux','host-recon','z-labs']
///OS: linux
///sources:
/// - 'https://raw.githubusercontent.com/The-Z-Labs/bof-launcher/main/bofs/src/coreutils/uname.zig'
///examples: '
/// uname
/// uname -a
///
/// Flags:
/// -a print all information
/// -s print the kernel name
/// -n print the network node hostname
/// -r print the kernel release
/// -v print the kernel version
/// -m print the machine hardware name
///'
///arguments:
///- name: option
/// desc: "Print only chosen system information. Supported options: -asnrvm"
/// type: string
/// required: false
const std = @import("std");
const beacon = @import("bof_api").beacon;
pub export fn go(args: ?[*]u8, args_len: i32) callconv(.C) u8 {
const utsn: std.posix.utsname = std.posix.uname();
if (args_len == 0) {
_ = beacon.printf(0, "%s\n", &utsn.sysname);
return 0;
}
var opt_size: i32 = 0;
var parser = beacon.datap{};
beacon.dataParse(&parser, args, args_len);
const opt = beacon.dataExtract(&parser, &opt_size);
const optS = opt.?[0..@as(usize, @intCast(opt_size - 1))];
std.debug.print("[uname] optS: {s} opt_size: {d}", .{ optS, opt_size });
//const optS = std.mem.sliceTo(opt, 0);
if (std.mem.eql(u8, optS, "-a")) {
_ = beacon.printf(0, "%s %s %s %s %s\n", &utsn.sysname, &utsn.nodename, &utsn.release, &utsn.version, &utsn.machine);
} else if (std.mem.eql(u8, optS, "-s")) {
_ = beacon.printf(0, "%s\n", &utsn.sysname);
} else if (std.mem.eql(u8, optS, "-n")) {
_ = beacon.printf(0, "%s\n", &utsn.nodename);
} else if (std.mem.eql(u8, optS, "-r")) {
_ = beacon.printf(0, "%s\n", &utsn.release);
} else if (std.mem.eql(u8, optS, "-v")) {
_ = beacon.printf(0, "%s\n", &utsn.version);
} else if (std.mem.eql(u8, optS, "-m")) {
_ = beacon.printf(0, "%s\n", &utsn.machine);
}
return 0;
}