xxd
Analyze binary files by creating hexdumps with ASCII representation to inspect file contents for malware analysis.
Instructions
Create a hexdump with ASCII representation
Example usage:
Standard xxd dump: { "target": "suspicious.exe" }
With length limit: { "target": "suspicious.exe", "length": 256 }
With column formatting: { "target": "suspicious.exe", "cols": 16 }
Binary bits mode: { "target": "suspicious.exe", "bits": true }
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| target | Yes | Target file or data to analyze | |
| options | No | Additional command-line options | |
| length | No | Number of bytes to display | |
| offset | No | Starting offset in the file | |
| cols | No | Format output into specified number of columns | |
| bits | No | Switch to bits (binary) dump |
Implementation Reference
- serverMCP.js:130-164 (handler)Core handler for executing the 'xxd' tool (and other specialized commands): validates input against schema, builds command string using tool-specific buildCommand, executes via terminalManager.shellCommand, and returns result.if (commands[name]) { try { const cmdConfig = commands[name]; // Validate arguments against schema const validationResult = cmdConfig.schema.safeParse(args); if (!validationResult.success) { return { content: [{ type: "text", text: `Error: Invalid parameters for ${name} command.\n${JSON.stringify(validationResult.error.format())}` }], isError: true, }; } // Build the command string const commandStr = cmdConfig.buildCommand(validationResult.data); console.error(`Executing specialized command: ${commandStr}`); // Execute the command via the terminal manager const result = await terminalManager.shellCommand(commandStr); console.error(`${name} command executed with PID: ${result.pid}, blocked: ${result.isBlocked}`); return { content: [{ type: "text", text: JSON.stringify(result) }], }; } catch (error) { console.error(`Error executing ${name} command:`, error); return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true, }; } }
- commands.js:142-162 (handler)xxd-specific logic to construct the xxd shell command from input parameters.buildCommand: (args) => { let options = args.options ? args.options : ''; if (args.length) { options += ` -l ${args.length}`; } if (args.offset) { options += ` -s ${args.offset}`; } if (args.cols) { options += ` -c ${args.cols}`; } if (args.bits) { options += ' -b'; } return `xxd ${options} ${args.target}`; },
- commands.js:136-141 (schema)Zod input schema for the xxd tool, defining parameters like length, offset, cols, bits extending baseCommandSchema.schema: baseCommandSchema.extend({ length: z.number().optional().describe("Number of bytes to display"), offset: z.number().optional().describe("Starting offset in the file"), cols: z.number().optional().describe("Format output into specified number of columns"), bits: z.boolean().optional().describe("Switch to bits (binary) dump") }),
- serverMCP.js:113-118 (registration)Registers 'xxd' (and other commands) as MCP tools dynamically from the commands configuration, providing name, description, and inputSchema.const specializedTools = Object.values(commands).map(cmd => ({ name: cmd.name, description: cmd.description + (cmd.helpText ? '\n' + cmd.helpText : ''), inputSchema: zodToJsonSchema(cmd.schema), }));
- commands.js:132-170 (registration)Configuration object for the 'xxd' tool, including name, description, schema, buildCommand, and helpText, exported as part of commands.// XXD command - hexdump with ASCII representation xxd: { name: 'xxd', description: 'Create a hexdump with ASCII representation', schema: baseCommandSchema.extend({ length: z.number().optional().describe("Number of bytes to display"), offset: z.number().optional().describe("Starting offset in the file"), cols: z.number().optional().describe("Format output into specified number of columns"), bits: z.boolean().optional().describe("Switch to bits (binary) dump") }), buildCommand: (args) => { let options = args.options ? args.options : ''; if (args.length) { options += ` -l ${args.length}`; } if (args.offset) { options += ` -s ${args.offset}`; } if (args.cols) { options += ` -c ${args.cols}`; } if (args.bits) { options += ' -b'; } return `xxd ${options} ${args.target}`; }, helpText: ` Example usage: - Standard xxd dump: { "target": "suspicious.exe" } - With length limit: { "target": "suspicious.exe", "length": 256 } - With column formatting: { "target": "suspicious.exe", "cols": 16 } - Binary bits mode: { "target": "suspicious.exe", "bits": true } ` }