apply patch from https://github.com/iv-org/inv_sig_helper/issues/36#issuecomment-2529907394
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 2m48s

This commit is contained in:
Fijxu 2024-12-09 22:13:19 -03:00
parent 7429664f3b
commit c0d54b2916
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
2 changed files with 35 additions and 9 deletions

View file

@ -20,8 +20,20 @@ pub static NSIG_FUNCTION_ENDINGS: &[&str] = &[
pub static REGEX_SIGNATURE_TIMESTAMP: &Lazy<Regex> = regex!("signatureTimestamp[=:](\\d+)"); pub static REGEX_SIGNATURE_TIMESTAMP: &Lazy<Regex> = regex!("signatureTimestamp[=:](\\d+)");
pub static REGEX_SIGNATURE_FUNCTION: &Lazy<Regex> = pub static REGEX_SIGNATURE_FUNCTION: Lazy<Regex> = Lazy::new(|| {
regex!("\\bc&&\\(c=([a-zA-Z0-9$]{2,})\\(decodeURIComponent\\(c\\)\\)"); Regex::new(concat!(
r#"(?:"#,
// Pattern 1
r#"\b[a-zA-Z0-9$]+&&\([a-zA-Z0-9$]+=([a-zA-Z0-9$]{2,})\(decodeURIComponent\([a-zA-Z0-9$]+\)\)\)"#,
r#"|"#,
// Pattern 2
r#"([a-zA-Z0-9$]+)\s*=\s*function\(\s*[a-zA-Z0-9$]+\s*\)\s*\{\s*[^}]+?\.split\(\s*""\s*\)[^}]+?\.join\(\s*""\s*\)"#,
r#"|"#,
// Pattern 3
r#"(?:\b|[^a-zA-Z0-9$])([a-zA-Z0-9$]{2,})\s*=\s*function\(\s*a\s*\)\s*\{\s*a\s*=\s*a\.split\(\s*""\s*\)"#,
r#")"#
)).unwrap()
});
pub static REGEX_HELPER_OBJ_NAME: &Lazy<Regex> = regex!(";([A-Za-z0-9_\\$]{2,})\\...\\("); pub static REGEX_HELPER_OBJ_NAME: &Lazy<Regex> = regex!(";([A-Za-z0-9_\\$]{2,})\\...\\(");
pub static NSIG_FUNCTION_NAME: &str = "decrypt_nsig"; pub static NSIG_FUNCTION_NAME: &str = "decrypt_nsig";

View file

@ -18,6 +18,12 @@ pub enum FetchUpdateStatus {
CannotFetchPlayerJS, CannotFetchPlayerJS,
NsigRegexCompileFailed, NsigRegexCompileFailed,
PlayerAlreadyUpdated, PlayerAlreadyUpdated,
CannotMatchSignature
}
fn fixup_n_function_code(code: &str) -> String {
let re = regex::Regex::new(r#";\s*if\s*\(\s*typeof\s+[a-zA-Z0-9_$]+\s*===?\s*["']undefined["']\s*\)\s*return\s+[a-zA-Z0-9_$]+;"#).unwrap();
re.replace_all(code, ";").to_string()
} }
pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStatus> { pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStatus> {
@ -140,18 +146,26 @@ pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStat
i.get(1).unwrap().as_str() i.get(1).unwrap().as_str()
} }
}; };
nsig_function_code = fixup_n_function_code(&nsig_function_code);
debug!("got nsig fn code: {}", nsig_function_code); debug!("got nsig fn code: {}", nsig_function_code);
break; break;
} }
// Extract signature function name // Extract signature function name
let sig_function_name = REGEX_SIGNATURE_FUNCTION let sig_function_name = match REGEX_SIGNATURE_FUNCTION.captures(&player_javascript) {
.captures(&player_javascript) Some(captures) => {
.unwrap() // Try groups 1, 2, and 3 which contain the signature function name
.get(1) [1, 2, 3].iter()
.unwrap() .find_map(|&i| captures.get(i))
.as_str(); .map(|m| m.as_str())
.ok_or(FetchUpdateStatus::CannotMatchSignature)?
}
None => {
error!("Could not match signature function pattern");
return Err(FetchUpdateStatus::CannotMatchSignature);
}
};
debug!("sig function name: {}", sig_function_name);
let mut sig_function_body_regex_str: String = String::new(); let mut sig_function_body_regex_str: String = String::new();
sig_function_body_regex_str += &sig_function_name.replace("$", "\\$"); sig_function_body_regex_str += &sig_function_name.replace("$", "\\$");
sig_function_body_regex_str += "=function\\([a-zA-Z0-9_]+\\)\\{.+?\\}"; sig_function_body_regex_str += "=function\\([a-zA-Z0-9_]+\\)\\{.+?\\}";