steam-manifest-tools 0.1.0 → 0.1.1

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);
@@ -214,4 +234,27 @@ module.exports = {
214
234
  }
215
235
  }
216
236
  },
237
+ verifyChunks: async (depotId, depotKey, onDeletedFile) => {
238
+ const files = await getFiles(`depot/${depotId}/chunk`);
239
+ const promises = [];
240
+ for (const file of files) {
241
+ const hash = file.substr(file.length - 40);
242
+ promises.push(getFileContents(file).then(async data => {
243
+ try {
244
+ data = SteamCrypto.symmetricDecrypt(data, depotKey);
245
+ data = await CdnCompression.unzip(data);
246
+ if (sha1(data) == hash) {
247
+ return;
248
+ }
249
+ }
250
+ catch (e) {
251
+ }
252
+ await fsPromises.unlink(file);
253
+ if (onDeletedFile) {
254
+ onDeletedFile(file, hash);
255
+ }
256
+ }));
257
+ }
258
+ await Promise.all(promises);
259
+ },
217
260
  };
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,6 +1,6 @@
1
1
  {
2
2
  "name": "steam-manifest-tools",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "include/lib.js",
5
5
  "dependencies": {
6
6
  "@doctormckay/steam-crypto": "^1.2.0",
@@ -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
- };