Skip to content

Commit

Permalink
Fixed "RegexMatcherError. Could not find function name"
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeucelli committed Jul 10, 2024
1 parent 46ce10f commit 62d6832
Show file tree
Hide file tree
Showing 5 changed files with 13,756 additions and 19 deletions.
8 changes: 7 additions & 1 deletion src/main/java/com/github/felipeucelli/javatube/Cipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ private static String getInitialFunctionName(String js) throws Exception {
}
private String getThrottlingFunctionName(String js) throws Exception {
// a.D && (b = a.get("n")) && (b = Usa[0](b), a.set("n", b), Usa.length || mma(""))
String functionPatterns = "a\\.[a-zA-Z]\\s*&&\\s*\\([a-z]\\s*=\\s*a\\.get\\(\\\"n\\\"\\)\\)\\s*&&\\s*\\([a-z]=([$a-zA-Z]*\\[\\d\\]).*?\\)";
// a\\.[a-zA-Z]\\s*&&\\s*\\([a-z]\\s*=\\s*a\\.get\\(\\\"n\\\"\\)\\)\\s*&&\\s*\\([a-z]=([$a-zA-Z]*\\[\\d\\]).*?\\)"

// New pattern added on July 9, 2024
// In this example we can find the name of the function at index "0" of "IRa"
// a.D && (b = String.fromCharCode(110), c = a.get(b)) && (c = IRa[0](c), a.set(b,c), IRa.length || Ima(""))

String functionPatterns = "(?:\\.get\\(\"n\"\\)\\)&&\\(b=|b=String\\.fromCharCode\\(\\d+\\),c=a\\.get\\(b\\)\\)&&\\(c=)([a-zA-Z0-9$]+)(?:\\[(\\d+)])?\\([a-zA-Z0-9]\\)";
Pattern regex = Pattern.compile(functionPatterns);
Matcher matcher = regex.matcher(js);
if (matcher.find()){
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/felipeucelli/javatube/InnerTube.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public InnerTube(String client) throws JSONException {
"clientName": "WEB",
"osName": "Windows",
"osVersion": "10.0",
"clientVersion": "2.20240530.02.00",
"clientVersion": "2.20240709.01.00",
"platform": "DESKTOP"
}
}
},
"header": {
"User-Agent": "Mozilla/5.0",
"X-Youtube-Client-Name": "1",
"X-Youtube-Client-Version": "2.20240530.02.00"
"X-Youtube-Client-Version": "2.20240709.01.00"
},
"apiKey": "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8",
"requireJsPlayer": "true"
Expand Down
47 changes: 35 additions & 12 deletions src/main/java/com/github/felipeucelli/javatube/JsInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1015,28 +1015,28 @@ Object[] dictItem(Object key, Object val) throws Exception {
remaining = argStr;
argStr = null;
}
String finalMember = member;
final String[] finalMember = {member};
String finalArgStr = argStr;
int finalAllowRecursion = allowRecursion;
class InnerClass {
void assertion(Object cndn, String msg) throws Exception {
try {
if(!(boolean) cndn){
throw new Exception(finalMember + msg);
throw new Exception(finalMember[0] + msg);
}
}catch (Exception e){
if(cndn.toString().isEmpty()){
throw new Exception(finalMember + msg);
throw new Exception(finalMember[0] + msg);
}
}
}

Object evalMethod() throws Exception {
Object obj = localVars.getValue(variable);
if (finalArgStr == null){
return index(obj, finalMember, Boolean.parseBoolean(nullish));
return index(obj, finalMember[0], Boolean.parseBoolean(nullish));
}
if(obj == null && !variable.equals("String") && !variable.equals("Math")){
if(obj == null && !variable.equals("String") && !variable.equals("Math") && !variable.equals("Array")){
if(!_objects.containsValue(variable)){
try {
_objects.put(variable, extractObject(variable));
Expand All @@ -1055,8 +1055,31 @@ Object evalMethod() throws Exception {
for(String v : _separate(finalArgStr, ",", null)){
argvals.add(interpretExpression(v, localVars, finalAllowRecursion));
}

if (finalMember[0].startsWith("prototype.")) {
String[] parts = finalMember[0].split("\\.");
String new_member = parts[1];
String func_prototype = parts[2];

assertion(!argvals.isEmpty(), "takes one or more arguments");

if (func_prototype.equals("call")) {
obj = argvals.get(0);
argvals = argvals.subList(1, argvals.size());
} else if (func_prototype.equals("apply")) {
assertion(argvals.size() == 2, "takes two arguments");
obj = argvals.get(0);
argvals = (List<Object>) argvals.get(1);
assertion(argvals != null, "second argument needs to be a list");
} else {
throw new RuntimeException("Unsupported Function method " + func_prototype);
}

finalMember[0] = new_member;
}

if (obj == null && variable.equals("String")){
if (finalMember.equals("fromCharCode")){
if (finalMember[0].equals("fromCharCode")){
assertion(argvals, "takes one or more arguments");
StringBuilder result = new StringBuilder();
for (Object ob : argvals) {
Expand All @@ -1067,15 +1090,15 @@ Object evalMethod() throws Exception {
}
return result.toString();
}
throw new Exception("Unsupported String method " + finalMember);
throw new Exception("Unsupported String method " + finalMember[0]);
}else if (obj == null && variable.equals("Math")){
if (finalMember.equals("pow")){
if (finalMember[0].equals("pow")){
assertion(argvals.size() == 2, "takes two arguments");
return castToInt(Math.pow(castToInt(argvals.get(0)), castToInt(argvals.get(1))));
}
throw new Exception("Unsupported Math method " + finalMember);
throw new Exception("Unsupported Math method " + finalMember[0]);
}
switch (finalMember) {
switch (finalMember[0]) {
case "split" -> {
assertion(argvals, "takes one or more arguments");
assertion(argvals.size() == 1, "with limit argument is not implemented");
Expand Down Expand Up @@ -1191,9 +1214,9 @@ Object evalMethod() throws Exception {
}
}
if (obj instanceof List) {
return ((List<?>) obj).get(Integer.parseInt(finalMember));
return ((List<?>) obj).get(Integer.parseInt(finalMember[0]));
} else if (obj instanceof Map) {
return ((FunctionWithRepr)((Map<?, ?>) obj).get(finalMember)).call(argvals.toArray(new Object[0]), finalAllowRecursion);
return ((FunctionWithRepr)((Map<?, ?>) obj).get(finalMember[0])).call(argvals.toArray(new Object[0]), finalAllowRecursion);
}else {
throw new Exception("Cannot get index for unsupported object type " + obj);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static Stream<String> fileNames() {
"31e0b6d9-player_ias.vflset-en_US.txt",
"42a553e1-player_ias.vflset-en_US.txt",
"3ffefd71-player_ias.vflset-en_US.txt",
"bc657243-player_ias.vflset-en_US.txt"
"bc657243-player_ias.vflset-en_US.txt",
"b22ef6e7-player_ias.vflset-en_US.txt"
);
}
private String readFileContent(String fileName) throws IOException {
Expand Down Expand Up @@ -100,6 +101,7 @@ private List<String> getNSigParams(String fileName) {
case "3ffefd71-player_ias.vflset-en_US.txt" -> List.of("Qp4YR89PTr-vmb", "ima", "70QzMb0nhneLLS6BN");
case "d8a5aa5e-player_ias.vflset-en_US.txt" -> List.of("KvdthMya5dxi87dY", "ema", "70QzMb0nhneLLS6BN");
case "bc657243-player_ias.vflset-en_US.txt" -> List.of("l_slyNHt1evTOm", "Ula", "70QzMb0nhneLLS6BN");
case "b22ef6e7-player_ias.vflset-en_US.txt" -> List.of("3imMGazkXNJnWK", "Ima", "70QzMb0nhneLLS6BN");
default -> List.of("", "", "");
};
}
Expand Down Expand Up @@ -127,9 +129,10 @@ private List<String> getSigParams(String fileName) {
case "5bdfe6d5-player_ias.vflset-en_US.txt" -> List.of("tTxUgoDDREeR36Kj5wrO_NjqCHEmy6PGNIGWF9GKnFEIC4P07pOGh54LI6biy39oUrq5mTnRI3mE0gJchXqWRWNIgIARw8JQ0q", "ZKa", "AOq0QJ8wRAIgINWRWqXhcJg0Em3IRnTm5qrUo93yib6IL45hGtp70P4CIEFnKG9FWGINGP6ymEHCqjN_Orw5jK63ReERDDogUxTO");
case "31e0b6d9-player_ias.vflset-en_US.txt" -> List.of("OTxUgoDDREeR36Kj5wrO_NjqCHEmy6PGNIGTF9GKnFEIC4P07ptGh54LI6biy39oUrq5m0nRI3mE0gJchXqWRWNIgIARw8JQA", "zLa", "AOq0QJ8wRAIgINWRWqXhcJg0Em3IRnTm5qrUo93yib6IL45hGtp70P4CIEFnKG9FWGINGP6ymEHCqjN_Orw5jK63ReERDDogUxTO");
case "42a553e1-player_ias.vflset-en_US.txt" -> List.of("xUgoDDREeR36Kj5wrObNjqCHEmy6PGNIGWF9GKnFEIC4P07ptGh54AI6Oiy39oUrq5mTnRI3mE0gJchXqWRWNIgIARw8JQ0qO", "YLa", "AOq0QJ8wRAIgINWRWqXhcJg0Em3IRnTm5qrUo93yib6IL45hGtp70P4CIEFnKG9FWGINGP6ymEHCqjN_Orw5jK63ReERDDogUxTO");
case "3ffefd71-player_ias.vflset-en_US.txt" -> List.of("UgoDDREeR36Kj5wrO_NjqCHEmy6PGNIGWO9GKnFEIC4P0JptGh54LI6biy39oUrq5mTnRI3mE0gJchXqWRWNIgIARw8", "CMa", "AOq0QJ8wRAIgINWRWqXhcJg0Em3IRnTm5qrUo93yib6IL45hGtp70P4CIEFnKG9FWGINGP6ymEHCqjN_Orw5jK63ReERDDogUxTO");
case "d8a5aa5e-player_ias.vflset-en_US.txt" -> List.of("gxUToDDREeR36Kj5wrO_NjqCHEqy6PGNIGWF9GKnFEIC4P07ptGh54LI6biy39oUrq5mTnRImmE0gJchXqWRWNIgIARw8JQ03", "MNa", "AOq0QJ8wRAIgINWRWqXhcJg0Em3IRnTm5qrUo93yib6IL45hGtp70P4CIEFnKG9FWGINGP6ymEHCqjN_Orw5jK63ReERDDogUxTO");
case "bc657243-player_ias.vflset-en_US.txt" -> List.of("pOq0QJ8wRAIgINWRWqXhcJg0Em3IRnTm5qrUo93yib6IL45hGt970P4CIEFnKGOFWGINGP6ymEHCqjN_Orw5jK63ReERDDogUxTA", "GOa", "AOq0QJ8wRAIgINWRWqXhcJg0Em3IRnTm5qrUo93yib6IL45hGtp70P4CIEFnKG9FWGINGP6ymEHCqjN_Orw5jK63ReERDDogUxTO");
case "3ffefd71-player_ias.vflset-en_US.txt" -> List.of("UgoDDREeR36Kj5wrO_NjqCHEmy6PGNIGWO9GKnFEIC4P0JptGh54LI6biy39oUrq5mTnRI3mE0gJchXqWRWNIgIARw8", "CMa", "AOq0QJ8wRAIgINWRWqXhcJg0Em3IRnTm5qrUo93yib6IL45hGtp70P4CIEFnKG9FWGINGP6ymEHCqjN_Orw5jK63ReERDDogUxTO");
case "d8a5aa5e-player_ias.vflset-en_US.txt" -> List.of("gxUToDDREeR36Kj5wrO_NjqCHEqy6PGNIGWF9GKnFEIC4P07ptGh54LI6biy39oUrq5mTnRImmE0gJchXqWRWNIgIARw8JQ03", "MNa", "AOq0QJ8wRAIgINWRWqXhcJg0Em3IRnTm5qrUo93yib6IL45hGtp70P4CIEFnKG9FWGINGP6ymEHCqjN_Orw5jK63ReERDDogUxTO");
case "bc657243-player_ias.vflset-en_US.txt" -> List.of("pOq0QJ8wRAIgINWRWqXhcJg0Em3IRnTm5qrUo93yib6IL45hGt970P4CIEFnKGOFWGINGP6ymEHCqjN_Orw5jK63ReERDDogUxTA", "GOa", "AOq0QJ8wRAIgINWRWqXhcJg0Em3IRnTm5qrUo93yib6IL45hGtp70P4CIEFnKG9FWGINGP6ymEHCqjN_Orw5jK63ReERDDogUxTO");
case "b22ef6e7-player_ias.vflset-en_US.txt" -> List.of("goDDREeR36Kj5wrO_NjqCHEmy6PANTGWF9GKnFEIC4P07ptGh54LI6biy39oUrq5ITnRI3mE0gJchXqWRWNIgIARw8JQ0qOG", "LPa", "AOq0QJ8wRAIgINWRWqXhcJg0Em3IRnTm5qrUo93yib6IL45hGtp70P4CIEFnKG9FWGINGP6ymEHCqjN_Orw5jK63ReERDDogUxTO");
default -> List.of("", "", "");
};

Expand Down
Loading

0 comments on commit 62d6832

Please sign in to comment.