llvm_sys/
disassembler.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//! A disassembler library.

#![allow(non_upper_case_globals, non_snake_case)]

#[derive(Debug)]
pub enum LLVMOpaqueDisasmContext {}

pub type LLVMDisasmContextRef = *mut LLVMOpaqueDisasmContext;

pub type LLVMOpInfoCallback = Option<
    extern "C" fn(
        DisInfo: *mut ::libc::c_void,
        PC: u64,
        Offset: u64,
        OpSize: u64,
        InstSize: u64,
        TagType: ::libc::c_int,
        TagBuf: *mut ::libc::c_void,
    ) -> ::libc::c_int,
>;

#[repr(C)]
#[derive(Debug)]
pub struct LLVMOpInfoSymbol1 {
    /// 1 if this symbol is present.
    pub Present: u64,
    /// Symbol name if not NULL.
    pub Name: *const ::libc::c_char,
    /// Symbol value if name is NULL.
    pub Value: u64,
}

#[repr(C)]
#[derive(Debug)]
pub struct Struct_LLVMOpInfo1 {
    pub AddSymbol: LLVMOpInfoSymbol1,
    pub SubtractSymbol: LLVMOpInfoSymbol1,
    pub Value: u64,
    pub VariantKind: u64,
}

pub const LLVMDisassembler_VariantKind_None: u64 = 0;
pub const LLVMDisassembler_VariantKind_ARM_HI16: u64 = 1;
pub const LLVMDisassembler_VariantKind_ARM_LO16: u64 = 2;
pub const LLVMDisassembler_VariantKind_ARM64_PAGE: u64 = 1;
pub const LLVMDisassembler_VariantKind_ARM64_PAGEOFF: u64 = 2;
pub const LLVMDisassembler_VariantKind_ARM64_GOTPAGE: u64 = 3;
pub const LLVMDisassembler_VariantKind_ARM64_GOTPAGEOFF: u64 = 4;
pub const LLVMDisassembler_VariantKind_ARM64_TLVP: u64 = 5;
pub const LLVMDisassembler_VariantKind_ARM64_TLVOFF: u64 = 6;

/// No input reference type or no output reference type.
pub const LLVMDisassembler_ReferenceType_InOut_None: u64 = 0;

/// The input reference is from a branch instruction.
pub const LLVMDisassembler_ReferenceType_In_Branch: u64 = 1;
/// The input reference is from a PC relative load instruction.
pub const LLVMDisassembler_ReferenceType_In_PCrel_Load: u64 = 2;

/// The input reference is from an ARM64::ADRP instruction.
pub const LLVMDisassembler_ReferenceType_In_ARM64_ADRP: u64 = 0x100000001;
/// The input reference is from an ARM64::ADDXri instruction.
pub const LLVMDisassembler_ReferenceType_In_ARM64_ADDXri: u64 = 0x100000002;
/// The input reference is from an ARM64::LDRXui instruction.
pub const LLVMDisassembler_ReferenceType_In_ARM64_LDRXui: u64 = 0x100000003;
/// The input reference is from an ARM64::LDRXl instruction.
pub const LLVMDisassembler_ReferenceType_In_ARM64_LDRXl: u64 = 0x100000004;
/// The input reference is from an ARM64::ADR instruction.
pub const LLVMDisassembler_ReferenceType_In_ARM64_ADR: u64 = 0x100000005;

/// The output reference is to as symbol stub.
pub const LLVMDisassembler_ReferenceType_Out_SymbolStub: u64 = 1;
/// The output reference is to a symbol address in a literal pool.
pub const LLVMDisassembler_ReferenceType_Out_LitPool_SymAddr: u64 = 2;
/// The output reference is to a cstring address in a literal pool.
pub const LLVMDisassembler_ReferenceType_Out_LitPool_CstrAddr: u64 = 3;

/// The output reference is to a Objective-C CoreFoundation string.
pub const LLVMDisassembler_ReferenceType_Out_Objc_CFString_Ref: u64 = 4;
/// The output reference is to a Objective-C message.
pub const LLVMDisassembler_ReferenceType_Out_Objc_Message: u64 = 5;
/// The output reference is to a Objective-C message ref.
pub const LLVMDisassembler_ReferenceType_Out_Objc_Message_Ref: u64 = 6;
/// The output reference is to a Objective-C selector ref.
pub const LLVMDisassembler_ReferenceType_Out_Objc_Selector_Ref: u64 = 7;
/// The output reference is to a Objective-C class ref.
pub const LLVMDisassembler_ReferenceType_Out_Objc_Class_Ref: u64 = 8;
/// The output reference is to a C++ symbol name.
pub const LLVMDisassembler_ReferenceType_DeMangled_Name: u64 = 9;

/// The option to produce marked up assembly.
pub const LLVMDisassembler_Option_UseMarkup: u64 = 1;
/// The option to print immediates as hex.
pub const LLVMDisassembler_Option_PrintImmHex: u64 = 2;
/// The option use the other assembler printer variant
pub const LLVMDisassembler_Option_AsmPrinterVariant: u64 = 4;
/// The option to set comment on instructions
pub const LLVMDisassembler_Option_SetInstrComments: u64 = 8;
/// The option to print latency information alongside instructions
pub const LLVMDisassembler_Option_PrintLatency: u64 = 16;

pub type LLVMSymbolLookupCallback = Option<
    extern "C" fn(
        DisInfo: *mut ::libc::c_void,
        ReferenceValue: u64,
        ReferenceType: *mut u64,
        ReferencePC: u64,
        ReferenceName: *mut *const ::libc::c_char,
    ) -> *const ::libc::c_char,
>;

extern "C" {
    pub fn LLVMCreateDisasm(
        TripleName: *const ::libc::c_char,
        DisInfo: *mut ::libc::c_void,
        TagType: ::libc::c_int,
        GetOpInfo: LLVMOpInfoCallback,
        SymbolLookUp: LLVMSymbolLookupCallback,
    ) -> LLVMDisasmContextRef;
    pub fn LLVMCreateDisasmCPU(
        Triple: *const ::libc::c_char,
        CPU: *const ::libc::c_char,
        DisInfo: *mut ::libc::c_void,
        TagType: ::libc::c_int,
        GetOpInfo: LLVMOpInfoCallback,
        SymbolLookUp: LLVMSymbolLookupCallback,
    ) -> LLVMDisasmContextRef;
    pub fn LLVMCreateDisasmCPUFeatures(
        Triple: *const ::libc::c_char,
        CPU: *const ::libc::c_char,
        Features: *const ::libc::c_char,
        DisInfo: *mut ::libc::c_void,
        TagType: ::libc::c_int,
        GetOpInfo: LLVMOpInfoCallback,
        SymbolLookUp: LLVMSymbolLookupCallback,
    ) -> LLVMDisasmContextRef;
    pub fn LLVMSetDisasmOptions(DC: LLVMDisasmContextRef, Options: u64) -> ::libc::c_int;
    pub fn LLVMDisasmDispose(DC: LLVMDisasmContextRef);
    pub fn LLVMDisasmInstruction(
        DC: LLVMDisasmContextRef,
        Bytes: *mut u8,
        BytesSize: u64,
        PC: u64,
        OutString: *mut ::libc::c_char,
        OutStringSize: ::libc::size_t,
    ) -> ::libc::size_t;
}