MCPcopy
hub / github.com/gchq/CyberChef / extractBZIP2

Function extractBZIP2

src/core/lib/FileSignatures.mjs:3645–3672  ·  view source on GitHub ↗
(bytes, offset)

Source from the content-addressed store, hash-verified

3643 * @returns {Uint8Array}
3644 */
3645export function extractBZIP2(bytes, offset) {
3646 const stream = new Stream(bytes.slice(offset));
3647
3648 // The EOFs shifted between all possible combinations.
3649 const lookingfor = [
3650 [0x77, 0x24, 0x53, 0x85, 0x09],
3651 [0xee, 0x48, 0xa7, 0x0a, 0x12],
3652 [0xdc, 0x91, 0x4e, 0x14, 0x24],
3653 [0xb9, 0x22, 0x9c, 0x28, 0x48],
3654 [0x72, 0x45, 0x38, 0x50, 0x90],
3655 [0xbb, 0x92, 0x29, 0xc2, 0x84],
3656 [0x5d, 0xc9, 0x14, 0xe1, 0x42],
3657 [0x2e, 0xe4, 0x8a, 0x70, 0xa1],
3658 [0x17, 0x72, 0x45, 0x38, 0x50]
3659 ];
3660
3661 for (let i = 0; i < lookingfor.length; i++) {
3662 // Continue until an EOF.
3663 stream.continueUntil(lookingfor[i]);
3664 if (stream.getBytes(5).join("") === lookingfor[i].join(""))
3665 break;
3666
3667 // Jump back to the start if invalid EOF.
3668 stream.moveTo(0);
3669 }
3670 stream.moveForwardsBy(4);
3671 return stream.carve();
3672}
3673
3674
3675/**

Callers

nothing calls this directly

Calls 5

continueUntilMethod · 0.95
getBytesMethod · 0.95
moveToMethod · 0.95
moveForwardsByMethod · 0.95
carveMethod · 0.95

Tested by

no test coverage detected