diff --git a/src/ssn/decryption/getDecryptionKeys.ts b/src/ssn/decryption/getDecryptionKeys.ts index 23d7b7a..db3dcfd 100644 --- a/src/ssn/decryption/getDecryptionKeys.ts +++ b/src/ssn/decryption/getDecryptionKeys.ts @@ -2,10 +2,10 @@ import updateKeys from './lib/updateKeys'; export default function getDecryptionKeys(password: Uint8Array): [number, number, number] { let [key0, key1, key2] = [0x12345678, 0x23456789, 0x34567890]; - const passwordLength = password.length; + const passwordLength = password.byteLength; //read through password - for (let i = 0; i < passwordLength; i++) { + for (let i = 0; i < passwordLength; i += 1) { const curChar = password[i]; //Exit early if there's a zero byte in the password diff --git a/src/ssn/extractFileAsStream.ts b/src/ssn/extractFileAsStream.ts index 1732c30..6e8d1bb 100644 --- a/src/ssn/extractFileAsStream.ts +++ b/src/ssn/extractFileAsStream.ts @@ -1,5 +1,6 @@ //Similar to extractFile.ts, but instead of receiving and returning an ArrayBuffer, works with Node.js streams. +import * as fs from 'fs'; import * as stream from 'stream'; import * as zlib from 'zlib'; import { ISsnFileEntry } from '../interfaces/ISsnFileEntry'; @@ -21,6 +22,11 @@ export default async function extractFileAsStream(file: ISsnFileEntry, inputStre await readBytesFromStream(curStream, 12); } + if (skipDecompression) { + const fileStream = fs.createWriteStream(`/tmp/patcher/${file.name}`); + curStream.pipe(fileStream); + } + if (!skipDecompression) { //pipe into decompression const decompressTransform = zlib.createInflateRaw(); diff --git a/src/ssn/getPatch.ts b/src/ssn/getPatch.ts index 1158798..b535283 100644 --- a/src/ssn/getPatch.ts +++ b/src/ssn/getPatch.ts @@ -39,8 +39,8 @@ export default async function getPatch(product: Product, from: number, to: numbe fileEntries.filter((file) => file.diffType === SsnDiffType.NewFile).forEach(async (file) => { try { const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, length: file.compressedSize }); - const fileContents = await extractFileAsStream(file, fileStream); - console.debug(file.name, file.compressedSize, await streamToArrayBuffer(fileContents)); + const fileContents = await extractFileAsStream(file, fileStream, true); + console.debug(file.name, file.compressedSize); //, await streamToArrayBuffer(fileContents)); //TODO: need to write to disk } catch (error) { console.error(`Could not extract file "${file.name}"`, error); @@ -51,8 +51,8 @@ export default async function getPatch(product: Product, from: number, to: numbe fileEntries.filter((file) => file.diffType === SsnDiffType.Changed).forEach(async (file) => { try { const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, length: file.compressedSize }); - const fileContents = await extractFileAsStream(file, fileStream); - console.debug(file.name, file.compressedSize, await streamToArrayBuffer(fileContents)); + const fileContents = await extractFileAsStream(file, fileStream, true); + console.debug(file.name, file.compressedSize); //, await streamToArrayBuffer(fileContents)); //TODO: need to apply diffing, then write to disk } catch (error) { console.error(`Could not extract file "${file.name}"`, error);