Skip to content

Commit 7aa764d

Browse files
committed
Add MBR format
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
1 parent 8f85b43 commit 7aa764d

File tree

11 files changed

+39
-2
lines changed

11 files changed

+39
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
testfiles/
33
fq
4+
*.swp

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ jpeg,
8686
json,
8787
[macho](doc/formats.md#macho),
8888
[matroska](doc/formats.md#matroska),
89+
mbr,
8990
mp3,
9091
mp3_frame,
9192
[mp4](doc/formats.md#mp4),

doc/dev.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- Create a directory `format/<name>`
66
- Copy some similar decoder, `format/format/bson.go` is quite small, to `format/<name>/<name>.go`
77
- Cleanup and fill in the register struct, rename `format.BSON` and add it
8-
to `format/fromat.go` and don't forget to change the string constant.
8+
to `format/format.go` and don't forget to change the string constant.
99
- Add an import to `format/all/all.go`
1010

1111
### Some general tips

doc/formats.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
|`json` |JSON |<sub></sub>|
5757
|[`macho`](#macho) |Mach-O&nbsp;macOS&nbsp;executable |<sub></sub>|
5858
|[`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>|
59+
|`mbr` |Master&nbsp;Boot&nbsp;Record
5960
|`mp3` |MP3&nbsp;file |<sub>`id3v2` `id3v1` `id3v11` `apev2` `mp3_frame`</sub>|
6061
|`mp3_frame` |MPEG&nbsp;audio&nbsp;layer&nbsp;3&nbsp;frame |<sub>`xing`</sub>|
6162
|[`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>|

format/all/all.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
_ "github.com/wader/fq/format/json"
2525
_ "github.com/wader/fq/format/macho"
2626
_ "github.com/wader/fq/format/matroska"
27+
_ "github.com/wader/fq/format/mbr"
2728
_ "github.com/wader/fq/format/mp3"
2829
_ "github.com/wader/fq/format/mp4"
2930
_ "github.com/wader/fq/format/mpeg"

format/format.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const (
6363
JSON = "json"
6464
MACHO = "macho"
6565
MATROSKA = "matroska"
66+
MBR = "mbr"
6667
MP3 = "mp3"
6768
MP3_FRAME = "mp3_frame"
6869
MP4 = "mp4"

format/mbr/mbr.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package mbr
2+
3+
import (
4+
"github.com/wader/fq/format"
5+
"github.com/wader/fq/format/registry"
6+
"github.com/wader/fq/pkg/decode"
7+
)
8+
9+
func init() {
10+
registry.MustRegister(decode.Format{
11+
Name: format.MBR,
12+
Description: "Master Boot Record",
13+
DecodeFn: mbrDecode,
14+
})
15+
}
16+
17+
func mbrDecode(d *decode.D, in interface{}) interface{} {
18+
d.FieldRawLen("code_area", 446*8)
19+
d.FieldRawLen("partition_table", 64*8)
20+
d.FieldRawLen("boot_record_sig", 2*8)
21+
return nil
22+
}

format/mbr/testdata/mbr.bin

512 Bytes
Binary file not shown.

format/mbr/testdata/mbr.fqtest

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# head -c 512 /dev/sda > mbr.bin
2+
$ fq . -d mbr mbr.bin
3+
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: mbr.bin (mbr)
4+
0x000|fa bc 00 7c 31 c0 8e d0 8e c0 8e d8 52 be 00 7c|...|1.......R..|| code_area: raw bits
5+
* |until 0x1bd.7 (446) | |
6+
0x1b0| 00 00| ..| partition_table: raw bits
7+
0x1c0|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00|................|
8+
* |until 0x1fd.7 (64) | |
9+
0x1f0| 55 aa| U.| boot_record_sig: raw bits

fq.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/wader/fq/pkg/cli"
77
)
88

9-
const version = "0.0.6"
9+
const version = "0.0.7"
1010

1111
func main() {
1212
cli.Main(registry.Default, version)

0 commit comments

Comments
 (0)