read_output
Retrieve output from running or completed processes during malware analysis to monitor execution results and gather forensic data.
Instructions
Read output from a running or completed process.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pid | Yes | The process ID to read output from |
Implementation Reference
- terminalManager.js:111-135 (handler)The core handler function readOutput(pid) that retrieves output from active or completed terminal sessions, formats completed output with exit code and runtime, and returns { output: string | null }.readOutput(pid) { // First check active sessions const session = this.sessions.get(pid); if (session) { const output = session.lastOutput; session.lastOutput = ''; // Clear the buffer after reading return { output }; } // Then check completed sessions const completedSession = this.completedSessions.get(pid); if (completedSession) { // Format completion message with exit code and runtime const runtime = (completedSession.endTime.getTime() - completedSession.startTime.getTime()) / 1000; const outputStr = `Process completed with exit code ${completedSession.exitCode}\nRuntime: ${runtime.toFixed(2)}s\nFinal output:\n${completedSession.output}`; // Remove from completed sessions as we've delivered the final output this.completedSessions.delete(pid); return { output: outputStr }; } // Return null if PID not found return { output: null }; }
- serverMCP.js:51-56 (schema)Zod schema defining the input parameters for the read_output tool: a required integer pid.* Schema for read_output tool * Defines parameters for reading process output */ const readOutputSchema = z.object({ pid: z.number().int().describe("The process ID to read output from") });
- serverMCP.js:105-109 (registration)Registration of the read_output tool in the ListToolsRequestSchema handler, specifying name, description, and input schema.{ name: 'read_output', description: 'Read output from a running or completed process.', inputSchema: zodToJsonSchema(readOutputSchema), },
- serverMCP.js:195-217 (handler)MCP server request handler dispatch for 'read_output' tool, which validates input and delegates to terminalManager.readOutput.case 'read_output': try { // Type-check and validate arguments if (!args || typeof args.pid !== 'number') { return { content: [{ type: "text", text: "Error: Invalid PID parameter" }], isError: true, }; } console.error(`Reading output for PID: ${args.pid}`); const result = terminalManager.readOutput(args.pid); return { content: [{ type: "text", text: JSON.stringify(result) }], }; } catch (error) { console.error('Error reading output:', error); return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true, }; }