Merge branch 'issue-242' into issue-245

This commit is contained in:
iadgovuser26 2020-04-28 10:50:34 -04:00
commit dda14ca16d
8 changed files with 105 additions and 136 deletions

View File

@ -15,7 +15,7 @@ public class UefiBootOrder {
*/ */
UefiBootOrder(final byte[] order) { UefiBootOrder(final byte[] order) {
bootOrder = new char[order.length / UefiConstants.SIZE_2]; bootOrder = new char[order.length / UefiConstants.SIZE_2];
for (int i = 0; i < order.length; i = i + UefiConstants.SIZE_2) { for (int i = 0; i < order.length; i += UefiConstants.SIZE_2) {
bootOrder[i / UefiConstants.SIZE_2] = bootOrder[i / UefiConstants.SIZE_2] =
(char) (order[i + 1] * UefiConstants.SIZE_256 + order[i]); (char) (order[i + 1] * UefiConstants.SIZE_256 + order[i]);
} }
@ -26,11 +26,10 @@ public class UefiBootOrder {
* @return A human readable Boot Order * @return A human readable Boot Order
*/ */
public String toString() { public String toString() {
StringBuffer orderList = new StringBuffer(); StringBuilder orderList = new StringBuilder();
orderList.append("BootOrder = "); orderList.append("BootOrder = ");
for (int i = 0; i < bootOrder.length; i++) { for (int i = 0; i < bootOrder.length; i++) {
int order = bootOrder[i]; orderList.append(String.format("Boot %04d", (int) bootOrder[i]));
orderList.append(" Boot" + String.format("%04d", order));
} }
return orderList.toString(); return orderList.toString();
} }

View File

@ -1,6 +1,7 @@
package hirs.tpm.eventlog.uefi; package hirs.tpm.eventlog.uefi;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import hirs.utils.HexUtils; import hirs.utils.HexUtils;
@ -49,7 +50,7 @@ public UefiBootVariable(final byte[] bootVar) throws UnsupportedEncodingExceptio
int descLength = getChar16ArrayLength(blob); int descLength = getChar16ArrayLength(blob);
byte[] desc = new byte[descLength * UefiConstants.SIZE_2]; byte[] desc = new byte[descLength * UefiConstants.SIZE_2];
System.arraycopy(bootVar, UefiConstants.OFFSET_6, desc, 0, descLength * UefiConstants.SIZE_2); System.arraycopy(bootVar, UefiConstants.OFFSET_6, desc, 0, descLength * UefiConstants.SIZE_2);
description = new String(UefiDevicePath.convertChar16tobyteArray(desc), "UTF-8"); description = new String(UefiDevicePath.convertChar16tobyteArray(desc), StandardCharsets.UTF_8);
// Data following the Description should be EFI Partition Data (EFI_DEVICE_PATH_PROTOCOL) // Data following the Description should be EFI Partition Data (EFI_DEVICE_PATH_PROTOCOL)
int devPathLength = blobLength; int devPathLength = blobLength;
int devPathOffset = UefiConstants.OFFSET_6 + descLength; //attributes+bloblength+desc+length+2 int devPathOffset = UefiConstants.OFFSET_6 + descLength; //attributes+bloblength+desc+length+2
@ -66,11 +67,10 @@ public UefiBootVariable(final byte[] bootVar) throws UnsupportedEncodingExceptio
* @return string that represents a UEFI boot variable. * @return string that represents a UEFI boot variable.
*/ */
public String toString() { public String toString() {
String bootInfo = ""; StringBuilder bootInfo = new StringBuilder("Description = ");
String bootvar = description.replaceAll("[^a-zA-Z_0-0\\s]", ""); // remove all non ascii chars String bootvar = description.replaceAll("[^a-zA-Z_0-0\\s]", ""); // remove all non ascii chars
bootInfo += "Description = " + bootvar + "\n"; bootInfo.append(bootvar + "\n" + efiDevPath.toString());
bootInfo += efiDevPath.toString(); return bootInfo.toString();
return bootInfo;
} }
/** /**
@ -82,15 +82,15 @@ public String toString() {
*/ */
public int getChar16ArrayLength(final byte[] data) { public int getChar16ArrayLength(final byte[] data) {
int count = 0; int count = 0;
byte[] nullTerminitor = new byte[UefiConstants.SIZE_2]; byte[] nullTerminator = new byte[UefiConstants.SIZE_2];
byte[] char16 = new byte[UefiConstants.SIZE_2]; byte[] char16 = new byte[UefiConstants.SIZE_2];
nullTerminitor[0] = 0; nullTerminator[0] = 0;
nullTerminitor[1] = 0; nullTerminator[1] = 0;
for (int i = 0; i < data.length; i = i + UefiConstants.SIZE_2) { for (int i = 0; i < data.length; i += UefiConstants.SIZE_2) {
char16[0] = data[i]; char16[0] = data[i];
char16[1] = data[i + 1]; char16[1] = data[i + 1];
count++; count++;
if (Arrays.equals(nullTerminitor, char16)) { if (Arrays.equals(nullTerminator, char16)) {
return count * UefiConstants.SIZE_2; return count * UefiConstants.SIZE_2;
} }
} }

View File

@ -83,27 +83,25 @@ public class UefiDevicePath {
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
*/ */
private String processDevPath(final byte[] path) throws UnsupportedEncodingException { private String processDevPath(final byte[] path) throws UnsupportedEncodingException {
StringBuffer pInfo = new StringBuffer(); StringBuilder pInfo = new StringBuilder();
String devicePathInfo = ""; String devicePathInfo = "";
int devLength = 0, pathOffset = 0; int devLength = 0, pathOffset = 0;
boolean moreDev = true; while (true) {
while (moreDev) {
Byte devPath = Byte.valueOf(path[pathOffset]); Byte devPath = Byte.valueOf(path[pathOffset]);
if ((devPath.intValue() == UefiConstants.TERMINATOR) if ((devPath.intValue() == UefiConstants.TERMINATOR)
|| (devPath.intValue() == UefiConstants.END_FLAG)) { || (devPath.intValue() == UefiConstants.END_FLAG)) {
moreDev = false;
break; break;
} }
devicePathInfo = processDev(path, pathOffset); devicePathInfo = processDev(path, pathOffset);
if (devicePathInfo.contains("Unknown Device Path")) { if (devicePathInfo.contains("Unknown Device Path")) {
moreDev = false; break;
} }
pInfo.append(devicePathInfo); pInfo.append(devicePathInfo);
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];
pathOffset = pathOffset + devLength; pathOffset = pathOffset + devLength;
if (pathOffset >= path.length) { if (pathOffset >= path.length) {
moreDev = false; break;
} }
} }
return pInfo.toString(); return pInfo.toString();
@ -171,16 +169,15 @@ 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) {
String tmpType = ""; subType = "";
switch (path[offset + UefiConstants.OFFSET_1]) { switch (path[offset + UefiConstants.OFFSET_1]) {
case 0x01: tmpType = "(Short): "; case 0x01: subType = "(Short): ";
tmpType += acpiShortSubType(path, offset); subType += acpiShortSubType(path, offset);
break; break;
case 0x02: tmpType = "Expanded ACPI Device Path"; break; case 0x02: subType = "Expanded ACPI Device Path"; break;
default: tmpType = "Invalid ACPI Device Path sub type"; default: subType = "Invalid ACPI Device Path sub type";
} }
subType = tmpType; return subType;
return tmpType;
} }
/** /**
@ -190,14 +187,13 @@ private String acpiSubType(final byte[] path, final int offset) {
* @return short acpi info. * @return short acpi info.
*/ */
private String acpiShortSubType(final byte[] path, final int offset) { private String acpiShortSubType(final byte[] path, final int offset) {
String tmpType = ""; 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);
tmpType += "_HID = " + HexUtils.byteArrayToHexString(hid); 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);
tmpType += "_UID = " + HexUtils.byteArrayToHexString(hid); subType += "_UID = " + HexUtils.byteArrayToHexString(hid);
subType = tmpType; return subType;
return tmpType;
} }
/** /**
@ -207,12 +203,11 @@ private String acpiShortSubType(final byte[] path, final int offset) {
* @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) {
String tmpType = "PCI: PCI Function Number = "; subType = "PCI: PCI Function Number = ";
tmpType += String.format("0x%x", path[offset + UefiConstants.SIZE_4]); subType += String.format("0x%x", path[offset + UefiConstants.SIZE_4]);
tmpType += " PCI Device Number = "; subType += " PCI Device Number = ";
tmpType += String.format("0x%x", path[offset + UefiConstants.SIZE_5]); subType += String.format("0x%x", path[offset + UefiConstants.SIZE_5]);
subType = tmpType; return subType;
return tmpType;
} }
/** /**
@ -222,16 +217,15 @@ private String pciSubType(final byte[] path, final int 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) {
String tmpType = "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);
tmpType += HexUtils.byteArrayToHexString(data); subType += HexUtils.byteArrayToHexString(data);
System.arraycopy(path, UefiConstants.OFFSET_6 + offset, data, 0, UefiConstants.SIZE_2); System.arraycopy(path, UefiConstants.OFFSET_6 + offset, data, 0, UefiConstants.SIZE_2);
tmpType += " 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);
tmpType += " Logical Unit Number = " + HexUtils.byteArrayToHexString(data); subType += " Logical Unit Number = " + HexUtils.byteArrayToHexString(data);
subType = tmpType; return subType;
return tmpType;
} }
/** /**
@ -241,38 +235,37 @@ private String sataSubType(final byte[] path, final int 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) {
String tmpType = "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, 0, UefiConstants.SIZE_4); System.arraycopy(path, UefiConstants.OFFSET_4 + offset, partnumber, 0, UefiConstants.SIZE_4);
tmpType += HexUtils.byteArrayToHexString(partnumber); subType += HexUtils.byteArrayToHexString(partnumber);
byte[] data = new byte[UefiConstants.SIZE_8]; byte[] data = new byte[UefiConstants.SIZE_8];
System.arraycopy(path, UefiConstants.OFFSET_8 + offset, data, 0, UefiConstants.SIZE_8); System.arraycopy(path, UefiConstants.OFFSET_8 + offset, data, 0, UefiConstants.SIZE_8);
tmpType += "Partition Start = " + HexUtils.byteArrayToHexString(data); subType += "Partition Start = " + HexUtils.byteArrayToHexString(data);
System.arraycopy(path, UefiConstants.OFFSET_16 + offset, data, 0, UefiConstants.SIZE_8); System.arraycopy(path, UefiConstants.OFFSET_16 + offset, data, 0, UefiConstants.SIZE_8);
tmpType += "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, UefiConstants.SIZE_16); System.arraycopy(path, UefiConstants.OFFSET_24 + offset, signature, 0, UefiConstants.SIZE_16);
tmpType += "Partition Signature = "; subType += "Partition Signature = ";
if (path[UefiConstants.OFFSET_41 + offset] == UefiConstants.DRIVE_SIG_NONE) { if (path[UefiConstants.OFFSET_41 + offset] == UefiConstants.DRIVE_SIG_NONE) {
tmpType += "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) {
tmpType += HexUtils.byteArrayToHexString(signature); subType += HexUtils.byteArrayToHexString(signature);
} else if (path[UefiConstants.OFFSET_41 + offset] == UefiConstants.DRIVE_SIG_GUID) { } else if (path[UefiConstants.OFFSET_41 + offset] == UefiConstants.DRIVE_SIG_GUID) {
UefiGuid guid = new UefiGuid(signature); UefiGuid guid = new UefiGuid(signature);
tmpType += guid.toString(); subType += guid.toString();
} else { } else {
tmpType += "invalid partition signature type"; subType += "invalid partition signature type";
} }
tmpType += "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) {
tmpType += "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) {
tmpType += "GUID Partition Table"; subType += "GUID Partition Table";
} else { } else {
tmpType += "Invalid partition table type"; subType += "Invalid partition table type";
} }
subType = tmpType; return subType;
return tmpType;
} }
/** /**
@ -284,16 +277,15 @@ private String hardDriveSubType(final byte[] path, final int offset) {
*/ */
private String filePathSubType(final byte[] path, final int offset) private String filePathSubType(final byte[] path, final int offset)
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
String tmpType = "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);
byte[] filePath = new byte[subTypeLength]; byte[] filePath = new byte[subTypeLength];
System.arraycopy(path, UefiConstants.OFFSET_4 + offset, filePath, 0, subTypeLength); System.arraycopy(path, UefiConstants.OFFSET_4 + offset, filePath, 0, subTypeLength);
byte[] fileName = convertChar16tobyteArray(filePath); byte[] fileName = convertChar16tobyteArray(filePath);
tmpType += new String(fileName, "UTF-8"); subType += new String(fileName, "UTF-8");
subType = tmpType; return subType;
return tmpType;
} }
/** /**
@ -306,24 +298,23 @@ private String filePathSubType(final byte[] path, final int offset)
* @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) {
String tmpType = "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, 0, UefiConstants.SIZE_2); System.arraycopy(path, UefiConstants.OFFSET_2 + offset, lengthBytes, 0, UefiConstants.SIZE_2);
int subTypeLength = HexUtils.leReverseInt(lengthBytes); int subTypeLength = HexUtils.leReverseInt(lengthBytes);
byte[] guidData = new byte[UefiConstants.SIZE_16]; byte[] guidData = new byte[UefiConstants.SIZE_16];
System.arraycopy(path, UefiConstants.OFFSET_4 + offset, guidData, 0, UefiConstants.SIZE_16); System.arraycopy(path, UefiConstants.OFFSET_4 + offset, guidData, 0, UefiConstants.SIZE_16);
UefiGuid guid = new UefiGuid(guidData); UefiGuid guid = new UefiGuid(guidData);
tmpType += guid.toString() + " "; subType += guid.toString() + " ";
if (subTypeLength - UefiConstants.SIZE_16 > 0) { if (subTypeLength - UefiConstants.SIZE_16 > 0) {
byte[] vendorData = new byte[subTypeLength - UefiConstants.SIZE_16]; byte[] vendorData = new byte[subTypeLength - UefiConstants.SIZE_16];
System.arraycopy(path, UefiConstants.OFFSET_20 System.arraycopy(path, UefiConstants.OFFSET_20
+ offset, vendorData, 0, subTypeLength - UefiConstants.SIZE_16); + offset, vendorData, 0, subTypeLength - UefiConstants.SIZE_16);
tmpType += " : Vendor Data = " + HexUtils.byteArrayToHexString(vendorData); subType += " : Vendor Data = " + HexUtils.byteArrayToHexString(vendorData);
} else { } else {
tmpType += " : No Vendor Data pesent"; subType += " : No Vendor Data pesent";
} }
subType = tmpType; return subType;
return tmpType;
} }
/** /**
@ -337,45 +328,42 @@ private String vendorSubType(final byte[] path, final int offset) {
* @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) {
String tmpType = "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, 0, UefiConstants.SIZE_2); System.arraycopy(path, UefiConstants.OFFSET_2 + offset, lengthBytes, 0, UefiConstants.SIZE_2);
int subTypeLength = HexUtils.leReverseInt(lengthBytes); int subTypeLength = HexUtils.leReverseInt(lengthBytes);
byte[] nvmData = new byte[subTypeLength]; byte[] nvmData = new byte[subTypeLength];
System.arraycopy(path, UefiConstants.OFFSET_4 + offset, nvmData, 0, subTypeLength); System.arraycopy(path, UefiConstants.OFFSET_4 + offset, nvmData, 0, subTypeLength);
tmpType += HexUtils.byteArrayToHexString(nvmData); subType += HexUtils.byteArrayToHexString(nvmData);
subType = tmpType; return subType;
return tmpType;
} }
/** /**
* BIOS Device Type definition. * BIOS Device Type definition.
* From Appendix A of the BIOS Boot Specification. * From Appendix A of the BIOS Boot Specification.
* Only process the Device type. * Only processes the Device type.
* Status bootHandler pointer, and description String pointer are ignored. * Status bootHandler pointer, and description String pointer are ignored.
* @param path byte array holding the device path. * @param path byte array holding the device path.
* @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) {
String devPath = "Legacy BIOS : Type = "; subType = "Legacy BIOS : Type = ";
byte devPathType = path[offset + 1]; Byte pathType = Byte.valueOf(path[offset + 1]);
Byte pathType = Byte.valueOf(devPathType);
switch (pathType.intValue()) { switch (pathType.intValue()) {
case UefiConstants.DEVPATH_BIOS_RESERVED: devPath += "Reserved"; break; case UefiConstants.DEVPATH_BIOS_RESERVED: subType += "Reserved"; break;
case UefiConstants.DEVPATH_BIOS_FLOPPY: devPath += "Floppy"; break; case UefiConstants.DEVPATH_BIOS_FLOPPY: subType += "Floppy"; break;
case UefiConstants.DEVPATH_BIOS_HD: devPath += "Hard Disk"; break; case UefiConstants.DEVPATH_BIOS_HD: subType += "Hard Disk"; break;
case UefiConstants.DEVPATH_BIOS_CD: devPath += "CD-ROM"; break; case UefiConstants.DEVPATH_BIOS_CD: subType += "CD-ROM"; break;
case UefiConstants.DEVPATH_BIOS_PCM: devPath += "PCMCIA"; break; case UefiConstants.DEVPATH_BIOS_PCM: subType += "PCMCIA"; break;
case UefiConstants.DEVPATH_BIOS_USB: devPath += "USB"; break; case UefiConstants.DEVPATH_BIOS_USB: subType += "USB"; break;
case UefiConstants.DEVPATH_BIOS_EN: devPath += "Embedded network"; break; case UefiConstants.DEVPATH_BIOS_EN: subType += "Embedded network"; break;
case UefiConstants.DEVPATH_BIOS_BEV: devPath += case UefiConstants.DEVPATH_BIOS_BEV: subType +=
"Bootstrap Entry Vector (BEV) from an Option ROM"; "Bootstrap Entry Vector (BEV) from an Option ROM";
break; break;
default: devPath += "Reserved"; default: subType += "Unknown";
break; break;
} }
subType = devPath; return subType;
return devPath;
} }
/** /**
@ -388,13 +376,12 @@ private String biosDevicePath(final byte[] path, final int offset) {
* @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) {
String fWPath = "PIWG Firmware File "; 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, 0, UefiConstants.SIZE_16); System.arraycopy(path, UefiConstants.OFFSET_4 + offset, guidData, 0, UefiConstants.SIZE_16);
UefiGuid guid = new UefiGuid(guidData); UefiGuid guid = new UefiGuid(guidData);
fWPath += guid.toString(); subType += guid.toString();
subType = fWPath; return subType;
return fWPath;
} }
/** /**
@ -407,13 +394,12 @@ private String piwgFirmVolFile(final byte[] path, final int offset) {
* @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) {
String fWPath = "PIWG Firmware Volume "; 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, 0, UefiConstants.SIZE_16); System.arraycopy(path, UefiConstants.OFFSET_4 + offset, guidData, 0, UefiConstants.SIZE_16);
UefiGuid guid = new UefiGuid(guidData); UefiGuid guid = new UefiGuid(guidData);
fWPath += guid.toString(); subType += guid.toString();
subType = fWPath; return subType;
return fWPath;
} }
/** /**
@ -421,7 +407,7 @@ private String piwgFirmVolPath(final byte[] path, final int offset) {
* @return UEFi Device path. * @return UEFi Device path.
*/ */
public String toString() { public String toString() {
return (devPathInfo); return devPathInfo;
} }
/** /**

View File

@ -52,13 +52,7 @@ private static UUID processGuid(final byte[] guid) {
UUID tmpUuid = new UUID(msbl, lsbl); UUID tmpUuid = new UUID(msbl, lsbl);
return tmpUuid; return tmpUuid;
} }
/**
* Returns the standard GUID length.
* @return guid length
*/
public static int getGuidLength() {
return UefiConstants.SIZE_16;
}
/** /**
* Returns a String that represents a specification name referenced by the EFI_CONFIGURATION_TABLE * Returns a String that represents a specification name referenced by the EFI_CONFIGURATION_TABLE
* VendorGUID field. For structure of EFI_CONFIGURATION_TABLE type, the UEFI specification * VendorGUID field. For structure of EFI_CONFIGURATION_TABLE type, the UEFI specification
@ -71,10 +65,9 @@ public static int getGuidLength() {
@SuppressWarnings("checkstyle:methodlength") @SuppressWarnings("checkstyle:methodlength")
public String getVendorTableReference() { public String getVendorTableReference() {
String vendorRef = uuid.toString().toLowerCase();
String reference = ""; String reference = "";
switch (vendorRef) { switch (uuid.toString().toLowerCase()) {
// UUIDS listed in the UEFI Specification // UUIDS listed in the UEFI Specification
case "eb9d2d30-2d88-11d3-9a16-0090273fc14d": reference = "ACPI_TABLE_GUID"; break; case "eb9d2d30-2d88-11d3-9a16-0090273fc14d": reference = "ACPI_TABLE_GUID"; break;
case "eb9d2d32-2d88-11d3-9a16-0090273fc14d": reference = "SAL_SYSTEM_TABLE_GUID"; break; case "eb9d2d32-2d88-11d3-9a16-0090273fc14d": reference = "SAL_SYSTEM_TABLE_GUID"; break;
@ -206,7 +199,7 @@ public String getVendorTableReference() {
// RHBoot Lenovo specific UUIDS // RHBoot Lenovo specific UUIDS
case "3cc24e96-22c7-41d8-8863-8e39dcdcc2cf":reference = "lenovo"; break; case "3cc24e96-22c7-41d8-8863-8e39dcdcc2cf":reference = "lenovo"; break;
case "82988420-7467-4490-9059-feb448dd1963":reference = "lenovo_me_config"; break; case "82988420-7467-4490-9059-feb448dd1963":reference = "lenovo_me_config"; break;
case "f7e615b-0d45-4f80-88dc-26b234958560":reference = "lenovo_diag"; break; case "3f7e615b-0d45-4f80-88dc-26b234958560":reference = "lenovo_diag"; break;
case "665d3f60-ad3e-4cad-8e26-db46eee9f1b5":reference = "lenovo_rescue"; break; case "665d3f60-ad3e-4cad-8e26-db46eee9f1b5":reference = "lenovo_rescue"; break;
case "721c8b66-426c-4e86-8e99-3457c46ab0b9":reference = "lenovo_setup"; break; case "721c8b66-426c-4e86-8e99-3457c46ab0b9":reference = "lenovo_setup"; break;
case "f46ee6f4-4785-43a3-923d-7f786c3c8479":reference = "lenovo_startup_interrupt"; break; case "f46ee6f4-4785-43a3-923d-7f786c3c8479":reference = "lenovo_startup_interrupt"; break;
@ -234,7 +227,7 @@ public String getVendorTableReference() {
// Linux specific GUIDS // Linux specific GUIDS
case "0fc63daf-8483-4772-8e79-3d69d8477de":reference = "Linux filesystem data"; break; case "0fc63daf-8483-4772-8e79-3d69d8477de":reference = "Linux filesystem data"; break;
case "44479540-f297-41b2-9af7-d131d5f0458a4":reference = "Root partition (x86)"; break; case "44479540-f297-41b2-9af7-d131d5f0458a":reference = "Root partition (x86)"; break;
case "69dad710-2ce4-4e3c-b16c-21a1d49abed3":reference = "Root partition (32-bit ARM)"; break; case "69dad710-2ce4-4e3c-b16c-21a1d49abed3":reference = "Root partition (32-bit ARM)"; break;
case "b921b045-1df0-41c3-af44-4c6f280d3fae": case "b921b045-1df0-41c3-af44-4c6f280d3fae":
reference = "Root partition (64-bit ARM/AArch64)"; break; reference = "Root partition (64-bit ARM/AArch64)"; break;
@ -295,7 +288,7 @@ public String getVendorTableReference() {
case "26a2481e-4424-46a2-9943-cc4039ead8f8":reference = "S3Save"; break; case "26a2481e-4424-46a2-9943-cc4039ead8f8":reference = "S3Save"; break;
case "efd652cc-0e99-40f0-96c0-e08c089070fc":reference = "S3Restore"; break; case "efd652cc-0e99-40f0-96c0-e08c089070fc":reference = "S3Restore"; break;
case "8c783970-f02a-4a4d-af09-8797a51eec8d":reference = "PowerManagement"; break; case "8c783970-f02a-4a4d-af09-8797a51eec8d":reference = "PowerManagement"; break;
case "299141bb-211a-48a5-92c0-6f9a0a3a006e0":reference = "PowerManagement-ACPI-table"; break; case "299141bb-211a-48a5-92c0-6f9a0a3a006e":reference = "PowerManagement-ACPI-table"; break;
case "2df10014-cf21-4280-8c3f-e539b8ee5150":reference = "PpmPolicyInitDxe"; break; case "2df10014-cf21-4280-8c3f-e539b8ee5150":reference = "PpmPolicyInitDxe"; break;
case "4b680e2d-0d63-4f62-b930-7ae995b9b3a3":reference = "SmBusDxe"; break; case "4b680e2d-0d63-4f62-b930-7ae995b9b3a3":reference = "SmBusDxe"; break;
// SMM handlers // SMM handlers
@ -382,7 +375,7 @@ public static boolean isValidUUID(final byte[] guid) {
if (tmpUuid.toString().length() != 0) { if (tmpUuid.toString().length() != 0) {
valid = true; valid = true;
} }
return (valid); return valid;
} }
/** /**
@ -398,10 +391,7 @@ public boolean isEmptyUUID() {
* @return true if the uuid is the Empty UUID, false if not * @return true if the uuid is the Empty UUID, false if not
*/ */
public boolean isUnknownUUID() { public boolean isUnknownUUID() {
if (getVendorTableReference().equals("Unknown GUID reference")) { return getVendorTableReference().equals("Unknown GUID reference");
return true;
}
return false;
} }
/** /**

View File

@ -42,19 +42,20 @@ public class UefiPartition {
* @throws UnsupportedEncodingException if parsing of the data fails. * @throws UnsupportedEncodingException if parsing of the data fails.
*/ */
public UefiPartition(final byte[] table) throws UnsupportedEncodingException { public UefiPartition(final byte[] table) throws UnsupportedEncodingException {
byte[] partitionGUID = new byte[UefiGuid.getGuidLength()]; byte[] partitionGuidBytes = new byte[UefiConstants.SIZE_16];
System.arraycopy(table, 0, partitionGUID, 0, UefiGuid.getGuidLength()); System.arraycopy(table, 0, partitionGuidBytes, 0, UefiConstants.SIZE_16);
partitionTypeGUID = new UefiGuid(partitionGUID); partitionTypeGUID = new UefiGuid(partitionGuidBytes);
byte[] uniquePartGUID = new byte[UefiGuid.getGuidLength()]; byte[] uniquePartGuidBytes = new byte[UefiConstants.SIZE_16];
System.arraycopy(table, UefiGuid.getGuidLength(), uniquePartGUID, 0, UefiGuid.getGuidLength()); System.arraycopy(table, UefiConstants.SIZE_16, uniquePartGuidBytes, 0, UefiConstants.SIZE_16);
uniquePartitionGUID = new UefiGuid(uniquePartGUID); uniquePartitionGUID = new UefiGuid(uniquePartGuidBytes);
byte[] attribute = new byte[UefiConstants.SIZE_8]; byte[] attributeBytes = new byte[UefiConstants.SIZE_8];
System.arraycopy(table, UefiConstants.ATTRIBUTE_LENGTH, attribute, 0, UefiConstants.SIZE_8); System.arraycopy(table, UefiConstants.ATTRIBUTE_LENGTH, attributeBytes,
attributes = HexUtils.byteArrayToHexString(attribute); 0, UefiConstants.SIZE_8);
byte[] partitionname = new byte[UefiConstants.UEFI_PT_LENGTH]; attributes = HexUtils.byteArrayToHexString(attributeBytes);
System.arraycopy(table, UefiConstants.PART_NAME_LENGTH, partitionname, byte[] partitionNameBytes = new byte[UefiConstants.UEFI_PT_LENGTH];
System.arraycopy(table, UefiConstants.PART_NAME_LENGTH, partitionNameBytes,
0, UefiConstants.UEFI_PT_LENGTH); 0, UefiConstants.UEFI_PT_LENGTH);
byte[] pName = convertChar16tobyteArray(partitionname); byte[] pName = convertChar16tobyteArray(partitionNameBytes);
partitionName = new String(pName, "UTF-8").trim(); partitionName = new String(pName, "UTF-8").trim();
} }
@ -102,7 +103,7 @@ public String toString() {
private byte[] convertChar16tobyteArray(final byte[] data) { private byte[] convertChar16tobyteArray(final byte[] data) {
byte[] hexdata = new byte[data.length]; byte[] hexdata = new byte[data.length];
int j = 0; int j = 0;
for (int i = 0; i < data.length; i = i + 2) { for (int i = 0; i < data.length; i += 2) {
hexdata[j++] = data[i]; hexdata[j++] = data[i];
} }
return hexdata; return hexdata;

View File

@ -188,7 +188,7 @@ public boolean isValidSigListGUID(final UefiGuid guid) {
* @return human readable description. * @return human readable description.
*/ */
public String toString() { public String toString() {
StringBuffer sigInfo = new StringBuffer(); StringBuilder sigInfo = new StringBuilder();
sigInfo.append("UEFI Signature List Type = " + signatureType.toString() + "\n"); sigInfo.append("UEFI Signature List Type = " + signatureType.toString() + "\n");
sigInfo.append("Number if items = " + numberOfItems + "\n"); sigInfo.append("Number if items = " + numberOfItems + "\n");
sigList.iterator(); sigList.iterator();

View File

@ -134,7 +134,7 @@ private void processSigList(final byte[] data)
* @return human readable description of the UEFi variable. * @return human readable description of the UEFi variable.
*/ */
public String toString() { public String toString() {
StringBuffer efiVariable = new StringBuffer(); StringBuilder efiVariable = new StringBuilder();
efiVariable.append("UEFI Variable Name:" + varName + "\n"); efiVariable.append("UEFI Variable Name:" + varName + "\n");
efiVariable.append("UEFI_GUID = " + getEfiVarGuid().toString() + "\n"); efiVariable.append("UEFI_GUID = " + getEfiVarGuid().toString() + "\n");
efiVariable.append("UEFI Variable Contents => " + "\n"); efiVariable.append("UEFI Variable Contents => " + "\n");

View File

@ -13,13 +13,6 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/*
import org.junit.Test;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
*/
/** /**
* Class for testing TCG Event Log processing of UEFI defined Data. * Class for testing TCG Event Log processing of UEFI defined Data.
*/ */