@kangyishuai/dsh-casefile 0.7.1 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions.js +5 -1
- package/lib/core/ingest-craft.js +111 -0
- package/lib/core/ingest.js +10 -4
- package/package.json +1 -1
package/lib/actions.js
CHANGED
|
@@ -19,6 +19,7 @@ import { buildBundle } from "./core/bundle.js";
|
|
|
19
19
|
import { createCheckers } from "./core/checks.js";
|
|
20
20
|
import { hashTree, shortDigest } from "./core/digest.js";
|
|
21
21
|
import { validateIngestPayload } from "./core/ingest.js";
|
|
22
|
+
import { looksLikeCraftReport, mapCraftReport } from "./core/ingest-craft.js";
|
|
22
23
|
import { awaitLogin } from "./core/login-wait.js";
|
|
23
24
|
import { gradeCapabilities } from "./core/manifest.js";
|
|
24
25
|
import {
|
|
@@ -1227,7 +1228,10 @@ export function createActions(options) {
|
|
|
1227
1228
|
*/
|
|
1228
1229
|
async ingestReport(projectId, payload, options = {}) {
|
|
1229
1230
|
const project = requireProject(projectId);
|
|
1230
|
-
|
|
1231
|
+
// 别的 agent 的报告常是「证据账本」形状(subject/operation/result…)。
|
|
1232
|
+
// Craft 的公开字段可自动映射;其余形状要求调用方先自己转成契约。
|
|
1233
|
+
const shaped = looksLikeCraftReport(payload) ? mapCraftReport(payload) : payload;
|
|
1234
|
+
const normalized = validateIngestPayload(shaped);
|
|
1231
1235
|
const dryRun = options?.dryRun === true;
|
|
1232
1236
|
|
|
1233
1237
|
// 报告本体若有路径,归档进项目目录(/tmp 会过期,过期就没法复算)
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// core/ingest-craft.js:把 Craft Anything 的报告映射成 casefile 的通用摄入契约。
|
|
3
|
+
//
|
|
4
|
+
// 依据:Craft 的 `craft-anything-evidence` 公开文档——每条工具结果是一条 Evidence
|
|
5
|
+
// 记录,字段为 subject / operation / params / result / confidence / authority /
|
|
6
|
+
// limitations(coverage) / locations,另有独立的 Unknown 记录(开放问题)。
|
|
7
|
+
// 我们只做**字段搬运**,不解释它的语义,也不替它提升置信度。
|
|
8
|
+
//
|
|
9
|
+
// ⚠️ 未用真实样例验证:本机没有装 Craft,映射按公开文档的字段名写,
|
|
10
|
+
// 首次拿到真实报告时需要复核(字段名变了会报 invalid-input,而不是静默丢字段)。
|
|
11
|
+
|
|
12
|
+
const OPERATION_KINDS = [
|
|
13
|
+
["disasm", "structure"],
|
|
14
|
+
["analy", "structure"],
|
|
15
|
+
["triage", "structure"],
|
|
16
|
+
["dossier", "structure"],
|
|
17
|
+
["parse", "structure"],
|
|
18
|
+
["string", "string"],
|
|
19
|
+
["js", "behavior"],
|
|
20
|
+
["network", "har"],
|
|
21
|
+
["capture", "har"],
|
|
22
|
+
["screenshot", "screen"],
|
|
23
|
+
["plist", "structure"],
|
|
24
|
+
["signature", "structure"],
|
|
25
|
+
["entitle", "structure"],
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 判断一份 JSON 是否像 Craft 的报告。
|
|
30
|
+
* @param {any} raw
|
|
31
|
+
* @returns {boolean}
|
|
32
|
+
*/
|
|
33
|
+
export function looksLikeCraftReport(raw) {
|
|
34
|
+
if (raw == null || typeof raw !== "object") return false;
|
|
35
|
+
const records = Array.isArray(raw) ? raw : (raw.evidence ?? raw.records);
|
|
36
|
+
if (!Array.isArray(records) || records.length === 0) return false;
|
|
37
|
+
return records.every(
|
|
38
|
+
(item) =>
|
|
39
|
+
item &&
|
|
40
|
+
typeof item === "object" &&
|
|
41
|
+
typeof item.operation === "string" &&
|
|
42
|
+
item.subject !== undefined,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @param {string} operation */
|
|
47
|
+
function kindForOperation(operation) {
|
|
48
|
+
const lower = String(operation).toLowerCase();
|
|
49
|
+
for (const [needle, kind] of OPERATION_KINDS) if (lower.includes(needle)) return kind;
|
|
50
|
+
return "other";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 把 Craft 报告映射成通用契约 payload。
|
|
55
|
+
* @param {any} raw
|
|
56
|
+
* @returns {Record<string, any>}
|
|
57
|
+
*/
|
|
58
|
+
export function mapCraftReport(raw) {
|
|
59
|
+
const records = Array.isArray(raw) ? raw : (raw.evidence ?? raw.records);
|
|
60
|
+
/** @type {Record<string, any>[]} */
|
|
61
|
+
const evidence = records.map((/** @type {any} */ record) => {
|
|
62
|
+
const subject = record.subject ?? {};
|
|
63
|
+
const subjectName =
|
|
64
|
+
typeof subject === "string"
|
|
65
|
+
? subject
|
|
66
|
+
: (subject.name ?? subject.path ?? subject.id ?? "未知对象");
|
|
67
|
+
const result = record.result ?? record.normalized_result ?? null;
|
|
68
|
+
const resultHint =
|
|
69
|
+
result == null
|
|
70
|
+
? "(无可读结果)"
|
|
71
|
+
: typeof result === "string"
|
|
72
|
+
? result.slice(0, 160)
|
|
73
|
+
: Array.isArray(result)
|
|
74
|
+
? `数组 ${result.length} 项`
|
|
75
|
+
: `字段 ${Object.keys(result).slice(0, 6).join("/")}`;
|
|
76
|
+
const locations = Array.isArray(record.locations) ? record.locations : [];
|
|
77
|
+
return {
|
|
78
|
+
summary: `Craft ${record.operation} on ${String(subjectName)}:${resultHint}`,
|
|
79
|
+
kind: kindForOperation(record.operation),
|
|
80
|
+
limitations: [
|
|
81
|
+
...(Array.isArray(record.limitations) ? record.limitations.map(String) : []),
|
|
82
|
+
"本条目由 Craft 产出,经映射写入;casefile 未复核其内容",
|
|
83
|
+
],
|
|
84
|
+
refs: locations
|
|
85
|
+
.map((/** @type {any} */ loc) => (loc && (loc.path ?? loc.file)) ?? null)
|
|
86
|
+
.filter((/** @type {any} */ item) => item != null)
|
|
87
|
+
.map(String),
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const unknownsRaw = Array.isArray(raw?.unknowns) ? raw.unknowns : [];
|
|
92
|
+
/** @type {Record<string, any>[]} */
|
|
93
|
+
const unknowns = unknownsRaw.map((/** @type {any} */ item) => ({
|
|
94
|
+
text: String(item?.text ?? item?.question ?? "(外部未知项)").slice(0, 500),
|
|
95
|
+
severity: ["low", "medium", "high"].includes(item?.severity) ? item.severity : "low",
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
version: 1,
|
|
100
|
+
source: {
|
|
101
|
+
tool: "craft-anything",
|
|
102
|
+
version: typeof raw?.version === "string" ? raw.version : null,
|
|
103
|
+
mode: "archive",
|
|
104
|
+
producedAt: typeof raw?.generatedAt === "string" ? raw.generatedAt : null,
|
|
105
|
+
reportPath: null,
|
|
106
|
+
},
|
|
107
|
+
evidence,
|
|
108
|
+
claims: [],
|
|
109
|
+
unknowns,
|
|
110
|
+
};
|
|
111
|
+
}
|
package/lib/core/ingest.js
CHANGED
|
@@ -18,13 +18,19 @@
|
|
|
18
18
|
/** 摄入契约版本;形状变化时递增。 */
|
|
19
19
|
export const INGEST_VERSION = 1;
|
|
20
20
|
|
|
21
|
+
// 必须与 core/model.js 的 evidence kind 枚举**完全一致**,否则摄入会被模型层拒绝。
|
|
22
|
+
// (这个不一致是真机跑出来的:Craft 的 capture.network 被映射成 network → invalid-input)
|
|
21
23
|
const EVIDENCE_KINDS = [
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
+
"pseudocode",
|
|
25
|
+
"assembly",
|
|
24
26
|
"string",
|
|
27
|
+
"xref",
|
|
28
|
+
"callgraph",
|
|
29
|
+
"har",
|
|
30
|
+
"process",
|
|
25
31
|
"screen",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
32
|
+
"structure",
|
|
33
|
+
"behavior",
|
|
28
34
|
"other",
|
|
29
35
|
];
|
|
30
36
|
const CLAIM_KINDS = ["structure", "behavior", "string", "other"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kangyishuai/dsh-casefile",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Evidence-first reverse-engineering workbench on top of REA: observations become citable evidence, a handoff spec pack, and recomputable acceptance checks. No bridge, no engine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|