Skip to content

Commit

Permalink
Added Zlib extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed Jan 11, 2019
1 parent 4e57b4b commit 2307325
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/core/lib/FileSignatures.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ export const FILE_SIGNATURES = {
0: 0x78,
1: [0x1, 0x9c, 0xda, 0x5e]
},
extractor: null
extractor: extractZlib
},
{
name: "xz compression",
Expand Down Expand Up @@ -1443,6 +1443,37 @@ export function extractGZIP(bytes, offset) {
}


/**
* Zlib extractor.
*
* @param {Uint8Array} bytes
* @param {number} offset
* @returns {Uint8Array}
*/
export function extractZlib(bytes, offset) {
const stream = new Stream(bytes.slice(offset));

// Skip over CMF
stream.moveForwardsBy(1);

// Read flags
const flags = stream.readInt(1);

// Skip over preset dictionary checksum
if (flags & 0x20) {
stream.moveForwardsBy(4);
}

// Parse DEFLATE stream
parseDEFLATE(stream);

// Skip over final checksum
stream.moveForwardsBy(4);

return stream.carve();
}


/**
* Steps through a DEFLATE stream
*
Expand Down

0 comments on commit 2307325

Please sign in to comment.