Skip to content

Commit

Permalink
ifd: Handle IFDs without zero vector
Browse files Browse the repository at this point in the history
Closes #21.
  • Loading branch information
al3xtjames committed Jul 19, 2022
1 parent 7370071 commit b7339d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/main/java/firmware/ifd/IntelFlashDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,13 @@ public class IntelFlashDescriptor {
*
* @param reader the specified BinaryReader
*/
public IntelFlashDescriptor(BinaryReader reader) throws IOException {
// Skip the IFD vector (16 0xFF bytes).
public IntelFlashDescriptor(BinaryReader reader, boolean hasZeroVector) throws IOException {
// Skip the IFD vector (16 0xFF bytes) if it's present.
// Some BIOSes may not include this (observed on HP Compaq dc7900).
headerOffset = reader.getPointerIndex();
reader.setPointerIndex(reader.getPointerIndex() + 16);
if (hasZeroVector) {
reader.setPointerIndex(reader.getPointerIndex() + 16);
}

signature = reader.readNextInt();
if (signature != IntelFlashDescriptorConstants.IFD_SIGNATURE) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/firmware/ifd/IntelFlashFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ public IntelFlashFileSystem(FSRLRoot fsFSRL) {
public void mount(ByteProvider provider, long offset, TaskMonitor monitor) throws IOException {
this.provider = provider;
BinaryReader reader = new BinaryReader(provider, true);
boolean hasZeroVector = offset >= 16;

reader.setPointerIndex(offset - 16);
IntelFlashDescriptor ifd = new IntelFlashDescriptor(reader);
if (hasZeroVector) {
reader.setPointerIndex(offset - 16);
}

IntelFlashDescriptor ifd = new IntelFlashDescriptor(reader, hasZeroVector);
List<IntelFlashRegion> regions = ifd.getRegions();

for (IntelFlashRegion region : regions) {
Expand Down

0 comments on commit b7339d2

Please sign in to comment.