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

Comparing pbcdedit/pbcdedit (file contents):
Revision 1.23 by root, Wed Aug 14 23:38:27 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
781=back 799=back
782 800
783 801
784=head1 SEE ALSO 802=head1 SEE ALSO
785 803
786For ideas on what you can do, and some introductory material, try 804For ideas on what you can do with BCD stores in
805general, and some introductory material, try
787L<http://www.mistyprojects.co.uk/documents/BCDEdit/index.html>. 806L<http://www.mistyprojects.co.uk/documents/BCDEdit/index.html>.
788 807
789For good reference on which BCD objects and 808For good reference on which BCD objects and
790elements exist, see Geoff Chappel's pages at 809elements exist, see Geoff Chappell's pages at
791L<http://www.geoffchappell.com/notes/windows/boot/bcd/index.htm>. 810L<http://www.geoffchappell.com/notes/windows/boot/bcd/index.htm>.
792 811
793=head1 AUTHOR 812=head1 AUTHOR
794 813
795Written by Marc A. Lehmann L<pbcdedit@schmorp.de>. 814Written by Marc A. Lehmann L<pbcdedit@schmorp.de>.
822free 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
823permitted by law. 842permitted by law.
824 843
825=cut 844=cut
826 845
827BEGIN { 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 }
828 848
829use Data::Dump; 849no warnings 'portable'; # avoid 32 bit integer warnings
850
830use Encode (); 851use Encode ();
831use List::Util (); 852use List::Util ();
832use IO::Handle (); 853use IO::Handle ();
833use Time::HiRes (); 854use Time::HiRes ();
834 855
857 or die "$path: short read\n"; 878 or die "$path: short read\n";
858 879
859 $buf 880 $buf
860} 881}
861 882
862# sources and resources used for this: 883# sources and resources used for writing pbcdedit
884#
863# registry: 885# registry:
864# 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
865# http://amnesia.gtisc.gatech.edu/~moyix/suzibandit.ltd.uk/MSc/ 887# http://amnesia.gtisc.gatech.edu/~moyix/suzibandit.ltd.uk/MSc/
866# bcd: 888# bcd:
867# http://www.geoffchappell.com/notes/windows/boot/bcd/index.htm 889# http://www.geoffchappell.com/notes/windows/boot/bcd/index.htm
1355sub BCDE_FORMAT_GUID_LIST () { 0x04000000 } 1377sub BCDE_FORMAT_GUID_LIST () { 0x04000000 }
1356sub BCDE_FORMAT_INTEGER () { 0x05000000 } 1378sub BCDE_FORMAT_INTEGER () { 0x05000000 }
1357sub BCDE_FORMAT_BOOLEAN () { 0x06000000 } 1379sub BCDE_FORMAT_BOOLEAN () { 0x06000000 }
1358sub BCDE_FORMAT_INTEGER_LIST () { 0x07000000 } 1380sub BCDE_FORMAT_INTEGER_LIST () { 0x07000000 }
1359 1381
1360sub dec_device;
1361sub enc_device;
1362
1363sub enc_integer($) { 1382sub enc_integer($) {
1364 no warnings 'portable'; # ugh
1365 my $value = shift; 1383 my $value = shift;
1366 $value = oct $value if $value =~ /^0[bBxX]/; 1384 $value = oct $value if $value =~ /^0[bBxX]/;
1367 unpack "H*", pack "Q<", $value 1385 unpack "H*", pack "Q<", $value
1368} 1386}
1387
1388sub enc_device($$);
1389sub dec_device($$);
1369 1390
1370our %bcde_dec = ( 1391our %bcde_dec = (
1371 BCDE_FORMAT_DEVICE , \&dec_device, 1392 BCDE_FORMAT_DEVICE , \&dec_device,
1372# # for round-trip verification 1393# # for round-trip verification
1373# BCDE_FORMAT_DEVICE , sub { 1394# BCDE_FORMAT_DEVICE , sub {
1383 BCDE_FORMAT_BOOLEAN , sub { shift eq "00" ? 0 : 1 }, 1404 BCDE_FORMAT_BOOLEAN , sub { shift eq "00" ? 0 : 1 },
1384 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
1385); 1406);
1386 1407
1387our %bcde_enc = ( 1408our %bcde_enc = (
1388 BCDE_FORMAT_DEVICE , sub { binary => enc_device shift }, 1409 BCDE_FORMAT_DEVICE , sub { binary => enc_device $_[0], $_[1] },
1389 BCDE_FORMAT_STRING , sub { sz => shift }, 1410 BCDE_FORMAT_STRING , sub { sz => shift },
1390 BCDE_FORMAT_GUID , sub { sz => "{" . (dec_guid enc_wguid shift) . "}" }, 1411 BCDE_FORMAT_GUID , sub { sz => "{" . (dec_guid enc_wguid shift) . "}" },
1391 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 ] },
1392 BCDE_FORMAT_INTEGER , sub { binary => enc_integer shift }, 1413 BCDE_FORMAT_INTEGER , sub { binary => enc_integer shift },
1393 BCDE_FORMAT_BOOLEAN , sub { binary => shift ? "01" : "00" }, 1414 BCDE_FORMAT_BOOLEAN , sub { binary => shift ? "01" : "00" },
1394 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 },
1395); 1416);
1396 1417
1397# BCD Elements 1418# BCD Elements
1398our %bcde = ( 1419our %bcde_byclass = (
1420 any => {
1399 0x11000001 => 'device', 1421 0x11000001 => 'device',
1400 0x12000002 => 'path', 1422 0x12000002 => 'path',
1401 0x12000004 => 'description', 1423 0x12000004 => 'description',
1402 0x12000005 => 'locale', 1424 0x12000005 => 'locale',
1403 0x14000006 => 'inherit', 1425 0x14000006 => 'inherit',
1404 0x15000007 => 'truncatememory', 1426 0x15000007 => 'truncatememory',
1405 0x14000008 => 'recoverysequence', 1427 0x14000008 => 'recoverysequence',
1406 0x16000009 => 'recoveryenabled', 1428 0x16000009 => 'recoveryenabled',
1407 0x1700000a => 'badmemorylist', 1429 0x1700000a => 'badmemorylist',
1408 0x1600000b => 'badmemoryaccess', 1430 0x1600000b => 'badmemoryaccess',
1409 0x1500000c => 'firstmegabytepolicy', 1431 0x1500000c => 'firstmegabytepolicy',
1410 0x1500000d => 'relocatephysical', 1432 0x1500000d => 'relocatephysical',
1411 0x1500000e => 'avoidlowmemory', 1433 0x1500000e => 'avoidlowmemory',
1412 0x1600000f => 'traditionalkseg', 1434 0x1600000f => 'traditionalkseg',
1413 0x16000010 => 'bootdebug', 1435 0x16000010 => 'bootdebug',
1414 0x15000011 => 'debugtype', 1436 0x15000011 => 'debugtype',
1415 0x15000012 => 'debugaddress', 1437 0x15000012 => 'debugaddress',
1416 0x15000013 => 'debugport', 1438 0x15000013 => 'debugport',
1417 0x15000014 => 'baudrate', 1439 0x15000014 => 'baudrate',
1418 0x15000015 => 'channel', 1440 0x15000015 => 'channel',
1419 0x12000016 => 'targetname', 1441 0x12000016 => 'targetname',
1420 0x16000017 => 'noumex', 1442 0x16000017 => 'noumex',
1421 0x15000018 => 'debugstart', 1443 0x15000018 => 'debugstart',
1422 0x12000019 => 'busparams', 1444 0x12000019 => 'busparams',
1423 0x1500001a => 'hostip', 1445 0x1500001a => 'hostip',
1424 0x1500001b => 'port', 1446 0x1500001b => 'port',
1425 0x1600001c => 'dhcp', 1447 0x1600001c => 'dhcp',
1426 0x1200001d => 'key', 1448 0x1200001d => 'key',
1427 0x1600001e => 'vm', 1449 0x1600001e => 'vm',
1428 0x16000020 => 'bootems', 1450 0x16000020 => 'bootems',
1429 0x15000022 => 'emsport', 1451 0x15000022 => 'emsport',
1430 0x15000023 => 'emsbaudrate', 1452 0x15000023 => 'emsbaudrate',
1431 0x12000030 => 'loadoptions', 1453 0x12000030 => 'loadoptions',
1432 0x16000040 => 'advancedoptions', 1454 0x16000040 => 'advancedoptions',
1433 0x16000041 => 'optionsedit', 1455 0x16000041 => 'optionsedit',
1434 0x15000042 => 'keyringaddress', 1456 0x15000042 => 'keyringaddress',
1435 0x11000043 => 'bootstatdevice', 1457 0x11000043 => 'bootstatdevice',
1436 0x12000044 => 'bootstatfilepath', 1458 0x12000044 => 'bootstatfilepath',
1437 0x16000045 => 'preservebootstat', 1459 0x16000045 => 'preservebootstat',
1438 0x16000046 => 'graphicsmodedisabled', 1460 0x16000046 => 'graphicsmodedisabled',
1439 0x15000047 => 'configaccesspolicy', 1461 0x15000047 => 'configaccesspolicy',
1440 0x16000048 => 'nointegritychecks', 1462 0x16000048 => 'nointegritychecks',
1441 0x16000049 => 'testsigning', 1463 0x16000049 => 'testsigning',
1442 0x1200004a => 'fontpath', 1464 0x1200004a => 'fontpath',
1443 0x1500004b => 'integrityservices', 1465 0x1500004b => 'integrityservices',
1444 0x1500004c => 'volumebandid', 1466 0x1500004c => 'volumebandid',
1445 0x16000050 => 'extendedinput', 1467 0x16000050 => 'extendedinput',
1446 0x15000051 => 'initialconsoleinput', 1468 0x15000051 => 'initialconsoleinput',
1447 0x15000052 => 'graphicsresolution', 1469 0x15000052 => 'graphicsresolution',
1448 0x16000053 => 'restartonfailure', 1470 0x16000053 => 'restartonfailure',
1449 0x16000054 => 'highestmode', 1471 0x16000054 => 'highestmode',
1450 0x16000060 => 'isolatedcontext', 1472 0x16000060 => 'isolatedcontext',
1451 0x15000065 => 'displaymessage', 1473 0x15000065 => 'displaymessage',
1452 0x15000066 => 'displaymessageoverride', 1474 0x15000066 => 'displaymessageoverride',
1453 0x16000068 => 'nobootuxtext', 1475 0x16000068 => 'nobootuxtext',
1454 0x16000069 => 'nobootuxprogress', 1476 0x16000069 => 'nobootuxprogress',
1455 0x1600006a => 'nobootuxfade', 1477 0x1600006a => 'nobootuxfade',
1456 0x1600006b => 'bootuxreservepooldebug', 1478 0x1600006b => 'bootuxreservepooldebug',
1457 0x1600006c => 'bootuxdisabled', 1479 0x1600006c => 'bootuxdisabled',
1458 0x1500006d => 'bootuxfadeframes', 1480 0x1500006d => 'bootuxfadeframes',
1459 0x1600006e => 'bootuxdumpstats', 1481 0x1600006e => 'bootuxdumpstats',
1460 0x1600006f => 'bootuxshowstats', 1482 0x1600006f => 'bootuxshowstats',
1461 0x16000071 => 'multibootsystem', 1483 0x16000071 => 'multibootsystem',
1462 0x16000072 => 'nokeyboard', 1484 0x16000072 => 'nokeyboard',
1463 0x15000073 => 'aliaswindowskey', 1485 0x15000073 => 'aliaswindowskey',
1464 0x16000074 => 'bootshutdowndisabled', 1486 0x16000074 => 'bootshutdowndisabled',
1465 0x15000075 => 'performancefrequency', 1487 0x15000075 => 'performancefrequency',
1466 0x15000076 => 'securebootrawpolicy', 1488 0x15000076 => 'securebootrawpolicy',
1467 0x17000077 => 'allowedinmemorysettings', 1489 0x17000077 => 'allowedinmemorysettings',
1468 0x15000079 => 'bootuxtransitiontime', 1490 0x15000079 => 'bootuxtransitiontime',
1469 0x1600007a => 'mobilegraphics', 1491 0x1600007a => 'mobilegraphics',
1470 0x1600007b => 'forcefipscrypto', 1492 0x1600007b => 'forcefipscrypto',
1471 0x1500007d => 'booterrorux', 1493 0x1500007d => 'booterrorux',
1472 0x1600007e => 'flightsigning', 1494 0x1600007e => 'flightsigning',
1473 0x1500007f => 'measuredbootlogformat', 1495 0x1500007f => 'measuredbootlogformat',
1474 0x15000080 => 'displayrotation', 1496 0x15000080 => 'displayrotation',
1475 0x15000081 => 'logcontrol', 1497 0x15000081 => 'logcontrol',
1476 0x16000082 => 'nofirmwaresync', 1498 0x16000082 => 'nofirmwaresync',
1477 0x11000084 => 'windowssyspart', 1499 0x11000084 => 'windowssyspart',
1478 0x16000087 => 'numlock', 1500 0x16000087 => 'numlock',
1479 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 => {
1480 0x24000001 => 'displayorder', 1526 0x24000001 => 'displayorder',
1481 0x21000001 => 'filedevice',
1482 0x21000001 => 'osdevice',
1483 0x25000001 => 'passcount',
1484 0x26000001 => 'pxesoftreboot',
1485 0x22000002 => 'applicationname',
1486 0x24000002 => 'bootsequence', 1527 0x24000002 => 'bootsequence',
1487 0x22000002 => 'filepath',
1488 0x22000002 => 'systemroot',
1489 0x25000002 => 'testmix',
1490 0x26000003 => 'cacheenable',
1491 0x26000003 => 'customsettings',
1492 0x23000003 => 'default', 1528 0x23000003 => 'default',
1493 0x25000003 => 'failurecount',
1494 0x23000003 => 'resumeobject',
1495 0x26000004 => 'failuresenabled',
1496 0x26000004 => 'pae',
1497 0x26000004 => 'stampdisks',
1498 0x25000004 => 'testtofail',
1499 0x25000004 => 'timeout', 1529 0x25000004 => 'timeout',
1500 0x21000005 => 'associatedosdevice',
1501 0x26000005 => 'cacheenable',
1502 0x26000005 => 'resume', 1530 0x26000005 => 'resume',
1503 0x25000005 => 'stridefailcount',
1504 0x26000006 => 'debugoptionenabled',
1505 0x25000006 => 'invcfailcount',
1506 0x23000006 => 'resumeobject', 1531 0x23000006 => 'resumeobject',
1507 0x25000007 => 'bootux',
1508 0x25000007 => 'matsfailcount',
1509 0x24000007 => 'startupsequence', 1532 0x24000007 => 'startupsequence',
1510 0x25000008 => 'bootmenupolicy',
1511 0x25000008 => 'randfailcount',
1512 0x25000009 => 'chckrfailcount',
1513 0x26000010 => 'detecthal',
1514 0x24000010 => 'toolsdisplayorder', 1533 0x24000010 => 'toolsdisplayorder',
1515 0x22000011 => 'kernel',
1516 0x22000012 => 'hal',
1517 0x22000013 => 'dbgtransport',
1518 0x26000020 => 'displaybootmenu', 1534 0x26000020 => 'displaybootmenu',
1519 0x25000020 => 'nx',
1520 0x26000021 => 'noerrordisplay', 1535 0x26000021 => 'noerrordisplay',
1521 0x25000021 => 'pae',
1522 0x21000022 => 'bcddevice', 1536 0x21000022 => 'bcddevice',
1523 0x26000022 => 'winpe',
1524 0x22000023 => 'bcdfilepath', 1537 0x22000023 => 'bcdfilepath',
1525 0x26000024 => 'hormenabled', 1538 0x26000024 => 'hormenabled',
1526 0x26000024 => 'hormenabled',
1527 0x26000024 => 'nocrashautoreboot',
1528 0x26000025 => 'hiberboot', 1539 0x26000025 => 'hiberboot',
1529 0x26000025 => 'lastknowngood',
1530 0x26000026 => 'oslnointegritychecks',
1531 0x22000026 => 'passwordoverride', 1540 0x22000026 => 'passwordoverride',
1532 0x26000027 => 'osltestsigning',
1533 0x22000027 => 'pinpassphraseoverride', 1541 0x22000027 => 'pinpassphraseoverride',
1534 0x26000028 => 'processcustomactionsfirst', 1542 0x26000028 => 'processcustomactionsfirst',
1535 0x27000030 => 'customactions', 1543 0x27000030 => 'customactions',
1536 0x26000030 => 'nolowmem',
1537 0x26000031 => 'persistbootsequence', 1544 0x26000031 => 'persistbootsequence',
1538 0x25000031 => 'removememory',
1539 0x25000032 => 'increaseuserva',
1540 0x26000032 => 'skipstartupsequence', 1545 0x26000032 => 'skipstartupsequence',
1541 0x25000033 => 'perfmem',
1542 0x22000040 => 'fverecoveryurl', 1546 0x22000040 => 'fverecoveryurl',
1543 0x26000040 => 'vga',
1544 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',
1545 0x26000041 => 'quietboot', 1600 0x26000041 => 'quietboot',
1546 0x26000042 => 'novesa', 1601 0x26000042 => 'novesa',
1547 0x26000043 => 'novga', 1602 0x26000043 => 'novga',
1548 0x25000050 => 'clustermodeaddressing', 1603 0x25000050 => 'clustermodeaddressing',
1549 0x26000051 => 'usephysicaldestination', 1604 0x26000051 => 'usephysicaldestination',
1550 0x25000052 => 'restrictapiccluster', 1605 0x25000052 => 'restrictapiccluster',
1551 0x22000053 => 'evstore', 1606 0x22000053 => 'evstore',
1552 0x26000054 => 'uselegacyapicmode', 1607 0x26000054 => 'uselegacyapicmode',
1553 0x26000060 => 'onecpu', 1608 0x26000060 => 'onecpu',
1554 0x25000061 => 'numproc', 1609 0x25000061 => 'numproc',
1555 0x26000062 => 'maxproc', 1610 0x26000062 => 'maxproc',
1556 0x25000063 => 'configflags', 1611 0x25000063 => 'configflags',
1557 0x26000064 => 'maxgroup', 1612 0x26000064 => 'maxgroup',
1558 0x26000065 => 'groupaware', 1613 0x26000065 => 'groupaware',
1559 0x25000066 => 'groupsize', 1614 0x25000066 => 'groupsize',
1560 0x26000070 => 'usefirmwarepcisettings', 1615 0x26000070 => 'usefirmwarepcisettings',
1561 0x25000071 => 'msi', 1616 0x25000071 => 'msi',
1562 0x25000072 => 'pciexpress', 1617 0x25000072 => 'pciexpress',
1563 0x25000080 => 'safeboot', 1618 0x25000080 => 'safeboot',
1564 0x26000081 => 'safebootalternateshell', 1619 0x26000081 => 'safebootalternateshell',
1565 0x26000090 => 'bootlog', 1620 0x26000090 => 'bootlog',
1566 0x26000091 => 'sos', 1621 0x26000091 => 'sos',
1567 0x260000a0 => 'debug', 1622 0x260000a0 => 'debug',
1568 0x260000a1 => 'halbreakpoint', 1623 0x260000a1 => 'halbreakpoint',
1569 0x260000a2 => 'useplatformclock', 1624 0x260000a2 => 'useplatformclock',
1570 0x260000a3 => 'forcelegacyplatform', 1625 0x260000a3 => 'forcelegacyplatform',
1571 0x260000a4 => 'useplatformtick', 1626 0x260000a4 => 'useplatformtick',
1572 0x260000a5 => 'disabledynamictick', 1627 0x260000a5 => 'disabledynamictick',
1573 0x250000a6 => 'tscsyncpolicy', 1628 0x250000a6 => 'tscsyncpolicy',
1574 0x260000b0 => 'ems', 1629 0x260000b0 => 'ems',
1575 0x250000c0 => 'forcefailure', 1630 0x250000c0 => 'forcefailure',
1576 0x250000c1 => 'driverloadfailurepolicy', 1631 0x250000c1 => 'driverloadfailurepolicy',
1577 0x250000c2 => 'bootmenupolicy', 1632 0x250000c2 => 'bootmenupolicy',
1578 0x260000c3 => 'onetimeadvancedoptions', 1633 0x260000c3 => 'onetimeadvancedoptions',
1579 0x260000c4 => 'onetimeoptionsedit', 1634 0x260000c4 => 'onetimeoptionsedit',
1580 0x250000e0 => 'bootstatuspolicy', 1635 0x250000e0 => 'bootstatuspolicy',
1581 0x260000e1 => 'disableelamdrivers', 1636 0x260000e1 => 'disableelamdrivers',
1582 0x250000f0 => 'hypervisorlaunchtype', 1637 0x250000f0 => 'hypervisorlaunchtype',
1583 0x220000f1 => 'hypervisorpath', 1638 0x220000f1 => 'hypervisorpath',
1584 0x260000f2 => 'hypervisordebug', 1639 0x260000f2 => 'hypervisordebug',
1585 0x250000f3 => 'hypervisordebugtype', 1640 0x250000f3 => 'hypervisordebugtype',
1586 0x250000f4 => 'hypervisordebugport', 1641 0x250000f4 => 'hypervisordebugport',
1587 0x250000f5 => 'hypervisorbaudrate', 1642 0x250000f5 => 'hypervisorbaudrate',
1588 0x250000f6 => 'hypervisorchannel', 1643 0x250000f6 => 'hypervisorchannel',
1589 0x250000f7 => 'bootux', 1644 0x250000f7 => 'bootux',
1590 0x260000f8 => 'hypervisordisableslat', 1645 0x260000f8 => 'hypervisordisableslat',
1591 0x220000f9 => 'hypervisorbusparams', 1646 0x220000f9 => 'hypervisorbusparams',
1592 0x250000fa => 'hypervisornumproc', 1647 0x250000fa => 'hypervisornumproc',
1593 0x250000fb => 'hypervisorrootprocpernode', 1648 0x250000fb => 'hypervisorrootprocpernode',
1594 0x260000fc => 'hypervisoruselargevtlb', 1649 0x260000fc => 'hypervisoruselargevtlb',
1595 0x250000fd => 'hypervisorhostip', 1650 0x250000fd => 'hypervisorhostip',
1596 0x250000fe => 'hypervisorhostport', 1651 0x250000fe => 'hypervisorhostport',
1597 0x250000ff => 'hypervisordebugpages', 1652 0x250000ff => 'hypervisordebugpages',
1598 0x25000100 => 'tpmbootentropy', 1653 0x25000100 => 'tpmbootentropy',
1599 0x22000110 => 'hypervisorusekey', 1654 0x22000110 => 'hypervisorusekey',
1600 0x22000112 => 'hypervisorproductskutype', 1655 0x22000112 => 'hypervisorproductskutype',
1601 0x25000113 => 'hypervisorrootproc', 1656 0x25000113 => 'hypervisorrootproc',
1602 0x26000114 => 'hypervisordhcp', 1657 0x26000114 => 'hypervisordhcp',
1603 0x25000115 => 'hypervisoriommupolicy', 1658 0x25000115 => 'hypervisoriommupolicy',
1604 0x26000116 => 'hypervisorusevapic', 1659 0x26000116 => 'hypervisorusevapic',
1605 0x22000117 => 'hypervisorloadoptions', 1660 0x22000117 => 'hypervisorloadoptions',
1606 0x25000118 => 'hypervisormsrfilterpolicy', 1661 0x25000118 => 'hypervisormsrfilterpolicy',
1607 0x25000119 => 'hypervisormmionxpolicy', 1662 0x25000119 => 'hypervisormmionxpolicy',
1608 0x2500011a => 'hypervisorschedulertype', 1663 0x2500011a => 'hypervisorschedulertype',
1609 0x25000120 => 'xsavepolicy', 1664 0x25000120 => 'xsavepolicy',
1610 0x25000121 => 'xsaveaddfeature0', 1665 0x25000121 => 'xsaveaddfeature0',
1611 0x25000122 => 'xsaveaddfeature1', 1666 0x25000122 => 'xsaveaddfeature1',
1612 0x25000123 => 'xsaveaddfeature2', 1667 0x25000123 => 'xsaveaddfeature2',
1613 0x25000124 => 'xsaveaddfeature3', 1668 0x25000124 => 'xsaveaddfeature3',
1614 0x25000125 => 'xsaveaddfeature4', 1669 0x25000125 => 'xsaveaddfeature4',
1615 0x25000126 => 'xsaveaddfeature5', 1670 0x25000126 => 'xsaveaddfeature5',
1616 0x25000127 => 'xsaveaddfeature6', 1671 0x25000127 => 'xsaveaddfeature6',
1617 0x25000128 => 'xsaveaddfeature7', 1672 0x25000128 => 'xsaveaddfeature7',
1618 0x25000129 => 'xsaveremovefeature', 1673 0x25000129 => 'xsaveremovefeature',
1619 0x2500012a => 'xsaveprocessorsmask', 1674 0x2500012a => 'xsaveprocessorsmask',
1620 0x2500012b => 'xsavedisable', 1675 0x2500012b => 'xsavedisable',
1621 0x2500012c => 'kerneldebugtype', 1676 0x2500012c => 'kerneldebugtype',
1622 0x2200012d => 'kernelbusparams', 1677 0x2200012d => 'kernelbusparams',
1623 0x2500012e => 'kerneldebugaddress', 1678 0x2500012e => 'kerneldebugaddress',
1624 0x2500012f => 'kerneldebugport', 1679 0x2500012f => 'kerneldebugport',
1625 0x25000130 => 'claimedtpmcounter', 1680 0x25000130 => 'claimedtpmcounter',
1626 0x25000131 => 'kernelchannel', 1681 0x25000131 => 'kernelchannel',
1627 0x22000132 => 'kerneltargetname', 1682 0x22000132 => 'kerneltargetname',
1628 0x25000133 => 'kernelhostip', 1683 0x25000133 => 'kernelhostip',
1629 0x25000134 => 'kernelport', 1684 0x25000134 => 'kernelport',
1630 0x26000135 => 'kerneldhcp', 1685 0x26000135 => 'kerneldhcp',
1631 0x22000136 => 'kernelkey', 1686 0x22000136 => 'kernelkey',
1632 0x22000137 => 'imchivename', 1687 0x22000137 => 'imchivename',
1633 0x21000138 => 'imcdevice', 1688 0x21000138 => 'imcdevice',
1634 0x25000139 => 'kernelbaudrate', 1689 0x25000139 => 'kernelbaudrate',
1635 0x22000140 => 'mfgmode', 1690 0x22000140 => 'mfgmode',
1636 0x26000141 => 'event', 1691 0x26000141 => 'event',
1637 0x25000142 => 'vsmlaunchtype', 1692 0x25000142 => 'vsmlaunchtype',
1638 0x25000144 => 'hypervisorenforcedcodeintegrity', 1693 0x25000144 => 'hypervisorenforcedcodeintegrity',
1639 0x26000145 => 'enablebootdebugpolicy',
1640 0x26000146 => 'enablebootorderclean',
1641 0x26000147 => 'enabledeviceid',
1642 0x26000148 => 'enableffuloader',
1643 0x26000149 => 'enableiuloader',
1644 0x2600014a => 'enablemassstorage',
1645 0x2600014b => 'enablerpmbprovisioning',
1646 0x2600014c => 'enablesecurebootpolicy',
1647 0x2600014d => 'enablestartcharge',
1648 0x2600014e => 'enableresettpm',
1649 0x21000150 => 'systemdatadevice', 1694 0x21000150 => 'systemdatadevice',
1650 0x21000151 => 'osarcdevice', 1695 0x21000151 => 'osarcdevice',
1651 0x21000153 => 'osdatadevice', 1696 0x21000153 => 'osdatadevice',
1652 0x21000154 => 'bspdevice', 1697 0x21000154 => 'bspdevice',
1653 0x21000155 => 'bspfilepath', 1698 0x21000155 => 'bspfilepath',
1654 0x26000202 => 'skipffumode', 1699 },
1655 0x26000203 => 'forceffumode', 1700 resume => {
1656 0x25000510 => 'chargethreshold', 1701 0x21000001 => 'filedevice',
1657 0x26000512 => 'offmodecharging', 1702 0x22000002 => 'filepath',
1658 0x25000aaa => 'bootflow', 1703 0x26000003 => 'customsettings',
1659 0x35000001 => 'ramdiskimageoffset', 1704 0x26000004 => 'pae',
1660 0x35000002 => 'ramdisktftpclientport', 1705 0x21000005 => 'associatedosdevice',
1661 0x31000003 => 'ramdisksdidevice', 1706 0x26000006 => 'debugoptionenabled',
1662 0x32000004 => 'ramdisksdipath', 1707 0x25000007 => 'bootux',
1663 0x35000005 => 'ramdiskimagelength', 1708 0x25000008 => 'bootmenupolicy',
1664 0x36000006 => 'exportascd', 1709 0x26000024 => 'hormenabled',
1665 0x35000007 => 'ramdisktftpblocksize', 1710 },
1666 0x35000008 => 'ramdisktftpwindowsize', 1711 startup => {
1667 0x36000009 => 'ramdiskmcenabled', 1712 0x26000001 => 'pxesoftreboot',
1668 0x3600000a => 'ramdiskmctftpfallback', 1713 0x22000002 => 'applicationname',
1669 0x3600000b => 'ramdisktftpvarwindow', 1714 },
1670 0x45000001 => 'devicetype',
1671 0x42000002 => 'applicationrelativepath',
1672 0x42000003 => 'ramdiskdevicerelativepath',
1673 0x46000004 => 'omitosloaderelements',
1674 0x47000006 => 'elementstomigrate',
1675 0x46000010 => 'recoveryos',
1676); 1715);
1677 1716
1678our %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);
1679 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
1680sub 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
1681 $bcde{$_[0]} // sprintf "custom:%08x", $_[0] 1758 sprintf "custom:%08x", $_[0]
1682} 1759}
1683 1760
1761# encodes (elem as name, type)
1684sub enc_bcde_id($) { 1762sub enc_bcde_id($$) {
1685 $_[0] =~ /^custom:([0-9a-fA-F]{8}$)/ 1763 $_[0] =~ /^custom:(?:0x)?([0-9a-fA-F]{8}$)/
1686 ? hex $1 1764 and return hex $1;
1687 : $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
1688} 1775}
1689 1776
1690# decode/encode bcd device element - the horror, no documentaion 1777# decode/encode bcd device element - the horror, no documentaion
1691# whatsoever, supercomplex, superinconsistent. 1778# whatsoever, supercomplex, superinconsistent.
1692 1779
1696 1783
1697our $NULL_DEVICE = "\x00" x 16; 1784our $NULL_DEVICE = "\x00" x 16;
1698 1785
1699# biggest bitch to decode, ever 1786# biggest bitch to decode, ever
1700# this decoded a device portion after the GUID 1787# this decoded a device portion after the GUID
1701sub dec_device_($); 1788sub dec_device_($$);
1702sub dec_device_($) { 1789sub dec_device_($$) {
1703 my ($device) = @_; 1790 my ($device, $type) = @_;
1704 1791
1705 my $res; 1792 my $res;
1706 1793
1707 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, "";
1708 1795
1753 1840
1754 my $partid = $parttype eq "gpt" ? dec_guid $partdata 1841 my $partid = $parttype eq "gpt" ? dec_guid $partdata
1755 : $type eq "partition" ? unpack "Q<", $partdata # byte offset to partition start 1842 : $type eq "partition" ? unpack "Q<", $partdata # byte offset to partition start
1756 : unpack "L<", $partdata; # partition number, one-based 1843 : unpack "L<", $partdata; # partition number, one-based
1757 1844
1758 (my $parent, $device) = dec_device_ $device; 1845 (my $parent, $device) = dec_device_ $device, $type;
1759 1846
1760 $res .= "="; 1847 $res .= "=";
1761 $res .= "<$parent>"; 1848 $res .= "<$parent>";
1762 $res .= ",$blocktype,$parttype,$diskid,$partid"; 1849 $res .= ",$blocktype,$parttype,$diskid,$partid";
1763 1850
1783 or die "unsupported file descriptor version '$fver'\n"; 1870 or die "unsupported file descriptor version '$fver'\n";
1784 1871
1785 $ftype == 5 1872 $ftype == 5
1786 or die "unsupported file descriptor path type '$type'\n"; 1873 or die "unsupported file descriptor path type '$type'\n";
1787 1874
1788 (my $parent, $path) = dec_device_ $path; 1875 (my $parent, $path) = dec_device_ $path, $type;
1789 1876
1790 $path = $dec_path->($path, "file device without path"); 1877 $path = $dec_path->($path, "file device without path");
1791 1878
1792 ($parent, $path) 1879 ($parent, $path)
1793 }; 1880 };
1799 1886
1800 } elsif ($blocktype eq "vhd") { 1887 } elsif ($blocktype eq "vhd") {
1801 $device =~ s/^\x00{20}//s 1888 $device =~ s/^\x00{20}//s
1802 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";
1803 1890
1804 (my $parent, $device) = dec_device_ $device; 1891 (my $parent, $device) = dec_device_ $device, $type;
1805 1892
1806 $res .= "=vhd,<$parent>"; 1893 $res .= "=vhd,<$parent>";
1807 1894
1808 } elsif ($blocktype eq "ramdisk") { 1895 } elsif ($blocktype eq "ramdisk") {
1809 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, "";
1822 my ($mode, $elem, $parent) = unpack "VVV", substr $device, 0, 4 * 3, ""; 1909 my ($mode, $elem, $parent) = unpack "VVV", substr $device, 0, 4 * 3, "";
1823 1910
1824 if ($parent) { 1911 if ($parent) {
1825 # 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
1826 $parent = substr $device, $parent - 4 * 3 - 4 * 4, 1e9, ""; 1913 $parent = substr $device, $parent - 4 * 3 - 4 * 4, 1e9, "";
1827 ($parent, my $tail) = dec_device_ $parent; 1914 ($parent, my $tail) = dec_device_ $parent, $type;
1828 0 == length $tail 1915 0 == length $tail
1829 or die "trailing data after locate device parent\n"; 1916 or die "trailing data after locate device parent\n";
1830 } else { 1917 } else {
1831 $parent = "null"; 1918 $parent = "null";
1832 } 1919 }
1838 1925
1839 if ($mode == 0) { # "Element" 1926 if ($mode == 0) { # "Element"
1840 !length $path 1927 !length $path
1841 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";
1842 1929
1843 $elem = dec_bcde_id $elem; 1930 $elem = dec_bcde_id $elem, $type;
1844 $res .= "element,$elem"; 1931 $res .= "element,$elem";
1845 1932
1846 } elsif ($mode == 1) { # "String" 1933 } elsif ($mode == 1) { # "String"
1847 !$elem 1934 !$elem
1848 or die "device locate mode 1 having non-zero element\n"; 1935 or die "device locate mode 1 having non-zero element\n";
1873 1960
1874 ($res, $tail) 1961 ($res, $tail)
1875} 1962}
1876 1963
1877# decode a full binary BCD device descriptor 1964# decode a full binary BCD device descriptor
1878sub dec_device($) { 1965sub dec_device($$) {
1879 my ($device) = @_; 1966 my ($device, $type) = @_;
1880 1967
1881 $device = pack "H*", $device; 1968 $device = pack "H*", $device;
1882 1969
1883 my $guid = dec_guid substr $device, 0, 16, ""; 1970 my $guid = dec_guid substr $device, 0, 16, "";
1884 $guid = $guid eq "00000000-0000-0000-0000-000000000000" 1971 $guid = $guid eq "00000000-0000-0000-0000-000000000000"
1885 ? "" : "{$guid}"; 1972 ? "" : "{$guid}";
1886 1973
1887 eval { 1974 eval {
1888 my ($dev, $tail) = dec_device_ $device; 1975 my ($dev, $tail) = dec_device_ $device, $type;
1889 1976
1890 $tail eq "" 1977 $tail eq ""
1891 or die "unsupported trailing data after device descriptor\n"; 1978 or die "unsupported trailing data after device descriptor\n";
1892 1979
1893 "$guid$dev" 1980 "$guid$dev"
1905 1992
1906 undef 1993 undef
1907} 1994}
1908 1995
1909# encode the device portion after the GUID 1996# encode the device portion after the GUID
1910sub enc_device_; 1997sub enc_device_($$);
1911sub enc_device_ { 1998sub enc_device_($$) {
1912 my ($device) = @_; 1999 my ($device, $type) = @_;
1913 2000
1914 my $enc_path = sub { 2001 my $enc_path = sub {
1915 my $path = shift; 2002 my $path = shift;
1916 $path =~ s/\//\\/g; 2003 $path =~ s/\//\\/g;
1917 (Encode::encode "UTF-16LE", $path) . "\x00\x00" 2004 (Encode::encode "UTF-16LE", $path) . "\x00\x00"
1935 2022
1936 my $parse_parent = sub { 2023 my $parse_parent = sub {
1937 my $parent; 2024 my $parent;
1938 2025
1939 if (s/^<//) { 2026 if (s/^<//) {
1940 ($parent, $_) = enc_device_ $_; 2027 ($parent, $_) = enc_device_ $_, $type;
1941 s/^>// 2028 s/^>//
1942 or die "$device: syntax error: parent device not followed by '>'\n"; 2029 or die "$device: syntax error: parent device not followed by '>'\n";
1943 } else { 2030 } else {
1944 $parent = $NULL_DEVICE; 2031 $parent = $NULL_DEVICE;
1945 } 2032 }
2033 2120
2034 s/^,// 2121 s/^,//
2035 or die "$_: missing comma after locate parent device\n"; 2122 or die "$_: missing comma after locate parent device\n";
2036 2123
2037 if (s/^element,//) { 2124 if (s/^element,//) {
2038 s/^([0-9a-z]+)//i 2125 s/^([0-9a-z:]+)//i
2039 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";
2040 $elem = enc_bcde_id $1; 2127 $elem = enc_bcde_id $1, $type;
2041 $mode = 0; 2128 $mode = 0;
2042 $path = $enc_path->(""); 2129 $path = $enc_path->("");
2043 2130
2044 } elsif (s/^path,//) { 2131 } elsif (s/^path,//) {
2045 $mode = 1; 2132 $mode = 1;
2124 ); 2211 );
2125 } 2212 }
2126} 2213}
2127 2214
2128# encode a full binary BCD device descriptor 2215# encode a full binary BCD device descriptor
2129sub enc_device { 2216sub enc_device($$) {
2130 my ($device) = @_; 2217 my ($device, $type) = @_;
2131 2218
2132 my $guid = "\x00" x 16; 2219 my $guid = "\x00" x 16;
2133 2220
2134 if ($device =~ s/^\{([A-Za-z0-9\-]+)\}//) { 2221 if ($device =~ s/^\{([A-Za-z0-9\-]+)\}//) {
2135 $guid = enc_guid $1 2222 $guid = enc_guid $1
2136 or die "$device: does not start with valid guid\n"; 2223 or die "$device: does not start with valid guid\n";
2137 } 2224 }
2138 2225
2139 my ($descriptor, $tail) = enc_device_ $device; 2226 my ($descriptor, $tail) = enc_device_ $device, $type;
2140 2227
2141 length $tail 2228 length $tail
2142 and die "$device: garbage after device descriptor\n"; 2229 and die "$device: garbage after device descriptor\n";
2143 2230
2144 unpack "H*", $guid . $descriptor 2231 unpack "H*", $guid . $descriptor
2159 $k = $bcd_objects{$k} // $k; 2246 $k = $bcd_objects{$k} // $k;
2160 2247
2161 my $type = $v->{Description}[0]{Type}[1]; 2248 my $type = $v->{Description}[0]{Type}[1];
2162 2249
2163 if ($type != $bcd_object_types{$k}) { 2250 if ($type != $bcd_object_types{$k}) {
2164 $type = $bcd_types{$type} // sprintf "0x%08x", $type; 2251 $kv{type} = $bcd_types{$type} // sprintf "0x%08x", $type;
2165 $kv{type} = $type;
2166 } 2252 }
2167 2253
2168 my $elems = $v->{Elements}[1]; 2254 my $elems = $v->{Elements}[1];
2169 2255
2170 while (my ($k, $v) = each %$elems) { 2256 while (my ($k, $v) = each %$elems) {
2171 my $k = hex $k; 2257 my $k = hex $k;
2172 2258
2173 my $v = $bcde_dec{$k & BCDE_FORMAT}->($v->[0]{Element}[1]); 2259 my $v = $bcde_dec{$k & BCDE_FORMAT}->($v->[0]{Element}[1], $type);
2174 my $k = dec_bcde_id $k; 2260 my $k = dec_bcde_id $k, $type;
2175 2261
2176 $kv{$k} = $v; 2262 $kv{$k} = $v;
2177 } 2263 }
2178 2264
2179 $bcd{$k} = \%kv; 2265 $bcd{$k} = \%kv;
2220 my %elem; 2306 my %elem;
2221 2307
2222 while (my ($k, $v) = each %$v) { 2308 while (my ($k, $v) = each %$v) {
2223 next if $k eq "type"; 2309 next if $k eq "type";
2224 2310
2225 $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";
2226 $elem{sprintf "%08x", $k} = [{ 2312 $elem{sprintf "%08x", $k} = [{
2227 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)]
2228 }]; 2314 }];
2229 } 2315 }
2230 2316
2246 Objects => [undef, \%objects], 2332 Objects => [undef, \%objects],
2247 }]] 2333 }]]
2248} 2334}
2249 2335
2250############################################################################# 2336#############################################################################
2337# edit instructions
2251 2338
2252sub bcd_edit_eval { 2339sub bcd_edit_eval {
2253 package pbcdedit; 2340 package pbcdedit;
2254 2341
2255 our ($PATH, $BCD, $DEFAULT); 2342 our ($PATH, $BCD, $DEFAULT);
2259} 2346}
2260 2347
2261sub bcd_edit { 2348sub bcd_edit {
2262 my ($path, $bcd, @insns) = @_; 2349 my ($path, $bcd, @insns) = @_;
2263 2350
2264 my $default = $bcd->{"{bootmgr}"}{resumeobject}; 2351 my $default = $bcd->{"{bootmgr}"}{default};
2265 2352
2266 # prepare "officially visible" variables 2353 # prepare "officially visible" variables
2267 local $pbcdedit::PATH = $path; 2354 local $pbcdedit::PATH = $path;
2268 local $pbcdedit::BCD = $bcd; 2355 local $pbcdedit::BCD = $bcd;
2269 local $pbcdedit::DEFAULT = $default; 2356 local $pbcdedit::DEFAULT = $default;
2287 $object = $object eq "{default}" ? $default : dec_wguid enc_wguid $object; 2374 $object = $object eq "{default}" ? $default : dec_wguid enc_wguid $object;
2288 2375
2289 $bcd->{$object}{$elem} = $value; 2376 $bcd->{$object}{$elem} = $value;
2290 2377
2291 } elsif ($insn eq "eval") { 2378 } elsif ($insn eq "eval") {
2292 bcd_edit_eval shift @insns; 2379 my $perl = shift @insns;
2380 bcd_edit_eval "#line 1 'eval'\n$perl";
2293 2381
2294 } elsif ($insn eq "do") { 2382 } elsif ($insn eq "do") {
2295 my $path = shift @insns; 2383 my $path = shift @insns;
2296 my $file = file_load $path; 2384 my $file = file_load $path;
2297 bcd_edit_eval "#line 1 '$path'\n$file"; 2385 bcd_edit_eval "#line 1 '$path'\n$file";
2302 } 2390 }
2303 2391
2304} 2392}
2305 2393
2306############################################################################# 2394#############################################################################
2395# command line parser
2307 2396
2308# json to stdout 2397# json to stdout
2309sub prjson($) { 2398sub prjson($) {
2310 print $json_coder->encode ($_[0]); 2399 print $json_coder->encode ($_[0]);
2311} 2400}
2350 2439
2351 print "\n"; 2440 print "\n";
2352 2441
2353 printf "%-39s %-23s %s\n", "Object GUID", "Alias", "(Hex) Default Type"; 2442 printf "%-39s %-23s %s\n", "Object GUID", "Alias", "(Hex) Default Type";
2354 for my $name (sort keys %rbcd_objects) { 2443 for my $name (sort keys %rbcd_objects) {
2355 my $guid = $rbcd_objects{$name}; 2444 my $guid = $rbcd_objects{$name};
2356 my $type = $bcd_object_types{$name}; 2445 my $type = $bcd_object_types{$name};
2357 my $tname = $bcd_types{$type}; 2446 my $tname = $bcd_types{$type};
2358 2447
2359 $type = $type ? sprintf "(%08x) %s", $type, $tname : "-"; 2448 $type = $type ? sprintf "(%08x) %s", $type, $tname : "-";
2360 2449
2361 printf "%-39s %-23s %s\n", $guid, $name, $type; 2450 printf "%-39s %-23s %s\n", $guid, $name, $type;
2375 BCDE_FORMAT_GUID_LIST , "guid list", 2464 BCDE_FORMAT_GUID_LIST , "guid list",
2376 BCDE_FORMAT_INTEGER , "integer", 2465 BCDE_FORMAT_INTEGER , "integer",
2377 BCDE_FORMAT_BOOLEAN , "boolean", 2466 BCDE_FORMAT_BOOLEAN , "boolean",
2378 BCDE_FORMAT_INTEGER_LIST, "integer list", 2467 BCDE_FORMAT_INTEGER_LIST, "integer list",
2379 ); 2468 );
2380 my %rbcde = reverse %bcde;
2381 $_ = sprintf "%08x", $_ for values %rbcde;
2382 2469
2383 my %element; 2470 my %element;
2384 2471
2472 for my $class (sort keys %rbcde_byclass) {
2473 my $rbcde = $rbcde_byclass{$class};
2474
2385 unless ($json) { 2475 unless ($json) {
2386 print "\n"; 2476 print "\n";
2477 printf "Elements applicable to class(es): $class\n";
2387 printf "%-9s %-12s %s\n", "Element", "Format", "Name Alias"; 2478 printf "%-9s %-12s %s\n", "Element", "Format", "Name Alias";
2388 } 2479 }
2389 for my $name (sort keys %rbcde) { 2480 for my $name (sort keys %$rbcde) {
2390 my $id = $rbcde{$name}; 2481 my $id = $rbcde->{$name};
2391 my $format = $format_name{(hex $id) & BCDE_FORMAT}; 2482 my $format = $format_name{$id & BCDE_FORMAT};
2483 $id = sprintf "%08x", $id;
2392 2484
2393 if ($json) { 2485 if ($json) {
2394 $element{$id} = [$format, $name]; 2486 $element{$id} = [$class, $format, $name];
2395 } else { 2487 } else {
2396 printf "%-9s %-12s %s\n", $id, $format, $name; 2488 printf "%-9s %-12s %s\n", $id, $format, $name;
2489 }
2397 } 2490 }
2398 } 2491 }
2399 print "\n" unless $json; 2492 print "\n" unless $json;
2400 2493
2401 prjson { 2494 prjson {
2402 version => $JSON_VERSION, 2495 version => $JSON_VERSION,
2403 element => \%element, 2496 element => \%element,
2497 class => \@bcde_typeclass,
2404 } if $json; 2498 } if $json;
2405 2499
2406 }, 2500 },
2407 2501
2408 export => sub { 2502 export => sub {
2460 } 2554 }
2461 } 2555 }
2462 } 2556 }
2463 } 2557 }
2464 }, 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 },
2465); 2569);
2466 2570
2467my $cmd = shift; 2571my $cmd = shift;
2468 2572
2469unless (exists $CMD{$cmd}) { 2573unless (exists $CMD{$cmd}) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines