Skip to content
Snippets Groups Projects
Commit 9777ab86 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Detect VBR bootloader

Detect if a partition has a bootloader installed on its Volume Boot
Record.
parent 57a7afd4
No related branches found
No related tags found
No related merge requests found
......@@ -152,4 +152,126 @@ def mbr_bootinfo(mbr):
return MBR_LDR[ret]
# Volume Boot Record Bootloaders
VBR_LDR = [
# GRUB Legacy
"grub1", # 0
# GRUB 2
"grub2",
# LILO (LInux LOader)
"lilo"
# SYSLINUX
"syslinux",
# Windows
"windows",
# FreeBSD's boot1 (First sector of FreeBSD slice)
"freebsd", # 5
# NetBSD's PBR
"netbsd",
# OpenBSD
"openbsd",
# ReactOS
"reactos",
# FreeDOS
"freedos",
# MS-DOS
"msdos", # 10
# HP Recovery
"hp",
# Dell Utility/Recovery
"dell",
# ISOhybrid
"isohybrid",
# Grub4Dos
"grub4dos",
# BootIt Boot Manager
"bootit", # 15
# Acronis Secure Zone
"acronis_sz",
]
# 2-byte VBR "no bootloader" signature
VBR_SIG2_NONE = (
"\x00\x00",
"\x55\xcd",
"\x69\x6e",
"\x6f\x6e",
)
# 2-byte VBR signature
VBR_SIG2 = {
"\x00\x20": 1,
"\x00\x69": 13,
"\x01\x0f": 11,
"\x02\x11": 12,
"\x04\x88": 1,
"\x06\x89": 3,
"\x07\x34": 10,
"\x07\x45": 4,
"\x08\x9e": 10,
"\x08\xcd": 4,
"\x08\xc7": 7,
"\x0b\x60": 12,
"\x0b\xd0": 4,
"\x0e\x00": 12,
"\x0f\xb6": 13,
"\x2a\x00": 8,
"\x2d\x5e": 10,
"\x31\xc0": 3,
"\x3c\x9a": 6,
"\x40\x7c": 3,
"\x42\x16": 14,
"\x44\x45": 12,
"\x48\xb4": 1,
"\x52\x72": 0,
"\x56\x26": 14,
"\x63\x8b": 9,
"\x66\x16": 4,
"\x69\x74": 15,
"\x6a\x02": 5,
"\x6f\x65": 15,
"\x74\x05": 4,
"\x7c\x3c": 1,
"\x7c\xc6": 4,
"\x7e\x1e": 14,
"\x80\x53": 2,
"\x8a\x56": 16,
"\x83\xe1": 13,
"\x8e\xc0": 4,
"\x8e\xd0": 12,
"\xaa\x75": 0,
"\xb1\x06": 3,
"\xb6\x00": 12,
"\xb6\xc6": 13,
"\xb6\xd1": 4,
"\xe8\x79": 13,
"\xe9\xd8": 4,
"\xf6\xc1": 4,
"\xfa\x33": 4,
}
# 4-byte VBR signature
VBR_SIG4 = {
"\x55\xaa\x75\x0a": 14,
"\x55\xaa\x75\x06": 4,
"\x78\x15\xb1\x06": 3,
}
def vbr_bootinfo(vbr):
"""Inspect a Volume Boot Record and return the installed bootloader"""
if vbr[0x80:0x82] in VBR_SIG2_NONE:
return "none"
try:
ret = VBR_SIG2[vbr[0x80:0x82]]
except KeyError:
try:
ret = VBR_SIG4[vbr[0x80:0x84]]
except KeyError:
return "unknown"
return MBR_LDR[ret]
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment