mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-28 16:00:33 +05:30
[YouTube] Fix extraction of n param deobfuscation function name and fixup function to prevent early return
This commit is contained in:
parent
ea401638f4
commit
56595bd9d5
@ -30,17 +30,31 @@ final class YoutubeThrottlingParameterUtils {
|
|||||||
private static final Pattern[] DEOBFUSCATION_FUNCTION_NAME_REGEXES = {
|
private static final Pattern[] DEOBFUSCATION_FUNCTION_NAME_REGEXES = {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The first regex matches the following text, where we want Wma and the array index
|
* The first regex matches the following text, where we want SDa and the array index
|
||||||
* accessed:
|
* accessed:
|
||||||
*
|
*
|
||||||
* a.D&&(b="nn"[+a.D],WL(a),c=a.j[b]||null)&&(c=SDa[0](c),a.set(b,c),SDa.length||Wma("")
|
* WL(a),c=a.j[b]||null)&&(c=SDa[0](
|
||||||
*/
|
*/
|
||||||
Pattern.compile(SINGLE_CHAR_VARIABLE_REGEX + "=\"nn\"\\[\\+" + MULTIPLE_CHARS_REGEX
|
Pattern.compile(MULTIPLE_CHARS_REGEX + "\\("
|
||||||
+ "\\." + MULTIPLE_CHARS_REGEX + "]," + MULTIPLE_CHARS_REGEX + "\\("
|
|
||||||
+ MULTIPLE_CHARS_REGEX + "\\)," + MULTIPLE_CHARS_REGEX + "="
|
+ MULTIPLE_CHARS_REGEX + "\\)," + MULTIPLE_CHARS_REGEX + "="
|
||||||
+ MULTIPLE_CHARS_REGEX + "\\." + MULTIPLE_CHARS_REGEX + "\\["
|
+ MULTIPLE_CHARS_REGEX + "\\." + MULTIPLE_CHARS_REGEX + "\\["
|
||||||
+ MULTIPLE_CHARS_REGEX + "]\\|\\|null\\).+\\|\\|(" + MULTIPLE_CHARS_REGEX
|
+ MULTIPLE_CHARS_REGEX + "]\\|\\|null\\)&&\\(" + MULTIPLE_CHARS_REGEX + "=("
|
||||||
+ ")\\(\"\"\\)"),
|
+ MULTIPLE_CHARS_REGEX + ")" + ARRAY_ACCESS_REGEX + "\\("),
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This regex matches the following text, where we want Wma:
|
||||||
|
*
|
||||||
|
* a.D&&(b="nn"[+a.D],WL(a),c=a.j[b]||null)&&(c=SDa[0](c),a.set(b,c),SDa.length||Wma("")
|
||||||
|
*
|
||||||
|
* UPDATE: This is broken and Wma is not the function needed anymore.
|
||||||
|
* We need the function which is in SDa[0] instead.
|
||||||
|
*/
|
||||||
|
// Pattern.compile(SINGLE_CHAR_VARIABLE_REGEX + "=\"nn\"\\[\\+" + MULTIPLE_CHARS_REGEX
|
||||||
|
// + "\\." + MULTIPLE_CHARS_REGEX + "]," + MULTIPLE_CHARS_REGEX + "\\("
|
||||||
|
// + MULTIPLE_CHARS_REGEX + "\\)," + MULTIPLE_CHARS_REGEX + "="
|
||||||
|
// + MULTIPLE_CHARS_REGEX + "\\." + MULTIPLE_CHARS_REGEX + "\\["
|
||||||
|
// + MULTIPLE_CHARS_REGEX + "]\\|\\|null\\).+\\|\\|(" + MULTIPLE_CHARS_REGEX
|
||||||
|
// + ")\\(\"\"\\)"),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The second regex matches the following text, where we want SDa and the array index
|
* The second regex matches the following text, where we want SDa and the array index
|
||||||
@ -112,6 +126,12 @@ final class YoutubeThrottlingParameterUtils {
|
|||||||
private static final String FUNCTION_NAMES_IN_DEOBFUSCATION_ARRAY_REGEX =
|
private static final String FUNCTION_NAMES_IN_DEOBFUSCATION_ARRAY_REGEX =
|
||||||
"\\s*=\\s*\\[(.+?)][;,]";
|
"\\s*=\\s*\\[(.+?)][;,]";
|
||||||
|
|
||||||
|
private static final String FUNCTION_ARGUMENTS_REGEX =
|
||||||
|
"=\\s*function\\s*\\(\\s*([^)]*)\\s*\\)";
|
||||||
|
|
||||||
|
private static final String EARLY_RETURN_REGEX =
|
||||||
|
";\\s*if\\s*\\(\\s*typeof\\s+" + MULTIPLE_CHARS_REGEX + "+\\s*===?\\s*([\"'])undefined\\1\\s*\\)\\s*return\\s+";
|
||||||
|
|
||||||
private YoutubeThrottlingParameterUtils() {
|
private YoutubeThrottlingParameterUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,11 +182,13 @@ final class YoutubeThrottlingParameterUtils {
|
|||||||
static String getDeobfuscationFunction(@Nonnull final String javaScriptPlayerCode,
|
static String getDeobfuscationFunction(@Nonnull final String javaScriptPlayerCode,
|
||||||
@Nonnull final String functionName)
|
@Nonnull final String functionName)
|
||||||
throws ParsingException {
|
throws ParsingException {
|
||||||
|
String function;
|
||||||
try {
|
try {
|
||||||
return parseFunctionWithLexer(javaScriptPlayerCode, functionName);
|
function = parseFunctionWithLexer(javaScriptPlayerCode, functionName);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return parseFunctionWithRegex(javaScriptPlayerCode, functionName);
|
function = parseFunctionWithRegex(javaScriptPlayerCode, functionName);
|
||||||
}
|
}
|
||||||
|
return fixupFunction(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -214,4 +236,15 @@ final class YoutubeThrottlingParameterUtils {
|
|||||||
JavaScript.compileOrThrow(function);
|
JavaScript.compileOrThrow(function);
|
||||||
return function;
|
return function;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private static String fixupFunction(@Nonnull final String function)
|
||||||
|
throws Parser.RegexException {
|
||||||
|
final String firstArgName = Parser.matchGroup1(FUNCTION_ARGUMENTS_REGEX, function).split(",")[0].trim();
|
||||||
|
final Pattern earlyReturnPattern = Pattern.compile(
|
||||||
|
EARLY_RETURN_REGEX + firstArgName + ";",
|
||||||
|
Pattern.DOTALL);
|
||||||
|
final Matcher earlyReturnCodeMatcher = earlyReturnPattern.matcher(function);
|
||||||
|
return earlyReturnCodeMatcher.replaceFirst(";");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user