diff --git a/.gitignore b/.gitignore index 875ed6e164..3cb12dd37a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store testfiles/ fq +*.swp diff --git a/README.md b/README.md index b352e90c91..88beea6682 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ jpeg, json, [macho](doc/formats.md#macho), [matroska](doc/formats.md#matroska), +mbr, mp3, mp3_frame, [mp4](doc/formats.md#mp4), diff --git a/doc/dev.md b/doc/dev.md index 5a4f980237..0ce5d54f68 100644 --- a/doc/dev.md +++ b/doc/dev.md @@ -5,7 +5,7 @@ - Create a directory `format/` - Copy some similar decoder, `format/format/bson.go` is quite small, to `format//.go` - Cleanup and fill in the register struct, rename `format.BSON` and add it -to `format/fromat.go` and don't forget to change the string constant. +to `format/format.go` and don't forget to change the string constant. - Add an import to `format/all/all.go` ### Some general tips diff --git a/doc/formats.md b/doc/formats.md index 6a71f9ba8f..2832eb6bc3 100644 --- a/doc/formats.md +++ b/doc/formats.md @@ -56,6 +56,7 @@ |`json` |JSON || |[`macho`](#macho) |Mach-O macOS executable || |[`matroska`](#matroska) |Matroska file |`aac_frame` `av1_ccr` `av1_frame` `avc_au` `avc_dcr` `flac_frame` `flac_metadatablocks` `hevc_au` `hevc_dcr` `image` `mp3_frame` `mpeg_asc` `mpeg_pes_packet` `mpeg_spu` `opus_packet` `vorbis_packet` `vp8_frame` `vp9_cfm` `vp9_frame`| +|`mbr` |Master Boot Record |`mp3` |MP3 file |`id3v2` `id3v1` `id3v11` `apev2` `mp3_frame`| |`mp3_frame` |MPEG audio layer 3 frame |`xing`| |[`mp4`](#mp4) |MPEG-4 file and similar |`aac_frame` `av1_ccr` `av1_frame` `flac_frame` `flac_metadatablocks` `id3v2` `image` `jpeg` `mp3_frame` `avc_au` `avc_dcr` `mpeg_es` `hevc_au` `hevc_dcr` `mpeg_pes_packet` `opus_packet` `protobuf_widevine` `pssh_playready` `vorbis_packet` `vp9_frame` `vpx_ccr` `icc_profile`| diff --git a/format/all/all.go b/format/all/all.go index 2d6d01d469..726575d958 100644 --- a/format/all/all.go +++ b/format/all/all.go @@ -24,6 +24,7 @@ import ( _ "github.com/wader/fq/format/json" _ "github.com/wader/fq/format/macho" _ "github.com/wader/fq/format/matroska" + _ "github.com/wader/fq/format/mbr" _ "github.com/wader/fq/format/mp3" _ "github.com/wader/fq/format/mp4" _ "github.com/wader/fq/format/mpeg" diff --git a/format/format.go b/format/format.go index c882981769..11eff957f2 100644 --- a/format/format.go +++ b/format/format.go @@ -63,6 +63,7 @@ const ( JSON = "json" MACHO = "macho" MATROSKA = "matroska" + MBR = "mbr" MP3 = "mp3" MP3_FRAME = "mp3_frame" MP4 = "mp4" diff --git a/format/mbr/mbr.go b/format/mbr/mbr.go new file mode 100644 index 0000000000..53f8716406 --- /dev/null +++ b/format/mbr/mbr.go @@ -0,0 +1,22 @@ +package mbr + +import ( + "github.com/wader/fq/format" + "github.com/wader/fq/format/registry" + "github.com/wader/fq/pkg/decode" +) + +func init() { + registry.MustRegister(decode.Format{ + Name: format.MBR, + Description: "Master Boot Record", + DecodeFn: mbrDecode, + }) +} + +func mbrDecode(d *decode.D, in interface{}) interface{} { + d.FieldRawLen("code_area", 446*8) + d.FieldRawLen("partition_table", 64*8) + d.FieldRawLen("boot_record_sig", 2*8) + return nil +} diff --git a/format/mbr/testdata/mbr.bin b/format/mbr/testdata/mbr.bin new file mode 100644 index 0000000000..def1810b56 Binary files /dev/null and b/format/mbr/testdata/mbr.bin differ diff --git a/format/mbr/testdata/mbr.fqtest b/format/mbr/testdata/mbr.fqtest new file mode 100644 index 0000000000..87c7ca4168 --- /dev/null +++ b/format/mbr/testdata/mbr.fqtest @@ -0,0 +1,9 @@ +# head -c 512 /dev/sda > mbr.bin +$ fq . -d mbr mbr.bin + |00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: mbr.bin (mbr) +0x000|fa bc 00 7c 31 c0 8e d0 8e c0 8e d8 52 be 00 7c|...|1.......R..|| code_area: raw bits +* |until 0x1bd.7 (446) | | +0x1b0| 00 00| ..| partition_table: raw bits +0x1c0|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00|................| +* |until 0x1fd.7 (64) | | +0x1f0| 55 aa| U.| boot_record_sig: raw bits diff --git a/fq.go b/fq.go index ad5865698b..cca885489b 100644 --- a/fq.go +++ b/fq.go @@ -6,7 +6,7 @@ import ( "github.com/wader/fq/pkg/cli" ) -const version = "0.0.6" +const version = "0.0.7" func main() { cli.Main(registry.Default, version) diff --git a/pkg/interp/testdata/args.fqtest b/pkg/interp/testdata/args.fqtest index 1a7e03e9df..4a3679a272 100644 --- a/pkg/interp/testdata/args.fqtest +++ b/pkg/interp/testdata/args.fqtest @@ -145,6 +145,7 @@ jpeg Joint Photographic Experts Group file json JSON macho Mach-O macOS executable matroska Matroska file +mbr Master Boot Record mp3 MP3 file mp3_frame MPEG audio layer 3 frame mp4 MPEG-4 file and similar