steam-manifest-tools 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,14 +1,14 @@
1
- Scripts to interact with Steam manifest files.
2
- - `node download-manifest.js <depot id> <manifest id>`
3
- - `node download-chunks.js <manifest file> [--lancache]` (basically the same as prefilling a LAN cache, optionally downloads from a LAN cache)
4
- - `node populate-chunks.js <manifest file> <install dir> [depot key]` (can also be used to prefill a LAN cache, tho compression is not as good as Steam's)
5
- - `node lancache.js`
1
+ Tools to interact with Steam manifest files.
2
+ - `mango download-manifest <depot id> <manifest id>`
3
+ - `mango download-chunks <manifest file> [--lancache]` (basically the same as prefilling a LAN cache, optionally downloads from a LAN cache)
4
+ - `mango populate-chunks <manifest file> <install dir> [depot key]` (can also be used to prefill a LAN cache, tho compression is not as good as Steam's)
5
+ - `mango lancache`
6
6
  - Must run as root to obtain port 80
7
7
  - `lancache.steamcontent.com` must resolve to your LAN cache server IP (either via custom DNS server or OS hosts file)
8
- - `node install.js <manifest file> [depot key]` (requires chunks to have been populated and/or downloaded beforehand)
9
- - `node to-json.js <manifest file> [depot key]`
10
- - `node to-hashdeep-auditfile.js <manifest file> [depot key]`
8
+ - `mango install <manifest file> [depot key]` (requires chunks to have been populated and/or downloaded beforehand)
9
+ - `mango to-json <manifest file> [depot key]`
10
+ - `mango to-hashdeep-auditfile <manifest file> [depot key]`
11
11
  - Note that hashdeep requires exact path matches and this script makes a few assumptions
12
12
  - Example verification usage: `hashdeep -a -l -v -v -k 241561_8497448424664183398.manifest.auditfile -r 8497448424664183398`
13
- - `node to-torrent.js <manifest file> <file hash>`
14
- - `node verify-chunks.js <depot id> [depot key]`
13
+ - `mango to-torrent <manifest file> <file hash>`
14
+ - `mango verify-chunks <depot id> [depot key]`
@@ -100,6 +100,20 @@ module.exports = {
100
100
  getFiles,
101
101
  getFileContents,
102
102
  getChunk,
103
+ fetchManifest: async (depotId, manifestId) => {
104
+ const forkers = [
105
+ "qwe213312",
106
+ "mejikuhibiniu1",
107
+ "Sainan",
108
+ "FreakyObservatory",
109
+ ];
110
+ for (const forker of forkers) {
111
+ const res = await fetch(`https://raw.githubusercontent.com/${forker}/k25FCdfEOoEJ42S6/refs/heads/main/${depotId}_${manifestId}.manifest`);
112
+ if (res.status == 200) {
113
+ return await res.arrayBuffer();
114
+ }
115
+ }
116
+ },
103
117
  fetchDepotKey: async (depotId) => {
104
118
  console.log(`Depot key was not supplied, attempting to fetch it...`);
105
119
  const depotkeys = await fetch("https://raw.githubusercontent.com/SteamAutoCracks/ManifestHub/refs/heads/main/depotkeys.json").then(x => x.json());
package/mango.js ADDED
@@ -0,0 +1,312 @@
1
+ const tool = process.argv[2];
2
+ switch (tool) {
3
+ default: {
4
+ console.error(tool ? `Unknown tool: ${tool}` : "Syntax: mango <tool>");
5
+ process.exit(1);
6
+ } break;
7
+
8
+ case "download-manifest": {
9
+ const depotId = process.argv[1 + 2];
10
+ const manifestId = process.argv[1 + 3];
11
+ if (!depotId || !manifestId) {
12
+ console.log("Syntax: mango download-manifest <depot id> <manifest id>");
13
+ process.exit(1);
14
+ }
15
+
16
+ const fsPromises = require("fs/promises");
17
+ const { fetchManifest } = require(".");
18
+
19
+ (async () => {
20
+ const ab = await fetchManifest(depotId, manifestId);
21
+ if (ab) {
22
+ await fsPromises.writeFile(`${depotId}_${manifestId}.manifest`, Buffer.from(ab));
23
+ console.log(`Saved in ${depotId}_${manifestId}.manifest`);
24
+ process.exit(0);
25
+ }
26
+ else {
27
+ console.log(`Could not find the given manifest. Double-check with https://steamdb.info/depot/${depotId}/manifests/ and report an issue in https://github.com/Sainan/k25FCdfEOoEJ42S6/issues if you're sure the manifest exists.`);
28
+ process.exit(1);
29
+ }
30
+ })();
31
+ } break;
32
+
33
+ case "download-chunks": {
34
+ let manifestFile = process.argv[1 + 2];
35
+ let lancache = (process.argv[1 + 3] == "--lancache");
36
+ if (manifestFile == "--lancache") {
37
+ lancache = true;
38
+ manifestFile = process.argv[1 + 3];
39
+ }
40
+ if (!manifestFile) {
41
+ console.log("Syntax: mango download-chunks <manifest file> [--lancache]");
42
+ process.exit(1);
43
+ }
44
+
45
+ const fs = require("fs");
46
+ const ContentManifest = require("steam-user/components/content_manifest");
47
+ const { DEFAULT_HOSTS, downloadChunks } = require(".");
48
+
49
+ const hosts = lancache ? ["http://lancache.steamcontent.com"] : DEFAULT_HOSTS;
50
+
51
+ const manifest = ContentManifest.parse(fs.readFileSync(manifestFile));
52
+ downloadChunks(
53
+ manifest,
54
+ undefined /*(num_chunks) => {}*/,
55
+ (path, host) => { console.log(`${path}: Downloading from ${host}`); },
56
+ (path, status, host) => { console.log(`${path}: Got ${status/*} from ${host*/}`); },
57
+ (path, err) => { console.log(`${path}: `, err); },
58
+ hosts
59
+ ).then(() => process.exit(0));
60
+ } break;
61
+
62
+ case "populate-chunks": {
63
+ const manifestFile = process.argv[1 + 2];
64
+ const installDir = process.argv[1 + 3];
65
+ let depotKey = process.argv[1 + 4];
66
+ if (!manifestFile || !installDir) {
67
+ console.log("Syntax: mango populate-chunks <manifest file> <install dir> [depot key]");
68
+ process.exit(1);
69
+ }
70
+
71
+ const fs = require("fs");
72
+ const ContentManifest = require("steam-user/components/content_manifest");
73
+ const { fetchDepotKey, populateChunks } = require(".");
74
+
75
+ (async () => {
76
+ const manifest = ContentManifest.parse(fs.readFileSync(manifestFile));
77
+ if (!depotKey) {
78
+ depotKey = await fetchDepotKey(manifest.depot_id);
79
+ }
80
+ depotKey = Buffer.from(depotKey, "hex");
81
+ await populateChunks(manifest, depotKey, installDir, (file, file_i, num_files, chunk_i, num_chunks) => {
82
+ if (chunk_i == 0) {
83
+ console.log(`Processing ${file}...`);
84
+ }
85
+ });
86
+ process.exit(0);
87
+ })();
88
+ } break;
89
+
90
+ case "lancache": {
91
+ const fs = require("fs");
92
+ const fsPromises = require("fs/promises");
93
+ const path = require("path");
94
+ const express = require("express");
95
+ const net = require("net");
96
+ const sni = require("sni");
97
+
98
+ const app = express();
99
+
100
+ app.use((req, res, next) => {
101
+ res.on("finish", () => {
102
+ console.log(`${req.socket.remoteAddress} - ${req.url} - ${res.statusCode}`);
103
+ });
104
+ next();
105
+ });
106
+
107
+ app.get("/depot/:depotId/chunk/:sha", async (req, res) => {
108
+ if (fs.existsSync(__dirname + req.url)) {
109
+ res.sendFile(__dirname + req.url);
110
+ }
111
+ else if (req.host.endsWith(".steamcontent.com")) {
112
+ const fr = await fetch(`http://${req.host}${req.url}`);
113
+ if (fr.status == 200) {
114
+ const buf = Buffer.from(await fr.arrayBuffer());
115
+ await fsPromises.mkdir(path.dirname(__dirname + req.url), { recursive: true });
116
+ await fsPromises.writeFile(__dirname + req.url, buf);
117
+ res.send(buf).end();
118
+ }
119
+ else {
120
+ res.status(fr.status).send("Upstream error").end();
121
+ }
122
+ }
123
+ else {
124
+ res.status(400).send("Don't have this chunk").end();
125
+ }
126
+ });
127
+
128
+ app.use((req, res) => {
129
+ res.status(400).send("Don't know this endpoint").end();
130
+ });
131
+
132
+ app.listen(80, () => {
133
+ console.log("Listening on port 80");
134
+ });
135
+
136
+ // Transparently forward traffic on port 443 to avoid breaking HTTPS connections
137
+
138
+ net.createServer(socket => {
139
+ socket.once("data", firstPacket => {
140
+ const hostname = sni(firstPacket);
141
+ if (!hostname) {
142
+ return;
143
+ }
144
+ console.log(`${socket.remoteAddress} - Starting TLS proxy to ${hostname}`);
145
+ const upstream = net.connect(443, hostname, () => {
146
+ upstream.write(firstPacket);
147
+ socket.pipe(upstream).pipe(socket);
148
+ });
149
+ upstream.on("error", () => socket.end());
150
+ });
151
+ socket.on("error", () => {});
152
+ }).listen(443, () => {
153
+ console.log("Listening on port 443");
154
+ });
155
+ } break;
156
+
157
+ case "install": {
158
+ const manifestFile = process.argv[1 + 2];
159
+ let depotKey = process.argv[1 + 3];
160
+ if (!manifestFile) {
161
+ console.log("Syntax: mango install <manifest file> [depot key]");
162
+ process.exit(1);
163
+ }
164
+
165
+ const fs = require("fs");
166
+ const ContentManifest = require("steam-user/components/content_manifest");
167
+ const { fetchDepotKey, install } = require(".");
168
+
169
+ (async () => {
170
+ const manifest = ContentManifest.parse(fs.readFileSync(manifestFile));
171
+ if (!depotKey) {
172
+ depotKey = await fetchDepotKey(manifest.depot_id);
173
+ }
174
+ depotKey = Buffer.from(depotKey, "hex");
175
+ await install(manifest, depotKey, undefined, (file, existed) => {
176
+ console.log(`${existed ? "Repaired" : "Created"} ${file}`);
177
+ });
178
+ process.exit(0);
179
+ })();
180
+ } break;
181
+
182
+ case "to-json": {
183
+ const fs = require("fs");
184
+ const ContentManifest = require("steam-user/components/content_manifest");
185
+
186
+ const file = process.argv[1 + 2];
187
+ const depotKey = process.argv[1 + 3];
188
+ if (!file) {
189
+ console.log("Syntax: mango to-json <manifest file> [depot key]");
190
+ process.exit(1);
191
+ }
192
+
193
+ const buf = fs.readFileSync(file);
194
+ const manifest = ContentManifest.parse(buf);
195
+ if (manifest.filenames_encrypted) {
196
+ if (depotKey) {
197
+ ContentManifest.decryptFilenames(manifest, Buffer.from(depotKey, "hex")); // Sets filenames_encrypted to false
198
+ //manifest.filenames_decrypted = true; // Indicate that this transformation took place in the JSON export // Kinda pointless because some .manifest files are already decrypted by their sources
199
+ } else {
200
+ console.log("Manifest has encrypted filenames, suggest supplying depot key");
201
+ }
202
+
203
+ }
204
+ fs.writeFileSync(file + ".json", JSON.stringify(manifest, null, 2));
205
+
206
+ process.exit(0);
207
+ } break;
208
+
209
+ case "to-hashdeep-auditfile": {
210
+ const fs = require("fs");
211
+ const path = require("path");
212
+ const ContentManifest = require("steam-user/components/content_manifest");
213
+
214
+ const file = process.argv[1 + 2];
215
+ let depotKey = process.argv[1 + 3];
216
+ if (!file) {
217
+ console.log("Syntax: mango to-hashdeep-auditfile <manifest file> [depot key]");
218
+ process.exit(1);
219
+ }
220
+
221
+ (async () => {
222
+ const buf = fs.readFileSync(file);
223
+ const manifest = ContentManifest.parse(buf);
224
+ if (manifest.filenames_encrypted) {
225
+ if (!depotKey) {
226
+ console.log("Manifest has encrypted filenames. A depot key will be needed.");
227
+ const { fetchDepotKey } = require(".");
228
+ depotKey = await fetchDepotKey(manifest.depot_id);
229
+ }
230
+ ContentManifest.decryptFilenames(manifest, Buffer.from(depotKey, "hex"));
231
+ }
232
+
233
+ const fh = fs.createWriteStream(`${file}.auditfile`);
234
+ fh.write("%%%% HASHDEEP-1.0\n");
235
+ fh.write("%%%% size,sha1,filename\n");
236
+ for (const file of manifest.files) {
237
+ if ((file.flags & 64) === 0) {
238
+ fh.write(`${file.size},${file.sha_content},${manifest.gid_manifest}${path.sep}${path.sep != '\\' ? file.filename.split('\\').join(path.sep) : file.filename.split('/').join(path.sep)}\n`);
239
+ }
240
+ }
241
+ fh.end();
242
+
243
+ process.exit(0);
244
+ })();
245
+ } break;
246
+
247
+ case "to-torrent": {
248
+ const fs = require("fs");
249
+ const ContentManifest = require("steam-user/components/content_manifest");
250
+
251
+ function toPieces(hexArray) {
252
+ const bufs = hexArray.map(h => {
253
+ if (typeof h !== "string" || h.length !== 40) {
254
+ throw new Error(`Invalid SHA1 hex string: ${h}`);
255
+ }
256
+ return Buffer.from(h, "hex");
257
+ });
258
+ return Buffer.concat(bufs);
259
+ }
260
+
261
+ const manifestFile = process.argv[1 + 2];
262
+ const fileHash = process.argv[1 + 3];
263
+ if (!manifestFile || !fileHash) {
264
+ console.log("Syntax: mango to-torrent <manifest file> <file hash>");
265
+ process.exit(1);
266
+ }
267
+ const manifest = ContentManifest.parse(fs.readFileSync(manifestFile));
268
+ const file = manifest.files.find(x => x.sha_content == fileHash);
269
+ if (!file) {
270
+ console.log(`No file with content hash ${fileHash} found in ${manifestFile}`);
271
+ process.exit(1);
272
+ }
273
+ import("parse-torrent").then(({ toTorrentFile }) => {
274
+ for (const chunk of file.chunks) {
275
+ chunk.offset = parseInt(chunk.offset);
276
+ }
277
+ file.chunks.sort((a, b) => a.offset - b.offset);
278
+ const buf = toTorrentFile({
279
+ info: {
280
+ name: file.sha_content,
281
+ length: parseInt(file.size),
282
+ 'piece length': 1048576,
283
+ pieces: toPieces(file.chunks.map(chunk => chunk.sha))
284
+ }
285
+ })
286
+ fs.writeFileSync(`${file.sha_content}.torrent`, buf);
287
+ process.exit(0);
288
+ });
289
+ } break;
290
+
291
+ case "verify-chunks": {
292
+ const depotId = process.argv[1 + 2];
293
+ let depotKey = process.argv[1 + 3];
294
+ if (!depotId) {
295
+ console.log("Syntax: mango verify-chunks <depot id> [depot key]");
296
+ process.exit(1);
297
+ }
298
+
299
+ const { fetchDepotKey, verifyChunks } = require(".");
300
+ (async () => {
301
+ if (!depotKey) {
302
+ depotKey = await fetchDepotKey(depotId);
303
+ }
304
+ depotKey = Buffer.from(depotKey, "hex");
305
+ console.log(`Verifying chunks...`);
306
+ await verifyChunks(depotId, depotKey, (file, expectedHash) => {
307
+ console.log(`Deleted ${file}`);
308
+ });
309
+ process.exit(0);
310
+ })();
311
+ } break;
312
+ }
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "steam-manifest-tools",
3
- "version": "0.1.3",
4
- "main": "include/lib.js",
3
+ "version": "0.1.4",
4
+ "main": "lib.js",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/Sainan/steam-manifest-tools.git"
8
8
  },
9
+ "scripts": {
10
+ "build": "bun build mango.js --compile"
11
+ },
9
12
  "dependencies": {
10
13
  "@doctormckay/steam-crypto": "^1.2.0",
11
14
  "adm-zip": "^0.5.16",
@@ -1,26 +0,0 @@
1
- let manifestFile = process.argv[2];
2
- let lancache = (process.argv[3] == "--lancache");
3
- if (manifestFile == "--lancache") {
4
- lancache = true;
5
- manifestFile = process.argv[3];
6
- }
7
- if (!manifestFile) {
8
- console.log("Syntax: node download-chunks.js <manifest file> [--lancache]");
9
- process.exit(1);
10
- }
11
-
12
- const fs = require("fs");
13
- const ContentManifest = require("steam-user/components/content_manifest");
14
- const { DEFAULT_HOSTS, downloadChunks } = require(".");
15
-
16
- const hosts = lancache ? ["http://lancache.steamcontent.com"] : DEFAULT_HOSTS;
17
-
18
- const manifest = ContentManifest.parse(fs.readFileSync(manifestFile));
19
- downloadChunks(
20
- manifest,
21
- undefined /*(num_chunks) => {}*/,
22
- (path, host) => { console.log(`${path}: Downloading from ${host}`); },
23
- (path, status, host) => { console.log(`${path}: Got ${status/*} from ${host*/}`); },
24
- (path, err) => { console.log(`${path}: `, err); },
25
- hosts
26
- );
@@ -1,28 +0,0 @@
1
- const depotId = process.argv[2];
2
- const manifestId = process.argv[3];
3
- if (!depotId || !manifestId) {
4
- console.log("Syntax: node download-manifest.js <depot id> <manifest id>");
5
- process.exit(1);
6
- }
7
-
8
- const fsPromises = require("fs/promises");
9
-
10
- const forkers = [
11
- "qwe213312",
12
- "mejikuhibiniu1",
13
- "Sainan",
14
- "FreakyObservatory",
15
- ];
16
- (async () => {
17
- let i = 0;
18
- for (const forker of forkers) {
19
- const res = await fetch(`https://raw.githubusercontent.com/${forker}/k25FCdfEOoEJ42S6/refs/heads/main/${depotId}_${manifestId}.manifest`);
20
- if (res.status == 200) {
21
- const ab = await res.arrayBuffer();
22
- await fsPromises.writeFile(`${depotId}_${manifestId}.manifest`, Buffer.from(ab));
23
- console.log(`Saved in ${depotId}_${manifestId}.manifest`);
24
- return;
25
- }
26
- }
27
- console.log(`Could not find the given manifest. Double-check with https://steamdb.info/depot/${depotId}/manifests/ and report an issue in https://github.com/Sainan/k25FCdfEOoEJ42S6/issues if you're sure the manifest exists.`);
28
- })();
package/install.js DELETED
@@ -1,21 +0,0 @@
1
- const manifestFile = process.argv[2];
2
- let depotKey = process.argv[3];
3
- if (!manifestFile) {
4
- console.log("Syntax: node install.js <manifest file> [depot key]");
5
- process.exit(1);
6
- }
7
-
8
- const fs = require("fs");
9
- const ContentManifest = require("steam-user/components/content_manifest");
10
- const { fetchDepotKey, install } = require(".");
11
-
12
- (async () => {
13
- const manifest = ContentManifest.parse(fs.readFileSync(manifestFile));
14
- if (!depotKey) {
15
- depotKey = await fetchDepotKey(manifest.depot_id);
16
- }
17
- depotKey = Buffer.from(depotKey, "hex");
18
- await install(manifest, depotKey, undefined, (file, existed) => {
19
- console.log(`${existed ? "Repaired" : "Created"} ${file}`);
20
- });
21
- })();
package/lancache.js DELETED
@@ -1,60 +0,0 @@
1
- const fs = require("fs");
2
- const fsPromises = require("fs/promises");
3
- const path = require("path");
4
- const express = require("express");
5
- const net = require("net");
6
- const sni = require("sni");
7
-
8
- const app = express();
9
-
10
- app.use((req, res, next) => {
11
- res.on("finish", () => {
12
- console.log(`${req.socket.remoteAddress} - ${req.url} - ${res.statusCode}`);
13
- });
14
- next();
15
- });
16
-
17
- app.get("/depot/:depotId/chunk/:sha", async (req, res) => {
18
- if (fs.existsSync(__dirname + req.url)) {
19
- res.sendFile(__dirname + req.url);
20
- }
21
- else if (req.host.endsWith(".steamcontent.com")) {
22
- const fr = await fetch(`http://${req.host}${req.url}`);
23
- if (fr.status == 200) {
24
- const buf = Buffer.from(await fr.arrayBuffer());
25
- await fsPromises.mkdir(path.dirname(__dirname + req.url), { recursive: true });
26
- await fsPromises.writeFile(__dirname + req.url, buf);
27
- res.send(buf).end();
28
- }
29
- else {
30
- res.status(fr.status).send("Upstream error").end();
31
- }
32
- }
33
- else {
34
- res.status(400).send("Don't have this chunk").end();
35
- }
36
- });
37
-
38
- app.use((req, res) => {
39
- res.status(400).send("Don't know this endpoint").end();
40
- });
41
-
42
- app.listen(80, () => {
43
- console.log("Listening on port 80");
44
- });
45
-
46
- // Transparently forward traffic on port 443 to avoid breaking HTTPS connections
47
-
48
- net.createServer(socket => {
49
- socket.once("data", firstPacket => {
50
- const hostname = sni(firstPacket);
51
- console.log(`${socket.remoteAddress} - Starting TLS proxy to ${hostname}`);
52
- const upstream = net.connect(443, hostname, () => {
53
- upstream.write(firstPacket);
54
- socket.pipe(upstream).pipe(socket);
55
- });
56
- upstream.on("error", () => socket.end());
57
- });
58
- }).listen(443, () => {
59
- console.log("Listening on port 443");
60
- });
@@ -1,24 +0,0 @@
1
- const manifestFile = process.argv[2];
2
- const installDir = process.argv[3];
3
- let depotKey = process.argv[4];
4
- if (!manifestFile || !installDir) {
5
- console.log("Syntax: node populate-chunks.js <manifest file> <install dir> [depot key]");
6
- process.exit(1);
7
- }
8
-
9
- const fs = require("fs");
10
- const ContentManifest = require("steam-user/components/content_manifest");
11
- const { fetchDepotKey, populateChunks } = require(".");
12
-
13
- (async () => {
14
- const manifest = ContentManifest.parse(fs.readFileSync(manifestFile));
15
- if (!depotKey) {
16
- depotKey = await fetchDepotKey(manifest.depot_id);
17
- }
18
- depotKey = Buffer.from(depotKey, "hex");
19
- await populateChunks(manifest, depotKey, installDir, (file, file_i, num_files, chunk_i, num_chunks) => {
20
- if (chunk_i == 0) {
21
- console.log(`Processing ${file}...`);
22
- }
23
- });
24
- })();
@@ -1,33 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const ContentManifest = require("steam-user/components/content_manifest");
4
-
5
- const file = process.argv[2];
6
- let depotKey = process.argv[3];
7
- if (!file) {
8
- console.log("Syntax: node to-hashdeep-auditfile.js <manifest file> [depot key]");
9
- process.exit(1);
10
- }
11
-
12
- (async () => {
13
- const buf = fs.readFileSync(file);
14
- const manifest = ContentManifest.parse(buf);
15
- if (manifest.filenames_encrypted) {
16
- if (!depotKey) {
17
- console.log("Manifest has encrypted filenames. A depot key will be needed.");
18
- const { fetchDepotKey } = require(".");
19
- depotKey = await fetchDepotKey(manifest.depot_id);
20
- }
21
- ContentManifest.decryptFilenames(manifest, Buffer.from(depotKey, "hex"));
22
- }
23
-
24
- const fh = fs.createWriteStream(`${file}.auditfile`);
25
- fh.write("%%%% HASHDEEP-1.0\n");
26
- fh.write("%%%% size,sha1,filename\n");
27
- for (const file of manifest.files) {
28
- if ((file.flags & 64) === 0) {
29
- fh.write(`${file.size},${file.sha_content},${manifest.gid_manifest}${path.sep}${path.sep != '\\' ? file.filename.split('\\').join(path.sep) : file.filename.split('/').join(path.sep)}\n`);
30
- }
31
- }
32
- fh.end();
33
- })();
package/to-json.js DELETED
@@ -1,22 +0,0 @@
1
- const fs = require("fs");
2
- const ContentManifest = require("steam-user/components/content_manifest");
3
-
4
- const file = process.argv[2];
5
- const depotKey = process.argv[3];
6
- if (!file) {
7
- console.log("Syntax: node to-json.js <manifest file> [depot key]");
8
- process.exit(1);
9
- }
10
-
11
- const buf = fs.readFileSync(file);
12
- const manifest = ContentManifest.parse(buf);
13
- if (manifest.filenames_encrypted) {
14
- if (depotKey) {
15
- ContentManifest.decryptFilenames(manifest, Buffer.from(depotKey, "hex")); // Sets filenames_encrypted to false
16
- //manifest.filenames_decrypted = true; // Indicate that this transformation took place in the JSON export // Kinda pointless because some .manifest files are already decrypted by their sources
17
- } else {
18
- console.log("Manifest has encrypted filenames, suggest supplying depot key");
19
- }
20
-
21
- }
22
- fs.writeFileSync(file + ".json", JSON.stringify(manifest, null, 2));
package/to-torrent.js DELETED
@@ -1,40 +0,0 @@
1
- const fs = require("fs");
2
- const ContentManifest = require("steam-user/components/content_manifest");
3
-
4
- function toPieces(hexArray) {
5
- const bufs = hexArray.map(h => {
6
- if (typeof h !== "string" || h.length !== 40) {
7
- throw new Error(`Invalid SHA1 hex string: ${h}`);
8
- }
9
- return Buffer.from(h, "hex");
10
- });
11
- return Buffer.concat(bufs);
12
- }
13
-
14
- const manifestFile = process.argv[2];
15
- const fileHash = process.argv[3];
16
- if (!manifestFile || !fileHash) {
17
- console.log("Syntax: node to-torrent.js <manifest file> <file hash>");
18
- process.exit(1);
19
- }
20
- const manifest = ContentManifest.parse(fs.readFileSync(manifestFile));
21
- const file = manifest.files.find(x => x.sha_content == fileHash);
22
- if (!file) {
23
- console.log(`No file with content hash ${fileHash} found in ${manifestFile}`);
24
- process.exit(1);
25
- }
26
- import("parse-torrent").then(({ toTorrentFile }) => {
27
- for (const chunk of file.chunks) {
28
- chunk.offset = parseInt(chunk.offset);
29
- }
30
- file.chunks.sort((a, b) => a.offset - b.offset);
31
- const buf = toTorrentFile({
32
- info: {
33
- name: file.sha_content,
34
- length: parseInt(file.size),
35
- 'piece length': 1048576,
36
- pieces: toPieces(file.chunks.map(chunk => chunk.sha))
37
- }
38
- })
39
- fs.writeFileSync(`${file.sha_content}.torrent`, buf);
40
- });
package/verify-chunks.js DELETED
@@ -1,18 +0,0 @@
1
- const depotId = process.argv[2];
2
- let depotKey = process.argv[3];
3
- if (!depotId) {
4
- console.log("Syntax: node verify-chunks.js <depot id> [depot key]");
5
- process.exit(1);
6
- }
7
-
8
- const { fetchDepotKey, verifyChunks } = require(".");
9
- (async () => {
10
- if (!depotKey) {
11
- depotKey = await fetchDepotKey(depotId);
12
- }
13
- depotKey = Buffer.from(depotKey, "hex");
14
- console.log(`Verifying chunks...`);
15
- await verifyChunks(depotId, depotKey, (file, expectedHash) => {
16
- console.log(`Deleted ${file}`);
17
- });
18
- })();