{"id":13872029,"url":"https://github.com/zydeco/capstone-swift","last_synced_at":"2025-04-09T23:33:22.509Z","repository":{"id":38352438,"uuid":"311962197","full_name":"zydeco/capstone-swift","owner":"zydeco","description":"Swift bindings for Capstone Engine","archived":false,"fork":false,"pushed_at":"2021-01-28T19:17:16.000Z","size":721,"stargazers_count":14,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T01:23:24.816Z","etag":null,"topics":["capstone-engine","disassembler","reverse-engineering","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zydeco.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":"2020-11-11T12:19:13.000Z","updated_at":"2025-02-23T22:38:12.000Z","dependencies_parsed_at":"2022-07-14T03:20:41.070Z","dependency_job_id":null,"html_url":"https://github.com/zydeco/capstone-swift","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/zydeco%2Fcapstone-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zydeco%2Fcapstone-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zydeco%2Fcapstone-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zydeco%2Fcapstone-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zydeco","download_url":"https://codeload.github.com/zydeco/capstone-swift/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248129974,"owners_count":21052671,"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":["capstone-engine","disassembler","reverse-engineering","swift"],"created_at":"2024-08-05T23:00:32.513Z","updated_at":"2025-04-09T23:33:22.482Z","avatar_url":"https://github.com/zydeco.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# Capstone\n\nSwift bindings for [Capstone Engine](https://www.capstone-engine.org).\n\nProvides a complete swift-native wrapper for Capstone, without exposing the C API.\n\nYou need to have the capstone library and headers installed on your system.\n\n* Swift 5.3\n* Use the branch corresponding to your version of Capstone:\n    * Version 4.x: `v4` branch:\n    \n    `.package(name:\"Capstone\", url: \"https://github.com/zydeco/capstone-swift\", .branch(\"v4\"))`\n    * `next` branch: `next` branch:\n    \n    `.package(name:\"Capstone\", url: \"https://github.com/zydeco/capstone-swift\", .branch(\"next\"))`\n* Include \"Capstone\" as a dependency for your executable target:\n    ```swift\n    let package = Package(\n        // name, platforms, products, etc.\n        dependencies: [\n            .package(name: \"Capstone\", url: \"https://github.com/zydeco/capstone-swift\", .branch(\"v4\")),\n            // other dependencies\n        ],\n        targets: [\n            .target(name: \"\u003ccommand-line-tool\u003e\", dependencies: [\n                \"Capstone\",\n            ]),\n            // other targets\n        ]\n    )\n    ```\n* On macOS, you can install capstone with Homebrew:\n    * `brew install capstone` for stable version (currently 4.0.2)\n    * `brew install capstone --head` for `next` branch\n* On Linux, build [Capstone 4.0.2](https://github.com/aquynh/capstone/releases/tag/4.0.2) or [next](https://github.com/aquynh/capstone/tree/next) branch from source.\n\n## API Usage\n1. Create an instance of `Capstone`, with the desired `Architecture` and `Mode`:\n```swift\nlet capstone = try Capstone(arch: .arm, mode: [Mode.arm.thumb, Mode.arm.mClass])\n```\n2. Set `Options`s if needed:\n```swift\ntry capstone.set(option: .detail(value: true))\n```\n3. Disassemble code:\n    \u003e Instructions are returned as an architecture-specific instruction class, which descends from `Instruction`\n```swift\nlet code = Data([0xef, 0xf3, 0x02, 0x80])\nlet instructions: [ArmInstruction] = try capstone.disassemble(code: code, address: 0x1000)\n```\n4. Examine code:\n```swift\nfor ins in instructions: {\n    print(\"  \\(ins.mnemonic) \\(ins.operandsString)\")\n}\n```\n\n## Documentation\n\n* [Documentation](https://namedfork.net/capstone-swift) is generated with [swift-doc](https://github.com/SwiftDocOrg/swift-doc).\n\n## Examples\n\n* See `Examples/cstool` for an implementation of [`cstool`](https://github.com/aquynh/capstone/tree/master/cstool) in Swift.\n\n### Small example\n\n```swift\nimport Capstone\nimport Foundation\n\n// Code to disassemble\nlet code = Data([0x8d, 0x4c, 0x32, 0x08, 0x01, 0xd8, 0x81, 0xc6, 0x34, 0x12, 0x00, 0x00, 0x05, 0x23, 0x01, 0x00, 0x00, 0x36, 0x8b, 0x84, 0x91, 0x23, 0x01, 0x00, 0x00, 0x41, 0x8d, 0x84, 0x39, 0x89, 0x67, 0x00, 0x00, 0x8d, 0x87, 0x89, 0x67, 0x00, 0x00, 0xb4, 0xc6, 0xe9, 0xea, 0xbe, 0xad, 0xde, 0xff, 0xa0, 0x23, 0x01, 0x00, 0x00, 0xe8, 0xdf, 0xbe, 0xad, 0xde, 0x74, 0xff])\n\n// Create instance of capstone\nlet capstone = try Capstone(arch: .x86, mode: Mode.bits.b32)\n\n// Enable detail mode to get instruction groups and operands\ntry capstone.set(option: .detail(value: true))\n\n// Disassemble instructions\nlet instructions: [X86Instruction] = try capstone.disassemble(code: code, address: 0x1000)\n\n// Iterate through instructions\nvar insCountByGroup: [X86Grp: Int] = [:]\nvar opCountByType: [X86Op: Int] = [:]\nprint(\"Disassembly:\")\nfor ins in instructions {\n    print(\"  \\(ins.mnemonic) \\(ins.operandsString)\")\n\n    // Count by instruction groups\n    insCountByGroup.merge(ins.groups.map({ ($0, 1) }), uniquingKeysWith: +)\n\n    // Count operands by type\n    opCountByType.merge(ins.operands.map({ ($0.type, 1) }), uniquingKeysWith: +)\n}\n\n// Print results\nprint(\"Instructions by group:\")\nfor (group, count) in insCountByGroup {\n    print(\"  \\(group): \\(count)\")\n}\n\nprint(\"Operands by type:\")\nfor (type, count) in opCountByType {\n    print(\"  \\(type): \\(count)\")\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzydeco%2Fcapstone-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzydeco%2Fcapstone-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzydeco%2Fcapstone-swift/lists"}