steam-manifest-tools 0.1.3 → 0.1.5

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