|
34 | 34 | #include <unistd.h> |
35 | 35 | #include <linux/version.h> |
36 | 36 |
|
| 37 | +#define BUFFERSIZE 1024 |
| 38 | +#include <b64/decode.h> |
37 | 39 | #include "ebpflow.ebpf.enc" |
38 | 40 |
|
39 | 41 | static ContainerInfo cinfo; |
40 | 42 |
|
41 | 43 | /* ******************************************* */ |
42 | 44 |
|
43 | | -std::string b64decode(const void* data, const size_t len) { |
44 | | - unsigned char* p = (unsigned char*)data; |
45 | | - int pad = len > 0 && (len % 4 || p[len - 1] == '='); |
46 | | - const size_t L = ((len + 3) / 4 - pad) * 4; |
47 | | - std::string str(L / 4 * 3 + pad, '\0'); |
48 | | - const int B64index[256] = { |
49 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
50 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
51 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 63, 62, 62, 63, 52, 53, 54, 55, |
52 | | - 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, |
53 | | - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, |
54 | | - 0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, |
55 | | - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 }; |
56 | | - |
57 | | - for(size_t i = 0, j = 0; i < L; i += 4) { |
58 | | - int n = B64index[p[i]] << 18 | |
59 | | - B64index[p[i + 1]] << 12 | |
60 | | - B64index[p[i + 2]] << 6 | |
61 | | - B64index[p[i + 3]]; |
62 | | - str[j++] = n >> 16; |
63 | | - str[j++] = n >> 8 & 0xFF; |
64 | | - str[j++] = n & 0xFF; |
65 | | - } |
66 | | - |
67 | | - if(pad) { |
68 | | - int n = B64index[p[L]] << 18 | B64index[p[L + 1]] << 12; |
69 | | - str[str.size() - 1] = n >> 16; |
70 | | - |
71 | | - if(len > L + 2 && p[L + 2] != '=') { |
72 | | - n |= B64index[p[L + 2]] << 6; |
73 | | - str.push_back(n >> 8 & 0xFF); |
74 | | - } |
75 | | - } |
76 | | - |
77 | | - return str; |
78 | | -} |
79 | | - |
80 | | -/* ******************************************* */ |
81 | | -/* ******************************************* */ |
82 | | - |
83 | 45 | static int attachEBPFTracepoint(ebpf::BPF *bpf, |
84 | 46 | const char *tracepoint, const char *probe_func) { |
85 | 47 | ebpf::StatusTuple rc = bpf->attach_tracepoint(tracepoint, probe_func); |
@@ -117,7 +79,13 @@ extern "C" { |
117 | 79 | void* init_ebpf_flow(void *priv_ptr, eBPFHandler ebpfHandler, |
118 | 80 | ebpfRetCode *rc, u_int16_t flags) { |
119 | 81 | ebpf::BPF *bpf = NULL; |
120 | | - std::string code = b64decode(ebpf_code, strlen(ebpf_code)); |
| 82 | + // Decoding ebpf b64 (http://libb64.sourceforge.net) |
| 83 | + std::stringstream ebpf_b64_s(ebpf_code); |
| 84 | + std::stringstream code_s; |
| 85 | + base64::decoder E; |
| 86 | + E.decode(ebpf_b64_s, code_s); |
| 87 | + std::string code = code_s.str().c_str(); |
| 88 | + |
121 | 89 | ebpf::StatusTuple open_res(0); |
122 | 90 |
|
123 | 91 | // Default value is 0 |
|
0 commit comments