From 09e93b4639c407dc019fa786cfbd883159b42683 Mon Sep 17 00:00:00 2001 From: n1073645 Date: Mon, 25 Nov 2019 11:26:31 +0000 Subject: [PATCH 1/4] Added ICO extractor --- src/core/lib/FileSignatures.mjs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/core/lib/FileSignatures.mjs b/src/core/lib/FileSignatures.mjs index dc7ced4d..41f870af 100644 --- a/src/core/lib/FileSignatures.mjs +++ b/src/core/lib/FileSignatures.mjs @@ -280,7 +280,7 @@ export const FILE_SIGNATURES = { 9: 0x0, 10: [0x0, 0x1] }, - extractor: null + extractor: extractICO }, { name: "Radiance High Dynamic Range image", @@ -2772,6 +2772,32 @@ export function extractBMP(bytes, offset) { } +/** + * ICO extractor. + * + * @param {Uint8Array} bytes + * @param {number} offset + */ +export function extractICO(bytes, offset) { + const stream = new Stream(bytes.slice(offset)); + + // Move to number of file there are. + stream.moveTo(4); + + // Read the number of files stored in the ICO + const numberFiles = stream.readInt(2, "le"); + + // Move forward to the last file header. + stream.moveForwardsBy(8 + ((numberFiles-1) * 16)); + const fileSize = stream.readInt(4, "le"); + const fileOffset = stream.readInt(4, "le"); + + // Move to the end of the last file. + stream.moveTo(fileOffset + fileSize); + return stream.carve(); +} + + /** * WAV extractor. * From 1118ff598d6ecf93792a439609e6c5a4224652d9 Mon Sep 17 00:00:00 2001 From: n1073645 Date: Mon, 25 Nov 2019 13:43:31 +0000 Subject: [PATCH 2/4] From Base85 and From Braille signatures added for magic --- src/core/operations/FromBase85.mjs | 17 +++++++++++++++++ src/core/operations/FromBraille.mjs | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/src/core/operations/FromBase85.mjs b/src/core/operations/FromBase85.mjs index c874d5dc..001f4f69 100644 --- a/src/core/operations/FromBase85.mjs +++ b/src/core/operations/FromBase85.mjs @@ -33,6 +33,23 @@ class FromBase85 extends Operation { value: ALPHABET_OPTIONS }, ]; + this.patterns = [ + { + match: "^\\s*(<~)?([!-u]{4})+([!-u]{1,3})??(~>)?\\s*$", + flags: "", + args: ["!-u", true] + }, + { + match: "^\\s*(<~)?([0-9A-Z.-:+=^!/*?&<>()[]{}@%$#]{4})+([0-9A-Z.-:+=^!/*?&<>()[]{}@%$#]{1,3})??(~>)?\\s*$", + flags: "i", + args: ["0-9a-zA-Z.-:+=^!/*?&<>()[]{}@%$#", true] + }, + { + match: "^\\s*(<~)?([0-9A-Z.-:+=^!/*?&_<>()[]{}@%$#;`|~]{4})+([0-9A-Z.-:+=^!/*?&_<>()[]{}@%$#;`|~]{1,3})??(~>)?\\s*$", + flags: "i", + args: ["0-9A-Za-z!#$%&()*+-;<=>?@^_`{|~}", true] + } + ]; } /** diff --git a/src/core/operations/FromBraille.mjs b/src/core/operations/FromBraille.mjs index adbcff91..60e590a3 100644 --- a/src/core/operations/FromBraille.mjs +++ b/src/core/operations/FromBraille.mjs @@ -25,6 +25,13 @@ class FromBraille extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = []; + this.patterns = [ + { + match: "^\\s*[⠀⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋⠌⠍⠎⠏⠐⠑⠒⠓⠔⠕⠖⠗⠘⠙⠚⠛⠜⠝⠞⠟⠠⠡⠢⠣⠤⠥⠦⠧⠨⠩⠪⠫⠬⠭⠮⠯⠰⠱⠲⠳⠴⠵⠶⠷⠸⠹⠺⠻⠼⠽⠾⠿]+\\s*$", + flags: "i", + args: [true] + } + ]; } /** From 47ccafcbb29cd34dafd2c157ceda326144a6e9c2 Mon Sep 17 00:00:00 2001 From: n1073645 Date: Thu, 5 Dec 2019 09:47:32 +0000 Subject: [PATCH 3/4] Linting and tidy up --- src/core/operations/FromBase85.mjs | 17 ----------------- src/core/operations/FromBraille.mjs | 7 ------- 2 files changed, 24 deletions(-) diff --git a/src/core/operations/FromBase85.mjs b/src/core/operations/FromBase85.mjs index 001f4f69..c874d5dc 100644 --- a/src/core/operations/FromBase85.mjs +++ b/src/core/operations/FromBase85.mjs @@ -33,23 +33,6 @@ class FromBase85 extends Operation { value: ALPHABET_OPTIONS }, ]; - this.patterns = [ - { - match: "^\\s*(<~)?([!-u]{4})+([!-u]{1,3})??(~>)?\\s*$", - flags: "", - args: ["!-u", true] - }, - { - match: "^\\s*(<~)?([0-9A-Z.-:+=^!/*?&<>()[]{}@%$#]{4})+([0-9A-Z.-:+=^!/*?&<>()[]{}@%$#]{1,3})??(~>)?\\s*$", - flags: "i", - args: ["0-9a-zA-Z.-:+=^!/*?&<>()[]{}@%$#", true] - }, - { - match: "^\\s*(<~)?([0-9A-Z.-:+=^!/*?&_<>()[]{}@%$#;`|~]{4})+([0-9A-Z.-:+=^!/*?&_<>()[]{}@%$#;`|~]{1,3})??(~>)?\\s*$", - flags: "i", - args: ["0-9A-Za-z!#$%&()*+-;<=>?@^_`{|~}", true] - } - ]; } /** diff --git a/src/core/operations/FromBraille.mjs b/src/core/operations/FromBraille.mjs index 60e590a3..adbcff91 100644 --- a/src/core/operations/FromBraille.mjs +++ b/src/core/operations/FromBraille.mjs @@ -25,13 +25,6 @@ class FromBraille extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = []; - this.patterns = [ - { - match: "^\\s*[⠀⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋⠌⠍⠎⠏⠐⠑⠒⠓⠔⠕⠖⠗⠘⠙⠚⠛⠜⠝⠞⠟⠠⠡⠢⠣⠤⠥⠦⠧⠨⠩⠪⠫⠬⠭⠮⠯⠰⠱⠲⠳⠴⠵⠶⠷⠸⠹⠺⠻⠼⠽⠾⠿]+\\s*$", - flags: "i", - args: [true] - } - ]; } /** From b8afbf7458671dc9cc124d9219a7af4f9f5308db Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 20 Dec 2019 15:04:27 +0000 Subject: [PATCH 4/4] Tidied up ICO extractor --- src/core/lib/FileSignatures.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/FileSignatures.mjs b/src/core/lib/FileSignatures.mjs index 0e318423..52c3d28f 100644 --- a/src/core/lib/FileSignatures.mjs +++ b/src/core/lib/FileSignatures.mjs @@ -2942,7 +2942,7 @@ export function extractBMP(bytes, offset) { export function extractICO(bytes, offset) { const stream = new Stream(bytes.slice(offset)); - // Move to number of file there are. + // Move to number of files there are. stream.moveTo(4); // Read the number of files stored in the ICO