1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/* smplayer, GUI front-end for mplayer.
Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "sig.h"
#include <QRegExp>
#include <QStringList>
#include <QtScript>
#include <QSettings>
#include <QDebug>
//#define ULTRAVERBOSE
QString Sig::findText(const QString & text, const QString & begin, const QString & end) {
QString res;
int pos = text.indexOf(begin);
if (pos > -1) {
int pos2 = text.indexOf(end, pos);
if (pos2 > -1) {
pos = pos + begin.length();
res = text.mid(pos, pos2 - pos);
}
}
return res;
}
QString Sig::findFunctions(const QString & text) {
QString res;
//QString sts;
QRegExp rx_sts("sts:(\\d+)");
if (rx_sts.indexIn(text) != -1) {
sts = rx_sts.cap(1);
}
qDebug() << "Sig::findFunctions: sts:" << sts;
QString sig_name;
//QRegExp rx_sig("\\.sig\\|\\|([a-zA-Z0-9\\$]+)\\(");
QRegExp rx_sig("([\"\'])signature\\1\\s*,\\s*([a-zA-Z0-9$]+)\\(");
if (rx_sig.indexIn(text) != -1) {
//sig_name = rx_sig.cap(1);
sig_name = rx_sig.cap(2);
}
qDebug() << "Sig::findFunctions: sig_name:" << sig_name;
QString sig_code;
if (!sig_name.isEmpty()) {
//int pos = text.indexOf("function " + sig_name);
int pos = text.indexOf("var " + sig_name + "=function");
if (pos == -1) pos = text.indexOf("," + sig_name + "=function");
if (pos == -1) pos = text.indexOf(sig_name + "=function");
if (pos > -1) {
int endpos = text.indexOf("}", pos);
#ifdef ULTRAVERBOSE
qDebug() << "Sig::findFunctions: pos:" << pos << "endpos:" << endpos;
#endif
if (endpos > -1) {
sig_code = text.mid(pos, (endpos-pos)+1);
if (sig_code.startsWith("var ")) sig_code.replace("var " + sig_name + "=function", "function " + sig_name);
else
if (sig_code.startsWith(",")) sig_code.replace("," + sig_name + "=function", "function " + sig_name);
else
if (sig_code.startsWith(sig_name+"=")) sig_code.replace(sig_name + "=function", "function " + sig_name);
}
}
}
qDebug() << "Sig::findFunctions: sig_code:" << sig_code;
// Find the 2nd function
QString function2;
if (!sig_code.isEmpty()) {
QStringList parts = sig_code.split(";");
#ifdef ULTRAVERBOSE
qDebug() << "Sig::findFunctions: parts:" << parts;
#endif
foreach(QString part, parts) {
//qDebug() << "Sig::findFunctions: part:" << part;
QRegExp rx("([a-zA-Z\\$]+)\\.([a-zA-Z0-9]+)\\(");
if (rx.indexIn(part) != -1) {
QString possible_var = rx.cap(1);
#ifdef ULTRAVERBOSE
qDebug() << "Sig::findFunctions: possible var:" << possible_var;
#endif
if ((possible_var != "a") && (possible_var != "")) {
QString s = findText(text, "var "+ possible_var +"=", "};");
#ifdef ULTRAVERBOSE
qDebug() << "Sig::findFunctions: s:" << s;
#endif
if (!s.isEmpty()) {
function2 = "var "+ possible_var +" = "+ s +" };";
break;
}
}
}
}
}
qDebug() << "Sig::findFunctions: function2:" << function2;
if (!sig_code.isEmpty()) {
//sig_code = sig_code.replace("function "+ sig_name + "(", "function aclara(");
function_name = sig_name;
#ifdef ULTRAVERBOSE
qDebug() << "Sig::findFunctions: sig_code:" << sig_code;
#endif
res = sig_code + " " + function2;
}
qDebug() << "Sig::findFunctions: res:" << res;
decrypt_function = res;
return res;
}
QString Sig::aclara(const QString & text) {
int dot = text.indexOf('.');
qDebug("Sig::aclara: length: %d (%d.%d)", text.size(), dot, text.size()-dot-1);
QString res;
if (!decrypt_function.isEmpty()) {
QString fname = function_name;
QScriptEngine engine;
engine.evaluate(decrypt_function);
QScriptValueList args;
args << text;
QScriptValue aclarar = engine.globalObject().property(fname);
res = aclarar.call(QScriptValue(), args).toString();
}
qDebug() << "Sig::aclara: res:" << res;
if (res.isEmpty()) {
qDebug() << "Sig::aclara: signature length not supported:" << text.size() << ":" << text;
}
return res;
}
void Sig::save(QSettings * set) {
qDebug() << "Sig::save";
set->beginGroup("sig");
set->setValue("player", html5_player);
set->setValue("sts", sts);
set->setValue("function_name", function_name);
set->setValue("function", decrypt_function);
set->endGroup();
}
void Sig::load(QSettings * set) {
qDebug() << "Sig::load";
set->beginGroup("sig");
html5_player = set->value("player", "").toString();
sts = set->value("sts", "").toString();
function_name = set->value("function_name", "").toString();
decrypt_function = set->value("function", "").toString();
set->endGroup();
}
|