From b08396520e38c548d83244213ba697586230210e Mon Sep 17 00:00:00 2001 From: lafkpages Date: Sat, 14 Oct 2023 16:52:28 +0200 Subject: [PATCH 01/11] Read the header size Pickle as uint32 --- src/asar.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/asar.ts b/src/asar.ts index 61141f6..2a28f14 100644 --- a/src/asar.ts +++ b/src/asar.ts @@ -30,7 +30,7 @@ export class Asar extends DirectoryEntry { // Read header size const headerSize = createFromBuffer(asarBytes.subarray(0, 16)) .createIterator() - .readInt(); + .readUInt32(); // Read header const rawHeader = asarBytes.subarray(16, headerSize + 16).toString(); From d243745c45f25c916fa70284144bd542415655dc Mon Sep 17 00:00:00 2001 From: lafkpages Date: Sat, 14 Oct 2023 16:52:34 +0200 Subject: [PATCH 02/11] Read header comments --- src/asar.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/asar.ts b/src/asar.ts index 2a28f14..d0517ec 100644 --- a/src/asar.ts +++ b/src/asar.ts @@ -33,6 +33,8 @@ export class Asar extends DirectoryEntry { .readUInt32(); // Read header + // We start at 16 because 0-8 are the Pickle object containing + // the header size, and 9-15 are the header size itself const rawHeader = asarBytes.subarray(16, headerSize + 16).toString(); const header = JSON.parse(rawHeader) as unknown; From 00e218978d161ae6ee4632ebda572e76db7cada7 Mon Sep 17 00:00:00 2001 From: lafkpages Date: Sat, 14 Oct 2023 16:59:15 +0200 Subject: [PATCH 03/11] Asar.getData check Pickle write calls succeed --- src/asar.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/asar.ts b/src/asar.ts index d0517ec..108a496 100644 --- a/src/asar.ts +++ b/src/asar.ts @@ -189,12 +189,16 @@ export class Asar extends DirectoryEntry { const headerDataStr = JSON.stringify(headerData); const headerPickle = createEmpty(); - headerPickle.writeString(headerDataStr); // TODO: check return val + if (!headerPickle.writeString(headerDataStr)) { + throw new Error("[Asar.getData] Failed to write header data to Pickle"); + } const headerDataBuf = headerPickle.toBuffer(); const headerSizePickle = createEmpty(); - headerSizePickle.writeUInt32(headerDataStr.length + 9); - const headerSizeDataBuf = headerSizePickle.toBuffer(); // TODO: ^^ + if (!headerSizePickle.writeUInt32(headerDataStr.length + 9)) { + throw new Error("[Asar.getData] Failed to write header size to Pickle"); + } + const headerSizeDataBuf = headerSizePickle.toBuffer(); const bufs = [headerSizeDataBuf, headerDataBuf]; From 6a162ff35feed328d1957069f10de95a7e1ea6e7 Mon Sep 17 00:00:00 2001 From: lafkpages Date: Sat, 14 Oct 2023 17:09:38 +0200 Subject: [PATCH 04/11] Remove old commented code in Asar.getData for offsets --- src/asar.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/asar.ts b/src/asar.ts index 108a496..3044ec5 100644 --- a/src/asar.ts +++ b/src/asar.ts @@ -215,12 +215,6 @@ export class Asar extends DirectoryEntry { throw new Error("[Asar.getData] File size mismatch"); } - // const realOffset = - // parseInt(fileEntry.offset) + - // headerSizeDataBuf.length + - // headerDataBuf.length + - // 1; - bufs.push(fileDataBuf); } } From cc330f947c04ec2838c94d6bbf93ee7fef526caf Mon Sep 17 00:00:00 2001 From: lafkpages Date: Sat, 14 Oct 2023 17:19:09 +0200 Subject: [PATCH 05/11] Install TypeDoc --- bun.lockb | Bin 6789 -> 10923 bytes package.json | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bun.lockb b/bun.lockb index e07a2c99e842fe9e37baec79dfd21447f6faced4..1b5767818bf33d12a11730ebb524bf5b975fe5f3 100755 GIT binary patch delta 3829 zcmcIndsLHG692xCKzJKoNqA#rK}fnuJtG?XeEk@1PG7{ zLo0GM3=B_miqfH02wbx`SCN{NLV=93fU!D5nW=<+Gfh#pF#ZPkFyMQDTLG^E?g0D} z*q|SYiNS6;a2ptB%kwf7sT7r!ugU`x$_wqZps}C;Sd$TrfwK zqQLQ@Jb7;JVv1tsDODMYJf%jhRHbDp(=#*!U~dWb18f7J{Mv109MuWQqhRMsZ^7&{ z$7XMSJ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6>&8a~&xY`$NC zExzEKLfHn)zy!rK5u8BWgY(Z{E`L2&<;aJiunQdrDaIulIn*Fbau|+r>3?Ht1x7Mh zRF{ZS0g}cgt|Mq&`ggdWb!m>O7%Ku0c8IGCVTnmc^56mN* zM5c#zvj?sjWT>;ac`V$uc))3tVF#HEC*nP@glszA&5f{)?3PJ}7V9Ob7giV$YFM!8 zG&{J1Sa@jLKl9TT$Di#rtEBPB8P1uZIJvUm&)=}oUhz&Vry9LXQT{!W;>zzo>`QTMDN(ku*t=JXI%I zlAsb)jwGoh#YM|6MdZI(!IIjbC0R7Mn3@a^QWHfrhc9V`!p*^uZWm)5@-ysWmBX8~ z1kRxu=cWW)Nw1}dx9NpqR=^g55?Cwc*}`&pHW(fv!FC{0&Zl#(0BO* z{w{A{n-4aehgAm)N}<(J4^MI=d#kt8i+_Rh2bASD{3Ce#a2&+IBv{U=fK^8>G-f5u I*qjsMAG_e%T>t<8 diff --git a/package.json b/package.json index 5c66e72..51c2f70 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "type": "module", "devDependencies": { "@electron/asar": "^3.2.7", - "bun-types": "latest" + "bun-types": "latest", + "typedoc": "^0.25.2" }, "peerDependencies": { "typescript": "^5.0.0" From c7e41538a1acc47340d499518c56b4b974d88f71 Mon Sep 17 00:00:00 2001 From: lafkpages Date: Sat, 14 Oct 2023 17:21:10 +0200 Subject: [PATCH 06/11] TypeDoc config file --- typedoc.json | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 typedoc.json diff --git a/typedoc.json b/typedoc.json new file mode 100644 index 0000000..f80995e --- /dev/null +++ b/typedoc.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://typedoc.org/schema.json", + "basePath": "src" +} From 60a13e2532aad32eb92be4ef993908dcf4888049 Mon Sep 17 00:00:00 2001 From: lafkpages Date: Sat, 14 Oct 2023 17:22:23 +0200 Subject: [PATCH 07/11] GitHub workflow for building docs --- .github/workflows/docs.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/docs.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..2b7c7e0 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,36 @@ +on: [push, pull_request] + +jobs: + docs: + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2 + + - uses: pnpm/action-setup@v2 + with: + version: 8.6.7 + + - name: Retrieve the cached "node_modules" directory (if present) + uses: actions/cache@v2 + id: node-cache + with: + path: node_modules + key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }} + + - name: Install dependencies (if the cached directory was not found) + if: steps.node-cache.outputs.cache-hit != 'true' + run: pnpm i + + - name: Create the docs directory locally in CI + run: pnpm build:docs + + - name: Deploy 🚀 + uses: JamesIves/github-pages-deploy-action@4.1.4 + with: + branch: gh-pages + folder: docs + token: ${{ secrets.GITHUB_TOKEN }} From bba769754c10bb34b4b4db8f5993bc20b99014fd Mon Sep 17 00:00:00 2001 From: lafkpages Date: Sat, 14 Oct 2023 17:23:29 +0200 Subject: [PATCH 08/11] build:docs package script --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 51c2f70..ae68351 100644 --- a/package.json +++ b/package.json @@ -12,5 +12,8 @@ }, "dependencies": { "@tybys/chromium-pickle-js": "^1.0.0" + }, + "scripts": { + "build:docs": "typedoc src/index.ts" } -} \ No newline at end of file +} From 604e695e5c073574feb62155a86b30c2fff39bb0 Mon Sep 17 00:00:00 2001 From: lafkpages Date: Sat, 14 Oct 2023 17:24:25 +0200 Subject: [PATCH 09/11] Git ignore TypeDoc-generated documentation --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 0090cc7..28bd622 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# TypeDoc generated documentation +/docs + # Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore # Logs From eff20f5613d83c88afd4643a41b12e838c5dfd0c Mon Sep 17 00:00:00 2001 From: lafkpages Date: Sat, 14 Oct 2023 17:31:25 +0200 Subject: [PATCH 10/11] Build script --- package.json | 1 + scripts/build.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 scripts/build.ts diff --git a/package.json b/package.json index ae68351..8abd21c 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@tybys/chromium-pickle-js": "^1.0.0" }, "scripts": { + "build": "bun scripts/build.ts", "build:docs": "typedoc src/index.ts" } } diff --git a/scripts/build.ts b/scripts/build.ts new file mode 100644 index 0000000..615c896 --- /dev/null +++ b/scripts/build.ts @@ -0,0 +1,14 @@ +import { rm } from "fs/promises"; + +const outdir = "dist"; + +await rm(outdir, { recursive: true, force: true }); + +await Bun.build({ + entrypoints: ["src/index.ts"], + target: "node", + minify: true, + sourcemap: "external", + outdir, + splitting: true, +}); From 054c82aa0bb78e70ed1560b7c19fb3b927fe59f5 Mon Sep 17 00:00:00 2001 From: lafkpages Date: Sat, 14 Oct 2023 17:36:19 +0200 Subject: [PATCH 11/11] Make test cleanup script a TS script --- package.json | 4 +++- scripts/cleanup-test-data.ts | 13 +++++++++++++ test/cleanupTestData.sh | 4 ---- 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100755 scripts/cleanup-test-data.ts delete mode 100755 test/cleanupTestData.sh diff --git a/package.json b/package.json index 8abd21c..4a28337 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,8 @@ }, "scripts": { "build": "bun scripts/build.ts", - "build:docs": "typedoc src/index.ts" + "build:docs": "typedoc src/index.ts", + "pretest": "bun scripts/cleanup-test-data.ts", + "test": "bun test" } } diff --git a/scripts/cleanup-test-data.ts b/scripts/cleanup-test-data.ts new file mode 100755 index 0000000..0f4d3b5 --- /dev/null +++ b/scripts/cleanup-test-data.ts @@ -0,0 +1,13 @@ +import { rm, readdir } from "fs/promises"; +import { join as joinPaths } from "path"; + +// rm -f test/ignore/*.{js,json,txt} +// rm -f test/ignore/app-*.asar + +const ignoreDir = "test/ignore"; + +for (const file of await readdir(ignoreDir)) { + if (/\.(js|json|txt)$|^app-.+\.asar/.test(file)) { + await rm(joinPaths(ignoreDir, file)); + } +} diff --git a/test/cleanupTestData.sh b/test/cleanupTestData.sh deleted file mode 100755 index 8c93fdb..0000000 --- a/test/cleanupTestData.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -rm -f test/ignore/*.{js,json,txt} -rm -f test/ignore/app-*.asar