ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/pbcdedit/pbcdedit
(Generate patch)

Comparing pbcdedit/pbcdedit (file contents):
Revision 1.25 by root, Wed Aug 14 23:38:53 2019 UTC vs.
Revision 1.39 by root, Thu Aug 15 23:49:22 2019 UTC

17# 17#
18# You should have received a copy of the GNU General Public License 18# You should have received a copy of the GNU General Public License
19# along with this program. If not, see <https://www.gnu.org/licenses/>. 19# along with this program. If not, see <https://www.gnu.org/licenses/>.
20# 20#
21 21
22use 5.014; # numerous features needed 22use 5.016; # numerous features need 5.14, __SUB__ needs 5.16
23 23
24our $VERSION = '1.0'; 24our $VERSION = '1.2';
25our $JSON_VERSION = 1; # the versiobn of the json objects generated by this program 25our $JSON_VERSION = 2; # the version of the json objects generated by this program
26
27our $CHANGELOG = <<EOF;
281.2 Fri Aug 16 00:20:41 CEST 2019
29 - bcde element names now depend on the bcd object type they are in,
30 also affects "elements" output.
31 - json schema bumped to 2.
32 - new version command.
33 - numerous minor bugfixes.
34
35EOF
26 36
27=head1 NAME 37=head1 NAME
28 38
29 pbcdedit - portable boot configuration data (BCD) store editor 39 pbcdedit - portable boot configuration data (BCD) store editor
30 40
31=head1 SYNOPSIS 41=head1 SYNOPSIS
32 42
33 pbcdedit help # output manual page 43 pbcdedit help # output manual page
44 pbcdedit version # output version and changelog
45
34 pbcdedit export path/to/BCD # output BCD hive as JSON 46 pbcdedit export path/to/BCD # output BCD hive as JSON
35 pbcdedit import path/to/bcd # convert standard input to BCD hive 47 pbcdedit import path/to/BCD # convert standard input to BCD hive
36 pbcdedit edit path/to/BCD edit-instructions... 48 pbcdedit edit path/to/BCD edit-instructions...
37 49
38 pbcdedit objects # list all supported object aliases and types 50 pbcdedit objects # list all supported object aliases and types
39 pbcdedit elements # list all supported bcd element aliases 51 pbcdedit elements # list all supported bcd element aliases
40 52
58 70
59=item Does not rely on Windows 71=item Does not rely on Windows
60 72
61As the "portable" in the name implies, this program does not rely on 73As the "portable" in the name implies, this program does not rely on
62C<bcdedit> or other windows programs or libraries, it works on any system 74C<bcdedit> or other windows programs or libraries, it works on any system
63that supports at least perl version 5.14. 75that supports at least perl version 5.16.
64 76
65=item Decodes and encodes BCD device elements 77=item Decodes and encodes BCD device elements
66 78
67PBCDEDIT can concisely decode and encode BCD device element contents. This 79PBCDEDIT can concisely decode and encode BCD device element contents. This
68is pretty unique, and offers a lot of potential that can't be realised 80is pretty unique, and offers a lot of potential that can't be realised
76 88
77=back 89=back
78 90
79The target audience for this program is professionals and tinkerers who 91The target audience for this program is professionals and tinkerers who
80are ready to invest time into learning how it works. It is not an easy 92are ready to invest time into learning how it works. It is not an easy
81program to use and requires patience and a good understanding of BCD data 93program to use and requires patience and a good understanding of BCD
82stores. 94stores.
83 95
84 96
85=head1 SUBCOMMANDS 97=head1 SUBCOMMANDS
86 98
91 103
92=item C<help> 104=item C<help>
93 105
94Displays the whole manual page (this document). 106Displays the whole manual page (this document).
95 107
108=item C<version>
109
110This outputs the PBCDEDIT version, the JSON schema version it uses and the
111full log of changes.
112
96=item C<export> F<path> 113=item C<export> F<path>
97 114
98Reads a BCD data store and writes a JSON representation of it to standard 115Reads a BCD data store and writes a JSON representation of it to standard
99output. 116output.
100 117
112 129
113=item C<edit> F<path> I<instructions...> 130=item C<edit> F<path> I<instructions...>
114 131
115Load a BCD data store, apply some instructions to it, and save it again. 132Load a BCD data store, apply some instructions to it, and save it again.
116 133
117See the section L<EDITING BCD DATA STORES>, below, for more info. 134See the section L<EDITING BCD STORES>, below, for more info.
118 135
119=item C<parse> F<path> I<instructions...> 136=item C<parse> F<path> I<instructions...>
120 137
121Same as C<edit>, above, except it doesn't save the data store again. Can 138Same as C<edit>, above, except it doesn't save the data store again. Can
122be useful to extract some data from it. 139be useful to extract some data from it.
146 163
147With C<--json> it prints similar information as a JSON object, for easier parsing. 164With C<--json> it prints similar information as a JSON object, for easier parsing.
148 165
149=item C<export-regf> F<path> 166=item C<export-regf> F<path>
150 167
151This has nothing to do with BCD data stores - it takes a registry hive 168This has nothing to do with BCD stores, but simply exposes PCBEDIT's
169internal registry hive reader - it takes a registry hive file as argument
152file as argument and outputs a JSON representation of it to standard 170and outputs a JSON representation of it to standard output.
153output.
154 171
155Hive versions 1.2 till 1.6 are supported. 172Hive versions 1.2 till 1.6 are supported.
156 173
157=item C<import-regf> F<path> 174=item C<import-regf> F<path>
158 175
170a BCD hive you will most likely destroy it. 187a BCD hive you will most likely destroy it.
171 188
172=back 189=back
173 190
174 191
175=head1 BCD DATA STORE REPRESENTATION FORMAT 192=head1 BCD STORE REPRESENTATION FORMAT
176 193
177A BCD data store is represented as a JSON object with one special key, 194A BCD data store is represented as a JSON object with one special key,
178C<meta>, and one key per BCD object. That is, each BCD object becomes 195C<meta>, and one key per BCD object. That is, each BCD object becomes
179one key-value pair in the object, and an additional key called C<meta> 196one key-value pair in the object, and an additional key called C<meta>
180contains meta information. 197contains meta information.
216 } 233 }
217 234
218=head2 Minimal BCD to boot windows 235=head2 Minimal BCD to boot windows
219 236
220Experimentally I found the following BCD is the minimum required to 237Experimentally I found the following BCD is the minimum required to
221successfully boot any post-XP version of Windows (suitable C<device> and 238successfully boot any post-XP version of Windows (assuming suitable
222C<osdevice> values, of course): 239C<device> and C<osdevice> values, of course, and assuming a BIOS boot -
240for UEFI, you should use F<winload.efi> instead of F<winload.exe>):
223 241
224 { 242 {
225 "{bootmgr}" : { 243 "{bootmgr}" : {
226 "resumeobject" : "{45b547a7-8ca6-4417-9eb0-a257b61f35b4}" 244 "default" : "{45b547a7-8ca6-4417-9eb0-a257b61f35b4}"
227 }, 245 },
228 246
229 "{45b547a7-8ca6-4417-9eb0-a257b61f35b1}" : { 247 "{45b547a7-8ca6-4417-9eb0-a257b61f35b1}" : {
230 "type" : "application::osloader", 248 "type" : "application::osloader",
231 "description" : "Windows Boot", 249 "description" : "Windows Boot",
358 376
359This represents a single GUID value wrapped in curly braces. It is used a 377This represents a single GUID value wrapped in curly braces. It is used a
360lot to refer from one BCD object to other one. 378lot to refer from one BCD object to other one.
361 379
362For example, The C<{bootmgr}> object might refer to a resume boot option 380For example, The C<{bootmgr}> object might refer to a resume boot option
363using C<resumeobject>: 381using C<default>:
364 382
365 "resumeobject" : "{7ae02178-821d-11e7-8813-1c872c5f5ab0}", 383 "default" : "{7ae02178-821d-11e7-8813-1c872c5f5ab0}",
366 384
367Human readable aliases are used and allowed. 385Human readable aliases are used and allowed.
368 386
369=item guid list 387=item guid list
370 388
709seems to be always there on this kind of entry. 727seems to be always there on this kind of entry.
710 728
711If you have some good examples to add here, feel free to mail me. 729If you have some good examples to add here, feel free to mail me.
712 730
713 731
714=head1 EDITING BCD DATA STORES 732=head1 EDITING BCD STORES
715 733
716The C<edit> and C<parse> subcommands allow you to read a BCD data store 734The C<edit> and C<parse> subcommands allow you to read a BCD data store
717and modify it or extract data from it. This is done by executing a series 735and modify it or extract data from it. This is done by executing a series
718of "editing instructions" which are explained here. 736of "editing instructions" which are explained here.
719 737
735Similar to C<get>, but sets the element to the given I<value> instead. 753Similar to C<get>, but sets the element to the given I<value> instead.
736 754
737Example: change the bootmgr default too 755Example: change the bootmgr default too
738C<{b097d2ad-bc00-11e9-8a9a-525400123456}>: 756C<{b097d2ad-bc00-11e9-8a9a-525400123456}>:
739 757
740 pbcdedit edit BCD set "{bootmgr}" resumeobject "{b097d2ad-bc00-11e9-8a9a-525400123456}" 758 pbcdedit edit BCD set "{bootmgr}" default "{b097d2ad-bc00-11e9-8a9a-525400123456}"
741 759
742=item C<eval> I<perlcode> 760=item C<eval> I<perlcode>
743 761
744This takes the next argument, interprets it as Perl code and 762This takes the next argument, interprets it as Perl code and
745evaluates it. This allows you to do more complicated modifications or 763evaluates it. This allows you to do more complicated modifications or
768 786
769 pbcdedit edit BCD eval 'say $BCD->{$DEFAULT}{description}' 787 pbcdedit edit BCD eval 'say $BCD->{$DEFAULT}{description}'
770 788
771The example given for C<set> could be expressed like this: 789The example given for C<set> could be expressed like this:
772 790
773 pbcdedit edit BCD eval '$BCD->{$DEFAULT}{resumeobject} = "{b097d2ad-bc00-11e9-8a9a-525400123456}"' 791 pbcdedit edit BCD eval '$BCD->{"{bootmgr}"{default} = "{b097d2ad-bc00-11e9-8a9a-525400123456}"'
774 792
775=item C<do> I<path> 793=item C<do> I<path>
776 794
777Similar to C<eval>, above, but instead of using the argument as perl code, 795Similar to C<eval>, above, but instead of using the argument as perl code,
778it loads the perl code from the given file and executes it. This makes it 796it loads the perl code from the given file and executes it. This makes it
823free to change and redistribute it. There is NO WARRANTY, to the extent 841free to change and redistribute it. There is NO WARRANTY, to the extent
824permitted by law. 842permitted by law.
825 843
826=cut 844=cut
827 845
828BEGIN { require "common/sense.pm"; common::sense->import } # common sense is optional, but recommended 846# common sense is optional, but recommended
847BEGIN { eval { require "common/sense.pm"; } && common::sense->import }
829 848
830use Data::Dump; 849no warnings 'portable'; # avoid 32 bit integer warnings
850
831use Encode (); 851use Encode ();
832use List::Util (); 852use List::Util ();
833use IO::Handle (); 853use IO::Handle ();
834use Time::HiRes (); 854use Time::HiRes ();
835 855
858 or die "$path: short read\n"; 878 or die "$path: short read\n";
859 879
860 $buf 880 $buf
861} 881}
862 882
863# sources and resources used for this: 883# sources and resources used for writing pbcdedit
884#
864# registry: 885# registry:
865# https://github.com/msuhanov/regf/blob/master/Windows%20registry%20file%20format%20specification.md 886# https://github.com/msuhanov/regf/blob/master/Windows%20registry%20file%20format%20specification.md
866# http://amnesia.gtisc.gatech.edu/~moyix/suzibandit.ltd.uk/MSc/ 887# http://amnesia.gtisc.gatech.edu/~moyix/suzibandit.ltd.uk/MSc/
867# bcd: 888# bcd:
868# http://www.geoffchappell.com/notes/windows/boot/bcd/index.htm 889# http://www.geoffchappell.com/notes/windows/boot/bcd/index.htm
1356sub BCDE_FORMAT_GUID_LIST () { 0x04000000 } 1377sub BCDE_FORMAT_GUID_LIST () { 0x04000000 }
1357sub BCDE_FORMAT_INTEGER () { 0x05000000 } 1378sub BCDE_FORMAT_INTEGER () { 0x05000000 }
1358sub BCDE_FORMAT_BOOLEAN () { 0x06000000 } 1379sub BCDE_FORMAT_BOOLEAN () { 0x06000000 }
1359sub BCDE_FORMAT_INTEGER_LIST () { 0x07000000 } 1380sub BCDE_FORMAT_INTEGER_LIST () { 0x07000000 }
1360 1381
1361sub dec_device;
1362sub enc_device;
1363
1364sub enc_integer($) { 1382sub enc_integer($) {
1365 no warnings 'portable'; # ugh
1366 my $value = shift; 1383 my $value = shift;
1367 $value = oct $value if $value =~ /^0[bBxX]/; 1384 $value = oct $value if $value =~ /^0[bBxX]/;
1368 unpack "H*", pack "Q<", $value 1385 unpack "H*", pack "Q<", $value
1369} 1386}
1387
1388sub enc_device($$);
1389sub dec_device($$);
1370 1390
1371our %bcde_dec = ( 1391our %bcde_dec = (
1372 BCDE_FORMAT_DEVICE , \&dec_device, 1392 BCDE_FORMAT_DEVICE , \&dec_device,
1373# # for round-trip verification 1393# # for round-trip verification
1374# BCDE_FORMAT_DEVICE , sub { 1394# BCDE_FORMAT_DEVICE , sub {
1384 BCDE_FORMAT_BOOLEAN , sub { shift eq "00" ? 0 : 1 }, 1404 BCDE_FORMAT_BOOLEAN , sub { shift eq "00" ? 0 : 1 },
1385 BCDE_FORMAT_INTEGER_LIST, sub { join " ", unpack "Q*", pack "H*", shift }, # not sure if this cna be 4 bytes 1405 BCDE_FORMAT_INTEGER_LIST, sub { join " ", unpack "Q*", pack "H*", shift }, # not sure if this cna be 4 bytes
1386); 1406);
1387 1407
1388our %bcde_enc = ( 1408our %bcde_enc = (
1389 BCDE_FORMAT_DEVICE , sub { binary => enc_device shift }, 1409 BCDE_FORMAT_DEVICE , sub { binary => enc_device $_[0], $_[1] },
1390 BCDE_FORMAT_STRING , sub { sz => shift }, 1410 BCDE_FORMAT_STRING , sub { sz => shift },
1391 BCDE_FORMAT_GUID , sub { sz => "{" . (dec_guid enc_wguid shift) . "}" }, 1411 BCDE_FORMAT_GUID , sub { sz => "{" . (dec_guid enc_wguid shift) . "}" },
1392 BCDE_FORMAT_GUID_LIST , sub { multi_sz => [map "{" . (dec_guid enc_wguid $_) . "}", split /\s+/, shift ] }, 1412 BCDE_FORMAT_GUID_LIST , sub { multi_sz => [map "{" . (dec_guid enc_wguid $_) . "}", split /\s+/, shift ] },
1393 BCDE_FORMAT_INTEGER , sub { binary => enc_integer shift }, 1413 BCDE_FORMAT_INTEGER , sub { binary => enc_integer shift },
1394 BCDE_FORMAT_BOOLEAN , sub { binary => shift ? "01" : "00" }, 1414 BCDE_FORMAT_BOOLEAN , sub { binary => shift ? "01" : "00" },
1395 BCDE_FORMAT_INTEGER_LIST, sub { binary => join "", map enc_integer $_, split /\s+/, shift }, 1415 BCDE_FORMAT_INTEGER_LIST, sub { binary => join "", map enc_integer $_, split /\s+/, shift },
1396); 1416);
1397 1417
1398# BCD Elements 1418# BCD Elements
1399our %bcde = ( 1419our %bcde_byclass = (
1420 any => {
1400 0x11000001 => 'device', 1421 0x11000001 => 'device',
1401 0x12000002 => 'path', 1422 0x12000002 => 'path',
1402 0x12000004 => 'description', 1423 0x12000004 => 'description',
1403 0x12000005 => 'locale', 1424 0x12000005 => 'locale',
1404 0x14000006 => 'inherit', 1425 0x14000006 => 'inherit',
1405 0x15000007 => 'truncatememory', 1426 0x15000007 => 'truncatememory',
1406 0x14000008 => 'recoverysequence', 1427 0x14000008 => 'recoverysequence',
1407 0x16000009 => 'recoveryenabled', 1428 0x16000009 => 'recoveryenabled',
1408 0x1700000a => 'badmemorylist', 1429 0x1700000a => 'badmemorylist',
1409 0x1600000b => 'badmemoryaccess', 1430 0x1600000b => 'badmemoryaccess',
1410 0x1500000c => 'firstmegabytepolicy', 1431 0x1500000c => 'firstmegabytepolicy',
1411 0x1500000d => 'relocatephysical', 1432 0x1500000d => 'relocatephysical',
1412 0x1500000e => 'avoidlowmemory', 1433 0x1500000e => 'avoidlowmemory',
1413 0x1600000f => 'traditionalkseg', 1434 0x1600000f => 'traditionalkseg',
1414 0x16000010 => 'bootdebug', 1435 0x16000010 => 'bootdebug',
1415 0x15000011 => 'debugtype', 1436 0x15000011 => 'debugtype',
1416 0x15000012 => 'debugaddress', 1437 0x15000012 => 'debugaddress',
1417 0x15000013 => 'debugport', 1438 0x15000013 => 'debugport',
1418 0x15000014 => 'baudrate', 1439 0x15000014 => 'baudrate',
1419 0x15000015 => 'channel', 1440 0x15000015 => 'channel',
1420 0x12000016 => 'targetname', 1441 0x12000016 => 'targetname',
1421 0x16000017 => 'noumex', 1442 0x16000017 => 'noumex',
1422 0x15000018 => 'debugstart', 1443 0x15000018 => 'debugstart',
1423 0x12000019 => 'busparams', 1444 0x12000019 => 'busparams',
1424 0x1500001a => 'hostip', 1445 0x1500001a => 'hostip',
1425 0x1500001b => 'port', 1446 0x1500001b => 'port',
1426 0x1600001c => 'dhcp', 1447 0x1600001c => 'dhcp',
1427 0x1200001d => 'key', 1448 0x1200001d => 'key',
1428 0x1600001e => 'vm', 1449 0x1600001e => 'vm',
1429 0x16000020 => 'bootems', 1450 0x16000020 => 'bootems',
1430 0x15000022 => 'emsport', 1451 0x15000022 => 'emsport',
1431 0x15000023 => 'emsbaudrate', 1452 0x15000023 => 'emsbaudrate',
1432 0x12000030 => 'loadoptions', 1453 0x12000030 => 'loadoptions',
1433 0x16000040 => 'advancedoptions', 1454 0x16000040 => 'advancedoptions',
1434 0x16000041 => 'optionsedit', 1455 0x16000041 => 'optionsedit',
1435 0x15000042 => 'keyringaddress', 1456 0x15000042 => 'keyringaddress',
1436 0x11000043 => 'bootstatdevice', 1457 0x11000043 => 'bootstatdevice',
1437 0x12000044 => 'bootstatfilepath', 1458 0x12000044 => 'bootstatfilepath',
1438 0x16000045 => 'preservebootstat', 1459 0x16000045 => 'preservebootstat',
1439 0x16000046 => 'graphicsmodedisabled', 1460 0x16000046 => 'graphicsmodedisabled',
1440 0x15000047 => 'configaccesspolicy', 1461 0x15000047 => 'configaccesspolicy',
1441 0x16000048 => 'nointegritychecks', 1462 0x16000048 => 'nointegritychecks',
1442 0x16000049 => 'testsigning', 1463 0x16000049 => 'testsigning',
1443 0x1200004a => 'fontpath', 1464 0x1200004a => 'fontpath',
1444 0x1500004b => 'integrityservices', 1465 0x1500004b => 'integrityservices',
1445 0x1500004c => 'volumebandid', 1466 0x1500004c => 'volumebandid',
1446 0x16000050 => 'extendedinput', 1467 0x16000050 => 'extendedinput',
1447 0x15000051 => 'initialconsoleinput', 1468 0x15000051 => 'initialconsoleinput',
1448 0x15000052 => 'graphicsresolution', 1469 0x15000052 => 'graphicsresolution',
1449 0x16000053 => 'restartonfailure', 1470 0x16000053 => 'restartonfailure',
1450 0x16000054 => 'highestmode', 1471 0x16000054 => 'highestmode',
1451 0x16000060 => 'isolatedcontext', 1472 0x16000060 => 'isolatedcontext',
1452 0x15000065 => 'displaymessage', 1473 0x15000065 => 'displaymessage',
1453 0x15000066 => 'displaymessageoverride', 1474 0x15000066 => 'displaymessageoverride',
1454 0x16000068 => 'nobootuxtext', 1475 0x16000068 => 'nobootuxtext',
1455 0x16000069 => 'nobootuxprogress', 1476 0x16000069 => 'nobootuxprogress',
1456 0x1600006a => 'nobootuxfade', 1477 0x1600006a => 'nobootuxfade',
1457 0x1600006b => 'bootuxreservepooldebug', 1478 0x1600006b => 'bootuxreservepooldebug',
1458 0x1600006c => 'bootuxdisabled', 1479 0x1600006c => 'bootuxdisabled',
1459 0x1500006d => 'bootuxfadeframes', 1480 0x1500006d => 'bootuxfadeframes',
1460 0x1600006e => 'bootuxdumpstats', 1481 0x1600006e => 'bootuxdumpstats',
1461 0x1600006f => 'bootuxshowstats', 1482 0x1600006f => 'bootuxshowstats',
1462 0x16000071 => 'multibootsystem', 1483 0x16000071 => 'multibootsystem',
1463 0x16000072 => 'nokeyboard', 1484 0x16000072 => 'nokeyboard',
1464 0x15000073 => 'aliaswindowskey', 1485 0x15000073 => 'aliaswindowskey',
1465 0x16000074 => 'bootshutdowndisabled', 1486 0x16000074 => 'bootshutdowndisabled',
1466 0x15000075 => 'performancefrequency', 1487 0x15000075 => 'performancefrequency',
1467 0x15000076 => 'securebootrawpolicy', 1488 0x15000076 => 'securebootrawpolicy',
1468 0x17000077 => 'allowedinmemorysettings', 1489 0x17000077 => 'allowedinmemorysettings',
1469 0x15000079 => 'bootuxtransitiontime', 1490 0x15000079 => 'bootuxtransitiontime',
1470 0x1600007a => 'mobilegraphics', 1491 0x1600007a => 'mobilegraphics',
1471 0x1600007b => 'forcefipscrypto', 1492 0x1600007b => 'forcefipscrypto',
1472 0x1500007d => 'booterrorux', 1493 0x1500007d => 'booterrorux',
1473 0x1600007e => 'flightsigning', 1494 0x1600007e => 'flightsigning',
1474 0x1500007f => 'measuredbootlogformat', 1495 0x1500007f => 'measuredbootlogformat',
1475 0x15000080 => 'displayrotation', 1496 0x15000080 => 'displayrotation',
1476 0x15000081 => 'logcontrol', 1497 0x15000081 => 'logcontrol',
1477 0x16000082 => 'nofirmwaresync', 1498 0x16000082 => 'nofirmwaresync',
1478 0x11000084 => 'windowssyspart', 1499 0x11000084 => 'windowssyspart',
1479 0x16000087 => 'numlock', 1500 0x16000087 => 'numlock',
1480 0x22000001 => 'bpbstring', 1501 0x26000202 => 'skipffumode',
1502 0x26000203 => 'forceffumode',
1503 0x25000510 => 'chargethreshold',
1504 0x26000512 => 'offmodecharging',
1505 0x25000aaa => 'bootflow',
1506 0x45000001 => 'devicetype',
1507 0x42000002 => 'applicationrelativepath',
1508 0x42000003 => 'ramdiskdevicerelativepath',
1509 0x46000004 => 'omitosloaderelements',
1510 0x47000006 => 'elementstomigrate',
1511 0x46000010 => 'recoveryos',
1512 },
1513 bootapp => {
1514 0x26000145 => 'enablebootdebugpolicy',
1515 0x26000146 => 'enablebootorderclean',
1516 0x26000147 => 'enabledeviceid',
1517 0x26000148 => 'enableffuloader',
1518 0x26000149 => 'enableiuloader',
1519 0x2600014a => 'enablemassstorage',
1520 0x2600014b => 'enablerpmbprovisioning',
1521 0x2600014c => 'enablesecurebootpolicy',
1522 0x2600014d => 'enablestartcharge',
1523 0x2600014e => 'enableresettpm',
1524 },
1525 bootmgr => {
1481 0x24000001 => 'displayorder', 1526 0x24000001 => 'displayorder',
1482 0x21000001 => 'filedevice',
1483 0x21000001 => 'osdevice',
1484 0x25000001 => 'passcount',
1485 0x26000001 => 'pxesoftreboot',
1486 0x22000002 => 'applicationname',
1487 0x24000002 => 'bootsequence', 1527 0x24000002 => 'bootsequence',
1488 0x22000002 => 'filepath',
1489 0x22000002 => 'systemroot',
1490 0x25000002 => 'testmix',
1491 0x26000003 => 'cacheenable',
1492 0x26000003 => 'customsettings',
1493 0x23000003 => 'default', 1528 0x23000003 => 'default',
1494 0x25000003 => 'failurecount',
1495 0x23000003 => 'resumeobject',
1496 0x26000004 => 'failuresenabled',
1497 0x26000004 => 'pae',
1498 0x26000004 => 'stampdisks',
1499 0x25000004 => 'testtofail',
1500 0x25000004 => 'timeout', 1529 0x25000004 => 'timeout',
1501 0x21000005 => 'associatedosdevice',
1502 0x26000005 => 'cacheenable',
1503 0x26000005 => 'resume', 1530 0x26000005 => 'resume',
1504 0x25000005 => 'stridefailcount',
1505 0x26000006 => 'debugoptionenabled',
1506 0x25000006 => 'invcfailcount',
1507 0x23000006 => 'resumeobject', 1531 0x23000006 => 'resumeobject',
1508 0x25000007 => 'bootux',
1509 0x25000007 => 'matsfailcount',
1510 0x24000007 => 'startupsequence', 1532 0x24000007 => 'startupsequence',
1511 0x25000008 => 'bootmenupolicy',
1512 0x25000008 => 'randfailcount',
1513 0x25000009 => 'chckrfailcount',
1514 0x26000010 => 'detecthal',
1515 0x24000010 => 'toolsdisplayorder', 1533 0x24000010 => 'toolsdisplayorder',
1516 0x22000011 => 'kernel',
1517 0x22000012 => 'hal',
1518 0x22000013 => 'dbgtransport',
1519 0x26000020 => 'displaybootmenu', 1534 0x26000020 => 'displaybootmenu',
1520 0x25000020 => 'nx',
1521 0x26000021 => 'noerrordisplay', 1535 0x26000021 => 'noerrordisplay',
1522 0x25000021 => 'pae',
1523 0x21000022 => 'bcddevice', 1536 0x21000022 => 'bcddevice',
1524 0x26000022 => 'winpe',
1525 0x22000023 => 'bcdfilepath', 1537 0x22000023 => 'bcdfilepath',
1526 0x26000024 => 'hormenabled', 1538 0x26000024 => 'hormenabled',
1527 0x26000024 => 'hormenabled',
1528 0x26000024 => 'nocrashautoreboot',
1529 0x26000025 => 'hiberboot', 1539 0x26000025 => 'hiberboot',
1530 0x26000025 => 'lastknowngood',
1531 0x26000026 => 'oslnointegritychecks',
1532 0x22000026 => 'passwordoverride', 1540 0x22000026 => 'passwordoverride',
1533 0x26000027 => 'osltestsigning',
1534 0x22000027 => 'pinpassphraseoverride', 1541 0x22000027 => 'pinpassphraseoverride',
1535 0x26000028 => 'processcustomactionsfirst', 1542 0x26000028 => 'processcustomactionsfirst',
1536 0x27000030 => 'customactions', 1543 0x27000030 => 'customactions',
1537 0x26000030 => 'nolowmem',
1538 0x26000031 => 'persistbootsequence', 1544 0x26000031 => 'persistbootsequence',
1539 0x25000031 => 'removememory',
1540 0x25000032 => 'increaseuserva',
1541 0x26000032 => 'skipstartupsequence', 1545 0x26000032 => 'skipstartupsequence',
1542 0x25000033 => 'perfmem',
1543 0x22000040 => 'fverecoveryurl', 1546 0x22000040 => 'fverecoveryurl',
1544 0x26000040 => 'vga',
1545 0x22000041 => 'fverecoverymessage', 1547 0x22000041 => 'fverecoverymessage',
1548 },
1549 device => {
1550 0x35000001 => 'ramdiskimageoffset',
1551 0x35000002 => 'ramdisktftpclientport',
1552 0x31000003 => 'ramdisksdidevice',
1553 0x32000004 => 'ramdisksdipath',
1554 0x35000005 => 'ramdiskimagelength',
1555 0x36000006 => 'exportascd',
1556 0x35000007 => 'ramdisktftpblocksize',
1557 0x35000008 => 'ramdisktftpwindowsize',
1558 0x36000009 => 'ramdiskmcenabled',
1559 0x3600000a => 'ramdiskmctftpfallback',
1560 0x3600000b => 'ramdisktftpvarwindow',
1561 },
1562 memdiag => {
1563 0x25000001 => 'passcount',
1564 0x25000002 => 'testmix',
1565 0x25000003 => 'failurecount',
1566 0x26000003 => 'cacheenable',
1567 0x25000004 => 'testtofail',
1568 0x26000004 => 'failuresenabled',
1569 0x25000005 => 'stridefailcount',
1570 0x26000005 => 'cacheenable',
1571 0x25000006 => 'invcfailcount',
1572 0x25000007 => 'matsfailcount',
1573 0x25000008 => 'randfailcount',
1574 0x25000009 => 'chckrfailcount',
1575 },
1576 ntldr => {
1577 0x22000001 => 'bpbstring',
1578 },
1579 osloader => {
1580 0x21000001 => 'osdevice',
1581 0x22000002 => 'systemroot',
1582 0x23000003 => 'resumeobject',
1583 0x26000004 => 'stampdisks',
1584 0x26000010 => 'detecthal',
1585 0x22000011 => 'kernel',
1586 0x22000012 => 'hal',
1587 0x22000013 => 'dbgtransport',
1588 0x25000020 => 'nx',
1589 0x25000021 => 'pae',
1590 0x26000022 => 'winpe',
1591 0x26000024 => 'nocrashautoreboot',
1592 0x26000025 => 'lastknowngood',
1593 0x26000026 => 'oslnointegritychecks',
1594 0x26000027 => 'osltestsigning',
1595 0x26000030 => 'nolowmem',
1596 0x25000031 => 'removememory',
1597 0x25000032 => 'increaseuserva',
1598 0x25000033 => 'perfmem',
1599 0x26000040 => 'vga',
1546 0x26000041 => 'quietboot', 1600 0x26000041 => 'quietboot',
1547 0x26000042 => 'novesa', 1601 0x26000042 => 'novesa',
1548 0x26000043 => 'novga', 1602 0x26000043 => 'novga',
1549 0x25000050 => 'clustermodeaddressing', 1603 0x25000050 => 'clustermodeaddressing',
1550 0x26000051 => 'usephysicaldestination', 1604 0x26000051 => 'usephysicaldestination',
1551 0x25000052 => 'restrictapiccluster', 1605 0x25000052 => 'restrictapiccluster',
1552 0x22000053 => 'evstore', 1606 0x22000053 => 'evstore',
1553 0x26000054 => 'uselegacyapicmode', 1607 0x26000054 => 'uselegacyapicmode',
1554 0x26000060 => 'onecpu', 1608 0x26000060 => 'onecpu',
1555 0x25000061 => 'numproc', 1609 0x25000061 => 'numproc',
1556 0x26000062 => 'maxproc', 1610 0x26000062 => 'maxproc',
1557 0x25000063 => 'configflags', 1611 0x25000063 => 'configflags',
1558 0x26000064 => 'maxgroup', 1612 0x26000064 => 'maxgroup',
1559 0x26000065 => 'groupaware', 1613 0x26000065 => 'groupaware',
1560 0x25000066 => 'groupsize', 1614 0x25000066 => 'groupsize',
1561 0x26000070 => 'usefirmwarepcisettings', 1615 0x26000070 => 'usefirmwarepcisettings',
1562 0x25000071 => 'msi', 1616 0x25000071 => 'msi',
1563 0x25000072 => 'pciexpress', 1617 0x25000072 => 'pciexpress',
1564 0x25000080 => 'safeboot', 1618 0x25000080 => 'safeboot',
1565 0x26000081 => 'safebootalternateshell', 1619 0x26000081 => 'safebootalternateshell',
1566 0x26000090 => 'bootlog', 1620 0x26000090 => 'bootlog',
1567 0x26000091 => 'sos', 1621 0x26000091 => 'sos',
1568 0x260000a0 => 'debug', 1622 0x260000a0 => 'debug',
1569 0x260000a1 => 'halbreakpoint', 1623 0x260000a1 => 'halbreakpoint',
1570 0x260000a2 => 'useplatformclock', 1624 0x260000a2 => 'useplatformclock',
1571 0x260000a3 => 'forcelegacyplatform', 1625 0x260000a3 => 'forcelegacyplatform',
1572 0x260000a4 => 'useplatformtick', 1626 0x260000a4 => 'useplatformtick',
1573 0x260000a5 => 'disabledynamictick', 1627 0x260000a5 => 'disabledynamictick',
1574 0x250000a6 => 'tscsyncpolicy', 1628 0x250000a6 => 'tscsyncpolicy',
1575 0x260000b0 => 'ems', 1629 0x260000b0 => 'ems',
1576 0x250000c0 => 'forcefailure', 1630 0x250000c0 => 'forcefailure',
1577 0x250000c1 => 'driverloadfailurepolicy', 1631 0x250000c1 => 'driverloadfailurepolicy',
1578 0x250000c2 => 'bootmenupolicy', 1632 0x250000c2 => 'bootmenupolicy',
1579 0x260000c3 => 'onetimeadvancedoptions', 1633 0x260000c3 => 'onetimeadvancedoptions',
1580 0x260000c4 => 'onetimeoptionsedit', 1634 0x260000c4 => 'onetimeoptionsedit',
1581 0x250000e0 => 'bootstatuspolicy', 1635 0x250000e0 => 'bootstatuspolicy',
1582 0x260000e1 => 'disableelamdrivers', 1636 0x260000e1 => 'disableelamdrivers',
1583 0x250000f0 => 'hypervisorlaunchtype', 1637 0x250000f0 => 'hypervisorlaunchtype',
1584 0x220000f1 => 'hypervisorpath', 1638 0x220000f1 => 'hypervisorpath',
1585 0x260000f2 => 'hypervisordebug', 1639 0x260000f2 => 'hypervisordebug',
1586 0x250000f3 => 'hypervisordebugtype', 1640 0x250000f3 => 'hypervisordebugtype',
1587 0x250000f4 => 'hypervisordebugport', 1641 0x250000f4 => 'hypervisordebugport',
1588 0x250000f5 => 'hypervisorbaudrate', 1642 0x250000f5 => 'hypervisorbaudrate',
1589 0x250000f6 => 'hypervisorchannel', 1643 0x250000f6 => 'hypervisorchannel',
1590 0x250000f7 => 'bootux', 1644 0x250000f7 => 'bootux',
1591 0x260000f8 => 'hypervisordisableslat', 1645 0x260000f8 => 'hypervisordisableslat',
1592 0x220000f9 => 'hypervisorbusparams', 1646 0x220000f9 => 'hypervisorbusparams',
1593 0x250000fa => 'hypervisornumproc', 1647 0x250000fa => 'hypervisornumproc',
1594 0x250000fb => 'hypervisorrootprocpernode', 1648 0x250000fb => 'hypervisorrootprocpernode',
1595 0x260000fc => 'hypervisoruselargevtlb', 1649 0x260000fc => 'hypervisoruselargevtlb',
1596 0x250000fd => 'hypervisorhostip', 1650 0x250000fd => 'hypervisorhostip',
1597 0x250000fe => 'hypervisorhostport', 1651 0x250000fe => 'hypervisorhostport',
1598 0x250000ff => 'hypervisordebugpages', 1652 0x250000ff => 'hypervisordebugpages',
1599 0x25000100 => 'tpmbootentropy', 1653 0x25000100 => 'tpmbootentropy',
1600 0x22000110 => 'hypervisorusekey', 1654 0x22000110 => 'hypervisorusekey',
1601 0x22000112 => 'hypervisorproductskutype', 1655 0x22000112 => 'hypervisorproductskutype',
1602 0x25000113 => 'hypervisorrootproc', 1656 0x25000113 => 'hypervisorrootproc',
1603 0x26000114 => 'hypervisordhcp', 1657 0x26000114 => 'hypervisordhcp',
1604 0x25000115 => 'hypervisoriommupolicy', 1658 0x25000115 => 'hypervisoriommupolicy',
1605 0x26000116 => 'hypervisorusevapic', 1659 0x26000116 => 'hypervisorusevapic',
1606 0x22000117 => 'hypervisorloadoptions', 1660 0x22000117 => 'hypervisorloadoptions',
1607 0x25000118 => 'hypervisormsrfilterpolicy', 1661 0x25000118 => 'hypervisormsrfilterpolicy',
1608 0x25000119 => 'hypervisormmionxpolicy', 1662 0x25000119 => 'hypervisormmionxpolicy',
1609 0x2500011a => 'hypervisorschedulertype', 1663 0x2500011a => 'hypervisorschedulertype',
1610 0x25000120 => 'xsavepolicy', 1664 0x25000120 => 'xsavepolicy',
1611 0x25000121 => 'xsaveaddfeature0', 1665 0x25000121 => 'xsaveaddfeature0',
1612 0x25000122 => 'xsaveaddfeature1', 1666 0x25000122 => 'xsaveaddfeature1',
1613 0x25000123 => 'xsaveaddfeature2', 1667 0x25000123 => 'xsaveaddfeature2',
1614 0x25000124 => 'xsaveaddfeature3', 1668 0x25000124 => 'xsaveaddfeature3',
1615 0x25000125 => 'xsaveaddfeature4', 1669 0x25000125 => 'xsaveaddfeature4',
1616 0x25000126 => 'xsaveaddfeature5', 1670 0x25000126 => 'xsaveaddfeature5',
1617 0x25000127 => 'xsaveaddfeature6', 1671 0x25000127 => 'xsaveaddfeature6',
1618 0x25000128 => 'xsaveaddfeature7', 1672 0x25000128 => 'xsaveaddfeature7',
1619 0x25000129 => 'xsaveremovefeature', 1673 0x25000129 => 'xsaveremovefeature',
1620 0x2500012a => 'xsaveprocessorsmask', 1674 0x2500012a => 'xsaveprocessorsmask',
1621 0x2500012b => 'xsavedisable', 1675 0x2500012b => 'xsavedisable',
1622 0x2500012c => 'kerneldebugtype', 1676 0x2500012c => 'kerneldebugtype',
1623 0x2200012d => 'kernelbusparams', 1677 0x2200012d => 'kernelbusparams',
1624 0x2500012e => 'kerneldebugaddress', 1678 0x2500012e => 'kerneldebugaddress',
1625 0x2500012f => 'kerneldebugport', 1679 0x2500012f => 'kerneldebugport',
1626 0x25000130 => 'claimedtpmcounter', 1680 0x25000130 => 'claimedtpmcounter',
1627 0x25000131 => 'kernelchannel', 1681 0x25000131 => 'kernelchannel',
1628 0x22000132 => 'kerneltargetname', 1682 0x22000132 => 'kerneltargetname',
1629 0x25000133 => 'kernelhostip', 1683 0x25000133 => 'kernelhostip',
1630 0x25000134 => 'kernelport', 1684 0x25000134 => 'kernelport',
1631 0x26000135 => 'kerneldhcp', 1685 0x26000135 => 'kerneldhcp',
1632 0x22000136 => 'kernelkey', 1686 0x22000136 => 'kernelkey',
1633 0x22000137 => 'imchivename', 1687 0x22000137 => 'imchivename',
1634 0x21000138 => 'imcdevice', 1688 0x21000138 => 'imcdevice',
1635 0x25000139 => 'kernelbaudrate', 1689 0x25000139 => 'kernelbaudrate',
1636 0x22000140 => 'mfgmode', 1690 0x22000140 => 'mfgmode',
1637 0x26000141 => 'event', 1691 0x26000141 => 'event',
1638 0x25000142 => 'vsmlaunchtype', 1692 0x25000142 => 'vsmlaunchtype',
1639 0x25000144 => 'hypervisorenforcedcodeintegrity', 1693 0x25000144 => 'hypervisorenforcedcodeintegrity',
1640 0x26000145 => 'enablebootdebugpolicy',
1641 0x26000146 => 'enablebootorderclean',
1642 0x26000147 => 'enabledeviceid',
1643 0x26000148 => 'enableffuloader',
1644 0x26000149 => 'enableiuloader',
1645 0x2600014a => 'enablemassstorage',
1646 0x2600014b => 'enablerpmbprovisioning',
1647 0x2600014c => 'enablesecurebootpolicy',
1648 0x2600014d => 'enablestartcharge',
1649 0x2600014e => 'enableresettpm',
1650 0x21000150 => 'systemdatadevice', 1694 0x21000150 => 'systemdatadevice',
1651 0x21000151 => 'osarcdevice', 1695 0x21000151 => 'osarcdevice',
1652 0x21000153 => 'osdatadevice', 1696 0x21000153 => 'osdatadevice',
1653 0x21000154 => 'bspdevice', 1697 0x21000154 => 'bspdevice',
1654 0x21000155 => 'bspfilepath', 1698 0x21000155 => 'bspfilepath',
1655 0x26000202 => 'skipffumode', 1699 },
1656 0x26000203 => 'forceffumode', 1700 resume => {
1657 0x25000510 => 'chargethreshold', 1701 0x21000001 => 'filedevice',
1658 0x26000512 => 'offmodecharging', 1702 0x22000002 => 'filepath',
1659 0x25000aaa => 'bootflow', 1703 0x26000003 => 'customsettings',
1660 0x35000001 => 'ramdiskimageoffset', 1704 0x26000004 => 'pae',
1661 0x35000002 => 'ramdisktftpclientport', 1705 0x21000005 => 'associatedosdevice',
1662 0x31000003 => 'ramdisksdidevice', 1706 0x26000006 => 'debugoptionenabled',
1663 0x32000004 => 'ramdisksdipath', 1707 0x25000007 => 'bootux',
1664 0x35000005 => 'ramdiskimagelength', 1708 0x25000008 => 'bootmenupolicy',
1665 0x36000006 => 'exportascd', 1709 0x26000024 => 'hormenabled',
1666 0x35000007 => 'ramdisktftpblocksize', 1710 },
1667 0x35000008 => 'ramdisktftpwindowsize', 1711 startup => {
1668 0x36000009 => 'ramdiskmcenabled', 1712 0x26000001 => 'pxesoftreboot',
1669 0x3600000a => 'ramdiskmctftpfallback', 1713 0x22000002 => 'applicationname',
1670 0x3600000b => 'ramdisktftpvarwindow', 1714 },
1671 0x45000001 => 'devicetype',
1672 0x42000002 => 'applicationrelativepath',
1673 0x42000003 => 'ramdiskdevicerelativepath',
1674 0x46000004 => 'omitosloaderelements',
1675 0x47000006 => 'elementstomigrate',
1676 0x46000010 => 'recoveryos',
1677); 1715);
1678 1716
1679our %rbcde = reverse %bcde; 1717# mask, value => class
1718our @bcde_typeclass = (
1719 [0x00000000, 0x00000000, 'any'],
1720 [0xf00fffff, 0x1000000a, 'bootapp'],
1721 [0xf0ffffff, 0x2020000a, 'bootapp'],
1722 [0xf00fffff, 0x10000001, 'bootmgr'],
1723 [0xf00fffff, 0x10000002, 'bootmgr'],
1724 [0xf0ffffff, 0x20200001, 'bootmgr'],
1725 [0xf0ffffff, 0x20200002, 'bootmgr'],
1726 [0xf0f00000, 0x20300000, 'device'],
1727 [0xf0000000, 0x30000000, 'device'],
1728 [0xf00fffff, 0x10000005, 'memdiag'],
1729 [0xf0ffffff, 0x20200005, 'memdiag'],
1730 [0xf00fffff, 0x10000006, 'ntldr'],
1731 [0xf00fffff, 0x10000007, 'ntldr'],
1732 [0xf0ffffff, 0x20200006, 'ntldr'],
1733 [0xf0ffffff, 0x20200007, 'ntldr'],
1734 [0xf00fffff, 0x10000003, 'osloader'],
1735 [0xf0ffffff, 0x20200003, 'osloader'],
1736 [0xf00fffff, 0x10000004, 'resume'],
1737 [0xf0ffffff, 0x20200004, 'resume'],
1738 [0xf00fffff, 0x10000009, 'startup'],
1739 [0xf0ffffff, 0x20200009, 'startup'],
1740);
1680 1741
1742our %rbcde_byclass;
1743
1744while (my ($k, $v) = each %bcde_byclass) {
1745 $rbcde_byclass{$k} = { reverse %$v };
1746}
1747
1748# decodes (numerical elem, type) to name
1681sub dec_bcde_id($) { 1749sub dec_bcde_id($$) {
1750 for my $class (@bcde_typeclass) {
1751 if (($_[1] & $class->[0]) == $class->[1]) {
1752 if (my $id = $bcde_byclass{$class->[2]}{$_[0]}) {
1753 return $id;
1754 }
1755 }
1756 }
1757
1682 $bcde{$_[0]} // sprintf "custom:%08x", $_[0] 1758 sprintf "custom:%08x", $_[0]
1683} 1759}
1684 1760
1761# encodes (elem as name, type)
1685sub enc_bcde_id($) { 1762sub enc_bcde_id($$) {
1686 $_[0] =~ /^custom:([0-9a-fA-F]{8}$)/ 1763 $_[0] =~ /^custom:(?:0x)?([0-9a-fA-F]{8}$)/
1687 ? hex $1 1764 and return hex $1;
1688 : $rbcde{$_[0]} 1765
1766 for my $class (@bcde_typeclass) {
1767 if (($_[1] & $class->[0]) == $class->[1]) {
1768 if (my $value = $rbcde_byclass{$class->[2]}{$_[0]}) {
1769 return $value;
1770 }
1771 }
1772 }
1773
1774 undef
1689} 1775}
1690 1776
1691# decode/encode bcd device element - the horror, no documentaion 1777# decode/encode bcd device element - the horror, no documentaion
1692# whatsoever, supercomplex, superinconsistent. 1778# whatsoever, supercomplex, superinconsistent.
1693 1779
1697 1783
1698our $NULL_DEVICE = "\x00" x 16; 1784our $NULL_DEVICE = "\x00" x 16;
1699 1785
1700# biggest bitch to decode, ever 1786# biggest bitch to decode, ever
1701# this decoded a device portion after the GUID 1787# this decoded a device portion after the GUID
1702sub dec_device_($); 1788sub dec_device_($$);
1703sub dec_device_($) { 1789sub dec_device_($$) {
1704 my ($device) = @_; 1790 my ($device, $type) = @_;
1705 1791
1706 my $res; 1792 my $res;
1707 1793
1708 my ($type, $flags, $length, $pad) = unpack "VVVV", substr $device, 0, 4 * 4, ""; 1794 my ($type, $flags, $length, $pad) = unpack "VVVV", substr $device, 0, 4 * 4, "";
1709 1795
1754 1840
1755 my $partid = $parttype eq "gpt" ? dec_guid $partdata 1841 my $partid = $parttype eq "gpt" ? dec_guid $partdata
1756 : $type eq "partition" ? unpack "Q<", $partdata # byte offset to partition start 1842 : $type eq "partition" ? unpack "Q<", $partdata # byte offset to partition start
1757 : unpack "L<", $partdata; # partition number, one-based 1843 : unpack "L<", $partdata; # partition number, one-based
1758 1844
1759 (my $parent, $device) = dec_device_ $device; 1845 (my $parent, $device) = dec_device_ $device, $type;
1760 1846
1761 $res .= "="; 1847 $res .= "=";
1762 $res .= "<$parent>"; 1848 $res .= "<$parent>";
1763 $res .= ",$blocktype,$parttype,$diskid,$partid"; 1849 $res .= ",$blocktype,$parttype,$diskid,$partid";
1764 1850
1784 or die "unsupported file descriptor version '$fver'\n"; 1870 or die "unsupported file descriptor version '$fver'\n";
1785 1871
1786 $ftype == 5 1872 $ftype == 5
1787 or die "unsupported file descriptor path type '$type'\n"; 1873 or die "unsupported file descriptor path type '$type'\n";
1788 1874
1789 (my $parent, $path) = dec_device_ $path; 1875 (my $parent, $path) = dec_device_ $path, $type;
1790 1876
1791 $path = $dec_path->($path, "file device without path"); 1877 $path = $dec_path->($path, "file device without path");
1792 1878
1793 ($parent, $path) 1879 ($parent, $path)
1794 }; 1880 };
1800 1886
1801 } elsif ($blocktype eq "vhd") { 1887 } elsif ($blocktype eq "vhd") {
1802 $device =~ s/^\x00{20}//s 1888 $device =~ s/^\x00{20}//s
1803 or die "virtualdisk has non-zero fields I don't understand\n"; 1889 or die "virtualdisk has non-zero fields I don't understand\n";
1804 1890
1805 (my $parent, $device) = dec_device_ $device; 1891 (my $parent, $device) = dec_device_ $device, $type;
1806 1892
1807 $res .= "=vhd,<$parent>"; 1893 $res .= "=vhd,<$parent>";
1808 1894
1809 } elsif ($blocktype eq "ramdisk") { 1895 } elsif ($blocktype eq "ramdisk") {
1810 my ($base, $size, $offset) = unpack "Q< Q< L<", substr $device, 0, 8 + 8 + 4, ""; 1896 my ($base, $size, $offset) = unpack "Q< Q< L<", substr $device, 0, 8 + 8 + 4, "";
1823 my ($mode, $elem, $parent) = unpack "VVV", substr $device, 0, 4 * 3, ""; 1909 my ($mode, $elem, $parent) = unpack "VVV", substr $device, 0, 4 * 3, "";
1824 1910
1825 if ($parent) { 1911 if ($parent) {
1826 # not sure why this is an offset - it must come after the path 1912 # not sure why this is an offset - it must come after the path
1827 $parent = substr $device, $parent - 4 * 3 - 4 * 4, 1e9, ""; 1913 $parent = substr $device, $parent - 4 * 3 - 4 * 4, 1e9, "";
1828 ($parent, my $tail) = dec_device_ $parent; 1914 ($parent, my $tail) = dec_device_ $parent, $type;
1829 0 == length $tail 1915 0 == length $tail
1830 or die "trailing data after locate device parent\n"; 1916 or die "trailing data after locate device parent\n";
1831 } else { 1917 } else {
1832 $parent = "null"; 1918 $parent = "null";
1833 } 1919 }
1839 1925
1840 if ($mode == 0) { # "Element" 1926 if ($mode == 0) { # "Element"
1841 !length $path 1927 !length $path
1842 or die "device locate mode 0 having non-empty path ($mode, $elem, $path)\n"; 1928 or die "device locate mode 0 having non-empty path ($mode, $elem, $path)\n";
1843 1929
1844 $elem = dec_bcde_id $elem; 1930 $elem = dec_bcde_id $elem, $type;
1845 $res .= "element,$elem"; 1931 $res .= "element,$elem";
1846 1932
1847 } elsif ($mode == 1) { # "String" 1933 } elsif ($mode == 1) { # "String"
1848 !$elem 1934 !$elem
1849 or die "device locate mode 1 having non-zero element\n"; 1935 or die "device locate mode 1 having non-zero element\n";
1874 1960
1875 ($res, $tail) 1961 ($res, $tail)
1876} 1962}
1877 1963
1878# decode a full binary BCD device descriptor 1964# decode a full binary BCD device descriptor
1879sub dec_device($) { 1965sub dec_device($$) {
1880 my ($device) = @_; 1966 my ($device, $type) = @_;
1881 1967
1882 $device = pack "H*", $device; 1968 $device = pack "H*", $device;
1883 1969
1884 my $guid = dec_guid substr $device, 0, 16, ""; 1970 my $guid = dec_guid substr $device, 0, 16, "";
1885 $guid = $guid eq "00000000-0000-0000-0000-000000000000" 1971 $guid = $guid eq "00000000-0000-0000-0000-000000000000"
1886 ? "" : "{$guid}"; 1972 ? "" : "{$guid}";
1887 1973
1888 eval { 1974 eval {
1889 my ($dev, $tail) = dec_device_ $device; 1975 my ($dev, $tail) = dec_device_ $device, $type;
1890 1976
1891 $tail eq "" 1977 $tail eq ""
1892 or die "unsupported trailing data after device descriptor\n"; 1978 or die "unsupported trailing data after device descriptor\n";
1893 1979
1894 "$guid$dev" 1980 "$guid$dev"
1906 1992
1907 undef 1993 undef
1908} 1994}
1909 1995
1910# encode the device portion after the GUID 1996# encode the device portion after the GUID
1911sub enc_device_; 1997sub enc_device_($$);
1912sub enc_device_ { 1998sub enc_device_($$) {
1913 my ($device) = @_; 1999 my ($device, $type) = @_;
1914 2000
1915 my $enc_path = sub { 2001 my $enc_path = sub {
1916 my $path = shift; 2002 my $path = shift;
1917 $path =~ s/\//\\/g; 2003 $path =~ s/\//\\/g;
1918 (Encode::encode "UTF-16LE", $path) . "\x00\x00" 2004 (Encode::encode "UTF-16LE", $path) . "\x00\x00"
1936 2022
1937 my $parse_parent = sub { 2023 my $parse_parent = sub {
1938 my $parent; 2024 my $parent;
1939 2025
1940 if (s/^<//) { 2026 if (s/^<//) {
1941 ($parent, $_) = enc_device_ $_; 2027 ($parent, $_) = enc_device_ $_, $type;
1942 s/^>// 2028 s/^>//
1943 or die "$device: syntax error: parent device not followed by '>'\n"; 2029 or die "$device: syntax error: parent device not followed by '>'\n";
1944 } else { 2030 } else {
1945 $parent = $NULL_DEVICE; 2031 $parent = $NULL_DEVICE;
1946 } 2032 }
2034 2120
2035 s/^,// 2121 s/^,//
2036 or die "$_: missing comma after locate parent device\n"; 2122 or die "$_: missing comma after locate parent device\n";
2037 2123
2038 if (s/^element,//) { 2124 if (s/^element,//) {
2039 s/^([0-9a-z]+)//i 2125 s/^([0-9a-z:]+)//i
2040 or die "$_ locate element must be either name or 8-digit hex id\n"; 2126 or die "$_ locate element must be either name or 8-digit hex id\n";
2041 $elem = enc_bcde_id $1; 2127 $elem = enc_bcde_id $1, $type;
2042 $mode = 0; 2128 $mode = 0;
2043 $path = $enc_path->(""); 2129 $path = $enc_path->("");
2044 2130
2045 } elsif (s/^path,//) { 2131 } elsif (s/^path,//) {
2046 $mode = 1; 2132 $mode = 1;
2125 ); 2211 );
2126 } 2212 }
2127} 2213}
2128 2214
2129# encode a full binary BCD device descriptor 2215# encode a full binary BCD device descriptor
2130sub enc_device { 2216sub enc_device($$) {
2131 my ($device) = @_; 2217 my ($device, $type) = @_;
2132 2218
2133 my $guid = "\x00" x 16; 2219 my $guid = "\x00" x 16;
2134 2220
2135 if ($device =~ s/^\{([A-Za-z0-9\-]+)\}//) { 2221 if ($device =~ s/^\{([A-Za-z0-9\-]+)\}//) {
2136 $guid = enc_guid $1 2222 $guid = enc_guid $1
2137 or die "$device: does not start with valid guid\n"; 2223 or die "$device: does not start with valid guid\n";
2138 } 2224 }
2139 2225
2140 my ($descriptor, $tail) = enc_device_ $device; 2226 my ($descriptor, $tail) = enc_device_ $device, $type;
2141 2227
2142 length $tail 2228 length $tail
2143 and die "$device: garbage after device descriptor\n"; 2229 and die "$device: garbage after device descriptor\n";
2144 2230
2145 unpack "H*", $guid . $descriptor 2231 unpack "H*", $guid . $descriptor
2160 $k = $bcd_objects{$k} // $k; 2246 $k = $bcd_objects{$k} // $k;
2161 2247
2162 my $type = $v->{Description}[0]{Type}[1]; 2248 my $type = $v->{Description}[0]{Type}[1];
2163 2249
2164 if ($type != $bcd_object_types{$k}) { 2250 if ($type != $bcd_object_types{$k}) {
2165 $type = $bcd_types{$type} // sprintf "0x%08x", $type; 2251 $kv{type} = $bcd_types{$type} // sprintf "0x%08x", $type;
2166 $kv{type} = $type;
2167 } 2252 }
2168 2253
2169 my $elems = $v->{Elements}[1]; 2254 my $elems = $v->{Elements}[1];
2170 2255
2171 while (my ($k, $v) = each %$elems) { 2256 while (my ($k, $v) = each %$elems) {
2172 my $k = hex $k; 2257 my $k = hex $k;
2173 2258
2174 my $v = $bcde_dec{$k & BCDE_FORMAT}->($v->[0]{Element}[1]); 2259 my $v = $bcde_dec{$k & BCDE_FORMAT}->($v->[0]{Element}[1], $type);
2175 my $k = dec_bcde_id $k; 2260 my $k = dec_bcde_id $k, $type;
2176 2261
2177 $kv{$k} = $v; 2262 $kv{$k} = $v;
2178 } 2263 }
2179 2264
2180 $bcd{$k} = \%kv; 2265 $bcd{$k} = \%kv;
2221 my %elem; 2306 my %elem;
2222 2307
2223 while (my ($k, $v) = each %$v) { 2308 while (my ($k, $v) = each %$v) {
2224 next if $k eq "type"; 2309 next if $k eq "type";
2225 2310
2226 $k = (enc_bcde_id $k) // die "$k: invalid bcde element name or id\n"; 2311 $k = (enc_bcde_id $k, $type) // die "$k: invalid bcde element name or id\n";
2227 $elem{sprintf "%08x", $k} = [{ 2312 $elem{sprintf "%08x", $k} = [{
2228 Element => [ ($bcde_enc{$k & BCDE_FORMAT} // die "$k: unable to encode unknown bcd element type}")->($v)] 2313 Element => [ ($bcde_enc{$k & BCDE_FORMAT} // die "$k: unable to encode unknown bcd element type}")->($v)]
2229 }]; 2314 }];
2230 } 2315 }
2231 2316
2247 Objects => [undef, \%objects], 2332 Objects => [undef, \%objects],
2248 }]] 2333 }]]
2249} 2334}
2250 2335
2251############################################################################# 2336#############################################################################
2337# edit instructions
2252 2338
2253sub bcd_edit_eval { 2339sub bcd_edit_eval {
2254 package pbcdedit; 2340 package pbcdedit;
2255 2341
2256 our ($PATH, $BCD, $DEFAULT); 2342 our ($PATH, $BCD, $DEFAULT);
2260} 2346}
2261 2347
2262sub bcd_edit { 2348sub bcd_edit {
2263 my ($path, $bcd, @insns) = @_; 2349 my ($path, $bcd, @insns) = @_;
2264 2350
2265 my $default = $bcd->{"{bootmgr}"}{resumeobject}; 2351 my $default = $bcd->{"{bootmgr}"}{default};
2266 2352
2267 # prepare "officially visible" variables 2353 # prepare "officially visible" variables
2268 local $pbcdedit::PATH = $path; 2354 local $pbcdedit::PATH = $path;
2269 local $pbcdedit::BCD = $bcd; 2355 local $pbcdedit::BCD = $bcd;
2270 local $pbcdedit::DEFAULT = $default; 2356 local $pbcdedit::DEFAULT = $default;
2288 $object = $object eq "{default}" ? $default : dec_wguid enc_wguid $object; 2374 $object = $object eq "{default}" ? $default : dec_wguid enc_wguid $object;
2289 2375
2290 $bcd->{$object}{$elem} = $value; 2376 $bcd->{$object}{$elem} = $value;
2291 2377
2292 } elsif ($insn eq "eval") { 2378 } elsif ($insn eq "eval") {
2293 bcd_edit_eval shift @insns; 2379 my $perl = shift @insns;
2380 bcd_edit_eval "#line 1 'eval'\n$perl";
2294 2381
2295 } elsif ($insn eq "do") { 2382 } elsif ($insn eq "do") {
2296 my $path = shift @insns; 2383 my $path = shift @insns;
2297 my $file = file_load $path; 2384 my $file = file_load $path;
2298 bcd_edit_eval "#line 1 '$path'\n$file"; 2385 bcd_edit_eval "#line 1 '$path'\n$file";
2303 } 2390 }
2304 2391
2305} 2392}
2306 2393
2307############################################################################# 2394#############################################################################
2395# command line parser
2308 2396
2309# json to stdout 2397# json to stdout
2310sub prjson($) { 2398sub prjson($) {
2311 print $json_coder->encode ($_[0]); 2399 print $json_coder->encode ($_[0]);
2312} 2400}
2351 2439
2352 print "\n"; 2440 print "\n";
2353 2441
2354 printf "%-39s %-23s %s\n", "Object GUID", "Alias", "(Hex) Default Type"; 2442 printf "%-39s %-23s %s\n", "Object GUID", "Alias", "(Hex) Default Type";
2355 for my $name (sort keys %rbcd_objects) { 2443 for my $name (sort keys %rbcd_objects) {
2356 my $guid = $rbcd_objects{$name}; 2444 my $guid = $rbcd_objects{$name};
2357 my $type = $bcd_object_types{$name}; 2445 my $type = $bcd_object_types{$name};
2358 my $tname = $bcd_types{$type}; 2446 my $tname = $bcd_types{$type};
2359 2447
2360 $type = $type ? sprintf "(%08x) %s", $type, $tname : "-"; 2448 $type = $type ? sprintf "(%08x) %s", $type, $tname : "-";
2361 2449
2362 printf "%-39s %-23s %s\n", $guid, $name, $type; 2450 printf "%-39s %-23s %s\n", $guid, $name, $type;
2376 BCDE_FORMAT_GUID_LIST , "guid list", 2464 BCDE_FORMAT_GUID_LIST , "guid list",
2377 BCDE_FORMAT_INTEGER , "integer", 2465 BCDE_FORMAT_INTEGER , "integer",
2378 BCDE_FORMAT_BOOLEAN , "boolean", 2466 BCDE_FORMAT_BOOLEAN , "boolean",
2379 BCDE_FORMAT_INTEGER_LIST, "integer list", 2467 BCDE_FORMAT_INTEGER_LIST, "integer list",
2380 ); 2468 );
2381 my %rbcde = reverse %bcde;
2382 $_ = sprintf "%08x", $_ for values %rbcde;
2383 2469
2384 my %element; 2470 my %element;
2385 2471
2472 for my $class (sort keys %rbcde_byclass) {
2473 my $rbcde = $rbcde_byclass{$class};
2474
2386 unless ($json) { 2475 unless ($json) {
2387 print "\n"; 2476 print "\n";
2477 printf "Elements applicable to class(es): $class\n";
2388 printf "%-9s %-12s %s\n", "Element", "Format", "Name Alias"; 2478 printf "%-9s %-12s %s\n", "Element", "Format", "Name Alias";
2389 } 2479 }
2390 for my $name (sort keys %rbcde) { 2480 for my $name (sort keys %$rbcde) {
2391 my $id = $rbcde{$name}; 2481 my $id = $rbcde->{$name};
2392 my $format = $format_name{(hex $id) & BCDE_FORMAT}; 2482 my $format = $format_name{$id & BCDE_FORMAT};
2483 $id = sprintf "%08x", $id;
2393 2484
2394 if ($json) { 2485 if ($json) {
2395 $element{$id} = [$format, $name]; 2486 $element{$id} = [$class, $format, $name];
2396 } else { 2487 } else {
2397 printf "%-9s %-12s %s\n", $id, $format, $name; 2488 printf "%-9s %-12s %s\n", $id, $format, $name;
2489 }
2398 } 2490 }
2399 } 2491 }
2400 print "\n" unless $json; 2492 print "\n" unless $json;
2401 2493
2402 prjson { 2494 prjson {
2403 version => $JSON_VERSION, 2495 version => $JSON_VERSION,
2404 element => \%element, 2496 element => \%element,
2497 class => \@bcde_typeclass,
2405 } if $json; 2498 } if $json;
2406 2499
2407 }, 2500 },
2408 2501
2409 export => sub { 2502 export => sub {
2461 } 2554 }
2462 } 2555 }
2463 } 2556 }
2464 } 2557 }
2465 }, 2558 },
2559
2560 version => sub {
2561 print "\n",
2562 "PBCDEDIT version $VERSION, copyright 2019 Marc A. Lehmann <pbcdedit\@schmorp.de>.\n",
2563 "JSON schema version: $JSON_VERSION\n",
2564 "Licensed under the GNU General Public License Version 3.0, or any later version.\n",
2565 "\n",
2566 $CHANGELOG,
2567 "\n";
2568 },
2466); 2569);
2467 2570
2468my $cmd = shift; 2571my $cmd = shift;
2469 2572
2470unless (exists $CMD{$cmd}) { 2573unless (exists $CMD{$cmd}) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines