use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.
the class UtilsTest method getOffsets.
@Test
public void getOffsets() throws IOException {
File file = File.createTempFile("test", "getOffsets.off");
file.deleteOnExit();
String offsets = "00000000-00000003-FF";
FileUtils.writeFileAscii(file.getAbsolutePath(), offsets);
OffsetEntry entry = new OffsetEntry(0, 3, Collections.singletonList("FF"));
List<OffsetEntry> resEntries = Collections.singletonList(entry);
Assert.assertEquals(resEntries, Utils.getOffsets(file.getAbsolutePath()));
Assert.assertEquals(resEntries, Utils.getOffsets(offsets));
}
use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.
the class HexViewer method nextOffset.
/**
* Next offset.
*/
private void nextOffset() {
Collections.sort(offEntries);
// Nos paramos en el primero cuyo start sea mayor a nuestro offset
for (OffsetEntry entry : offEntries) {
if (entry.getStart() > offset) {
offset = entry.getStart();
refreshAll();
break;
}
}
}
use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.
the class HexViewer method endItemAction.
/**
* End item action.
*
* @param selectedEntry the selected entry
*/
private void endItemAction(OffsetEntry selectedEntry) {
asciiTextArea.setSelectionEnd(asciiTextArea.getCaretPosition());
String result = JOptionPane.showInputDialog(rb.getString(KeyConstants.KEY_INPUT_ENDCHARS), lastSelectedEndChars);
if (result != null && result.length() > 0) {
if (result.matches(REGEXP_OFFSET_ENTRIES)) {
lastSelectedEndChars = result;
selectedEntry.setEndChars(Arrays.asList(lastSelectedEndChars.toUpperCase().replace(Constants.SPACE_STR, Constants.EMPTY).split(Constants.OFFSET_CHAR_SEPARATOR)));
selectedEntry.setEnd(offset + asciiTextArea.getCaretPosition());
if ((selectedEntry.getStart() > 0 || selectedEntry.getEnd() > 0) && selectedEntry == currEntry) {
currEntry.mergeInto(offEntries);
currEntry = new OffsetEntry();
currEntry.setStart(-1);
currEntry.setEnd(-1);
}
} else {
JOptionPane.showMessageDialog(asciiTextArea.getParent(), rb.getString(KeyConstants.KEY_ALERT_INVALID_ENDCHARS), rb.getString(KeyConstants.KEY_ALERT_INVALID_ENDCHARS_TITLE), JOptionPane.ERROR_MESSAGE);
}
}
}
use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.
the class HexViewer method prevOffset.
/**
* Prev offset.
*/
private void prevOffset() {
offEntries.sort(Collections.reverseOrder());
for (OffsetEntry entry : offEntries) {
if (entry.getStart() < offset) {
offset = entry.getStart();
refreshAll();
break;
}
}
}
use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.
the class HexViewer method getCaretEntry.
/**
* Gets the caret entry.
*
* @return the caret entry
*/
private OffsetEntry getCaretEntry() {
// By default our current is in range, is there anybody else?
int caretPosition = asciiTextArea.getCaretPosition() + offset;
OffsetEntry inRange = currEntry;
for (OffsetEntry entry : offEntries) {
// 1D collision, positions are inclusive
if (caretPosition >= entry.getStart() && caretPosition <= entry.getEnd()) {
inRange = entry;
}
}
return inRange;
}
Aggregations