From 2307c62a612f4f433e2bf4df2b9458f80bc4210e Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Thu, 3 Jul 2025 19:04:12 +0200 Subject: [PATCH 1/3] [Spicy] Bump `auxil/spicy/` to latest development snapshot. --- auxil/spicy | 2 +- scripts/spicy/zeek_rt.hlt | 6 +++--- src/spicy/manager.cc | 9 +++++---- src/spicy/manager.h | 16 +++++++++------- src/spicy/runtime-support.cc | 7 ++++--- src/spicy/runtime-support.h | 9 ++++++--- 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/auxil/spicy b/auxil/spicy index c262027677..f9cf2115cf 160000 --- a/auxil/spicy +++ b/auxil/spicy @@ -1 +1 @@ -Subproject commit c26202767742818a0ef0e5538ea7df5ca54620b1 +Subproject commit f9cf2115cf330e7dff61f438ba04c96d9f1a132c diff --git a/scripts/spicy/zeek_rt.hlt b/scripts/spicy/zeek_rt.hlt index 46906d8079..860dd22e68 100644 --- a/scripts/spicy/zeek_rt.hlt +++ b/scripts/spicy/zeek_rt.hlt @@ -18,9 +18,9 @@ type ZeekTypeTag = enum { } &cxxname="::zeek::spicy::rt::ZeekTypeTag"; declare public void register_spicy_module_begin(string name, string description) &cxxname="zeek::spicy::rt::register_spicy_module_begin"; -declare public void register_protocol_analyzer(string name, hilti::Protocol protocol, vector ports, string parser_orig, string parser_resp, string replaces, string linker_scope) &cxxname="zeek::spicy::rt::register_protocol_analyzer" &have_prototype; -declare public void register_file_analyzer(string name, vector mime_types, string parser, string replaces, string linker_scope) &cxxname="zeek::spicy::rt::register_file_analyzer" &have_prototype; -declare public void register_packet_analyzer(string name, string parser, string replaces, string linker_scope) &cxxname="zeek::spicy::rt::register_packet_analyzer" &have_prototype; +declare public void register_protocol_analyzer(string name, hilti::Protocol protocol, vector ports, string parser_orig, string parser_resp, string replaces, uint<64> linker_scope) &cxxname="zeek::spicy::rt::register_protocol_analyzer" &have_prototype; +declare public void register_file_analyzer(string name, vector mime_types, string parser, string replaces, uint<64> linker_scope) &cxxname="zeek::spicy::rt::register_file_analyzer" &have_prototype; +declare public void register_packet_analyzer(string name, string parser, string replaces, uint<64> linker_scope) &cxxname="zeek::spicy::rt::register_packet_analyzer" &have_prototype; declare public void register_type(string ns, string id, BroType t) &cxxname="zeek::spicy::rt::register_type" &have_prototype; declare public void register_spicy_module_end() &cxxname="zeek::spicy::rt::register_spicy_module_end"; diff --git a/src/spicy/manager.cc b/src/spicy/manager.cc index d28e811559..ef51535297 100644 --- a/src/spicy/manager.cc +++ b/src/spicy/manager.cc @@ -64,7 +64,8 @@ void Manager::registerSpicyModuleEnd() { void Manager::registerProtocolAnalyzer(const std::string& name, hilti::rt::Protocol proto, const hilti::rt::Vector<::zeek::spicy::rt::PortRange>& ports, const std::string& parser_orig, const std::string& parser_resp, - const std::string& replaces, const std::string& linker_scope) { + const std::string& replaces, + const hilti::rt::integer::safe& linker_scope) { SPICY_DEBUG(hilti::rt::fmt("Have Spicy protocol analyzer %s", name)); ProtocolAnalyzerInfo info; @@ -125,7 +126,7 @@ void Manager::registerProtocolAnalyzer(const std::string& name, hilti::rt::Proto void Manager::registerFileAnalyzer(const std::string& name, const hilti::rt::Vector& mime_types, const std::string& parser, const std::string& replaces, - const std::string& linker_scope) { + const hilti::rt::integer::safe& linker_scope) { SPICY_DEBUG(hilti::rt::fmt("Have Spicy file analyzer %s", name)); FileAnalyzerInfo info; @@ -170,7 +171,7 @@ void Manager::registerFileAnalyzer(const std::string& name, const hilti::rt::Vec } void Manager::registerPacketAnalyzer(const std::string& name, const std::string& parser, const std::string& replaces, - const std::string& linker_scope) { + const hilti::rt::integer::safe& linker_scope) { SPICY_DEBUG(hilti::rt::fmt("Have Spicy packet analyzer %s", name)); PacketAnalyzerInfo info; @@ -651,7 +652,7 @@ void Manager::InitPostScript() { // Fill in the parser information now that we derived from the ASTs. auto find_parser = [](const std::string& analyzer, const std::string& parser, - const std::string& linker_scope) -> const ::spicy::rt::Parser* { + const auto& linker_scope) -> const ::spicy::rt::Parser* { if ( parser.empty() ) return nullptr; diff --git a/src/spicy/manager.h b/src/spicy/manager.h index 9ebc2aceb7..a456b62612 100644 --- a/src/spicy/manager.h +++ b/src/spicy/manager.h @@ -2,15 +2,16 @@ #pragma once +#include #include #include #include -#include #include #include #include #include +#include #include #include "zeek/Scope.h" @@ -99,7 +100,7 @@ public: void registerProtocolAnalyzer(const std::string& name, hilti::rt::Protocol proto, const hilti::rt::Vector<::zeek::spicy::rt::PortRange>& ports, const std::string& parser_orig, const std::string& parser_resp, - const std::string& replaces, const std::string& linker_scope); + const std::string& replaces, const hilti::rt::integer::safe& linker_scope); /** * Runtime method to register a file analyzer with its Zeek-side @@ -117,7 +118,8 @@ public: * registration */ void registerFileAnalyzer(const std::string& name, const hilti::rt::Vector& mime_types, - const std::string& parser, const std::string& replaces, const std::string& linker_scope); + const std::string& parser, const std::string& replaces, + const hilti::rt::integer::safe& linker_scope); /** * Runtime method to register a packet analyzer with its Zeek-side @@ -134,7 +136,7 @@ public: * registration */ void registerPacketAnalyzer(const std::string& name, const std::string& parser, const std::string& replaces, - const std::string& linker_scope); + const hilti::rt::integer::safe& linker_scope); /** * Runtime method to register a Spicy-generated type with Zeek. The type @@ -345,7 +347,7 @@ private: std::string name_replaces; hilti::rt::Protocol protocol = hilti::rt::Protocol::Undef; std::vector<::zeek::spicy::rt::PortRange> ports; // we keep this sorted - std::string linker_scope; + hilti::rt::integer::safe linker_scope; // Computed and available once the analyzer has been registered. std::string name_zeek; @@ -371,7 +373,7 @@ private: std::string name_parser; std::string name_replaces; hilti::rt::Vector mime_types; - std::string linker_scope; + hilti::rt::integer::safe linker_scope; // Computed and available once the analyzer has been registered. std::string name_zeek; @@ -395,7 +397,7 @@ private: std::string name_analyzer; std::string name_parser; std::string name_replaces; - std::string linker_scope; + hilti::rt::integer::safe linker_scope; // Computed and available once the analyzer has been registered. std::string name_zeek; diff --git a/src/spicy/runtime-support.cc b/src/spicy/runtime-support.cc index 76cf8c1f59..a9faf37438 100644 --- a/src/spicy/runtime-support.cc +++ b/src/spicy/runtime-support.cc @@ -29,20 +29,21 @@ void rt::register_spicy_module_end() { spicy_mgr->registerSpicyModuleEnd(); } void rt::register_protocol_analyzer(const std::string& name, hilti::rt::Protocol proto, const hilti::rt::Vector<::zeek::spicy::rt::PortRange>& ports, const std::string& parser_orig, const std::string& parser_resp, - const std::string& replaces, const std::string& linker_scope) { + const std::string& replaces, + const hilti::rt::integer::safe& linker_scope) { auto _ = hilti::rt::profiler::start("zeek/rt/register_protocol_analyzer"); spicy_mgr->registerProtocolAnalyzer(name, proto, ports, parser_orig, parser_resp, replaces, linker_scope); } void rt::register_file_analyzer(const std::string& name, const hilti::rt::Vector& mime_types, const std::string& parser, const std::string& replaces, - const std::string& linker_scope) { + const hilti::rt::integer::safe& linker_scope) { auto _ = hilti::rt::profiler::start("zeek/rt/register_file_analyzer"); spicy_mgr->registerFileAnalyzer(name, mime_types, parser, replaces, linker_scope); } void rt::register_packet_analyzer(const std::string& name, const std::string& parser, const std::string& replaces, - const std::string& linker_scope) { + const hilti::rt::integer::safe& linker_scope) { auto _ = hilti::rt::profiler::start("zeek/rt/register_packet_analyzer"); spicy_mgr->registerPacketAnalyzer(name, parser, replaces, linker_scope); } diff --git a/src/spicy/runtime-support.h b/src/spicy/runtime-support.h index fef0957824..be6fcc56e7 100644 --- a/src/spicy/runtime-support.h +++ b/src/spicy/runtime-support.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -111,14 +113,15 @@ void register_spicy_module_begin(const std::string& id, const std::string& descr void register_protocol_analyzer(const std::string& id, hilti::rt::Protocol proto, const hilti::rt::Vector<::zeek::spicy::rt::PortRange>& ports, const std::string& parser_orig, const std::string& parser_resp, - const std::string& replaces, const std::string& linker_scope); + const std::string& replaces, const hilti::rt::integer::safe& linker_scope); /** * Registers a Spicy file analyzer with its EVT meta information with the * plugin's runtime. */ void register_file_analyzer(const std::string& id, const hilti::rt::Vector& mime_types, - const std::string& parser, const std::string& replaces, const std::string& linker_scope); + const std::string& parser, const std::string& replaces, + const hilti::rt::integer::safe& linker_scope); /** Reports a Zeek-side "weird". */ void weird(const std::string& id, const std::string& addl); @@ -128,7 +131,7 @@ void weird(const std::string& id, const std::string& addl); * plugin's runtime. */ void register_packet_analyzer(const std::string& id, const std::string& parser, const std::string& replaces, - const std::string& linker_scope); + const hilti::rt::integer::safe& linker_scope); /** Registers a Spicy-generated type to make it available inside Zeek. */ void register_type(const std::string& ns, const std::string& id, const TypePtr& type); From 96b8cd8ee42a5065e4e23b911057cc445b44cb6e Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Fri, 4 Jul 2025 18:39:34 +0200 Subject: [PATCH 2/3] [Spicy] Remove declarations for unimplemented functions. --- src/spicy/spicyz/driver.h | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/spicy/spicyz/driver.h b/src/spicy/spicyz/driver.h index a0228a4e45..d9a29f8a26 100644 --- a/src/spicy/spicyz/driver.h +++ b/src/spicy/spicyz/driver.h @@ -133,32 +133,6 @@ public: /** Returns the glue compiler in use by the driver. */ const auto* glueCompiler() const { return _glue.get(); } - /** - * Parses some options command-line style *before* Zeek-side scripts have - * been processed. Most of the option processing happens in - * `parseOptionsPostScript()` instead, except for things that must be in - * place already before script processing. - * - * @param options space-separated string of command line argument to parse - * @return success if all argument could be parsed, or a suitable error message - */ - static hilti::Result parseOptionsPreScript(const std::string& options); - - /** - * Parses options command-line style after Zeek-side scripts have been - * fully processed. Most of the option processing happens here (vs. in - * `parseOptionsPreScript()`) except for things that must be in place - * already before script processing. - * - * @param options space-separated string of command line argument to parse - * @param driver_options instance of options to update per parsed arguments - * @param compiler_options instance of options to update per parsed arguments - * @return success if all argument could be parsed, or a suitable error message - */ - static hilti::Result parseOptionsPostScript(const std::string& options, - hilti::driver::Options* driver_options, - hilti::Options* compiler_options); - /** Prints a usage message for options supported by `parseOptions{Pre,Post}Script()`. */ static void usage(std::ostream& out); From da59c12a9a43471c7717b761d0d96d8e3ad57420 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Wed, 9 Jul 2025 14:24:00 +0200 Subject: [PATCH 3/3] [Spicy] Add linker scope to debugging output. --- src/spicy/manager.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/spicy/manager.cc b/src/spicy/manager.cc index ef51535297..22339479e5 100644 --- a/src/spicy/manager.cc +++ b/src/spicy/manager.cc @@ -66,7 +66,7 @@ void Manager::registerProtocolAnalyzer(const std::string& name, hilti::rt::Proto const std::string& parser_orig, const std::string& parser_resp, const std::string& replaces, const hilti::rt::integer::safe& linker_scope) { - SPICY_DEBUG(hilti::rt::fmt("Have Spicy protocol analyzer %s", name)); + SPICY_DEBUG(hilti::rt::fmt("Have Spicy protocol analyzer %s (scope 0x%" PRIx64 ")", name, linker_scope.Ref())); ProtocolAnalyzerInfo info; info.name_analyzer = name; @@ -127,7 +127,7 @@ void Manager::registerProtocolAnalyzer(const std::string& name, hilti::rt::Proto void Manager::registerFileAnalyzer(const std::string& name, const hilti::rt::Vector& mime_types, const std::string& parser, const std::string& replaces, const hilti::rt::integer::safe& linker_scope) { - SPICY_DEBUG(hilti::rt::fmt("Have Spicy file analyzer %s", name)); + SPICY_DEBUG(hilti::rt::fmt("Have Spicy file analyzer %s (scope 0x%" PRIx64 ")", name, linker_scope.Ref())); FileAnalyzerInfo info; info.name_analyzer = name; @@ -172,7 +172,7 @@ void Manager::registerFileAnalyzer(const std::string& name, const hilti::rt::Vec void Manager::registerPacketAnalyzer(const std::string& name, const std::string& parser, const std::string& replaces, const hilti::rt::integer::safe& linker_scope) { - SPICY_DEBUG(hilti::rt::fmt("Have Spicy packet analyzer %s", name)); + SPICY_DEBUG(hilti::rt::fmt("Have Spicy packet analyzer %s (scope 0x%" PRIx64 ")", name, linker_scope.Ref())); PacketAnalyzerInfo info; info.name_analyzer = name; @@ -661,8 +661,8 @@ void Manager::InitPostScript() { return p; } - reporter->InternalError("Unknown Spicy parser '%s' requested by analyzer '%s'", parser.c_str(), - analyzer.c_str()); + reporter->InternalError("Unknown Spicy parser '%s' (scope 0x%" PRIx64 ") requested by analyzer '%s'", + parser.c_str(), linker_scope.Ref(), analyzer.c_str()); return nullptr; // cannot be reached }; @@ -672,7 +672,8 @@ void Manager::InitPostScript() { // vector element not set continue; - SPICY_DEBUG(hilti::rt::fmt("Registering %s protocol analyzer %s with Zeek", p.protocol, p.name_analyzer)); + SPICY_DEBUG(hilti::rt::fmt("Registering %s protocol analyzer %s (scope 0x%" PRIx64 ") with Zeek", p.protocol, + p.name_analyzer, p.linker_scope)); p.parser_orig = find_parser(p.name_analyzer, p.name_parser_orig, p.linker_scope); p.parser_resp = find_parser(p.name_analyzer, p.name_parser_resp, p.linker_scope); @@ -729,7 +730,8 @@ void Manager::InitPostScript() { // vector element not set continue; - SPICY_DEBUG(hilti::rt::fmt("Registering file analyzer %s with Zeek", p.name_analyzer.c_str())); + SPICY_DEBUG(hilti::rt::fmt("Registering file analyzer %s (scope 0x%" PRIx64 ") with Zeek", + p.name_analyzer.c_str(), p.linker_scope.Ref())); p.parser = find_parser(p.name_analyzer, p.name_parser, p.linker_scope); @@ -764,7 +766,8 @@ void Manager::InitPostScript() { // vector element not set continue; - SPICY_DEBUG(hilti::rt::fmt("Registering packet analyzer %s with Zeek", p.name_analyzer.c_str())); + SPICY_DEBUG(hilti::rt::fmt("Registering packet analyzer %s (scope 0x%" PRIx64 ") with Zeek", + p.name_analyzer.c_str(), p.linker_scope.Ref())); p.parser = find_parser(p.name_analyzer, p.name_parser, p.linker_scope); }