@futpib/parser 1.0.0 → 1.0.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/build/allSettledStream.js +32 -14
- package/build/allSettledStream.test.js +32 -0
- package/build/androidPackage.d.ts +39 -0
- package/build/androidPackageParser.d.ts +17 -0
- package/build/androidPackageParser.js +183 -0
- package/build/{apkParser.test.js → androidPackageParser.test.js} +7 -7
- package/build/androidPackageUnparser.d.ts +4 -0
- package/build/androidPackageUnparser.js +90 -0
- package/build/androidPackageUnparser.test.js +26 -0
- package/build/arbitrarilySlicedAsyncInterable.d.ts +3 -1
- package/build/arbitrarilySlicedAsyncInterable.js +3 -3
- package/build/arbitraryFileSystemEntry.js +1 -1
- package/build/arbitraryZip.d.ts +1 -1
- package/build/arbitraryZip.js +13 -19
- package/build/arbitraryZipPermissions.d.ts +1 -8
- package/build/arbitraryZipPermissions.js +1 -16
- package/build/arbitraryZipStream.d.ts +1 -1
- package/build/arbitraryZipStream.js +3 -3
- package/build/arrayParser.d.ts +1 -1
- package/build/arrayParser.js +2 -2
- package/build/arrayParser.test.js +4 -4
- package/build/arrayUnparser.d.ts +2 -0
- package/build/arrayUnparser.js +8 -0
- package/build/backsmali.d.ts +1 -0
- package/build/backsmali.js +22 -0
- package/build/bsonParser.js +6 -2
- package/build/bsonParser.test.js +2 -2
- package/build/{parserInvariant.d.ts → customInvariant.d.ts} +1 -1
- package/build/{parserInvariant.js → customInvariant.js} +1 -1
- package/build/dalvikBytecodeParser/formatParsers.d.ts +97 -0
- package/build/dalvikBytecodeParser/formatParsers.js +169 -0
- package/build/dalvikBytecodeParser.d.ts +107 -0
- package/build/dalvikBytecodeParser.js +836 -0
- package/build/dalvikExecutable.d.ts +158 -0
- package/build/dalvikExecutable.js +20 -0
- package/build/dalvikExecutableParser/stringSyntaxParser.d.ts +4 -0
- package/build/dalvikExecutableParser/stringSyntaxParser.js +76 -0
- package/build/dalvikExecutableParser/typeParsers.d.ts +10 -0
- package/build/dalvikExecutableParser/typeParsers.js +34 -0
- package/build/dalvikExecutableParser/typedNumbers.d.ts +90 -0
- package/build/dalvikExecutableParser/typedNumbers.js +19 -0
- package/build/dalvikExecutableParser.d.ts +5 -0
- package/build/dalvikExecutableParser.js +1439 -0
- package/build/dalvikExecutableParser.test.js +70 -0
- package/build/dalvikExecutableParserAgainstSmaliParser.test.js +298 -0
- package/build/debugLogInputParser.d.ts +4 -0
- package/build/debugLogInputParser.js +16 -0
- package/build/debugLogParser.d.ts +1 -1
- package/build/debugLogParser.js +15 -4
- package/build/disjunctionParser.d.ts +2 -1
- package/build/disjunctionParser.js +4 -2
- package/build/elementParser.d.ts +2 -2
- package/build/elementParser.js +1 -1
- package/build/elementTerminatedArrayParser.d.ts +3 -0
- package/build/elementTerminatedArrayParser.js +18 -0
- package/build/elementTerminatedArrayParser.test.js +52 -0
- package/build/elementTerminatedSequenceArrayParser.d.ts +3 -0
- package/build/elementTerminatedSequenceArrayParser.js +32 -0
- package/build/elementTerminatedSequenceArrayParser.test.js +34 -0
- package/build/elementTerminatedSequenceParser.d.ts +3 -0
- package/build/elementTerminatedSequenceParser.js +27 -0
- package/build/elementTerminatedSequenceParser.test.js +34 -0
- package/build/endOfInputParser.d.ts +2 -2
- package/build/exactElementParser.d.ts +1 -1
- package/build/exactElementParser.js +10 -5
- package/build/exactSequenceParser.d.ts +2 -1
- package/build/exactSequenceParser.js +12 -2
- package/build/fetchCid.d.ts +1 -0
- package/build/fetchCid.js +107 -0
- package/build/fixedLengthSequenceParser.d.ts +1 -0
- package/build/fixedLengthSequenceParser.js +18 -1
- package/build/fixedLengthSequenceParser.test.js +41 -0
- package/build/hasExecutable.d.ts +1 -0
- package/build/hasExecutable.js +8 -0
- package/build/highResolutionTimer.d.ts +16 -0
- package/build/highResolutionTimer.js +42 -0
- package/build/index.d.ts +5 -2
- package/build/index.js +3 -0
- package/build/inputReader.d.ts +14 -3
- package/build/inputReader.js +43 -6
- package/build/inputReader.test.js +172 -7
- package/build/inputReaderState.d.ts +10 -0
- package/build/inputReaderState.js +16 -0
- package/build/inspect.d.ts +1 -0
- package/build/inspect.js +7 -0
- package/build/javaKeyStoreParser.d.ts +2 -0
- package/build/javaKeyStoreParser.js +67 -0
- package/build/javaKeyStoreParser.test.d.ts +1 -0
- package/build/javaKeyStoreParser.test.js +16 -0
- package/build/jsonParser.d.ts +2 -0
- package/build/jsonParser.js +13 -15
- package/build/jsonParser.test.js +2 -2
- package/build/leb128Parser.d.ts +7 -0
- package/build/leb128Parser.js +82 -0
- package/build/leb128Parser.test.d.ts +1 -0
- package/build/leb128Parser.test.js +107 -0
- package/build/listParser.d.ts +1 -1
- package/build/listParser.js +5 -5
- package/build/lookaheadParser.d.ts +2 -0
- package/build/lookaheadParser.js +14 -0
- package/build/{negativeLookahead.d.ts → negativeLookaheadParser.d.ts} +1 -1
- package/build/negativeLookaheadParser.js +24 -0
- package/build/negativeLookaheadParser.test.d.ts +1 -0
- package/build/negativeLookaheadParser.test.js +30 -0
- package/build/nonEmptyArrayParser.d.ts +2 -0
- package/build/nonEmptyArrayParser.js +32 -0
- package/build/nonEmptyArrayParser.test.d.ts +1 -0
- package/build/nonEmptyArrayParser.test.js +16 -0
- package/build/optionalParser.d.ts +1 -1
- package/build/optionalParser.js +2 -2
- package/build/parser.d.ts +13 -4
- package/build/parser.js +67 -32
- package/build/parser.test.js +94 -27
- package/build/parserAccessorParser.d.ts +1 -1
- package/build/parserAccessorParser.js +9 -1
- package/build/parserConsumedSequenceParser.d.ts +2 -0
- package/build/parserConsumedSequenceParser.js +22 -0
- package/build/parserContext.d.ts +20 -6
- package/build/parserContext.js +70 -40
- package/build/parserContext.test.js +34 -7
- package/build/parserCreatorCompose.d.ts +4 -3
- package/build/parserCreatorCompose.js +9 -3
- package/build/parserError.d.ts +6 -0
- package/build/parserError.js +6 -6
- package/build/parserImplementationInvariant.d.ts +1 -1
- package/build/parserImplementationInvariant.js +2 -2
- package/build/parserInputCompanion.d.ts +35 -0
- package/build/parserInputCompanion.js +68 -0
- package/build/promiseCompose.d.ts +1 -1
- package/build/promiseCompose.js +12 -1
- package/build/promiseSettled.d.ts +1 -0
- package/build/promiseSettled.js +4 -0
- package/build/quantifierParser.d.ts +2 -0
- package/build/quantifierParser.js +17 -0
- package/build/separatedArrayParser.d.ts +2 -0
- package/build/separatedArrayParser.js +39 -0
- package/build/separatedArrayParser.test.d.ts +1 -0
- package/build/separatedArrayParser.test.js +21 -0
- package/build/sequenceBuffer.d.ts +13 -3
- package/build/sequenceBuffer.js +60 -8
- package/build/sequenceBuffer.test.js +59 -2
- package/build/sequenceTerminatedSequenceParser.d.ts +5 -0
- package/build/sequenceTerminatedSequenceParser.js +32 -0
- package/build/sequenceTerminatedSequenceParser.test.d.ts +1 -0
- package/build/sequenceTerminatedSequenceParser.test.js +37 -0
- package/build/sequenceUnparser.d.ts +2 -0
- package/build/sequenceUnparser.js +6 -0
- package/build/skipParser.d.ts +1 -1
- package/build/skipParser.js +4 -2
- package/build/skipToParser.d.ts +2 -0
- package/build/skipToParser.js +11 -0
- package/build/sliceBoundedParser.d.ts +2 -2
- package/build/sliceBoundedParser.js +8 -3
- package/build/sliceBoundedParser.test.js +37 -3
- package/build/smali.d.ts +1 -0
- package/build/smali.js +17 -0
- package/build/smaliParser.d.ts +12 -0
- package/build/smaliParser.js +656 -0
- package/build/smaliParser.test.d.ts +1 -0
- package/build/smaliParser.test.js +115 -0
- package/build/terminatedArrayParser.d.ts +4 -2
- package/build/terminatedArrayParser.js +82 -5
- package/build/terminatedArrayParser.test.d.ts +1 -0
- package/build/terminatedArrayParser.test.js +131 -0
- package/build/toAsyncIterable.d.ts +1 -0
- package/build/toAsyncIterable.js +7 -0
- package/build/toAsyncIterator.d.ts +1 -0
- package/build/toAsyncIterator.js +33 -0
- package/build/tupleParser.d.ts +4 -0
- package/build/tupleParser.js +1 -5
- package/build/uint8Array.d.ts +1 -0
- package/build/uint8Array.js +7 -0
- package/build/unionParser.d.ts +2 -1
- package/build/unionParser.js +27 -12
- package/build/unionParser.test.d.ts +1 -0
- package/build/unionParser.test.js +60 -0
- package/build/unparser.d.ts +8 -0
- package/build/unparser.js +104 -0
- package/build/unparser.test.d.ts +1 -0
- package/build/unparser.test.js +150 -0
- package/build/unparserContext.d.ts +31 -0
- package/build/unparserContext.js +74 -0
- package/build/unparserError.d.ts +9 -0
- package/build/unparserError.js +9 -0
- package/build/unparserImplementationInvariant.d.ts +2 -0
- package/build/unparserImplementationInvariant.js +5 -0
- package/build/unparserOutputCompanion.d.ts +15 -0
- package/build/unparserOutputCompanion.js +13 -0
- package/build/zip.d.ts +9 -17
- package/build/zipParser.d.ts +20 -12
- package/build/zipParser.js +83 -71
- package/build/zipParser.test.js +2 -7
- package/build/zipUnparser.d.ts +8 -0
- package/build/zipUnparser.js +200 -0
- package/build/zipUnparser.test.d.ts +1 -0
- package/build/zipUnparser.test.js +80 -0
- package/package.json +26 -8
- package/src/allSettledStream.test.ts +40 -0
- package/src/allSettledStream.ts +47 -15
- package/src/androidPackage.ts +48 -0
- package/src/{apkParser.test.ts → androidPackageParser.test.ts} +7 -8
- package/src/androidPackageParser.test.ts.md +271 -0
- package/src/androidPackageParser.test.ts.snap +0 -0
- package/src/androidPackageParser.ts +440 -0
- package/src/androidPackageUnparser.test.ts +36 -0
- package/src/androidPackageUnparser.ts +120 -0
- package/src/arbitrarilySlicedAsyncInterable.ts +7 -2
- package/src/arbitraryFileSystemEntry.ts +2 -4
- package/src/arbitraryZip.ts +20 -27
- package/src/arbitraryZipPermissions.ts +0 -25
- package/src/arbitraryZipStream.ts +4 -4
- package/src/arrayParser.test.ts +4 -4
- package/src/arrayParser.ts +3 -2
- package/src/arrayUnparser.ts +13 -0
- package/src/backsmali.ts +30 -0
- package/src/bsonParser.test.ts +2 -2
- package/src/bsonParser.ts +16 -5
- package/src/{parserInvariant.ts → customInvariant.ts} +2 -2
- package/src/dalvikBytecodeParser/formatParsers.ts +421 -0
- package/src/dalvikBytecodeParser.ts +2074 -0
- package/src/dalvikExecutable.ts +220 -0
- package/src/dalvikExecutableParser/stringSyntaxParser.ts +145 -0
- package/src/dalvikExecutableParser/typeParsers.ts +65 -0
- package/src/dalvikExecutableParser/typedNumbers.ts +57 -0
- package/src/dalvikExecutableParser.test.ts +89 -0
- package/src/dalvikExecutableParser.test.ts.md +634 -0
- package/src/dalvikExecutableParser.test.ts.snap +0 -0
- package/src/dalvikExecutableParser.ts +2768 -0
- package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +346 -0
- package/src/debugLogInputParser.ts +28 -0
- package/src/debugLogParser.ts +20 -4
- package/src/disjunctionParser.ts +10 -5
- package/src/elementParser.ts +3 -3
- package/src/elementTerminatedArrayParser.test.ts +99 -0
- package/src/elementTerminatedArrayParser.ts +31 -0
- package/src/elementTerminatedSequenceArrayParser.test.ts +54 -0
- package/src/elementTerminatedSequenceArrayParser.ts +52 -0
- package/src/elementTerminatedSequenceParser.test.ts +54 -0
- package/src/elementTerminatedSequenceParser.ts +43 -0
- package/src/endOfInputParser.ts +4 -4
- package/src/exactElementParser.ts +18 -12
- package/src/exactSequenceParser.ts +24 -3
- package/src/fetchCid.ts +125 -0
- package/src/fixedLengthSequenceParser.test.ts +77 -0
- package/src/fixedLengthSequenceParser.ts +28 -1
- package/src/hasExecutable.ts +11 -0
- package/src/highResolutionTimer.ts +49 -0
- package/src/index.ts +15 -2
- package/src/inputReader.test.ts +216 -7
- package/src/inputReader.ts +80 -5
- package/src/inputReaderState.ts +33 -0
- package/src/inspect.ts +9 -0
- package/src/javaKeyStore.ts +0 -0
- package/src/javaKeyStoreParser.test.ts +22 -0
- package/src/javaKeyStoreParser.test.ts.md +103 -0
- package/src/javaKeyStoreParser.test.ts.snap +0 -0
- package/src/javaKeyStoreParser.ts +136 -0
- package/src/jsonParser.test.ts +2 -2
- package/src/jsonParser.ts +23 -34
- package/src/leb128Parser.test.ts +171 -0
- package/src/leb128Parser.ts +125 -0
- package/src/listParser.ts +6 -6
- package/src/lookaheadParser.ts +19 -0
- package/src/negativeLookaheadParser.test.ts +53 -0
- package/src/negativeLookaheadParser.ts +36 -0
- package/src/nonEmptyArrayParser.test.ts +20 -0
- package/src/nonEmptyArrayParser.ts +44 -0
- package/src/optionalParser.ts +4 -3
- package/src/parser.test.ts +148 -27
- package/src/parser.test.ts.md +21 -21
- package/src/parser.test.ts.snap +0 -0
- package/src/parser.ts +153 -49
- package/src/parserAccessorParser.ts +12 -2
- package/src/parserConsumedSequenceParser.ts +29 -0
- package/src/parserContext.test.ts +38 -7
- package/src/parserContext.ts +127 -51
- package/src/parserCreatorCompose.ts +25 -7
- package/src/parserError.ts +9 -6
- package/src/parserImplementationInvariant.ts +2 -2
- package/src/parserInputCompanion.ts +102 -0
- package/src/promiseCompose.ts +17 -3
- package/src/promiseSettled.ts +6 -0
- package/src/quantifierParser.ts +25 -0
- package/src/separatedArrayParser.test.ts +34 -0
- package/src/separatedArrayParser.ts +55 -0
- package/src/sequenceBuffer.test.ts +72 -2
- package/src/sequenceBuffer.ts +93 -7
- package/src/sequenceTerminatedSequenceParser.test.ts +60 -0
- package/src/sequenceTerminatedSequenceParser.ts +62 -0
- package/src/sequenceUnparser.ts +9 -0
- package/src/skipParser.ts +7 -5
- package/src/skipToParser.ts +16 -0
- package/src/sliceBoundedParser.test.ts +45 -3
- package/src/sliceBoundedParser.ts +21 -3
- package/src/smali.ts +24 -0
- package/src/smaliParser.test.ts +132 -0
- package/src/smaliParser.test.ts.md +2320 -0
- package/src/smaliParser.test.ts.snap +0 -0
- package/src/smaliParser.ts +1166 -0
- package/src/terminatedArrayParser.test.ts +258 -0
- package/src/terminatedArrayParser.ts +111 -6
- package/src/toAsyncIterable.ts +7 -0
- package/src/toAsyncIterator.ts +48 -0
- package/src/tupleParser.ts +8 -5
- package/src/uint8Array.ts +10 -0
- package/src/unionParser.test.ts +79 -0
- package/src/unionParser.ts +44 -16
- package/src/unparser.test.ts +221 -0
- package/src/unparser.ts +209 -0
- package/src/unparserContext.ts +127 -0
- package/src/unparserError.ts +12 -0
- package/src/unparserImplementationInvariant.ts +6 -0
- package/src/unparserOutputCompanion.ts +24 -0
- package/src/zip.ts +10 -22
- package/src/zipParser.test.ts +2 -8
- package/src/zipParser.ts +223 -146
- package/src/zipUnparser.test.ts +119 -0
- package/src/zipUnparser.ts +300 -0
- package/build/apk.d.ts +0 -13
- package/build/apkParser.d.ts +0 -3
- package/build/apkParser.js +0 -135
- package/build/arbitraryDosDate.d.ts +0 -2
- package/build/arbitraryDosDate.js +0 -8
- package/build/arbitraryZipEntry.d.ts +0 -3
- package/build/arbitraryZipEntry.js +0 -26
- package/build/createDisjunctionParser.d.ts +0 -2
- package/build/createDisjunctionParser.js +0 -47
- package/build/createExactParser.d.ts +0 -2
- package/build/createExactParser.js +0 -12
- package/build/createSequentialUnionParser.d.ts +0 -2
- package/build/createSequentialUnionParser.js +0 -69
- package/build/fixedLengthChunkParser.d.ts +0 -2
- package/build/fixedLengthChunkParser.js +0 -12
- package/build/fixedLengthParser.d.ts +0 -2
- package/build/fixedLengthParser.js +0 -12
- package/build/inputChunkBuffer.d.ts +0 -15
- package/build/inputChunkBuffer.js +0 -40
- package/build/inputChunkBuffer.test.js +0 -34
- package/build/inputCompanion.d.ts +0 -18
- package/build/inputCompanion.js +0 -28
- package/build/invariantDefined.d.ts +0 -1
- package/build/invariantDefined.js +0 -5
- package/build/invariantIdentity.d.ts +0 -3
- package/build/invariantIdentity.js +0 -5
- package/build/jsonParser2.d.ts +0 -3
- package/build/jsonParser2.js +0 -52
- package/build/jsonParser2.test.js +0 -22
- package/build/negativeLookahead.js +0 -20
- package/build/parserCompose.d.ts +0 -3
- package/build/parserCompose.js +0 -7
- package/build/parserImplementationInvariantInvariant.d.ts +0 -3
- package/build/parserImplementationInvariantInvariant.js +0 -15
- package/build/promiseFish.d.ts +0 -1
- package/build/promiseFish.js +0 -3
- package/build/sequenceParser.d.ts +0 -3
- package/build/sequenceParser.js +0 -10
- package/build/terminatedSequenceParser.d.ts +0 -2
- package/build/terminatedSequenceParser.js +0 -24
- package/build/zipEntry.d.ts +0 -28
- package/build/zipFile.d.ts +0 -32
- package/build/zipFileEntry.d.ts +0 -6
- package/src/apk.ts +0 -16
- package/src/apkParser.test.ts.md +0 -268
- package/src/apkParser.test.ts.snap +0 -0
- package/src/apkParser.ts +0 -327
- package/src/inputCompanion.ts +0 -43
- package/src/invariantDefined.ts +0 -6
- package/src/invariantIdentity.ts +0 -8
- package/src/negativeLookahead.ts +0 -26
- /package/build/{apk.js → androidPackage.js} +0 -0
- /package/build/{apkParser.test.d.ts → androidPackageParser.test.d.ts} +0 -0
- /package/build/{arbitraryDosPermissions.d.ts → androidPackageUnparser.test.d.ts} +0 -0
- /package/build/{arbitraryDosPermissions.js → dalvikExecutableParser.test.d.ts} +0 -0
- /package/build/{inputChunkBuffer.test.d.ts → dalvikExecutableParserAgainstSmaliParser.test.d.ts} +0 -0
- /package/build/{jsonParser2.test.d.ts → elementTerminatedArrayParser.test.d.ts} +0 -0
- /package/build/{parserParsingInvariant.d.ts → elementTerminatedSequenceArrayParser.test.d.ts} +0 -0
- /package/build/{parserParsingInvariant.js → elementTerminatedSequenceParser.test.d.ts} +0 -0
- /package/build/{zipEntry.js → fixedLengthSequenceParser.test.d.ts} +0 -0
- /package/build/{zipFile.js → javaKeyStore.d.ts} +0 -0
- /package/build/{zipFileEntry.js → javaKeyStore.js} +0 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import zlib from 'node:zlib';
|
|
2
|
+
import { Unparser } from "./unparser.js";
|
|
3
|
+
import { Zip, ZipEntry, ZipFileEntry } from "./zip.js";
|
|
4
|
+
import { Readable } from 'node:stream';
|
|
5
|
+
import { pipeline } from 'node:stream/promises';
|
|
6
|
+
import { ZipEndOfCentralDirectoryRecord, ZipLocalFileHeader } from './zipParser.js';
|
|
7
|
+
import { uint8ArrayAsyncIterableToUint8Array } from './uint8Array.js';
|
|
8
|
+
|
|
9
|
+
const uint16LEUnparser: Unparser<number, Uint8Array> = async function * (uint16LE) {
|
|
10
|
+
const buffer = Buffer.alloc(2);
|
|
11
|
+
buffer.writeUInt16LE(uint16LE);
|
|
12
|
+
yield buffer;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const uint32LEUnparser: Unparser<number, Uint8Array> = async function * (uint32LE) {
|
|
16
|
+
const buffer = Buffer.alloc(4);
|
|
17
|
+
buffer.writeUInt32LE(uint32LE);
|
|
18
|
+
yield buffer;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const uint16LEPrefixedUint8ArrayUnparser: Unparser<Uint8Array, Uint8Array> = async function * (uint8Array, unparserContext) {
|
|
22
|
+
yield * uint16LEUnparser(uint8Array.length, unparserContext);
|
|
23
|
+
yield uint8Array;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const uint16LEPrefixedStringUnparser: Unparser<string, Uint8Array> = async function * (string, unparserContext) {
|
|
27
|
+
yield * uint16LEPrefixedUint8ArrayUnparser(Buffer.from(string, 'utf8'), unparserContext);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const dosDateTimeUnparser: Unparser<Date, Uint8Array> = async function * (date, unparserContext) {
|
|
31
|
+
yield * uint16LEUnparser(
|
|
32
|
+
(
|
|
33
|
+
date.getUTCSeconds() / 2
|
|
34
|
+
| date.getUTCMinutes() << 5
|
|
35
|
+
| date.getUTCHours() << 11
|
|
36
|
+
),
|
|
37
|
+
unparserContext,
|
|
38
|
+
);
|
|
39
|
+
yield * uint16LEUnparser(
|
|
40
|
+
(
|
|
41
|
+
date.getUTCDate()
|
|
42
|
+
| (date.getUTCMonth() + 1) << 5
|
|
43
|
+
| (date.getUTCFullYear() - 1980) << 9
|
|
44
|
+
),
|
|
45
|
+
unparserContext,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const zipCompressionMethodUnparser: Unparser<'store' | 'deflate', Uint8Array> = async function * (compressionMethod, unparserContext) {
|
|
50
|
+
if (compressionMethod === 'store') {
|
|
51
|
+
yield * uint16LEUnparser(0, unparserContext);
|
|
52
|
+
} else {
|
|
53
|
+
yield * uint16LEUnparser(8, unparserContext);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const zipEndOfCentralDirectoryRecordUnparser: Unparser<ZipEndOfCentralDirectoryRecord, Uint8Array> = async function * (zipEndOfCentralDirectoryRecord, unparserContext) {
|
|
58
|
+
yield Buffer.from('504b0506', 'hex');
|
|
59
|
+
yield * uint16LEUnparser(zipEndOfCentralDirectoryRecord.numberOfThisDisk, unparserContext);
|
|
60
|
+
yield * uint16LEUnparser(zipEndOfCentralDirectoryRecord.numberOfTheDiskWithTheStartOfTheCentralDirectory, unparserContext);
|
|
61
|
+
yield * uint16LEUnparser(zipEndOfCentralDirectoryRecord.totalNumberOfEntriesInTheCentralDirectoryOnThisDisk, unparserContext);
|
|
62
|
+
yield * uint16LEUnparser(zipEndOfCentralDirectoryRecord.totalNumberOfEntriesInTheCentralDirectory, unparserContext);
|
|
63
|
+
yield * uint32LEUnparser(zipEndOfCentralDirectoryRecord.sizeOfTheCentralDirectory, unparserContext);
|
|
64
|
+
yield * uint32LEUnparser(zipEndOfCentralDirectoryRecord.offsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber, unparserContext);
|
|
65
|
+
|
|
66
|
+
yield * uint16LEPrefixedStringUnparser(zipEndOfCentralDirectoryRecord.zipFileComment, unparserContext);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const zipDataDescriptorUnparser: Unparser<{
|
|
70
|
+
crc32: number;
|
|
71
|
+
compressedSize: number;
|
|
72
|
+
uncompressedSize: number;
|
|
73
|
+
}, Uint8Array> = async function * ({
|
|
74
|
+
crc32,
|
|
75
|
+
compressedSize,
|
|
76
|
+
uncompressedSize,
|
|
77
|
+
}, unparserContext) {
|
|
78
|
+
yield Buffer.from('504b0708', 'hex');
|
|
79
|
+
yield * uint32LEUnparser(crc32, unparserContext);
|
|
80
|
+
yield * uint32LEUnparser(compressedSize, unparserContext);
|
|
81
|
+
yield * uint32LEUnparser(uncompressedSize, unparserContext);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const zipLocalFileHeaderUnparser: Unparser<ZipLocalFileHeader, Uint8Array> = async function * ({
|
|
85
|
+
versionNeededToExtract,
|
|
86
|
+
generalPurposeBitFlag,
|
|
87
|
+
compressionMethod,
|
|
88
|
+
lastModifiedFile,
|
|
89
|
+
crc32,
|
|
90
|
+
compressedSize,
|
|
91
|
+
uncompressedSize,
|
|
92
|
+
|
|
93
|
+
filePath,
|
|
94
|
+
extraField,
|
|
95
|
+
}, unparserContext) {
|
|
96
|
+
yield Buffer.from('504b0304', 'hex');
|
|
97
|
+
|
|
98
|
+
yield * uint16LEUnparser(versionNeededToExtract, unparserContext);
|
|
99
|
+
yield * uint16LEUnparser(generalPurposeBitFlag, unparserContext);
|
|
100
|
+
yield * zipCompressionMethodUnparser(compressionMethod, unparserContext);
|
|
101
|
+
yield * dosDateTimeUnparser(lastModifiedFile, unparserContext);
|
|
102
|
+
yield * uint32LEUnparser(crc32, unparserContext);
|
|
103
|
+
yield * uint32LEUnparser(compressedSize, unparserContext);
|
|
104
|
+
yield * uint32LEUnparser(uncompressedSize, unparserContext);
|
|
105
|
+
|
|
106
|
+
const filePathBuffer = Buffer.from(filePath, 'utf8');
|
|
107
|
+
|
|
108
|
+
yield * uint16LEUnparser(filePathBuffer.length, unparserContext);
|
|
109
|
+
yield * uint16LEUnparser(extraField.length, unparserContext);
|
|
110
|
+
yield filePathBuffer;
|
|
111
|
+
yield extraField;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const createZipUnparser = ({
|
|
115
|
+
dataDescriptor = false,
|
|
116
|
+
}: {
|
|
117
|
+
dataDescriptor?: boolean;
|
|
118
|
+
} = {}): Unparser<Zip, Uint8Array> => async function * (zip, unparserContext) {
|
|
119
|
+
const compressedContentByZipFileEntry = new Map<ZipFileEntry, undefined | Promise<Uint8Array>>(
|
|
120
|
+
zip.entries.flatMap(zipEntry => {
|
|
121
|
+
if (zipEntry.type !== 'file') {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (zipEntry.compression === 'store') {
|
|
126
|
+
return [[zipEntry, Promise.resolve(zipEntry.content)]];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const uncompressedContent = zipEntry.content;
|
|
130
|
+
|
|
131
|
+
const deflate = zlib.createDeflateRaw();
|
|
132
|
+
const input = Readable.from(Buffer.from(uncompressedContent));
|
|
133
|
+
|
|
134
|
+
const promise = Promise.all([
|
|
135
|
+
pipeline(input, deflate),
|
|
136
|
+
uint8ArrayAsyncIterableToUint8Array(deflate),
|
|
137
|
+
]);
|
|
138
|
+
|
|
139
|
+
return [[zipEntry, promise.then(([, compressedContent]) => compressedContent)]];
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const filePathByZipEntry = new Map<ZipEntry, string>(
|
|
144
|
+
zip.entries.map(zipEntry => [zipEntry, zipEntry.type === 'file' ? zipEntry.path : zipEntry.path + '/']),
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const localHeaderPositionByZipEntry = new Map<ZipEntry, number>();
|
|
148
|
+
|
|
149
|
+
for (const zipEntry of zip.entries) {
|
|
150
|
+
localHeaderPositionByZipEntry.set(zipEntry, unparserContext.position);
|
|
151
|
+
|
|
152
|
+
const filePath = filePathByZipEntry.get(zipEntry)!;
|
|
153
|
+
|
|
154
|
+
const zipLocalFileHeader: ZipLocalFileHeader = {
|
|
155
|
+
versionNeededToExtract: 20,
|
|
156
|
+
generalPurposeBitFlag: 0,
|
|
157
|
+
compressionMethod: 'store',
|
|
158
|
+
lastModifiedFile: zipEntry.date,
|
|
159
|
+
crc32: 0,
|
|
160
|
+
compressedSize: 0,
|
|
161
|
+
uncompressedSize: 0,
|
|
162
|
+
filePath,
|
|
163
|
+
extraField: Buffer.alloc(0),
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
let shouldWriteDataDescriptor = false;
|
|
167
|
+
|
|
168
|
+
if (zipEntry.type === 'file') {
|
|
169
|
+
const compressedContent = await compressedContentByZipFileEntry.get(zipEntry)!;
|
|
170
|
+
|
|
171
|
+
zipLocalFileHeader.compressionMethod = zipEntry.compression;
|
|
172
|
+
zipLocalFileHeader.crc32 = 0; // TODO
|
|
173
|
+
zipLocalFileHeader.compressedSize = compressedContent.length;
|
|
174
|
+
zipLocalFileHeader.uncompressedSize = zipEntry.content.length;
|
|
175
|
+
|
|
176
|
+
if (dataDescriptor) {
|
|
177
|
+
shouldWriteDataDescriptor = true;
|
|
178
|
+
|
|
179
|
+
zipLocalFileHeader.generalPurposeBitFlag |= 0b0000_0000_0000_1000;
|
|
180
|
+
zipLocalFileHeader.crc32 = 0;
|
|
181
|
+
zipLocalFileHeader.compressedSize = 0;
|
|
182
|
+
zipLocalFileHeader.uncompressedSize = 0;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
yield * zipLocalFileHeaderUnparser(zipLocalFileHeader, unparserContext);
|
|
187
|
+
|
|
188
|
+
if (zipEntry.type === 'file') {
|
|
189
|
+
const compressedContent = await compressedContentByZipFileEntry.get(zipEntry)!;
|
|
190
|
+
|
|
191
|
+
yield compressedContent;
|
|
192
|
+
|
|
193
|
+
if (shouldWriteDataDescriptor) {
|
|
194
|
+
yield * zipDataDescriptorUnparser({
|
|
195
|
+
crc32: zipLocalFileHeader.crc32,
|
|
196
|
+
compressedSize: zipLocalFileHeader.compressedSize,
|
|
197
|
+
uncompressedSize: zipLocalFileHeader.uncompressedSize,
|
|
198
|
+
}, unparserContext);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const startOfCentralDirectoryPosition = unparserContext.position;
|
|
204
|
+
|
|
205
|
+
for (const zipEntry of zip.entries) {
|
|
206
|
+
yield Buffer.from('504b0102', 'hex');
|
|
207
|
+
|
|
208
|
+
if (zipEntry.hostSystem === 'unix') {
|
|
209
|
+
yield 0; // zip specification version
|
|
210
|
+
yield 3; // host system
|
|
211
|
+
} else {
|
|
212
|
+
yield 0;
|
|
213
|
+
yield 0;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
yield * uint16LEUnparser(0, unparserContext); // version needed to extract
|
|
217
|
+
yield * uint16LEUnparser(0, unparserContext); // general purpose bit flag
|
|
218
|
+
|
|
219
|
+
if (zipEntry.type === 'file') {
|
|
220
|
+
yield * zipCompressionMethodUnparser(zipEntry.compression, unparserContext);
|
|
221
|
+
} else {
|
|
222
|
+
yield * uint16LEUnparser(0, unparserContext);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
yield * dosDateTimeUnparser(zipEntry.date, unparserContext);
|
|
226
|
+
|
|
227
|
+
if (zipEntry.type === 'file') {
|
|
228
|
+
const compressedContent = await compressedContentByZipFileEntry.get(zipEntry)!;
|
|
229
|
+
|
|
230
|
+
yield * uint32LEUnparser(0, unparserContext); // crc32 // TODO
|
|
231
|
+
yield * uint32LEUnparser(compressedContent.length, unparserContext);
|
|
232
|
+
yield * uint32LEUnparser(zipEntry.content.length, unparserContext);
|
|
233
|
+
} else {
|
|
234
|
+
yield * uint32LEUnparser(0, unparserContext);
|
|
235
|
+
yield * uint32LEUnparser(0, unparserContext);
|
|
236
|
+
yield * uint32LEUnparser(0, unparserContext);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const filePath = filePathByZipEntry.get(zipEntry)!;
|
|
240
|
+
|
|
241
|
+
const filePathBuffer = Buffer.from(filePath, 'utf8');
|
|
242
|
+
yield * uint16LEUnparser(filePathBuffer.length, unparserContext);
|
|
243
|
+
const extraFieldBuffer = Buffer.alloc(0);
|
|
244
|
+
yield * uint16LEUnparser(extraFieldBuffer.length, unparserContext);
|
|
245
|
+
const fileCommentBuffer = Buffer.from(zipEntry.comment, 'utf8');
|
|
246
|
+
yield * uint16LEUnparser(fileCommentBuffer.length, unparserContext);
|
|
247
|
+
|
|
248
|
+
yield * uint16LEUnparser(0, unparserContext); // disk number start
|
|
249
|
+
yield * uint16LEUnparser(0, unparserContext); // internal file attributes
|
|
250
|
+
|
|
251
|
+
if (zipEntry.hostSystem === 'unix') {
|
|
252
|
+
yield * uint32LEUnparser(
|
|
253
|
+
(
|
|
254
|
+
0
|
|
255
|
+
| (
|
|
256
|
+
zipEntry.type === 'directory'
|
|
257
|
+
? (0b0100_0000_0000_0000 << 16)
|
|
258
|
+
: (0b1000_0000_0000_0000 << 16)
|
|
259
|
+
)
|
|
260
|
+
) >>> 0,
|
|
261
|
+
unparserContext,
|
|
262
|
+
);
|
|
263
|
+
} else {
|
|
264
|
+
yield * uint32LEUnparser(
|
|
265
|
+
(
|
|
266
|
+
0
|
|
267
|
+
| (
|
|
268
|
+
zipEntry.type === 'directory'
|
|
269
|
+
? 0b0001_0000
|
|
270
|
+
: 0
|
|
271
|
+
)
|
|
272
|
+
),
|
|
273
|
+
unparserContext,
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const localHeaderPosition = localHeaderPositionByZipEntry.get(zipEntry)!;
|
|
278
|
+
|
|
279
|
+
yield * uint32LEUnparser(localHeaderPosition, unparserContext);
|
|
280
|
+
|
|
281
|
+
yield filePathBuffer;
|
|
282
|
+
yield extraFieldBuffer;
|
|
283
|
+
yield fileCommentBuffer;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const endOfCentralDirectoryPosition = unparserContext.position;
|
|
287
|
+
const sizeOfTheCentralDirectory = endOfCentralDirectoryPosition - startOfCentralDirectoryPosition;
|
|
288
|
+
|
|
289
|
+
yield * zipEndOfCentralDirectoryRecordUnparser({
|
|
290
|
+
numberOfThisDisk: 0,
|
|
291
|
+
numberOfTheDiskWithTheStartOfTheCentralDirectory: 0,
|
|
292
|
+
totalNumberOfEntriesInTheCentralDirectoryOnThisDisk: zip.entries.length,
|
|
293
|
+
totalNumberOfEntriesInTheCentralDirectory: zip.entries.length,
|
|
294
|
+
sizeOfTheCentralDirectory,
|
|
295
|
+
offsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber: startOfCentralDirectoryPosition,
|
|
296
|
+
zipFileComment: zip.comment,
|
|
297
|
+
}, unparserContext);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export const zipUnparser = createZipUnparser();
|
package/build/apk.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Zip } from './zip.js';
|
|
2
|
-
export type ApkSigningBlockPair = {
|
|
3
|
-
id: number;
|
|
4
|
-
value: Uint8Array;
|
|
5
|
-
};
|
|
6
|
-
export type ApkSigningBlock = {
|
|
7
|
-
zeroPaddingLength?: number;
|
|
8
|
-
signatureV2?: unknown;
|
|
9
|
-
pairs: ApkSigningBlockPair[];
|
|
10
|
-
};
|
|
11
|
-
export type Apk = Zip & {
|
|
12
|
-
signingBlock?: ApkSigningBlock;
|
|
13
|
-
};
|
package/build/apkParser.d.ts
DELETED
package/build/apkParser.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { createArrayParser } from "./arrayParser.js";
|
|
2
|
-
import { createOptionalParser } from "./optionalParser.js";
|
|
3
|
-
import { setParserName } from "./parser.js";
|
|
4
|
-
import { promiseCompose } from "./promiseCompose.js";
|
|
5
|
-
import { createTupleParser } from "./tupleParser.js";
|
|
6
|
-
import { zip64EndOfCentralDirectoryLocatorParser, zip64EndOfCentralDirectoryRecordParser, zipArchiveDecryptionHeaderParser, zipArchiveExtraDataRecordParser, zipCentralDirectoryHeaderParser, zipEndOfCentralDirectoryRecordParser, zipFromZipSegments, zipLocalFileParser } from "./zipParser.js";
|
|
7
|
-
import { createFixedLengthSequenceParser } from "./fixedLengthSequenceParser.js";
|
|
8
|
-
import { parserCreatorCompose } from "./parserCreatorCompose.js";
|
|
9
|
-
import { createExactSequenceParser } from "./exactSequenceParser.js";
|
|
10
|
-
import { createSliceBoundedParser } from "./sliceBoundedParser.js";
|
|
11
|
-
import { createDisjunctionParser } from "./disjunctionParser.js";
|
|
12
|
-
import invariant from "invariant";
|
|
13
|
-
import { createExactElementParser } from "./exactElementParser.js";
|
|
14
|
-
// https://source.android.com/docs/security/features/apksigning/v2#apk-signing-block
|
|
15
|
-
const uint32LEParser = promiseCompose(createFixedLengthSequenceParser(4), array => Buffer.from(array).readUInt32LE());
|
|
16
|
-
setParserName(uint32LEParser, 'uint32LEParser');
|
|
17
|
-
const uint64LEParser = promiseCompose(createFixedLengthSequenceParser(8), array => Buffer.from(array).readBigUInt64LE());
|
|
18
|
-
setParserName(uint64LEParser, 'uint64LEParser');
|
|
19
|
-
const createUint32LengthPrefixedParser = (createInnerParser) => parserCreatorCompose(() => uint32LEParser, length => createInnerParser(length))();
|
|
20
|
-
const createUint64LengthPrefixedParser = (createInnerParser) => parserCreatorCompose(() => uint64LEParser, length => createInnerParser(length))();
|
|
21
|
-
const createUint32LengthPrefixedSliceBoundedParser = (innerParser) => createUint32LengthPrefixedParser(length => createSliceBoundedParser(innerParser, length));
|
|
22
|
-
const createUint32LengthPrefixedSliceBoundedArrayParser = (innerParser) => createUint32LengthPrefixedSliceBoundedParser(createArrayParser(innerParser));
|
|
23
|
-
const createApkSigningBlockZeroPaddingPairInnerParser = (length) => promiseCompose(createTupleParser([
|
|
24
|
-
createExactSequenceParser(Buffer.from('77657242', 'hex')),
|
|
25
|
-
createFixedLengthSequenceParser(length - 4),
|
|
26
|
-
]), ([_magic, zeroPadding]) => ({ type: 'zeroPadding', length: zeroPadding.length }));
|
|
27
|
-
const createApkSigningBlockSignatureV2PairInnerParser = (length) => {
|
|
28
|
-
const apkSigningBlockSignatureV2PairInnerParser = promiseCompose(createTupleParser([
|
|
29
|
-
createExactSequenceParser(Buffer.from('1a870971', 'hex')),
|
|
30
|
-
apkSignatureSchemeV2SignersParser,
|
|
31
|
-
]), ([_magic, signers = []]) => ({ type: 'signatureV2', signers }));
|
|
32
|
-
return setParserName(apkSigningBlockSignatureV2PairInnerParser, 'apkSigningBlockSignatureV2PairInnerParser');
|
|
33
|
-
};
|
|
34
|
-
const createApkSigningBlockGenericPairInnerParser = (length) => promiseCompose(createTupleParser([
|
|
35
|
-
uint32LEParser,
|
|
36
|
-
createFixedLengthSequenceParser(length - 4),
|
|
37
|
-
]), ([id, value]) => ({ type: 'generic', pair: { id, value } }));
|
|
38
|
-
const createApkSigningBlockPairInnerParser = (length) => createDisjunctionParser([
|
|
39
|
-
createApkSigningBlockZeroPaddingPairInnerParser(length),
|
|
40
|
-
createApkSigningBlockSignatureV2PairInnerParser(length),
|
|
41
|
-
createApkSigningBlockGenericPairInnerParser(length),
|
|
42
|
-
]);
|
|
43
|
-
const apkSigningBlockPairParser = createUint64LengthPrefixedParser(length => createApkSigningBlockPairInnerParser(Number(length)));
|
|
44
|
-
setParserName(apkSigningBlockPairParser, 'apkSigningBlockPairParser');
|
|
45
|
-
const apkSigningBlockPairsParser = createArrayParser(apkSigningBlockPairParser);
|
|
46
|
-
const apkSigningBlockParser = createUint64LengthPrefixedParser(sizeOfBlock => promiseCompose(createTupleParser([
|
|
47
|
-
apkSigningBlockPairsParser,
|
|
48
|
-
uint64LEParser,
|
|
49
|
-
createExactSequenceParser(Buffer.from('APK Sig Block 42', 'utf8')),
|
|
50
|
-
]), async ([pairs, sizeOfBlockRepeated, _magic]) => {
|
|
51
|
-
invariant(sizeOfBlock === sizeOfBlockRepeated, 'Size of block mismatch: %s !== %s.', sizeOfBlock, sizeOfBlockRepeated);
|
|
52
|
-
const zeroPaddingPair = pairs.find(pair => pair.type === 'zeroPadding');
|
|
53
|
-
const signatureV2Pair = pairs.find(pair => pair.type === 'signatureV2');
|
|
54
|
-
const genericPairs = (pairs
|
|
55
|
-
.filter(pair => (pair !== zeroPaddingPair
|
|
56
|
-
&& pair !== signatureV2Pair))
|
|
57
|
-
.map(pair => {
|
|
58
|
-
invariant(pair.type === 'generic', 'Expected generic pair, got %s.', pair.type);
|
|
59
|
-
return pair.pair;
|
|
60
|
-
}));
|
|
61
|
-
return {
|
|
62
|
-
zeroPaddingLength: zeroPaddingPair?.length,
|
|
63
|
-
signatureV2: signatureV2Pair?.signers,
|
|
64
|
-
pairs: genericPairs,
|
|
65
|
-
};
|
|
66
|
-
}));
|
|
67
|
-
const apkSignatureSchemeV2DigestParser = createUint32LengthPrefixedParser(pairLength => promiseCompose(createTupleParser([
|
|
68
|
-
uint32LEParser,
|
|
69
|
-
createUint32LengthPrefixedParser(digestLength => createFixedLengthSequenceParser(digestLength)),
|
|
70
|
-
]), ([signatureAlgorithmId, digest]) => ({ signatureAlgorithmId, digest })));
|
|
71
|
-
const apkSignatureSchemeV2DigestsParser = createUint32LengthPrefixedSliceBoundedArrayParser(apkSignatureSchemeV2DigestParser);
|
|
72
|
-
const apkSignatureSchemeV2CertificateParser = createUint32LengthPrefixedParser(certificateLength => createFixedLengthSequenceParser(certificateLength));
|
|
73
|
-
const apkSignatureSchemeV2CertificatesParser = createUint32LengthPrefixedSliceBoundedArrayParser(apkSignatureSchemeV2CertificateParser);
|
|
74
|
-
const apkSignatureSchemeV2AdditionalAttributeParser = createUint32LengthPrefixedParser(pairLength => promiseCompose(createTupleParser([
|
|
75
|
-
uint32LEParser,
|
|
76
|
-
createFixedLengthSequenceParser(pairLength - 4),
|
|
77
|
-
]), ([id, value]) => ({ id, value })));
|
|
78
|
-
const apkSignatureSchemeV2AdditionalAttributesParser = createUint32LengthPrefixedSliceBoundedArrayParser(apkSignatureSchemeV2AdditionalAttributeParser);
|
|
79
|
-
const apkSignatureSchemeV2SignedDataParser = createUint32LengthPrefixedSliceBoundedParser(promiseCompose(createTupleParser([
|
|
80
|
-
apkSignatureSchemeV2DigestsParser,
|
|
81
|
-
apkSignatureSchemeV2CertificatesParser,
|
|
82
|
-
createOptionalParser(apkSignatureSchemeV2AdditionalAttributesParser),
|
|
83
|
-
createArrayParser(createExactElementParser(0)),
|
|
84
|
-
]), ([digests = [], certificates = [], additionalAttributes = [],]) => ({
|
|
85
|
-
digests,
|
|
86
|
-
certificates,
|
|
87
|
-
additionalAttributes,
|
|
88
|
-
})));
|
|
89
|
-
setParserName(apkSignatureSchemeV2SignedDataParser, 'apkSignatureSchemeV2SignedDataParser');
|
|
90
|
-
const apkSignatureSchemeV2SignatureParser = createUint32LengthPrefixedParser(signatureLength => promiseCompose(createTupleParser([
|
|
91
|
-
uint32LEParser,
|
|
92
|
-
createUint32LengthPrefixedParser(signatureLength => createFixedLengthSequenceParser(signatureLength)),
|
|
93
|
-
]), ([signatureAlgorithmId, signature,]) => ({
|
|
94
|
-
signatureAlgorithmId,
|
|
95
|
-
signature,
|
|
96
|
-
})));
|
|
97
|
-
const apkSignatureSchemeV2SignaturesParser = createUint32LengthPrefixedSliceBoundedArrayParser(apkSignatureSchemeV2SignatureParser);
|
|
98
|
-
setParserName(apkSignatureSchemeV2SignaturesParser, 'apkSignatureSchemeV2SignaturesParser');
|
|
99
|
-
const apkSignatureSchemeV2PublicKeyParser = createUint32LengthPrefixedParser(publicKeyLength => createFixedLengthSequenceParser(publicKeyLength));
|
|
100
|
-
setParserName(apkSignatureSchemeV2PublicKeyParser, 'apkSignatureSchemeV2PublicKeyParser');
|
|
101
|
-
const apkSignatureSchemeV2SignerParser = createUint32LengthPrefixedSliceBoundedParser(promiseCompose(createTupleParser([
|
|
102
|
-
apkSignatureSchemeV2SignedDataParser,
|
|
103
|
-
apkSignatureSchemeV2SignaturesParser,
|
|
104
|
-
apkSignatureSchemeV2PublicKeyParser,
|
|
105
|
-
]), ([signedData, signatures = [], publicKey]) => ({
|
|
106
|
-
signedData,
|
|
107
|
-
signatures,
|
|
108
|
-
publicKey,
|
|
109
|
-
})));
|
|
110
|
-
setParserName(apkSignatureSchemeV2SignerParser, 'apkSignatureSchemeV2SignerParser');
|
|
111
|
-
const apkSignatureSchemeV2SignersParser = createUint32LengthPrefixedSliceBoundedArrayParser(apkSignatureSchemeV2SignerParser);
|
|
112
|
-
setParserName(apkSignatureSchemeV2SignersParser, 'apkSignatureSchemeV2SignersParser');
|
|
113
|
-
const apkParser_ = createTupleParser([
|
|
114
|
-
createArrayParser(zipLocalFileParser),
|
|
115
|
-
createOptionalParser(zipArchiveDecryptionHeaderParser),
|
|
116
|
-
createOptionalParser(zipArchiveExtraDataRecordParser),
|
|
117
|
-
createOptionalParser(apkSigningBlockParser),
|
|
118
|
-
createArrayParser(zipCentralDirectoryHeaderParser),
|
|
119
|
-
createOptionalParser(zip64EndOfCentralDirectoryRecordParser),
|
|
120
|
-
createOptionalParser(zip64EndOfCentralDirectoryLocatorParser),
|
|
121
|
-
zipEndOfCentralDirectoryRecordParser,
|
|
122
|
-
]);
|
|
123
|
-
setParserName(apkParser_, 'apkParser_');
|
|
124
|
-
export const apkParser = promiseCompose(apkParser_, async ([zipLocalFiles, zipArchiveDecryptionHeader, zipArchiveExtraDataRecord, apkSigningBlock, zipCentralDirectoryHeaders, zip64EndOfCentralDirectoryRecord, zip64EndOfCentralDirectoryLocator, zipEndOfCentralDirectoryRecord,]) => {
|
|
125
|
-
const zip = await zipFromZipSegments({
|
|
126
|
-
zipLocalFiles,
|
|
127
|
-
zipCentralDirectoryHeaders,
|
|
128
|
-
zipEndOfCentralDirectoryRecord,
|
|
129
|
-
});
|
|
130
|
-
return {
|
|
131
|
-
...zip,
|
|
132
|
-
signingBlock: apkSigningBlock,
|
|
133
|
-
};
|
|
134
|
-
});
|
|
135
|
-
setParserName(apkParser, 'apkParser');
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as fc from 'fast-check';
|
|
2
|
-
export const arbitraryZipEntry = fc.letrec((tie) => ({
|
|
3
|
-
entry: fc.oneof(fc.record({
|
|
4
|
-
type: fc.constant('file'),
|
|
5
|
-
name: fc.string({ minLength: 1 }),
|
|
6
|
-
date: fc.date(),
|
|
7
|
-
comment: fc.uint8Array(),
|
|
8
|
-
unixPermissions: fc.integer(),
|
|
9
|
-
dosPermissions: fc.integer(),
|
|
10
|
-
compression: fc.oneof(fc.record({
|
|
11
|
-
type: fc.constant('store'),
|
|
12
|
-
}), fc.record({
|
|
13
|
-
type: fc.constant('deflate'),
|
|
14
|
-
level: fc.nat({ max: 9 }),
|
|
15
|
-
})),
|
|
16
|
-
content: fc.uint8Array(),
|
|
17
|
-
}), fc.record({
|
|
18
|
-
type: fc.constant('directory'),
|
|
19
|
-
name: fc.string({ minLength: 1 }),
|
|
20
|
-
date: fc.date(),
|
|
21
|
-
comment: fc.uint8Array(),
|
|
22
|
-
unixPermissions: fc.integer(),
|
|
23
|
-
dosPermissions: fc.integer(),
|
|
24
|
-
entries: fc.array(tie('entry')),
|
|
25
|
-
})),
|
|
26
|
-
})).entry;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ParserParsingFailedError } from './parserError.js';
|
|
2
|
-
import { parserImplementationInvariant } from './parserImplementationInvariant.js';
|
|
3
|
-
import { parserParsingInvariant } from './parserParsingInvariant.js';
|
|
4
|
-
function getParserName(parser) {
|
|
5
|
-
return parser.name || 'anonymousDisjunctionChild';
|
|
6
|
-
}
|
|
7
|
-
export const createDisjunctionParser = (childParsers) => {
|
|
8
|
-
parserImplementationInvariant(childParsers.length > 0, 'Disjunction parser must have at least one child parser.');
|
|
9
|
-
const disjunctionParser = async (parserContext) => {
|
|
10
|
-
const parserParsingFailedErrors = [];
|
|
11
|
-
for (const childParser of childParsers) {
|
|
12
|
-
const childParserContext = parserContext.lookahead(getParserName(childParser));
|
|
13
|
-
const [childParserResult] = await Promise.allSettled([childParser(childParserContext)]);
|
|
14
|
-
if (childParserResult.status === 'fulfilled') {
|
|
15
|
-
const successfulParserOutput = childParserResult.value;
|
|
16
|
-
childParserContext.unlookahead();
|
|
17
|
-
childParserContext.dispose();
|
|
18
|
-
return successfulParserOutput;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
const error = childParserResult.reason;
|
|
22
|
-
if (error instanceof ParserParsingFailedError) {
|
|
23
|
-
parserParsingFailedErrors.push(error);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
parserParsingInvariant(false, [
|
|
31
|
-
'No disjunction child parser succeeded.',
|
|
32
|
-
'Parsing errors, indented, separated by newlines:',
|
|
33
|
-
'%s',
|
|
34
|
-
'End of parsing errors.',
|
|
35
|
-
], parserParsingFailedErrors
|
|
36
|
-
.flatMap(error => error.stack?.split('\n'))
|
|
37
|
-
.map(line => ' ' + line)
|
|
38
|
-
.join('\n'));
|
|
39
|
-
};
|
|
40
|
-
const name = [
|
|
41
|
-
'(',
|
|
42
|
-
...childParsers.map(getParserName).join('|'),
|
|
43
|
-
')',
|
|
44
|
-
].join('');
|
|
45
|
-
Object.defineProperty(disjunctionParser, 'name', { value: name });
|
|
46
|
-
return disjunctionParser;
|
|
47
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { parserImplementationInvariant } from './parserImplementationInvariant.js';
|
|
2
|
-
export const createExactParser = (inputChunk) => {
|
|
3
|
-
parserImplementationInvariant(length > 0, 'Length must be positive.');
|
|
4
|
-
return async (parserContext) => {
|
|
5
|
-
const elements = [];
|
|
6
|
-
for (let i = 0; i < length; i++) {
|
|
7
|
-
const element = await parserContext.read(0);
|
|
8
|
-
elements.push(element);
|
|
9
|
-
}
|
|
10
|
-
return parserContext.from(elements);
|
|
11
|
-
};
|
|
12
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { ParserParsingFailedError } from './parserError.js';
|
|
2
|
-
import { parserImplementationInvariant } from './parserImplementationInvariant.js';
|
|
3
|
-
import { parserParsingInvariant } from './parserParsingInvariant.js';
|
|
4
|
-
function getParserName(parser) {
|
|
5
|
-
return parser.name || 'anonymousSequentialUnionChild';
|
|
6
|
-
}
|
|
7
|
-
export const createDisjunctionParser = (childParsers) => {
|
|
8
|
-
parserImplementationInvariant(childParsers.length > 0, 'SequentialUnion parser must have at least one child parser.');
|
|
9
|
-
const sequentialUnionParser = async (parserContext) => {
|
|
10
|
-
let runningChildParserContexts = [];
|
|
11
|
-
const childParserResults = (async function* () {
|
|
12
|
-
for (const childParser of childParsers) {
|
|
13
|
-
const childParserContext = parserContext.lookahead(getParserName(childParser));
|
|
14
|
-
runningChildParserContexts.push(childParserContext);
|
|
15
|
-
const [promiseSettledResult] = await Promise.allSettled([childParser(childParserContext)]);
|
|
16
|
-
yield {
|
|
17
|
-
...promiseSettledResult,
|
|
18
|
-
context: childParserContext,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
})();
|
|
22
|
-
const parserParsingFailedErrors = [];
|
|
23
|
-
const successfulParserOutputs = [];
|
|
24
|
-
const successfulParserContexts = [];
|
|
25
|
-
for await (const childParserResult of childParserResults) {
|
|
26
|
-
runningChildParserContexts = runningChildParserContexts.filter(runningChildParserContext => runningChildParserContext !== childParserResult.context);
|
|
27
|
-
if (childParserResult.status === 'fulfilled') {
|
|
28
|
-
successfulParserOutputs.push(childParserResult.value);
|
|
29
|
-
successfulParserContexts.push(childParserResult.context);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
const error = childParserResult.reason;
|
|
33
|
-
if (error instanceof ParserParsingFailedError) {
|
|
34
|
-
parserParsingFailedErrors.push(error);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
throw error;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
parserImplementationInvariant(successfulParserOutputs.length <= 1, [
|
|
42
|
-
'Multiple sequentialUnion child parsers succeeded.',
|
|
43
|
-
'Successful parser outputs, indented, separated by newlines:',
|
|
44
|
-
'%s',
|
|
45
|
-
'End of successful parser outputs.',
|
|
46
|
-
], successfulParserOutputs.map(output => ' ' + JSON.stringify(output)).join('\n'));
|
|
47
|
-
parserParsingInvariant(successfulParserOutputs.length === 1, [
|
|
48
|
-
'No sequentialUnion child parser succeeded.',
|
|
49
|
-
'Parsing errors, indented, separated by newlines:',
|
|
50
|
-
'%s',
|
|
51
|
-
'End of parsing errors.',
|
|
52
|
-
], parserParsingFailedErrors
|
|
53
|
-
.flatMap(error => error.stack?.split('\n'))
|
|
54
|
-
.map(line => ' ' + line)
|
|
55
|
-
.join('\n'));
|
|
56
|
-
const [successfulParserContext] = successfulParserContexts;
|
|
57
|
-
successfulParserContext.unlookahead();
|
|
58
|
-
successfulParserContext.dispose();
|
|
59
|
-
const [successfulParserOutput] = successfulParserOutputs;
|
|
60
|
-
return successfulParserOutput;
|
|
61
|
-
};
|
|
62
|
-
const name = [
|
|
63
|
-
'(',
|
|
64
|
-
...childParsers.map(getParserName).join('|'),
|
|
65
|
-
')',
|
|
66
|
-
].join('');
|
|
67
|
-
Object.defineProperty(sequentialUnionParser, 'name', { value: name });
|
|
68
|
-
return sequentialUnionParser;
|
|
69
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { parserImplementationInvariant } from './parserImplementationInvariant.js';
|
|
2
|
-
export const createFixedLengthParser = (length) => {
|
|
3
|
-
parserImplementationInvariant(length > 0, 'Length must be positive.');
|
|
4
|
-
return async (parserContext) => {
|
|
5
|
-
const elements = [];
|
|
6
|
-
for (let i = 0; i < length; i++) {
|
|
7
|
-
const element = await parserContext.read(0);
|
|
8
|
-
elements.push(element);
|
|
9
|
-
}
|
|
10
|
-
return parserContext.from(elements);
|
|
11
|
-
};
|
|
12
|
-
};
|