-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper.rs
91 lines (81 loc) · 3.21 KB
/
helper.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
use std::time::Duration;
use serde::Serialize;
use tauri::command;
use vmprotect::licensing::{ActivationStatus, SerialNumberData, SerialState};
#[derive(Serialize)]
pub struct SerializableSerialNumberData {
state: Vec<&'static str>,
user_name: String,
email: String,
expire: Option<String>,
max_build: Option<String>,
running_time: String, // Represented as a readable string
user_data: String, // Base64 encoded
}
fn format_duration(duration: Duration) -> String {
format!("{} seconds", duration.as_secs())
}
pub fn serialize_serial_state(serial_state: SerialState) -> Vec<&'static str> {
let flags = [
(SerialState::CORRUPTED, "Corrupted"),
(SerialState::INVALID, "Invalid"),
(SerialState::BLACKLISTED, "Blacklisted"),
(SerialState::DATE_EXPIRED, "Date Expired"),
(SerialState::RUNNING_TIME_OVER, "Running Time Over"),
(SerialState::BAD_HWID, "Bad HWID"),
(SerialState::MAX_BUILD_EXPIRED, "Max Build Expired"),
];
flags
.iter()
.filter(|(flag, _)| serial_state.contains(*flag))
.map(|(_, desc)| *desc)
.collect()
}
impl From<SerialNumberData> for SerializableSerialNumberData {
fn from(data: SerialNumberData) -> Self {
SerializableSerialNumberData {
state: serialize_serial_state(data.state),
user_name: data.user_name,
email: data.email,
expire: data.expire.map(|date| date.and_hms(0, 0, 0).to_rfc3339()),
max_build: data
.max_build
.map(|date| date.and_hms(0, 0, 0).to_rfc3339()),
running_time: format_duration(data.running_time),
user_data: base64::encode(&data.user_data),
}
}
}
pub fn activation_status_to_error_message(status: ActivationStatus) -> String {
match status {
ActivationStatus::Ok => "Unexpected OK status".to_string(),
ActivationStatus::SmallBuffer => "The provided buffer is too small.".to_string(),
ActivationStatus::NoConnection => "No connection to the activation server.".to_string(),
ActivationStatus::BadReply => "Received a bad reply from the server.".to_string(),
ActivationStatus::Banned => "The license has been banned.".to_string(),
ActivationStatus::Corrupted => "The license data is corrupted.".to_string(),
ActivationStatus::BadCode => "The provided license code is invalid.".to_string(),
ActivationStatus::AlreadyUsed => "The license has already been used.".to_string(),
ActivationStatus::SerialUnknown => "The serial number is unknown.".to_string(),
ActivationStatus::Expired => "The license has expired.".to_string(),
ActivationStatus::NotAvailable => "The license is not available.".to_string(),
ActivationStatus::NulError => "The license contains a NUL character.".to_string(),
}
}
#[derive(Serialize)]
pub struct Features {
pub licensing: bool,
pub service: bool,
}
impl Features {
pub fn new() -> Features {
Features {
licensing: cfg!(feature = "licensing"),
service: cfg!(feature = "service"),
}
}
}
#[command]
pub fn feature_check_command() -> Result<Features, ()> {
Ok(Features::new())
}