signature fix for new player

Tested on player version 03dbdfad
This commit is contained in:
alive4ever 2024-12-24 06:41:13 +00:00
parent 9d300d7bd3
commit 6045b5635a
2 changed files with 17 additions and 2 deletions

View file

@ -13,7 +13,7 @@ pub static NSIG_FUNCTION_ARRAYS: &[&str] = &[
];
pub static NSIG_FUNCTION_ENDINGS: &[&str] = &[
r#"=\s*function(\([\w]+\)\{\s*var\s+[\w\s]+=[\w\.\s]+?\.call\s*\([\w\s$]+?,[\(\)\",\s]+\)[\S\s]*?\}\s*return [\w\.\s$]+?\.call\s*\([\w\s$]+?\s*,[\(\)\",\s]+\)\s*\}\s*;)"#,
r#"\s*=function\s*(\(\w\)\s*\{\s*var\s+\w=\w.split.*?\{\s*return"[a-zA-Z0-9_]+.?_w8_".*?\}\s*return\s+\w+\.join\(""\)\s*\}\s*;)"#,
r#"=\s*function([\S\s]*?\}\s*return \w+?\.join\(\"\"\)\s*\};)"#,
r#"=\s*function([\S\s]*?\}\s*return [\W\w$]+?\.call\([\w$]+?,\"\"\)\s*\};)"#,
];
@ -21,7 +21,7 @@ pub static NSIG_FUNCTION_ENDINGS: &[&str] = &[
pub static REGEX_SIGNATURE_TIMESTAMP: &Lazy<Regex> = regex!("signatureTimestamp[=:](\\d+)");
pub static REGEX_SIGNATURE_FUNCTION: &Lazy<Regex> =
regex!("\\bc&&\\(c=([a-zA-Z0-9$]{2,})\\(decodeURIComponent\\(c\\)\\)");
regex!(r#"\s*?([a-zA-Z0-9_]{1,})=function\([a-zA-Z]{1}\)\{(.{1}=.{1}\.split\(""\)[^\}{]+)return .{1}\.join\(""\)\}"#);
pub static REGEX_HELPER_OBJ_NAME: &Lazy<Regex> = regex!(";([A-Za-z0-9_\\$]{2,})\\...\\(");
pub static NSIG_FUNCTION_NAME: &str = "decrypt_nsig";

View file

@ -20,6 +20,19 @@ pub enum FetchUpdateStatus {
PlayerAlreadyUpdated,
}
fn fixup_nsig_jscode(jscode: &str) -> String {
let fixup_re = Regex::new(r#";\s*if\s*\(\s*typeof\s+[a-zA-Z0-9_$]+\s*===?\s*"undefined"\s*\)\s*return\s+\w+;"#).unwrap();
// Replace the matched pattern with just ";"
if fixup_re.is_match(jscode) {
info!("Fixing up nsig_func_body.");
return fixup_re.replace_all(jscode, ";").to_string();
} else {
info!("nsig_func returned with no fixup");
return jscode.to_string();
}
}
pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStatus> {
let global_state = state.clone();
let response = match reqwest::get(TEST_YOUTUBE_VIDEO).await {
@ -122,6 +135,7 @@ pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStat
// Extract nsig function code
for (index, ending) in NSIG_FUNCTION_ENDINGS.iter().enumerate() {
let mut nsig_function_code_regex_str: String = String::new();
nsig_function_code_regex_str += "(?ms)";
nsig_function_code_regex_str += &nsig_function_name.replace("$", "\\$");
nsig_function_code_regex_str += ending;
@ -140,6 +154,7 @@ pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStat
i.get(1).unwrap().as_str()
}
};
nsig_function_code = fixup_nsig_jscode(&nsig_function_code);
debug!("got nsig fn code: {}", nsig_function_code);
break;
}