mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00

This is a larger internal change that moves the analyzer infrastructure to a more flexible model where the available analyzers don't need to be hardcoded at compile time anymore. While currently they actually still are, this will in the future enable external analyzer plugins. For now, it does already add the capability to dynamically enable/disable analyzers from script-land, replacing the old Analyzer::Available() methods. There are three major parts going into this: - A new plugin infrastructure in src/plugin. This is independent of analyzers and will eventually support plugins for other parts of Bro as well (think: readers and writers). The goal is that plugins can be alternatively compiled in statically or loadead dynamically at runtime from a shared library. While the latter isn't there yet, there'll be almost no code change for a plugin to make it dynamic later (hopefully :) - New analyzer infrastructure in src/analyzer. I've moved a number of analyzer-related classes here, including Analyzer and DPM; the latter now renamed to Analyzer::Manager. More will move here later. Currently, there's only one plugin here, which provides *all* existing analyzers. We can modularize this further in the future (or not). - A new script interface in base/framework/analyzer. I think that this will eventually replace the dpm framework, but for now that's still there as well, though some parts have moved over. I've also remove the dpd_config table; ports are now configured via the analyzer framework. For exmaple, for SSH: const ports = { 22/tcp } &redef; event bro_init() &priority=5 { ... Analyzer::register_for_ports(Analyzer::ANALYZER_SSH, ports); } As you can see, the old ANALYZER_SSH constants have more into an enum in the Analyzer namespace. This is all hardly tested right now, and not everything works yet. There's also a lot more cleanup to do (moving more classes around; removing no longer used functionality; documenting script and C++ interfaces; regression tests). But it seems to generally work with a small trace at least. The debug stream "dpm" shows more about the loaded/enabled analyzers. A new option -N lists loaded plugins and what they provide (including those compiled in statically; i.e., right now it outputs all the analyzers). This is all not cast-in-stone yet, for some things we need to see if they make sense this way. Feedback welcome.
73 lines
2.1 KiB
C++
73 lines
2.1 KiB
C++
#ifndef base64_h
|
|
#define base64_h
|
|
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "util.h"
|
|
#include "BroString.h"
|
|
#include "Reporter.h"
|
|
#include "analyzer/Analyzer.h"
|
|
|
|
// Maybe we should have a base class for generic decoders?
|
|
class Base64Converter {
|
|
public:
|
|
// <analyzer> is used for error reporting, and it should be zero when
|
|
// the decoder is called by the built-in function decode_base64() or encode_base64().
|
|
// Empty alphabet indicates the default base64 alphabet.
|
|
Base64Converter(analyzer::Analyzer* analyzer, const string& alphabet = "");
|
|
~Base64Converter();
|
|
|
|
// A note on Decode():
|
|
//
|
|
// The input is specified by <len> and <data> and the output
|
|
// buffer by <blen> and <buf>. If *buf is nil, a buffer of
|
|
// an appropriate size will be new'd and *buf will point
|
|
// to the buffer on return. *blen holds the length of
|
|
// decoded data on return. The function returns the number of
|
|
// input bytes processed, since the decoding will stop when there
|
|
// is not enough output buffer space.
|
|
|
|
int Decode(int len, const char* data, int* blen, char** buf);
|
|
void Encode(int len, const unsigned char* data, int* blen, char** buf);
|
|
|
|
int Done(int* pblen, char** pbuf);
|
|
int HasData() const { return base64_group_next != 0; }
|
|
|
|
// True if an error has occurred.
|
|
int Errored() const { return errored; }
|
|
|
|
const char* ErrorMsg() const { return error_msg; }
|
|
void IllegalEncoding(const char* msg)
|
|
{
|
|
// strncpy(error_msg, msg, sizeof(error_msg));
|
|
if ( analyzer )
|
|
analyzer->Weird("base64_illegal_encoding", msg);
|
|
else
|
|
reporter->Error("%s", msg);
|
|
}
|
|
|
|
protected:
|
|
char error_msg[256];
|
|
|
|
protected:
|
|
static const string default_alphabet;
|
|
string alphabet;
|
|
|
|
static int* InitBase64Table(const string& alphabet);
|
|
static int default_base64_table[256];
|
|
char base64_group[4];
|
|
int base64_group_next;
|
|
int base64_padding;
|
|
int base64_after_padding;
|
|
int* base64_table;
|
|
int errored; // if true, we encountered an error - skip further processing
|
|
analyzer::Analyzer* analyzer;
|
|
|
|
};
|
|
|
|
BroString* decode_base64(const BroString* s, const BroString* a = 0);
|
|
BroString* encode_base64(const BroString* s, const BroString* a = 0);
|
|
|
|
#endif /* base64_h */
|