nsig function extraction works!

This commit is contained in:
techmetx11 2024-04-29 06:47:17 +01:00
parent 33a33f4060
commit b601571cff
No known key found for this signature in database
GPG Key ID: 20E0C88A0E7E5AF2
3 changed files with 51 additions and 12 deletions

View File

@ -8,5 +8,3 @@ pub static REGEX_PLAYER_ID: &Lazy<Regex> = regex!("\\/s\\/player\\/([0-9a-f]{8})
pub static NSIG_FUNCTION_ARRAY: &Lazy<Regex> = regex!( pub static NSIG_FUNCTION_ARRAY: &Lazy<Regex> = regex!(
"\\.get\\(\"n\"\\)\\)&&\\([a-zA-Z0-9$_]=([a-zA-Z0-9$_]+)(?:\\[(\\d+)])?\\([a-zA-Z0-9$_]\\)" "\\.get\\(\"n\"\\)\\)&&\\([a-zA-Z0-9$_]=([a-zA-Z0-9$_]+)(?:\\[(\\d+)])?\\([a-zA-Z0-9$_]\\)"
); );
pub static NSIG_FUNCTION_BODY: &Lazy<Regex> =
regex!("=\\s*function([\\S\\s]*?\\}\\s*return [\\w$]+?\\.join\\(\"\"\\)\\s*\\};)");

View File

@ -17,20 +17,22 @@ impl From<u8> for JobOpcode {
match value { match value {
0x00 => Self::ForceUpdate, 0x00 => Self::ForceUpdate,
0x01 => Self::DecryptNSignature, 0x01 => Self::DecryptNSignature,
// make debugging easier
b'a' => Self::ForceUpdate,
_ => Self::UnknownOpcode, _ => Self::UnknownOpcode,
} }
} }
} }
pub struct PlayerInfo { pub struct PlayerInfo {
nsig_function_code: Vec<u8>, nsig_function_code: String,
player_id: u32, player_id: u32,
} }
pub struct JavascriptInterpreter { pub struct JavascriptInterpreter {
js_runtime: AsyncRuntimeWrapper, js_runtime: AsyncRuntimeWrapper,
nsig_context: AsyncContextWrapper, nsig_context: AsyncContextWrapper,
nsig_function_name: String,
player_id: u32, player_id: u32,
} }
@ -70,7 +72,6 @@ impl JavascriptInterpreter {
JavascriptInterpreter { JavascriptInterpreter {
js_runtime: AsyncRuntimeWrapper(js_runtime), js_runtime: AsyncRuntimeWrapper(js_runtime),
nsig_context: AsyncContextWrapper(nsig_context), nsig_context: AsyncContextWrapper(nsig_context),
nsig_function_name: Default::default(),
player_id: 0, player_id: 0,
} }
} }
@ -89,10 +90,9 @@ impl GlobalState {
.get(); .get();
let mut runtime_vector: Vec<Arc<JavascriptInterpreter>> = let mut runtime_vector: Vec<Arc<JavascriptInterpreter>> =
Vec::with_capacity(number_of_runtimes); Vec::with_capacity(number_of_runtimes);
runtime_vector for n in 0..number_of_runtimes {
.iter_mut() runtime_vector.push(Arc::new(JavascriptInterpreter::new()));
.for_each(|a| *a = Arc::new(JavascriptInterpreter::new())); }
// Make a clone of the vector, this will clone all the values inside (Arc) // Make a clone of the vector, this will clone all the values inside (Arc)
let mut runtime_vector2: Vec<Arc<JavascriptInterpreter>> = let mut runtime_vector2: Vec<Arc<JavascriptInterpreter>> =
Vec::with_capacity(number_of_runtimes); Vec::with_capacity(number_of_runtimes);
@ -125,7 +125,7 @@ pub async fn process_fetch_update(state: Arc<GlobalState>) {
let player_id: u32 = u32::from_str_radix(player_id_str, 16).unwrap(); let player_id: u32 = u32::from_str_radix(player_id_str, 16).unwrap();
let current_player_info = global_state.player_info.lock().await; let mut current_player_info = global_state.player_info.lock().await;
let current_player_id = current_player_info.player_id; let current_player_id = current_player_info.player_id;
// release the mutex for other tasks // release the mutex for other tasks
drop(current_player_info); drop(current_player_info);
@ -150,7 +150,12 @@ pub async fn process_fetch_update(state: Arc<GlobalState>) {
let nsig_function_array = NSIG_FUNCTION_ARRAY.captures(&player_javascript).unwrap(); let nsig_function_array = NSIG_FUNCTION_ARRAY.captures(&player_javascript).unwrap();
let nsig_array_name = nsig_function_array.get(1).unwrap().as_str(); let nsig_array_name = nsig_function_array.get(1).unwrap().as_str();
let nsig_array_value = usize::from_str_radix(nsig_function_array.get(2).unwrap().as_str(), 10); let nsig_array_value = nsig_function_array
.get(2)
.unwrap()
.as_str()
.parse::<usize>()
.unwrap();
let mut nsig_array_context_regex: String = String::new(); let mut nsig_array_context_regex: String = String::new();
nsig_array_context_regex += "var "; nsig_array_context_regex += "var ";
@ -164,5 +169,40 @@ pub async fn process_fetch_update(state: Arc<GlobalState>) {
return; return;
} }
}; };
let array_content = nsig_array_context
.captures(&player_javascript)
.unwrap()
.get(1)
.unwrap()
.as_str()
.split(",");
let array_values: Vec<&str> = array_content.collect();
let nsig_function_name = array_values.get(nsig_array_value).unwrap();
// Extract nsig function code
let mut nsig_function_code_regex_str: String = String::new();
nsig_function_code_regex_str += nsig_function_name;
nsig_function_code_regex_str +=
"=\\s*function([\\S\\s]*?\\}\\s*return [\\w$]+?\\.join\\(\"\"\\)\\s*\\};)";
let nsig_function_code_regex = Regex::new(&nsig_function_code_regex_str).unwrap();
let mut nsig_function_code = String::new();
nsig_function_code += "decrypt_nsig = function";
nsig_function_code += nsig_function_code_regex
.captures(&player_javascript)
.unwrap()
.get(1)
.unwrap()
.as_str();
current_player_info = global_state.player_info.lock().await;
current_player_info.player_id = player_id;
current_player_info.nsig_function_code = nsig_function_code;
println!("{}", current_player_info.nsig_function_code);
} }
pub async fn process_decrypt_n_signature(_state: Arc<GlobalState>, _sig: String) {} pub async fn process_decrypt_n_signature(_state: Arc<GlobalState>, _sig: String) {}

View File

@ -5,7 +5,7 @@ use consts::DEFAULT_SOCK_PATH;
use jobs::{process_decrypt_n_signature, process_fetch_update, GlobalState, JobOpcode}; use jobs::{process_decrypt_n_signature, process_fetch_update, GlobalState, JobOpcode};
use std::{env::args, sync::Arc}; use std::{env::args, sync::Arc};
use tokio::{ use tokio::{
io::{AsyncReadExt, BufReader}, io::{AsyncBufReadExt, AsyncReadExt, BufReader},
net::{UnixListener, UnixStream}, net::{UnixListener, UnixStream},
}; };
@ -46,6 +46,7 @@ async fn main() {
async fn process_socket(state: Arc<GlobalState>, socket: UnixStream) { async fn process_socket(state: Arc<GlobalState>, socket: UnixStream) {
let mut bufreader = BufReader::new(socket); let mut bufreader = BufReader::new(socket);
bufreader.fill_buf().await;
loop { loop {
let opcode_byte: u8 = break_fail!(bufreader.read_u8().await); let opcode_byte: u8 = break_fail!(bufreader.read_u8().await);