vmprotect_sys/
lib.rs

1use std::os::raw::{c_char, c_void};
2
3// Original API implementation
4#[cfg_attr(
5    all(not(target_os = "macos"), target_pointer_width = "64"),
6    link(name = "VMProtectSDK64")
7)]
8#[cfg_attr(
9    all(target_os = "macos", target_pointer_width = "64"),
10    link(name = "VMProtectSDK")
11)]
12#[cfg_attr(target_pointer_width = "32", link(name = "VMProtectSDK32"))]
13unsafe extern "system" {
14    // Markers
15    pub fn VMProtectBegin(name: *const c_char);
16    pub fn VMProtectBeginVirtualization(name: *const c_char);
17    pub fn VMProtectBeginMutation(name: *const c_char);
18    pub fn VMProtectBeginUltra(name: *const c_char);
19    pub fn VMProtectBeginVirtualizationLockByKey(name: *const c_char);
20    pub fn VMProtectBeginUltraLockByKey(name: *const c_char);
21    pub fn VMProtectEnd();
22    // Service
23    pub fn VMProtectIsProtected() -> u8;
24    pub fn VMProtectIsDebuggerPresent(kernel: u8) -> u8;
25    pub fn VMProtectIsVirtualMachinePresent() -> u8;
26    pub fn VMProtectIsValidImageCRC() -> u8;
27    // Also service by vmprotect docs, but here located under strings feature
28    pub fn VMProtectDecryptStringA(value: *const c_char) -> *const c_char;
29    pub fn VMProtectDecryptStringW(value: *const i16) -> *const i16;
30    pub fn VMProtectFreeString(value: *const c_void) -> u8;
31    // Licensing
32    pub fn VMProtectSetSerialNumber(serial: *const c_char) -> u32;
33    pub fn VMProtectGetSerialNumberState() -> u32;
34    pub fn VMProtectGetSerialNumberData(data: *mut VMProtectSerialNumberData, size: u32) -> u8;
35    pub fn VMProtectGetCurrentHWID(hwid: *mut c_char, size: u32) -> u32;
36    pub fn VMProtectGetOfflineActivationString(
37        code: *const c_char,
38        buf: *const c_char,
39        size: u32,
40    ) -> u32;
41    pub fn VMProtectGetOfflineDeactivationString(
42        serial: *const c_char,
43        buf: *const c_char,
44        size: u32,
45    ) -> u32;
46    // Activation
47    pub fn VMProtectActivateLicense(code: *const c_char, serial: *mut c_char, size: u32) -> u32;
48    pub fn VMProtectDeactivateLicense(serial: *const c_char) -> u32;
49}
50
51#[derive(Default, Clone, Copy)]
52#[repr(C, packed)]
53pub struct VMProtectDate {
54    pub w_year: u16,
55    pub b_month: u8,
56    pub b_day: u8,
57}
58
59#[derive(Clone, Copy)]
60#[repr(C, packed)]
61pub struct VMProtectSerialNumberData {
62    /// State flags
63    pub state: u32,
64    /// User name
65    pub user_name: [u16; 256],
66    /// Email
67    pub email: [u16; 256],
68    /// Date of serial number expiration
69    pub expire: VMProtectDate,
70    /// Max date of build, that will accept this key
71    pub max_build: VMProtectDate,
72    /// Running time in minutes
73    pub running_time: u32,
74    /// Length of user data in bUserData
75    pub user_data_length: u8,
76    /// Up to 255 bytes of user data
77    pub user_data: [u8; 255],
78}
79
80impl Default for VMProtectSerialNumberData {
81    fn default() -> Self {
82        VMProtectSerialNumberData {
83            state: 0,
84            user_name: [0; 256],
85            email: [0; 256],
86            expire: VMProtectDate::default(),
87            max_build: VMProtectDate::default(),
88            running_time: 0,
89            user_data_length: 0,
90            user_data: [0; 255],
91        }
92    }
93}