mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 09:56:23 +00:00
* feat(yara): scan an admitted artifact with caller-supplied YARA rules Add inspect_yara_matches (CLI inspect-yara-matches), which runs the installed yara command (REA_YARA_COMMAND or yara on PATH) with caller-supplied rule files against one local file. The result lists matching rules with tags, typed metadata and string match offsets, bound to the SHA-256 of the scanned file and of each rule file. yara is launched with an argument list under owned process supervision. Its stdout is parsed as it streams, and the scanned file is re-verified after the scan. command_timeout_ms, max_output_bytes and max_matches are per-call arguments and runtime analysis settings with REA_YARA_* launch seeds; max_file_bytes is per call. String matches beyond max_matches are counted and coverage is partial. A rule compile error is an input error naming the rule file, and a missing yara command is reported as capability_unavailable without affecting other tools. REA bundles no rules and downloads nothing. * Address review feedback * fix(yara): keep the scanned file's observation when a rule file fails * fix(yara): require qualified Windows paths and resolve relative POSIX commands * fix(yara): stage owned snapshot, preserve CLI array bounds, and report file-size required_value * fix(yara): preserve relative includes, retain completed matches, order snapshot cleanup, and declare writesFilesystem * chore(yara): update advertised schema summary for inspect_yara_matches * fix(yara): handle regex arguments in include rewriter and retain completed matches across process cleanup * fix(yara): preserve raw include bytes and staged file identity across close * fix(yara): preserve completed rule identities and malformed-output primaries * fix(yara): bound rewritten rule staging and preserve cleanup cancellation * fix(yara): record completed rule identity before flushing rewritten includes * Address review feedback * Address review feedback * fix(skills): restore the macOS flat installer guidance this branch dropped The authored native-and-artifacts reference had lost main's macOS .pkg paragraph, so the generated Cursor plugin copy no longer matched it and the skill freshness check failed in docs, source tests and packaging. * fix(yara): classify compile errors by kind and keep unrecognized diagnostics yara 4.x prints compiler diagnostics in two forms, with and without a rule (cli/yara.c print_compiler_error). The include failure in the stub used a form yara never prints, so a real missing include was untested. Parse both forms once into severity, source, line, rule and message, classify the message by libyara's text (include, syntax, undefined, duplicate, unreadable file, other), and give one repair per kind present. Stderr lines that match no documented form are kept verbatim instead of only counted. * fix(yara): decode every meta escape yara prints and anchor diagnostic file names Meta strings: yara 4.x print_escaped_data also escapes an apostrophe and writes \a \b \v \f, so a meta value such as "author's" failed the whole scan as an unknown escape. Decode exactly the escapes yara writes, named after that function, and refuse octal forms it never writes. Diagnostics: a file name or message can contain "(N): ". Match the rule files yara was given exactly and end any other file name at the first location rather than the last. Name yara's EXIT_FAILURE. * fix(yara): keep an ambiguous diagnostic location unknown and scope duplicate advice A file name and a message can both contain "(N): ". Split an unnamed file only where one complete diagnostic remains; several splits leave the source and line null with the whole text kept, instead of shortening the file name or dropping the line to unrecognized stderr. Duplicate advice now covers string, tag and metadata identifiers within their rule, not only rule names. --------- Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
115 lines
3.2 KiB
JavaScript
115 lines
3.2 KiB
JavaScript
import { matchesGlob } from "node:path";
|
|
|
|
/** Canonical file ownership shared by Vitest and development-test planning. */
|
|
export const SOURCE_TEST_PROJECTS = [
|
|
{
|
|
name: "domain",
|
|
group: "source",
|
|
isolate: false,
|
|
include: ["src/{contracts,domain,kernel,ports}/**/*.test.ts"],
|
|
},
|
|
{
|
|
name: "services",
|
|
group: "source",
|
|
isolate: false,
|
|
include: ["src/application/**/*.test.ts"],
|
|
},
|
|
{
|
|
name: "adapters",
|
|
group: "source",
|
|
include: [
|
|
"src/*.test.ts",
|
|
"src/{android,apkSignature,apktool,jeb,adb,artifacts,browser,compression,config,cutter,deb,desktop,dotnet,electron,erlang,evm,firmware,flutter,frida,pcap,ghidra,go,gpu,hopper,hopperPaths,ida,inspector,java,javascript,kuna,main,native,nuget,oci,process,providers,python,reference,resources,rust,server,sqlite,uefi,v8,vsix,wasm,windows,yara}/**/*.test.ts",
|
|
],
|
|
},
|
|
{
|
|
name: "composition",
|
|
group: "source",
|
|
isolate: false,
|
|
include: ["tests/composition/**/*.test.ts"],
|
|
},
|
|
{
|
|
name: "conformance",
|
|
group: "source",
|
|
isolate: false,
|
|
include: ["tests/conformance/**/*.test.ts"],
|
|
exclude: ["tests/conformance/providers/hopper/realHopperSearch.test.ts"],
|
|
},
|
|
{
|
|
name: "evaluation",
|
|
group: "source",
|
|
isolate: false,
|
|
include: ["tests/evaluation/**/*.test.ts"],
|
|
},
|
|
];
|
|
|
|
export const BUILT_TEST_PROJECTS = [
|
|
{
|
|
name: "boundary",
|
|
group: "built",
|
|
include: [
|
|
"tests/boundary/**/*.test.ts",
|
|
"tests/conformance/providers/hopper/realHopperSearch.test.ts",
|
|
],
|
|
exclude: [
|
|
"tests/boundary/cli/**/*.test.ts",
|
|
"tests/boundary/mcp/**/*.test.ts",
|
|
"tests/boundary/process/**/*.test.ts",
|
|
],
|
|
},
|
|
{
|
|
name: "cli-boundary",
|
|
group: "built",
|
|
isolate: false,
|
|
include: ["tests/boundary/cli/**/*.test.ts"],
|
|
},
|
|
{
|
|
name: "process-boundary",
|
|
group: "built",
|
|
include: ["tests/boundary/process/**/*.test.ts"],
|
|
},
|
|
{
|
|
name: "mcp-boundary",
|
|
group: "built",
|
|
isolate: false,
|
|
include: ["tests/boundary/mcp/**/*.test.ts"],
|
|
},
|
|
{
|
|
name: "acceptance",
|
|
group: "built",
|
|
include: ["tests/acceptance/**/*.test.ts"],
|
|
},
|
|
{
|
|
name: "process-global",
|
|
group: "built",
|
|
include: ["tests/process-global/**/*.test.ts"],
|
|
},
|
|
];
|
|
|
|
const ALL_TEST_PROJECTS = [...SOURCE_TEST_PROJECTS, ...BUILT_TEST_PROJECTS];
|
|
|
|
/** Return the unique Vitest owner for an exact repository-relative test path. */
|
|
export const projectForTest = (testPath) => {
|
|
if (
|
|
typeof testPath !== "string" ||
|
|
testPath.startsWith("/") ||
|
|
testPath.includes("\\") ||
|
|
testPath.split("/").some((part) => part === ".." || part === ".") ||
|
|
!testPath.endsWith(".test.ts")
|
|
)
|
|
throw new Error(`Expected a normalized repository test path: ${testPath}`);
|
|
|
|
const owners = ALL_TEST_PROJECTS.filter(
|
|
({ include, exclude = [] }) =>
|
|
include.some((pattern) => matchesGlob(testPath, pattern)) &&
|
|
!exclude.some((pattern) => matchesGlob(testPath, pattern)),
|
|
);
|
|
if (owners.length !== 1)
|
|
throw new Error(
|
|
owners.length === 0
|
|
? `No test project owns ${testPath}`
|
|
: `Multiple test projects own ${testPath}: ${owners.map(({ name }) => name).join(", ")}`,
|
|
);
|
|
return owners[0];
|
|
};
|