@futpib/parser 1.0.1 → 1.0.3
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/.github/copilot-instructions.md +149 -0
- package/.github/workflows/copilot-setup-steps.yml +18 -0
- package/.github/workflows/main.yml +29 -8
- package/.yarn/releases/yarn-4.9.4.cjs +942 -0
- package/.yarnrc.yml +1 -1
- 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 +185 -0
- package/build/androidPackageParser.test.js +22 -0
- package/build/androidPackageUnparser.d.ts +4 -0
- package/build/androidPackageUnparser.js +94 -0
- package/build/androidPackageUnparser.test.js +26 -0
- package/build/arbitrarilySlicedAsyncInterable.d.ts +3 -1
- package/build/arbitrarilySlicedAsyncInterable.js +3 -3
- package/build/arbitrarilySlicedAsyncInterator.js +2 -1
- package/build/arbitraryDalvikBytecode.d.ts +4 -0
- package/build/arbitraryDalvikBytecode.js +640 -0
- package/build/arbitraryDalvikExecutable.d.ts +3 -0
- package/build/arbitraryDalvikExecutable.js +282 -0
- package/build/arbitraryDosDateTime.js +1 -0
- package/build/arbitraryZipStream.js +1 -1
- package/build/arrayParser.js +2 -2
- package/build/arrayParser.test.js +3 -3
- package/build/arrayUnparser.d.ts +1 -1
- package/build/backsmali.d.ts +3 -0
- package/build/backsmali.js +50 -0
- package/build/bsonParser.js +6 -2
- package/build/customInvariant.d.ts +2 -1
- package/build/customInvariant.js +4 -6
- package/build/dalvikBytecodeParser/formatParsers.d.ts +171 -0
- package/build/dalvikBytecodeParser/formatParsers.js +304 -0
- package/build/dalvikBytecodeParser/formatSizes.d.ts +34 -0
- package/build/dalvikBytecodeParser/formatSizes.js +34 -0
- package/build/dalvikBytecodeParser/operationFormats.d.ts +225 -0
- package/build/dalvikBytecodeParser/operationFormats.js +225 -0
- package/build/dalvikBytecodeParser.d.ts +1207 -0
- package/build/dalvikBytecodeParser.js +1289 -0
- package/build/dalvikBytecodeUnparser/formatUnparsers.d.ts +152 -0
- package/build/dalvikBytecodeUnparser/formatUnparsers.js +225 -0
- package/build/dalvikBytecodeUnparser.d.ts +3 -0
- package/build/dalvikBytecodeUnparser.js +642 -0
- package/build/dalvikBytecodeUnparser.test.js +25 -0
- package/build/dalvikExecutable.d.ts +215 -0
- package/build/dalvikExecutable.js +56 -0
- package/build/dalvikExecutableParser/stringSyntaxParser.d.ts +4 -0
- package/build/dalvikExecutableParser/stringSyntaxParser.js +76 -0
- package/build/dalvikExecutableParser/typeParsers.d.ts +11 -0
- package/build/dalvikExecutableParser/typeParsers.js +39 -0
- package/build/dalvikExecutableParser/typedNumbers.d.ts +106 -0
- package/build/dalvikExecutableParser/typedNumbers.js +18 -0
- package/build/dalvikExecutableParser.d.ts +5 -0
- package/build/dalvikExecutableParser.js +1757 -0
- package/build/dalvikExecutableParser.test.js +72 -0
- package/build/dalvikExecutableParserAgainstSmaliParser.test.js +275 -0
- package/build/dalvikExecutableUnparser/annotationUnparsers.d.ts +14 -0
- package/build/dalvikExecutableUnparser/annotationUnparsers.js +97 -0
- package/build/dalvikExecutableUnparser/poolBuilders.d.ts +49 -0
- package/build/dalvikExecutableUnparser/poolBuilders.js +140 -0
- package/build/dalvikExecutableUnparser/poolScanners.d.ts +4 -0
- package/build/dalvikExecutableUnparser/poolScanners.js +220 -0
- package/build/dalvikExecutableUnparser/sectionUnparsers.d.ts +25 -0
- package/build/dalvikExecutableUnparser/sectionUnparsers.js +581 -0
- package/build/dalvikExecutableUnparser/utils.d.ts +10 -0
- package/build/dalvikExecutableUnparser/utils.js +108 -0
- package/build/dalvikExecutableUnparser.d.ts +4 -0
- package/build/dalvikExecutableUnparser.js +406 -0
- package/build/dalvikExecutableUnparser.test.js +31 -0
- package/build/debugLogInputParser.d.ts +4 -0
- package/build/debugLogInputParser.js +16 -0
- package/build/debugLogParser.js +14 -3
- package/build/disjunctionParser.d.ts +2 -1
- package/build/disjunctionParser.js +6 -4
- 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 +1 -1
- package/build/exactElementParser.js +10 -5
- package/build/exactElementSwitchParser.d.ts +3 -0
- package/build/exactElementSwitchParser.js +22 -0
- package/build/exactSequenceParser.d.ts +2 -1
- package/build/exactSequenceParser.js +12 -2
- package/build/fetchCid.d.ts +1 -0
- package/build/fetchCid.js +103 -0
- package/build/fetchCid.test.js +16 -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/inputReader.d.ts +11 -0
- package/build/inputReader.js +37 -0
- package/build/inputReader.test.js +161 -8
- 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.test.js +8 -8
- package/build/jsonParser.d.ts +2 -0
- package/build/jsonParser.js +19 -22
- package/build/lazyMessageError.d.ts +48 -0
- package/build/lazyMessageError.js +53 -0
- package/build/lazyMessageError.test.d.ts +1 -0
- package/build/lazyMessageError.test.js +15 -0
- 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/lookaheadParser.d.ts +2 -0
- package/build/lookaheadParser.js +14 -0
- package/build/negativeLookaheadParser.js +22 -16
- package/build/negativeLookaheadParser.test.d.ts +1 -0
- package/build/negativeLookaheadParser.test.js +30 -0
- package/build/noStackCaptureOverheadError.d.ts +4 -0
- package/build/noStackCaptureOverheadError.js +9 -0
- package/build/noStackCaptureOverheadError.test.d.ts +1 -0
- package/build/noStackCaptureOverheadError.test.js +15 -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 +17 -0
- package/build/optionalParser.js +2 -2
- package/build/parser.d.ts +11 -1
- package/build/parser.js +82 -32
- package/build/parser.test.js +141 -25
- package/build/parserAccessorParser.js +9 -1
- package/build/parserConsumedSequenceParser.d.ts +1 -1
- package/build/parserConsumedSequenceParser.js +21 -16
- package/build/parserContext.d.ts +22 -6
- package/build/parserContext.js +113 -57
- package/build/parserContext.test.js +33 -2
- package/build/parserCreatorCompose.d.ts +1 -0
- package/build/parserCreatorCompose.js +8 -2
- package/build/parserError.d.ts +605 -40
- package/build/parserError.js +98 -53
- package/build/parserImplementationInvariant.d.ts +1 -1
- package/build/parserImplementationInvariant.js +2 -2
- package/build/parserInputCompanion.d.ts +15 -0
- package/build/parserInputCompanion.js +38 -0
- package/build/promiseCompose.d.ts +1 -1
- package/build/promiseCompose.js +11 -1
- package/build/promiseSettled.d.ts +1 -0
- package/build/promiseSettled.js +4 -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/separatedNonEmptyArrayParser.d.ts +2 -0
- package/build/separatedNonEmptyArrayParser.js +40 -0
- package/build/separatedNonEmptyArrayParser.test.d.ts +1 -0
- package/build/separatedNonEmptyArrayParser.test.js +66 -0
- package/build/sequenceBuffer.d.ts +10 -0
- package/build/sequenceBuffer.js +54 -2
- package/build/sequenceBuffer.test.js +57 -0
- 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 +1 -1
- 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 +1 -1
- package/build/sliceBoundedParser.js +7 -2
- package/build/sliceBoundedParser.test.js +30 -1
- package/build/smali.d.ts +1 -0
- package/build/smali.js +21 -0
- package/build/smaliParser.d.ts +68 -0
- package/build/smaliParser.js +2081 -0
- package/build/smaliParser.test.d.ts +1 -0
- package/build/smaliParser.test.js +410 -0
- package/build/stringFromAsyncIterable.d.ts +1 -0
- package/build/stringFromAsyncIterable.js +7 -0
- package/build/terminatedArrayParser.d.ts +3 -1
- package/build/terminatedArrayParser.js +79 -2
- 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/unionParser.d.ts +2 -1
- package/build/unionParser.js +29 -14
- package/build/unionParser.test.d.ts +1 -0
- package/build/unionParser.test.js +60 -0
- package/build/unparser.d.ts +3 -3
- package/build/unparser.js +6 -4
- package/build/unparser.test.js +7 -19
- package/build/unparserContext.d.ts +2 -2
- package/build/unparserContext.js +2 -3
- package/build/unparserError.d.ts +2 -1
- package/build/unparserError.js +2 -1
- package/build/unparserImplementationInvariant.d.ts +1 -1
- package/build/unparserOutputCompanion.d.ts +1 -1
- package/build/unparserOutputCompanion.js +1 -1
- package/build/zipParser.d.ts +7 -2
- package/build/zipParser.js +36 -12
- package/build/zipUnparser.d.ts +7 -4
- package/build/zipUnparser.js +64 -45
- package/build/zipUnparser.test.js +15 -15
- package/package.json +33 -24
- package/src/allSettledStream.test.ts +40 -0
- package/src/allSettledStream.ts +47 -15
- package/src/androidPackage.ts +48 -0
- package/src/androidPackageParser.test.ts +27 -0
- package/src/{apkParser.test.ts.md → androidPackageParser.test.ts.md} +4 -4
- package/src/androidPackageParser.test.ts.snap +0 -0
- package/src/androidPackageParser.ts +398 -0
- package/src/androidPackageUnparser.test.ts +34 -0
- package/src/androidPackageUnparser.ts +126 -0
- package/src/arbitrarilySlicedAsyncInterable.ts +7 -2
- package/src/arbitrarilySlicedAsyncInterator.ts +4 -4
- package/src/arbitraryDalvikBytecode.ts +992 -0
- package/src/arbitraryDalvikExecutable.ts +434 -0
- package/src/arbitraryDosDateTime.ts +1 -0
- package/src/arbitraryZipStream.ts +1 -1
- package/src/arrayParser.test.ts +3 -3
- package/src/arrayParser.ts +2 -2
- package/src/arrayUnparser.ts +2 -2
- package/src/backsmali.ts +74 -0
- package/src/bsonParser.test.ts +12 -14
- package/src/bsonParser.ts +13 -2
- package/src/customInvariant.ts +8 -12
- package/src/dalvikBytecodeParser/formatParsers.ts +780 -0
- package/src/dalvikBytecodeParser/formatSizes.ts +35 -0
- package/src/dalvikBytecodeParser/operationFormats.ts +226 -0
- package/src/dalvikBytecodeParser.ts +2873 -0
- package/src/dalvikBytecodeUnparser/formatUnparsers.ts +442 -0
- package/src/dalvikBytecodeUnparser.test.ts +44 -0
- package/src/dalvikBytecodeUnparser.ts +758 -0
- package/src/dalvikExecutable.ts +282 -0
- package/src/dalvikExecutableParser/stringSyntaxParser.ts +145 -0
- package/src/dalvikExecutableParser/typeParsers.ts +74 -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 +3245 -0
- package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +363 -0
- package/src/dalvikExecutableUnparser/annotationUnparsers.ts +135 -0
- package/src/dalvikExecutableUnparser/poolBuilders.ts +189 -0
- package/src/dalvikExecutableUnparser/poolScanners.ts +297 -0
- package/src/dalvikExecutableUnparser/sectionUnparsers.ts +683 -0
- package/src/dalvikExecutableUnparser/utils.ts +149 -0
- package/src/dalvikExecutableUnparser.test.ts +57 -0
- package/src/dalvikExecutableUnparser.ts +581 -0
- package/src/debugLogInputParser.ts +28 -0
- package/src/debugLogParser.ts +19 -3
- package/src/disjunctionParser.ts +12 -7
- package/src/elementTerminatedArrayParser.test.ts +99 -0
- package/src/elementTerminatedArrayParser.ts +31 -0
- package/src/elementTerminatedSequenceArrayParser.test.ts +52 -0
- package/src/elementTerminatedSequenceArrayParser.ts +52 -0
- package/src/elementTerminatedSequenceParser.test.ts +52 -0
- package/src/elementTerminatedSequenceParser.ts +43 -0
- package/src/endOfInputParser.ts +1 -1
- package/src/exactElementParser.ts +17 -11
- package/src/exactElementSwitchParser.ts +41 -0
- package/src/exactSequenceParser.ts +23 -2
- package/src/fetchCid.test.ts +20 -0
- package/src/fetchCid.ts +121 -0
- package/src/fixedLengthSequenceParser.test.ts +75 -0
- package/src/fixedLengthSequenceParser.ts +28 -1
- package/src/hasExecutable.ts +11 -0
- package/src/highResolutionTimer.ts +49 -0
- package/src/inputReader.test.ts +204 -8
- package/src/inputReader.ts +76 -3
- package/src/inputReaderState.ts +33 -0
- package/src/inspect.ts +9 -0
- package/src/javaKeyStoreParser.test.ts +12 -15
- package/src/javaKeyStoreParser.ts +2 -6
- package/src/jsonParser.test.ts +2 -4
- package/src/jsonParser.ts +46 -62
- package/src/lazyMessageError.test.ts +21 -0
- package/src/lazyMessageError.ts +88 -0
- package/src/leb128Parser.test.ts +173 -0
- package/src/leb128Parser.ts +125 -0
- package/src/lookaheadParser.ts +19 -0
- package/src/negativeLookaheadParser.test.ts +49 -0
- package/src/negativeLookaheadParser.ts +27 -15
- package/src/noStackCaptureOverheadError.test.ts +17 -0
- package/src/noStackCaptureOverheadError.ts +12 -0
- package/src/nonEmptyArrayParser.test.ts +21 -0
- package/src/nonEmptyArrayParser.ts +44 -0
- package/src/optionalParser.ts +3 -2
- package/src/parser.test.ts +203 -31
- package/src/parser.test.ts.md +34 -27
- package/src/parser.test.ts.snap +0 -0
- package/src/parser.ts +172 -45
- package/src/parserAccessorParser.ts +12 -2
- package/src/parserConsumedSequenceParser.ts +26 -17
- package/src/parserContext.test.ts +37 -2
- package/src/parserContext.ts +185 -79
- package/src/parserCreatorCompose.ts +20 -2
- package/src/parserError.ts +144 -61
- package/src/parserImplementationInvariant.ts +3 -3
- package/src/parserInputCompanion.ts +55 -0
- package/src/promiseCompose.ts +17 -3
- package/src/promiseSettled.ts +6 -0
- package/src/separatedArrayParser.test.ts +34 -0
- package/src/separatedArrayParser.ts +55 -0
- package/src/separatedNonEmptyArrayParser.test.ts +117 -0
- package/src/separatedNonEmptyArrayParser.ts +61 -0
- package/src/sequenceBuffer.test.ts +70 -0
- package/src/sequenceBuffer.ts +88 -2
- package/src/sequenceTerminatedSequenceParser.test.ts +58 -0
- package/src/sequenceTerminatedSequenceParser.ts +62 -0
- package/src/sequenceUnparser.ts +2 -2
- package/src/skipParser.ts +7 -5
- package/src/skipToParser.ts +16 -0
- package/src/sliceBoundedParser.test.ts +35 -1
- package/src/sliceBoundedParser.ts +19 -1
- package/src/smali.ts +29 -0
- package/src/smaliParser.test.ts +443 -0
- package/src/smaliParser.test.ts.md +3907 -0
- package/src/smaliParser.test.ts.snap +0 -0
- package/src/smaliParser.ts +3348 -0
- package/src/stringFromAsyncIterable.ts +9 -0
- package/src/terminatedArrayParser.test.ts +258 -0
- package/src/terminatedArrayParser.ts +109 -6
- package/src/toAsyncIterable.ts +7 -0
- package/src/toAsyncIterator.ts +48 -0
- package/src/tupleParser.ts +8 -5
- package/src/uint8Array.ts +2 -3
- package/src/unionParser.test.ts +78 -0
- package/src/unionParser.ts +47 -21
- package/src/unparser.test.ts +18 -34
- package/src/unparser.ts +13 -9
- package/src/unparserContext.ts +9 -13
- package/src/unparserError.ts +2 -1
- package/src/unparserImplementationInvariant.ts +1 -1
- package/src/unparserOutputCompanion.ts +1 -1
- package/src/zip.ts +2 -6
- package/src/zipParser.ts +71 -20
- package/src/zipUnparser.test.ts +19 -19
- package/src/zipUnparser.ts +139 -90
- package/tsconfig.json +7 -1
- package/xo.config.ts +15 -0
- package/.yarn/releases/yarn-4.5.3.cjs +0 -934
- package/build/apk.d.ts +0 -39
- package/build/apkParser.d.ts +0 -16
- package/build/apkParser.js +0 -164
- package/build/apkParser.test.js +0 -22
- package/build/apkUnparser.d.ts +0 -4
- package/build/apkUnparser.js +0 -90
- package/build/apkUnparser.test.js +0 -26
- 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/javaKeystoreParser.d.ts +0 -2
- package/build/javaKeystoreParser.js +0 -7
- package/build/jsonParser2.d.ts +0 -3
- package/build/jsonParser2.js +0 -52
- package/build/jsonParser2.test.js +0 -22
- package/build/negativeLookahead.d.ts +0 -2
- package/build/negativeLookahead.js +0 -18
- 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/parserInvariant.d.ts +0 -4
- package/build/parserInvariant.js +0 -11
- 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/unparserInputCompanion.d.ts +0 -15
- package/build/unparserInputCompanion.js +0 -13
- 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 -48
- package/src/apkParser.test.ts +0 -30
- package/src/apkParser.test.ts.snap +0 -0
- package/src/apkParser.ts +0 -392
- package/src/apkUnparser.test.ts +0 -37
- package/src/apkUnparser.ts +0 -120
- package/src/invariantDefined.ts +0 -6
- package/src/invariantIdentity.ts +0 -8
- /package/build/{apk.js → androidPackage.js} +0 -0
- /package/build/{apkParser.test.d.ts → androidPackageParser.test.d.ts} +0 -0
- /package/build/{apkUnparser.test.d.ts → androidPackageUnparser.test.d.ts} +0 -0
- /package/build/{arbitraryDosPermissions.d.ts → dalvikBytecodeUnparser.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 → dalvikExecutableUnparser.test.d.ts} +0 -0
- /package/build/{parserParsingInvariant.d.ts → elementTerminatedArrayParser.test.d.ts} +0 -0
- /package/build/{parserParsingInvariant.js → elementTerminatedSequenceArrayParser.test.d.ts} +0 -0
- /package/build/{zipEntry.js → elementTerminatedSequenceParser.test.d.ts} +0 -0
- /package/build/{zipFile.js → fetchCid.test.d.ts} +0 -0
- /package/build/{zipFileEntry.js → fixedLengthSequenceParser.test.d.ts} +0 -0
package/build/apk.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type Zip } from './zip.js';
|
|
2
|
-
export type ApkSigningBlockPair = {
|
|
3
|
-
id: number;
|
|
4
|
-
value: Uint8Array;
|
|
5
|
-
};
|
|
6
|
-
export type ApkSignatureV2Digest = {
|
|
7
|
-
signatureAlgorithmId: number;
|
|
8
|
-
digest: Uint8Array;
|
|
9
|
-
};
|
|
10
|
-
export type ApkSignatureV2AdditionalAttribute = {
|
|
11
|
-
id: number;
|
|
12
|
-
value: Uint8Array;
|
|
13
|
-
};
|
|
14
|
-
export type ApkSignatureV2SignedData = {
|
|
15
|
-
digests: ApkSignatureV2Digest[];
|
|
16
|
-
certificates: Uint8Array[];
|
|
17
|
-
additionalAttributes: ApkSignatureV2AdditionalAttribute[];
|
|
18
|
-
zeroPaddingLength?: number;
|
|
19
|
-
};
|
|
20
|
-
export type ApkSignatureV2Signature = {
|
|
21
|
-
signatureAlgorithmId: number;
|
|
22
|
-
signature: Uint8Array;
|
|
23
|
-
};
|
|
24
|
-
export type ApkSignatureV2Signer = {
|
|
25
|
-
signedData: ApkSignatureV2SignedData;
|
|
26
|
-
signatures: ApkSignatureV2Signature[];
|
|
27
|
-
publicKey: Uint8Array;
|
|
28
|
-
};
|
|
29
|
-
export type ApkSignatureV2 = {
|
|
30
|
-
signers: ApkSignatureV2Signer[];
|
|
31
|
-
};
|
|
32
|
-
export type ApkSigningBlock = {
|
|
33
|
-
pairs: ApkSigningBlockPair[];
|
|
34
|
-
signatureV2?: ApkSignatureV2;
|
|
35
|
-
zeroPaddingLength?: number;
|
|
36
|
-
};
|
|
37
|
-
export type Apk = Zip & {
|
|
38
|
-
signingBlock?: ApkSigningBlock;
|
|
39
|
-
};
|
package/build/apkParser.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type Parser } from './parser.js';
|
|
2
|
-
import { ZipCentralDirectoryHeader, ZipEndOfCentralDirectoryRecord, ZipLocalFile } from './zipParser.js';
|
|
3
|
-
import { type Apk, type ApkSigningBlock } from './apk.js';
|
|
4
|
-
export declare const apkSigningBlockParser: Parser<ApkSigningBlock, Uint8Array>;
|
|
5
|
-
export declare const apkParser: Parser<Apk, Uint8Array>;
|
|
6
|
-
export type ApkSignableSections = {
|
|
7
|
-
zipLocalFiles: ZipLocalFile[];
|
|
8
|
-
apkSigningBlock?: ApkSigningBlock;
|
|
9
|
-
zipCentralDirectory: ZipCentralDirectoryHeader[];
|
|
10
|
-
zipEndOfCentralDirectory: ZipEndOfCentralDirectoryRecord;
|
|
11
|
-
zipLocalFilesUint8Array: Uint8Array;
|
|
12
|
-
apkSigningBlockUint8Array?: Uint8Array;
|
|
13
|
-
zipCentralDirectoryUint8Array: Uint8Array;
|
|
14
|
-
zipEndOfCentralDirectoryUint8Array: Uint8Array;
|
|
15
|
-
};
|
|
16
|
-
export declare const apkSignableSectionsParser: Parser<ApkSignableSections, Uint8Array>;
|
package/build/apkParser.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import invariant from 'invariant';
|
|
2
|
-
import { createArrayParser } from './arrayParser.js';
|
|
3
|
-
import { createOptionalParser } from './optionalParser.js';
|
|
4
|
-
import { setParserName } from './parser.js';
|
|
5
|
-
import { promiseCompose } from './promiseCompose.js';
|
|
6
|
-
import { createTupleParser } from './tupleParser.js';
|
|
7
|
-
import { zip64EndOfCentralDirectoryLocatorParser, zip64EndOfCentralDirectoryRecordParser, zipArchiveDecryptionHeaderParser, zipArchiveExtraDataRecordParser, zipCentralDirectoryHeaderParser, zipEndOfCentralDirectoryRecordParser, zipFromZipSegments, zipLocalFileParser, } from './zipParser.js';
|
|
8
|
-
import { createFixedLengthSequenceParser } from './fixedLengthSequenceParser.js';
|
|
9
|
-
import { parserCreatorCompose } from './parserCreatorCompose.js';
|
|
10
|
-
import { createExactSequenceParser } from './exactSequenceParser.js';
|
|
11
|
-
import { createSliceBoundedParser } from './sliceBoundedParser.js';
|
|
12
|
-
import { createDisjunctionParser } from './disjunctionParser.js';
|
|
13
|
-
import { createExactElementParser } from './exactElementParser.js';
|
|
14
|
-
import { createParserConsumedSequenceParser } from './parserConsumedSequenceParser.js';
|
|
15
|
-
// https://source.android.com/docs/security/features/apksigning/v2#apk-signing-block
|
|
16
|
-
const uint32LEParser = promiseCompose(createFixedLengthSequenceParser(4), array => Buffer.from(array).readUInt32LE());
|
|
17
|
-
setParserName(uint32LEParser, 'uint32LEParser');
|
|
18
|
-
const uint64LEParser = promiseCompose(createFixedLengthSequenceParser(8), array => Buffer.from(array).readBigUInt64LE());
|
|
19
|
-
setParserName(uint64LEParser, 'uint64LEParser');
|
|
20
|
-
const createUint32LengthPrefixedParser = (createInnerParser) => parserCreatorCompose(() => uint32LEParser, length => createInnerParser(length))();
|
|
21
|
-
const createUint64LengthPrefixedParser = (createInnerParser) => parserCreatorCompose(() => uint64LEParser, length => createInnerParser(length))();
|
|
22
|
-
const createUint32LengthPrefixedSliceBoundedParser = (innerParser) => createUint32LengthPrefixedParser(length => createSliceBoundedParser(innerParser, length));
|
|
23
|
-
const createUint32LengthPrefixedSliceBoundedArrayParser = (innerParser) => createUint32LengthPrefixedSliceBoundedParser(createArrayParser(innerParser));
|
|
24
|
-
const createApkSigningBlockZeroPaddingPairInnerParser = (length) => promiseCompose(createTupleParser([
|
|
25
|
-
createExactSequenceParser(Buffer.from('77657242', 'hex')),
|
|
26
|
-
createFixedLengthSequenceParser(length - 4),
|
|
27
|
-
]), ([_magic, zeroPadding]) => ({ type: 'zeroPadding', length: zeroPadding.length }));
|
|
28
|
-
const createApkSigningBlockSignatureV2PairInnerParser = (length) => {
|
|
29
|
-
const apkSigningBlockSignatureV2PairInnerParser = promiseCompose(createTupleParser([
|
|
30
|
-
createExactSequenceParser(Buffer.from('1a870971', 'hex')),
|
|
31
|
-
apkSignatureV2SignersParser,
|
|
32
|
-
]), ([_magic, signers = []]) => ({ type: 'signatureV2', signers }));
|
|
33
|
-
return setParserName(apkSigningBlockSignatureV2PairInnerParser, 'apkSigningBlockSignatureV2PairInnerParser');
|
|
34
|
-
};
|
|
35
|
-
const createApkSigningBlockGenericPairInnerParser = (length) => promiseCompose(createTupleParser([
|
|
36
|
-
uint32LEParser,
|
|
37
|
-
createFixedLengthSequenceParser(length - 4),
|
|
38
|
-
]), ([id, value]) => ({ type: 'generic', pair: { id, value } }));
|
|
39
|
-
const createApkSigningBlockPairInnerParser = (length) => createDisjunctionParser([
|
|
40
|
-
createApkSigningBlockZeroPaddingPairInnerParser(length),
|
|
41
|
-
createApkSigningBlockSignatureV2PairInnerParser(length),
|
|
42
|
-
createApkSigningBlockGenericPairInnerParser(length),
|
|
43
|
-
]);
|
|
44
|
-
const apkSigningBlockPairParser = createUint64LengthPrefixedParser(length => createApkSigningBlockPairInnerParser(Number(length)));
|
|
45
|
-
setParserName(apkSigningBlockPairParser, 'apkSigningBlockPairParser');
|
|
46
|
-
const apkSigningBlockPairsParser = createArrayParser(apkSigningBlockPairParser);
|
|
47
|
-
export const apkSigningBlockParser = createUint64LengthPrefixedParser(sizeOfBlock => promiseCompose(createTupleParser([
|
|
48
|
-
apkSigningBlockPairsParser,
|
|
49
|
-
uint64LEParser,
|
|
50
|
-
createExactSequenceParser(Buffer.from('APK Sig Block 42', 'utf8')),
|
|
51
|
-
]), async ([pairs, sizeOfBlockRepeated, _magic]) => {
|
|
52
|
-
invariant(sizeOfBlock === sizeOfBlockRepeated, 'Size of block mismatch: %s !== %s.', sizeOfBlock, sizeOfBlockRepeated);
|
|
53
|
-
const zeroPaddingPair = pairs.find(pair => pair.type === 'zeroPadding');
|
|
54
|
-
const signatureV2Pair = pairs.find(pair => pair.type === 'signatureV2');
|
|
55
|
-
const genericPairs = (pairs
|
|
56
|
-
.filter(pair => (pair !== zeroPaddingPair
|
|
57
|
-
&& pair !== signatureV2Pair))
|
|
58
|
-
.map(pair => {
|
|
59
|
-
invariant(pair.type === 'generic', 'Expected generic pair, got %s.', pair.type);
|
|
60
|
-
return pair.pair;
|
|
61
|
-
}));
|
|
62
|
-
return {
|
|
63
|
-
zeroPaddingLength: zeroPaddingPair?.length,
|
|
64
|
-
signatureV2: signatureV2Pair ? {
|
|
65
|
-
signers: signatureV2Pair?.signers,
|
|
66
|
-
} : undefined,
|
|
67
|
-
pairs: genericPairs,
|
|
68
|
-
};
|
|
69
|
-
}));
|
|
70
|
-
const apkSignatureV2DigestParser = createUint32LengthPrefixedParser(pairLength => promiseCompose(createTupleParser([
|
|
71
|
-
uint32LEParser,
|
|
72
|
-
createUint32LengthPrefixedParser(digestLength => createFixedLengthSequenceParser(digestLength)),
|
|
73
|
-
]), ([signatureAlgorithmId, digest]) => ({ signatureAlgorithmId, digest })));
|
|
74
|
-
const apkSignatureV2DigestsParser = createUint32LengthPrefixedSliceBoundedArrayParser(apkSignatureV2DigestParser);
|
|
75
|
-
const apkSignatureV2CertificateParser = createUint32LengthPrefixedParser(certificateLength => createFixedLengthSequenceParser(certificateLength));
|
|
76
|
-
const apkSignatureV2CertificatesParser = createUint32LengthPrefixedSliceBoundedArrayParser(apkSignatureV2CertificateParser);
|
|
77
|
-
const apkSignatureV2AdditionalAttributeParser = createUint32LengthPrefixedParser(pairLength => promiseCompose(createTupleParser([
|
|
78
|
-
uint32LEParser,
|
|
79
|
-
createFixedLengthSequenceParser(pairLength - 4),
|
|
80
|
-
]), ([id, value]) => ({ id, value })));
|
|
81
|
-
setParserName(apkSignatureV2AdditionalAttributeParser, 'apkSignatureV2AdditionalAttributeParser');
|
|
82
|
-
const apkSignatureV2AdditionalAttributesParser = createUint32LengthPrefixedSliceBoundedArrayParser(apkSignatureV2AdditionalAttributeParser);
|
|
83
|
-
setParserName(apkSignatureV2AdditionalAttributesParser, 'apkSignatureV2AdditionalAttributesParser');
|
|
84
|
-
const apkSignatureV2SignedDataParser = createUint32LengthPrefixedSliceBoundedParser(promiseCompose(createTupleParser([
|
|
85
|
-
apkSignatureV2DigestsParser,
|
|
86
|
-
apkSignatureV2CertificatesParser,
|
|
87
|
-
apkSignatureV2AdditionalAttributesParser,
|
|
88
|
-
createArrayParser(createExactElementParser(0)),
|
|
89
|
-
]), ([digests, certificates, additionalAttributes, zeroPadding,]) => ({
|
|
90
|
-
digests,
|
|
91
|
-
certificates,
|
|
92
|
-
additionalAttributes,
|
|
93
|
-
zeroPaddingLength: zeroPadding.length,
|
|
94
|
-
})));
|
|
95
|
-
setParserName(apkSignatureV2SignedDataParser, 'apkSignatureV2SignedDataParser');
|
|
96
|
-
const apkSignatureV2SignatureParser = createUint32LengthPrefixedParser(signatureLength => promiseCompose(createTupleParser([
|
|
97
|
-
uint32LEParser,
|
|
98
|
-
createUint32LengthPrefixedParser(signatureLength => createFixedLengthSequenceParser(signatureLength)),
|
|
99
|
-
]), ([signatureAlgorithmId, signature,]) => ({
|
|
100
|
-
signatureAlgorithmId,
|
|
101
|
-
signature,
|
|
102
|
-
})));
|
|
103
|
-
const apkSignatureV2SignaturesParser = createUint32LengthPrefixedSliceBoundedArrayParser(apkSignatureV2SignatureParser);
|
|
104
|
-
setParserName(apkSignatureV2SignaturesParser, 'apkSignatureV2SignaturesParser');
|
|
105
|
-
const apkSignatureV2PublicKeyParser = createUint32LengthPrefixedParser(publicKeyLength => createFixedLengthSequenceParser(publicKeyLength));
|
|
106
|
-
setParserName(apkSignatureV2PublicKeyParser, 'apkSignatureV2PublicKeyParser');
|
|
107
|
-
const apkSignatureV2SignerParser = createUint32LengthPrefixedSliceBoundedParser(promiseCompose(createTupleParser([
|
|
108
|
-
apkSignatureV2SignedDataParser,
|
|
109
|
-
apkSignatureV2SignaturesParser,
|
|
110
|
-
apkSignatureV2PublicKeyParser,
|
|
111
|
-
]), ([signedData, signatures = [], publicKey,]) => ({
|
|
112
|
-
signedData,
|
|
113
|
-
signatures,
|
|
114
|
-
publicKey,
|
|
115
|
-
})));
|
|
116
|
-
setParserName(apkSignatureV2SignerParser, 'apkSignatureV2SignerParser');
|
|
117
|
-
const apkSignatureV2SignersParser = createUint32LengthPrefixedSliceBoundedArrayParser(apkSignatureV2SignerParser);
|
|
118
|
-
setParserName(apkSignatureV2SignersParser, 'apkSignatureV2SignersParser');
|
|
119
|
-
const apkParser_ = createTupleParser([
|
|
120
|
-
createArrayParser(zipLocalFileParser),
|
|
121
|
-
createOptionalParser(zipArchiveDecryptionHeaderParser),
|
|
122
|
-
createOptionalParser(zipArchiveExtraDataRecordParser),
|
|
123
|
-
createOptionalParser(apkSigningBlockParser),
|
|
124
|
-
createArrayParser(zipCentralDirectoryHeaderParser),
|
|
125
|
-
createOptionalParser(zip64EndOfCentralDirectoryRecordParser),
|
|
126
|
-
createOptionalParser(zip64EndOfCentralDirectoryLocatorParser),
|
|
127
|
-
zipEndOfCentralDirectoryRecordParser,
|
|
128
|
-
]);
|
|
129
|
-
setParserName(apkParser_, 'apkParser_');
|
|
130
|
-
export const apkParser = promiseCompose(apkParser_, async ([zipLocalFiles, zipArchiveDecryptionHeader, zipArchiveExtraDataRecord, apkSigningBlock, zipCentralDirectoryHeaders, zip64EndOfCentralDirectoryRecord, zip64EndOfCentralDirectoryLocator, zipEndOfCentralDirectoryRecord,]) => {
|
|
131
|
-
const zip = await zipFromZipSegments({
|
|
132
|
-
zipLocalFiles,
|
|
133
|
-
zipCentralDirectoryHeaders,
|
|
134
|
-
zipEndOfCentralDirectoryRecord,
|
|
135
|
-
});
|
|
136
|
-
return {
|
|
137
|
-
...zip,
|
|
138
|
-
signingBlock: apkSigningBlock,
|
|
139
|
-
};
|
|
140
|
-
});
|
|
141
|
-
setParserName(apkParser, 'apkParser');
|
|
142
|
-
export const apkSignableSectionsParser = promiseCompose(createTupleParser([
|
|
143
|
-
createParserConsumedSequenceParser(createTupleParser([
|
|
144
|
-
createArrayParser(zipLocalFileParser),
|
|
145
|
-
createOptionalParser(zipArchiveDecryptionHeaderParser),
|
|
146
|
-
createOptionalParser(zipArchiveExtraDataRecordParser),
|
|
147
|
-
])),
|
|
148
|
-
createOptionalParser(createParserConsumedSequenceParser(apkSigningBlockParser)),
|
|
149
|
-
createParserConsumedSequenceParser(createTupleParser([
|
|
150
|
-
createArrayParser(zipCentralDirectoryHeaderParser),
|
|
151
|
-
createOptionalParser(zip64EndOfCentralDirectoryRecordParser),
|
|
152
|
-
createOptionalParser(zip64EndOfCentralDirectoryLocatorParser),
|
|
153
|
-
])),
|
|
154
|
-
createParserConsumedSequenceParser(zipEndOfCentralDirectoryRecordParser),
|
|
155
|
-
]), async ([[[zipLocalFiles,], zipLocalFilesUint8Array,], [apkSigningBlock = undefined, apkSigningBlockUint8Array = undefined,] = [], [[zipCentralDirectory,], zipCentralDirectoryUint8Array,], [zipEndOfCentralDirectory, zipEndOfCentralDirectoryUint8Array,],]) => ({
|
|
156
|
-
zipLocalFiles,
|
|
157
|
-
apkSigningBlock,
|
|
158
|
-
zipCentralDirectory,
|
|
159
|
-
zipEndOfCentralDirectory,
|
|
160
|
-
zipLocalFilesUint8Array,
|
|
161
|
-
apkSigningBlockUint8Array,
|
|
162
|
-
zipCentralDirectoryUint8Array,
|
|
163
|
-
zipEndOfCentralDirectoryUint8Array,
|
|
164
|
-
}));
|
package/build/apkParser.test.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import { uint8ArrayParserInputCompanion } from './parserInputCompanion.js';
|
|
3
|
-
import { runParser } from './parser.js';
|
|
4
|
-
import { apkParser } from './apkParser.js';
|
|
5
|
-
for (const apkCid of [
|
|
6
|
-
'bafkreicckcmzrdxwoc3w2in3tivpyxrdtcfpct4zwauq3igew3nkpvfapu',
|
|
7
|
-
'bafkreidqycbgrtp7ywhevsgtm464dqpamxsijpaqfcfz2k3ymc3wrzsb5m',
|
|
8
|
-
]) {
|
|
9
|
-
test('apk ' + apkCid, async (t) => {
|
|
10
|
-
const apkResponse = await fetch('https://ipfs.io/ipfs/' + apkCid);
|
|
11
|
-
const apkStream = apkResponse.body;
|
|
12
|
-
const actual = await runParser(apkParser, apkStream, uint8ArrayParserInputCompanion, {
|
|
13
|
-
errorJoinMode: 'all',
|
|
14
|
-
});
|
|
15
|
-
for (const entry of actual.entries) {
|
|
16
|
-
if (entry.type === 'file') {
|
|
17
|
-
entry.content = new Uint8Array([entry.content.length]);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
t.snapshot(actual);
|
|
21
|
-
});
|
|
22
|
-
}
|
package/build/apkUnparser.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ApkSignatureV2SignedData, ApkSigningBlock } from "./apk.js";
|
|
2
|
-
import { Unparser } from "./unparser.js";
|
|
3
|
-
export declare const apkSignatureV2SignedDataUnparser: Unparser<ApkSignatureV2SignedData, Uint8Array>;
|
|
4
|
-
export declare const apkSigningBlockUnparser: Unparser<ApkSigningBlock, Uint8Array>;
|
package/build/apkUnparser.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { createArrayUnparser } from "./arrayUnparser.js";
|
|
2
|
-
import { createSequenceUnparser } from "./sequenceUnparser.js";
|
|
3
|
-
const uint8ArrayUnparser = createSequenceUnparser();
|
|
4
|
-
const uint32LEUnparser = async function* (input) {
|
|
5
|
-
const buffer = Buffer.alloc(4);
|
|
6
|
-
buffer.writeUInt32LE(input);
|
|
7
|
-
yield buffer;
|
|
8
|
-
};
|
|
9
|
-
const uint64LEUnparser = async function* (input) {
|
|
10
|
-
const buffer = Buffer.alloc(8);
|
|
11
|
-
buffer.writeBigUInt64LE(BigInt(input));
|
|
12
|
-
yield buffer;
|
|
13
|
-
};
|
|
14
|
-
const createUint32LengthPrefixedUnparser = (innerUnparser) => async function* (input, unparserContext) {
|
|
15
|
-
const length = yield* unparserContext.writeLater(4);
|
|
16
|
-
yield* innerUnparser(input, unparserContext);
|
|
17
|
-
yield* unparserContext.writeEarlier(length, uint32LEUnparser, unparserContext.position - length.positionEnd);
|
|
18
|
-
};
|
|
19
|
-
const createUint64LengthPrefixedUnparser = (innerUnparser) => async function* (input, unparserContext) {
|
|
20
|
-
const length = yield* unparserContext.writeLater(8);
|
|
21
|
-
yield* innerUnparser(input, unparserContext);
|
|
22
|
-
yield* unparserContext.writeEarlier(length, uint64LEUnparser, unparserContext.position - length.positionEnd);
|
|
23
|
-
};
|
|
24
|
-
const apkSignatureV2DigestUnparser = createUint32LengthPrefixedUnparser(async function* (input, unparserContext) {
|
|
25
|
-
yield* uint32LEUnparser(input.signatureAlgorithmId, unparserContext);
|
|
26
|
-
yield* uint32LEUnparser(input.digest.length, unparserContext);
|
|
27
|
-
yield input.digest;
|
|
28
|
-
});
|
|
29
|
-
const apkSignatureV2DigestsUnparser = createUint32LengthPrefixedUnparser(createArrayUnparser(apkSignatureV2DigestUnparser));
|
|
30
|
-
const apkSignatureV2CertificateUnparser = createUint32LengthPrefixedUnparser(uint8ArrayUnparser);
|
|
31
|
-
const apkSignatureV2CertificatesUnparser = createUint32LengthPrefixedUnparser(createArrayUnparser(apkSignatureV2CertificateUnparser));
|
|
32
|
-
const apkSignatureV2AdditionalAttributeUnparser = createUint32LengthPrefixedUnparser(async function* (input, unparserContext) {
|
|
33
|
-
yield* uint32LEUnparser(input.id, unparserContext);
|
|
34
|
-
yield input.value;
|
|
35
|
-
});
|
|
36
|
-
const apkSignatureV2AdditionalAttributesUnparser = createUint32LengthPrefixedUnparser(createArrayUnparser(apkSignatureV2AdditionalAttributeUnparser));
|
|
37
|
-
export const apkSignatureV2SignedDataUnparser = createUint32LengthPrefixedUnparser(async function* (input, unparserContext) {
|
|
38
|
-
yield* apkSignatureV2DigestsUnparser(input.digests, unparserContext);
|
|
39
|
-
yield* apkSignatureV2CertificatesUnparser(input.certificates, unparserContext);
|
|
40
|
-
yield* apkSignatureV2AdditionalAttributesUnparser(input.additionalAttributes, unparserContext);
|
|
41
|
-
if (input.zeroPaddingLength) {
|
|
42
|
-
yield Buffer.alloc(input.zeroPaddingLength);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
const apkSignatureV2SignatureUnparser = createUint32LengthPrefixedUnparser(async function* (input, unparserContext) {
|
|
46
|
-
yield* uint32LEUnparser(input.signatureAlgorithmId, unparserContext);
|
|
47
|
-
yield* uint32LEUnparser(input.signature.length, unparserContext);
|
|
48
|
-
yield input.signature;
|
|
49
|
-
});
|
|
50
|
-
const apkSignatureV2SignaturesUnparser = createUint32LengthPrefixedUnparser(createArrayUnparser(apkSignatureV2SignatureUnparser));
|
|
51
|
-
const apkSignatureV2PublicKeyUnparser = createUint32LengthPrefixedUnparser(uint8ArrayUnparser);
|
|
52
|
-
const apkSignatureV2SignerUnparser = createUint32LengthPrefixedUnparser(async function* (input, unparserContext) {
|
|
53
|
-
yield* apkSignatureV2SignedDataUnparser(input.signedData, unparserContext);
|
|
54
|
-
yield* apkSignatureV2SignaturesUnparser(input.signatures, unparserContext);
|
|
55
|
-
yield* apkSignatureV2PublicKeyUnparser(input.publicKey, unparserContext);
|
|
56
|
-
});
|
|
57
|
-
const apkSignatureV2SignersUnparser = createUint32LengthPrefixedUnparser(createArrayUnparser(apkSignatureV2SignerUnparser));
|
|
58
|
-
const apkSigningBlockPairUnparser = createUint64LengthPrefixedUnparser(async function* (input, unparserContext) {
|
|
59
|
-
yield* uint32LEUnparser(input.id, unparserContext);
|
|
60
|
-
if (input.value instanceof Uint8Array) {
|
|
61
|
-
yield input.value;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
yield* apkSignatureV2SignersUnparser(input.value, unparserContext);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
const apkSigningBlockPairsUnparser = createArrayUnparser(apkSigningBlockPairUnparser);
|
|
68
|
-
export const apkSigningBlockUnparser = async function* (input, unparserContext) {
|
|
69
|
-
const pairs = [
|
|
70
|
-
...input.pairs,
|
|
71
|
-
...(input.signatureV2 ? [
|
|
72
|
-
{
|
|
73
|
-
id: 0x7109871a,
|
|
74
|
-
value: input.signatureV2.signers,
|
|
75
|
-
},
|
|
76
|
-
] : []),
|
|
77
|
-
...(input.zeroPaddingLength ? [
|
|
78
|
-
{
|
|
79
|
-
id: 0x42726577,
|
|
80
|
-
value: Buffer.alloc(input.zeroPaddingLength),
|
|
81
|
-
},
|
|
82
|
-
] : []),
|
|
83
|
-
];
|
|
84
|
-
const sizeOfBlockWriteLater = yield* unparserContext.writeLater(8);
|
|
85
|
-
yield* apkSigningBlockPairsUnparser(pairs, unparserContext);
|
|
86
|
-
const sizeOfBlock = unparserContext.position - sizeOfBlockWriteLater.position + 16;
|
|
87
|
-
yield* uint64LEUnparser(sizeOfBlock, unparserContext);
|
|
88
|
-
yield* unparserContext.writeEarlier(sizeOfBlockWriteLater, uint64LEUnparser, sizeOfBlock);
|
|
89
|
-
yield Buffer.from('APK Sig Block 42', 'utf8');
|
|
90
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import { uint8ArrayParserInputCompanion } from './parserInputCompanion.js';
|
|
3
|
-
import { runParser } from './parser.js';
|
|
4
|
-
import { apkParser, apkSigningBlockParser } from './apkParser.js';
|
|
5
|
-
import { runUnparser } from './unparser.js';
|
|
6
|
-
import { apkSigningBlockUnparser } from './apkUnparser.js';
|
|
7
|
-
import { uint8ArrayUnparserOutputCompanion } from './unparserOutputCompanion.js';
|
|
8
|
-
import invariant from 'invariant';
|
|
9
|
-
for (const apkCid of [
|
|
10
|
-
'bafkreicckcmzrdxwoc3w2in3tivpyxrdtcfpct4zwauq3igew3nkpvfapu',
|
|
11
|
-
]) {
|
|
12
|
-
test('apk ' + apkCid, async (t) => {
|
|
13
|
-
const apkResponse = await fetch('https://ipfs.io/ipfs/' + apkCid);
|
|
14
|
-
const apkStream = apkResponse.body;
|
|
15
|
-
const apk = await runParser(apkParser, apkStream, uint8ArrayParserInputCompanion, {
|
|
16
|
-
errorJoinMode: 'all',
|
|
17
|
-
});
|
|
18
|
-
const apkSigningBlock = apk.signingBlock;
|
|
19
|
-
invariant(apkSigningBlock, 'APK has no signing block');
|
|
20
|
-
const apkSigningBlockStream = runUnparser(apkSigningBlockUnparser, apkSigningBlock, uint8ArrayUnparserOutputCompanion);
|
|
21
|
-
const actual = await runParser(apkSigningBlockParser, apkSigningBlockStream, uint8ArrayParserInputCompanion, {
|
|
22
|
-
errorJoinMode: 'all',
|
|
23
|
-
});
|
|
24
|
-
t.deepEqual(actual, apkSigningBlock);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
@@ -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
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { parserImplementationInvariant } from './parserImplementationInvariant.js';
|
|
2
|
-
export const createFixedLengthSequenceParser = (length) => {
|
|
3
|
-
parserImplementationInvariant(length >= 0, 'Length must be non-negative got %s.', length);
|
|
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,15 +0,0 @@
|
|
|
1
|
-
import { type InputCompanion } from './inputCompanion.js';
|
|
2
|
-
export interface SequenceBuffer<Sequence, InputElement> {
|
|
3
|
-
push(sequence: Sequence): void;
|
|
4
|
-
peek(offset: number): InputElement | undefined;
|
|
5
|
-
skip(offset: number): void;
|
|
6
|
-
}
|
|
7
|
-
export declare class SequenceBufferImplementation<Sequence, InputElement> implements SequenceBuffer<Sequence, InputElement> {
|
|
8
|
-
private readonly _inputCompanion;
|
|
9
|
-
private readonly _sequences;
|
|
10
|
-
private _indexInFirstSequence;
|
|
11
|
-
constructor(_inputCompanion: InputCompanion<Sequence, InputElement>);
|
|
12
|
-
push(sequence: Sequence): void;
|
|
13
|
-
peek(offset: number): InputElement | undefined;
|
|
14
|
-
skip(offset: number): void;
|
|
15
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import invariant from 'invariant';
|
|
2
|
-
export class SequenceBufferImplementation {
|
|
3
|
-
_inputCompanion;
|
|
4
|
-
_sequences = [];
|
|
5
|
-
_indexInFirstSequence = 0;
|
|
6
|
-
constructor(_inputCompanion) {
|
|
7
|
-
this._inputCompanion = _inputCompanion;
|
|
8
|
-
}
|
|
9
|
-
push(sequence) {
|
|
10
|
-
this._sequences.push(sequence);
|
|
11
|
-
while (this._sequences.length > 0) {
|
|
12
|
-
const firstSequence = this._sequences[0];
|
|
13
|
-
const firstSequenceLength = this._inputCompanion.length(firstSequence);
|
|
14
|
-
if (firstSequenceLength === 0) {
|
|
15
|
-
this._sequences.shift();
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
if (this._indexInFirstSequence < firstSequenceLength) {
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
this._sequences.shift();
|
|
22
|
-
this._indexInFirstSequence -= firstSequenceLength;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
peek(offset) {
|
|
26
|
-
invariant(offset >= 0, 'Offset must be non-negative.');
|
|
27
|
-
let index = this._indexInFirstSequence + offset;
|
|
28
|
-
for (const sequence of this._sequences) {
|
|
29
|
-
const sequenceLength = this._inputCompanion.length(sequence);
|
|
30
|
-
if (index < sequenceLength) {
|
|
31
|
-
return this._inputCompanion.at(sequence, index);
|
|
32
|
-
}
|
|
33
|
-
index -= sequenceLength;
|
|
34
|
-
}
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
skip(offset) {
|
|
38
|
-
this._indexInFirstSequence += offset;
|
|
39
|
-
}
|
|
40
|
-
}
|