temporarily reverting 3 files back to what they are in main to get past a merge conflict, will deal with the conflict after this

This commit is contained in:
iadgovuser58 2024-08-07 11:41:05 -04:00
parent 6124e63201
commit 9884e668eb
3 changed files with 119 additions and 112 deletions

View File

@ -3,6 +3,7 @@ package hirs.utils.tpm.eventlog.events;
import hirs.utils.HexUtils; import hirs.utils.HexUtils;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import static hirs.utils.PciIds.translateDevice; import static hirs.utils.PciIds.translateDevice;
@ -101,6 +102,7 @@ public class DeviceSecurityEventDataPciContext extends DeviceSecurityEventDataDe
byte[] pciSubsystemIdBytes = new byte[2]; byte[] pciSubsystemIdBytes = new byte[2];
System.arraycopy(dSEDpciContextBytes, 14, pciSubsystemIdBytes, 0, 2); System.arraycopy(dSEDpciContextBytes, 14, pciSubsystemIdBytes, 0, 2);
subsystemId = HexUtils.byteArrayToHexString(HexUtils.leReverseByte(pciSubsystemIdBytes)); subsystemId = HexUtils.byteArrayToHexString(HexUtils.leReverseByte(pciSubsystemIdBytes));
} }
/** /**
@ -112,22 +114,22 @@ public class DeviceSecurityEventDataPciContext extends DeviceSecurityEventDataDe
String dSEDpciContextInfo = ""; String dSEDpciContextInfo = "";
dSEDpciContextInfo += super.toString(); dSEDpciContextInfo += super.toString();
dSEDpciContextInfo += " Device Type = PCI\n"; dSEDpciContextInfo += "\n Device Type = PCI";
dSEDpciContextInfo += " Vendor = " + translateVendor(vendorId) + "\n"; dSEDpciContextInfo += "\n Vendor = " + translateVendor(vendorId);
dSEDpciContextInfo += " Device = " + translateDevice(vendorId, deviceId) + "\n"; dSEDpciContextInfo += "\n Device = " + translateDevice(vendorId, deviceId);
dSEDpciContextInfo += " RevisionID = " + revisionId + "\n"; dSEDpciContextInfo += "\n RevisionID = " + revisionId;
List<String> classCodeList = translateDeviceClass(classCode); List<String> classCodeList = translateDeviceClass(classCode);
dSEDpciContextInfo += " Device Class: \n"; dSEDpciContextInfo += "\n Device Class: ";
if(classCodeList.size() == 3) { if(classCodeList.size() == 3) {
dSEDpciContextInfo += " Class = " + classCodeList.get(0) + "\n"; dSEDpciContextInfo += "\n Class = " + classCodeList.get(0);
dSEDpciContextInfo += " Subclass = " + classCodeList.get(1) + "\n"; dSEDpciContextInfo += "\n Subclass = " + classCodeList.get(1);
dSEDpciContextInfo += " Programming Interface = " + classCodeList.get(2) + "\n"; dSEDpciContextInfo += "\n Programming Interface = " + classCodeList.get(2);
} else { } else {
dSEDpciContextInfo += " ** Class code could not be determined **"; dSEDpciContextInfo += " ** Class code could not be determined **";
} }
dSEDpciContextInfo += " SubsystemVendor = " + translateVendor(subsystemVendorId) + "\n"; dSEDpciContextInfo += "\n SubsystemVendor = " + translateVendor(subsystemVendorId);
dSEDpciContextInfo += " Subsystem = " + translateDevice(subsystemVendorId, subsystemId) + "\n"; dSEDpciContextInfo += "\n Subsystem = " + translateDevice(subsystemVendorId, subsystemId);
return dSEDpciContextInfo; return dSEDpciContextInfo;
} }

View File

@ -5,6 +5,7 @@ import hirs.utils.tpm.eventlog.uefi.UefiConstants;
import hirs.utils.tpm.eventlog.uefi.UefiDevicePath; import hirs.utils.tpm.eventlog.uefi.UefiDevicePath;
import lombok.Getter; import lombok.Getter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
/** /**
@ -83,9 +84,34 @@ public abstract class DeviceSecurityEventHeader {
*/ */
@Getter @Getter
private UefiDevicePath devicePath = null; private UefiDevicePath devicePath = null;
/**
* Is the Device Path Valid.
*/
private boolean devicePathValid = false;
/** /**
* DeviceSecurityEventDataHeader Constructor. * Device Security Event Data Device Type = no device type.
*/
public static final int DEVICE_TYPE_NONE = 0;
/**
* Device Security Event Data Device Type = DEVICE_TYPE_PCI.
*/
public static final int DEVICE_TYPE_PCI = 1;
/**
* Device Security Event Data Device Type = DEVICE_TYPE_USB.
*/
public static final int DEVICE_TYPE_USB = 2;
/**
* DeviceSecurityEventDataHeaderBase Default Constructor.
*/
public DeviceSecurityEventHeader() {
}
/**
* DeviceSecurityEventDataHeaderBase Constructor.
* *
* @param dSEDbytes byte array holding the DeviceSecurityEventData. * @param dSEDbytes byte array holding the DeviceSecurityEventData.
*/ */
@ -100,6 +126,7 @@ public abstract class DeviceSecurityEventHeader {
System.arraycopy(dSEDbytes, UefiConstants.OFFSET_16, versionBytes, 0, System.arraycopy(dSEDbytes, UefiConstants.OFFSET_16, versionBytes, 0,
UefiConstants.SIZE_2); UefiConstants.SIZE_2);
version = HexUtils.byteArrayToHexString(versionBytes); version = HexUtils.byteArrayToHexString(versionBytes);
} }
/** /**
@ -127,17 +154,24 @@ public abstract class DeviceSecurityEventHeader {
public void extractDevicePathAndFinalSize(final byte[] dsedBytes, int startByte) { public void extractDevicePathAndFinalSize(final byte[] dsedBytes, int startByte) {
// get the device path length // get the device path length
byte[] devicePathLengthBytes = new byte[8]; byte[] devicePathLengthBytes = new byte[UefiConstants.SIZE_8];
System.arraycopy(dsedBytes, startByte, devicePathLengthBytes, 0, 8); System.arraycopy(dsedBytes, startByte, devicePathLengthBytes, 0,
UefiConstants.SIZE_8);
int devicePathLength = HexUtils.leReverseInt(devicePathLengthBytes); int devicePathLength = HexUtils.leReverseInt(devicePathLengthBytes);
// get the device path // get the device path
if (devicePathLength > 0) { if (devicePathLength != 0) {
startByte = startByte + 8; startByte = startByte + UefiConstants.SIZE_8;
byte[] devPathBytes = new byte[devicePathLength]; byte[] devPathBytes = new byte[devicePathLength];
System.arraycopy(dsedBytes, startByte, devPathBytes, System.arraycopy(dsedBytes, startByte, devPathBytes,
0, devicePathLength); 0, devicePathLength);
devicePath = new UefiDevicePath(devPathBytes); try {
devicePath = new UefiDevicePath(devPathBytes);
devicePathValid = true;
}
catch (UnsupportedEncodingException e) {
devicePathValid = false;
}
} }
// header total size // header total size
@ -153,11 +187,11 @@ public abstract class DeviceSecurityEventHeader {
*/ */
public String deviceTypeToString(final int deviceTypeInt) { public String deviceTypeToString(final int deviceTypeInt) {
switch (deviceTypeInt) { switch (deviceTypeInt) {
case DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_NONE: case DEVICE_TYPE_NONE:
return "No device type"; return "No device type";
case DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_PCI: case DEVICE_TYPE_PCI:
return "PCI"; return "PCI";
case DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_USB: case DEVICE_TYPE_USB:
return "USB"; return "USB";
default: default:
return "Unknown or invalid Device Type"; return "Unknown or invalid Device Type";
@ -172,13 +206,13 @@ public abstract class DeviceSecurityEventHeader {
public String toString() { public String toString() {
String dsedHeaderCommonInfo = ""; String dsedHeaderCommonInfo = "";
dsedHeaderCommonInfo += " SPDM Device Type = " + deviceTypeToString(deviceType) + "\n"; dsedHeaderCommonInfo += "\n SPDM Device Type = " + deviceTypeToString(deviceType);
if (devicePath != null) { if (devicePathValid) {
dsedHeaderCommonInfo += " SPDM Device Path:\n"; dsedHeaderCommonInfo += "\n SPDM Device Path:\n";
dsedHeaderCommonInfo += devicePath; dsedHeaderCommonInfo += devicePath;
} }
else { else {
dsedHeaderCommonInfo += " SPDM Device Path = Unknown or invalid\n"; dsedHeaderCommonInfo += "\n SPDM Device Path = Unknown or invalid";
} }
return dsedHeaderCommonInfo; return dsedHeaderCommonInfo;

View File

@ -7,20 +7,8 @@ import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
/** /**
* Class to process a Device Path. A Device Path is a variable-length binary * Class to process EFI_DEVICE_PATH_PROTOCOL which is referred to as the UEFI_DEVICE_PATH
* 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> * <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 * #define EFI_DEVICE_PATH_PROTOCOL_GUID \09576e91-6d3f-11d2-8e39-00a0c969723b
* typedef struct _EFI_DEVICE_PATH_PROTOCOL { * typedef struct _EFI_DEVICE_PATH_PROTOCOL {
* UINT8 Type; * UINT8 Type;
@ -35,7 +23,7 @@ import java.nio.charset.StandardCharsets;
* Type 0x04 Media Device Path * Type 0x04 Media Device Path
* Type 0x05 BIOS Boot Specification Device Path * Type 0x05 BIOS Boot Specification Device Path
* Type 0x7F End of Hardware Device Path * Type 0x7F End of Hardware Device Path
* Each Type has a Subtype that may or may not be defined in the section * Each Type has a sub-type that may or may no be defined in the section
* <p> * <p>
* Only a few of the SubTypes have been implemented as there are many, * 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. * but only those that were reported using the test devices at hand.
@ -48,11 +36,11 @@ public class UefiDevicePath {
@Getter @Getter
private String type = ""; private String type = "";
/** /**
* UEFI Device path subtype. * UEFI Device path sub-type.
*/ */
private String subType = ""; private String subType = "";
/** /**
* UEFI Device path human-readable description. * UEFI Device path human readable description.
*/ */
private String devPathInfo = ""; private String devPathInfo = "";
/** /**
@ -67,7 +55,7 @@ public class UefiDevicePath {
* @param path byte array holding device path data * @param path byte array holding device path data
* @throws java.io.UnsupportedEncodingException if path byte array contains unexpected values * @throws java.io.UnsupportedEncodingException if path byte array contains unexpected values
*/ */
public UefiDevicePath(final byte[] path) { public UefiDevicePath(final byte[] path) throws UnsupportedEncodingException {
devPathInfo = processDevPath(path); devPathInfo = processDevPath(path);
byte[] lengthBytes = new byte[UefiConstants.SIZE_2]; byte[] lengthBytes = new byte[UefiConstants.SIZE_2];
System.arraycopy(path, UefiConstants.OFFSET_2, lengthBytes, 0, UefiConstants.OFFSET_2); System.arraycopy(path, UefiConstants.OFFSET_2, lengthBytes, 0, UefiConstants.OFFSET_2);
@ -75,9 +63,9 @@ public class UefiDevicePath {
} }
/** /**
* Returns the UEFI device subtype. * Returns the UEFI device sub-type.
* *
* @return uefi subtype * @return uefi sub-type
*/ */
public String getSubType() { public String getSubType() {
return subType.trim(); return subType.trim();
@ -93,7 +81,7 @@ public class UefiDevicePath {
* @return Human readable string containing the device path description. * @return Human readable string containing the device path description.
* @throws java.io.UnsupportedEncodingException * @throws java.io.UnsupportedEncodingException
*/ */
private String processDevPath(final byte[] path) { private String processDevPath(final byte[] path) throws UnsupportedEncodingException {
StringBuilder pInfo = new StringBuilder(); StringBuilder pInfo = new StringBuilder();
int devLength = 0, pathOffset = 0, devCount = 0; int devLength = 0, pathOffset = 0, devCount = 0;
while (true) { while (true) {
@ -102,6 +90,9 @@ public class UefiDevicePath {
|| (devPath.intValue() == UefiConstants.END_FLAG)) { || (devPath.intValue() == UefiConstants.END_FLAG)) {
break; break;
} }
if (devCount++ > 0) {
pInfo.append("\n");
}
pInfo.append(processDev(path, pathOffset)); pInfo.append(processDev(path, pathOffset));
devLength = path[pathOffset + UefiConstants.OFFSET_3] * UefiConstants.SIZE_256 devLength = path[pathOffset + UefiConstants.OFFSET_3] * UefiConstants.SIZE_256
+ path[pathOffset + UefiConstants.OFFSET_2]; + path[pathOffset + UefiConstants.OFFSET_2];
@ -120,10 +111,11 @@ public class UefiDevicePath {
* *
* @param path * @param path
* @param offset * @param offset
* @return human-readable string representing the UEFI device path * @return human readable string representing the UEFI device path
* @throws java.io.UnsupportedEncodingException * @throws java.io.UnsupportedEncodingException
*/ */
private String processDev(final byte[] path, final int offset) { private String processDev(final byte[] path, final int offset)
throws UnsupportedEncodingException {
String devInfo = " "; String devInfo = " ";
int devPath = path[offset]; int devPath = path[offset];
byte unknownSubType = path[offset + UefiConstants.OFFSET_1]; byte unknownSubType = path[offset + UefiConstants.OFFSET_1];
@ -131,50 +123,50 @@ public class UefiDevicePath {
case UefiConstants.DEV_HW: case UefiConstants.DEV_HW:
type = "Hardware Device Path"; type = "Hardware Device Path";
if (devPath == UefiConstants.DEVPATH_HARWARE) { if (devPath == UefiConstants.DEVPATH_HARWARE) {
devInfo += type + ":\n" + pciSubType(path, offset); devInfo += type + ": " + pciSubType(path, offset);
} }
break; break;
case UefiConstants.DEV_ACPI: case UefiConstants.DEV_ACPI:
type = "ACPI Device Path"; type = "ACPI Device Path";
devInfo += type + ":\n" + acpiSubType(path, offset); devInfo += type + ": " + acpiSubType(path, offset);
break; break;
case UefiConstants.DEV_MSG: case UefiConstants.DEV_MSG:
type = "Messaging Device Path"; type = "Messaging Device Path";
if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEV_SUB_SATA) { if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEV_SUB_SATA) {
devInfo += type + ":\n" + sataSubType(path, offset); devInfo += type + ": " + sataSubType(path, offset);
} else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEV_SUB_NVM) { } else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEV_SUB_NVM) {
devInfo += type + ":\n" + nvmSubType(path, offset); devInfo += type + ": " + nvmSubType(path, offset);
} else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEV_SUB_USB) { } else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEV_SUB_USB) {
devInfo += type + ":\n" + usbSubType(path, offset); devInfo += type + ": " + usbSubType(path, offset);
} else { } else {
devInfo += "UEFI Messaging Device Path Type " + Integer.valueOf(unknownSubType) + "\n"; devInfo += "UEFI Messaging Device Path Type " + Integer.valueOf(unknownSubType);
} }
break; break;
case UefiConstants.DEV_MEDIA: case UefiConstants.DEV_MEDIA:
type = "Media Device Path"; type = "Media Device Path";
if (path[offset + UefiConstants.OFFSET_1] == 0x01) { if (path[offset + UefiConstants.OFFSET_1] == 0x01) {
devInfo += type + ":\n" + hardDriveSubType(path, offset); devInfo += type + ": " + hardDriveSubType(path, offset);
} else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEVPATH_VENDOR) { } else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEVPATH_VENDOR) {
devInfo += type + ":\n" + vendorSubType(path, offset); devInfo += type + ": " + vendorSubType(path, offset);
} else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEVPATH_FILE) { } else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEVPATH_FILE) {
devInfo += type + ":\n" + filePathSubType(path, offset); devInfo += type + ": " + filePathSubType(path, offset);
} else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEVPATH_PWIG_FILE) { } else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEVPATH_PWIG_FILE) {
devInfo += type + ":\n" + piwgFirmVolFile(path, offset); devInfo += type + ": " + piwgFirmVolFile(path, offset);
} else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEVPATH_PWIG_VOL) { } else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEVPATH_PWIG_VOL) {
devInfo += type + ":\n" + piwgFirmVolPath(path, offset); devInfo += type + ": " + piwgFirmVolPath(path, offset);
} else { } else {
devInfo += "UEFI Media Device Path Type " + Integer.valueOf(unknownSubType) + "\n"; devInfo += "UEFI Media Device Path Type " + Integer.valueOf(unknownSubType);
} }
break; break;
case UefiConstants.DEV_BIOS: case UefiConstants.DEV_BIOS:
type = "BIOS Device Path"; type = "BIOS Device Path";
devInfo += type + ":\n" + biosDevicePath(path, offset); devInfo += type + ": " + biosDevicePath(path, offset);
break; break;
case UefiConstants.TERMINATOR: case UefiConstants.TERMINATOR:
devInfo += "End of Hardware Device Path\n"; devInfo += "End of Hardware Device Path";
break; break;
default: default:
devInfo += "UEFI Device Path Type " + Integer.valueOf(unknownSubType) + "\n"; devInfo += "UEFI Device Path Type " + Integer.valueOf(unknownSubType);
} }
return devInfo; return devInfo;
} }
@ -187,17 +179,17 @@ public class UefiDevicePath {
* @return acpi device info * @return acpi device info
*/ */
private String acpiSubType(final byte[] path, final int offset) { private String acpiSubType(final byte[] path, final int offset) {
subType = " Sub Type = ACPI\n"; subType = "";
switch (path[offset + UefiConstants.OFFSET_1]) { switch (path[offset + UefiConstants.OFFSET_1]) {
case 0x01: // standard version case 0x01:
subType = "(Short): ";
subType += acpiShortSubType(path, offset); subType += acpiShortSubType(path, offset);
break; break;
case 0x02: case 0x02:
subType = "(expanded version):\n"; subType = "Expanded ACPI Device Path";
// tbd
break; break;
default: default:
subType = "Invalid ACPI Device Path sub type\n"; subType = "Invalid ACPI Device Path sub type";
} }
return subType; return subType;
} }
@ -213,13 +205,9 @@ public class UefiDevicePath {
subType = ""; subType = "";
byte[] hid = new byte[UefiConstants.SIZE_4]; byte[] hid = new byte[UefiConstants.SIZE_4];
System.arraycopy(path, UefiConstants.OFFSET_4 + offset, hid, 0, UefiConstants.SIZE_4); System.arraycopy(path, UefiConstants.OFFSET_4 + offset, hid, 0, UefiConstants.SIZE_4);
subType += " _HID = " + HexUtils.byteArrayToHexString(hid) + "\n"; subType += "_HID = " + HexUtils.byteArrayToHexString(hid);
System.arraycopy(path, 2 * UefiConstants.SIZE_4 + offset, hid, 0, UefiConstants.SIZE_4); System.arraycopy(path, 2 * UefiConstants.SIZE_4 + offset, hid, 0, UefiConstants.SIZE_4);
String uid = HexUtils.byteArrayToHexString(hid); subType += "_UID = " + HexUtils.byteArrayToHexString(hid);
if(uid.contains("00000000")) {
uid = "No _UID exists for this device";
}
subType += " _UID = " + uid + "\n";
return subType; return subType;
} }
@ -231,25 +219,22 @@ public class UefiDevicePath {
* @return pci device info. * @return pci device info.
*/ */
private String pciSubType(final byte[] path, final int offset) { private String pciSubType(final byte[] path, final int offset) {
subType = " Sub Type = PCI\n"; subType = "PCI: PCI Function Number = ";
subType += " PCI Function Number = ";
subType += String.format("0x%x", path[offset + UefiConstants.SIZE_4]); subType += String.format("0x%x", path[offset + UefiConstants.SIZE_4]);
subType += "\n PCI Device Number = "; subType += " PCI Device Number = ";
subType += String.format("0x%x", path[offset + UefiConstants.SIZE_5]); subType += String.format("0x%x", path[offset + UefiConstants.SIZE_5]);
subType += "\n";
return subType; return subType;
} }
/** /**
* processes the SATA subtype. * processes the SATA sub type.
* *
* @param path * @param path
* @param offset * @param offset
* @return SATA drive info. * @return SATA drive info.
*/ */
private String sataSubType(final byte[] path, final int offset) { private String sataSubType(final byte[] path, final int offset) {
subType = " Sub Type = SATA\n"; subType = "SATA: HBA Port Number = ";
subType += " SATA: HBA Port Number = ";
byte[] data = new byte[UefiConstants.SIZE_2]; byte[] data = new byte[UefiConstants.SIZE_2];
System.arraycopy(path, UefiConstants.OFFSET_4 + offset, data, 0, UefiConstants.SIZE_2); System.arraycopy(path, UefiConstants.OFFSET_4 + offset, data, 0, UefiConstants.SIZE_2);
subType += HexUtils.byteArrayToHexString(data); subType += HexUtils.byteArrayToHexString(data);
@ -257,20 +242,18 @@ public class UefiDevicePath {
subType += " Port Multiplier = " + HexUtils.byteArrayToHexString(data); subType += " Port Multiplier = " + HexUtils.byteArrayToHexString(data);
System.arraycopy(path, UefiConstants.OFFSET_8 + offset, data, 0, UefiConstants.SIZE_2); System.arraycopy(path, UefiConstants.OFFSET_8 + offset, data, 0, UefiConstants.SIZE_2);
subType += " Logical Unit Number = " + HexUtils.byteArrayToHexString(data); subType += " Logical Unit Number = " + HexUtils.byteArrayToHexString(data);
subType += "\n";
return subType; return subType;
} }
/** /**
* Processes the hard drive subtype. * Processes the hard drive sub type.
* *
* @param path * @param path
* @param offset * @param offset
* @return hard drive info. * @return hard drive info.
*/ */
private String hardDriveSubType(final byte[] path, final int offset) { private String hardDriveSubType(final byte[] path, final int offset) {
subType = " Sub Type = Hard Drive\n"; subType = "Partition Number = ";
subType += " Partition Number = ";
byte[] partnumber = new byte[UefiConstants.SIZE_4]; byte[] partnumber = new byte[UefiConstants.SIZE_4];
System.arraycopy(path, UefiConstants.OFFSET_4 + offset, partnumber, System.arraycopy(path, UefiConstants.OFFSET_4 + offset, partnumber,
0, UefiConstants.SIZE_4); 0, UefiConstants.SIZE_4);
@ -278,14 +261,14 @@ public class UefiDevicePath {
byte[] data = new byte[UefiConstants.SIZE_8]; byte[] data = new byte[UefiConstants.SIZE_8];
System.arraycopy(path, UefiConstants.OFFSET_8 + offset, data, 0, System.arraycopy(path, UefiConstants.OFFSET_8 + offset, data, 0,
UefiConstants.SIZE_8); UefiConstants.SIZE_8);
subType += "\n Partition Start = " + HexUtils.byteArrayToHexString(data); subType += " Partition Start = " + HexUtils.byteArrayToHexString(data);
System.arraycopy(path, UefiConstants.OFFSET_16 + offset, data, 0, System.arraycopy(path, UefiConstants.OFFSET_16 + offset, data, 0,
UefiConstants.SIZE_8); UefiConstants.SIZE_8);
subType += "\n Partition Size = " + HexUtils.byteArrayToHexString(data); subType += " Partition Size = " + HexUtils.byteArrayToHexString(data);
byte[] signature = new byte[UefiConstants.SIZE_16]; byte[] signature = new byte[UefiConstants.SIZE_16];
System.arraycopy(path, UefiConstants.OFFSET_24 + offset, signature, 0, System.arraycopy(path, UefiConstants.OFFSET_24 + offset, signature, 0,
UefiConstants.SIZE_16); UefiConstants.SIZE_16);
subType += "\n Partition Signature = "; subType += "\n Partition Signature = ";
if (path[UefiConstants.OFFSET_41 + offset] == UefiConstants.DRIVE_SIG_NONE) { if (path[UefiConstants.OFFSET_41 + offset] == UefiConstants.DRIVE_SIG_NONE) {
subType += "None"; subType += "None";
} else if (path[UefiConstants.OFFSET_41 + offset] == UefiConstants.DRIVE_SIG_32BIT) { } else if (path[UefiConstants.OFFSET_41 + offset] == UefiConstants.DRIVE_SIG_32BIT) {
@ -296,28 +279,26 @@ public class UefiDevicePath {
} else { } else {
subType += "invalid partition signature type"; subType += "invalid partition signature type";
} }
subType += "\n Partition Format = "; subType += " Partition Format = ";
if (path[UefiConstants.OFFSET_40 + offset] == UefiConstants.DRIVE_TYPE_PC_AT) { if (path[UefiConstants.OFFSET_40 + offset] == UefiConstants.DRIVE_TYPE_PC_AT) {
subType += "PC-AT compatible legacy MBR"; subType += " PC-AT compatible legacy MBR";
} else if (path[UefiConstants.OFFSET_40 + offset] == UefiConstants.DRIVE_TYPE_GPT) { } else if (path[UefiConstants.OFFSET_40 + offset] == UefiConstants.DRIVE_TYPE_GPT) {
subType += "GUID Partition Table"; subType += " GUID Partition Table";
} else { } else {
subType += "Invalid partition table type"; subType += " Invalid partition table type";
} }
subType += "\n";
return subType; return subType;
} }
/** /**
* Process the File path subtype. * Process the File path sub type.
* *
* @param path * @param path
* @param offset * @param offset
* @return file path info. * @return file path info.
*/ */
private String filePathSubType(final byte[] path, final int offset) { private String filePathSubType(final byte[] path, final int offset) {
subType = " Sub Type = File Path\n"; subType = "File Path = ";
subType += " File Path = ";
byte[] lengthBytes = new byte[UefiConstants.SIZE_2]; byte[] lengthBytes = new byte[UefiConstants.SIZE_2];
System.arraycopy(path, 2 + offset, lengthBytes, 0, UefiConstants.SIZE_2); System.arraycopy(path, 2 + offset, lengthBytes, 0, UefiConstants.SIZE_2);
int subTypeLength = HexUtils.leReverseInt(lengthBytes); int subTypeLength = HexUtils.leReverseInt(lengthBytes);
@ -326,12 +307,11 @@ public class UefiDevicePath {
0, subTypeLength); 0, subTypeLength);
byte[] fileName = convertChar16tobyteArray(filePath); byte[] fileName = convertChar16tobyteArray(filePath);
subType += new String(fileName, StandardCharsets.UTF_8); subType += new String(fileName, StandardCharsets.UTF_8);
subType += "\n";
return subType; return subType;
} }
/** /**
* Process a vendor subtype on a Media Type. * Process a vendor sub-type on a Media Type.
* Length of this structure in bytes. Length is 20 + n bytes * Length of this structure in bytes. Length is 20 + n bytes
* Vendor-assigned GUID that defines the data that follows. * Vendor-assigned GUID that defines the data that follows.
* Vendor-defined variable size data. * Vendor-defined variable size data.
@ -341,8 +321,7 @@ public class UefiDevicePath {
* @return vendor device info. * @return vendor device info.
*/ */
private String vendorSubType(final byte[] path, final int offset) { private String vendorSubType(final byte[] path, final int offset) {
subType = " Sub Type = Vendor\n"; subType = "Vendor Subtype GUID = ";
subType += " Vendor Subtype GUID = ";
byte[] lengthBytes = new byte[UefiConstants.SIZE_2]; byte[] lengthBytes = new byte[UefiConstants.SIZE_2];
System.arraycopy(path, UefiConstants.OFFSET_2 + offset, lengthBytes, System.arraycopy(path, UefiConstants.OFFSET_2 + offset, lengthBytes,
0, UefiConstants.SIZE_2); 0, UefiConstants.SIZE_2);
@ -358,9 +337,8 @@ public class UefiDevicePath {
+ offset, vendorData, 0, subTypeLength - UefiConstants.SIZE_16); + offset, vendorData, 0, subTypeLength - UefiConstants.SIZE_16);
subType += " : Vendor Data = " + HexUtils.byteArrayToHexString(vendorData); subType += " : Vendor Data = " + HexUtils.byteArrayToHexString(vendorData);
} else { } else {
subType += " : No Vendor Data present"; subType += " : No Vendor Data pesent";
} }
subType += "\n";
return subType; return subType;
} }
@ -373,8 +351,8 @@ public class UefiDevicePath {
* @return USB device info. * @return USB device info.
*/ */
private String usbSubType(final byte[] path, final int offset) { private String usbSubType(final byte[] path, final int offset) {
subType = " Sub Type = USB\n"; subType = " USB ";
subType += " port = " + Integer.valueOf(path[offset + UefiConstants.OFFSET_4]); subType += " port = " + Integer.valueOf(path[offset + UefiConstants.OFFSET_4]);
subType += " interface = " + Integer.valueOf(path[offset + UefiConstants.OFFSET_5]); subType += " interface = " + Integer.valueOf(path[offset + UefiConstants.OFFSET_5]);
byte[] lengthBytes = new byte[UefiConstants.SIZE_2]; byte[] lengthBytes = new byte[UefiConstants.SIZE_2];
System.arraycopy(path, UefiConstants.OFFSET_2 + offset, lengthBytes, System.arraycopy(path, UefiConstants.OFFSET_2 + offset, lengthBytes,
@ -383,7 +361,6 @@ public class UefiDevicePath {
byte[] usbData = new byte[subTypeLength]; byte[] usbData = new byte[subTypeLength];
System.arraycopy(path, UefiConstants.OFFSET_4 + offset, usbData, System.arraycopy(path, UefiConstants.OFFSET_4 + offset, usbData,
0, subTypeLength); 0, subTypeLength);
subType += "\n";
// Todo add further USB processing ... // Todo add further USB processing ...
return subType; return subType;
} }
@ -400,8 +377,7 @@ public class UefiDevicePath {
* @return NVM device info. * @return NVM device info.
*/ */
private String nvmSubType(final byte[] path, final int offset) { private String nvmSubType(final byte[] path, final int offset) {
subType = " Sub Type = NVM\n"; subType = "NVM Express Namespace = ";
subType += " NVM Express Namespace = ";
byte[] lengthBytes = new byte[UefiConstants.SIZE_2]; byte[] lengthBytes = new byte[UefiConstants.SIZE_2];
System.arraycopy(path, UefiConstants.OFFSET_2 + offset, lengthBytes, System.arraycopy(path, UefiConstants.OFFSET_2 + offset, lengthBytes,
0, UefiConstants.SIZE_2); 0, UefiConstants.SIZE_2);
@ -410,7 +386,6 @@ public class UefiDevicePath {
System.arraycopy(path, UefiConstants.OFFSET_4 + offset, nvmData, System.arraycopy(path, UefiConstants.OFFSET_4 + offset, nvmData,
0, subTypeLength); 0, subTypeLength);
subType += HexUtils.byteArrayToHexString(nvmData); subType += HexUtils.byteArrayToHexString(nvmData);
subType += "\n";
return subType; return subType;
} }
@ -425,8 +400,7 @@ public class UefiDevicePath {
* @return String that represents the UEFI defined BIOS Device Type. * @return String that represents the UEFI defined BIOS Device Type.
*/ */
private String biosDevicePath(final byte[] path, final int offset) { private String biosDevicePath(final byte[] path, final int offset) {
subType = " Sub Type = Bios Device Path\n"; subType = "Legacy BIOS : Type = ";
subType += " Legacy BIOS : Type = ";
Byte pathType = Byte.valueOf(path[offset + 1]); Byte pathType = Byte.valueOf(path[offset + 1]);
switch (pathType.intValue()) { switch (pathType.intValue()) {
case UefiConstants.DEVPATH_BIOS_RESERVED: case UefiConstants.DEVPATH_BIOS_RESERVED:
@ -458,7 +432,6 @@ public class UefiDevicePath {
subType += "Unknown"; subType += "Unknown";
break; break;
} }
subType += "\n";
return subType; return subType;
} }
@ -473,13 +446,12 @@ public class UefiDevicePath {
* @return String that represents the PIWG Firmware Volume Path * @return String that represents the PIWG Firmware Volume Path
*/ */
private String piwgFirmVolFile(final byte[] path, final int offset) { private String piwgFirmVolFile(final byte[] path, final int offset) {
subType = " Sub Type = PIWG Firmware Volume File\n"; subType = "PIWG Firmware File ";
byte[] guidData = new byte[UefiConstants.SIZE_16]; byte[] guidData = new byte[UefiConstants.SIZE_16];
System.arraycopy(path, UefiConstants.OFFSET_4 + offset, guidData, System.arraycopy(path, UefiConstants.OFFSET_4 + offset, guidData,
0, UefiConstants.SIZE_16); 0, UefiConstants.SIZE_16);
UefiGuid guid = new UefiGuid(guidData); UefiGuid guid = new UefiGuid(guidData);
subType += guid.toString(); subType += guid.toString();
subType += "\n";
return subType; return subType;
} }
@ -494,13 +466,12 @@ public class UefiDevicePath {
* @return String that represents the PIWG Firmware Volume Path * @return String that represents the PIWG Firmware Volume Path
*/ */
private String piwgFirmVolPath(final byte[] path, final int offset) { private String piwgFirmVolPath(final byte[] path, final int offset) {
subType = " Sub Type = PIWG Firmware Volume Path\n"; subType = "PIWG Firmware Volume ";
byte[] guidData = new byte[UefiConstants.SIZE_16]; byte[] guidData = new byte[UefiConstants.SIZE_16];
System.arraycopy(path, UefiConstants.OFFSET_4 + offset, guidData, System.arraycopy(path, UefiConstants.OFFSET_4 + offset, guidData,
0, UefiConstants.SIZE_16); 0, UefiConstants.SIZE_16);
UefiGuid guid = new UefiGuid(guidData); UefiGuid guid = new UefiGuid(guidData);
subType += guid.toString(); subType += guid.toString();
subType += "\n";
return subType; return subType;
} }