MCPcopy Create free account
hub / github.com/MemNixFS/MemNixFS / main

Function main

tests/unit/yara_format_test.cpp:16–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14 } while (0)
15
16int main() {
17 const lmpfs::u8 sample[] = {
18 'm','e','t','e','r','p','r','e','t','e','r','/',
19 'x','\n','\t','\\','"',0x00,0xff
20 };
21 const std::string text = yara_text_preview(sample, sizeof(sample));
22 CHECK(text == "meterpreter/x\\n\\t\\\\\\\"\\x00\\xff",
23 "text preview is readable and safely escapes control/binary bytes");
24
25 const std::string hex = yara_hex_preview(sample, sizeof(sample));
26 CHECK(hex.rfind("6d 65 74 65 72 70 72 65 74 65 72", 0) == 0,
27 "hex preview preserves exact bytes");
28
29 lmpfs::u8 long_data[80];
30 for (auto& b : long_data) b = 'A';
31 CHECK(yara_text_preview(long_data, sizeof(long_data)).size() == 64,
32 "text preview is capped at 64 readable bytes");
33 CHECK(yara_hex_preview(long_data, sizeof(long_data)).size() == 95,
34 "hex preview is capped at 32 bytes");
35
36 const lmpfs::u8 heap_tail[] = {'s','o','c','a','t',' ',0,0,0,0,0,0};
37 CHECK(yara_text_preview(heap_tail, sizeof(heap_tail)) == "socat ...",
38 "sustained binary heap data is collapsed");
39
40 const lmpfs::u8 binary_only[] = {0x90,0x90,0x90,0x90,0x90};
41 CHECK(yara_text_preview(binary_only, sizeof(binary_only)) == "<binary data>",
42 "binary-only matches receive a readable label");
43
44 if (g_failures) {
45 std::printf("\n== %d failure(s) ==\n", g_failures);
46 return 1;
47 }
48 std::printf("\nall YARA formatting tests passed\n");
49 return 0;
50}

Callers

nothing calls this directly

Calls 3

yara_text_previewFunction · 0.85
yara_hex_previewFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected