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

Function extractFLV

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

Source from the content-addressed store, hash-verified

3311 * @returns {Uint8Array}
3312 */
3313export function extractFLV(bytes, offset) {
3314 const stream = new Stream(bytes.slice(offset));
3315
3316 // Move past signature, version and flags
3317 stream.moveForwardsBy(5);
3318
3319 // Read header size
3320 const headerSize = stream.readInt(4, "be");
3321
3322 // Skip through the rest of the header
3323 stream.moveForwardsBy(headerSize - 9);
3324
3325 let tagSize = -11; // Fake size of previous tag header
3326 while (stream.hasMore()) {
3327 const prevTagSize = stream.readInt(4, "be");
3328 const tagType = stream.readInt(1);
3329
3330 if ([8, 9, 18].indexOf(tagType) < 0) {
3331 // This tag is not valid
3332 stream.moveBackwardsBy(1);
3333 break;
3334 }
3335
3336 if (prevTagSize !== (tagSize + 11)) {
3337 // Previous tag was not valid, reverse back over this header
3338 // and the previous tag body and header
3339 stream.moveBackwardsBy(tagSize + 11 + 5);
3340 break;
3341 }
3342
3343 tagSize = stream.readInt(3, "be");
3344
3345 // Move past the rest of the tag header and payload
3346 stream.moveForwardsBy(7 + tagSize);
3347 }
3348
3349 return stream.carve();
3350}
3351
3352
3353/**

Callers

nothing calls this directly

Calls 5

moveForwardsByMethod · 0.95
readIntMethod · 0.95
hasMoreMethod · 0.95
moveBackwardsByMethod · 0.95
carveMethod · 0.95

Tested by

no test coverage detected