{"id":15646267,"url":"https://github.com/gregorycomer/rust-x86asm","last_synced_at":"2025-04-15T11:50:47.225Z","repository":{"id":57672445,"uuid":"95988302","full_name":"GregoryComer/rust-x86asm","owner":"GregoryComer","description":"A Rust library for x86/64 assembly/disassembly.","archived":false,"fork":false,"pushed_at":"2020-06-21T18:39:44.000Z","size":4076,"stargazers_count":49,"open_issues_count":10,"forks_count":14,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-03-15T15:22:26.582Z","etag":null,"topics":["assembly","disassembly","rust","x86","x86-64"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GregoryComer.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}},"created_at":"2017-07-01T21:24:38.000Z","updated_at":"2024-01-27T10:38:44.000Z","dependencies_parsed_at":"2022-08-31T02:40:21.476Z","dependency_job_id":null,"html_url":"https://github.com/GregoryComer/rust-x86asm","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GregoryComer%2Frust-x86asm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GregoryComer%2Frust-x86asm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GregoryComer%2Frust-x86asm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GregoryComer%2Frust-x86asm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GregoryComer","download_url":"https://codeload.github.com/GregoryComer/rust-x86asm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249067175,"owners_count":21207392,"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","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","disassembly","rust","x86","x86-64"],"created_at":"2024-10-03T12:12:08.580Z","updated_at":"2025-04-15T11:50:47.207Z","avatar_url":"https://github.com/GregoryComer.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# x86asm - A Rust crate for assembling \u0026 disassembling x86/64 instructions\n\nThe x86asm crate is a Rust library designed for programatically assembling \u0026 disassembling x86 instructions. This project supports real, protected, and long mode assembly.\n\n## Status\nThis crate is feature complete but immature. If you encounter bugs or wish for a helpful new feature, feel free to contribute or create an issue. See the contributing  section below.\n\n## Usage Examples\nSee the *examples* directory for full examples.\n\nEncode a series of instructions to an in-memory buffer:\n```rust\nuse std::io:Cursor;\nuse x86asm::{InstructionWriter, Mnemonic, Mode, Operand, Reg};\n\n...\n\nlet buffer = Cursor::new(Vec::new());\nlet mut writer = InstructionWriter::new(buffer, Mode::Protected);\n\n// mov eax, 10\n// mov ebx, 20\n// add eax, ebx\n\nwriter.write2(Mnemonic::MOV, Operand::Direct(Reg::EAX), Operand::Literal32(10)); // mov eax, 10\nwriter.write2(Mnemonic::MOV, Operand::Direct(Reg::EBX), Operand::Literal32(20)); // mov ebx, 20\nwriter.write2(Mnemonic::ADD, Operand::Direct(Reg::EAX), Operand::Direct(Reg::EBX)); // add eax, ebx\n```\n\nA more in-depth example demonstrating different addressing modes:\n```rust\nlet buffer = Cursor::new(Vec::new());\nlet mut writer = InstructionWriter::new(buffer, Mode::Protected);\n\n// mov ebx, dword ptr [eax]\n// mov ebx, dword ptr [eax+5]\n// mov ebx, dword ptr [eax+ecx*2]\n// mov ebx, dword ptr [eax+ecx*2+5]\n// mov ebx, dword ptr ds:5\n\nlet instructions = \u0026[\n    Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBX), Operand::Indirect(Reg::EAX, Some(OperandSize::Dword), None)), // mov ebx, dword ptr [eax]\n    Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBX), Operand::IndirectDisplaced(Reg::EAX, 5, Some(OperandSize::Dword), None)), // mov ebx, dword ptr [eax+5]\n    Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBX), Operand::IndirectScaledIndexed(Reg::EAX, Reg::ECX, RegScale::Two, Some(OperandSize::Dword), None)), // mov ebx, dword ptr [eax+ecx*2]\n    Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBX), Operand::IndirectScaledIndexedDisplaced(Reg::EAX, Reg::ECX, RegScale::Two, 5, Some(OperandSize::Dword), None)), // mov ebx, dword ptr [eax+ecx*2+5]\n    Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBX), Operand::Memory(5, Some(OperandSize::Dword), None)), // mov ebx, dword ptr ds:5\n];\n\nfor instr in instructions { writer.write(instr).unwrap(); }\n```\n\nReal mode assembly:\n```rust\nlet buffer = Cursor::new(Vec::new());\nlet mut writer = InstructionWriter::new(buffer, Mode::Real);\n\n// mov ax, [bx+si]\n// add ax, bx\n// mov [bp+si], ax\n\nlet instructions = \u0026[\n    Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::AX), Operand::IndirectScaledIndexed(Reg::BX, Reg::SI, RegScale::One, Some(OperandSize::Word), None)), // mov ax, [bx+si]\n    Instruction::new2(Mnemonic::ADD, Operand::Direct(Reg::AX), Operand::Direct(Reg::BX)), // add ax, bx\n    Instruction::new2(Mnemonic::MOV, Operand::IndirectScaledIndexed(Reg::BX, Reg::SI, RegScale::One, Some(OperandSize::Word), None), Operand::Direct(Reg::AX)), // mov [bp+si]\n];\n\nfor instr in instructions { writer.write(instr).unwrap(); }\n```\n\nLong mode assembly:\n```rust\nlet buffer = Cursor::new(Vec::new());\nlet mut writer = InstructionWriter::new(buffer, Mode::Long);\n\n// mov rax, qword ptr [rip+100]\n// mov rbx, 500\n// sub rax, rbx\n// mov [rcx+rdx*4], rax\n\nlet instructions = \u0026[\n    Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::RAX), Operand::IndirectDisplaced(Reg::RIP, 100, Some(OperandSize::Qword), None)), // mov rax, qword ptr [rip+100]\n    Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::RBX), Operand::Literal32(500)), // mov rbx, 500\n    Instruction::new2(Mnemonic::SUB, Operand::Direct(Reg::RAX), Operand::Direct(Reg::RBX)), // sub rax, rbx\n    Instruction::new2(Mnemonic::MOV, Operand::IndirectScaledIndexed(Reg::RCX, Reg::RDX, RegScale::Four, Some(OperandSize::Qword), None), Operand::Direct(Reg::RAX)), // mov [rcx+rdx*4], rax\n];\n\nfor instr in instructions { writer.write(instr).unwrap(); }\n```\n## Build\nThe x86asm crate uses Cargo. To build, clone the repository using Git and run `cargo build` from the command line using either stable or nightly Rust.\n## Contribute\nContributions are welcome! If you're not inclined to dig into the code yourself but encounter an issue, feel free to submit an issue using the GitHub issue tracker. Before contributing, please see *gen_defs/README* and *src/test/README* for a detailed description of the instruction format, as well as in-depth guidelines for contributing.\n\n## Contributors\n* Gregory Comer - Author\n\n## License\nThis project is open source and is licensed under the MIT License. The full text is included in the repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregorycomer%2Frust-x86asm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregorycomer%2Frust-x86asm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregorycomer%2Frust-x86asm/lists"}