-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch_gryphon.js
155 lines (130 loc) · 3.89 KB
/
fetch_gryphon.js
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
/*
Experimental autofetcher/updater that fetches and updates tweetdeck's JS
*/
const https = require("https");
const fs = require("fs");
const path = require("path");
const beautify = require("js-beautify").js;
let pageContent = "";
let noWrite = false;
console.log(" Starting TweetDeck Decompiler - Fetcher (Gryphon)");
console.log(" Contacting tweetdeck.twitter.com...");
function processPage() {
try {
fs.mkdirSync("./sources_gryphon");
} catch (e) {}
pageContent.match(/https:\/\/[\w\.\d\/\-\%\~]+\.js/g).forEach(a => {
var data = "";
console.log(" Found JS file " + a + " on page.");
let fileName = a.match(/(?<=\.com\/)[\w\d\.\-\/\~]+\.js/g)[0];
let folder = fileName.split("/");
folder.pop();
folder = folder.join("/");
fs.mkdirSync("./sources_gryphon/" + folder, { recursive: true });
https.get(a, res => {
res.on("data", d => {
data += d;
});
res.on("end", () => {
console.log(" Writing file " + fileName);
if (!noWrite)
fs.writeFileSync("./sources_gryphon/" + fileName, beautify(data));
if (fileName.match("bundle") !== null && !noWrite) {
stealDependencies(data);
}
});
});
});
const bundleMatchRegex = /([0-9]+)\:\"([a-zA-Z.~-]+)"/g;
pageContent
.match(bundleMatchRegex)
.map(bundleMatch => {
const [, bundleId, bundleName] = /([0-9]+)\:\"([a-zA-Z.~-]+)"/.exec(
bundleMatch
);
if (!bundleId || !bundleName) {
return undefined;
}
const bundleRegex = new RegExp(`${bundleId}:"([a-f0-9]+)"`);
const [, bundleHash] = bundleRegex.exec(pageContent);
return `https://abs.twimg.com/gryphon-client/client-web/${bundleName}.${bundleHash}5.js`;
})
.filter(Boolean)
.forEach(bundleUrl => {
const fileName = path.basename(bundleUrl);
let data = "";
https.get(bundleUrl, res => {
res.on("data", d => {
data += d;
});
res.on("end", () => {
console.log(" Writing file " + fileName);
fs.writeFileSync(
"./sources_gryphon/gryphon-client/client-web/" + fileName,
beautify(data)
);
});
});
});
}
function stealDependencies(bundleJs) {
let o = [];
let p = [];
var whatever = true;
bundleJs
.match(
/(?<=\+\"web\/dist\/\"\+\()[\:\,\"\d\w\(\)\{\}\~\.\-\[\]\|\+]+\}(?=\[.\]\+\"\.js\"\})/g
)[0]
.match(/\{[\w\.\:\"\~\-\,]+\}/g)
.forEach(json => {
let object = JSON.parse(
json
.replace(/(?<=[\,\{]\d?\d?)(?=\d?\d?[\:])/g, '"')
.replace(/(?<=\d)\"(?=\d)/g, "")
);
if (whatever) {
for (var a in object) {
o.push(object[a]);
}
} else {
for (var b in object) {
p.push(object[b]);
}
}
whatever = false;
});
o.forEach((asdf, i) => {
console.log(" Fetching additional JS file " + o[i] + "." + p[i] + ".js");
let data = "";
let fileName = o[i] + "." + p[i] + ".js";
let baseURL = "https://ton.twimg.com/tweetdeck-web/web/dist/";
https.get(baseURL + fileName, res => {
res.on("data", d => {
data += d;
});
res.on("end", () => {
console.log(" Writing file " + fileName);
fs.writeFileSync("./sources_gryphon/" + fileName, data);
if (fileName.match("bundle") !== null) {
stealDependencies(data);
}
});
});
});
}
https.get(
"https://tweetdeck.twitter.com",
{
headers: {
Cookie: "tweetdeck_version=beta;",
"User-Agent": `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36`
}
},
res => {
console.log(" Loading tweetdeck.twitter.com...");
res.on("data", d => {
pageContent += d + ""; // lazy cast to string
});
res.on("end", () => processPage(pageContent));
}
);