3.5b's ordered exec-lineage proved inert in clean A/Bs; replace it with a general write->exec data-flow feature: WindowSummary.self_written_execs (exec of a file written earlier in the same window) at x[42], tracked via OpenWindow.written_paths. Honest status: this is the conceptually-correct provenance feature (it separates download->exec-the-same-file from download->exec-unrelated), but it ALSO shows no AUC gain on detector-labeled data -- for the same structural reason as 3.5b: the teacher labels (DownloadThenExecute etc.) correlate with existing count/location features or re-derive the detector. Validating provenance LEARNING requires the novel-chain generalization benchmark (train on detector-covered, hold out detector-evading attacks); committed as that benchmark's feature foundation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
65 lines
2.3 KiB
C++
65 lines
2.3 KiB
C++
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <string>
|
|
|
|
#include "strawberry/learn/features.hpp"
|
|
|
|
using namespace strawberry::learn;
|
|
|
|
#define CHECK(cond) \
|
|
do { \
|
|
if (!(cond)) { \
|
|
std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
|
|
std::exit(1); \
|
|
} \
|
|
} while (0)
|
|
|
|
int main() {
|
|
static_assert(kTupleKinds == 5, "layout assumes 5 tuple kinds");
|
|
static_assert(37 + kTupleKinds <= kDenseDims, "fleet slots must fit in dense dims");
|
|
{
|
|
WindowSummary s{};
|
|
auto x0 = featurize(s);
|
|
CHECK(x0[37] == 0.0f && x0[41] == 0.0f);
|
|
}
|
|
{
|
|
WindowSummary s{};
|
|
s.fleet_bits = {1.6f, 3.2f, 0.0f, 16.0f, 8.0f};
|
|
auto x = featurize(s);
|
|
CHECK(x[37] == 1.6f / 16.0f);
|
|
CHECK(x[38] == 3.2f / 16.0f);
|
|
CHECK(x[39] == 0.0f);
|
|
CHECK(x[40] == 16.0f / 16.0f);
|
|
CHECK(x[41] == 8.0f / 16.0f);
|
|
}
|
|
{
|
|
WindowSummary s{};
|
|
s.max_bits = {2, 4, 6, 8, 10};
|
|
s.fleet_bits = {1, 1, 1, 1, 1};
|
|
CHECK(featurize(s)[25] == 2.0f / 16.0f);
|
|
}
|
|
{
|
|
// Write->exec data-flow (Stage 3.5b2): differs exactly at x[42].
|
|
WindowSummary a{};
|
|
a.execs = 4;
|
|
WindowSummary b = a;
|
|
b.self_written_execs = 2;
|
|
const auto xa = featurize(a);
|
|
const auto xb = featurize(b);
|
|
CHECK(featurize(b) == xb); // deterministic
|
|
CHECK(xa[42] == 0.0f);
|
|
CHECK(xb[42] == 0.5f);
|
|
for (std::size_t i = 0; i < kFeatureDim; ++i) {
|
|
if (i != 42) CHECK(xa[i] == xb[i]);
|
|
}
|
|
WindowSummary c = a;
|
|
c.self_written_execs = 9; // clamped
|
|
CHECK(featurize(c)[42] == 1.0f);
|
|
CHECK(featurize(WindowSummary{})[42] == 0.0f); // execs == 0
|
|
// empty summary: hashed region stays all-zero
|
|
const auto e = featurize(WindowSummary{});
|
|
for (std::size_t i = kDenseDims; i < kFeatureDim; ++i) CHECK(e[i] == 0.0f);
|
|
}
|
|
std::puts("test_features OK");
|
|
return 0;
|
|
}
|