Skip to content

Commit

Permalink
updating Device Path output
Browse files Browse the repository at this point in the history
  • Loading branch information
iadgovuser58 committed Jul 11, 2024
1 parent e414605 commit 341b8b4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public class UefiBootOrder {
}

/**
* Provides a human readable Boot Order list on single line.
* Provides a human-readable Boot Order list on single line.
*
* @return A human readable Boot Order
* @return A human-readable Boot Order
*/
public String toString() {
StringBuilder orderList = new StringBuilder();
orderList.append("BootOrder = ");
for (int i = 0; i < bootOrder.length; i++) {
orderList.append(String.format("Boot %04d", (int) bootOrder[i]));
orderList.append(String.format("Boot%04d ", (int) bootOrder[i]));
}
//orderList.append("\n");
return orderList.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
public class UefiBootVariable {
/**
* Human readable description of the variable.
* Human-readable description of the variable.
*/
private String description = "";
/**
Expand Down Expand Up @@ -81,7 +81,7 @@ public UefiBootVariable(final byte[] bootVar) throws UnsupportedEncodingExceptio
* @return string that represents a UEFI boot variable.
*/
public String toString() {
StringBuilder bootInfo = new StringBuilder("Description = ");
StringBuilder bootInfo = new StringBuilder(" EFI Load Option = ");
// remove all non ascii chars
String bootVar = description.replaceAll("[^a-zA-Z_0-0\\s]", "");
bootInfo.append(bootVar + "\n" + efiDevPath.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@
import java.nio.charset.StandardCharsets;

/**
* Class to process EFI_DEVICE_PATH_PROTOCOL which is referred to as the UEFI_DEVICE_PATH
* Class to process a Device Path. A Device Path is a variable-length binary
* structure that is made up of variable-length generic Device Path nodes.
* The first Device Path node starts at byte offset zero of the Device Path.
* The next Device Path node starts at the end of the previous Device Path node.
* There is no limit to the number, type, or sequence of nodes in a Device Path.
* <p>
* Generic Device Path Node Structure:
* Name Byte Offset Byte Length Description
* Type 0 1 Device path type (such as 0x01 - Hardware Device Path)
* Sub-Type 1 1 Sub-Type
* Length 2 2 Length of this structure in bytes. Length is 4+n bytes
* Data 4 n Specific Device Path data
* <p>
* EFI_DEVICE_PATH_PROTOCOL:
* #define EFI_DEVICE_PATH_PROTOCOL_GUID \09576e91-6d3f-11d2-8e39-00a0c969723b
* typedef struct _EFI_DEVICE_PATH_PROTOCOL {
* UINT8 Type;
Expand All @@ -23,7 +35,7 @@
* Type 0x04 Media Device Path
* Type 0x05 BIOS Boot Specification Device Path
* Type 0x7F End of Hardware Device Path
* Each Type has a sub-type that may or may no be defined in the section
* Each Type has a Subtype that may or may not be defined in the section
* <p>
* Only a few of the SubTypes have been implemented as there are many,
* but only those that were reported using the test devices at hand.
Expand All @@ -36,11 +48,11 @@ public class UefiDevicePath {
@Getter
private String type = "";
/**
* UEFI Device path sub-type.
* UEFI Device path subtype.
*/
private String subType = "";
/**
* UEFI Device path human readable description.
* UEFI Device path human-readable description.
*/
private String devPathInfo = "";
/**
Expand Down Expand Up @@ -111,7 +123,7 @@ private String processDevPath(final byte[] path) throws UnsupportedEncodingExcep
*
* @param path
* @param offset
* @return human readable string representing the UEFI device path
* @return human-readable string representing the UEFI device path
* @throws java.io.UnsupportedEncodingException
*/
private String processDev(final byte[] path, final int offset)
Expand Down Expand Up @@ -181,12 +193,11 @@ private String processDev(final byte[] path, final int offset)
private String acpiSubType(final byte[] path, final int offset) {
subType = "";
switch (path[offset + UefiConstants.OFFSET_1]) {
case 0x01:
subType = "(Short): ";
case 0x01: // standard version
subType += acpiShortSubType(path, offset);
break;
case 0x02:
subType = "Expanded ACPI Device Path";
subType = "(expanded version): ";
break;
default:
subType = "Invalid ACPI Device Path sub type";
Expand All @@ -205,9 +216,13 @@ private String acpiShortSubType(final byte[] path, final int offset) {
subType = "";
byte[] hid = new byte[UefiConstants.SIZE_4];
System.arraycopy(path, UefiConstants.OFFSET_4 + offset, hid, 0, UefiConstants.SIZE_4);
subType += "_HID = " + HexUtils.byteArrayToHexString(hid);
subType += "\n _HID = " + HexUtils.byteArrayToHexString(hid);
System.arraycopy(path, 2 * UefiConstants.SIZE_4 + offset, hid, 0, UefiConstants.SIZE_4);
subType += "_UID = " + HexUtils.byteArrayToHexString(hid);
String uid = HexUtils.byteArrayToHexString(hid);
if(uid.contains("00000000")) {
uid = "No _UID exists for this device";
}
subType += "\n _UID = " + uid;
return subType;
}

Expand All @@ -219,9 +234,9 @@ private String acpiShortSubType(final byte[] path, final int offset) {
* @return pci device info.
*/
private String pciSubType(final byte[] path, final int offset) {
subType = "PCI: PCI Function Number = ";
subType = "\n PCI Function Number = ";
subType += String.format("0x%x", path[offset + UefiConstants.SIZE_4]);
subType += " PCI Device Number = ";
subType += "\n PCI Device Number = ";
subType += String.format("0x%x", path[offset + UefiConstants.SIZE_5]);
return subType;
}
Expand Down

0 comments on commit 341b8b4

Please sign in to comment.