From 80362cfa84083f3c0550f39e180f5f77589329ba Mon Sep 17 00:00:00 2001 From: n1073645 Date: Fri, 8 Nov 2019 11:39:50 +0000 Subject: [PATCH] Bzip2 extractor completed --- src/core/lib/FileSignatures.mjs | 38 ++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/core/lib/FileSignatures.mjs b/src/core/lib/FileSignatures.mjs index c6672c68..8c0a3aff 100644 --- a/src/core/lib/FileSignatures.mjs +++ b/src/core/lib/FileSignatures.mjs @@ -1444,7 +1444,7 @@ export const FILE_SIGNATURES = { 1: 0x5a, 2: 0x68 }, - extractor: null + extractor: extractBZIP2 }, { name: "7zip", @@ -2817,6 +2817,42 @@ export function extractGZIP(bytes, offset) { } +/** + * @param {Uint8Array} bytes + * @param {Number} offset + * @returns {Uint8Array} + */ +export function extractBZIP2(bytes, offset){ + const stream = new Stream(bytes.slice(offset)); + + //The EOFs shifted between all possible combinations. + var lookingfor = [ + [0x77, 0x24, 0x53, 0x85, 0x09], + [0xee, 0x48, 0xa7, 0x0a, 0x12], + [0xdc, 0x91, 0x4e, 0x14, 0x24], + [0xb9, 0x22, 0x9c, 0x28, 0x48], + [0x72, 0x45, 0x38, 0x50, 0x90], + [0xbb, 0x92, 0x29, 0xc2, 0x84], + [0x5d, 0xc9, 0x14, 0xe1, 0x42], + [0x2e, 0xe4, 0x8a, 0x70, 0xa1], + [0x17, 0x72, 0x45, 0x38, 0x50]]; + + for(let i = 0; i < 9; i++){ + + //Continue until an EOF. + stream.continueUntil(lookingfor[i]); + if(stream.getBytes(5).join("") == lookingfor[i].join("")) + break; + + //Jump back to the start if invalid EOF. + stream.moveTo(0); + } + stream.moveForwardsBy(4); + + return stream.carve(); +} + + /** * Zlib extractor. *