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

Comparing pbcdedit/pbcdedit (file contents):
Revision 1.32 by root, Thu Aug 15 08:38:41 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
34 45
35 pbcdedit export path/to/BCD # output BCD hive as JSON 46 pbcdedit export path/to/BCD # output BCD hive as JSON
36 pbcdedit import path/to/BCD # convert standard input to BCD hive 47 pbcdedit import path/to/BCD # convert standard input to BCD hive
37 pbcdedit edit path/to/BCD edit-instructions... 48 pbcdedit edit path/to/BCD edit-instructions...
38 49
59 70
60=item Does not rely on Windows 71=item Does not rely on Windows
61 72
62As 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
63C<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
64that supports at least perl version 5.14. 75that supports at least perl version 5.16.
65 76
66=item Decodes and encodes BCD device elements 77=item Decodes and encodes BCD device elements
67 78
68PBCDEDIT can concisely decode and encode BCD device element contents. This 79PBCDEDIT can concisely decode and encode BCD device element contents. This
69is 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
91=over 102=over
92 103
93=item C<help> 104=item C<help>
94 105
95Displays the whole manual page (this document). 106Displays the whole manual page (this document).
107
108=item C<version>
109
110This outputs the PBCDEDIT version, the JSON schema version it uses and the
111full log of changes.
96 112
97=item C<export> F<path> 113=item C<export> F<path>
98 114
99Reads 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
100output. 116output.
217 } 233 }
218 234
219=head2 Minimal BCD to boot windows 235=head2 Minimal BCD to boot windows
220 236
221Experimentally I found the following BCD is the minimum required to 237Experimentally I found the following BCD is the minimum required to
222successfully boot any post-XP version of Windows (suitable C<device> and 238successfully boot any post-XP version of Windows (assuming suitable
223C<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>):
224 241
225 { 242 {
226 "{bootmgr}" : { 243 "{bootmgr}" : {
227 "resumeobject" : "{45b547a7-8ca6-4417-9eb0-a257b61f35b4}" 244 "default" : "{45b547a7-8ca6-4417-9eb0-a257b61f35b4}"
228 }, 245 },
229 246
230 "{45b547a7-8ca6-4417-9eb0-a257b61f35b1}" : { 247 "{45b547a7-8ca6-4417-9eb0-a257b61f35b1}" : {
231 "type" : "application::osloader", 248 "type" : "application::osloader",
232 "description" : "Windows Boot", 249 "description" : "Windows Boot",
359 376
360This 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
361lot to refer from one BCD object to other one. 378lot to refer from one BCD object to other one.
362 379
363For 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
364using C<resumeobject>: 381using C<default>:
365 382
366 "resumeobject" : "{7ae02178-821d-11e7-8813-1c872c5f5ab0}", 383 "default" : "{7ae02178-821d-11e7-8813-1c872c5f5ab0}",
367 384
368Human readable aliases are used and allowed. 385Human readable aliases are used and allowed.
369 386
370=item guid list 387=item guid list
371 388
736Similar 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.
737 754
738Example: change the bootmgr default too 755Example: change the bootmgr default too
739C<{b097d2ad-bc00-11e9-8a9a-525400123456}>: 756C<{b097d2ad-bc00-11e9-8a9a-525400123456}>:
740 757
741 pbcdedit edit BCD set "{bootmgr}" resumeobject "{b097d2ad-bc00-11e9-8a9a-525400123456}" 758 pbcdedit edit BCD set "{bootmgr}" default "{b097d2ad-bc00-11e9-8a9a-525400123456}"
742 759
743=item C<eval> I<perlcode> 760=item C<eval> I<perlcode>
744 761
745This takes the next argument, interprets it as Perl code and 762This takes the next argument, interprets it as Perl code and
746evaluates it. This allows you to do more complicated modifications or 763evaluates it. This allows you to do more complicated modifications or
769 786
770 pbcdedit edit BCD eval 'say $BCD->{$DEFAULT}{description}' 787 pbcdedit edit BCD eval 'say $BCD->{$DEFAULT}{description}'
771 788
772The example given for C<set> could be expressed like this: 789The example given for C<set> could be expressed like this:
773 790
774 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}"'
775 792
776=item C<do> I<path> 793=item C<do> I<path>
777 794
778Similar 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,
779it 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
825permitted by law. 842permitted by law.
826 843
827=cut 844=cut
828 845
829# common sense is optional, but recommended 846# common sense is optional, but recommended
830#BEGIN { eval { require "common/sensex.pm"; } && common::sensex->import } 847BEGIN { eval { require "common/sense.pm"; } && common::sense->import }
831use common::sense;
832 848
833use Data::Dump; 849no warnings 'portable'; # avoid 32 bit integer warnings
850
834use Encode (); 851use Encode ();
835use List::Util (); 852use List::Util ();
836use IO::Handle (); 853use IO::Handle ();
837use Time::HiRes (); 854use Time::HiRes ();
838 855
1360sub BCDE_FORMAT_GUID_LIST () { 0x04000000 } 1377sub BCDE_FORMAT_GUID_LIST () { 0x04000000 }
1361sub BCDE_FORMAT_INTEGER () { 0x05000000 } 1378sub BCDE_FORMAT_INTEGER () { 0x05000000 }
1362sub BCDE_FORMAT_BOOLEAN () { 0x06000000 } 1379sub BCDE_FORMAT_BOOLEAN () { 0x06000000 }
1363sub BCDE_FORMAT_INTEGER_LIST () { 0x07000000 } 1380sub BCDE_FORMAT_INTEGER_LIST () { 0x07000000 }
1364 1381
1365sub dec_device;
1366sub enc_device;
1367
1368sub enc_integer($) { 1382sub enc_integer($) {
1369 no warnings 'portable'; # ugh
1370 my $value = shift; 1383 my $value = shift;
1371 $value = oct $value if $value =~ /^0[bBxX]/; 1384 $value = oct $value if $value =~ /^0[bBxX]/;
1372 unpack "H*", pack "Q<", $value 1385 unpack "H*", pack "Q<", $value
1373} 1386}
1387
1388sub enc_device($$);
1389sub dec_device($$);
1374 1390
1375our %bcde_dec = ( 1391our %bcde_dec = (
1376 BCDE_FORMAT_DEVICE , \&dec_device, 1392 BCDE_FORMAT_DEVICE , \&dec_device,
1377# # for round-trip verification 1393# # for round-trip verification
1378# BCDE_FORMAT_DEVICE , sub { 1394# BCDE_FORMAT_DEVICE , sub {
1388 BCDE_FORMAT_BOOLEAN , sub { shift eq "00" ? 0 : 1 }, 1404 BCDE_FORMAT_BOOLEAN , sub { shift eq "00" ? 0 : 1 },
1389 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
1390); 1406);
1391 1407
1392our %bcde_enc = ( 1408our %bcde_enc = (
1393 BCDE_FORMAT_DEVICE , sub { binary => enc_device shift }, 1409 BCDE_FORMAT_DEVICE , sub { binary => enc_device $_[0], $_[1] },
1394 BCDE_FORMAT_STRING , sub { sz => shift }, 1410 BCDE_FORMAT_STRING , sub { sz => shift },
1395 BCDE_FORMAT_GUID , sub { sz => "{" . (dec_guid enc_wguid shift) . "}" }, 1411 BCDE_FORMAT_GUID , sub { sz => "{" . (dec_guid enc_wguid shift) . "}" },
1396 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 ] },
1397 BCDE_FORMAT_INTEGER , sub { binary => enc_integer shift }, 1413 BCDE_FORMAT_INTEGER , sub { binary => enc_integer shift },
1398 BCDE_FORMAT_BOOLEAN , sub { binary => shift ? "01" : "00" }, 1414 BCDE_FORMAT_BOOLEAN , sub { binary => shift ? "01" : "00" },
1399 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 },
1400); 1416);
1401 1417
1402# BCD Elements 1418# BCD Elements
1403our %bcde = ( 1419our %bcde_byclass = (
1420 any => {
1404 0x11000001 => 'device', 1421 0x11000001 => 'device',
1405 0x12000002 => 'path', 1422 0x12000002 => 'path',
1406 0x12000004 => 'description', 1423 0x12000004 => 'description',
1407 0x12000005 => 'locale', 1424 0x12000005 => 'locale',
1408 0x14000006 => 'inherit', 1425 0x14000006 => 'inherit',
1409 0x15000007 => 'truncatememory', 1426 0x15000007 => 'truncatememory',
1410 0x14000008 => 'recoverysequence', 1427 0x14000008 => 'recoverysequence',
1411 0x16000009 => 'recoveryenabled', 1428 0x16000009 => 'recoveryenabled',
1412 0x1700000a => 'badmemorylist', 1429 0x1700000a => 'badmemorylist',
1413 0x1600000b => 'badmemoryaccess', 1430 0x1600000b => 'badmemoryaccess',
1414 0x1500000c => 'firstmegabytepolicy', 1431 0x1500000c => 'firstmegabytepolicy',
1415 0x1500000d => 'relocatephysical', 1432 0x1500000d => 'relocatephysical',
1416 0x1500000e => 'avoidlowmemory', 1433 0x1500000e => 'avoidlowmemory',
1417 0x1600000f => 'traditionalkseg', 1434 0x1600000f => 'traditionalkseg',
1418 0x16000010 => 'bootdebug', 1435 0x16000010 => 'bootdebug',
1419 0x15000011 => 'debugtype', 1436 0x15000011 => 'debugtype',
1420 0x15000012 => 'debugaddress', 1437 0x15000012 => 'debugaddress',
1421 0x15000013 => 'debugport', 1438 0x15000013 => 'debugport',
1422 0x15000014 => 'baudrate', 1439 0x15000014 => 'baudrate',
1423 0x15000015 => 'channel', 1440 0x15000015 => 'channel',
1424 0x12000016 => 'targetname', 1441 0x12000016 => 'targetname',
1425 0x16000017 => 'noumex', 1442 0x16000017 => 'noumex',
1426 0x15000018 => 'debugstart', 1443 0x15000018 => 'debugstart',
1427 0x12000019 => 'busparams', 1444 0x12000019 => 'busparams',
1428 0x1500001a => 'hostip', 1445 0x1500001a => 'hostip',
1429 0x1500001b => 'port', 1446 0x1500001b => 'port',
1430 0x1600001c => 'dhcp', 1447 0x1600001c => 'dhcp',
1431 0x1200001d => 'key', 1448 0x1200001d => 'key',
1432 0x1600001e => 'vm', 1449 0x1600001e => 'vm',
1433 0x16000020 => 'bootems', 1450 0x16000020 => 'bootems',
1434 0x15000022 => 'emsport', 1451 0x15000022 => 'emsport',
1435 0x15000023 => 'emsbaudrate', 1452 0x15000023 => 'emsbaudrate',
1436 0x12000030 => 'loadoptions', 1453 0x12000030 => 'loadoptions',
1437 0x16000040 => 'advancedoptions', 1454 0x16000040 => 'advancedoptions',
1438 0x16000041 => 'optionsedit', 1455 0x16000041 => 'optionsedit',
1439 0x15000042 => 'keyringaddress', 1456 0x15000042 => 'keyringaddress',
1440 0x11000043 => 'bootstatdevice', 1457 0x11000043 => 'bootstatdevice',
1441 0x12000044 => 'bootstatfilepath', 1458 0x12000044 => 'bootstatfilepath',
1442 0x16000045 => 'preservebootstat', 1459 0x16000045 => 'preservebootstat',
1443 0x16000046 => 'graphicsmodedisabled', 1460 0x16000046 => 'graphicsmodedisabled',
1444 0x15000047 => 'configaccesspolicy', 1461 0x15000047 => 'configaccesspolicy',
1445 0x16000048 => 'nointegritychecks', 1462 0x16000048 => 'nointegritychecks',
1446 0x16000049 => 'testsigning', 1463 0x16000049 => 'testsigning',
1447 0x1200004a => 'fontpath', 1464 0x1200004a => 'fontpath',
1448 0x1500004b => 'integrityservices', 1465 0x1500004b => 'integrityservices',
1449 0x1500004c => 'volumebandid', 1466 0x1500004c => 'volumebandid',
1450 0x16000050 => 'extendedinput', 1467 0x16000050 => 'extendedinput',
1451 0x15000051 => 'initialconsoleinput', 1468 0x15000051 => 'initialconsoleinput',
1452 0x15000052 => 'graphicsresolution', 1469 0x15000052 => 'graphicsresolution',
1453 0x16000053 => 'restartonfailure', 1470 0x16000053 => 'restartonfailure',
1454 0x16000054 => 'highestmode', 1471 0x16000054 => 'highestmode',
1455 0x16000060 => 'isolatedcontext', 1472 0x16000060 => 'isolatedcontext',
1456 0x15000065 => 'displaymessage', 1473 0x15000065 => 'displaymessage',
1457 0x15000066 => 'displaymessageoverride', 1474 0x15000066 => 'displaymessageoverride',
1458 0x16000068 => 'nobootuxtext', 1475 0x16000068 => 'nobootuxtext',
1459 0x16000069 => 'nobootuxprogress', 1476 0x16000069 => 'nobootuxprogress',
1460 0x1600006a => 'nobootuxfade', 1477 0x1600006a => 'nobootuxfade',
1461 0x1600006b => 'bootuxreservepooldebug', 1478 0x1600006b => 'bootuxreservepooldebug',
1462 0x1600006c => 'bootuxdisabled', 1479 0x1600006c => 'bootuxdisabled',
1463 0x1500006d => 'bootuxfadeframes', 1480 0x1500006d => 'bootuxfadeframes',
1464 0x1600006e => 'bootuxdumpstats', 1481 0x1600006e => 'bootuxdumpstats',
1465 0x1600006f => 'bootuxshowstats', 1482 0x1600006f => 'bootuxshowstats',
1466 0x16000071 => 'multibootsystem', 1483 0x16000071 => 'multibootsystem',
1467 0x16000072 => 'nokeyboard', 1484 0x16000072 => 'nokeyboard',
1468 0x15000073 => 'aliaswindowskey', 1485 0x15000073 => 'aliaswindowskey',
1469 0x16000074 => 'bootshutdowndisabled', 1486 0x16000074 => 'bootshutdowndisabled',
1470 0x15000075 => 'performancefrequency', 1487 0x15000075 => 'performancefrequency',
1471 0x15000076 => 'securebootrawpolicy', 1488 0x15000076 => 'securebootrawpolicy',
1472 0x17000077 => 'allowedinmemorysettings', 1489 0x17000077 => 'allowedinmemorysettings',
1473 0x15000079 => 'bootuxtransitiontime', 1490 0x15000079 => 'bootuxtransitiontime',
1474 0x1600007a => 'mobilegraphics', 1491 0x1600007a => 'mobilegraphics',
1475 0x1600007b => 'forcefipscrypto', 1492 0x1600007b => 'forcefipscrypto',
1476 0x1500007d => 'booterrorux', 1493 0x1500007d => 'booterrorux',
1477 0x1600007e => 'flightsigning', 1494 0x1600007e => 'flightsigning',
1478 0x1500007f => 'measuredbootlogformat', 1495 0x1500007f => 'measuredbootlogformat',
1479 0x15000080 => 'displayrotation', 1496 0x15000080 => 'displayrotation',
1480 0x15000081 => 'logcontrol', 1497 0x15000081 => 'logcontrol',
1481 0x16000082 => 'nofirmwaresync', 1498 0x16000082 => 'nofirmwaresync',
1482 0x11000084 => 'windowssyspart', 1499 0x11000084 => 'windowssyspart',
1483 0x16000087 => 'numlock', 1500 0x16000087 => 'numlock',
1484 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 => {
1485 0x24000001 => 'displayorder', 1526 0x24000001 => 'displayorder',
1486 0x21000001 => 'filedevice',
1487 0x21000001 => 'osdevice',
1488 0x25000001 => 'passcount',
1489 0x26000001 => 'pxesoftreboot',
1490 0x22000002 => 'applicationname',
1491 0x24000002 => 'bootsequence', 1527 0x24000002 => 'bootsequence',
1492 0x22000002 => 'filepath',
1493 0x22000002 => 'systemroot',
1494 0x25000002 => 'testmix',
1495 0x26000003 => 'cacheenable',
1496 0x26000003 => 'customsettings',
1497 0x23000003 => 'default', 1528 0x23000003 => 'default',
1498 0x25000003 => 'failurecount',
1499 0x23000003 => 'resumeobject',
1500 0x26000004 => 'failuresenabled',
1501 0x26000004 => 'pae',
1502 0x26000004 => 'stampdisks',
1503 0x25000004 => 'testtofail',
1504 0x25000004 => 'timeout', 1529 0x25000004 => 'timeout',
1505 0x21000005 => 'associatedosdevice',
1506 0x26000005 => 'cacheenable',
1507 0x26000005 => 'resume', 1530 0x26000005 => 'resume',
1508 0x25000005 => 'stridefailcount',
1509 0x26000006 => 'debugoptionenabled',
1510 0x25000006 => 'invcfailcount',
1511 0x23000006 => 'resumeobject', 1531 0x23000006 => 'resumeobject',
1512 0x25000007 => 'bootux',
1513 0x25000007 => 'matsfailcount',
1514 0x24000007 => 'startupsequence', 1532 0x24000007 => 'startupsequence',
1515 0x25000008 => 'bootmenupolicy',
1516 0x25000008 => 'randfailcount',
1517 0x25000009 => 'chckrfailcount',
1518 0x26000010 => 'detecthal',
1519 0x24000010 => 'toolsdisplayorder', 1533 0x24000010 => 'toolsdisplayorder',
1520 0x22000011 => 'kernel',
1521 0x22000012 => 'hal',
1522 0x22000013 => 'dbgtransport',
1523 0x26000020 => 'displaybootmenu', 1534 0x26000020 => 'displaybootmenu',
1524 0x25000020 => 'nx',
1525 0x26000021 => 'noerrordisplay', 1535 0x26000021 => 'noerrordisplay',
1526 0x25000021 => 'pae',
1527 0x21000022 => 'bcddevice', 1536 0x21000022 => 'bcddevice',
1528 0x26000022 => 'winpe',
1529 0x22000023 => 'bcdfilepath', 1537 0x22000023 => 'bcdfilepath',
1530 0x26000024 => 'hormenabled', 1538 0x26000024 => 'hormenabled',
1531 0x26000024 => 'hormenabled',
1532 0x26000024 => 'nocrashautoreboot',
1533 0x26000025 => 'hiberboot', 1539 0x26000025 => 'hiberboot',
1534 0x26000025 => 'lastknowngood',
1535 0x26000026 => 'oslnointegritychecks',
1536 0x22000026 => 'passwordoverride', 1540 0x22000026 => 'passwordoverride',
1537 0x26000027 => 'osltestsigning',
1538 0x22000027 => 'pinpassphraseoverride', 1541 0x22000027 => 'pinpassphraseoverride',
1539 0x26000028 => 'processcustomactionsfirst', 1542 0x26000028 => 'processcustomactionsfirst',
1540 0x27000030 => 'customactions', 1543 0x27000030 => 'customactions',
1541 0x26000030 => 'nolowmem',
1542 0x26000031 => 'persistbootsequence', 1544 0x26000031 => 'persistbootsequence',
1543 0x25000031 => 'removememory',
1544 0x25000032 => 'increaseuserva',
1545 0x26000032 => 'skipstartupsequence', 1545 0x26000032 => 'skipstartupsequence',
1546 0x25000033 => 'perfmem',
1547 0x22000040 => 'fverecoveryurl', 1546 0x22000040 => 'fverecoveryurl',
1548 0x26000040 => 'vga',
1549 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',
1550 0x26000041 => 'quietboot', 1600 0x26000041 => 'quietboot',
1551 0x26000042 => 'novesa', 1601 0x26000042 => 'novesa',
1552 0x26000043 => 'novga', 1602 0x26000043 => 'novga',
1553 0x25000050 => 'clustermodeaddressing', 1603 0x25000050 => 'clustermodeaddressing',
1554 0x26000051 => 'usephysicaldestination', 1604 0x26000051 => 'usephysicaldestination',
1555 0x25000052 => 'restrictapiccluster', 1605 0x25000052 => 'restrictapiccluster',
1556 0x22000053 => 'evstore', 1606 0x22000053 => 'evstore',
1557 0x26000054 => 'uselegacyapicmode', 1607 0x26000054 => 'uselegacyapicmode',
1558 0x26000060 => 'onecpu', 1608 0x26000060 => 'onecpu',
1559 0x25000061 => 'numproc', 1609 0x25000061 => 'numproc',
1560 0x26000062 => 'maxproc', 1610 0x26000062 => 'maxproc',
1561 0x25000063 => 'configflags', 1611 0x25000063 => 'configflags',
1562 0x26000064 => 'maxgroup', 1612 0x26000064 => 'maxgroup',
1563 0x26000065 => 'groupaware', 1613 0x26000065 => 'groupaware',
1564 0x25000066 => 'groupsize', 1614 0x25000066 => 'groupsize',
1565 0x26000070 => 'usefirmwarepcisettings', 1615 0x26000070 => 'usefirmwarepcisettings',
1566 0x25000071 => 'msi', 1616 0x25000071 => 'msi',
1567 0x25000072 => 'pciexpress', 1617 0x25000072 => 'pciexpress',
1568 0x25000080 => 'safeboot', 1618 0x25000080 => 'safeboot',
1569 0x26000081 => 'safebootalternateshell', 1619 0x26000081 => 'safebootalternateshell',
1570 0x26000090 => 'bootlog', 1620 0x26000090 => 'bootlog',
1571 0x26000091 => 'sos', 1621 0x26000091 => 'sos',
1572 0x260000a0 => 'debug', 1622 0x260000a0 => 'debug',
1573 0x260000a1 => 'halbreakpoint', 1623 0x260000a1 => 'halbreakpoint',
1574 0x260000a2 => 'useplatformclock', 1624 0x260000a2 => 'useplatformclock',
1575 0x260000a3 => 'forcelegacyplatform', 1625 0x260000a3 => 'forcelegacyplatform',
1576 0x260000a4 => 'useplatformtick', 1626 0x260000a4 => 'useplatformtick',
1577 0x260000a5 => 'disabledynamictick', 1627 0x260000a5 => 'disabledynamictick',
1578 0x250000a6 => 'tscsyncpolicy', 1628 0x250000a6 => 'tscsyncpolicy',
1579 0x260000b0 => 'ems', 1629 0x260000b0 => 'ems',
1580 0x250000c0 => 'forcefailure', 1630 0x250000c0 => 'forcefailure',
1581 0x250000c1 => 'driverloadfailurepolicy', 1631 0x250000c1 => 'driverloadfailurepolicy',
1582 0x250000c2 => 'bootmenupolicy', 1632 0x250000c2 => 'bootmenupolicy',
1583 0x260000c3 => 'onetimeadvancedoptions', 1633 0x260000c3 => 'onetimeadvancedoptions',
1584 0x260000c4 => 'onetimeoptionsedit', 1634 0x260000c4 => 'onetimeoptionsedit',
1585 0x250000e0 => 'bootstatuspolicy', 1635 0x250000e0 => 'bootstatuspolicy',
1586 0x260000e1 => 'disableelamdrivers', 1636 0x260000e1 => 'disableelamdrivers',
1587 0x250000f0 => 'hypervisorlaunchtype', 1637 0x250000f0 => 'hypervisorlaunchtype',
1588 0x220000f1 => 'hypervisorpath', 1638 0x220000f1 => 'hypervisorpath',
1589 0x260000f2 => 'hypervisordebug', 1639 0x260000f2 => 'hypervisordebug',
1590 0x250000f3 => 'hypervisordebugtype', 1640 0x250000f3 => 'hypervisordebugtype',
1591 0x250000f4 => 'hypervisordebugport', 1641 0x250000f4 => 'hypervisordebugport',
1592 0x250000f5 => 'hypervisorbaudrate', 1642 0x250000f5 => 'hypervisorbaudrate',
1593 0x250000f6 => 'hypervisorchannel', 1643 0x250000f6 => 'hypervisorchannel',
1594 0x250000f7 => 'bootux', 1644 0x250000f7 => 'bootux',
1595 0x260000f8 => 'hypervisordisableslat', 1645 0x260000f8 => 'hypervisordisableslat',
1596 0x220000f9 => 'hypervisorbusparams', 1646 0x220000f9 => 'hypervisorbusparams',
1597 0x250000fa => 'hypervisornumproc', 1647 0x250000fa => 'hypervisornumproc',
1598 0x250000fb => 'hypervisorrootprocpernode', 1648 0x250000fb => 'hypervisorrootprocpernode',
1599 0x260000fc => 'hypervisoruselargevtlb', 1649 0x260000fc => 'hypervisoruselargevtlb',
1600 0x250000fd => 'hypervisorhostip', 1650 0x250000fd => 'hypervisorhostip',
1601 0x250000fe => 'hypervisorhostport', 1651 0x250000fe => 'hypervisorhostport',
1602 0x250000ff => 'hypervisordebugpages', 1652 0x250000ff => 'hypervisordebugpages',
1603 0x25000100 => 'tpmbootentropy', 1653 0x25000100 => 'tpmbootentropy',
1604 0x22000110 => 'hypervisorusekey', 1654 0x22000110 => 'hypervisorusekey',
1605 0x22000112 => 'hypervisorproductskutype', 1655 0x22000112 => 'hypervisorproductskutype',
1606 0x25000113 => 'hypervisorrootproc', 1656 0x25000113 => 'hypervisorrootproc',
1607 0x26000114 => 'hypervisordhcp', 1657 0x26000114 => 'hypervisordhcp',
1608 0x25000115 => 'hypervisoriommupolicy', 1658 0x25000115 => 'hypervisoriommupolicy',
1609 0x26000116 => 'hypervisorusevapic', 1659 0x26000116 => 'hypervisorusevapic',
1610 0x22000117 => 'hypervisorloadoptions', 1660 0x22000117 => 'hypervisorloadoptions',
1611 0x25000118 => 'hypervisormsrfilterpolicy', 1661 0x25000118 => 'hypervisormsrfilterpolicy',
1612 0x25000119 => 'hypervisormmionxpolicy', 1662 0x25000119 => 'hypervisormmionxpolicy',
1613 0x2500011a => 'hypervisorschedulertype', 1663 0x2500011a => 'hypervisorschedulertype',
1614 0x25000120 => 'xsavepolicy', 1664 0x25000120 => 'xsavepolicy',
1615 0x25000121 => 'xsaveaddfeature0', 1665 0x25000121 => 'xsaveaddfeature0',
1616 0x25000122 => 'xsaveaddfeature1', 1666 0x25000122 => 'xsaveaddfeature1',
1617 0x25000123 => 'xsaveaddfeature2', 1667 0x25000123 => 'xsaveaddfeature2',
1618 0x25000124 => 'xsaveaddfeature3', 1668 0x25000124 => 'xsaveaddfeature3',
1619 0x25000125 => 'xsaveaddfeature4', 1669 0x25000125 => 'xsaveaddfeature4',
1620 0x25000126 => 'xsaveaddfeature5', 1670 0x25000126 => 'xsaveaddfeature5',
1621 0x25000127 => 'xsaveaddfeature6', 1671 0x25000127 => 'xsaveaddfeature6',
1622 0x25000128 => 'xsaveaddfeature7', 1672 0x25000128 => 'xsaveaddfeature7',
1623 0x25000129 => 'xsaveremovefeature', 1673 0x25000129 => 'xsaveremovefeature',
1624 0x2500012a => 'xsaveprocessorsmask', 1674 0x2500012a => 'xsaveprocessorsmask',
1625 0x2500012b => 'xsavedisable', 1675 0x2500012b => 'xsavedisable',
1626 0x2500012c => 'kerneldebugtype', 1676 0x2500012c => 'kerneldebugtype',
1627 0x2200012d => 'kernelbusparams', 1677 0x2200012d => 'kernelbusparams',
1628 0x2500012e => 'kerneldebugaddress', 1678 0x2500012e => 'kerneldebugaddress',
1629 0x2500012f => 'kerneldebugport', 1679 0x2500012f => 'kerneldebugport',
1630 0x25000130 => 'claimedtpmcounter', 1680 0x25000130 => 'claimedtpmcounter',
1631 0x25000131 => 'kernelchannel', 1681 0x25000131 => 'kernelchannel',
1632 0x22000132 => 'kerneltargetname', 1682 0x22000132 => 'kerneltargetname',
1633 0x25000133 => 'kernelhostip', 1683 0x25000133 => 'kernelhostip',
1634 0x25000134 => 'kernelport', 1684 0x25000134 => 'kernelport',
1635 0x26000135 => 'kerneldhcp', 1685 0x26000135 => 'kerneldhcp',
1636 0x22000136 => 'kernelkey', 1686 0x22000136 => 'kernelkey',
1637 0x22000137 => 'imchivename', 1687 0x22000137 => 'imchivename',
1638 0x21000138 => 'imcdevice', 1688 0x21000138 => 'imcdevice',
1639 0x25000139 => 'kernelbaudrate', 1689 0x25000139 => 'kernelbaudrate',
1640 0x22000140 => 'mfgmode', 1690 0x22000140 => 'mfgmode',
1641 0x26000141 => 'event', 1691 0x26000141 => 'event',
1642 0x25000142 => 'vsmlaunchtype', 1692 0x25000142 => 'vsmlaunchtype',
1643 0x25000144 => 'hypervisorenforcedcodeintegrity', 1693 0x25000144 => 'hypervisorenforcedcodeintegrity',
1644 0x26000145 => 'enablebootdebugpolicy',
1645 0x26000146 => 'enablebootorderclean',
1646 0x26000147 => 'enabledeviceid',
1647 0x26000148 => 'enableffuloader',
1648 0x26000149 => 'enableiuloader',
1649 0x2600014a => 'enablemassstorage',
1650 0x2600014b => 'enablerpmbprovisioning',
1651 0x2600014c => 'enablesecurebootpolicy',
1652 0x2600014d => 'enablestartcharge',
1653 0x2600014e => 'enableresettpm',
1654 0x21000150 => 'systemdatadevice', 1694 0x21000150 => 'systemdatadevice',
1655 0x21000151 => 'osarcdevice', 1695 0x21000151 => 'osarcdevice',
1656 0x21000153 => 'osdatadevice', 1696 0x21000153 => 'osdatadevice',
1657 0x21000154 => 'bspdevice', 1697 0x21000154 => 'bspdevice',
1658 0x21000155 => 'bspfilepath', 1698 0x21000155 => 'bspfilepath',
1659 0x26000202 => 'skipffumode', 1699 },
1660 0x26000203 => 'forceffumode', 1700 resume => {
1661 0x25000510 => 'chargethreshold', 1701 0x21000001 => 'filedevice',
1662 0x26000512 => 'offmodecharging', 1702 0x22000002 => 'filepath',
1663 0x25000aaa => 'bootflow', 1703 0x26000003 => 'customsettings',
1664 0x35000001 => 'ramdiskimageoffset', 1704 0x26000004 => 'pae',
1665 0x35000002 => 'ramdisktftpclientport', 1705 0x21000005 => 'associatedosdevice',
1666 0x31000003 => 'ramdisksdidevice', 1706 0x26000006 => 'debugoptionenabled',
1667 0x32000004 => 'ramdisksdipath', 1707 0x25000007 => 'bootux',
1668 0x35000005 => 'ramdiskimagelength', 1708 0x25000008 => 'bootmenupolicy',
1669 0x36000006 => 'exportascd', 1709 0x26000024 => 'hormenabled',
1670 0x35000007 => 'ramdisktftpblocksize', 1710 },
1671 0x35000008 => 'ramdisktftpwindowsize', 1711 startup => {
1672 0x36000009 => 'ramdiskmcenabled', 1712 0x26000001 => 'pxesoftreboot',
1673 0x3600000a => 'ramdiskmctftpfallback', 1713 0x22000002 => 'applicationname',
1674 0x3600000b => 'ramdisktftpvarwindow', 1714 },
1675 0x45000001 => 'devicetype',
1676 0x42000002 => 'applicationrelativepath',
1677 0x42000003 => 'ramdiskdevicerelativepath',
1678 0x46000004 => 'omitosloaderelements',
1679 0x47000006 => 'elementstomigrate',
1680 0x46000010 => 'recoveryos',
1681); 1715);
1682 1716
1683our %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);
1684 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
1685sub 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
1686 $bcde{$_[0]} // sprintf "custom:%08x", $_[0] 1758 sprintf "custom:%08x", $_[0]
1687} 1759}
1688 1760
1761# encodes (elem as name, type)
1689sub enc_bcde_id($) { 1762sub enc_bcde_id($$) {
1690 $_[0] =~ /^custom:([0-9a-fA-F]{8}$)/ 1763 $_[0] =~ /^custom:(?:0x)?([0-9a-fA-F]{8}$)/
1691 ? hex $1 1764 and return hex $1;
1692 : $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
1693} 1775}
1694 1776
1695# decode/encode bcd device element - the horror, no documentaion 1777# decode/encode bcd device element - the horror, no documentaion
1696# whatsoever, supercomplex, superinconsistent. 1778# whatsoever, supercomplex, superinconsistent.
1697 1779
1701 1783
1702our $NULL_DEVICE = "\x00" x 16; 1784our $NULL_DEVICE = "\x00" x 16;
1703 1785
1704# biggest bitch to decode, ever 1786# biggest bitch to decode, ever
1705# this decoded a device portion after the GUID 1787# this decoded a device portion after the GUID
1706sub dec_device_($); 1788sub dec_device_($$);
1707sub dec_device_($) { 1789sub dec_device_($$) {
1708 my ($device) = @_; 1790 my ($device, $type) = @_;
1709 1791
1710 my $res; 1792 my $res;
1711 1793
1712 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, "";
1713 1795
1758 1840
1759 my $partid = $parttype eq "gpt" ? dec_guid $partdata 1841 my $partid = $parttype eq "gpt" ? dec_guid $partdata
1760 : $type eq "partition" ? unpack "Q<", $partdata # byte offset to partition start 1842 : $type eq "partition" ? unpack "Q<", $partdata # byte offset to partition start
1761 : unpack "L<", $partdata; # partition number, one-based 1843 : unpack "L<", $partdata; # partition number, one-based
1762 1844
1763 (my $parent, $device) = dec_device_ $device; 1845 (my $parent, $device) = dec_device_ $device, $type;
1764 1846
1765 $res .= "="; 1847 $res .= "=";
1766 $res .= "<$parent>"; 1848 $res .= "<$parent>";
1767 $res .= ",$blocktype,$parttype,$diskid,$partid"; 1849 $res .= ",$blocktype,$parttype,$diskid,$partid";
1768 1850
1788 or die "unsupported file descriptor version '$fver'\n"; 1870 or die "unsupported file descriptor version '$fver'\n";
1789 1871
1790 $ftype == 5 1872 $ftype == 5
1791 or die "unsupported file descriptor path type '$type'\n"; 1873 or die "unsupported file descriptor path type '$type'\n";
1792 1874
1793 (my $parent, $path) = dec_device_ $path; 1875 (my $parent, $path) = dec_device_ $path, $type;
1794 1876
1795 $path = $dec_path->($path, "file device without path"); 1877 $path = $dec_path->($path, "file device without path");
1796 1878
1797 ($parent, $path) 1879 ($parent, $path)
1798 }; 1880 };
1804 1886
1805 } elsif ($blocktype eq "vhd") { 1887 } elsif ($blocktype eq "vhd") {
1806 $device =~ s/^\x00{20}//s 1888 $device =~ s/^\x00{20}//s
1807 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";
1808 1890
1809 (my $parent, $device) = dec_device_ $device; 1891 (my $parent, $device) = dec_device_ $device, $type;
1810 1892
1811 $res .= "=vhd,<$parent>"; 1893 $res .= "=vhd,<$parent>";
1812 1894
1813 } elsif ($blocktype eq "ramdisk") { 1895 } elsif ($blocktype eq "ramdisk") {
1814 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, "";
1827 my ($mode, $elem, $parent) = unpack "VVV", substr $device, 0, 4 * 3, ""; 1909 my ($mode, $elem, $parent) = unpack "VVV", substr $device, 0, 4 * 3, "";
1828 1910
1829 if ($parent) { 1911 if ($parent) {
1830 # 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
1831 $parent = substr $device, $parent - 4 * 3 - 4 * 4, 1e9, ""; 1913 $parent = substr $device, $parent - 4 * 3 - 4 * 4, 1e9, "";
1832 ($parent, my $tail) = dec_device_ $parent; 1914 ($parent, my $tail) = dec_device_ $parent, $type;
1833 0 == length $tail 1915 0 == length $tail
1834 or die "trailing data after locate device parent\n"; 1916 or die "trailing data after locate device parent\n";
1835 } else { 1917 } else {
1836 $parent = "null"; 1918 $parent = "null";
1837 } 1919 }
1843 1925
1844 if ($mode == 0) { # "Element" 1926 if ($mode == 0) { # "Element"
1845 !length $path 1927 !length $path
1846 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";
1847 1929
1848 $elem = dec_bcde_id $elem; 1930 $elem = dec_bcde_id $elem, $type;
1849 $res .= "element,$elem"; 1931 $res .= "element,$elem";
1850 1932
1851 } elsif ($mode == 1) { # "String" 1933 } elsif ($mode == 1) { # "String"
1852 !$elem 1934 !$elem
1853 or die "device locate mode 1 having non-zero element\n"; 1935 or die "device locate mode 1 having non-zero element\n";
1878 1960
1879 ($res, $tail) 1961 ($res, $tail)
1880} 1962}
1881 1963
1882# decode a full binary BCD device descriptor 1964# decode a full binary BCD device descriptor
1883sub dec_device($) { 1965sub dec_device($$) {
1884 my ($device) = @_; 1966 my ($device, $type) = @_;
1885 1967
1886 $device = pack "H*", $device; 1968 $device = pack "H*", $device;
1887 1969
1888 my $guid = dec_guid substr $device, 0, 16, ""; 1970 my $guid = dec_guid substr $device, 0, 16, "";
1889 $guid = $guid eq "00000000-0000-0000-0000-000000000000" 1971 $guid = $guid eq "00000000-0000-0000-0000-000000000000"
1890 ? "" : "{$guid}"; 1972 ? "" : "{$guid}";
1891 1973
1892 eval { 1974 eval {
1893 my ($dev, $tail) = dec_device_ $device; 1975 my ($dev, $tail) = dec_device_ $device, $type;
1894 1976
1895 $tail eq "" 1977 $tail eq ""
1896 or die "unsupported trailing data after device descriptor\n"; 1978 or die "unsupported trailing data after device descriptor\n";
1897 1979
1898 "$guid$dev" 1980 "$guid$dev"
1910 1992
1911 undef 1993 undef
1912} 1994}
1913 1995
1914# encode the device portion after the GUID 1996# encode the device portion after the GUID
1915sub enc_device_; 1997sub enc_device_($$);
1916sub enc_device_ { 1998sub enc_device_($$) {
1917 my ($device) = @_; 1999 my ($device, $type) = @_;
1918 2000
1919 my $enc_path = sub { 2001 my $enc_path = sub {
1920 my $path = shift; 2002 my $path = shift;
1921 $path =~ s/\//\\/g; 2003 $path =~ s/\//\\/g;
1922 (Encode::encode "UTF-16LE", $path) . "\x00\x00" 2004 (Encode::encode "UTF-16LE", $path) . "\x00\x00"
1940 2022
1941 my $parse_parent = sub { 2023 my $parse_parent = sub {
1942 my $parent; 2024 my $parent;
1943 2025
1944 if (s/^<//) { 2026 if (s/^<//) {
1945 ($parent, $_) = enc_device_ $_; 2027 ($parent, $_) = enc_device_ $_, $type;
1946 s/^>// 2028 s/^>//
1947 or die "$device: syntax error: parent device not followed by '>'\n"; 2029 or die "$device: syntax error: parent device not followed by '>'\n";
1948 } else { 2030 } else {
1949 $parent = $NULL_DEVICE; 2031 $parent = $NULL_DEVICE;
1950 } 2032 }
2038 2120
2039 s/^,// 2121 s/^,//
2040 or die "$_: missing comma after locate parent device\n"; 2122 or die "$_: missing comma after locate parent device\n";
2041 2123
2042 if (s/^element,//) { 2124 if (s/^element,//) {
2043 s/^([0-9a-z]+)//i 2125 s/^([0-9a-z:]+)//i
2044 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";
2045 $elem = enc_bcde_id $1; 2127 $elem = enc_bcde_id $1, $type;
2046 $mode = 0; 2128 $mode = 0;
2047 $path = $enc_path->(""); 2129 $path = $enc_path->("");
2048 2130
2049 } elsif (s/^path,//) { 2131 } elsif (s/^path,//) {
2050 $mode = 1; 2132 $mode = 1;
2129 ); 2211 );
2130 } 2212 }
2131} 2213}
2132 2214
2133# encode a full binary BCD device descriptor 2215# encode a full binary BCD device descriptor
2134sub enc_device { 2216sub enc_device($$) {
2135 my ($device) = @_; 2217 my ($device, $type) = @_;
2136 2218
2137 my $guid = "\x00" x 16; 2219 my $guid = "\x00" x 16;
2138 2220
2139 if ($device =~ s/^\{([A-Za-z0-9\-]+)\}//) { 2221 if ($device =~ s/^\{([A-Za-z0-9\-]+)\}//) {
2140 $guid = enc_guid $1 2222 $guid = enc_guid $1
2141 or die "$device: does not start with valid guid\n"; 2223 or die "$device: does not start with valid guid\n";
2142 } 2224 }
2143 2225
2144 my ($descriptor, $tail) = enc_device_ $device; 2226 my ($descriptor, $tail) = enc_device_ $device, $type;
2145 2227
2146 length $tail 2228 length $tail
2147 and die "$device: garbage after device descriptor\n"; 2229 and die "$device: garbage after device descriptor\n";
2148 2230
2149 unpack "H*", $guid . $descriptor 2231 unpack "H*", $guid . $descriptor
2164 $k = $bcd_objects{$k} // $k; 2246 $k = $bcd_objects{$k} // $k;
2165 2247
2166 my $type = $v->{Description}[0]{Type}[1]; 2248 my $type = $v->{Description}[0]{Type}[1];
2167 2249
2168 if ($type != $bcd_object_types{$k}) { 2250 if ($type != $bcd_object_types{$k}) {
2169 $type = $bcd_types{$type} // sprintf "0x%08x", $type; 2251 $kv{type} = $bcd_types{$type} // sprintf "0x%08x", $type;
2170 $kv{type} = $type;
2171 } 2252 }
2172 2253
2173 my $elems = $v->{Elements}[1]; 2254 my $elems = $v->{Elements}[1];
2174 2255
2175 while (my ($k, $v) = each %$elems) { 2256 while (my ($k, $v) = each %$elems) {
2176 my $k = hex $k; 2257 my $k = hex $k;
2177 2258
2178 my $v = $bcde_dec{$k & BCDE_FORMAT}->($v->[0]{Element}[1]); 2259 my $v = $bcde_dec{$k & BCDE_FORMAT}->($v->[0]{Element}[1], $type);
2179 my $k = dec_bcde_id $k; 2260 my $k = dec_bcde_id $k, $type;
2180 2261
2181 $kv{$k} = $v; 2262 $kv{$k} = $v;
2182 } 2263 }
2183 2264
2184 $bcd{$k} = \%kv; 2265 $bcd{$k} = \%kv;
2225 my %elem; 2306 my %elem;
2226 2307
2227 while (my ($k, $v) = each %$v) { 2308 while (my ($k, $v) = each %$v) {
2228 next if $k eq "type"; 2309 next if $k eq "type";
2229 2310
2230 $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";
2231 $elem{sprintf "%08x", $k} = [{ 2312 $elem{sprintf "%08x", $k} = [{
2232 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)]
2233 }]; 2314 }];
2234 } 2315 }
2235 2316
2265} 2346}
2266 2347
2267sub bcd_edit { 2348sub bcd_edit {
2268 my ($path, $bcd, @insns) = @_; 2349 my ($path, $bcd, @insns) = @_;
2269 2350
2270 my $default = $bcd->{"{bootmgr}"}{resumeobject}; 2351 my $default = $bcd->{"{bootmgr}"}{default};
2271 2352
2272 # prepare "officially visible" variables 2353 # prepare "officially visible" variables
2273 local $pbcdedit::PATH = $path; 2354 local $pbcdedit::PATH = $path;
2274 local $pbcdedit::BCD = $bcd; 2355 local $pbcdedit::BCD = $bcd;
2275 local $pbcdedit::DEFAULT = $default; 2356 local $pbcdedit::DEFAULT = $default;
2293 $object = $object eq "{default}" ? $default : dec_wguid enc_wguid $object; 2374 $object = $object eq "{default}" ? $default : dec_wguid enc_wguid $object;
2294 2375
2295 $bcd->{$object}{$elem} = $value; 2376 $bcd->{$object}{$elem} = $value;
2296 2377
2297 } elsif ($insn eq "eval") { 2378 } elsif ($insn eq "eval") {
2298 bcd_edit_eval shift @insns; 2379 my $perl = shift @insns;
2380 bcd_edit_eval "#line 1 'eval'\n$perl";
2299 2381
2300 } elsif ($insn eq "do") { 2382 } elsif ($insn eq "do") {
2301 my $path = shift @insns; 2383 my $path = shift @insns;
2302 my $file = file_load $path; 2384 my $file = file_load $path;
2303 bcd_edit_eval "#line 1 '$path'\n$file"; 2385 bcd_edit_eval "#line 1 '$path'\n$file";
2357 2439
2358 print "\n"; 2440 print "\n";
2359 2441
2360 printf "%-39s %-23s %s\n", "Object GUID", "Alias", "(Hex) Default Type"; 2442 printf "%-39s %-23s %s\n", "Object GUID", "Alias", "(Hex) Default Type";
2361 for my $name (sort keys %rbcd_objects) { 2443 for my $name (sort keys %rbcd_objects) {
2362 my $guid = $rbcd_objects{$name}; 2444 my $guid = $rbcd_objects{$name};
2363 my $type = $bcd_object_types{$name}; 2445 my $type = $bcd_object_types{$name};
2364 my $tname = $bcd_types{$type}; 2446 my $tname = $bcd_types{$type};
2365 2447
2366 $type = $type ? sprintf "(%08x) %s", $type, $tname : "-"; 2448 $type = $type ? sprintf "(%08x) %s", $type, $tname : "-";
2367 2449
2368 printf "%-39s %-23s %s\n", $guid, $name, $type; 2450 printf "%-39s %-23s %s\n", $guid, $name, $type;
2382 BCDE_FORMAT_GUID_LIST , "guid list", 2464 BCDE_FORMAT_GUID_LIST , "guid list",
2383 BCDE_FORMAT_INTEGER , "integer", 2465 BCDE_FORMAT_INTEGER , "integer",
2384 BCDE_FORMAT_BOOLEAN , "boolean", 2466 BCDE_FORMAT_BOOLEAN , "boolean",
2385 BCDE_FORMAT_INTEGER_LIST, "integer list", 2467 BCDE_FORMAT_INTEGER_LIST, "integer list",
2386 ); 2468 );
2387 my %rbcde = reverse %bcde;
2388 $_ = sprintf "%08x", $_ for values %rbcde;
2389 2469
2390 my %element; 2470 my %element;
2391 2471
2472 for my $class (sort keys %rbcde_byclass) {
2473 my $rbcde = $rbcde_byclass{$class};
2474
2392 unless ($json) { 2475 unless ($json) {
2393 print "\n"; 2476 print "\n";
2477 printf "Elements applicable to class(es): $class\n";
2394 printf "%-9s %-12s %s\n", "Element", "Format", "Name Alias"; 2478 printf "%-9s %-12s %s\n", "Element", "Format", "Name Alias";
2395 } 2479 }
2396 for my $name (sort keys %rbcde) { 2480 for my $name (sort keys %$rbcde) {
2397 my $id = $rbcde{$name}; 2481 my $id = $rbcde->{$name};
2398 my $format = $format_name{(hex $id) & BCDE_FORMAT}; 2482 my $format = $format_name{$id & BCDE_FORMAT};
2483 $id = sprintf "%08x", $id;
2399 2484
2400 if ($json) { 2485 if ($json) {
2401 $element{$id} = [$format, $name]; 2486 $element{$id} = [$class, $format, $name];
2402 } else { 2487 } else {
2403 printf "%-9s %-12s %s\n", $id, $format, $name; 2488 printf "%-9s %-12s %s\n", $id, $format, $name;
2489 }
2404 } 2490 }
2405 } 2491 }
2406 print "\n" unless $json; 2492 print "\n" unless $json;
2407 2493
2408 prjson { 2494 prjson {
2409 version => $JSON_VERSION, 2495 version => $JSON_VERSION,
2410 element => \%element, 2496 element => \%element,
2497 class => \@bcde_typeclass,
2411 } if $json; 2498 } if $json;
2412 2499
2413 }, 2500 },
2414 2501
2415 export => sub { 2502 export => sub {
2467 } 2554 }
2468 } 2555 }
2469 } 2556 }
2470 } 2557 }
2471 }, 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 },
2472); 2569);
2473 2570
2474my $cmd = shift; 2571my $cmd = shift;
2475 2572
2476unless (exists $CMD{$cmd}) { 2573unless (exists $CMD{$cmd}) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines