Last active
May 26, 2018 20:02
-
-
Save gabonator/2afe9d93625efd03502589e80a1c106c to your computer and use it in GitHub Desktop.
Scorm player grabber and decoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require("request"); | |
var fs = require("fs"); | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11', | |
'Cookie': "MoodleSession=bd84957dad9ea0a2939fbcb0ffbd7116;", | |
'Accept': '/', | |
'Connection': 'keep-alive' | |
}; | |
var r = (url,root) => request({ url: url, headers:headers}, (a, b)=> | |
{ | |
quiz = b.body.match("quizJson = \"(.*)\"")[1]; | |
FC(quiz, (o) => add(root, o)); | |
}); | |
function getTestId(i) | |
{ | |
console.log("test nr:"+i); | |
request({url:"http://www.eautoskola.sk/lms/course/view.php?id=" + (120+i), headers:headers}, | |
(a, b)=> | |
{ | |
var id = b.body.match('"contextid":(\\d+)')[1]; | |
var scoid=b.body.match("name=\"scoid\" value=\"(.*?)\"")[1]; | |
var cm=b.body.match("name=\"cm\" value=\"(.*?)\"")[1]; | |
getRedir(scoid, cm); | |
}); | |
} | |
function getRedir(scoid, cm) | |
{ | |
console.log("scoid="+scoid+" cm="+cm); | |
request.post({ | |
url: 'http://www.eautoskola.sk/lms/mod/scorm/player.php', | |
headers: headers, | |
form: { mode:"normal", newattempt:"on", display:"popup", scoid:scoid, cm:cm, currentorg:"mKmy0QaoJ66sI_organization" } | |
}, function(error, response, body){ | |
var sesskey = body.match('"sesskey":"(.*?)"')[1]; | |
var url = body.match('\\\\"url\\\\":\\\\"(.*?)\\\\"')[1]; | |
var target = "http://www.eautoskola.sk/lms/mod/scorm/player.php?"+url+"&sesskey="+sesskey; | |
var target = "http://www.eautoskola.sk/lms/mod/scorm/loadSCO.php?"+url; | |
getPlayer(target); | |
}); | |
} | |
function getPlayer(url) | |
{ | |
request({url:url, headers:headers}, (a,b)=> | |
{ | |
target = b.body.match("location = \"(.*?)\"")[1]; | |
var root = target; | |
root = root.replace("/res/index.html", "/"); | |
if (target.indexOf("/index.html") == -1) | |
target += "res/index.html"; | |
console.log("test target:"+target); | |
r(target, root); | |
}); | |
} | |
var all = {}; | |
function add(id, json) | |
{ | |
var json = JSON.parse(json); | |
all[id]=(json); | |
console.log("got "+id + " name = "+json.T) | |
done(); | |
} | |
var current = 1; | |
function done() | |
{ | |
current ++; | |
if (current >61) | |
{ | |
fs.writeFileSync("quiz.js", "quiz="+JSON.stringify(all), "utf8"); | |
console.log("Hotovo!!!"); | |
return; | |
} | |
main(); | |
} | |
function main() | |
{ | |
if (current == 3) | |
done(); | |
else | |
getTestId(current); | |
} | |
main(); | |
// decoder | |
var Ye = null; | |
function FC(a, b) { | |
for (var c = gf(a), c = (new EC(c)).NT(), d = [], e = 0, g, h, k, m = -1, p = c.length; e < p; ) | |
(g = c[e]) ? 128 > g ? (d[++m] = String.fromCharCode(g), | |
++e) : 191 < g && 224 > g ? (h = c[e + 1], | |
d[++m] = String.fromCharCode((g & 31) << 6 | h & 63), | |
e += 2) : (h = c[e + 1], | |
k = c[e + 2], | |
d[++m] = String.fromCharCode((g & 15) << 12 | (h & 63) << 6 | k & 63), | |
e += 3) : ++e; | |
c = d.join(""); | |
b(c) | |
} | |
var EC = function() { | |
function a() { | |
throw Error("stream error"); | |
} | |
function b(a) { | |
return "undefined" == typeof a | |
} | |
function c(b) { | |
var c = 0 | |
, d = b[c++] | |
, e = b[c++]; | |
(-1 == d || -1 == e || 8 != (d & 15) || 0 != ((d << 8) + e) % 31 || e & 32) && a(); | |
this.aF = b; | |
this.Hr = c; | |
this.Su = this.Yu = this.Zu = 0; | |
this.oF = !1; | |
this.My = null | |
} | |
var d = [], e = [], g = [], h, k; | |
(function() { | |
var a = [], b, c = 2; | |
for (b = 0; 8 > b; ++b) | |
a.push(c), | |
c += 1 << (b >> 1); | |
for (b = 0; 3 > b; ++b) | |
d.push(b + 16); | |
for (b = 0; 7 >= b; ++b) | |
d.push((8 - b) % 8), | |
d.push(8 + b); | |
for (b = 1; 3 > b; ++b) | |
e.push(b); | |
for (b = 0; 28 > b; ++b) { | |
var h = b >> 1 << 16 | |
, c = b % 8 | |
, h = h + ((a[c] << (b - c) / 2) + 1); | |
e.push(h) | |
} | |
for (b = 3; 7 > b; ++b) | |
g.push(b); | |
c = 7; | |
for (b = 0; 24 > b; ++b) | |
a = b >> 2, | |
h = (a << 16) + c, | |
c += 1 << a, | |
g.push(h); | |
for (b = 0; 3 > b; ++b) | |
g.push(258) | |
} | |
)(); | |
c.prototype.nF = function(a) { | |
var b = this.My | |
, c = b ? b.length : 0; | |
if (a < c) | |
return b; | |
for (var d = 1024; d < a; ) | |
d <<= 1; | |
a = Array(d); | |
for (d = 0; d < c; ++d) | |
a[d] = b[d]; | |
return this.My = a | |
} | |
; | |
c.prototype.NT = function() { | |
for (; !this.oF; ) | |
this.VU(); | |
return this.My.slice(0, this.Su) | |
} | |
; | |
c.prototype.Rm = function(c) { | |
for (var d = this.Zu, e = this.Yu, g = this.aF, h = this.Hr, k; d < c; ) | |
b(k = g[h++]) && a(), | |
e |= k << d, | |
d += 8; | |
this.Yu = e >> c; | |
this.Zu = d - c; | |
this.Hr = h; | |
return e & (1 << c) - 1 | |
} | |
; | |
c.prototype.vF = function(c) { | |
var d = c[0] | |
, e = c[1]; | |
c = this.Zu; | |
for (var g = this.Yu, h = this.aF, k = this.Hr; c < e; ) { | |
var m; | |
b(m = h[k++]) && a(); | |
g |= m << c; | |
c += 8 | |
} | |
e = d[g & (1 << e) - 1]; | |
d = e >> 16; | |
e &= 65535; | |
(0 == c || c < d || 0 == d) && a(); | |
this.Yu = g >> d; | |
this.Zu = c - d; | |
this.Hr = k; | |
return e | |
} | |
; | |
c.prototype.lv = function(a) { | |
for (var b = a.length, c = 0, d = 0; d < b; ++d) | |
a[d] > c && (c = a[d]); | |
for (var e = 1 << c, g = Array(e), h = 1, k = 0, m = 2; h <= c; ++h, | |
k <<= 1, | |
m <<= 1) | |
for (var Ba = 0; Ba < b; ++Ba) | |
if (a[Ba] == h) { | |
for (var zf = 0, br = k, d = 0; d < h; ++d) | |
zf = zf << 1 | br & 1, | |
br >>= 1; | |
for (d = zf; d < e; d += m) | |
g[d] = h << 16 | Ba; | |
++k | |
} | |
return [g, c] | |
} | |
; | |
c.prototype.VU = function() { | |
function c(a, b, c, d, e) { | |
for (a = a.Rm(c) + d; 0 < a--; ) | |
b[O++] = e | |
} | |
var p = this.Rm(3); | |
p & 1 && (this.oF = !0); | |
p >>= 1; | |
if (0 == p) { | |
var t = this.aF, v = this.Hr, y; | |
b(y = t[v++]) && a(); | |
var z = y; | |
b(y = t[v++]) && a(); | |
z |= y << 8; | |
b(y = t[v++]) && a(); | |
p = y; | |
b(y = t[v++]) && a(); | |
(p | y << 8) != (~z & 65535) && a(); | |
this.Zu = this.Yu = 0; | |
y = this.Su; | |
p = this.nF(y + z); | |
this.Su = z = y + z; | |
for (var I = y; I < z; ++I) { | |
if (b(y = t[v++])) { | |
this.oF = !0; | |
break | |
} | |
p[I] = y | |
} | |
this.Hr = v | |
} else { | |
if (1 == p) { | |
if (!h) { | |
for (var t = Array(288), O = 0; 143 >= O; ++O) | |
t[O] = 8; | |
for (; 255 >= O; ++O) | |
t[O] = 9; | |
for (; 279 >= O; ++O) | |
t[O] = 7; | |
for (; 287 >= O; ++O) | |
t[O] = 8; | |
h = this.lv(t); | |
p = Array(31); | |
for (O = 0; 32 > O; ++O) | |
p[O] = 5; | |
k = this.lv(p); | |
k[0][15] = 0; | |
k[0][31] = 0 | |
} | |
v = h; | |
y = k | |
} else if (2 == p) { | |
p = this.Rm(5) + 257; | |
y = this.Rm(5) + 1; | |
v = this.Rm(4) + 4; | |
t = Array(d.length); | |
for (O = 0; O < v; ) | |
t[d[O++]] = this.Rm(3); | |
v = this.lv(t); | |
O = t = 0; | |
y = p + y; | |
for (z = Array(y); O < y; ) | |
I = this.vF(v), | |
16 == I ? c(this, z, 2, 3, t) : 17 == I ? c(this, z, 3, 3, t = 0) : 18 == I ? c(this, z, 7, 11, t = 0) : z[O++] = t = I; | |
v = this.lv(z.slice(0, p)); | |
y = this.lv(z.slice(p, y)) | |
} else | |
a(); | |
z = (p = this.My) ? p.length : 0; | |
for (I = this.Su; ; ) { | |
var ca = this.vF(v); | |
if (256 > ca) | |
I + 1 >= z && (p = this.nF(I + 1), | |
z = p.length), | |
p[I++] = ca; | |
else { | |
if (256 == ca) { | |
this.Su = I; | |
break | |
} | |
var ca = ca - 257 | |
, ca = g[ca] | |
, Ba = ca >> 16; | |
0 < Ba && (Ba = this.Rm(Ba)); | |
t = (ca & 65535) + Ba; | |
ca = this.vF(y); | |
ca = e[ca]; | |
Ba = ca >> 16; | |
0 < Ba && (Ba = this.Rm(Ba)); | |
ca = (ca & 65535) + Ba; | |
I + t >= z && (p = this.nF(I + t), | |
z = p.length); | |
for (Ba = 0; Ba < t; ++Ba, | |
++I) | |
p[I] = p[I - ca] | |
} | |
} | |
} | |
} | |
; | |
return c | |
}(); | |
function gf(a) { | |
var b = []; | |
ff(a, function(a) { | |
b.push(a) | |
}); | |
return b | |
} | |
function ff(a, b) { | |
function c(b) { | |
for (; d < a.length; ) { | |
var c = a.charAt(d++) | |
, e = Ze[c]; | |
if (null != e) | |
return e; | |
if (!/^[\s\xa0]*$/.test(c)) | |
throw Error("Unknown base64 encoding at char: " + c); | |
} | |
return b | |
} | |
df(); | |
for (var d = 0; ; ) { | |
var e = c(-1) | |
, g = c(0) | |
, h = c(64) | |
, k = c(64); | |
if (64 === k && -1 === e) | |
break; | |
b(e << 2 | g >> 4); | |
64 != h && (b(g << 4 & 240 | h >> 2), | |
64 != k && b(h << 6 & 192 | k)) | |
} | |
} | |
function df() { | |
if (!Ye) { | |
Ye = {}; | |
Ze = {}; | |
for (var a = 0; 65 > a; a++) | |
Ye[a] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(a), | |
Ze[Ye[a]] = a, | |
62 <= a && (Ze["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.".charAt(a)] = a) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment