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
/* automatically generated by rust-bindgen 0.63.0 */

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ByteArray {
    pub data: *mut u8,
    pub len: ::std::os::raw::c_int,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Attributes {
    pub country: ByteArray,
    pub organization: ByteArray,
    pub organizationalUnit: ByteArray,
    pub nameQualifier: ByteArray,
    pub state: ByteArray,
    pub commonName: ByteArray,
    pub serialNumber: ByteArray,
    pub locality: ByteArray,
    pub title: ByteArray,
    pub surname: ByteArray,
    pub givenName: ByteArray,
    pub initials: ByteArray,
    pub pseudonym: ByteArray,
    pub generationQualifier: ByteArray,
    pub emailAddress: ByteArray,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Certificate {
    pub version: ::std::os::raw::c_long,
    pub issuer: *mut ::std::os::raw::c_char,
    pub subject: *mut ::std::os::raw::c_char,
    pub serial: *mut ::std::os::raw::c_char,
    pub sha1: ByteArray,
    pub sha256: ByteArray,
    pub key_alg: *mut ::std::os::raw::c_char,
    pub sig_alg: *mut ::std::os::raw::c_char,
    pub sig_alg_oid: *mut ::std::os::raw::c_char,
    pub not_before: i64,
    pub not_after: i64,
    pub key: *mut ::std::os::raw::c_char,
    pub issuer_attrs: Attributes,
    pub subject_attrs: Attributes,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct CertificateArray {
    pub certs: *mut *mut Certificate,
    pub count: usize,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Countersignature {
    pub verify_flags: ::std::os::raw::c_int,
    pub sign_time: i64,
    pub digest_alg: *mut ::std::os::raw::c_char,
    pub digest: ByteArray,
    pub chain: *mut CertificateArray,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct CountersignatureArray {
    pub counters: *mut *mut Countersignature,
    pub count: usize,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Signer {
    pub digest: ByteArray,
    pub digest_alg: *mut ::std::os::raw::c_char,
    pub program_name: *mut ::std::os::raw::c_char,
    pub chain: *mut CertificateArray,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Authenticode {
    pub verify_flags: ::std::os::raw::c_int,
    pub version: ::std::os::raw::c_int,
    pub digest_alg: *mut ::std::os::raw::c_char,
    pub digest: ByteArray,
    pub file_digest: ByteArray,
    pub signer: *mut Signer,
    pub certs: *mut CertificateArray,
    pub countersigs: *mut CountersignatureArray,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct AuthenticodeArray {
    pub signatures: *mut *mut Authenticode,
    pub count: usize,
}

extern "C" {
    pub fn ap_initialize_authenticode_parser();

    pub fn ap_parse_authenticode(pe_data: *const u8, pe_len: u64) -> *mut AuthenticodeArray;

    pub fn ap_authenticode_new(data: *const u8, len: i32) -> *mut AuthenticodeArray;

    pub fn ap_authenticode_array_free(auth: *mut AuthenticodeArray);
}