mirror of
https://github.com/morluto/rea
synced 2026-10-28 15:07:26 -04:00
fef6f73064
* feat(adb): acquire installed APK sets from connected Android devices Add a read-only ADB device-acquisition family over the caller's adb binary: inspect_adb_client, list_adb_devices, inspect_adb_device, list_adb_packages, and pull_adb_package, exposed through the CLI and MCP with shared admission, Evidence provenance (binary, version, serial, transport), and fixed argv vectors that never reach a shell. pull_adb_package acquires the complete split set reported by pm path into a package-named directory that must not exist, digesting every file with SHA-256 and keeping per-file failure reasons and partial coverage. Device kind is reported as an inference with its basis; getprop whitelisting keeps build identity bounded. REA installs nothing and never manages devices or emulators; the first device query may start the caller's local adb server, recorded when observed. Verified against adb 34.0.5 on Linux with an Android 14 (API 34) x86_64 emulator: full 224-package inventory, a real two-APK split set pulled with byte-exact digests, and a 73.9 MB system-package pull. npm run verify:adb records the lane; parser goldens come from the same device. READMEs carry the new row in every supported language. * feat(adb): complete the adb surface with observation, transfer, and lifecycle tools Extend the ADB family from five to twenty-four operations, all through fixed adb argument vectors with no shell exposure: Observation: read_adb_logcat (bounded dump, count/buffer/pid), inspect_adb_package (dumpsys package projection), list_adb_processes (ps -A), list_adb_directory (ls -la with kinds and symlink targets), list_adb_features (hex GL versions), list_adb_services (AIDL slash-suffixed names), inspect_adb_display (wm size and density), inspect_adb_window (focus declarations), read_adb_setting (device-side nulls reported as such), capture_adb_screen (exec-out screencap with PNG dimensions), collect_adb_bugreport (digested device archive). Transfer and search: pull_adb_file and push_adb_file (device-side sha256sum verification, explicit overwrite authority), resolve_adb_packages (substring package search with exact-match flag — the find step of an easy get). Lifecycle for dynamic analysis, each declaring mutatesTarget: install_adb_package and uninstall_adb_package preserving the device's Success/Failure verdict, start_adb_app (resolve-activity then am start -W), start_adb_activity (typed extras as --es/--ez/--ei/--el/--ef), and stop_adb_app (am force-stop). Verified end-to-end against adb 34.0.5 on Linux with an Android 14 (API 34) x86_64 emulator: 287 services, 92 features, split-set pulls with byte-exact digests, verified push/pull roundtrip, sized screen capture, and the full install → resolve → start → observe-in-ps → force-stop → uninstall lifecycle. Fixed a v-mode regex incompatibility in the settings key pattern and added argument descriptions required by the CLI catalog audit. * fix(adb): quote remote shell operands and protect captured output * test(adb): cover bugreport destinations containing spaces --------- Co-authored-by: REA Contributor <contributor@rea.tools> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
326 lines
10 KiB
JavaScript
326 lines
10 KiB
JavaScript
import { names } from "./catalog-core.mjs";
|
|
|
|
/** Build tool-family counts and sorted tool-name lists. */
|
|
export const toolFamilyCatalog = (sources) => {
|
|
const families = [
|
|
{
|
|
id: "direct",
|
|
surface: "official-proxy",
|
|
contracts: sources.officialContracts.OFFICIAL_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
id: "enhanced",
|
|
surface: "enhanced",
|
|
contracts: sources.enhancedContracts.ENHANCED_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
id: "native",
|
|
surface: "native-provider",
|
|
contracts: [
|
|
...sources.nativeContracts.NATIVE_TOOL_CONTRACTS,
|
|
...sources.binaryDiagnosticsContracts.BINARY_DIAGNOSTICS_TOOL_CONTRACTS,
|
|
],
|
|
},
|
|
{
|
|
id: "artifact",
|
|
surface: "artifact-provider",
|
|
contracts: [
|
|
...sources.artifactContracts.ARTIFACT_TOOL_CONTRACTS,
|
|
...sources.evmContracts.EVM_TOOL_CONTRACTS,
|
|
],
|
|
},
|
|
{
|
|
id: "managed",
|
|
surface: "managed",
|
|
contracts: [
|
|
...sources.managedContracts.MANAGED_TOOL_CONTRACTS,
|
|
...sources.managedWorkflowContracts.MANAGED_WORKFLOW_TOOL_CONTRACTS,
|
|
],
|
|
},
|
|
{
|
|
id: "firmware",
|
|
surface: "firmware-provider",
|
|
contracts: sources.firmwareContracts.FIRMWARE_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
id: "android",
|
|
surface: "android-provider",
|
|
contracts: sources.androidContracts.ANDROID_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
id: "adb",
|
|
surface: "adb-provider",
|
|
contracts: sources.adbContracts.ADB_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
id: "browser",
|
|
surface: "browser-provider",
|
|
contracts: [
|
|
...sources.browserContracts.BROWSER_TOOL_CONTRACTS,
|
|
...sources.webRuntimeContracts.WEB_RUNTIME_TOOL_CONTRACTS,
|
|
...sources.browserScenarioContracts.BROWSER_SCENARIO_TOOL_CONTRACTS,
|
|
...sources.webNetworkCaptureContracts
|
|
.WEB_NETWORK_CAPTURE_TOOL_CONTRACTS,
|
|
],
|
|
},
|
|
{
|
|
id: "electron",
|
|
surface: "electron-provider",
|
|
contracts: sources.electronContracts.ELECTRON_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
id: "javascript-runtime",
|
|
surface: "runtime-provider",
|
|
contracts:
|
|
sources.javascriptRuntimeObservationContracts
|
|
.JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
id: "application",
|
|
surface: "application-workflow",
|
|
contracts: [
|
|
...sources.applicationContracts.APPLICATION_TOOL_CONTRACTS,
|
|
...sources.analysisViewContracts.ANALYSIS_VIEW_TOOL_CONTRACTS,
|
|
...sources.webScriptContracts.WEB_SCRIPT_TOOL_CONTRACTS,
|
|
...sources.javascriptRecoveryContracts
|
|
.JAVASCRIPT_RECOVERY_TOOL_CONTRACTS,
|
|
],
|
|
},
|
|
{
|
|
id: "session",
|
|
surface: "session",
|
|
contracts: sources.sessionContracts.SESSION_TOOL_CONTRACTS,
|
|
},
|
|
].map(({ id, surface, contracts }) => ({
|
|
id,
|
|
surface,
|
|
count: contracts.length,
|
|
tools: names(contracts),
|
|
}));
|
|
const familyTotal = families.reduce(
|
|
(total, family) => total + family.count,
|
|
0,
|
|
);
|
|
if (
|
|
familyTotal !== sources.toolContracts.TOOL_CONTRACTS.length ||
|
|
familyTotal !== sources.catalogIdentity.CATALOG_IDENTITY.counts.mcp_tools
|
|
)
|
|
throw new Error("Tool family inventory does not match TOOL_CONTRACTS");
|
|
return { total: familyTotal, families };
|
|
};
|
|
|
|
/** Build provider identities with their sorted capability names. */
|
|
export const providerCatalog = (sources) => {
|
|
const contractsByName = new Map(
|
|
sources.toolContracts.TOOL_CONTRACTS.map((contract) => [
|
|
contract.name,
|
|
contract,
|
|
]),
|
|
);
|
|
const declaredContracts = (providerId, operations) =>
|
|
operations.map((operation) => {
|
|
const contract = contractsByName.get(operation);
|
|
if (contract === undefined)
|
|
throw new TypeError(
|
|
`Provider ${providerId} declares an unknown analyst operation: ${operation}`,
|
|
);
|
|
return contract;
|
|
});
|
|
const {
|
|
applicationContracts,
|
|
reconciliationContracts,
|
|
observationContracts,
|
|
activeContracts,
|
|
} = electronContractSlices(sources);
|
|
return [
|
|
{
|
|
identity: sources.hopperProvider.HOPPER_PROVIDER_IDENTITY,
|
|
contracts: declaredContracts(
|
|
"hopper",
|
|
sources.hopperProvider.HOPPER_OPERATIONS,
|
|
),
|
|
},
|
|
{
|
|
identity: sources.ghidraProvider.GHIDRA_PROVIDER_IDENTITY,
|
|
contracts: declaredContracts(
|
|
"ghidra",
|
|
sources.ghidraProvider.GHIDRA_OPERATIONS,
|
|
),
|
|
},
|
|
{
|
|
identity: sources.idaProvider.IDA_PROVIDER_IDENTITY,
|
|
contracts: declaredContracts("ida", sources.idaProvider.IDA_OPERATIONS),
|
|
},
|
|
{
|
|
identity: sources.nativeProvider.NATIVE_MACOS_PROVIDER_IDENTITY,
|
|
contracts: sources.nativeContracts.NATIVE_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.pwntoolsProvider.PWNTOOLS_PROVIDER_IDENTITY,
|
|
contracts:
|
|
sources.binaryDiagnosticsContracts.BINARY_DIAGNOSTICS_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.evmProvider.EVMOLE_PROVIDER_IDENTITY,
|
|
contracts: sources.evmContracts.EVM_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.artifactProviders.ARTIFACT_GRAPH_PROVIDER,
|
|
contracts: sources.artifactContracts.ARTIFACT_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.artifactProviders.MANAGED_STATIC_PROVIDER,
|
|
contracts: sources.managedContracts.MANAGED_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.artifactProviders.MANAGED_WORKFLOW_PROVIDER,
|
|
contracts:
|
|
sources.managedWorkflowContracts.MANAGED_WORKFLOW_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.firmwareProvider.BINWALK_PROVIDER_IDENTITY,
|
|
contracts: sources.firmwareContracts.FIRMWARE_TOOL_CONTRACTS.filter(
|
|
({ name }) => name === "inspect_firmware_regions",
|
|
),
|
|
},
|
|
{
|
|
identity: sources.firmwareProvider.UNBLOB_PROVIDER_IDENTITY,
|
|
contracts: sources.firmwareContracts.FIRMWARE_TOOL_CONTRACTS.filter(
|
|
({ name }) => name === "extract_firmware",
|
|
),
|
|
},
|
|
{
|
|
identity: sources.androidProvider.JADX_PROVIDER_IDENTITY,
|
|
contracts: sources.androidContracts.ANDROID_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.adbProvider.ADB_PROVIDER_IDENTITY,
|
|
contracts: sources.adbContracts.ADB_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.webNetworkCaptureProvider.HAR_CAPTURE_PROVIDER_IDENTITY,
|
|
contracts:
|
|
sources.webNetworkCaptureContracts.WEB_NETWORK_CAPTURE_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity:
|
|
sources.webNetworkCaptureProvider.MITMPROXY_CAPTURE_PROVIDER_IDENTITY,
|
|
contracts:
|
|
sources.webNetworkCaptureContracts.WEB_NETWORK_CAPTURE_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.browserIdentities.CDP_BROWSER_PROVIDER_IDENTITY,
|
|
contracts: [
|
|
...sources.browserContracts.BROWSER_TOOL_CONTRACTS,
|
|
...sources.webRuntimeContracts.WEB_RUNTIME_TOOL_CONTRACTS,
|
|
],
|
|
},
|
|
{
|
|
identity:
|
|
sources.browserIdentities.PLAYWRIGHT_BROWSER_SCENARIO_PROVIDER_IDENTITY,
|
|
contracts:
|
|
sources.browserScenarioContracts.BROWSER_SCENARIO_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.browserIdentities.CDP_ELECTRON_PROVIDER_IDENTITY,
|
|
contracts: observationContracts,
|
|
},
|
|
{
|
|
identity:
|
|
sources.browserIdentities.PLAYWRIGHT_ELECTRON_ACTIVE_PROVIDER_IDENTITY,
|
|
contracts: activeContracts,
|
|
},
|
|
{
|
|
identity: sources.v8InspectorProvider.V8_INSPECTOR_PROVIDER_IDENTITY,
|
|
contracts:
|
|
sources.javascriptRuntimeObservationContracts
|
|
.JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.artifactProviders.JAVASCRIPT_APPLICATION_PROVIDER,
|
|
contracts: applicationContracts,
|
|
},
|
|
{
|
|
identity:
|
|
sources.artifactProviders.JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER,
|
|
contracts: reconciliationContracts,
|
|
},
|
|
{
|
|
identity:
|
|
sources.artifactProviders.JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER,
|
|
contracts: sources.applicationContracts.APPLICATION_TOOL_CONTRACTS.filter(
|
|
({ name }) =>
|
|
name !== "project_android_application_graph" &&
|
|
name !== "project_apple_application_graph",
|
|
),
|
|
},
|
|
{
|
|
identity: sources.artifactProviders.ANALYSIS_VIEW_PROVIDER,
|
|
contracts: sources.analysisViewContracts.ANALYSIS_VIEW_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.artifactProviders.ANDROID_APPLICATION_PROVIDER,
|
|
contracts: sources.applicationContracts.APPLICATION_TOOL_CONTRACTS.filter(
|
|
({ name }) => name === "project_android_application_graph",
|
|
),
|
|
},
|
|
{
|
|
identity: sources.artifactProviders.APPLE_APPLICATION_PROVIDER,
|
|
contracts: sources.applicationContracts.APPLICATION_TOOL_CONTRACTS.filter(
|
|
({ name }) => name === "project_apple_application_graph",
|
|
),
|
|
},
|
|
{
|
|
identity: sources.artifactProviders.WEB_SCRIPT_EXPORT_PROVIDER,
|
|
contracts: sources.webScriptContracts.WEB_SCRIPT_TOOL_CONTRACTS,
|
|
},
|
|
{
|
|
identity: sources.javascriptRecoveryProvider.WAKARU_PROVIDER_IDENTITY,
|
|
contracts:
|
|
sources.javascriptRecoveryContracts.JAVASCRIPT_RECOVERY_TOOL_CONTRACTS,
|
|
},
|
|
]
|
|
.map(({ identity, contracts }) => ({
|
|
id: identity.id,
|
|
name: identity.name,
|
|
version: identity.version,
|
|
capabilities: names(contracts),
|
|
}))
|
|
.sort((left, right) => left.id.localeCompare(right.id));
|
|
};
|
|
|
|
const electronContractSlices = (sources) => {
|
|
const applicationContracts =
|
|
sources.electronContracts.ELECTRON_TOOL_CONTRACTS.filter(
|
|
({ name }) => name === "analyze_javascript_application",
|
|
);
|
|
const reconciliationContracts =
|
|
sources.electronContracts.ELECTRON_TOOL_CONTRACTS.filter(
|
|
({ name }) => name === "reconcile_javascript_runtime",
|
|
);
|
|
const observationContracts =
|
|
sources.electronContracts.ELECTRON_TOOL_CONTRACTS.filter(
|
|
({ name }) =>
|
|
name !== "analyze_javascript_application" &&
|
|
name !== "reconcile_javascript_runtime" &&
|
|
name !== "capture_electron_scenario",
|
|
);
|
|
const activeContracts =
|
|
sources.electronContracts.ELECTRON_TOOL_CONTRACTS.filter(
|
|
({ name }) => name === "capture_electron_scenario",
|
|
);
|
|
if (
|
|
applicationContracts.length !== 1 ||
|
|
reconciliationContracts.length !== 1 ||
|
|
observationContracts.length !== 2 ||
|
|
activeContracts.length !== 1
|
|
)
|
|
throw new Error("Electron provider capability ownership drifted");
|
|
return {
|
|
applicationContracts,
|
|
reconciliationContracts,
|
|
observationContracts,
|
|
activeContracts,
|
|
};
|
|
};
|