added the 3 files back in that had caused merge conflict

This commit is contained in:
iadgovuser58 2024-08-07 11:53:29 -04:00
parent e92b3b51ce
commit d858246ce0
3 changed files with 112 additions and 121 deletions

View File

@ -3,7 +3,6 @@ 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;
@ -102,7 +101,6 @@ 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));
} }
/** /**
@ -114,22 +112,22 @@ public class DeviceSecurityEventDataPciContext extends DeviceSecurityEventDataDe
String dSEDpciContextInfo = ""; String dSEDpciContextInfo = "";
dSEDpciContextInfo += super.toString(); dSEDpciContextInfo += super.toString();
dSEDpciContextInfo += "\n Device Type = PCI"; dSEDpciContextInfo += " Device Type = PCI\n";
dSEDpciContextInfo += "\n Vendor = " + translateVendor(vendorId); dSEDpciContextInfo += " Vendor = " + translateVendor(vendorId) + "\n";
dSEDpciContextInfo += "\n Device = " + translateDevice(vendorId, deviceId); dSEDpciContextInfo += " Device = " + translateDevice(vendorId, deviceId) + "\n";
dSEDpciContextInfo += "\n RevisionID = " + revisionId; dSEDpciContextInfo += " RevisionID = " + revisionId + "\n";
List<String> classCodeList = translateDeviceClass(classCode); List<String> classCodeList = translateDeviceClass(classCode);
dSEDpciContextInfo += "\n Device Class: "; dSEDpciContextInfo += " Device Class: \n";
if(classCodeList.size() == 3) { if(classCodeList.size() == 3) {
dSEDpciContextInfo += "\n Class = " + classCodeList.get(0); dSEDpciContextInfo += " Class = " + classCodeList.get(0) + "\n";
dSEDpciContextInfo += "\n Subclass = " + classCodeList.get(1); dSEDpciContextInfo += " Subclass = " + classCodeList.get(1) + "\n";
dSEDpciContextInfo += "\n Programming Interface = " + classCodeList.get(2); dSEDpciContextInfo += " Programming Interface = " + classCodeList.get(2) + "\n";
} else { } else {
dSEDpciContextInfo += " ** Class code could not be determined **"; dSEDpciContextInfo += " ** Class code could not be determined **";
} }
dSEDpciContextInfo += "\n SubsystemVendor = " + translateVendor(subsystemVendorId); dSEDpciContextInfo += " SubsystemVendor = " + translateVendor(subsystemVendorId) + "\n";
dSEDpciContextInfo += "\n Subsystem = " + translateDevice(subsystemVendorId, subsystemId); dSEDpciContextInfo += " Subsystem = " + translateDevice(subsystemVendorId, subsystemId) + "\n";
return dSEDpciContextInfo; return dSEDpciContextInfo;
} }

View File

@ -5,7 +5,6 @@ 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;
/** /**
@ -84,34 +83,9 @@ public abstract class DeviceSecurityEventHeader {
*/ */
@Getter @Getter
private UefiDevicePath devicePath = null; private UefiDevicePath devicePath = null;
/**
* Is the Device Path Valid.
*/
private boolean devicePathValid = false;
/** /**
* Device Security Event Data Device Type = no device type. * DeviceSecurityEventDataHeader Constructor.
*/
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.
*/ */
@ -126,7 +100,6 @@ 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);
} }
/** /**
@ -154,24 +127,17 @@ 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[UefiConstants.SIZE_8]; byte[] devicePathLengthBytes = new byte[8];
System.arraycopy(dsedBytes, startByte, devicePathLengthBytes, 0, System.arraycopy(dsedBytes, startByte, devicePathLengthBytes, 0, 8);
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 + UefiConstants.SIZE_8; startByte = startByte + 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);
try { devicePath = new UefiDevicePath(devPathBytes);
devicePath = new UefiDevicePath(devPathBytes);
devicePathValid = true;
}
catch (UnsupportedEncodingException e) {
devicePathValid = false;
}
} }
// header total size // header total size
@ -187,11 +153,11 @@ public abstract class DeviceSecurityEventHeader {
*/ */
public String deviceTypeToString(final int deviceTypeInt) { public String deviceTypeToString(final int deviceTypeInt) {
switch (deviceTypeInt) { switch (deviceTypeInt) {
case DEVICE_TYPE_NONE: case DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_NONE:
return "No device type"; return "No device type";
case DEVICE_TYPE_PCI: case DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_PCI:
return "PCI"; return "PCI";
case DEVICE_TYPE_USB: case DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_USB:
return "USB"; return "USB";
default: default:
return "Unknown or invalid Device Type"; return "Unknown or invalid Device Type";
@ -206,13 +172,13 @@ public abstract class DeviceSecurityEventHeader {
public String toString() { public String toString() {
String dsedHeaderCommonInfo = ""; String dsedHeaderCommonInfo = "";
dsedHeaderCommonInfo += "\n SPDM Device Type = " + deviceTypeToString(deviceType); dsedHeaderCommonInfo += " SPDM Device Type = " + deviceTypeToString(deviceType) + "\n";
if (devicePathValid) { if (devicePath != null) {
dsedHeaderCommonInfo += "\n SPDM Device Path:\n"; dsedHeaderCommonInfo += " SPDM Device Path:\n";
dsedHeaderCommonInfo += devicePath; dsedHeaderCommonInfo += devicePath;
} }
else { else {
dsedHeaderCommonInfo += "\n SPDM Device Path = Unknown or invalid"; dsedHeaderCommonInfo += " SPDM Device Path = Unknown or invalid\n";
} }
return dsedHeaderCommonInfo; return dsedHeaderCommonInfo;

View File

@ -3,12 +3,23 @@ package hirs.utils.tpm.eventlog.uefi;
import hirs.utils.HexUtils; import hirs.utils.HexUtils;
import lombok.Getter; import lombok.Getter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets; 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> * <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;
@ -23,7 +34,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 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> * <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.
@ -36,11 +47,11 @@ public class UefiDevicePath {
@Getter @Getter
private String type = ""; private String type = "";
/** /**
* UEFI Device path sub-type. * UEFI Device path subtype.
*/ */
private String subType = ""; private String subType = "";
/** /**
* UEFI Device path human readable description. * UEFI Device path human-readable description.
*/ */
private String devPathInfo = ""; private String devPathInfo = "";
/** /**
@ -53,9 +64,8 @@ public class UefiDevicePath {
* UEFI Device path constructor. * UEFI Device path constructor.
* *
* @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
*/ */
public UefiDevicePath(final byte[] path) throws UnsupportedEncodingException { public UefiDevicePath(final byte[] path) {
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);
@ -63,9 +73,9 @@ public class UefiDevicePath {
} }
/** /**
* Returns the UEFI device sub-type. * Returns the UEFI device subtype.
* *
* @return uefi sub-type * @return uefi subtype
*/ */
public String getSubType() { public String getSubType() {
return subType.trim(); return subType.trim();
@ -81,7 +91,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) throws UnsupportedEncodingException { private String processDevPath(final byte[] path) {
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) {
@ -90,9 +100,6 @@ 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];
@ -111,11 +118,10 @@ 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];
@ -123,50 +129,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 + ": " + pciSubType(path, offset); devInfo += type + ":\n" + pciSubType(path, offset);
} }
break; break;
case UefiConstants.DEV_ACPI: case UefiConstants.DEV_ACPI:
type = "ACPI Device Path"; type = "ACPI Device Path";
devInfo += type + ": " + acpiSubType(path, offset); devInfo += type + ":\n" + 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 + ": " + sataSubType(path, offset); devInfo += type + ":\n" + 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 + ": " + nvmSubType(path, offset); devInfo += type + ":\n" + 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 + ": " + usbSubType(path, offset); devInfo += type + ":\n" + usbSubType(path, offset);
} else { } else {
devInfo += "UEFI Messaging Device Path Type " + Integer.valueOf(unknownSubType); devInfo += "UEFI Messaging Device Path Type " + Integer.valueOf(unknownSubType) + "\n";
} }
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 + ": " + hardDriveSubType(path, offset); devInfo += type + ":\n" + 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 + ": " + vendorSubType(path, offset); devInfo += type + ":\n" + 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 + ": " + filePathSubType(path, offset); devInfo += type + ":\n" + 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 + ": " + piwgFirmVolFile(path, offset); devInfo += type + ":\n" + 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 + ": " + piwgFirmVolPath(path, offset); devInfo += type + ":\n" + piwgFirmVolPath(path, offset);
} else { } else {
devInfo += "UEFI Media Device Path Type " + Integer.valueOf(unknownSubType); devInfo += "UEFI Media Device Path Type " + Integer.valueOf(unknownSubType) + "\n";
} }
break; break;
case UefiConstants.DEV_BIOS: case UefiConstants.DEV_BIOS:
type = "BIOS Device Path"; type = "BIOS Device Path";
devInfo += type + ": " + biosDevicePath(path, offset); devInfo += type + ":\n" + biosDevicePath(path, offset);
break; break;
case UefiConstants.TERMINATOR: case UefiConstants.TERMINATOR:
devInfo += "End of Hardware Device Path"; devInfo += "End of Hardware Device Path\n";
break; break;
default: default:
devInfo += "UEFI Device Path Type " + Integer.valueOf(unknownSubType); devInfo += "UEFI Device Path Type " + Integer.valueOf(unknownSubType) + "\n";
} }
return devInfo; return devInfo;
} }
@ -179,17 +185,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 = ""; subType = " Sub Type = ACPI\n";
switch (path[offset + UefiConstants.OFFSET_1]) { switch (path[offset + UefiConstants.OFFSET_1]) {
case 0x01: case 0x01: // standard version
subType = "(Short): ";
subType += acpiShortSubType(path, offset); subType += acpiShortSubType(path, offset);
break; break;
case 0x02: case 0x02:
subType = "Expanded ACPI Device Path"; subType = "(expanded version):\n";
// tbd
break; break;
default: default:
subType = "Invalid ACPI Device Path sub type"; subType = "Invalid ACPI Device Path sub type\n";
} }
return subType; return subType;
} }
@ -205,9 +211,13 @@ 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); subType += " _HID = " + HexUtils.byteArrayToHexString(hid) + "\n";
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);
subType += "_UID = " + HexUtils.byteArrayToHexString(hid); String uid = HexUtils.byteArrayToHexString(hid);
if(uid.contains("00000000")) {
uid = "No _UID exists for this device";
}
subType += " _UID = " + uid + "\n";
return subType; return subType;
} }
@ -219,22 +229,25 @@ 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 = "PCI: PCI Function Number = "; subType = " Sub Type = PCI\n";
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 += " PCI Device Number = "; subType += "\n 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 sub type. * processes the SATA subtype.
* *
* @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 = "SATA: HBA Port Number = "; subType = " Sub Type = SATA\n";
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);
@ -242,18 +255,20 @@ 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 sub type. * Processes the hard drive subtype.
* *
* @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 = "Partition Number = "; subType = " Sub Type = Hard Drive\n";
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);
@ -261,14 +276,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 += " Partition Start = " + HexUtils.byteArrayToHexString(data); subType += "\n 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 += " Partition Size = " + HexUtils.byteArrayToHexString(data); subType += "\n 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) {
@ -279,26 +294,28 @@ public class UefiDevicePath {
} else { } else {
subType += "invalid partition signature type"; subType += "invalid partition signature type";
} }
subType += " Partition Format = "; subType += "\n 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 sub type. * Process the File path subtype.
* *
* @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 = "File Path = "; subType = " Sub Type = File Path\n";
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);
@ -307,11 +324,12 @@ 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 sub-type on a Media Type. * Process a vendor subtype 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.
@ -321,7 +339,8 @@ 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 = "Vendor Subtype GUID = "; subType = " Sub Type = Vendor\n";
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);
@ -337,8 +356,9 @@ 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 pesent"; subType += " : No Vendor Data present";
} }
subType += "\n";
return subType; return subType;
} }
@ -351,8 +371,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 = " USB "; subType = " Sub Type = USB\n";
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,
@ -361,6 +381,7 @@ 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;
} }
@ -377,7 +398,8 @@ 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 = "NVM Express Namespace = "; subType = " Sub Type = NVM\n";
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);
@ -386,6 +408,7 @@ 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;
} }
@ -400,7 +423,8 @@ 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 = "Legacy BIOS : Type = "; subType = " Sub Type = Bios Device Path\n";
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:
@ -432,6 +456,7 @@ public class UefiDevicePath {
subType += "Unknown"; subType += "Unknown";
break; break;
} }
subType += "\n";
return subType; return subType;
} }
@ -446,12 +471,13 @@ 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 = "PIWG Firmware File "; subType = " Sub Type = PIWG Firmware Volume File\n";
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;
} }
@ -466,12 +492,13 @@ 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 = "PIWG Firmware Volume "; subType = " Sub Type = PIWG Firmware Volume Path\n";
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;
} }