Class
Capstone
public class Capstone
An instance of Capstone is used to disassemble code.
Initializers
init(arch:mode:)
public init(arch: Architecture, mode: Mode = []) throws
Creates a new instance of Capstone for a given architecture and mode.
Parameters
Name | Type | Description |
---|---|---|
arch | Architecture |
target architecture to disassemble |
mode | Mode |
combination of modes - some are architecture-specific |
Throws
CapstoneError.unsupportedArchitecture
if capstone was built without support for the chosen architectureCapstoneError.invalidMode
if the given combination of modes is invalid for the target architectureCapstoneError.unsupportedVersion
if the installed version of capstone does not match the Swift bindings
Properties
version
var version: (major: Int32, minor: Int32)
The linked version of Capstone.
Methods
supports(arch:)
public static func supports(arch: Architecture) -> Bool
Check if an architecture is supported.
By default, Capstone is built with support for all architectures, but some can be removed to reduce size.
Parameters
Name | Type | Description |
---|---|---|
arch | Architecture |
architecture to check for |
Returns
true
if the architecture is supported, false
otherwise
supports(buildMode:)
public static func supports(buildMode: BuildMode) -> Bool
Check the build mode of the library.
Parameters
Name | Type | Description |
---|---|---|
buildMode | BuildMode |
mode to check for |
Returns
true
if capstone was built in this mode
disassemble(code:address:count:)
public func disassemble<InsType: Instruction>(code: Data, address: UInt64, count: Int? = nil) throws -> [InsType]
Disassembles binary code.
Parameters
Name | Type | Description |
---|---|---|
InsType | instruction class to return. Must be |
|
code | Data |
code to disassemble |
address | UInt64 |
address of the first instruction in given |
count | Int? |
number of instructions to disassemble; 0 or nil to get all of them |
Throws
CapstoneError.unsupportedArchitecture
if the return array is not ofInstruction
or the target architecture's instruction classCapstoneError.outOfMemory
if capstone runs out of memory during disassembly
Returns
disassembled instructions in the instruction class of the target architecture
name(ofRegister:)
public func name<T: RawRepresentable>(ofRegister id: T) -> String? where T.RawValue == UInt16
Returns the name of a register in a string.
Parameters
Name | Type | Description |
---|---|---|
id | T |
register to name. must match the register enum for the target architecture. |
Returns
the name of the register, or nil
if it's not a valid value.