Skip to content

Commit

Permalink
Updated for JEB 2.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
nfalliere committed Dec 9, 2015
1 parent 84860bf commit 1a47d1b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
31 changes: 15 additions & 16 deletions src/com/pnf/plugin/fat/FatPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.pnfsoftware.jeb.core.PluginInformation;
import com.pnfsoftware.jeb.core.Version;
import com.pnfsoftware.jeb.core.input.IInput;
import com.pnfsoftware.jeb.core.properties.IPropertyDefinitionManager;
import com.pnfsoftware.jeb.core.units.AbstractUnitIdentifier;
import com.pnfsoftware.jeb.core.units.IUnit;
import com.pnfsoftware.jeb.core.units.IUnitProcessor;
Expand All @@ -44,28 +43,34 @@ public FatPlugin() {
super(ID, 0);
}

public boolean canIdentify(IInput stream, IUnitCreator unit) {
@Override
public PluginInformation getPluginInformation() {
// requires JEB 2.1
return new PluginInformation("FAT Plugin", "Parser for FAT filesystem images", "PNF Software", Version.create(
1, 0, 1), Version.create(2, 1), null);
}

public boolean canIdentify(IInput input, IUnitCreator unit) {
if(input == null) {
return false;
}

// First check to make sure that we are not parsing an OBB file (FAT
// image with OBB footer)
boolean isObb = true;

try(SeekableByteChannel ch = stream.getChannel()) {
try(SeekableByteChannel ch = input.getChannel()) {
ch.position(ch.size() - OBB_SIG.length);
ByteBuffer buff = ByteBuffer.allocate(OBB_SIG.length);
ch.read(buff);
isObb = checkBytes(buff, 0, OBB_SIG);
isObb = checkBytes(buff.array(), 0, OBB_SIG);
}
catch(IOException | IllegalArgumentException e) {
isObb = false;
}

// Then check for FAT boot sector signature
return !isObb && checkBytes(stream, FAT_BOOT_SIG_OFFSET, FAT_BOOT_SIG);
}

public void initialize(IPropertyDefinitionManager parent) {
super.initialize(parent);
/** Add any necessary property definitions here **/
return !isObb && checkBytes(input, FAT_BOOT_SIG_OFFSET, FAT_BOOT_SIG);
}

@Override
Expand All @@ -74,10 +79,4 @@ public IUnit prepare(String name, IInput data, IUnitProcessor processor, IUnitCr
fatUnit.process();
return fatUnit;
}

@Override
public PluginInformation getPluginInformation() {
return new PluginInformation("FAT Plugin", "Parser for FAT filesystem images", "PNF Software", new Version(1,
0, 0));
}
}
10 changes: 5 additions & 5 deletions src/com/pnf/plugin/fat/FatUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import com.pnf.plugin.fat.streams.ContainerStream;
import com.pnf.plugin.fat.streams.DocumentStream;
import com.pnfsoftware.jeb.core.IUnitCreator;
import com.pnfsoftware.jeb.core.events.J;
import com.pnfsoftware.jeb.core.events.JebEvent;
import com.pnfsoftware.jeb.core.input.BytesInput;
import com.pnfsoftware.jeb.core.input.IInput;
import com.pnfsoftware.jeb.core.properties.IPropertyDefinitionManager;
Expand Down Expand Up @@ -55,6 +53,10 @@ public String getDescription() {
}

public boolean process() {
if(isProcessed()) {
return true;
}

// Read the entire image into memory
byte[] bytes = null;
try(InputStream stream = getInput().getStream()) {
Expand All @@ -80,9 +82,7 @@ public boolean process() {
IUnit root = getContainerFor(core.getRootStream(), this);
addChildUnit(root);

// Throw unit change event
notifyListeners(new JebEvent(J.UnitChange));

setProcessed(true);
return true;
}

Expand Down

0 comments on commit 1a47d1b

Please sign in to comment.