Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 GRNET S.A.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Module hosting code for determining the installed boot loader on an image.
The bootloader signatures are taken from the "Boot Info Script" project:
https://github.com/arvidjaar/bootinfoscript
"""
# Master Boot Record Bootloaders
MBR_LDR = [
# GRUB Legacy
"grub1", # 0
# GRUB 2
"grub2",
# LILO (LInux LOader)
"lilo",
# SYSLINUX
"syslinux",
# Windows
"Windows",
# FreeBSD's boot0
"freebsd", # 5
# NetBSD's Stage 0/SUSE generic MBR
"netbsd",
# OpenBSD's MBR
"openbsd",
# ReactOS
"reactos",
# FreeDOS
"freedos",
# MS-DOS
"msdos", # 10
# Solaris
"solaris",
# ThinkPad MBR
"thinkpad",
# HP/Gateway
"hp",
# Plop Boot Manager
"plop",
# TrueCrypt boot loader
"truecrypt", # 15
# Paragon Partition Manager
"paragon",
# Testdisk MBR
"testdist",
# GAG Graphical Boot Manager
"gag",
# BootIt Boot Manager
"bootit",
# DiskCryptor
"diskcryptor", # 20
# xOSL (Extended Operating System Loader)
"xosl",
# Fbinst
"fbinst",
# Grub4Dos
"grub4dos",
# WEE boot manager
"wee",
# mbldr (Master Boot LoaDeR)
"mbldr", # 25
# Libparted generic boot code
"libparted",
# ISOhybrid
"isohybrid",
# Acer PQservice MBR
"pqservice",
]
# 2-bytes MBR signature
MBR_SIG2 = {
"\x3b\x48": 0,
"\xeb\x4c": 1,
"\xeb\x63": 1,
"\xeb\x04": 11,
"\x0e\xbe": 12,
"\x33\xed": 27,
"\x33\xff": 13,
"\xb8\x00": 14,
"\xea\x1e": 15,
"\xeb\x04": 11,
"\xeb\x31": 16,
"\xfa\x33": 10,
"\xfa\xeb": 2,
"\xfa\xfc": 8,
"\xfc\x31": 17,
"\xfc\x33": 18,
"\xfc\xeb": 19,
}
# 3-bytes MBR signature
MBR_SIG3 = {
"\x33\xc0\x8e": 4,
"\x33\xc0\x90": 20,
"\x33\xc0\xfa": 3,
"\xea\x05\x00": 7,
"\xea\x05\x01": 21,
"\xeb\x5e\x00": 22,
"\xeb\x5e\x80": 23,
"\xeb\x5e\x90": 24,
"\xfa\x31\xc0": 3,
"\xfa\x31\xc9": 25,
"\xfa\x31\xed": 27,
}
# 4-bytes MBR signature
MBR_SIG4 = {
"\xfa\xb8\x00\x00": 9,
"\xfa\xb8\x00\x10": 26,
}
# 8-bytes MBR signature
MBR_SIG8 = {
"\x31\xc0\x8e\xd0\xbc\x00\x7c\x8e": 6,
"\x31\xc0\x8e\xd0\xbc\x00\x7c\xfb": 28,
}
def mbr_bootinfo(mbr):
"""Inspect a Master Boot Record and return the installed bootloader"""
if mbr[:2] == '\x00\x00':
return "none"
try:
ret = MBR_SIG2[mbr[:2]]
except KeyError:
try:
ret = MBR_SIG3[mbr[:3]]
except KeyError:
try:
ret = MBR_SIG4[mbr[:4]]
except KeyError:
try:
ret = MBR_SIG8[mbr[:8]]
except KeyError:
return "unknown"
return MBR_LDR[ret]
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :