From 9d5dddab299eeda386edc4b7ad54849030cc5040 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Tue, 28 Aug 2018 09:51:59 -0500 Subject: [PATCH] Fix signature extraction --- src/invidious/signatures.cr | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/invidious/signatures.cr b/src/invidious/signatures.cr index 7959cb0b9..ecc9edc78 100644 --- a/src/invidious/signatures.cr +++ b/src/invidious/signatures.cr @@ -4,22 +4,21 @@ def fetch_decrypt_function(client, id = "CvFH_6DNRCY") player = client.get(url).body function_name = player.match(/"signature",(?[a-zA-Z0-9]{2})\(/).not_nil!["name"] - function_body = player.match(/#{function_name}=function\(a\){(?[^}]+)}/).not_nil!["body"] + function_body = player.match(/^#{function_name}=function\(a\){(?[^}]+)}/m).not_nil!["body"] function_body = function_body.split(";")[1..-2] var_name = function_body[0][0, 2] + var_body = player.delete("\n").match(/var #{var_name}={(?(.*?))};/).not_nil!["body"] operations = {} of String => String - matches = player.delete("\n").match(/var #{var_name}={(?[a-zA-Z0-9]{2}:[^}]+}),(?[a-zA-Z0-9]{2}:[^}]+}),(?[a-zA-Z0-9]{2}:[^}]+})};/).not_nil! - 3.times do |i| - operation = matches["op#{i + 1}"] - op_name = operation[0, 2] + var_body.split("},").each do |operation| + op_name = operation.match(/^[^:]+/).not_nil![0] + op_body = operation.match(/\{[^}]+/).not_nil![0] - op_body = operation.match(/\{[^}]+\}/).not_nil![0] case op_body - when "{a.reverse()}" + when "{a.reverse()" operations[op_name] = "a" - when "{a.splice(0,b)}" + when "{a.splice(0,b)" operations[op_name] = "b" else operations[op_name] = "c" @@ -28,11 +27,10 @@ def fetch_decrypt_function(client, id = "CvFH_6DNRCY") decrypt_function = [] of {name: String, value: Int32} function_body.each do |function| - function = function.lchop(var_name + ".") - op_name = function[0, 2] + function = function.lchop(var_name).delete("[].") - function = function.lchop(op_name + "(a,") - value = function.rchop(")").to_i + op_name = function.match(/[^\(]+/).not_nil![0] + value = function.match(/\(a,(?[\d]+)\)/).not_nil!["value"].to_i decrypt_function << {name: operations[op_name], value: value} end