steam-manifest-tools 0.1.0 → 0.1.2

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
@@ -11,3 +11,4 @@ Scripts to interact with Steam manifest files.
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
13
  - `node to-torrent.js <manifest file> <file hash>`
14
+ - `node verify-chunks.js <depot id> [depot key]`
@@ -10,7 +10,6 @@ if (!manifestFile) {
10
10
  }
11
11
 
12
12
  const fs = require("fs");
13
- const fsPromises = require("fs/promises");
14
13
  const ContentManifest = require("steam-user/components/content_manifest");
15
14
  const { DEFAULT_HOSTS, downloadChunks } = require(".");
16
15
 
package/include/lib.js CHANGED
@@ -59,22 +59,14 @@ const getFiles = async (dir) => {
59
59
  return Array.prototype.concat(...files);
60
60
  };
61
61
 
62
- const getChunk = async (depotId, depotKey, hash) => {
62
+ const getFileContents = async (file) => {
63
63
  while (true) {
64
64
  try {
65
- let data = await fsPromises.readFile(`depot/${depotId}/chunk/${hash}`);
66
- data = SteamCrypto.symmetricDecrypt(data, depotKey);
67
- data = await CdnCompression.unzip(data);
68
- if (sha1(data) != hash) {
69
- throw new Error(`depot/${depotId}/chunk/${hash} does not match the expected hash`);
70
- }
71
- return data;
72
- } catch (e) {
73
- if (e.code == "ENOENT") {
74
- throw new Error(`depot/${depotId}/chunk/${hash} is missing`);
75
- }
65
+ return await fsPromises.readFile(file);
66
+ }
67
+ catch (e) {
76
68
  if (e.code != "EMFILE") {
77
- //console.log(`Error reading depot/${depotId}/chunk/${hash}`);
69
+ //console.log(`Error reading ${file}`);
78
70
  throw e;
79
71
  }
80
72
  await sleep(500);
@@ -82,13 +74,41 @@ const getChunk = async (depotId, depotKey, hash) => {
82
74
  }
83
75
  };
84
76
 
77
+ const getChunk = async (depotId, depotKey, hash) => {
78
+ try {
79
+ let data = await getFileContents(`depot/${depotId}/chunk/${hash}`);
80
+ data = SteamCrypto.symmetricDecrypt(data, depotKey);
81
+ data = await CdnCompression.unzip(data);
82
+ if (sha1(data) != hash) {
83
+ throw new Error(`depot/${depotId}/chunk/${hash} does not match the expected hash`);
84
+ }
85
+ return data;
86
+ }
87
+ catch (e) {
88
+ if (e.code == "ENOENT") {
89
+ throw new Error(`depot/${depotId}/chunk/${hash} is missing`);
90
+ }
91
+ throw e;
92
+ }
93
+ };
94
+
85
95
  module.exports = {
86
96
  DEFAULT_HOSTS,
87
97
  sha1,
88
98
  sha1file,
89
99
  compress,
90
100
  getFiles,
101
+ getFileContents,
91
102
  getChunk,
103
+ fetchDepotKey: async (depotId) => {
104
+ console.log(`Depot key was not supplied, attempting to fetch it...`);
105
+ const depotkeys = await fetch("https://raw.githubusercontent.com/SteamAutoCracks/ManifestHub/refs/heads/main/depotkeys.json").then(x => x.json());
106
+ if (!depotkeys[depotId]) {
107
+ console.log(`Failed to get the depot key. Please provide it manually.`);
108
+ process.exit(1);
109
+ }
110
+ return depotkeys[depotId];
111
+ },
92
112
  populateChunks: async (manifest, depotKey, installDir, onProgress) => {
93
113
  if (manifest.filenames_encrypted) {
94
114
  ContentManifest.decryptFilenames(manifest, depotKey);
@@ -200,18 +220,39 @@ module.exports = {
200
220
  }
201
221
  file.chunks.sort((a, b) => a.offset - b.offset);
202
222
 
203
- const chunkPromises = [];
223
+ await fsPromises.mkdir(path.dirname(path.join(installDir, file.filename)), { recursive: true });
224
+ const writeStream = await fsPromises.open(path.join(installDir, file.filename), "w");
204
225
  for (const chunk of file.chunks) {
205
- chunkPromises.push(getChunk(manifest.depot_id, depotKey, chunk.sha));
226
+ await writeStream.write(await getChunk(manifest.depot_id, depotKey, chunk.sha));
206
227
  }
207
- const chunks = await Promise.all(chunkPromises);
208
- const data = Buffer.concat(chunks);
209
- await fsPromises.mkdir(path.dirname(path.join(installDir, file.filename)), { recursive: true });
210
- await fsPromises.writeFile(path.join(installDir, file.filename), data);
228
+ await writeStream.close();
211
229
  if (onFileWritten) {
212
230
  onFileWritten(file.filename, exists);
213
231
  }
214
232
  }
215
233
  }
216
234
  },
235
+ verifyChunks: async (depotId, depotKey, onDeletedFile) => {
236
+ const files = await getFiles(`depot/${depotId}/chunk`);
237
+ const promises = [];
238
+ for (const file of files) {
239
+ const hash = file.substr(file.length - 40);
240
+ promises.push(getFileContents(file).then(async data => {
241
+ try {
242
+ data = SteamCrypto.symmetricDecrypt(data, depotKey);
243
+ data = await CdnCompression.unzip(data);
244
+ if (sha1(data) == hash) {
245
+ return;
246
+ }
247
+ }
248
+ catch (e) {
249
+ }
250
+ await fsPromises.unlink(file);
251
+ if (onDeletedFile) {
252
+ onDeletedFile(file, hash);
253
+ }
254
+ }));
255
+ }
256
+ await Promise.all(promises);
257
+ },
217
258
  };
package/install.js CHANGED
@@ -7,12 +7,12 @@ if (!manifestFile) {
7
7
 
8
8
  const fs = require("fs");
9
9
  const ContentManifest = require("steam-user/components/content_manifest");
10
- const { install } = require(".");
10
+ const { fetchDepotKey, install } = require(".");
11
11
 
12
12
  (async () => {
13
13
  const manifest = ContentManifest.parse(fs.readFileSync(manifestFile));
14
14
  if (!depotKey) {
15
- depotKey = await require("./include/fetch-depot-key.js")(manifest.depot_id);
15
+ depotKey = await fetchDepotKey(manifest.depot_id);
16
16
  }
17
17
  depotKey = Buffer.from(depotKey, "hex");
18
18
  await install(manifest, depotKey, undefined, (file, existed) => {
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "steam-manifest-tools",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "main": "include/lib.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/Sainan/steam-manifest-tools.git"
8
+ },
5
9
  "dependencies": {
6
10
  "@doctormckay/steam-crypto": "^1.2.0",
7
11
  "adm-zip": "^0.5.16",
@@ -5,15 +5,17 @@ if (!manifestFile || !installDir) {
5
5
  console.log("Syntax: node populate-chunks.js <manifest file> <install dir> [depot key]");
6
6
  process.exit(1);
7
7
  }
8
+
9
+ const fs = require("fs");
10
+ const ContentManifest = require("steam-user/components/content_manifest");
11
+ const { fetchDepotKey, populateChunks } = require(".");
12
+
8
13
  (async () => {
9
- const fs = require("fs");
10
- const ContentManifest = require("steam-user/components/content_manifest");
11
14
  const manifest = ContentManifest.parse(fs.readFileSync(manifestFile));
12
15
  if (!depotKey) {
13
- depotKey = await require("./include/fetch-depot-key.js")(manifest.depot_id);
16
+ depotKey = await fetchDepotKey(manifest.depot_id);
14
17
  }
15
18
  depotKey = Buffer.from(depotKey, "hex");
16
- const { populateChunks } = require(".");
17
19
  await populateChunks(manifest, depotKey, installDir, (file, file_i, num_files, chunk_i, num_chunks) => {
18
20
  if (chunk_i == 0) {
19
21
  console.log(`Processing ${file}...`);
@@ -15,7 +15,8 @@ if (!file) {
15
15
  if (manifest.filenames_encrypted) {
16
16
  if (!depotKey) {
17
17
  console.log("Manifest has encrypted filenames. A depot key will be needed.");
18
- depotKey = await require("./include/fetch-depot-key.js")(manifest.depot_id);
18
+ const { fetchDepotKey } = require(".");
19
+ depotKey = await fetchDepotKey(manifest.depot_id);
19
20
  }
20
21
  ContentManifest.decryptFilenames(manifest, Buffer.from(depotKey, "hex"));
21
22
  }
@@ -0,0 +1,18 @@
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
+ })();
@@ -1,9 +0,0 @@
1
- module.exports = async (depotId) => {
2
- console.log(`Depot key was not supplied, attempting to fetch it...`);
3
- const depotkeys = await fetch("https://raw.githubusercontent.com/SteamAutoCracks/ManifestHub/refs/heads/main/depotkeys.json").then(x => x.json());
4
- if (!depotkeys[depotId]) {
5
- console.log(`Failed to get the depot key. Please provide it manually.`);
6
- process.exit(1);
7
- }
8
- return depotkeys[depotId];
9
- };