Skip to content

Commit

Permalink
Add MBR format
Browse files Browse the repository at this point in the history
MBR is short for Master Boot Record. It is the legacy method of booting,
the code area is limited to 446 bytes, and it's all 16-bit x86 opcodes.
Old BIOS code knows how to call into it and execute the instructions there.
MBR also has a 64-byte partition table that can store up to 4 partitions.
The GPT partitioning scheme obsoletes this, and allows for more partitions, but
that requires UEFI to work.

For more information on MBR, see: https://thestarman.pcministry.com/asm/mbr/PartTables.htm#mbr
  • Loading branch information
tlehman committed Apr 27, 2022
1 parent 8f85b43 commit 7aa764d
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
testfiles/
fq
*.swp
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion doc/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- Create a directory `format/<name>`
- Copy some similar decoder, `format/format/bson.go` is quite small, to `format/<name>/<name>.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
Expand Down
1 change: 1 addition & 0 deletions doc/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
|`json` |JSON |<sub></sub>|
|[`macho`](#macho) |Mach-O&nbsp;macOS&nbsp;executable |<sub></sub>|
|[`matroska`](#matroska) |Matroska&nbsp;file |<sub>`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`</sub>|
|`mbr` |Master&nbsp;Boot&nbsp;Record
|`mp3` |MP3&nbsp;file |<sub>`id3v2` `id3v1` `id3v11` `apev2` `mp3_frame`</sub>|
|`mp3_frame` |MPEG&nbsp;audio&nbsp;layer&nbsp;3&nbsp;frame |<sub>`xing`</sub>|
|[`mp4`](#mp4) |MPEG-4&nbsp;file&nbsp;and&nbsp;similar |<sub>`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`</sub>|
Expand Down
1 change: 1 addition & 0 deletions format/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const (
JSON = "json"
MACHO = "macho"
MATROSKA = "matroska"
MBR = "mbr"
MP3 = "mp3"
MP3_FRAME = "mp3_frame"
MP4 = "mp4"
Expand Down
22 changes: 22 additions & 0 deletions format/mbr/mbr.go
Original file line number Diff line number Diff line change
@@ -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
}
Binary file added format/mbr/testdata/mbr.bin
Binary file not shown.
9 changes: 9 additions & 0 deletions format/mbr/testdata/mbr.fqtest
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion fq.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/interp/testdata/args.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7aa764d

Please sign in to comment.