lib/closure/src/binary/root.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const digest_mod = @import("digest.zig");
2 const elf = @import("elf.zig");
3 const pe = @import("pe.zig");
4
5 pub const digest = digest_mod.digest;
6 pub const strict = @import("strict.zig");
7
8 pub const Kind = enum {
9 elf64,
10 pe32_plus,
11 };
12
13 pub const EvidenceKind = enum {
14 symbols,
15 relocations,
16 };
17
18 pub const Range = struct {
19 offset: u64,
20 length: u64,
21 };
22
23 pub const Evidence = struct {
24 kind: EvidenceKind,
25 offset: u64,
26 length: u64,
27 };
28
29 pub const Scratch = struct {
30 ranges: []Range,
31 evidence: []Evidence,
32 };
33
34 pub const Report = struct {
35 kind: Kind,
36 ranges: []const Range,
37 evidence: []const Evidence,
38 work: u64,
39 };
40
41 const DispatchError = error{UnsupportedBinary};
42
43 pub const Error = elf.Error || pe.Error || DispatchError;
44
45 pub fn inspect(bytes: []const u8, scratch: Scratch) Error!Report {
46 if (elf.matches(bytes)) return elf.inspect(bytes, scratch);
47 if (pe.matches(bytes)) return pe.inspect(bytes, scratch);
48 return error.UnsupportedBinary;
49 }