Search in sources :

Example 16 with OffsetEntry

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));
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry) File(java.io.File) Test(org.junit.Test)

Example 17 with OffsetEntry

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;
        }
    }
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry)

Example 18 with OffsetEntry

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);
        }
    }
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry)

Example 19 with OffsetEntry

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;
        }
    }
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry)

Example 20 with OffsetEntry

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;
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry)

Aggregations

OffsetEntry (com.wave.hextractor.pojo.OffsetEntry)20 Test (org.junit.Test)5 HexTable (com.wave.hextractor.object.HexTable)3 TableSearchResult (com.wave.hextractor.pojo.TableSearchResult)1 File (java.io.File)1 BadLocationException (javax.swing.text.BadLocationException)1 DefaultHighlighter (javax.swing.text.DefaultHighlighter)1 Highlighter (javax.swing.text.Highlighter)1