Skip to content

Commit 04deb5d

Browse files
committed
[YouTube] extract global variable for signature deobfuscation
Extracts the global variable used in newer signature deobfuscation functions, such as the one found in the `59b252b9` player.
1 parent 8b9f9ef commit 04deb5d

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSignatureUtils.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ final class YoutubeSignatureUtils {
3737
private static final String DEOBF_FUNC_REGEX_START = "(";
3838
private static final String DEOBF_FUNC_REGEX_END = "=function\\([a-zA-Z0-9_]+\\)\\{.+?\\})";
3939

40-
private static final String SIG_DEOBF_HELPER_OBJ_NAME_REGEX = ";([A-Za-z0-9_\\$]{2,})\\...\\(";
40+
// CHECKSTYLE:OFF
41+
private static final String SIG_DEOBF_GLOBAL_ARRAY_REGEX = "(var [A-Z]='.*'.split\\(\";\"\\))";
42+
private static final String SIG_DEOBF_HELPER_OBJ_NAME_REGEX = ";([A-Za-z0-9_\\$]{2,})\\[..";
4143
private static final String SIG_DEOBF_HELPER_OBJ_REGEX_START = "(var ";
4244
private static final String SIG_DEOBF_HELPER_OBJ_REGEX_END = "=\\{(?>.|\\n)+?\\}\\};)";
45+
// CHECKSTYLE:ON
4346

4447
private YoutubeSignatureUtils() {
4548
}
@@ -88,6 +91,9 @@ static String getDeobfuscationCode(@Nonnull final String javaScriptPlayerCode)
8891
// Assert the extracted deobfuscation function is valid
8992
JavaScript.compileOrThrow(deobfuscationFunction);
9093

94+
final String globalVar =
95+
Parser.matchGroup1(SIG_DEOBF_GLOBAL_ARRAY_REGEX, javaScriptPlayerCode);
96+
9197
final String helperObjectName =
9298
Parser.matchGroup1(SIG_DEOBF_HELPER_OBJ_NAME_REGEX, deobfuscationFunction);
9399

@@ -98,7 +104,7 @@ static String getDeobfuscationCode(@Nonnull final String javaScriptPlayerCode)
98104
+ deobfuscationFunctionName
99105
+ "(a);}";
100106

101-
return helperObject + deobfuscationFunction + ";" + callerFunction;
107+
return globalVar + ";" + helperObject + deobfuscationFunction + ";" + callerFunction;
102108
} catch (final Exception e) {
103109
throw new ParsingException("Could not parse deobfuscation function", e);
104110
}

0 commit comments

Comments
 (0)