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

Function extractGIF

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

Source from the content-addressed store, hash-verified

2731 * @returns {Uint8Array}
2732 */
2733export function extractGIF(bytes, offset) {
2734 const stream = new Stream(bytes.slice(offset));
2735
2736 // Move to application extension block.
2737 stream.continueUntil([0x21, 0xff]);
2738
2739 // Move to Graphic Control Extension for frame #1.
2740 stream.continueUntil([0x21, 0xf9]);
2741 stream.moveForwardsBy(2);
2742
2743 while (stream.hasMore()) {
2744 // Move to Image descriptor.
2745 stream.moveForwardsBy(stream.readInt(1) + 1);
2746
2747 // Move past Image descriptor to the image data.
2748 stream.moveForwardsBy(11);
2749
2750 // Loop until next Graphic Control Extension.
2751 while (!Array.from(stream.getBytes(2)).equals([0x21, 0xf9])) {
2752 stream.moveBackwardsBy(2);
2753 stream.moveForwardsBy(stream.readInt(1));
2754 if (!stream.readInt(1))
2755 break;
2756 stream.moveBackwardsBy(1);
2757 }
2758
2759 // When the end of the file is [0x00, 0x3b], end.
2760 if (stream.readInt(1) === 0x3b)
2761 break;
2762
2763 stream.moveForwardsBy(1);
2764 }
2765 return stream.carve();
2766}
2767
2768
2769/**

Callers

nothing calls this directly

Calls 7

continueUntilMethod · 0.95
moveForwardsByMethod · 0.95
hasMoreMethod · 0.95
readIntMethod · 0.95
getBytesMethod · 0.95
moveBackwardsByMethod · 0.95
carveMethod · 0.95

Tested by

no test coverage detected