@@ -9,6 +9,7 @@ const category = Object.fromEntries(
9
9
"FF D8 FF E8" : [ "image" , "jpeg" ] ,
10
10
"FF D8 FF EE" : [ "image" , "jpeg" ] ,
11
11
"FF D8 FF E0" : [ "image" , "jpeg" ] ,
12
+ "52 49 46 46 ?? ?? ?? ?? 57 45 42 50" : [ "image" , "webp" ] ,
12
13
"49 44 33" : [ "audio" , "mp3" ] ,
13
14
"FF FB" : [ "audio" , "mp3" ] ,
14
15
"FF F3" : [ "audio" , "mp3" ] ,
@@ -62,7 +63,7 @@ function parseFileSig(filePath, signatures) {
62
63
const match = regex . exec ( hexString ) ;
63
64
if ( match ) {
64
65
console . log ( match . index ) ;
65
- return parseFileBody ( match , signature , match [ 1 ] . length ) ;
66
+ return parseFileBody ( match ) ;
66
67
}
67
68
}
68
69
return null ;
@@ -71,11 +72,13 @@ function parseFileSig(filePath, signatures) {
71
72
function sigToRegex ( signature ) {
72
73
// Signatures are either at the very beginning of the file or after a CRLF following the header
73
74
// 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' ) ;
75
76
}
76
77
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 ) ;
79
82
const buffer = Buffer . from ( body , 'hex' ) ;
80
83
// console.log(buffer);
81
84
// fs.writeFileSync("test.png", buffer);
0 commit comments