Skip to content

Commit b978f29

Browse files
committed
webp support
1 parent 537e261 commit b978f29

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

parser.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const category = Object.fromEntries(
99
"FF D8 FF E8" : ["image", "jpeg"],
1010
"FF D8 FF EE" : ["image", "jpeg"],
1111
"FF D8 FF E0" : ["image", "jpeg"],
12+
"52 49 46 46 ?? ?? ?? ?? 57 45 42 50" : ["image", "webp"],
1213
"49 44 33" : ["audio", "mp3"],
1314
"FF FB" : ["audio", "mp3"],
1415
"FF F3" : ["audio", "mp3"],
@@ -62,7 +63,7 @@ function parseFileSig(filePath, signatures) {
6263
const match = regex.exec(hexString);
6364
if (match) {
6465
console.log(match.index);
65-
return parseFileBody(match, signature, match[1].length);
66+
return parseFileBody(match);
6667
}
6768
}
6869
return null;
@@ -71,11 +72,13 @@ function parseFileSig(filePath, signatures) {
7172
function sigToRegex(signature) {
7273
// Signatures are either at the very beginning of the file or after a CRLF following the header
7374
// Signatures are NOT GUARANTEED to be at the beginning of the file
74-
return new RegExp(`(^|0d0a)${signature}`, 'g');
75+
return new RegExp(`(^|0d0a)${signature.replace(/\?/g, '.')}`, 'g');
7576
}
7677

77-
function parseFileBody(match, signature, offset) {
78-
const body = signature + match.input.substring(match.index + signature.length + offset);
78+
function parseFileBody(match) {
79+
const offset = match[1].length;
80+
const body = match.input.substring(match.index + offset);
81+
console.log(body);
7982
const buffer = Buffer.from(body, 'hex');
8083
// console.log(buffer);
8184
// fs.writeFileSync("test.png", buffer);

public/httpParser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const fileTypeToSignatures = {
1010
"png": ["89 50 4E 47 0D 0A 1A 0A"],
1111
"jpg": ["FF D8 FF E0", "FF D8 FF EE", "FF D8 FF DB", "FF D8 FF E0 00 10 4A 46 49 46 00 01", "FF D8 FF E8"], // missing FF D8 FF E1 ?? ?? 45 78 69 66 00 00
1212
// "gif": ["GIF87a", "GIF89a"],
13+
"webp": ["52 49 46 46 ?? ?? ?? ?? 57 45 42 50"],
1314
"zip": ["50 4B 03 04", "50 4B 05 06", "50 4B 07 08"],
1415
"exe": ["4D 5A"],
1516
"mp3": ["49 44 33", "FF FB", "FF F3"],

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h2>Configure</h2>
2929
<label for="limit">Limit results (0 for no limit):</label><br>
3030
<input class="mb" id="limitInput" type="number" name="limit" placeholder="0" required><br>
3131

32-
<label>File signatures <a target="_blank" href="https://en.wikipedia.org/wiki/List_of_file_signatures">(Hex)</a>:</label><br>
32+
<label><a target="_blank" href="https://en.wikipedia.org/wiki/List_of_file_signatures">File signatures</a> (Hex):</label><br>
3333
<label for="preset">Preset: </label>
3434
<select class="mb" name="preset" id="preset">
3535
<option value="none" selected>None</option>

0 commit comments

Comments
 (0)