{"id":15691964,"url":"https://github.com/tenderlove/hatstone","last_synced_at":"2025-05-07T23:45:11.515Z","repository":{"id":56876069,"uuid":"469192784","full_name":"tenderlove/hatstone","owner":"tenderlove","description":"A minimal Ruby wrapper for Capstone disassembler","archived":false,"fork":false,"pushed_at":"2024-11-05T21:38:11.000Z","size":18,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-07T23:45:05.690Z","etag":null,"topics":["assembly","capstone","disassembler","ruby"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tenderlove.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-12T20:27:53.000Z","updated_at":"2024-11-05T21:37:46.000Z","dependencies_parsed_at":"2022-08-20T23:10:23.208Z","dependency_job_id":null,"html_url":"https://github.com/tenderlove/hatstone","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/tenderlove%2Fhatstone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenderlove%2Fhatstone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenderlove%2Fhatstone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenderlove%2Fhatstone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tenderlove","download_url":"https://codeload.github.com/tenderlove/hatstone/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252973616,"owners_count":21834105,"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","capstone","disassembler","ruby"],"created_at":"2024-10-03T18:26:50.844Z","updated_at":"2025-05-07T23:45:11.494Z","avatar_url":"https://github.com/tenderlove.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hatstone\n\nThis is a very simple wrapper around [Capstone](https://www.capstone-engine.org).\nCapstone is a library that disassembles binary data in to assembly code.  This\nlibrary, Hatstone, offers a Ruby interface to the Capstone library.\n\n## Why a new library?\n\n[Crabstone](https://github.com/bnagy/crabstone) is a different wrapper for Capstone.\nI've been using Crabstone for quite a while and I really love it.  However,\nI've been running in to problems with libffi, and especially problems on my M1\nMac where I have both the ARM64 installation and x86 installation of Capstone\non the same system (via two installations of Homebrew).\n\nThis C extension finds the right Capstone library at gem installation time, so\nyou can be assured that if you can install this gem, you can use this gem (hopefully!!)\n\n## Installation\n\nMake sure you have Capstone installed.  On macOS this is `brew install capstone`.\nThen install this gem via the normal method `gem install hatstone`.\n\nNote: RISCV support is only available in Capstone version 5 or later.\n\n## Example Usage\n\nIn this example we'll assemble some simple ARM64 instructions and then use\nHatstone to disassemble them.\n\n```ruby\nrequire \"hatstone\"\n\n# ARM64 movz instruction\ndef movz reg, imm\n  insn = 0b0_10_100101_00_0000000000000000_00000\n  insn |= (1 \u003c\u003c 31)  # 64 bit\n  insn |= (imm \u003c\u003c 5) # immediate\n  insn |= reg        # reg\nend\n\n# ARM64 ret instruction\ndef ret xn = 30\n  insn = 0b1101011_0_0_10_11111_0000_0_0_00000_00000\n  insn |= (xn \u003c\u003c 5)\n  insn\nend\n\n# Assemble some instructions\ninsns = [\n  movz(0, 0x2a), # mov X0, 0x2a\n  ret            # ret\n].pack(\"L\u003cL\u003c\")\n\n# Now disassemble the instructions with Hatstone\nhs = Hatstone.new(Hatstone::ARCH_ARM64, Hatstone::MODE_ARM)\n\nhs.disasm(insns, 0x0).each do |insn|\n  puts \"%#05x %s %s\" % [insn.address, insn.mnemonic, insn.op_str]\nend\n```\nAnother example, this time for RISCV64\n\n```ruby\nrequire 'hatstone'\n\ndef lui reg, imm\n  insn = 0b00000000000000000000_00000_0110111 \n  insn |= (reg \u003c\u003c 7)  # Set destination register \n  insn |= (imm \u0026 0xFFFFF) \u003c\u003c 12  # Set 20-bit immediate\n  insn\nend\n\ndef auipc reg, imm\n  insn = 0b00000000000000000000_00000_0010111  # auipc base\n  insn |= (reg \u003c\u003c 7)  # Set destination register\n  insn |= (imm \u0026 0xFFFFF) \u003c\u003c 12  # Set 20-bit immediate\n  insn\nend\n\ndef addi reg, imm\n  insn = 0b00000000000000000000_00000_0010011  # addi base\n  insn |= (reg \u003c\u003c 7)  # Set destination register\n  insn |= (reg \u003c\u003c 15)  # Set source register\n  insn |= (imm \u0026 0xFFF) \u003c\u003c 20  # Set 12-bit immediate\n  insn\nend\n\ninsns = [\n  lui(17, 64), # lui a7,64\n  lui(10, 1),  # lui a0,1\n  auipc(0, 0), # auipc a0,0x0\n  addi(0, 36), # addi a0,a0,36\n].pack(\"L\u003c*\")\n\nhs = Hatstone.new(Hatstone::ARCH_RISCV, Hatstone::MODE_RISCV64)\n\nhs.disasm(insns, 0x0).each do |insn|\n  puts \"%#05x %s %s\" % [insn.address, insn.mnemonic, insn.op_str]\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenderlove%2Fhatstone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftenderlove%2Fhatstone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenderlove%2Fhatstone/lists"}