{"id":27464785,"url":"https://github.com/specy/x86-js","last_synced_at":"2026-03-07T11:32:29.825Z","repository":{"id":285461757,"uuid":"958152259","full_name":"Specy/x86-js","owner":"Specy","description":"An x86 interpreter in js using unicorn.js","archived":false,"fork":false,"pushed_at":"2025-05-16T11:25:18.000Z","size":3778,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-08T20:55:33.640Z","etag":null,"topics":["assembly","emscripten","typescript","x86"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@specy/x86","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Specy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-31T18:18:51.000Z","updated_at":"2025-05-16T11:25:21.000Z","dependencies_parsed_at":"2025-03-31T22:21:38.419Z","dependency_job_id":"7dc91848-e714-4bb5-b518-4b963688a545","html_url":"https://github.com/Specy/x86-js","commit_stats":null,"previous_names":["specy/x86-js"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Specy/x86-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Specy%2Fx86-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Specy%2Fx86-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Specy%2Fx86-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Specy%2Fx86-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Specy","download_url":"https://codeload.github.com/Specy/x86-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Specy%2Fx86-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003710,"owners_count":26083610,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assembly","emscripten","typescript","x86"],"created_at":"2025-04-15T23:15:22.343Z","updated_at":"2025-10-10T11:35:57.792Z","avatar_url":"https://github.com/Specy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# X86 Interpreter\n[![npm](https://img.shields.io/npm/v/@specy/x86.svg)](https://www.npmjs.com/package/@specy/x86)\n\nA TypeScript library for x86 assembly interpretation, simulation, and debugging.\nIt is part of a family of javascript assembly interpreters/simulators: \n\n- MIPS: [git repo](https://github.com/Specy/mars),  [npm package](https://www.npmjs.com/package/@specy/mips)\n- RISC-V: [git repo](https://github.com/Specy/rars), [npm package](https://www.npmjs.com/package/@specy/risc-v)\n- X86: [git repo](https://github.com/Specy/x86-js), [npm package](https://www.npmjs.com/package/@specy/x86)\n- M68K: [git repo](https://github.com/Specy/s68k), [npm package](https://www.npmjs.com/package/@specy/s68k)\n\n\n## Overview\n\nThis library provides a JavaScript/TypeScript interface for interpreting and simulating x86 assembly code. It combines three powerful engines:\n\n- **[Unicorn.js](https://github.com/AlexAltea/unicorn.js)** - For CPU emulation\n- **[Keystone.js](https://github.com/AlexAltea/keystone.js)** - For assembly\n- **[Capstone.js](https://github.com/AlexAltea/capstone.js)** - For disassembly\n\nWith this library, you can assemble, execute, and debug x86 instructions, manipulate registers and memory, and analyze program behavior at the instruction level.\n\n## Bundle size\nThe library has a Gzipped bundle size of around 1.5MB, uncompressed is around 9MB\n\n## Features\n\n- **Assembly/Disassembly**: Convert x86 assembly code to machine code and back\n- **Full Simulation**: Execute assembled code with configurable limits and breakpoints\n- **Register Access**: Read and write x86 registers (EAX, EBX, ECX, etc.)\n- **Memory Management**: Allocate, read, and write memory\n- **Debugging Support**: Single-step execution, breakpoints, and state inspection\n- **Flag Monitoring**: Track condition flags (carry, zero, sign, overflow, etc.)\n\n## Installation\n\n```bash\nnpm install @specy/x86\n```\n\n## Basic Usage\n\n```typescript\nimport { X86Interpreter } from '@specy/x86';\n\n// Create an interpreter with assembly code\nconst code = `\nmov eax, 42\nadd ebx, eax\n`;\n\n// Create and initialize the interpreter\nconst interpreter = X86Interpreter.create(code);\ninterpreter.assemble();\ninterpreter.initialize();\n\n// Execute the code\ninterpreter.simulate();\n\n// Read results\nconst eaxValue = interpreter.getRegisterValue(X86Register.EAX);\nconst ebxValue = interpreter.getRegisterValue(X86Register.EBX);\n\nconsole.log(`EAX: ${eaxValue}, EBX: ${ebxValue}`);\n\n// Clean up resources\ninterpreter.dispose();\n```\n\n## Step-by-Step Debugging\n\n```typescript\n// Create and initialize\nconst interpreter = X86Interpreter.create(assemblyCode);\ninterpreter.assemble();\ninterpreter.initialize();\n\n// Execute one instruction at a time\nwhile (!interpreter.isTerminated()) {\n  const instruction = interpreter.getNextStatement();\n  console.log(`Executing: ${instruction?.text}`);\n  \n  // Show register values\n  const eax = interpreter.getRegisterValue(X86Register.EAX);\n  console.log(`EAX: 0x${eax.toString(16)}`);\n  \n  // Execute one instruction\n  interpreter.step();\n}\n\ninterpreter.dispose();\n```\n\n## Breakpoint Support\n\n```typescript\n// Set breakpoints at specific addresses\nconst breakpoints = [0x1010, 0x1020];\ninterpreter.simulateWithBreakpoints(breakpoints);\n\n// Program execution will pause at each breakpoint\nconsole.log(\"Execution paused at breakpoint\");\nconsole.log(`PC: 0x${interpreter.getProgramCounter().toString(16)}`);\n```\n\n## Memory Access\n\n```typescript\n// Write bytes to memory\nconst bytes = [0x90, 0x90, 0x90]; // NOP instructions\ninterpreter.setMemoryBytes(0x2000, bytes);\n\n// Read memory content\nconst memoryContent = interpreter.readMemoryBytes(0x2000, 3);\nconsole.log(\"Memory content:\", memoryContent);\n```\n\n## Flag Inspection\n\n```typescript\n// After execution, check condition flags\nconst flags = interpreter.getConditionFlags();\nconsole.log(\"Zero flag:\", flags[X86ConditionFlags.Z]);\nconsole.log(\"Carry flag:\", flags[X86ConditionFlags.C]);\n```\n\n## API Reference\n\n### X86Interpreter Class\n\nThe main class for x86 assembly interpretation and simulation.\n\n#### Constructor\n\n- `constructor(code: string, assembler: any, interpreter: any, disambler: any)`\n\n#### Static Methods\n\n- `create(code: string): X86Interpreter` - Creates a new interpreter instance with the provided assembly code\n\n#### Methods\n\n- `assemble(): void` - Assembles the code and prepares for interpretation\n- `initialize(): void` - Initializes memory and registers for the interpreter\n- `simulate(limit?: number): void` - Simulates the execution of the code\n- `simulateWithBreakpoints(breakpoints: number[], limit?: number): void` - Simulates execution with specified breakpoints\n- `step(): void` - Executes a single instruction\n- `getRegisterValue(register: X86Register): number` - Gets the value of a register\n- `setRegisterValue(register: X86Register, value: number): void` - Sets the value of a register\n- `getStackPointer(): number` - Gets the current stack pointer value\n- `getProgramCounter(): number` - Gets the current program counter value\n- `getRegistersValues(): number[]` - Gets the values of all registers\n- `readMemoryBytes(address: number, length: number): number[]` - Reads bytes from memory\n- `setMemoryBytes(address: number, bytes: number[]): void` - Writes bytes to memory\n- `getNextStatement(): X86Instruction | null` - Gets the next instruction to be executed\n- `isTerminated(): boolean` - Checks if the execution has terminated\n- `getConditionFlags(): Record\u003cX86ConditionFlags, number\u003e` - Gets the current state of all condition flags\n- `getStatementAtAddress(address: number): X86Instruction | null` - Gets the instruction at a specific address\n- `getStatementAtSourceLine(lineIndex: number): X86Instruction | null` - Gets the instruction at a specific source line\n- `getAssembledStatements(): X86Instruction[]` - Gets all disassembled instructions\n- `dispose(): void` - Releases resources used by the interpreter\n\n### Enums\n\n#### X86Register\n\n```typescript\nenum X86Register {\n    EAX = 19,\n    EBX = 21,\n    ECX = 22,\n    ESP = 30,\n    EBP = 20,\n    EDI = 23,\n    ESI = 29,\n    EDX = 24,\n}\n```\n\n#### X86ConditionFlags\n\n```typescript\nenum X86ConditionFlags {\n    C = 0, // Carry flag\n    Z = 1, // Zero flag\n    S = 2, // Sign flag\n    O = 3, // Overflow flag\n    P = 4, // Parity flag\n    A = 5, // Auxiliary carry flag\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspecy%2Fx86-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspecy%2Fx86-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspecy%2Fx86-js/lists"}