fix: use card whitelist for cloudlink scores injection

This commit is contained in:
Adamaq01 2023-09-07 01:20:08 +02:00
parent f750adc485
commit 8418d47080
2 changed files with 31 additions and 11 deletions

View File

@ -78,6 +78,20 @@ pub fn get_current_card_id() -> Option<String> {
guard.clone() guard.clone()
} }
pub fn is_current_card_id_whitelisted() -> bool {
if let Some(card) = get_current_card_id() {
if !CONFIGURATION.cards.whitelist.is_empty()
&& !CONFIGURATION.cards.whitelist.contains(&card)
{
return false;
}
return true;
}
false
}
pub fn read_node_str(node: *const (), path: *const u8, length: usize) -> Option<String> { pub fn read_node_str(node: *const (), path: *const u8, length: usize) -> Option<String> {
let mut buffer = [0u8; 32]; let mut buffer = [0u8; 32];
let result = unsafe { let result = unsafe {

View File

@ -8,6 +8,7 @@ use log::{debug, error, info, warn};
use crate::handlers::save::process_save; use crate::handlers::save::process_save;
use crate::handlers::scores::process_scores; use crate::handlers::scores::process_scores;
use crate::helpers::is_current_card_id_whitelisted;
use crate::sys::{ use crate::sys::{
property_clear_error, property_mem_write, property_node_name, property_node_refer, property_clear_error, property_mem_write, property_node_name, property_node_refer,
property_query_size, property_search, property_set_flag, NodeType, property_query_size, property_search, property_set_flag, NodeType,
@ -200,10 +201,11 @@ pub unsafe fn property_mem_read_hook_wrapped(
Ok(response) Ok(response)
})()) })())
} else if load } else if is_current_card_id_whitelisted()
.then(|| root.pointer(&["game", "code"])) && load
.flatten() .then(|| root.pointer(&["game", "code"]))
.is_some() .flatten()
.is_some()
{ {
Some((|| { Some((|| {
let game = root let game = root
@ -222,14 +224,18 @@ pub unsafe fn property_mem_read_hook_wrapped(
Ok(response) Ok(response)
})()) })())
} else if let Some(music) = load_m.then(|| root.pointer(&["game", "music"])).flatten() { } else if let Some(music) = load_m.then(|| root.pointer(&["game", "music"])).flatten() {
Some((|| { if is_current_card_id_whitelisted() {
let user = USER.load(Ordering::SeqCst).to_string(); Some((|| {
let response = crate::cloudlink::process_pbs(user.as_str(), music)?; let user = USER.load(Ordering::SeqCst).to_string();
let response = build_response(&original_signature, response, encoding)?; let response = crate::cloudlink::process_pbs(user.as_str(), music)?;
LOAD_M.store(false, Ordering::Relaxed); let response = build_response(&original_signature, response, encoding)?;
LOAD_M.store(false, Ordering::Relaxed);
Ok(response) Ok(response)
})()) })())
} else {
None
}
} else { } else {
None None
} }