mirror of
https://github.com/iv-org/inv_sig_helper.git
synced 2024-11-22 21:49:42 +00:00
nsig function extraction works!
This commit is contained in:
parent
33a33f4060
commit
b601571cff
@ -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!(
|
||||
"\\.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*\\};)");
|
||||
|
58
src/jobs.rs
58
src/jobs.rs
@ -17,20 +17,22 @@ impl From<u8> for JobOpcode {
|
||||
match value {
|
||||
0x00 => Self::ForceUpdate,
|
||||
0x01 => Self::DecryptNSignature,
|
||||
|
||||
// make debugging easier
|
||||
b'a' => Self::ForceUpdate,
|
||||
_ => Self::UnknownOpcode,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PlayerInfo {
|
||||
nsig_function_code: Vec<u8>,
|
||||
nsig_function_code: String,
|
||||
player_id: u32,
|
||||
}
|
||||
|
||||
pub struct JavascriptInterpreter {
|
||||
js_runtime: AsyncRuntimeWrapper,
|
||||
nsig_context: AsyncContextWrapper,
|
||||
nsig_function_name: String,
|
||||
player_id: u32,
|
||||
}
|
||||
|
||||
@ -70,7 +72,6 @@ impl JavascriptInterpreter {
|
||||
JavascriptInterpreter {
|
||||
js_runtime: AsyncRuntimeWrapper(js_runtime),
|
||||
nsig_context: AsyncContextWrapper(nsig_context),
|
||||
nsig_function_name: Default::default(),
|
||||
player_id: 0,
|
||||
}
|
||||
}
|
||||
@ -89,10 +90,9 @@ impl GlobalState {
|
||||
.get();
|
||||
let mut runtime_vector: Vec<Arc<JavascriptInterpreter>> =
|
||||
Vec::with_capacity(number_of_runtimes);
|
||||
runtime_vector
|
||||
.iter_mut()
|
||||
.for_each(|a| *a = Arc::new(JavascriptInterpreter::new()));
|
||||
|
||||
for n in 0..number_of_runtimes {
|
||||
runtime_vector.push(Arc::new(JavascriptInterpreter::new()));
|
||||
}
|
||||
// Make a clone of the vector, this will clone all the values inside (Arc)
|
||||
let mut runtime_vector2: Vec<Arc<JavascriptInterpreter>> =
|
||||
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 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;
|
||||
// release the mutex for other tasks
|
||||
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_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();
|
||||
nsig_array_context_regex += "var ";
|
||||
@ -164,5 +169,40 @@ pub async fn process_fetch_update(state: Arc<GlobalState>) {
|
||||
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) {}
|
||||
|
@ -5,7 +5,7 @@ use consts::DEFAULT_SOCK_PATH;
|
||||
use jobs::{process_decrypt_n_signature, process_fetch_update, GlobalState, JobOpcode};
|
||||
use std::{env::args, sync::Arc};
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, BufReader},
|
||||
io::{AsyncBufReadExt, AsyncReadExt, BufReader},
|
||||
net::{UnixListener, UnixStream},
|
||||
};
|
||||
|
||||
@ -46,6 +46,7 @@ async fn main() {
|
||||
|
||||
async fn process_socket(state: Arc<GlobalState>, socket: UnixStream) {
|
||||
let mut bufreader = BufReader::new(socket);
|
||||
bufreader.fill_buf().await;
|
||||
|
||||
loop {
|
||||
let opcode_byte: u8 = break_fail!(bufreader.read_u8().await);
|
||||
|
Loading…
Reference in New Issue
Block a user